@@ -32,6 +32,12 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
32
32
'n/a ' => '' ,
33
33
);
34
34
35
+ private $ booleanChoicesWithNull = array (
36
+ 'Yes ' => true ,
37
+ 'No ' => false ,
38
+ 'n/a ' => null ,
39
+ );
40
+
35
41
private $ numericChoicesFlipped = array (
36
42
0 => 'Bernhard ' ,
37
43
1 => 'Fabien ' ,
@@ -183,6 +189,19 @@ public function testExpandedChoiceListWithScalarValues()
183
189
$ this ->assertTrue ($ view ->children [2 ]->vars ['checked ' ], 'Empty value should be pre selected ' );
184
190
}
185
191
192
+ public function testExpandedChoiceListWithBooleanAndNullValues ()
193
+ {
194
+ $ view = $ this ->factory ->create ('choice ' , null , array (
195
+ 'choices ' => $ this ->booleanChoicesWithNull ,
196
+ 'choices_as_values ' => true ,
197
+ 'expanded ' => true ,
198
+ ))->createView ();
199
+
200
+ $ this ->assertFalse ($ view ->children [0 ]->vars ['checked ' ], 'True value should not be pre selected ' );
201
+ $ this ->assertFalse ($ view ->children [1 ]->vars ['checked ' ], 'False value should not be pre selected ' );
202
+ $ this ->assertTrue ($ view ->children [2 ]->vars ['checked ' ], 'Empty value should be pre selected ' );
203
+ }
204
+
186
205
public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData ()
187
206
{
188
207
$ view = $ this ->factory ->create ('choice ' , false , array (
@@ -197,6 +216,19 @@ public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData()
197
216
$ this ->assertFalse ($ view ->children [2 ]->vars ['checked ' ], 'Empty value should not be pre selected ' );
198
217
}
199
218
219
+ public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetData ()
220
+ {
221
+ $ view = $ this ->factory ->create ('choice ' , false , array (
222
+ 'choices ' => $ this ->booleanChoicesWithNull ,
223
+ 'choices_as_values ' => true ,
224
+ 'expanded ' => true ,
225
+ ))->createView ();
226
+
227
+ $ this ->assertFalse ($ view ->children [0 ]->vars ['checked ' ], 'True value should not be pre selected ' );
228
+ $ this ->assertTrue ($ view ->children [1 ]->vars ['checked ' ], 'False value should be pre selected ' );
229
+ $ this ->assertFalse ($ view ->children [2 ]->vars ['checked ' ], 'Null value should not be pre selected ' );
230
+ }
231
+
200
232
public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice ()
201
233
{
202
234
$ form = $ this ->factory ->create ('choice ' , null , array (
@@ -319,7 +351,7 @@ public function testPlaceholderWithExpandedBooleanChoices()
319
351
320
352
$ view = $ form ->createView ();
321
353
322
- $ this ->assertSame ( '' , $ view ->vars ['value ' ], 'Value should be empty ' );
354
+ $ this ->assertEmpty ( $ view ->vars ['value ' ], 'Value should be empty ' );
323
355
$ this ->assertSame ('1 ' , $ view ->vars ['choices ' ][0 ]->value );
324
356
$ this ->assertSame ('0 ' , $ view ->vars ['choices ' ][1 ]->value , 'Choice "false" should have "0" as value ' );
325
357
$ this ->assertFalse ($ view ->children [1 ]->vars ['checked ' ], 'Choice "false" should not be selected ' );
@@ -940,7 +972,7 @@ public function testSubmitSingleExpandedRequiredNull()
940
972
$ form ->submit (null );
941
973
942
974
$ this ->assertNull ($ form ->getData ());
943
- $ this ->assertNull ($ form ->getViewData ());
975
+ $ this ->assertEmpty ($ form ->getViewData ());
944
976
$ this ->assertEmpty ($ form ->getExtraData ());
945
977
$ this ->assertTrue ($ form ->isSynchronized ());
946
978
@@ -972,7 +1004,7 @@ public function testSubmitSingleExpandedRequiredNullNoChoices()
972
1004
$ form ->submit (null );
973
1005
974
1006
$ this ->assertNull ($ form ->getData ());
975
- $ this ->assertNull ($ form ->getViewData ());
1007
+ $ this ->assertEmpty ($ form ->getViewData ());
976
1008
$ this ->assertEmpty ($ form ->getExtraData ());
977
1009
$ this ->assertTrue ($ form ->isSynchronized ());
978
1010
}
@@ -990,7 +1022,7 @@ public function testSubmitSingleExpandedRequiredEmpty()
990
1022
$ form ->submit ('' );
991
1023
992
1024
$ this ->assertNull ($ form ->getData ());
993
- $ this ->assertNull ($ form ->getViewData ());
1025
+ $ this ->assertEmpty ($ form ->getViewData ());
994
1026
$ this ->assertEmpty ($ form ->getExtraData ());
995
1027
$ this ->assertTrue ($ form ->isSynchronized ());
996
1028
@@ -1022,7 +1054,7 @@ public function testSubmitSingleExpandedRequiredEmptyNoChoices()
1022
1054
$ form ->submit ('' );
1023
1055
1024
1056
$ this ->assertNull ($ form ->getData ());
1025
- $ this ->assertNull ($ form ->getViewData ());
1057
+ $ this ->assertEmpty ($ form ->getViewData ());
1026
1058
$ this ->assertEmpty ($ form ->getExtraData ());
1027
1059
$ this ->assertTrue ($ form ->isSynchronized ());
1028
1060
}
@@ -1040,7 +1072,7 @@ public function testSubmitSingleExpandedRequiredFalse()
1040
1072
$ form ->submit (false );
1041
1073
1042
1074
$ this ->assertNull ($ form ->getData ());
1043
- $ this ->assertNull ($ form ->getViewData ());
1075
+ $ this ->assertEmpty ($ form ->getViewData ());
1044
1076
$ this ->assertEmpty ($ form ->getExtraData ());
1045
1077
$ this ->assertTrue ($ form ->isSynchronized ());
1046
1078
@@ -1072,7 +1104,7 @@ public function testSubmitSingleExpandedRequiredFalseNoChoices()
1072
1104
$ form ->submit (false );
1073
1105
1074
1106
$ this ->assertNull ($ form ->getData ());
1075
- $ this ->assertNull ($ form ->getViewData ());
1107
+ $ this ->assertEmpty ($ form ->getViewData ());
1076
1108
$ this ->assertEmpty ($ form ->getExtraData ());
1077
1109
$ this ->assertTrue ($ form ->isSynchronized ());
1078
1110
}
@@ -1090,7 +1122,7 @@ public function testSubmitSingleExpandedNonRequiredNull()
1090
1122
$ form ->submit (null );
1091
1123
1092
1124
$ this ->assertNull ($ form ->getData ());
1093
- $ this ->assertNull ($ form ->getViewData ());
1125
+ $ this ->assertEmpty ($ form ->getViewData ());
1094
1126
$ this ->assertEmpty ($ form ->getExtraData ());
1095
1127
$ this ->assertTrue ($ form ->isSynchronized ());
1096
1128
@@ -1124,7 +1156,7 @@ public function testSubmitSingleExpandedNonRequiredNullNoChoices()
1124
1156
$ form ->submit (null );
1125
1157
1126
1158
$ this ->assertNull ($ form ->getData ());
1127
- $ this ->assertNull ($ form ->getViewData ());
1159
+ $ this ->assertEmpty ($ form ->getViewData ());
1128
1160
$ this ->assertEmpty ($ form ->getExtraData ());
1129
1161
$ this ->assertTrue ($ form ->isSynchronized ());
1130
1162
}
@@ -1142,7 +1174,7 @@ public function testSubmitSingleExpandedNonRequiredEmpty()
1142
1174
$ form ->submit ('' );
1143
1175
1144
1176
$ this ->assertNull ($ form ->getData ());
1145
- $ this ->assertNull ($ form ->getViewData ());
1177
+ $ this ->assertEmpty ($ form ->getViewData ());
1146
1178
$ this ->assertEmpty ($ form ->getExtraData ());
1147
1179
$ this ->assertTrue ($ form ->isSynchronized ());
1148
1180
@@ -1176,7 +1208,7 @@ public function testSubmitSingleExpandedNonRequiredEmptyNoChoices()
1176
1208
$ form ->submit ('' );
1177
1209
1178
1210
$ this ->assertNull ($ form ->getData ());
1179
- $ this ->assertNull ($ form ->getViewData ());
1211
+ $ this ->assertEmpty ($ form ->getViewData ());
1180
1212
$ this ->assertEmpty ($ form ->getExtraData ());
1181
1213
$ this ->assertTrue ($ form ->isSynchronized ());
1182
1214
}
@@ -1194,7 +1226,7 @@ public function testSubmitSingleExpandedNonRequiredFalse()
1194
1226
$ form ->submit (false );
1195
1227
1196
1228
$ this ->assertNull ($ form ->getData ());
1197
- $ this ->assertNull ($ form ->getViewData ());
1229
+ $ this ->assertEmpty ($ form ->getViewData ());
1198
1230
$ this ->assertEmpty ($ form ->getExtraData ());
1199
1231
$ this ->assertTrue ($ form ->isSynchronized ());
1200
1232
@@ -1228,7 +1260,7 @@ public function testSubmitSingleExpandedNonRequiredFalseNoChoices()
1228
1260
$ form ->submit (false );
1229
1261
1230
1262
$ this ->assertNull ($ form ->getData ());
1231
- $ this ->assertNull ($ form ->getViewData ());
1263
+ $ this ->assertEmpty ($ form ->getViewData ());
1232
1264
$ this ->assertEmpty ($ form ->getExtraData ());
1233
1265
$ this ->assertTrue ($ form ->isSynchronized ());
1234
1266
}
@@ -1247,7 +1279,7 @@ public function testSubmitSingleExpandedWithEmptyChild()
1247
1279
1248
1280
$ form ->submit ('' );
1249
1281
1250
- $ this ->assertNull ($ form ->getData ());
1282
+ $ this ->assertEmpty ($ form ->getData ());
1251
1283
$ this ->assertTrue ($ form ->isSynchronized ());
1252
1284
1253
1285
$ this ->assertTrue ($ form [0 ]->getData ());
0 commit comments