diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php | 649 |
1 files changed, 649 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php new file mode 100644 index 00000000..9bdfe156 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php | |||
@@ -0,0 +1,649 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Tests\Extension\Core\Type; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Form\FormError; | ||
16 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
17 | |||
18 | class TimeTypeTest extends TypeTestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | IntlTestHelper::requireIntl($this); | ||
23 | |||
24 | parent::setUp(); | ||
25 | } | ||
26 | |||
27 | public function testSubmitDateTime() | ||
28 | { | ||
29 | $form = $this->factory->create('time', null, array( | ||
30 | 'model_timezone' => 'UTC', | ||
31 | 'view_timezone' => 'UTC', | ||
32 | 'input' => 'datetime', | ||
33 | )); | ||
34 | |||
35 | $input = array( | ||
36 | 'hour' => '3', | ||
37 | 'minute' => '4', | ||
38 | ); | ||
39 | |||
40 | $form->submit($input); | ||
41 | |||
42 | $dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); | ||
43 | |||
44 | $this->assertEquals($dateTime, $form->getData()); | ||
45 | $this->assertEquals($input, $form->getViewData()); | ||
46 | } | ||
47 | |||
48 | public function testSubmitString() | ||
49 | { | ||
50 | $form = $this->factory->create('time', null, array( | ||
51 | 'model_timezone' => 'UTC', | ||
52 | 'view_timezone' => 'UTC', | ||
53 | 'input' => 'string', | ||
54 | )); | ||
55 | |||
56 | $input = array( | ||
57 | 'hour' => '3', | ||
58 | 'minute' => '4', | ||
59 | ); | ||
60 | |||
61 | $form->submit($input); | ||
62 | |||
63 | $this->assertEquals('03:04:00', $form->getData()); | ||
64 | $this->assertEquals($input, $form->getViewData()); | ||
65 | } | ||
66 | |||
67 | public function testSubmitTimestamp() | ||
68 | { | ||
69 | $form = $this->factory->create('time', null, array( | ||
70 | 'model_timezone' => 'UTC', | ||
71 | 'view_timezone' => 'UTC', | ||
72 | 'input' => 'timestamp', | ||
73 | )); | ||
74 | |||
75 | $input = array( | ||
76 | 'hour' => '3', | ||
77 | 'minute' => '4', | ||
78 | ); | ||
79 | |||
80 | $form->submit($input); | ||
81 | |||
82 | $dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); | ||
83 | |||
84 | $this->assertEquals($dateTime->format('U'), $form->getData()); | ||
85 | $this->assertEquals($input, $form->getViewData()); | ||
86 | } | ||
87 | |||
88 | public function testSubmitArray() | ||
89 | { | ||
90 | $form = $this->factory->create('time', null, array( | ||
91 | 'model_timezone' => 'UTC', | ||
92 | 'view_timezone' => 'UTC', | ||
93 | 'input' => 'array', | ||
94 | )); | ||
95 | |||
96 | $input = array( | ||
97 | 'hour' => '3', | ||
98 | 'minute' => '4', | ||
99 | ); | ||
100 | |||
101 | $form->submit($input); | ||
102 | |||
103 | $this->assertEquals($input, $form->getData()); | ||
104 | $this->assertEquals($input, $form->getViewData()); | ||
105 | } | ||
106 | |||
107 | public function testSubmitDatetimeSingleText() | ||
108 | { | ||
109 | $form = $this->factory->create('time', null, array( | ||
110 | 'model_timezone' => 'UTC', | ||
111 | 'view_timezone' => 'UTC', | ||
112 | 'input' => 'datetime', | ||
113 | 'widget' => 'single_text', | ||
114 | )); | ||
115 | |||
116 | $form->submit('03:04'); | ||
117 | |||
118 | $this->assertEquals(new \DateTime('1970-01-01 03:04:00 UTC'), $form->getData()); | ||
119 | $this->assertEquals('03:04', $form->getViewData()); | ||
120 | } | ||
121 | |||
122 | public function testSubmitDatetimeSingleTextWithoutMinutes() | ||
123 | { | ||
124 | $form = $this->factory->create('time', null, array( | ||
125 | 'model_timezone' => 'UTC', | ||
126 | 'view_timezone' => 'UTC', | ||
127 | 'input' => 'datetime', | ||
128 | 'widget' => 'single_text', | ||
129 | 'with_minutes' => false, | ||
130 | )); | ||
131 | |||
132 | $form->submit('03'); | ||
133 | |||
134 | $this->assertEquals(new \DateTime('1970-01-01 03:00:00 UTC'), $form->getData()); | ||
135 | $this->assertEquals('03', $form->getViewData()); | ||
136 | } | ||
137 | |||
138 | public function testSubmitArraySingleText() | ||
139 | { | ||
140 | $form = $this->factory->create('time', null, array( | ||
141 | 'model_timezone' => 'UTC', | ||
142 | 'view_timezone' => 'UTC', | ||
143 | 'input' => 'array', | ||
144 | 'widget' => 'single_text', | ||
145 | )); | ||
146 | |||
147 | $data = array( | ||
148 | 'hour' => '3', | ||
149 | 'minute' => '4', | ||
150 | ); | ||
151 | |||
152 | $form->submit('03:04'); | ||
153 | |||
154 | $this->assertEquals($data, $form->getData()); | ||
155 | $this->assertEquals('03:04', $form->getViewData()); | ||
156 | } | ||
157 | |||
158 | public function testSubmitArraySingleTextWithoutMinutes() | ||
159 | { | ||
160 | $form = $this->factory->create('time', null, array( | ||
161 | 'model_timezone' => 'UTC', | ||
162 | 'view_timezone' => 'UTC', | ||
163 | 'input' => 'array', | ||
164 | 'widget' => 'single_text', | ||
165 | 'with_minutes' => false, | ||
166 | )); | ||
167 | |||
168 | $data = array( | ||
169 | 'hour' => '3', | ||
170 | ); | ||
171 | |||
172 | $form->submit('03'); | ||
173 | |||
174 | $this->assertEquals($data, $form->getData()); | ||
175 | $this->assertEquals('03', $form->getViewData()); | ||
176 | } | ||
177 | |||
178 | public function testSubmitArraySingleTextWithSeconds() | ||
179 | { | ||
180 | $form = $this->factory->create('time', null, array( | ||
181 | 'model_timezone' => 'UTC', | ||
182 | 'view_timezone' => 'UTC', | ||
183 | 'input' => 'array', | ||
184 | 'widget' => 'single_text', | ||
185 | 'with_seconds' => true, | ||
186 | )); | ||
187 | |||
188 | $data = array( | ||
189 | 'hour' => '3', | ||
190 | 'minute' => '4', | ||
191 | 'second' => '5', | ||
192 | ); | ||
193 | |||
194 | $form->submit('03:04:05'); | ||
195 | |||
196 | $this->assertEquals($data, $form->getData()); | ||
197 | $this->assertEquals('03:04:05', $form->getViewData()); | ||
198 | } | ||
199 | |||
200 | public function testSubmitStringSingleText() | ||
201 | { | ||
202 | $form = $this->factory->create('time', null, array( | ||
203 | 'model_timezone' => 'UTC', | ||
204 | 'view_timezone' => 'UTC', | ||
205 | 'input' => 'string', | ||
206 | 'widget' => 'single_text', | ||
207 | )); | ||
208 | |||
209 | $form->submit('03:04'); | ||
210 | |||
211 | $this->assertEquals('03:04:00', $form->getData()); | ||
212 | $this->assertEquals('03:04', $form->getViewData()); | ||
213 | } | ||
214 | |||
215 | public function testSubmitStringSingleTextWithoutMinutes() | ||
216 | { | ||
217 | $form = $this->factory->create('time', null, array( | ||
218 | 'model_timezone' => 'UTC', | ||
219 | 'view_timezone' => 'UTC', | ||
220 | 'input' => 'string', | ||
221 | 'widget' => 'single_text', | ||
222 | 'with_minutes' => false, | ||
223 | )); | ||
224 | |||
225 | $form->submit('03'); | ||
226 | |||
227 | $this->assertEquals('03:00:00', $form->getData()); | ||
228 | $this->assertEquals('03', $form->getViewData()); | ||
229 | } | ||
230 | |||
231 | public function testSetDataWithoutMinutes() | ||
232 | { | ||
233 | $form = $this->factory->create('time', null, array( | ||
234 | 'model_timezone' => 'UTC', | ||
235 | 'view_timezone' => 'UTC', | ||
236 | 'input' => 'datetime', | ||
237 | 'with_minutes' => false, | ||
238 | )); | ||
239 | |||
240 | $form->setData(new \DateTime('03:04:05 UTC')); | ||
241 | |||
242 | $this->assertEquals(array('hour' => 3), $form->getViewData()); | ||
243 | } | ||
244 | |||
245 | public function testSetDataWithSeconds() | ||
246 | { | ||
247 | $form = $this->factory->create('time', null, array( | ||
248 | 'model_timezone' => 'UTC', | ||
249 | 'view_timezone' => 'UTC', | ||
250 | 'input' => 'datetime', | ||
251 | 'with_seconds' => true, | ||
252 | )); | ||
253 | |||
254 | $form->setData(new \DateTime('03:04:05 UTC')); | ||
255 | |||
256 | $this->assertEquals(array('hour' => 3, 'minute' => 4, 'second' => 5), $form->getViewData()); | ||
257 | } | ||
258 | |||
259 | public function testSetDataDifferentTimezones() | ||
260 | { | ||
261 | $form = $this->factory->create('time', null, array( | ||
262 | 'model_timezone' => 'America/New_York', | ||
263 | 'view_timezone' => 'Asia/Hong_Kong', | ||
264 | 'input' => 'string', | ||
265 | 'with_seconds' => true, | ||
266 | )); | ||
267 | |||
268 | $dateTime = new \DateTime('2013-01-01 12:04:05'); | ||
269 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
270 | |||
271 | $form->setData($dateTime->format('H:i:s')); | ||
272 | |||
273 | $outputTime = clone $dateTime; | ||
274 | $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
275 | |||
276 | $displayedData = array( | ||
277 | 'hour' => (int) $outputTime->format('H'), | ||
278 | 'minute' => (int) $outputTime->format('i'), | ||
279 | 'second' => (int) $outputTime->format('s') | ||
280 | ); | ||
281 | |||
282 | $this->assertEquals($displayedData, $form->getViewData()); | ||
283 | } | ||
284 | |||
285 | public function testSetDataDifferentTimezonesDateTime() | ||
286 | { | ||
287 | $form = $this->factory->create('time', null, array( | ||
288 | 'model_timezone' => 'America/New_York', | ||
289 | 'view_timezone' => 'Asia/Hong_Kong', | ||
290 | 'input' => 'datetime', | ||
291 | 'with_seconds' => true, | ||
292 | )); | ||
293 | |||
294 | $dateTime = new \DateTime('12:04:05'); | ||
295 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
296 | |||
297 | $form->setData($dateTime); | ||
298 | |||
299 | $outputTime = clone $dateTime; | ||
300 | $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
301 | |||
302 | $displayedData = array( | ||
303 | 'hour' => (int) $outputTime->format('H'), | ||
304 | 'minute' => (int) $outputTime->format('i'), | ||
305 | 'second' => (int) $outputTime->format('s') | ||
306 | ); | ||
307 | |||
308 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
309 | $this->assertEquals($displayedData, $form->getViewData()); | ||
310 | } | ||
311 | |||
312 | public function testHoursOption() | ||
313 | { | ||
314 | $form = $this->factory->create('time', null, array( | ||
315 | 'hours' => array(6, 7), | ||
316 | )); | ||
317 | |||
318 | $view = $form->createView(); | ||
319 | |||
320 | $this->assertEquals(array( | ||
321 | new ChoiceView('6', '6', '06'), | ||
322 | new ChoiceView('7', '7', '07'), | ||
323 | ), $view['hour']->vars['choices']); | ||
324 | } | ||
325 | |||
326 | public function testIsMinuteWithinRangeReturnsTrueIfWithin() | ||
327 | { | ||
328 | $form = $this->factory->create('time', null, array( | ||
329 | 'minutes' => array(6, 7), | ||
330 | )); | ||
331 | |||
332 | $view = $form->createView(); | ||
333 | |||
334 | $this->assertEquals(array( | ||
335 | new ChoiceView('6', '6', '06'), | ||
336 | new ChoiceView('7', '7', '07'), | ||
337 | ), $view['minute']->vars['choices']); | ||
338 | } | ||
339 | |||
340 | public function testIsSecondWithinRangeReturnsTrueIfWithin() | ||
341 | { | ||
342 | $form = $this->factory->create('time', null, array( | ||
343 | 'seconds' => array(6, 7), | ||
344 | 'with_seconds' => true, | ||
345 | )); | ||
346 | |||
347 | $view = $form->createView(); | ||
348 | |||
349 | $this->assertEquals(array( | ||
350 | new ChoiceView('6', '6', '06'), | ||
351 | new ChoiceView('7', '7', '07'), | ||
352 | ), $view['second']->vars['choices']); | ||
353 | } | ||
354 | |||
355 | public function testIsPartiallyFilledReturnsFalseIfCompletelyEmpty() | ||
356 | { | ||
357 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
358 | |||
359 | $form = $this->factory->create('time', null, array( | ||
360 | 'widget' => 'choice', | ||
361 | )); | ||
362 | |||
363 | $form->submit(array( | ||
364 | 'hour' => '', | ||
365 | 'minute' => '', | ||
366 | )); | ||
367 | |||
368 | $this->assertFalse($form->isPartiallyFilled()); | ||
369 | } | ||
370 | |||
371 | public function testIsPartiallyFilledReturnsFalseIfCompletelyEmptyWithSeconds() | ||
372 | { | ||
373 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
374 | |||
375 | $form = $this->factory->create('time', null, array( | ||
376 | 'widget' => 'choice', | ||
377 | 'with_seconds' => true, | ||
378 | )); | ||
379 | |||
380 | $form->submit(array( | ||
381 | 'hour' => '', | ||
382 | 'minute' => '', | ||
383 | 'second' => '', | ||
384 | )); | ||
385 | |||
386 | $this->assertFalse($form->isPartiallyFilled()); | ||
387 | } | ||
388 | |||
389 | public function testIsPartiallyFilledReturnsFalseIfCompletelyFilled() | ||
390 | { | ||
391 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
392 | |||
393 | $form = $this->factory->create('time', null, array( | ||
394 | 'widget' => 'choice', | ||
395 | )); | ||
396 | |||
397 | $form->submit(array( | ||
398 | 'hour' => '0', | ||
399 | 'minute' => '0', | ||
400 | )); | ||
401 | |||
402 | $this->assertFalse($form->isPartiallyFilled()); | ||
403 | } | ||
404 | |||
405 | public function testIsPartiallyFilledReturnsFalseIfCompletelyFilledWithSeconds() | ||
406 | { | ||
407 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
408 | |||
409 | $form = $this->factory->create('time', null, array( | ||
410 | 'widget' => 'choice', | ||
411 | 'with_seconds' => true, | ||
412 | )); | ||
413 | |||
414 | $form->submit(array( | ||
415 | 'hour' => '0', | ||
416 | 'minute' => '0', | ||
417 | 'second' => '0', | ||
418 | )); | ||
419 | |||
420 | $this->assertFalse($form->isPartiallyFilled()); | ||
421 | } | ||
422 | |||
423 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndHourEmpty() | ||
424 | { | ||
425 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
426 | |||
427 | $form = $this->factory->create('time', null, array( | ||
428 | 'widget' => 'choice', | ||
429 | 'with_seconds' => true, | ||
430 | )); | ||
431 | |||
432 | $form->submit(array( | ||
433 | 'hour' => '', | ||
434 | 'minute' => '0', | ||
435 | 'second' => '0', | ||
436 | )); | ||
437 | |||
438 | $this->assertTrue($form->isPartiallyFilled()); | ||
439 | } | ||
440 | |||
441 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndMinuteEmpty() | ||
442 | { | ||
443 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
444 | |||
445 | $form = $this->factory->create('time', null, array( | ||
446 | 'widget' => 'choice', | ||
447 | 'with_seconds' => true, | ||
448 | )); | ||
449 | |||
450 | $form->submit(array( | ||
451 | 'hour' => '0', | ||
452 | 'minute' => '', | ||
453 | 'second' => '0', | ||
454 | )); | ||
455 | |||
456 | $this->assertTrue($form->isPartiallyFilled()); | ||
457 | } | ||
458 | |||
459 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndSecondsEmpty() | ||
460 | { | ||
461 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
462 | |||
463 | $form = $this->factory->create('time', null, array( | ||
464 | 'widget' => 'choice', | ||
465 | 'with_seconds' => true, | ||
466 | )); | ||
467 | |||
468 | $form->submit(array( | ||
469 | 'hour' => '0', | ||
470 | 'minute' => '0', | ||
471 | 'second' => '', | ||
472 | )); | ||
473 | |||
474 | $this->assertTrue($form->isPartiallyFilled()); | ||
475 | } | ||
476 | |||
477 | // Bug fix | ||
478 | public function testInitializeWithDateTime() | ||
479 | { | ||
480 | // Throws an exception if "data_class" option is not explicitly set | ||
481 | // to null in the type | ||
482 | $this->factory->create('time', new \DateTime()); | ||
483 | } | ||
484 | |||
485 | public function testSingleTextWidgetShouldUseTheRightInputType() | ||
486 | { | ||
487 | $form = $this->factory->create('time', null, array( | ||
488 | 'widget' => 'single_text', | ||
489 | )); | ||
490 | |||
491 | $view = $form->createView(); | ||
492 | $this->assertEquals('time', $view->vars['type']); | ||
493 | } | ||
494 | |||
495 | public function testPassDefaultEmptyValueToViewIfNotRequired() | ||
496 | { | ||
497 | $form = $this->factory->create('time', null, array( | ||
498 | 'required' => false, | ||
499 | 'with_seconds' => true, | ||
500 | )); | ||
501 | |||
502 | $view = $form->createView(); | ||
503 | $this->assertSame('', $view['hour']->vars['empty_value']); | ||
504 | $this->assertSame('', $view['minute']->vars['empty_value']); | ||
505 | $this->assertSame('', $view['second']->vars['empty_value']); | ||
506 | } | ||
507 | |||
508 | public function testPassNoEmptyValueToViewIfRequired() | ||
509 | { | ||
510 | $form = $this->factory->create('time', null, array( | ||
511 | 'required' => true, | ||
512 | 'with_seconds' => true, | ||
513 | )); | ||
514 | |||
515 | $view = $form->createView(); | ||
516 | $this->assertNull($view['hour']->vars['empty_value']); | ||
517 | $this->assertNull($view['minute']->vars['empty_value']); | ||
518 | $this->assertNull($view['second']->vars['empty_value']); | ||
519 | } | ||
520 | |||
521 | public function testPassEmptyValueAsString() | ||
522 | { | ||
523 | $form = $this->factory->create('time', null, array( | ||
524 | 'empty_value' => 'Empty', | ||
525 | 'with_seconds' => true, | ||
526 | )); | ||
527 | |||
528 | $view = $form->createView(); | ||
529 | $this->assertSame('Empty', $view['hour']->vars['empty_value']); | ||
530 | $this->assertSame('Empty', $view['minute']->vars['empty_value']); | ||
531 | $this->assertSame('Empty', $view['second']->vars['empty_value']); | ||
532 | } | ||
533 | |||
534 | public function testPassEmptyValueAsArray() | ||
535 | { | ||
536 | $form = $this->factory->create('time', null, array( | ||
537 | 'empty_value' => array( | ||
538 | 'hour' => 'Empty hour', | ||
539 | 'minute' => 'Empty minute', | ||
540 | 'second' => 'Empty second', | ||
541 | ), | ||
542 | 'with_seconds' => true, | ||
543 | )); | ||
544 | |||
545 | $view = $form->createView(); | ||
546 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
547 | $this->assertSame('Empty minute', $view['minute']->vars['empty_value']); | ||
548 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
549 | } | ||
550 | |||
551 | public function testPassEmptyValueAsPartialArrayAddEmptyIfNotRequired() | ||
552 | { | ||
553 | $form = $this->factory->create('time', null, array( | ||
554 | 'required' => false, | ||
555 | 'empty_value' => array( | ||
556 | 'hour' => 'Empty hour', | ||
557 | 'second' => 'Empty second', | ||
558 | ), | ||
559 | 'with_seconds' => true, | ||
560 | )); | ||
561 | |||
562 | $view = $form->createView(); | ||
563 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
564 | $this->assertSame('', $view['minute']->vars['empty_value']); | ||
565 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
566 | } | ||
567 | |||
568 | public function testPassEmptyValueAsPartialArrayAddNullIfRequired() | ||
569 | { | ||
570 | $form = $this->factory->create('time', null, array( | ||
571 | 'required' => true, | ||
572 | 'empty_value' => array( | ||
573 | 'hour' => 'Empty hour', | ||
574 | 'second' => 'Empty second', | ||
575 | ), | ||
576 | 'with_seconds' => true, | ||
577 | )); | ||
578 | |||
579 | $view = $form->createView(); | ||
580 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
581 | $this->assertNull($view['minute']->vars['empty_value']); | ||
582 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
583 | } | ||
584 | |||
585 | public function provideCompoundWidgets() | ||
586 | { | ||
587 | return array( | ||
588 | array('text'), | ||
589 | array('choice'), | ||
590 | ); | ||
591 | } | ||
592 | |||
593 | /** | ||
594 | * @dataProvider provideCompoundWidgets | ||
595 | */ | ||
596 | public function testHourErrorsBubbleUp($widget) | ||
597 | { | ||
598 | $error = new FormError('Invalid!'); | ||
599 | $form = $this->factory->create('time', null, array( | ||
600 | 'widget' => $widget, | ||
601 | )); | ||
602 | $form['hour']->addError($error); | ||
603 | |||
604 | $this->assertSame(array(), $form['hour']->getErrors()); | ||
605 | $this->assertSame(array($error), $form->getErrors()); | ||
606 | } | ||
607 | |||
608 | /** | ||
609 | * @dataProvider provideCompoundWidgets | ||
610 | */ | ||
611 | public function testMinuteErrorsBubbleUp($widget) | ||
612 | { | ||
613 | $error = new FormError('Invalid!'); | ||
614 | $form = $this->factory->create('time', null, array( | ||
615 | 'widget' => $widget, | ||
616 | )); | ||
617 | $form['minute']->addError($error); | ||
618 | |||
619 | $this->assertSame(array(), $form['minute']->getErrors()); | ||
620 | $this->assertSame(array($error), $form->getErrors()); | ||
621 | } | ||
622 | |||
623 | /** | ||
624 | * @dataProvider provideCompoundWidgets | ||
625 | */ | ||
626 | public function testSecondErrorsBubbleUp($widget) | ||
627 | { | ||
628 | $error = new FormError('Invalid!'); | ||
629 | $form = $this->factory->create('time', null, array( | ||
630 | 'widget' => $widget, | ||
631 | 'with_seconds' => true, | ||
632 | )); | ||
633 | $form['second']->addError($error); | ||
634 | |||
635 | $this->assertSame(array(), $form['second']->getErrors()); | ||
636 | $this->assertSame(array($error), $form->getErrors()); | ||
637 | } | ||
638 | |||
639 | /** | ||
640 | * @expectedException \Symfony\Component\Form\Exception\InvalidConfigurationException | ||
641 | */ | ||
642 | public function testInitializeWithSecondsAndWithoutMinutes() | ||
643 | { | ||
644 | $this->factory->create('time', null, array( | ||
645 | 'with_minutes' => false, | ||
646 | 'with_seconds' => true, | ||
647 | )); | ||
648 | } | ||
649 | } | ||