OSDN Git Service

f5bec36e4933023f64d657251df1061f63b4c0b6
[ethna/ethna.git] / test / Ethna_ActionForm_Validator_Type_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_ActionForm_Validator_Type_Test.php
5  *
6  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
7  *  @version    $Id$
8  */
9
10 // {{{    Ethna_ActionForm_Validator_Type_Test
11 /**
12  *  Test Case For Ethna_ActionForm(Type Validator)
13  *
14  *  @access public
15  */
16 class Ethna_ActionForm_Validator_Type_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 Type Integer. 
27     function test_Validate_Type_Integer()
28     {
29         $form_def = array(
30                         'type' => VAR_TYPE_INT,
31                     );        
32         $this->af->setDef('input', $form_def);
33         
34         $this->af->set('input', 5);
35         $this->af->validate();
36         $this->assertFalse($this->ae->isError('input'));
37         $this->ae->clear();
38
39         //    null の値はTypeではチェックしない
40         $this->af->set('input', null); 
41         $this->af->validate();
42         $this->assertFalse($this->ae->isError('input'));
43         $this->ae->clear();
44  
45         $this->af->set('input', 6.5);
46         $this->af->validate();
47         $this->assertTrue($this->ae->isError('input'));
48         $this->ae->clear();
49
50         $this->af->set('input', 'abcd');
51         $this->af->validate();
52         $this->assertTrue($this->ae->isError('input'));
53     }
54     // }}}
55
56     // {{{ Validator Type Float. 
57     function test_Validate_Type_Float()
58     {
59         $form_def = array(
60                         'type' => VAR_TYPE_FLOAT,
61                     );        
62         $this->af->setDef('input', $form_def);
63         
64         $this->af->set('input', 4.999999); 
65         $this->af->validate();
66         $this->assertFalse($this->ae->isError('input'));
67         $this->ae->clear();
68
69         //    null の値はTypeではチェックしない
70         $this->af->set('input', null);
71         $this->af->validate();
72         $this->assertFalse($this->ae->isError('input'));
73         $this->ae->clear();
74
75         $this->af->set('input', 'abcd');
76         $this->af->validate();
77         $this->assertTrue($this->ae->isError('input'));
78         $this->ae->clear();
79
80         $this->af->set('input', 4);
81         $this->af->validate();
82         $this->assertFalse($this->ae->isError('input'));
83     }
84     // }}}
85
86     // {{{ Validator Type Datetime. 
87     function test_Validate_Type_DateTime()
88     {
89         $form_def = array(
90                         'type' => VAR_TYPE_DATETIME,
91                     );        
92         $this->af->setDef('input', $form_def);
93         
94         $this->af->set('input', '1999-12-31'); 
95         $this->af->validate();
96         $this->assertFalse($this->ae->isError('input'));
97         $this->ae->clear();
98
99         $this->af->set('input', 'abcd');
100         $this->af->validate();
101         $this->assertTrue($this->ae->isError('input'));
102         $this->ae->clear();
103
104         $this->af->set('input', ';-!#');
105         $this->af->validate();
106         $this->assertTrue($this->ae->isError('input'));
107         $this->ae->clear();
108
109         //    null の値はTypeではチェックしない
110         $this->af->set('input', null);
111         $this->af->validate();
112         $this->assertFalse($this->ae->isError('input'));
113         $this->ae->clear();
114     }
115     // }}}
116
117     // {{{ Validator Type String. 
118     function test_Validate_Min_String()
119     {
120         $form_def = array(
121                         'type' => VAR_TYPE_STRING,
122                     );        
123         $this->af->setDef('input', $form_def);
124         
125         //   in ascii.
126         $this->af->set('input', 'abcd'); 
127         $this->af->validate();
128         $this->assertFalse($this->ae->isError('input'));
129         $this->ae->clear();
130
131         //   multibyte.
132         $this->af->set('input', 'あいうえお');
133         $this->af->validate();
134         $this->assertFalse($this->ae->isError('input'));
135         $this->ae->clear();
136
137         //    null の値はTypeではチェックしない
138         $this->af->set('input', null);
139         $this->af->validate();
140         $this->assertFalse($this->ae->isError('input'));
141         $this->ae->clear();
142
143         //    空文字の値はTypeではチェックしない
144         $this->af->set('input', '');
145         $this->af->validate();
146         $this->assertFalse($this->ae->isError('input'));
147         $this->ae->clear();
148     }
149     // }}}
150 }
151 // }}}
152
153 ?>