1 | <?php |
||
15 | class FormTest extends \PHPUnit_Framework_TestCase { |
||
16 | |||
17 | /** |
||
18 | * |
||
19 | */ |
||
20 | public function testIsValidFlush() { |
||
21 | $form = new Form(); |
||
22 | $form->input('email'); |
||
23 | |||
24 | $form->handle(new FormData('post', [ |
||
25 | $form->getUid() => 1, |
||
26 | 'email' => 'test@test', |
||
27 | ])); |
||
28 | $this->assertTrue($form->isValid()); |
||
29 | |||
30 | $form->handle(new FormData('post', [])); |
||
31 | $this->assertFalse($form->isValid()); |
||
32 | } |
||
33 | |||
34 | |||
35 | /** |
||
36 | * |
||
37 | */ |
||
38 | public function testUid() { |
||
46 | |||
47 | |||
48 | /** |
||
49 | * |
||
50 | */ |
||
51 | public function testData() { |
||
52 | $form = new Form(); |
||
53 | $form->input('email'); |
||
54 | |||
55 | $form->handle(new FormData('post', [ |
||
56 | $form->getUid() => 1, |
||
57 | 'other_custom_data' => 123, |
||
58 | 'email' => 'test@test', |
||
59 | ])); |
||
60 | |||
61 | $this->assertEquals([ |
||
62 | 'email' => 'test@test', |
||
63 | ], $form->getData()); |
||
64 | |||
65 | } |
||
66 | |||
67 | |||
68 | /** |
||
69 | * |
||
70 | */ |
||
71 | public function testGetElements() { |
||
75 | |||
76 | |||
77 | /** |
||
78 | * |
||
79 | */ |
||
80 | public function testFormMethods() { |
||
100 | |||
101 | |||
102 | /** |
||
103 | * |
||
104 | */ |
||
105 | public function testFormRender() { |
||
113 | |||
114 | |||
115 | /** |
||
116 | * |
||
117 | */ |
||
118 | public function testIsSubmittedFalse() { |
||
123 | |||
124 | |||
125 | /** |
||
126 | * |
||
127 | */ |
||
128 | public function testIsSubmittedTrue() { |
||
129 | $form = new Form(); |
||
130 | $form->setName('test-form'); |
||
131 | $form->handle(new FormData('post', [ |
||
132 | 'test-form' => 1, |
||
133 | ])); |
||
134 | $this->assertEquals(true, $form->isSubmitted()); |
||
135 | |||
136 | $form = new Form(); |
||
137 | $form->submit('test-submit', 'test-value'); |
||
138 | $form->handle(new FormData('post', [$form->getUid() => 1])); |
||
139 | $this->assertEquals(true, $form->isSubmitted()); |
||
140 | } |
||
141 | |||
142 | |||
143 | /** |
||
144 | * |
||
145 | */ |
||
146 | public function testValidateWithoutSubmit() { |
||
147 | $form = new Form(); |
||
148 | $form->setName('test-form'); |
||
149 | $this->assertFalse($form->isValid()); |
||
150 | $this->assertFalse($form->isSubmitted()); |
||
151 | } |
||
152 | |||
153 | |||
154 | /** |
||
155 | * |
||
156 | */ |
||
157 | public function testHandleRequestContext() { |
||
158 | $form = new Form(); |
||
159 | $form->setName('test-form'); |
||
160 | $form->handle(new FormData('post', [ |
||
161 | $form->getUid() => 1, |
||
162 | 'other_custom_data' => 123, |
||
163 | 'email' => 'test@test', |
||
164 | ])); |
||
165 | |||
166 | $this->assertTrue($form->isSubmitted()); |
||
167 | $this->assertTrue($form->isValid()); |
||
168 | |||
169 | $form->handle(new FormData('post', [])); |
||
170 | $this->assertFalse($form->isSubmitted()); |
||
171 | } |
||
172 | |||
173 | |||
174 | /** |
||
175 | * @expectedException \Exception |
||
176 | */ |
||
177 | public function testAddElementsWithSameNames() { |
||
186 | |||
187 | |||
188 | /** |
||
189 | * |
||
190 | */ |
||
191 | public function testSetElementsWithSameNames() { |
||
207 | |||
208 | |||
209 | public function testFormValidationCache() { |
||
210 | $form = new Form(); |
||
211 | $form->setName('user_registration'); |
||
212 | |||
213 | |||
214 | $element = (new Input())->setName('test')->setValue('first'); |
||
215 | |||
216 | $checkedItemsNum = 0; |
||
217 | |||
218 | $element->addValidator(new CallBackValidator(function ($value) use (&$checkedItemsNum) { |
||
219 | $checkedItemsNum++; |
||
220 | |||
221 | return !empty($value); |
||
222 | })); |
||
223 | |||
224 | $form->setElement($element); |
||
225 | # emulate form submit |
||
226 | $form->handle(new FormData('post', [ |
||
227 | $form->getUid() => '1', |
||
228 | 'test' => '123', |
||
229 | ])); |
||
230 | |||
231 | $this->assertTrue($form->isValid()); |
||
232 | $this->assertEquals(1, $checkedItemsNum); |
||
233 | $this->assertTrue($form->isValid()); |
||
234 | $this->assertTrue($form->isValid()); |
||
235 | |||
236 | $this->assertEquals(1, $checkedItemsNum); |
||
237 | |||
238 | } |
||
239 | |||
240 | |||
241 | public function testRenderStartEnd() { |
||
249 | |||
250 | |||
251 | public function testRenderElements() { |
||
256 | |||
257 | |||
258 | /** |
||
259 | * @expectedException \InvalidArgumentException |
||
260 | */ |
||
261 | public function testGetElementByInvalidName() { |
||
262 | $form = new Form(); |
||
265 | |||
266 | |||
267 | public function testGetElementByName() { |
||
275 | |||
276 | |||
277 | public function testFormValidationErrors() { |
||
301 | |||
302 | |||
303 | public function testReSetData() { |
||
331 | |||
332 | |||
333 | public function testHandleRequest() { |
||
366 | |||
367 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: