File tree 10 files changed +159
-0
lines changed
src/Symfony/Component/Form
Tests/Extension/Core/Type
10 files changed +159
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
24
24
$ resolver ->setDefaults (array (
25
25
'years ' => range (date ('Y ' ) - 120 , date ('Y ' )),
26
26
));
27
+
28
+ $ resolver ->setAllowedTypes (array (
29
+ 'years ' => 'array ' ,
30
+ ));
27
31
}
28
32
29
33
/**
Original file line number Diff line number Diff line change @@ -237,6 +237,9 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
237
237
238
238
$ resolver ->setAllowedTypes (array (
239
239
'format ' => array ('int ' , 'string ' ),
240
+ 'years ' => 'array ' ,
241
+ 'months ' => 'array ' ,
242
+ 'days ' => 'array ' ,
240
243
));
241
244
}
242
245
Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
55
55
'second_name ' => 'second ' ,
56
56
'error_bubbling ' => false ,
57
57
));
58
+
59
+ $ resolver ->setAllowedTypes (array (
60
+ 'options ' => 'array ' ,
61
+ 'first_options ' => 'array ' ,
62
+ 'second_options ' => 'array ' ,
63
+ ));
58
64
}
59
65
60
66
/**
Original file line number Diff line number Diff line change @@ -221,6 +221,12 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
221
221
'choice ' ,
222
222
),
223
223
));
224
+
225
+ $ resolver ->setAllowedTypes (array (
226
+ 'hours ' => 'array ' ,
227
+ 'minutes ' => 'array ' ,
228
+ 'seconds ' => 'array ' ,
229
+ ));
224
230
}
225
231
226
232
/**
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
34
34
$ resolver ->setDefaults (array (
35
35
'default_protocol ' => 'http ' ,
36
36
));
37
+
38
+ $ resolver ->setAllowedTypes (array (
39
+ 'default_protocol ' => array ('null ' , 'string ' ),
40
+ ));
37
41
}
38
42
39
43
/**
Original file line number Diff line number Diff line change
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
+ /**
15
+ * @author Stepan Anchugov <kixxx1@gmail.com>
16
+ */
17
+ class BirthdayTypeTest extends BaseTypeTest
18
+ {
19
+ /**
20
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
21
+ */
22
+ public function testSetInvalidYearsOption ()
23
+ {
24
+ $ this ->factory ->create ('birthday ' , null , array (
25
+ 'years ' => 'bad value ' ,
26
+ ));
27
+ }
28
+
29
+ protected function getTestedType ()
30
+ {
31
+ return 'birthday ' ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -340,6 +340,36 @@ public function testThrowExceptionIfFormatIsInvalid()
340
340
));
341
341
}
342
342
343
+ /**
344
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
345
+ */
346
+ public function testThrowExceptionIfYearsIsInvalid ()
347
+ {
348
+ $ this ->factory ->create ('date ' , null , array (
349
+ 'years ' => 'bad value ' ,
350
+ ));
351
+ }
352
+
353
+ /**
354
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
355
+ */
356
+ public function testThrowExceptionIfMonthsIsInvalid ()
357
+ {
358
+ $ this ->factory ->create ('date ' , null , array (
359
+ 'months ' => 'bad value ' ,
360
+ ));
361
+ }
362
+
363
+ /**
364
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
365
+ */
366
+ public function testThrowExceptionIfDaysIsInvalid ()
367
+ {
368
+ $ this ->factory ->create ('date ' , null , array (
369
+ 'days ' => 'bad value ' ,
370
+ ));
371
+ }
372
+
343
373
public function testSetDataWithDifferentTimezones ()
344
374
{
345
375
$ form = $ this ->factory ->create ('date ' , null , array (
Original file line number Diff line number Diff line change @@ -72,6 +72,39 @@ public function testSetRequired()
72
72
$ this ->assertFalse ($ form ['second ' ]->isRequired ());
73
73
}
74
74
75
+ /**
76
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
77
+ */
78
+ public function testSetInvalidOptions ()
79
+ {
80
+ $ this ->factory ->create ('repeated ' , null , array (
81
+ 'type ' => 'text ' ,
82
+ 'options ' => 'bad value ' ,
83
+ ));
84
+ }
85
+
86
+ /**
87
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
88
+ */
89
+ public function testSetInvalidFirstOptions ()
90
+ {
91
+ $ this ->factory ->create ('repeated ' , null , array (
92
+ 'type ' => 'text ' ,
93
+ 'first_options ' => 'bad value ' ,
94
+ ));
95
+ }
96
+
97
+ /**
98
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
99
+ */
100
+ public function testSetInvalidSecondOptions ()
101
+ {
102
+ $ this ->factory ->create ('repeated ' , null , array (
103
+ 'type ' => 'text ' ,
104
+ 'second_options ' => 'bad value ' ,
105
+ ));
106
+ }
107
+
75
108
public function testSetErrorBubblingToTrue ()
76
109
{
77
110
$ form = $ this ->factory ->create ('repeated ' , null , array (
Original file line number Diff line number Diff line change @@ -673,4 +673,34 @@ public function testInitializeWithSecondsAndWithoutMinutes()
673
673
'with_seconds ' => true ,
674
674
));
675
675
}
676
+
677
+ /**
678
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
679
+ */
680
+ public function testThrowExceptionIfHoursIsInvalid ()
681
+ {
682
+ $ this ->factory ->create ('time ' , null , array (
683
+ 'hours ' => 'bad value ' ,
684
+ ));
685
+ }
686
+
687
+ /**
688
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
689
+ */
690
+ public function testThrowExceptionIfMinutesIsInvalid ()
691
+ {
692
+ $ this ->factory ->create ('time ' , null , array (
693
+ 'minutes ' => 'bad value ' ,
694
+ ));
695
+ }
696
+
697
+ /**
698
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
699
+ */
700
+ public function testThrowExceptionIfSecondsIsInvalid ()
701
+ {
702
+ $ this ->factory ->create ('time ' , null , array (
703
+ 'seconds ' => 'bad value ' ,
704
+ ));
705
+ }
676
706
}
Original file line number Diff line number Diff line change @@ -70,4 +70,14 @@ public function testSubmitAddsNoDefaultProtocolIfSetToNull()
70
70
$ this ->assertSame ('www.domain.com ' , $ form ->getData ());
71
71
$ this ->assertSame ('www.domain.com ' , $ form ->getViewData ());
72
72
}
73
+
74
+ /**
75
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
76
+ */
77
+ public function testThrowExceptionIfDefaultProtocolIsInvalid ()
78
+ {
79
+ $ this ->factory ->create ('url ' , null , array (
80
+ 'default_protocol ' => array (),
81
+ ));
82
+ }
73
83
}
You can’t perform that action at this time.
0 commit comments