2 // vim: foldmethod=marker
4 * Ethna_ActionForm_Validator_Max_Test.php
6 * @author Yoshinari Takaoka <takaoka@beatcraft.com>
10 // {{{ Ethna_ActionForm_Validator_Max_Test
12 * Test Case For Ethna_ActionForm(Max Validator)
16 class Ethna_ActionForm_Validator_Max_Test extends Ethna_UnitTestBase
20 $this->af->use_validator_plugin = false;
21 $this->af->clearFormVars();
22 $this->af->form = array();
26 // {{{ Validator Max Integer.
27 function test_Validate_Max_Integer()
30 'type' => VAR_TYPE_INT,
31 'form_type' => FORM_TYPE_TEXT,
35 $this->af->setDef('input', $form_def);
37 $this->af->set('input', 5);
38 $this->af->validate();
39 $this->assertFalse($this->ae->isError('input'));
42 $this->af->set('input', 6);
43 $this->af->validate();
44 $this->assertTrue($this->ae->isError('input'));
47 $this->af->set('input', 4);
48 $this->af->validate();
49 $this->assertFalse($this->ae->isError('input'));
53 // {{{ Validator Max Float.
54 function test_Validate_Max_Float()
57 'type' => VAR_TYPE_FLOAT,
58 'form_type' => FORM_TYPE_TEXT,
62 $this->af->setDef('input', $form_def);
64 $this->af->set('input', 4.999999);
65 $this->af->validate();
66 $this->assertFalse($this->ae->isError('input'));
69 $this->af->set('input', 5.000001);
70 $this->af->validate();
71 $this->assertTrue($this->ae->isError('input'));
74 $this->af->set('input', 5.0);
75 $this->af->validate();
76 $this->assertFalse($this->ae->isError('input'));
79 $this->af->set('input', 6.0);
80 $this->af->validate();
81 $this->assertTrue($this->ae->isError('input'));
85 // {{{ Validator Max Datetime.
86 function test_Validate_Max_DateTime()
89 'type' => VAR_TYPE_DATETIME,
90 'form_type' => FORM_TYPE_TEXT,
92 'max' => '2000-01-01',
94 $this->af->setDef('input', $form_def);
96 $this->af->set('input', '1999-12-31');
97 $this->af->validate();
98 $this->assertFalse($this->ae->isError('input'));
101 $this->af->set('input', '2000-01-02');
102 $this->af->validate();
103 $this->assertTrue($this->ae->isError('input'));
106 $this->af->set('input', '2000-01-01');
107 $this->af->validate();
108 $this->assertFalse($this->ae->isError('input'));
113 // {{{ Validator Max String.
114 // {{{ Validator Max String(UTF-8)
115 function test_Validate_Max_String_UTF8()
118 'type' => VAR_TYPE_STRING,
119 'form_type' => FORM_TYPE_TEXT,
123 $this->af->setDef('input', $form_def);
126 $this->af->set('input', 'abcd');
127 $this->af->validate();
128 $this->assertFalse($this->ae->isError('input'));
131 $this->af->set('input', 'abcdef');
132 $this->af->validate();
133 $this->assertTrue($this->ae->isError('input'));
136 $this->af->set('input', 'abcde');
137 $this->af->validate();
138 $this->assertFalse($this->ae->isError('input'));
142 $this->af->set('input', 'あいうえお');
143 $this->af->validate();
144 $this->assertFalse($this->ae->isError('input'));
147 $this->af->set('input', 'あいうえおか');
148 $this->af->validate();
149 $this->assertTrue($this->ae->isError('input'));
152 $this->af->set('input', 'あいうえ');
153 $this->af->validate();
154 $this->assertFalse($this->ae->isError('input'));
158 // {{{ Validator Max String(EUC-JP)
159 function test_Validate_Max_String_EUCJP()
161 $this->ctl->setClientEncoding('EUC-JP');
164 'type' => VAR_TYPE_STRING,
165 'form_type' => FORM_TYPE_TEXT,
167 'max' => 4, // 全角2文字、半角4文字
169 $this->af->setDef('input', $form_def);
172 $this->af->set('input', 'abc');
173 $this->af->validate();
174 $this->assertFalse($this->ae->isError('input'));
177 $this->af->set('input', 'abcde');
178 $this->af->validate();
179 $this->assertTrue($this->ae->isError('input'));
182 $this->af->set('input', 'abcd');
183 $this->af->validate();
184 $this->assertFalse($this->ae->isError('input'));
188 $this->af->set('input', mb_convert_encoding('あい', 'EUC-JP', 'UTF-8'));
189 $this->af->validate();
190 $this->assertFalse($this->ae->isError('input'));
193 $this->af->set('input', mb_convert_encoding('あいう', 'EUC-JP', 'UTF-8'));
194 $this->af->validate();
195 $this->assertTrue($this->ae->isError('input'));
198 $this->af->set('input', mb_convert_encoding('あ', 'EUC-JP', 'UTF-8'));
199 $this->af->validate();
200 $this->assertFalse($this->ae->isError('input'));
202 // reset client encoding
203 $this->ctl->setClientEncoding('UTF-8');
207 // {{{ Validator Max String(ASCII)
208 function test_Validate_Max_String_ASCII()
210 $this->ctl->setClientEncoding('ASCII');
213 'type' => VAR_TYPE_STRING,
214 'form_type' => FORM_TYPE_TEXT,
216 'max' => 4, // ascii 4文字
218 $this->af->setDef('input', $form_def);
221 $this->af->set('input', 'abc');
222 $this->af->validate();
223 $this->assertFalse($this->ae->isError('input'));
226 $this->af->set('input', 'abcde');
227 $this->af->validate();
228 $this->assertTrue($this->ae->isError('input'));
231 $this->af->set('input', 'abcd');
232 $this->af->validate();
233 $this->assertFalse($this->ae->isError('input'));
236 // reset client encoding
237 $this->ctl->setClientEncoding('UTF-8');
242 // {{{ Validator Max File.
243 function test_Validate_Max_File()
245 // skipped because we can't bypass
246 // is_uploaded_file function.