@@ -126,6 +126,20 @@ public function testChoiceListAndChoicesCanBeEmpty()
126
126
));
127
127
}
128
128
129
+ public function testChoiceListWithBooleanAsValues ()
130
+ {
131
+ $ view = $ this ->factory ->create ('Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , null , array (
132
+ 'choices ' => array (
133
+ 'Yes ' => true ,
134
+ 'No ' => false ,
135
+ ),
136
+ 'choices_as_values ' => true ,
137
+ ))->createView ();
138
+
139
+ $ this ->assertSame ('1 ' , $ view ->vars ['choices ' ][0 ]->value );
140
+ $ this ->assertSame ('0 ' , $ view ->vars ['choices ' ][1 ]->value );
141
+ }
142
+
129
143
public function testExpandedChoicesOptionsTurnIntoChildren ()
130
144
{
131
145
$ form = $ this ->factory ->create ('Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , null , array (
@@ -209,6 +223,30 @@ public function testPlaceholderNotPresentIfEmptyChoice()
209
223
$ this ->assertCount (2 , $ form , 'Each choice should become a new field ' );
210
224
}
211
225
226
+ public function testPlaceholderWithBooleanChoices ()
227
+ {
228
+ $ form = $ this ->factory ->create ('Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , null , array (
229
+ 'multiple ' => false ,
230
+ 'expanded ' => true ,
231
+ 'required ' => false ,
232
+ 'choices ' => array (
233
+ 'Yes ' => true ,
234
+ 'No ' => false ,
235
+ ),
236
+ 'placeholder ' => 'Select an option ' ,
237
+ 'choices_as_values ' => true ,
238
+ ));
239
+
240
+ $ this ->assertTrue (isset ($ form ['placeholder ' ]), 'Placeholder should be set ' );
241
+ $ this ->assertCount (3 , $ form , 'Each choice should become a new field, placeholder included ' );
242
+
243
+ $ view = $ form ->createView ();
244
+
245
+ $ this ->assertSame ('Select an option ' , $ view ->vars ['empty_value ' ], 'Placeholder should be selected ' );
246
+ $ this ->assertSame ('1 ' , $ view ->vars ['choices ' ][0 ]->value );
247
+ $ this ->assertSame ('0 ' , $ view ->vars ['choices ' ][1 ]->value , 'Choice "false" should have 0 as value ' );
248
+ }
249
+
212
250
public function testExpandedChoicesOptionsAreFlattened ()
213
251
{
214
252
$ form = $ this ->factory ->create ('Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , null , array (
0 commit comments