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 | $form->getUid() => 1, |
||
63 | 'other_custom_data' => 123, |
||
64 | 'email' => 'test@test', |
||
65 | ], $form->getData()); |
||
66 | |||
67 | } |
||
68 | |||
69 | |||
70 | /** |
||
71 | * |
||
72 | */ |
||
73 | public function testGetElements() { |
||
74 | $form = new Form(); |
||
75 | $this->assertEmpty($form->getElements()); |
||
76 | } |
||
77 | |||
78 | |||
79 | /** |
||
80 | * |
||
81 | */ |
||
82 | public function testFormMethods() { |
||
83 | $form = new Form(); |
||
84 | $this->assertEquals('post', $form->getMethod()); |
||
85 | |||
86 | $form->setMethod('POST'); |
||
87 | $this->assertEquals('post', $form->getMethod()); |
||
88 | |||
89 | $form->setMethod('get'); |
||
90 | $this->assertEquals('get', $form->getMethod()); |
||
91 | |||
92 | $form->setMethod('put'); |
||
93 | $this->assertEquals('put', $form->getMethod()); |
||
94 | |||
95 | $form->setMethod(false); |
||
|
|||
96 | $this->assertEquals(null, $form->getMethod()); |
||
97 | |||
98 | $form->setAttribute('method', 'test'); |
||
99 | $this->assertEquals('test', $form->getMethod()); |
||
100 | |||
101 | } |
||
102 | |||
103 | |||
104 | /** |
||
105 | * |
||
106 | */ |
||
107 | public function testFormRender() { |
||
108 | $form = new Form(); |
||
109 | $this->assertContains('method="post"', $form->render()); |
||
110 | |||
111 | $form = new Form(); |
||
112 | $form->setMethod('get'); |
||
113 | $this->assertContains('method="get"', $form->render()); |
||
114 | } |
||
115 | |||
116 | |||
117 | /** |
||
118 | * |
||
119 | */ |
||
120 | public function testIsSubmittedFalse() { |
||
121 | $form = new Form(); |
||
122 | $form->handle(new FormData('post', [])); |
||
123 | $this->assertEquals(false, $form->isSubmitted()); |
||
124 | } |
||
125 | |||
126 | |||
127 | /** |
||
128 | * |
||
129 | */ |
||
130 | public function testIsSubmittedTrue() { |
||
131 | $form = new Form(); |
||
132 | $form->setName('test-form'); |
||
133 | $form->handle(new FormData('post', [ |
||
134 | 'test-form' => 1, |
||
135 | ])); |
||
136 | $this->assertEquals(true, $form->isSubmitted()); |
||
137 | |||
138 | $form = new Form(); |
||
139 | $form->submit('test-submit', 'test-value'); |
||
140 | $form->handle(new FormData('post', [$form->getUid() => 1])); |
||
141 | $this->assertEquals(true, $form->isSubmitted()); |
||
142 | } |
||
143 | |||
144 | |||
145 | /** |
||
146 | * |
||
147 | */ |
||
148 | public function testValidateWithoutSubmit() { |
||
154 | |||
155 | |||
156 | /** |
||
157 | * |
||
158 | */ |
||
159 | public function testHandleRequestContext() { |
||
160 | $exception = null; |
||
161 | |||
162 | $form = new Form(); |
||
163 | $form->setName('test-form'); |
||
164 | $form->handle(new FormData('post', [ |
||
165 | $form->getUid() => 1, |
||
166 | 'other_custom_data' => 123, |
||
167 | 'email' => 'test@test', |
||
168 | ])); |
||
169 | |||
170 | $this->assertTrue($form->isSubmitted()); |
||
171 | $this->assertTrue($form->isValid()); |
||
172 | |||
173 | $form->handle(new FormData('post', [])); |
||
174 | $this->assertFalse($form->isSubmitted()); |
||
175 | } |
||
176 | |||
177 | |||
178 | /** |
||
179 | * @expectedException \Exception |
||
180 | */ |
||
181 | public function testAddElementsWithSameNames() { |
||
190 | |||
191 | |||
192 | /** |
||
193 | * |
||
194 | */ |
||
195 | public function testSetElementsWithSameNames() { |
||
211 | |||
212 | |||
213 | public function testFormValidationCache() { |
||
243 | |||
244 | |||
245 | public function testRenderStartEnd() { |
||
253 | |||
254 | |||
255 | public function testRenderElements() { |
||
260 | |||
261 | |||
262 | /** |
||
263 | * @expectedException \InvalidArgumentException |
||
264 | */ |
||
265 | public function testGetElementByInvalidName() { |
||
269 | |||
270 | |||
271 | public function testGetElementByName() { |
||
279 | |||
280 | |||
281 | public function testFormValidationErrors() { |
||
282 | $form = new Form(); |
||
305 | |||
306 | |||
307 | public function testReSetData() { |
||
326 | |||
327 | |||
328 | public function testHandleRequest() { |
||
357 | |||
358 | } |
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: