2 // vim: foldmethod=marker
4 * Ethna_ActionForm_Validator_Type_Test.php
6 * @author Yoshinari Takaoka <takaoka@beatcraft.com>
10 // {{{ Ethna_ActionForm_Validator_Type_Test
12 * Test Case For Ethna_ActionForm(Type Validator)
16 class Ethna_ActionForm_Validator_Type_Test extends Ethna_UnitTestBase
20 $this->af->use_validator_plugin = false;
21 $this->af->clearFormVars();
22 $this->af->form = array();
26 // {{{ Validator Type Integer.
27 function test_Validate_Type_Integer()
30 'type' => VAR_TYPE_INT,
32 $this->af->setDef('input', $form_def);
34 $this->af->set('input', 5);
35 $this->af->validate();
36 $this->assertFalse($this->ae->isError('input'));
39 // null の値はTypeではチェックしない
40 $this->af->set('input', null);
41 $this->af->validate();
42 $this->assertFalse($this->ae->isError('input'));
45 $this->af->set('input', 6.5);
46 $this->af->validate();
47 $this->assertTrue($this->ae->isError('input'));
50 $this->af->set('input', 'abcd');
51 $this->af->validate();
52 $this->assertTrue($this->ae->isError('input'));
56 // {{{ Validator Type Float.
57 function test_Validate_Type_Float()
60 'type' => VAR_TYPE_FLOAT,
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 // null の値はTypeではチェックしない
70 $this->af->set('input', null);
71 $this->af->validate();
72 $this->assertFalse($this->ae->isError('input'));
75 $this->af->set('input', 'abcd');
76 $this->af->validate();
77 $this->assertTrue($this->ae->isError('input'));
80 $this->af->set('input', 4);
81 $this->af->validate();
82 $this->assertFalse($this->ae->isError('input'));
86 // {{{ Validator Type Datetime.
87 function test_Validate_Type_DateTime()
90 'type' => VAR_TYPE_DATETIME,
92 $this->af->setDef('input', $form_def);
94 $this->af->set('input', '1999-12-31');
95 $this->af->validate();
96 $this->assertFalse($this->ae->isError('input'));
99 $this->af->set('input', 'abcd');
100 $this->af->validate();
101 $this->assertTrue($this->ae->isError('input'));
104 $this->af->set('input', ';-!#');
105 $this->af->validate();
106 $this->assertTrue($this->ae->isError('input'));
109 // null の値はTypeではチェックしない
110 $this->af->set('input', null);
111 $this->af->validate();
112 $this->assertFalse($this->ae->isError('input'));
117 // {{{ Validator Type String.
118 function test_Validate_Min_String()
121 'type' => VAR_TYPE_STRING,
123 $this->af->setDef('input', $form_def);
126 $this->af->set('input', 'abcd');
127 $this->af->validate();
128 $this->assertFalse($this->ae->isError('input'));
132 $this->af->set('input', 'あいうえお');
133 $this->af->validate();
134 $this->assertFalse($this->ae->isError('input'));
137 // null の値はTypeではチェックしない
138 $this->af->set('input', null);
139 $this->af->validate();
140 $this->assertFalse($this->ae->isError('input'));
143 // 空文字の値はTypeではチェックしない
144 $this->af->set('input', '');
145 $this->af->validate();
146 $this->assertFalse($this->ae->isError('input'));