1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KochTest\Form; |
4
|
|
|
|
5
|
|
|
use Koch\Form\Elements; |
6
|
|
|
use Koch\Form\Form; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @todo method chaining tests on all setter methods |
10
|
|
|
*/ |
11
|
|
|
class FormTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Form |
15
|
|
|
*/ |
16
|
|
|
protected $form; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Sets up the fixture, for example, opens a network connection. |
20
|
|
|
* This method is called before a test is executed. |
21
|
|
|
*/ |
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->form = new Form('TestForm'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tears down the fixture, for example, closes a network connection. |
29
|
|
|
* This method is called after a test is executed. |
30
|
|
|
*/ |
31
|
|
|
public function tearDown() |
32
|
|
|
{ |
33
|
|
|
unset($this->form); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @covers Koch\Form\Form::__construct |
38
|
|
|
* @expectedException InvalidArgumentException |
39
|
|
|
* @expectedExceptionMessage |
40
|
|
|
*/ |
41
|
|
|
public function testConstructorThrowsExceptionWhenFirstArgumentMissing() |
42
|
|
|
{ |
43
|
|
|
$this->form = new Form(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @covers Koch\Form\Form::__construct |
48
|
|
|
*/ |
49
|
|
|
public function testConstructorArgsAreSet() |
50
|
|
|
{ |
51
|
|
|
$this->form = new Form('Form', 'GET', 'someActionName'); |
52
|
|
|
|
53
|
|
|
$this->assertEquals('GET', $this->form->getMethod()); |
54
|
|
View Code Duplication |
if (defined('REWRITE_ENGINE_ON') and REWRITE_ENGINE_ON) { |
|
|
|
|
55
|
|
|
$expectedURL = WWW_ROOT . 'someActionName'; |
56
|
|
|
} else { |
57
|
|
|
$expectedURL = WWW_ROOT . 'index.php?mod=someActionName'; |
58
|
|
|
} |
59
|
|
|
$this->assertEquals($expectedURL, $this->form->getAction()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @expectedException InvalidArgumentException |
64
|
|
|
* @expectedExceptionMessage The method parameter is "abc", but has to be GET or POST. |
65
|
|
|
*/ |
66
|
|
|
public function testSetMethodThrowsInvalidArgumentException() |
67
|
|
|
{ |
68
|
|
|
$this->form->setMethod('abc'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetMethod() |
72
|
|
|
{ |
73
|
|
|
$this->form->setMethod('GET'); |
74
|
|
|
|
75
|
|
|
// via getter |
76
|
|
|
$this->assertNotEquals('get', $this->form->getMethod()); |
77
|
|
|
$this->assertEquals('GET', $this->form->getMethod()); |
78
|
|
|
// via property |
79
|
|
|
$this->assertEquals('GET', $this->form->method); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetMethod() |
83
|
|
|
{ |
84
|
|
|
// defaults to POST |
85
|
|
|
$this->assertEquals('POST', $this->form->getMethod()); |
86
|
|
|
|
87
|
|
|
$this->form->setMethod('GET'); |
88
|
|
|
// via getter |
89
|
|
|
$this->assertEquals('GET', $this->form->getMethod()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testSetAction() |
93
|
|
|
{ |
94
|
|
|
// set internal url - rebuilds the external url via router |
95
|
|
|
$this->form->setAction('/news/show'); |
96
|
|
View Code Duplication |
if (defined('REWRITE_ENGINE_ON') and REWRITE_ENGINE_ON) { |
|
|
|
|
97
|
|
|
$expectedURL = WWW_ROOT . 'news/show'; |
98
|
|
|
} else { |
99
|
|
|
$expectedURL = WWW_ROOT . 'index.php?mod=news&ctrl=show'; |
100
|
|
|
} |
101
|
|
|
$this->assertEquals($expectedURL, $this->form->getAction()); |
102
|
|
|
|
103
|
|
|
// set external url |
104
|
|
|
$this->form->setAction(WWW_ROOT . 'index.php?mod=news&action=show'); |
105
|
|
|
$this->assertEquals(WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction()); |
106
|
|
|
|
107
|
|
|
// set external url withput www_root (http root) |
108
|
|
|
$this->form->setAction('index.php?mod=news&action=show'); |
109
|
|
|
$this->assertEquals(WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testGetAction() |
113
|
|
|
{ |
114
|
|
|
// via getter - qualified url |
115
|
|
|
$url = WWW_ROOT . 'index.php?mod=news&action=show'; |
116
|
|
|
$this->form->setAction($url); |
117
|
|
|
$this->assertEquals($url, $this->form->getAction()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @expectedException InvalidArgumentException |
122
|
|
|
* @expectedExceptionMessage The target parameter is "abc", but has to be one of _blank, _self, _parent, _top. |
123
|
|
|
*/ |
124
|
|
|
public function testMethodsetTargetThrowsException() |
125
|
|
|
{ |
126
|
|
|
$this->form->setTarget('abc'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @covers Koch\Form\Form::getTarget |
131
|
|
|
* @covers Koch\Form\Form::setTarget |
132
|
|
|
*/ |
133
|
|
|
public function testMethodsetTarget() |
134
|
|
|
{ |
135
|
|
|
$this->form->setTarget('_self'); |
136
|
|
|
|
137
|
|
|
$this->assertEquals('_self', $this->form->getTarget()); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testGetAutocomplete() |
141
|
|
|
{ |
142
|
|
|
$this->form->setAutoComplete(false); |
143
|
|
|
$this->assertEquals('off', $this->form->isAutoComplete()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testSetAutocomplete() |
147
|
|
|
{ |
148
|
|
|
$this->form->setAutoComplete(false); |
149
|
|
|
$this->assertEquals('off', $this->form->isAutoComplete()); |
150
|
|
|
|
151
|
|
|
$this->form->setAutoComplete(true); |
152
|
|
|
$this->assertEquals('on', $this->form->isAutoComplete()); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testGetNoValidation() |
156
|
|
|
{ |
157
|
|
|
$this->form->setNoValidation(true); |
158
|
|
|
$this->assertEquals('novalidate', $this->form->isNoValidation()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function testSetNoValidation() |
162
|
|
|
{ |
163
|
|
|
$this->form->setNoValidation(false); |
164
|
|
|
|
165
|
|
|
// via getter - returns empty string |
166
|
|
|
$this->assertEquals('', $this->form->isNoValidation()); |
167
|
|
|
|
168
|
|
|
$this->form->setNoValidation(true); |
169
|
|
|
|
170
|
|
|
// via getter - returns string |
171
|
|
|
$this->assertEquals('novalidate', $this->form->isNoValidation()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function testGetAttribute() |
175
|
|
|
{ |
176
|
|
|
$this->form->setAttribute('myAttribute', true); |
|
|
|
|
177
|
|
|
|
178
|
|
|
// via getter - returns string |
179
|
|
|
$this->assertEquals(true, $this->form->getAttribute('myAttribute')); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testSetAttribute() |
183
|
|
|
{ |
184
|
|
|
$this->form->setAttribute('myAttribute', true); |
|
|
|
|
185
|
|
|
|
186
|
|
|
// via getter - returns string |
187
|
|
|
$this->assertEquals(true, $this->form->getAttribute('myAttribute')); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function testSetAttributes() |
191
|
|
|
{ |
192
|
|
|
$array = ['attr1' => 'val1', 'attr2' => true]; |
193
|
|
|
|
194
|
|
|
$this->form->setAttributes($array); |
195
|
|
|
|
196
|
|
|
// via getter - returns string |
197
|
|
|
$this->assertEquals('val1', $this->form->getAttribute('attr1')); |
198
|
|
|
$this->assertEquals(true, $this->form->getAttribute('attr2')); |
199
|
|
|
|
200
|
|
|
unset($array); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testSetAttributesContainFormKey() |
204
|
|
|
{ |
205
|
|
|
$this->markTestSkipped('Depends on Form\Generator\PHPArray'); |
206
|
|
|
|
207
|
|
|
$attributes = [ |
208
|
|
|
'attr1' => 'val1', |
209
|
|
|
'attr2' => true, |
210
|
|
|
'form' => [ |
211
|
|
|
'name' => 'formname', |
212
|
|
|
'action' => 'someAction', |
213
|
|
|
'method' => 'POST', |
214
|
|
|
'key-a' => 'value-a', |
215
|
|
|
'key-b' => 'value-b', |
216
|
|
|
], |
217
|
|
|
]; |
218
|
|
|
|
219
|
|
|
$this->form->setAttributes($attributes); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function testCopyObjectProperties() |
223
|
|
|
{ |
224
|
|
|
// prefilled object |
225
|
|
|
$from_object_a = new \stdClass(); |
|
|
|
|
226
|
|
|
$from_object_a->attribute_string = 'value_of_attr_a'; |
|
|
|
|
227
|
|
|
$from_object_a->attribute_int = 9; |
|
|
|
|
228
|
|
|
$from_object_a->attribute_bool = true; |
|
|
|
|
229
|
|
|
$from_object_a->attribute_array = ['key' => 'value']; |
|
|
|
|
230
|
|
|
|
231
|
|
|
// empty target object |
232
|
|
|
$to_object_b = new \stdClass(); |
|
|
|
|
233
|
|
|
|
234
|
|
|
$this->form->copyObjectProperties($from_object_a, $to_object_b); |
|
|
|
|
235
|
|
|
|
236
|
|
|
$this->assertEquals($from_object_a, $to_object_b); |
|
|
|
|
237
|
|
|
$this->assertEquals($to_object_b->attribute_string, 'value_of_attr_a'); |
|
|
|
|
238
|
|
|
$this->assertEquals($to_object_b->attribute_int, 9); |
|
|
|
|
239
|
|
|
$this->assertEquals($to_object_b->attribute_bool, true); |
|
|
|
|
240
|
|
|
$this->assertEquals($to_object_b->attribute_array['key'], 'value'); |
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @covers Koch\Form\Form::setID() |
245
|
|
|
* @covers Koch\Form\Form::getID() |
246
|
|
|
*/ |
247
|
|
|
public function testSetID() |
248
|
|
|
{ |
249
|
|
|
$this->form->setId('identifier1'); |
250
|
|
|
$this->assertEquals('identifier1', $this->form->getId()); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @covers Koch\Form\Form::setName() |
255
|
|
|
* @covers Koch\Form\Form::getName() |
256
|
|
|
*/ |
257
|
|
|
public function testSetName() |
258
|
|
|
{ |
259
|
|
|
$this->form->setName('name1'); |
260
|
|
|
$this->assertEquals('name1', $this->form->getName()); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @covers Koch\Form\Form::setAcceptCharset() |
265
|
|
|
* @covers Koch\Form\Form::getAcceptCharset() |
266
|
|
|
*/ |
267
|
|
|
public function testGetAcceptCharset() |
268
|
|
|
{ |
269
|
|
|
// via getter - returns default value utf-8 as string |
270
|
|
|
$this->assertEquals('utf-8', $this->form->getAcceptCharset()); |
271
|
|
|
|
272
|
|
|
$this->form->setAcceptCharset('iso-8859-1'); |
273
|
|
|
|
274
|
|
|
// via getter - returns string |
275
|
|
|
$this->assertEquals('iso-8859-1', $this->form->getAcceptCharset()); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @covers Koch\Form\Form::setClass() |
280
|
|
|
* @covers Koch\Form\Form::getClass() |
281
|
|
|
*/ |
282
|
|
|
public function testSetClass() |
283
|
|
|
{ |
284
|
|
|
$this->form->setClass('cssclassname1'); |
285
|
|
|
|
286
|
|
|
// via getter - returns string |
287
|
|
|
$this->assertEquals('cssclassname1', $this->form->getClass()); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @covers Koch\Form\Form::setDescription() |
292
|
|
|
* @covers Koch\Form\Form::getDescription() |
293
|
|
|
*/ |
294
|
|
|
public function testSetDescription() |
295
|
|
|
{ |
296
|
|
|
$this->form->setDescription('description1'); |
297
|
|
|
|
298
|
|
|
// via getter - returns string |
299
|
|
|
$this->assertEquals('description1', $this->form->getDescription()); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @covers Koch\Form\Form::setHeading() |
304
|
|
|
* @covers Koch\Form\Form::getHeading() |
305
|
|
|
*/ |
306
|
|
|
public function testSetHeading() |
307
|
|
|
{ |
308
|
|
|
$this->form->setHeading('heading2'); |
309
|
|
|
|
310
|
|
|
// via getter - returns string |
311
|
|
|
$this->assertEquals('heading2', $this->form->getHeading()); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @covers Koch\Form\Form::setEncoding() |
316
|
|
|
* @covers Koch\Form\Form::getEncoding() |
317
|
|
|
*/ |
318
|
|
|
public function testGetEncoding() |
319
|
|
|
{ |
320
|
|
|
// via getter - returns default value as string |
321
|
|
|
$this->assertEquals('multipart/form-data', $this->form->getEncoding()); |
322
|
|
|
|
323
|
|
|
$this->form->setEncoding('text/plain'); |
324
|
|
|
|
325
|
|
|
// via getter - returns string |
326
|
|
|
$this->assertEquals('text/plain', $this->form->getEncoding()); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @covers Koch\Form\Form::setLegend() |
331
|
|
|
* @covers Koch\Form\Form::getLegend() |
332
|
|
|
*/ |
333
|
|
|
public function testSetLegend() |
334
|
|
|
{ |
335
|
|
|
$this->form->setLegend('legend-set'); |
336
|
|
|
|
337
|
|
|
// via getter - returns string |
338
|
|
|
$this->assertEquals('legend-set', $this->form->getLegend()); |
339
|
|
|
|
340
|
|
|
// allows method chaining |
341
|
|
|
$this->assertEquals($this->form, $this->form->setLegend('returns form object')); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
public function testSetLegend_allowsMethodChaining() |
|
|
|
|
345
|
|
|
{ |
346
|
|
|
$return_value = $this->form->setLegend('returns form object'); |
|
|
|
|
347
|
|
|
|
348
|
|
|
$this->assertSame($this->form, $return_value); |
|
|
|
|
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* @covers Koch\Form\Form::setFormelements() |
353
|
|
|
* @covers Koch\Form\Form::getFormelements() |
354
|
|
|
*/ |
355
|
|
|
public function testSetFormelements() |
356
|
|
|
{ |
357
|
|
|
// via getter - returns inital empty array |
358
|
|
|
$this->assertEquals([], $this->form->getFormelements()); |
359
|
|
|
|
360
|
|
|
$formelements = ['formelements']; |
361
|
|
|
$this->form->setFormelements($formelements); |
362
|
|
|
$this->assertEquals($formelements, $this->form->getFormelements()); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
public function testFormHasErrors() |
366
|
|
|
{ |
367
|
|
|
$this->assertFalse($this->form->FormHasErrors()); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
public function testregisterDefaultFormelementDecorators() |
371
|
|
|
{ |
372
|
|
|
$this->form->addElement('Textarea'); |
373
|
|
|
$formelements = $this->form->getFormelements(); |
374
|
|
|
$textarea_formelement = $formelements['0']; |
|
|
|
|
375
|
|
|
|
376
|
|
|
$this->form->registerDefaultFormelementDecorators($textarea_formelement); |
|
|
|
|
377
|
|
|
|
378
|
|
|
$formelement_decorators = $textarea_formelement->getDecorators(); |
|
|
|
|
379
|
|
|
|
380
|
|
|
$this->assertFalse(empty($formelement_decorators)); |
|
|
|
|
381
|
|
|
$this->assertTrue(is_object($formelement_decorators['label'])); |
|
|
|
|
382
|
|
|
$this->assertTrue(is_object($formelement_decorators['description'])); |
|
|
|
|
383
|
|
|
$this->assertTrue(is_object($formelement_decorators['div'])); |
|
|
|
|
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
public function testRenderAllFormelements() |
387
|
|
|
{ |
388
|
|
|
$this->form->addElement('Textarea'); |
389
|
|
|
|
390
|
|
|
$formelements_html_expected = CR . '<div class="formline"><textarea id="textarea-formelement-0"></textarea></div>' . CR; |
|
|
|
|
391
|
|
|
|
392
|
|
|
$formelements_html = $this->form->renderAllFormelements(); |
|
|
|
|
393
|
|
|
$this->assertFalse(empty($formelements_html)); |
|
|
|
|
394
|
|
|
$this->assertEquals($formelements_html, $formelements_html_expected); |
|
|
|
|
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @expectedException Koch\Exception\Exception |
399
|
|
|
* @expectedExceptionMessage Error rendering formelements. No formelements on form object. Consider adding some formelements using addElement(). |
400
|
|
|
*/ |
401
|
|
|
public function testRenderAllFormelementsThrowsException() |
402
|
|
|
{ |
403
|
|
|
$this->form->renderAllFormelements(); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
public function testuseDefaultFormDecoratorsDisableViaConstructor() |
407
|
|
|
{ |
408
|
|
|
$form = new Form(['useDefaultFormDecorators' => true]); |
409
|
|
|
$decorators = $form->getDecorators(); |
410
|
|
|
$this->assertEquals([], $decorators); |
411
|
|
|
unset($form); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
View Code Duplication |
public function testuseDefaultFormDecoratorsMethodTrue() |
|
|
|
|
415
|
|
|
{ |
416
|
|
|
$this->form->useDefaultFormDecorators(true); |
417
|
|
|
|
418
|
|
|
$this->form->registerDefaultFormDecorators(); |
419
|
|
|
$default_form_decorators = $this->form->getDecorators(); |
|
|
|
|
420
|
|
|
$this->assertFalse(empty($default_form_decorators)); |
|
|
|
|
421
|
|
|
$this->assertTrue(is_object($default_form_decorators['form'])); |
|
|
|
|
422
|
|
|
$this->assertTrue(is_a($default_form_decorators['form'], 'Koch\Form\AbstractFormDecorator')); |
|
|
|
|
423
|
|
|
} |
424
|
|
|
|
425
|
|
View Code Duplication |
public function testregisterDefaultFormDecorators() |
|
|
|
|
426
|
|
|
{ |
427
|
|
|
$this->form->registerDefaultFormDecorators(); |
428
|
|
|
$default_form_decorators = $this->form->getDecorators(); |
|
|
|
|
429
|
|
|
$this->assertFalse(empty($default_form_decorators)); |
|
|
|
|
430
|
|
|
$this->assertTrue(is_object($default_form_decorators['form'])); |
|
|
|
|
431
|
|
|
$this->assertTrue(is_a($default_form_decorators['form'], 'Koch\Form\AbstractFormDecorator')); |
|
|
|
|
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
public function testremoveDecorator() |
435
|
|
|
{ |
436
|
|
|
$this->form->registerDefaultFormDecorators(); |
437
|
|
|
$this->form->removeDecorator('form'); |
438
|
|
|
$default_form_decorators = $this->form->getDecorators(); |
|
|
|
|
439
|
|
|
$this->assertFalse(array_key_exists('form', $default_form_decorators)); |
|
|
|
|
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
public function testgetDecorator() |
443
|
|
|
{ |
444
|
|
|
$this->form->registerDefaultFormDecorators(); |
445
|
|
|
$default_form_decorators = $this->form->getDecorators(); |
|
|
|
|
446
|
|
|
$this->assertTrue(array_key_exists('form', $default_form_decorators)); |
|
|
|
|
447
|
|
|
$this->assertInstanceOf('Koch\Form\Decorators\Form\Form', $this->form->getDecorator('form')); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/* |
451
|
|
|
* expectedException InvalidArgumentException |
452
|
|
|
* expectedExceptionMessage The Form does not have a Decorator called "not-existing-formdecorator". |
453
|
|
|
*/ |
454
|
|
|
|
455
|
|
|
public function testgetDecoratorNotFoundException() |
456
|
|
|
{ |
457
|
|
|
$this->setExpectedException('InvalidArgumentException'); |
458
|
|
|
$this->form->getDecorator('not-existing-formdecorator'); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
View Code Duplication |
public function testRender() |
|
|
|
|
462
|
|
|
{ |
463
|
|
|
$this->form->addElement('Textarea'); |
464
|
|
|
|
465
|
|
|
$html = $this->form->render(); |
466
|
|
|
$this->assertFalse(empty($html)); |
467
|
|
|
$this->assertContains('<form', $html); |
468
|
|
|
$this->assertContains('<textarea id="textarea-formelement-0">', $html); |
469
|
|
|
$this->assertContains('</form>', $html); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
public function testRenderWithDecorator() |
473
|
|
|
{ |
474
|
|
|
$this->form->addElement('Textarea'); |
475
|
|
|
$this->form->addErrorMessage('Doh! This is an error message. Doh!'); |
476
|
|
|
$this->form->addDecorator('Errors'); |
|
|
|
|
477
|
|
|
|
478
|
|
|
$html = $this->form->render(); |
479
|
|
|
|
480
|
|
|
$this->assertFalse(empty($html)); |
481
|
|
|
|
482
|
|
|
// content from decorator |
483
|
|
|
$this->assertContains('<ul id="form-errors">', $html); |
484
|
|
|
$this->assertContains('<li>Doh! This is an error message. Doh!</li>', $html); |
485
|
|
|
$this->assertContains('</ul>', $html); |
486
|
|
|
|
487
|
|
|
// normal form tag |
488
|
|
|
$this->assertContains('<!-- Start of Form "TestForm" -->', $html); |
489
|
|
|
$this->assertContains('<form', $html); |
490
|
|
|
$this->assertContains('<textarea id="textarea-formelement-0">', $html); |
491
|
|
|
$this->assertContains('</form>', $html); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
View Code Duplication |
public function testRenderViaToString() |
|
|
|
|
495
|
|
|
{ |
496
|
|
|
$this->form->addElement('Textarea'); |
497
|
|
|
|
498
|
|
|
$html = $this->form->__toString(); |
499
|
|
|
|
500
|
|
|
$this->assertFalse(empty($html)); |
501
|
|
|
$this->assertContains('<form', $html); |
502
|
|
|
$this->assertContains('<textarea id="textarea-formelement-0">', $html); |
503
|
|
|
$this->assertContains('</form>', $html); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
public function testAddElement() |
507
|
|
|
{ |
508
|
|
|
$this->form->addElement('Text'); |
509
|
|
|
// $this->form->getElementByPosition('0'); |
|
|
|
|
510
|
|
|
$formelements_array = $this->form->getFormelements(); |
|
|
|
|
511
|
|
|
|
512
|
|
|
$formelement = new \Koch\Form\Elements\Text(); |
513
|
|
|
$formelement->setID('text-formelement-0'); |
514
|
|
|
|
515
|
|
|
$this->assertEquals($formelement, $formelements_array[0]); |
|
|
|
|
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
public function testAddElementAddingFileElementSetsEncoding() |
519
|
|
|
{ |
520
|
|
|
$this->form->addElement('file'); |
521
|
|
|
$this->assertEquals('multipart/form-data', $this->form->getEncoding()); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
public function testAddElement_toSpecificPositions() |
|
|
|
|
525
|
|
|
{ |
526
|
|
|
$this->form->addElement('textarea', [], 'Position1'); |
527
|
|
|
$this->form->addElement('checkbox', [], 'Position2'); |
528
|
|
|
$this->form->addElement('submitbutton', [], 'Position3'); |
529
|
|
|
|
530
|
|
|
$formelements = $this->form->getFormelements(); |
531
|
|
|
$this->assertArrayHasKey('Position1', $formelements); |
532
|
|
|
$this->assertArrayHasKey('Position2', $formelements); |
533
|
|
|
$this->assertArrayHasKey('Position3', $formelements); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
public function testAddElementWithMultipleElements() |
537
|
|
|
{ |
538
|
|
|
$formelements = []; |
539
|
|
|
$formelements[] = $this->form->addElement('ButtonBar'); |
540
|
|
|
$formelements[] = $this->form->addElement('Textarea'); |
541
|
|
|
$formelements[] = $this->form->addElement('Checkbox'); |
542
|
|
|
|
543
|
|
|
$formelements_from_testobject = $this->form->getFormelements(); |
|
|
|
|
544
|
|
|
|
545
|
|
|
$this->assertNotEmpty($formelements_from_testobject); |
|
|
|
|
546
|
|
|
$this->assertSame($formelements, $this->form->getFormelements()); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
public function testAddElementWithSettingAttributes() |
550
|
|
|
{ |
551
|
|
|
// test element |
552
|
|
|
$attributes = [ |
553
|
|
|
'class' => 'myFormelementClass', |
554
|
|
|
'maxlength' => '20', |
555
|
|
|
'label' => 'myFormelementLabel', |
556
|
|
|
'id' => 'text-formelement-0', |
557
|
|
|
]; |
558
|
|
|
|
559
|
|
|
$this->form->addElement('Text', $attributes); |
560
|
|
|
$formelement = $this->form->getElementByPosition('0'); |
561
|
|
|
|
562
|
|
|
$this->assertEquals($attributes['class'], $formelement->class); |
563
|
|
|
$this->assertEquals($attributes['maxlength'], $formelement->maxlength); |
564
|
|
|
$this->assertEquals($attributes['label'], $formelement->label); |
565
|
|
|
$this->assertEquals($attributes['id'], $formelement->id); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
View Code Duplication |
public function testAddElementToCertainPosition() |
|
|
|
|
569
|
|
|
{ |
570
|
|
|
// PREPARE: |
571
|
|
|
// this will take position 0 |
572
|
|
|
$this->form->addElement('File'); |
573
|
|
|
// this will take position 1 |
574
|
|
|
$this->form->addElement('Captcha'); |
575
|
|
|
|
576
|
|
|
// TEST: |
577
|
|
|
// this will take position 0 + reorders the array |
578
|
|
|
$this->form->addElement('Text', null, 0); |
579
|
|
|
|
580
|
|
|
$array = []; |
581
|
|
|
$array[] = new Elements\Text(); // 0 - Text |
582
|
|
|
$array[] = new Elements\File(); // 1 - File |
583
|
|
|
$array[] = new Elements\Captcha(); // 2 - Captcha |
584
|
|
|
// manually reapply formelement identifiers |
585
|
|
|
$array['0']->setID('text-formelement-0'); |
586
|
|
|
$array['1']->setID('file-formelement-1'); |
587
|
|
|
$array['2']->setID('captcha-formelement-2'); |
588
|
|
|
|
589
|
|
|
$this->assertEquals($array, $this->form->getFormelements()); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
public function testAddElementSwitchEncodingWhenUsingFormelementFile() |
593
|
|
|
{ |
594
|
|
|
$this->form->addElement('File'); |
595
|
|
|
|
596
|
|
|
$this->assertContains('enctype="multipart/form-data"', $this->form->render()); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
View Code Duplication |
public function testregenerateFormelementIdentifiers() |
|
|
|
|
600
|
|
|
{ |
601
|
|
|
// PREPARE: |
602
|
|
|
// this will take position 0 |
603
|
|
|
$this->form->addElement('File'); |
604
|
|
|
// this will take position 1 |
605
|
|
|
$this->form->addElement('Captcha'); |
606
|
|
|
|
607
|
|
|
// TEST: |
608
|
|
|
// this will take position 0 and reorder the array |
609
|
|
|
$this->form->addElement('Text', null, 0); |
610
|
|
|
|
611
|
|
|
$array = []; |
612
|
|
|
$array[] = new \Koch\Form\Elements\Text(); // 0 - Text |
613
|
|
|
$array[] = new \Koch\Form\Elements\File(); // 1 - File |
614
|
|
|
$array[] = new \Koch\Form\Elements\Captcha(); // 2 - Captcha |
615
|
|
|
// manually reapply formelement identifiers |
616
|
|
|
$array['0']->setID('text-formelement-0'); |
617
|
|
|
$array['1']->setID('file-formelement-1'); |
618
|
|
|
$array['2']->setID('captcha-formelement-2'); |
619
|
|
|
|
620
|
|
|
$this->assertEquals($array, $this->form->getFormelements()); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
public function testDelElementByName() |
624
|
|
|
{ |
625
|
|
|
$this->form->addElement('Textarea')->setName('myTextareaElement'); |
626
|
|
|
$this->form->delElementByName('myTextareaElement'); |
627
|
|
|
|
628
|
|
|
$this->assertNull($this->form->getElementByName('myTextareaElement')); |
629
|
|
|
|
630
|
|
|
// delete of non existing element returns false |
631
|
|
|
$this->assertFalse($this->form->delElementByName('a-not-existing-formelement')); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
public function testGetElementByPosition() |
635
|
|
|
{ |
636
|
|
|
$this->form->addElement('Text'); |
637
|
|
|
|
638
|
|
|
$formelements_array = $this->form->getFormelements(); |
|
|
|
|
639
|
|
|
|
640
|
|
|
$this->assertSame($formelements_array['0'], $this->form->getElementByPosition(0)); |
|
|
|
|
641
|
|
|
|
642
|
|
|
// not existing position returns null |
643
|
|
|
$this->assertNull($this->form->getElementByPosition(1)); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
public function testGetElementByName() |
647
|
|
|
{ |
648
|
|
|
$this->form->addElement('Button')->setName('myButton1'); |
649
|
|
|
|
650
|
|
|
$formelement_object = $this->form->getElementByName('myButton1'); |
|
|
|
|
651
|
|
|
$this->assertSame('myButton1', $formelement_object->getName()); |
|
|
|
|
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
public function testGetElement_ByNameOrByPositionOrLastElement() |
|
|
|
|
655
|
|
|
{ |
656
|
|
|
$this->form->addElement('Button')->setName('myButton1'); |
657
|
|
|
|
658
|
|
|
// ByName |
659
|
|
|
$formelement_object = $this->form->getElement('myButton1'); |
|
|
|
|
660
|
|
|
$this->assertSame('myButton1', $formelement_object->getName()); |
|
|
|
|
661
|
|
|
|
662
|
|
|
// ByPosition |
663
|
|
|
$formelement_object = $this->form->getElement('0'); |
|
|
|
|
664
|
|
|
$this->assertSame('myButton1', $formelement_object->getName()); |
|
|
|
|
665
|
|
|
|
666
|
|
|
// Default Value null as param |
667
|
|
|
$formelement_object = $this->form->getElement(); |
|
|
|
|
668
|
|
|
$this->assertSame('myButton1', $formelement_object->getName()); |
|
|
|
|
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
public function testFormelementFactory() |
672
|
|
|
{ |
673
|
|
|
$formelement_object = $this->form->formelementFactory('Url'); |
|
|
|
|
674
|
|
|
|
675
|
|
|
$this->assertInstanceof('\Koch\Form\Elements\Url', $formelement_object); |
|
|
|
|
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
public function testMethodprocessForm() |
679
|
|
|
{ |
680
|
|
|
$this->form->addElement('Textarea')->setRules('maxvalue=120')->setValue(123); |
681
|
|
|
|
682
|
|
|
$this->form->processForm(); |
683
|
|
|
|
684
|
|
|
$html = $this->form->render(); |
685
|
|
|
|
686
|
|
|
$this->assertContains('error', $html); |
687
|
|
|
$this->assertContains('<form', $html); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
public function testMethodprocessForm_withIncommingData() |
|
|
|
|
691
|
|
|
{ |
692
|
|
|
$this->form->addElement('Textarea')->setValue(123)->setRules('string'); |
693
|
|
|
|
694
|
|
|
// two options were selected (array is incomming via post) |
695
|
|
|
$data = ['textarea-formelement-0' => 'Lore ipsum...']; |
696
|
|
|
$this->form->setValues($data); |
697
|
|
|
|
698
|
|
|
$html = $this->form->render(); |
699
|
|
|
|
700
|
|
|
$this->assertContains('<form', $html); |
701
|
|
|
$this->assertContains('</form>', $html); |
702
|
|
|
$this->assertContains('<textarea', $html); |
703
|
|
|
$this->assertContains('Lore ipsum...', $html); |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
public function testsetValuesDataArrayPassedToMethod() |
707
|
|
|
{ |
708
|
|
|
// create multiselect "Snacks" with three options |
709
|
|
|
$this->form->addElement('MultiSelect')->setName('Snacks')->setOptions( |
710
|
|
|
['cola' => 'Cola', 'popcorn' => 'Popcorn', 'peanuts' => 'Peanuts'] |
711
|
|
|
); |
712
|
|
|
|
713
|
|
|
// two options were selected (array is incomming via post) |
714
|
|
|
$data = ['snacks' => ['cola', 'popcorn']]; |
715
|
|
|
|
716
|
|
|
$this->form->setValues($data); |
717
|
|
|
|
718
|
|
|
$snacks_array = $this->form->getElementByName('Snacks')->getValue(); |
|
|
|
|
719
|
|
|
$this->assertSame(count($snacks_array), 2); |
|
|
|
|
720
|
|
|
$this->assertSame($snacks_array[0], 'cola'); |
|
|
|
|
721
|
|
|
$this->assertSame($snacks_array[1], 'popcorn'); |
|
|
|
|
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
public function testgetValues() |
725
|
|
|
{ |
726
|
|
|
$this->form->addElement('Textarea', ['value' => 'Some Text Inside The First Textarea']); |
727
|
|
|
$this->form->addElement('Textarea', ['value' => 'More Text Inside The Second Textarea']); |
728
|
|
|
|
729
|
|
|
$values = $this->form->getValues(); |
730
|
|
|
|
731
|
|
|
$this->assertTrue(is_array($values)); |
732
|
|
|
$this->assertSame(count($values), 2); |
733
|
|
|
|
734
|
|
|
$expected_values = [ |
|
|
|
|
735
|
|
|
'textarea-formelement-0' => 'Some Text Inside The First Textarea', |
736
|
|
|
'textarea-formelement-1' => 'More Text Inside The Second Textarea', |
737
|
|
|
]; |
738
|
|
|
|
739
|
|
|
$this->assertSame($values, $expected_values); |
|
|
|
|
740
|
|
|
} |
741
|
|
|
|
742
|
|
View Code Duplication |
public function testSetFormelementDecoratorFormelementPositionNull() |
|
|
|
|
743
|
|
|
{ |
744
|
|
|
$this->form->addElement('Textarea'); |
745
|
|
|
$this->form->setFormelementDecorator('label', null); |
746
|
|
|
|
747
|
|
|
$formelements = $this->form->getFormelements(); |
748
|
|
|
$textarea_element = $formelements[0]; |
|
|
|
|
749
|
|
|
$decorators = $textarea_element->formelementdecorators; |
|
|
|
|
750
|
|
|
|
751
|
|
|
$this->assertTrue(is_array($decorators)); |
752
|
|
|
$this->assertEquals(1, count($decorators)); |
753
|
|
|
$this->assertTrue(isset($decorators['label'])); |
754
|
|
|
} |
755
|
|
|
|
756
|
|
View Code Duplication |
public function testAddFormelementDecorator() |
|
|
|
|
757
|
|
|
{ |
758
|
|
|
$this->form->addElement('Textarea'); |
759
|
|
|
$this->form->addElement('MultiSelect'); |
760
|
|
|
$this->form->addFormelementDecorator('label', 1); |
761
|
|
|
|
762
|
|
|
$formelements = $this->form->getFormelements(); |
763
|
|
|
$textarea_element = $formelements[1]; |
|
|
|
|
764
|
|
|
$decorators = $textarea_element->formelementdecorators; |
|
|
|
|
765
|
|
|
|
766
|
|
|
$this->assertTrue(is_array($decorators)); |
767
|
|
|
$this->assertEquals(1, count($decorators)); |
768
|
|
|
$this->assertTrue(isset($decorators['label'])); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* @expectedException RuntimeException |
773
|
|
|
* @expectedExceptionMessage No Formelements found. Add the formelement(s) first, then decorate! |
774
|
|
|
*/ |
775
|
|
|
public function testAddFormelementDecorator_ThrowsExceptionWhenNoFormelementsFound() |
|
|
|
|
776
|
|
|
{ |
777
|
|
|
$this->form->addFormelementDecorator('label', 1); |
778
|
|
|
} |
779
|
|
|
|
780
|
|
View Code Duplication |
public function testRemoveFormelementDecorator() |
|
|
|
|
781
|
|
|
{ |
782
|
|
|
$this->form->addElement('Textarea'); |
783
|
|
|
$this->form->addFormelementDecorator('label', 0); |
784
|
|
|
|
785
|
|
|
$this->form->removeFormelementDecorator('label'); |
786
|
|
|
|
787
|
|
|
$formelements = $this->form->getFormelements(); |
788
|
|
|
$textarea_element = $formelements[0]; |
|
|
|
|
789
|
|
|
$decorators = $textarea_element->formelementdecorators; |
|
|
|
|
790
|
|
|
|
791
|
|
|
$this->assertTrue(is_array($decorators)); |
792
|
|
|
$this->assertEquals(0, count($decorators)); |
793
|
|
|
$this->assertFalse(isset($decorators['label'])); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
View Code Duplication |
public function testSetDecorator() |
|
|
|
|
797
|
|
|
{ |
798
|
|
|
$this->form->setDecorator('label'); |
799
|
|
|
|
800
|
|
|
$decorators = $this->form->getDecorators(); |
801
|
|
|
|
802
|
|
|
$this->assertTrue(is_array($decorators)); |
803
|
|
|
$this->assertEquals(1, count($decorators)); |
804
|
|
|
$this->assertTrue(isset($decorators['label'])); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
View Code Duplication |
public function testAddDecorator() |
|
|
|
|
808
|
|
|
{ |
809
|
|
|
$this->form->addDecorator('label'); |
|
|
|
|
810
|
|
|
|
811
|
|
|
$decorators = $this->form->getDecorators(); |
812
|
|
|
|
813
|
|
|
$this->assertTrue(is_array($decorators)); |
814
|
|
|
$this->assertEquals(1, count($decorators)); |
815
|
|
|
$this->assertTrue(isset($decorators['label'])); |
816
|
|
|
} |
817
|
|
|
|
818
|
|
View Code Duplication |
public function testGetDecorators() |
|
|
|
|
819
|
|
|
{ |
820
|
|
|
$this->form->setDecorator('label'); |
821
|
|
|
$decorators = $this->form->getDecorators(); |
822
|
|
|
|
823
|
|
|
$this->assertTrue(is_array($decorators)); |
824
|
|
|
$this->assertEquals(1, count($decorators)); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
public function testDecoratorFactory() |
828
|
|
|
{ |
829
|
|
|
$form_decorator_object = $this->form->DecoratorFactory('label'); |
|
|
|
|
830
|
|
|
|
831
|
|
|
$this->assertInstanceOf('Koch\Form\Decorators\Form\Label', $form_decorator_object); |
|
|
|
|
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* @covers Koch\Form\Form::setDecoratorAttributesArray() |
836
|
|
|
* @covers Koch\Form\Form::getDecoratorAttributesArray() |
837
|
|
|
*/ |
838
|
|
|
public function testsetDecoratorAttributesArray() |
839
|
|
|
{ |
840
|
|
|
$attributes = ['attribute1' => 'value1']; |
841
|
|
|
$this->form->setDecoratorAttributesArray($attributes); |
842
|
|
|
|
843
|
|
|
$this->assertSame($attributes, $this->form->getDecoratorAttributesArray()); |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
public function testapplyDecoratorAttributes() |
847
|
|
|
{ |
848
|
|
|
// decorator type will be form |
849
|
|
|
// this is just another way of setting attributes to the form itself |
850
|
|
|
$attributes = ['form' => ['form' => // this is Koch\Form\Decorator\Form |
851
|
|
|
['heading' => 'This is the Heading of the form.', |
852
|
|
|
'description' => 'This is a form description text.', ], |
853
|
|
|
]]; |
854
|
|
|
|
855
|
|
|
$this->form->setDecoratorAttributesArray($attributes); |
856
|
|
|
|
857
|
|
|
$this->form->registerDefaultFormDecorators(); |
858
|
|
|
|
859
|
|
|
$this->form->applyDecoratorAttributes(); |
860
|
|
|
|
861
|
|
|
$form_decorator_form = $this->form->getDecorator('form'); |
|
|
|
|
862
|
|
|
|
863
|
|
|
$this->assertSame('This is the Heading of the form.', $form_decorator_form->heading); |
|
|
|
|
864
|
|
|
$this->assertSame('This is a form description text.', $form_decorator_form->description); |
|
|
|
|
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
public function testAddValidator() |
868
|
|
|
{ |
869
|
|
|
$this->form->addElement('Textarea')->addValidator('required'); |
870
|
|
|
|
871
|
|
|
$this->assertInstanceOf('Koch\Form\Validators\Required', $this->form->getElement()->validators[0]); |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
public function testValidateFormFalse() |
875
|
|
|
{ |
876
|
|
|
$this->form->addElement('Textarea') |
877
|
|
|
->setName('Textarea-testValidateForm-false') |
878
|
|
|
->setRequired() |
879
|
|
|
->setRules('required, string, maxlength=20'); |
880
|
|
|
// ->setValue() is missing intentionally |
881
|
|
|
// no value set, but required |
882
|
|
|
$this->assertFalse($this->form->validateForm()); |
883
|
|
|
|
884
|
|
|
// set a value, exceeding maxlength |
885
|
|
|
$element = $this->form->getElementByName('Textarea-testValidateForm-false'); |
886
|
|
|
$element->setValue('0123456789-0123456789'); // 21 chars |
887
|
|
|
// max length exceeded |
888
|
|
|
$this->assertFalse($this->form->validateForm()); |
889
|
|
|
} |
890
|
|
|
|
891
|
|
View Code Duplication |
public function testValidateForm_true() |
|
|
|
|
892
|
|
|
{ |
893
|
|
|
$this->form->addElement('Textarea') |
894
|
|
|
->setName('Textarea-testValidateForm-true') |
895
|
|
|
->setRequired() |
896
|
|
|
->setRules('required, string, maxlength=20'); |
897
|
|
|
|
898
|
|
|
// set value, length ok |
899
|
|
|
$element = $this->form->getElementByName('Textarea-testValidateForm-true'); |
900
|
|
|
$element->setValue('01234567890123456789'); // 20 chars |
901
|
|
|
|
902
|
|
|
$this->assertTrue($this->form->validateForm()); |
903
|
|
|
} |
904
|
|
|
|
905
|
|
View Code Duplication |
public function testsetRequired() |
|
|
|
|
906
|
|
|
{ |
907
|
|
|
$this->form->addElement('Textarea')->setName('Textarea-A')->setRequired(); |
908
|
|
|
|
909
|
|
|
$formelement = $this->form->getElementByName('Textarea-A'); |
910
|
|
|
$this->assertTrue($formelement->required); |
911
|
|
|
$this->assertTrue($formelement->isRequired()); |
912
|
|
|
} |
913
|
|
|
|
914
|
|
View Code Duplication |
public function testIsRequired() |
|
|
|
|
915
|
|
|
{ |
916
|
|
|
$this->form->addElement('Textarea')->setName('Textarea-A')->setRequired(); |
917
|
|
|
$formelement = $this->form->getElementByName('Textarea-A'); |
918
|
|
|
$this->assertTrue($formelement->required); |
919
|
|
|
$this->assertTrue($formelement->isRequired()); |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
public function testhasErrors() |
923
|
|
|
{ |
924
|
|
|
$this->form->hasErrors(true); |
925
|
|
|
$this->assertTrue($this->form->error); |
|
|
|
|
926
|
|
|
$this->assertTrue($this->form->hasErrors()); |
927
|
|
|
|
928
|
|
|
$this->form->hasErrors(false); |
929
|
|
|
$this->assertFalse($this->form->error); |
|
|
|
|
930
|
|
|
$this->assertFalse($this->form->hasErrors()); |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
public function testaddErrorMessage() |
934
|
|
|
{ |
935
|
|
|
$message = 'message text'; |
936
|
|
|
$this->form->addErrorMessage($message); |
937
|
|
|
$errormessages = $this->form->getErrorMessages(); |
938
|
|
|
$this->assertSame($message, $errormessages['0']); |
939
|
|
|
} |
940
|
|
|
|
941
|
|
|
public function testaddErrorMessages() |
942
|
|
|
{ |
943
|
|
|
$set1 = ['aaa', 'bbb', 'ccc']; |
944
|
|
|
$this->form->addErrorMessages($set1); |
945
|
|
|
$this->assertSame($set1, $this->form->getErrorMessages()); |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
public function testaddErrorMessagesOverwriteMessages() |
949
|
|
|
{ |
950
|
|
|
$set1 = ['aaa', 'bbb', 'ccc']; |
951
|
|
|
$set2 = ['ddd', 'eee']; |
952
|
|
|
$this->form->addErrorMessages($set1); |
953
|
|
|
$this->assertSame($set1, $this->form->getErrorMessages()); |
954
|
|
|
$this->form->addErrorMessages($set2); |
955
|
|
|
$this->assertSame($set2, $this->form->getErrorMessages()); |
956
|
|
|
} |
957
|
|
|
|
958
|
|
|
public function testresetErrorMessages() |
959
|
|
|
{ |
960
|
|
|
$set1 = ['aaa', 'bbb', 'ccc']; |
961
|
|
|
$this->form->addErrorMessages($set1); |
962
|
|
|
$this->form->resetErrorMessages(); |
963
|
|
|
$messages = $this->form->getErrorMessages(); |
964
|
|
|
$this->assertTrue(empty($messages)); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
public function testgetErrorMessages() |
968
|
|
|
{ |
969
|
|
|
$set1 = ['aaa', 'bbb', 'ccc']; |
970
|
|
|
$this->form->addErrorMessages($set1); |
971
|
|
|
$this->assertSame($set1, $this->form->getErrorMessages()); |
972
|
|
|
} |
973
|
|
|
|
974
|
|
|
public function testMagicSet() |
975
|
|
|
{ |
976
|
|
|
// this will call __set |
977
|
|
|
$this->form->method = 'methodname'; |
|
|
|
|
978
|
|
|
|
979
|
|
|
$this->assertEquals('methodname', $this->form->getMethod()); |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
public function testMagicGet() |
983
|
|
|
{ |
984
|
|
|
// this will call __set |
985
|
|
|
$this->form->method = 'methodname'; |
|
|
|
|
986
|
|
|
|
987
|
|
|
// this will call __get |
988
|
|
|
$this->assertEquals('methodname', $this->form->method); |
|
|
|
|
989
|
|
|
} |
990
|
|
|
} |
991
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.