OSDN Git Service

- added Validator Required and Filter Test.
[ethna/ethna.git] / test / Ethna_ActionForm_Validator_Required_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_ActionForm_Validator_Required_Test.php
5  *
6  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
7  *  @version    $Id$
8  */
9
10 // {{{    Ethna_ActionForm_Validator_Required_Test
11 /**
12  *  Test Case For Ethna_ActionForm(Required Validator)
13  *
14  *  @access public
15  */
16 class Ethna_ActionForm_Validator_Required_Test extends Ethna_UnitTestBase
17 {
18     function setUp()
19     {
20         $this->af->use_validator_plugin = false;
21         $this->af->clearFormVars();
22         $this->af->form = array();
23         $this->ae->clear();
24     }
25
26     // {{{ Validator Required Integer. 
27     function test_Validate_Required_Integer()
28     {
29         $form_def = array(
30                         'type' => VAR_TYPE_INT,
31                         'form_type' => FORM_TYPE_TEXT,
32                         'required' => true,
33                     );        
34         $this->af->setDef('input', $form_def);
35         
36         $this->af->validate();
37         $this->assertTrue($this->ae->isError('input'));
38         $this->ae->clear();
39  
40         $this->af->set('input', 5);
41         $this->af->validate();
42         $this->assertFalse($this->ae->isError('input'));
43         $this->ae->clear();
44
45         $this->af->set('input', null); 
46         $this->af->validate();
47         $this->assertTrue($this->ae->isError('input'));
48     }
49     // }}}
50
51     // {{{ Validator Required Float. 
52     function test_Validate_Required_Float()
53     {
54         $form_def = array(
55                         'type' => VAR_TYPE_FLOAT,
56                         'form_type' => FORM_TYPE_TEXT,
57                         'required' => true,
58                     );        
59         $this->af->setDef('input', $form_def);
60         
61         $this->af->validate();
62         $this->assertTrue($this->ae->isError('input'));
63         $this->ae->clear();
64  
65         $this->af->set('input', 4.999999); 
66         $this->af->validate();
67         $this->assertFalse($this->ae->isError('input'));
68         $this->ae->clear();
69
70         $this->af->set('input', null); 
71         $this->af->validate();
72         $this->assertTrue($this->ae->isError('input'));
73     }
74     // }}}
75
76     // {{{ Validator Required Datetime. 
77     function test_Validate_Required_DateTime()
78     {
79         $form_def = array(
80                         'type' => VAR_TYPE_DATETIME,
81                         'form_type' => FORM_TYPE_TEXT,
82                         'required' => true,
83                     );        
84         $this->af->setDef('input', $form_def);
85         
86         $this->af->validate();
87         $this->assertTrue($this->ae->isError('input'));
88         $this->ae->clear();
89  
90         $this->af->set('input', '1999-12-31'); 
91         $this->af->validate();
92         $this->assertFalse($this->ae->isError('input'));
93         $this->ae->clear();
94
95         $this->af->set('input', null); 
96         $this->af->validate();
97         $this->assertTrue($this->ae->isError('input'));
98     }
99     // }}}
100
101     // {{{ Validator Required String. 
102     function test_Validate_Min_String()
103     {
104         $form_def = array(
105                         'type' => VAR_TYPE_STRING,
106                         'form_type' => FORM_TYPE_TEXT,
107                         'required' => true,
108                     );        
109         $this->af->setDef('input', $form_def);
110         
111         $this->af->validate();
112         $this->assertTrue($this->ae->isError('input'));
113         $this->ae->clear();
114  
115         $this->af->set('input', 'ああああ'); 
116         $this->af->validate();
117         $this->assertFalse($this->ae->isError('input'));
118         $this->ae->clear();
119
120         $this->af->set('input', 'abcd'); 
121         $this->af->validate();
122         $this->assertFalse($this->ae->isError('input'));
123         $this->ae->clear();
124
125         $this->af->set('input', null); 
126         $this->af->validate();
127         $this->assertTrue($this->ae->isError('input'));
128     }
129     // }}}
130
131     // {{{ Validator Max File. 
132     function test_Validate_Max_File()
133     {
134         //  skipped because we can't bypass 
135         //  is_uploaded_file function.
136     }
137     // }}}
138
139 }
140 // }}}
141
142 ?>