2 // vim: foldmethod=marker
4 * Ethna_ActionForm_Test.php
6 * @author Yoshinari Takaoka <takaoka@beatcraft.com>
10 // {{{ Ethna_Test_ActionForm
16 class Ethna_Test_ActionForm extends Ethna_ActionForm
20 'type' => VAR_TYPE_STRING,
21 'form_type' => FORM_TYPE_TEXT,
26 'type' => VAR_TYPE_STRING,
27 'form_type' => FORM_TYPE_TEXT,
30 'test_array' => array(
31 'type' => array(VAR_TYPE_STRING),
32 'form_type' => FORM_TYPE_TEXT,
33 'name' => 'test array',
40 // {{{ Ethna_ActionForm_Test
42 * Test Case For Ethna_ActionForm(Mainly Validator)
46 class Ethna_ActionForm_Test extends Ethna_UnitTestBase
52 // REQUEST_METHOD を設定しないと
54 $_SERVER['REQUEST_METHOD'] = 'POST';
55 $this->local_af = new Ethna_Test_ActionForm($this->ctl);
56 $this->local_af->clearFormVars();
62 $_SERVER['REQUEST_METHOD'] = NULL;
63 $this->local_af = NULL;
70 $this->local_af->set('test', 'test');
71 $this->assertEqual('test', $this->local_af->get('test'));
76 function test_getDef()
79 $def = $this->local_af->getDef();
80 $this->assertEqual(3, count($def));
81 $this->assertEqual(10, count($def['test']));
82 $this->assertEqual('test', $def['test']['name']);
85 $this->assertNull($this->local_af->getDef('hoge'));
87 $def = $this->local_af->getDef('test');
88 $this->assertEqual(10, count($def));
89 $this->assertEqual('test', $def['name']);
94 function test_getName()
96 $this->assertNull($this->local_af->getName('hoge'));
97 $this->assertEqual('test', $this->local_af->getName('test'));
99 // もしフォームのname属性がないと、keyそのものが返ってくる
100 $this->assertEqual('no_name', $this->local_af->getName('no_name'));
105 function test_clearFormVars()
107 $this->local_af->set('test', 'hoge');
108 $this->local_af->set('no_name', 'fuga');
110 $this->local_af->clearFormVars();
112 $this->assertNull($this->local_af->get('test'));
113 $this->assertNull($this->local_af->get('no_name'));
120 $this->local_af->set('test', 'test');
121 $this->assertEqual('test', $this->local_af->get('test'));
126 function test_getHiddenVars()
128 // フォーム定義が配列で、submit された値が非配列の場合
129 // かつ、フォーム定義が配列なので、結局出力するhiddden
130 // タグも配列用のものとなる. 警告も勿論でない
131 $this->local_af->set('test_array', 1);
133 $hidden = $this->local_af->getHiddenVars();
134 $expected = "<input type=\"hidden\" name=\"test_array[0]\" value=\"1\" />\n";
135 $this->assertEqual($hidden, $expected);
136 $this->local_af->clearFormVars();
139 $this->local_af->set('test_array', array(1, 2));
140 $hidden = $this->local_af->getHiddenVars();
141 $expected = "<input type=\"hidden\" name=\"test_array[0]\" value=\"1\" />\n"
142 . "<input type=\"hidden\" name=\"test_array[1]\" value=\"2\" />\n";
143 $this->assertEqual($hidden, $expected);
144 $this->local_af->clearFormVars();
147 $this->local_af->set('test', 1);
148 $hidden = $this->local_af->getHiddenVars();
149 $expected = "<input type=\"hidden\" name=\"test\" value=\"1\" />\n";
150 $this->assertEqual($hidden, $expected);
151 $this->local_af->clearFormVars();
153 // フォーム定義がスカラーで、submitされた値が配列の場合
154 // この場合は明らかに使い方が間違っている上、2重に値が
155 // 出力されても意味がないので、警告(E_NOTICE)扱いにする
156 // この場合、hiddenタグは出力されない
157 $this->local_af->set('test', array(1,2));
158 $hidden = $this->local_af->getHiddenVars();
159 $this->assertEqual($hidden, ''); // 値が入っていない扱いなので空文字が返る
160 $this->local_af->clearFormVars();
163 $this->local_af->set('test', 1);
164 $this->local_af->set('no_name', 'name');
165 $this->local_af->set('test_array', array(1,2));
166 $include_list = array('test');
167 $hidden = $this->local_af->getHiddenVars($include_list);
168 $expected = "<input type=\"hidden\" name=\"test\" value=\"1\" />\n";
169 $this->assertEqual($hidden, $expected);
172 $exclude_list = array('test_array', 'no_name');
173 $hidden = $this->local_af->getHiddenVars(NULL, $exclude_list);
174 $expected = "<input type=\"hidden\" name=\"test\" value=\"1\" />\n";
175 $this->assertEqual($hidden, $expected);
177 // include_list, exclude_list の組み合わせ
178 $include_list = array('test', 'no_name');
179 $exclude_list = array('no_name');
180 $hidden = $this->local_af->getHiddenVars($include_list, $exclude_list);
181 $expected = "<input type=\"hidden\" name=\"test\" value=\"1\" />\n";
182 $this->assertEqual($hidden, $expected);