OSDN Git Service

- implemented String [Max|Min] Validator with newly arranged Plugins.
[ethna/ethna.git] / test / Ethna_ActionForm_Validator_Max_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_ActionForm_Validator_Max_Test.php
5  *
6  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
7  *  @version    $Id$
8  */
9
10 // {{{    Ethna_ActionForm_Validator_Max_Test
11 /**
12  *  Test Case For Ethna_ActionForm(Max Validator)
13  *
14  *  @access public
15  */
16 class Ethna_ActionForm_Validator_Max_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 Max Integer. 
27     function test_Validate_Max_Integer()
28     {
29         $form_def = array(
30                         'type' => VAR_TYPE_INT,
31                         'form_type' => FORM_TYPE_TEXT,
32                         'required' => true,
33                         'max' => 5,
34                     );        
35         $this->af->setDef('input', $form_def);
36         
37         $this->af->set('input', 5);
38         $this->af->validate();
39         $this->assertFalse($this->ae->isError('input'));
40         $this->ae->clear();
41
42         $this->af->set('input', 6);
43         $this->af->validate();
44         $this->assertTrue($this->ae->isError('input'));
45         $this->ae->clear();
46
47         $this->af->set('input', 4); 
48         $this->af->validate();
49         $this->assertFalse($this->ae->isError('input'));
50     }
51     // }}}
52
53     // {{{ Validator Max Float. 
54     function test_Validate_Max_Float()
55     {
56         $form_def = array(
57                         'type' => VAR_TYPE_FLOAT,
58                         'form_type' => FORM_TYPE_TEXT,
59                         'required' => true,
60                         'max' => 5,
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         $this->af->set('input', 5.000001);
70         $this->af->validate();
71         $this->assertTrue($this->ae->isError('input'));
72         $this->ae->clear();
73
74         $this->af->set('input', 5.0);
75         $this->af->validate();
76         $this->assertFalse($this->ae->isError('input'));
77         $this->ae->clear();
78
79         $this->af->set('input', 6.0);
80         $this->af->validate();
81         $this->assertTrue($this->ae->isError('input'));
82     }
83     // }}}
84
85     // {{{ Validator Max Datetime. 
86     function test_Validate_Max_DateTime()
87     {
88         $form_def = array(
89                         'type' => VAR_TYPE_DATETIME,
90                         'form_type' => FORM_TYPE_TEXT,
91                         'required' => true,
92                         'max' => '2000-01-01',
93                     );        
94         $this->af->setDef('input', $form_def);
95         
96         $this->af->set('input', '1999-12-31'); 
97         $this->af->validate();
98         $this->assertFalse($this->ae->isError('input'));
99         $this->ae->clear();
100
101         $this->af->set('input', '2000-01-02');
102         $this->af->validate();
103         $this->assertTrue($this->ae->isError('input'));
104         $this->ae->clear();
105
106         $this->af->set('input', '2000-01-01');
107         $this->af->validate();
108         $this->assertFalse($this->ae->isError('input'));
109         $this->ae->clear();
110     }
111     // }}}
112
113     // {{{ Validator Max String. 
114     // {{{ Validator Max String(UTF-8)
115     function test_Validate_Max_String_UTF8()
116     {
117         $form_def = array(
118                         'type' => VAR_TYPE_STRING,
119                         'form_type' => FORM_TYPE_TEXT,
120                         'required' => true,
121                         'max' => 5,
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         $this->af->set('input', 'abcdef');
132         $this->af->validate();
133         $this->assertTrue($this->ae->isError('input'));
134         $this->ae->clear();
135
136         $this->af->set('input', 'abcde');
137         $this->af->validate();
138         $this->assertFalse($this->ae->isError('input'));
139         $this->ae->clear();
140
141         //   multibyte.
142         $this->af->set('input', 'あいうえお');
143         $this->af->validate();
144         $this->assertFalse($this->ae->isError('input'));
145         $this->ae->clear();
146
147         $this->af->set('input', 'あいうえおか');
148         $this->af->validate();
149         $this->assertTrue($this->ae->isError('input'));
150         $this->ae->clear();
151
152         $this->af->set('input', 'あいうえ');
153         $this->af->validate();
154         $this->assertFalse($this->ae->isError('input'));
155     }
156     // }}}
157
158     // {{{ Validator Max String(EUC-JP)
159     function test_Validate_Max_String_EUCJP()
160     {
161         $this->ctl->setClientEncoding('EUC-JP');
162  
163         $form_def = array(
164                         'type' => VAR_TYPE_STRING,
165                         'form_type' => FORM_TYPE_TEXT,
166                         'required' => true,
167                         'max' => 4,  //  全角2文字、半角4文字
168                     );        
169         $this->af->setDef('input', $form_def);
170         
171         //   in ascii.
172         $this->af->set('input', 'abc'); 
173         $this->af->validate();
174         $this->assertFalse($this->ae->isError('input'));
175         $this->ae->clear();
176
177         $this->af->set('input', 'abcde');
178         $this->af->validate();
179         $this->assertTrue($this->ae->isError('input'));
180         $this->ae->clear();
181
182         $this->af->set('input', 'abcd');
183         $this->af->validate();
184         $this->assertFalse($this->ae->isError('input'));
185         $this->ae->clear();
186
187         //   multibyte.
188         $this->af->set('input', mb_convert_encoding('あい', 'EUC-JP', 'UTF-8'));
189         $this->af->validate();
190         $this->assertFalse($this->ae->isError('input'));
191         $this->ae->clear();
192
193         $this->af->set('input', mb_convert_encoding('あいう', 'EUC-JP', 'UTF-8'));
194         $this->af->validate();
195         $this->assertTrue($this->ae->isError('input'));
196         $this->ae->clear();
197
198         $this->af->set('input', mb_convert_encoding('あ', 'EUC-JP', 'UTF-8'));
199         $this->af->validate();
200         $this->assertFalse($this->ae->isError('input'));
201
202         //   reset client encoding
203         $this->ctl->setClientEncoding('UTF-8');
204     }
205     // }}}
206
207     // {{{ Validator Max String(ASCII)
208     function test_Validate_Max_String_ASCII()
209     {
210         $this->ctl->setClientEncoding('ASCII');
211  
212         $form_def = array(
213                         'type' => VAR_TYPE_STRING,
214                         'form_type' => FORM_TYPE_TEXT,
215                         'required' => true,
216                         'max' => 4,  //  ascii 4文字 
217                     );        
218         $this->af->setDef('input', $form_def);
219         
220         //   in ascii.
221         $this->af->set('input', 'abc'); 
222         $this->af->validate();
223         $this->assertFalse($this->ae->isError('input'));
224         $this->ae->clear();
225
226         $this->af->set('input', 'abcde');
227         $this->af->validate();
228         $this->assertTrue($this->ae->isError('input'));
229         $this->ae->clear();
230
231         $this->af->set('input', 'abcd');
232         $this->af->validate();
233         $this->assertFalse($this->ae->isError('input'));
234         $this->ae->clear();
235
236         //   reset client encoding
237         $this->ctl->setClientEncoding('UTF-8');
238     }
239     // }}}
240     // }}}
241
242     // {{{ Validator Max File. 
243     function test_Validate_Max_File()
244     {
245         //  skipped because we can't bypass 
246         //  is_uploaded_file function.
247     }
248     // }}}
249
250 }
251 // }}}
252
253 ?>