@@ -49,7 +49,12 @@ protected function setUp(): void
49
49
$ this ->rawExtension = new FormExtension ();
50
50
$ this ->translatorExtension = new FormExtension (new StubTranslator ());
51
51
52
- $ form = $ this ->factory ->createNamedBuilder ('register ' , FormType::class, ['username ' => 'tgalopin ' ])
52
+ $ data = [
53
+ 'username ' => 'tgalopin ' ,
54
+ 'choice_multiple ' => ['sugar ' , 'salt ' ],
55
+ ];
56
+
57
+ $ form = $ this ->factory ->createNamedBuilder ('register ' , FormType::class, $ data )
53
58
->add ('username ' , TextType::class, [
54
59
'label ' => 'base.username ' ,
55
60
'label_translation_parameters ' => ['%label_brand% ' => 'Symfony ' ],
@@ -77,6 +82,14 @@ protected function setUp(): void
77
82
],
78
83
'choice_translation_domain ' => 'forms ' ,
79
84
])
85
+ ->add ('choice_multiple ' , ChoiceType::class, [
86
+ 'choices ' => [
87
+ 'base.sugar ' => 'sugar ' ,
88
+ 'base.salt ' => 'salt ' ,
89
+ ],
90
+ 'multiple ' => true ,
91
+ 'expanded ' => true ,
92
+ ])
80
93
->getForm ()
81
94
;
82
95
@@ -95,6 +108,7 @@ public function testFieldName()
95
108
public function testFieldValue ()
96
109
{
97
110
$ this ->assertSame ('tgalopin ' , $ this ->rawExtension ->getFieldValue ($ this ->view ->children ['username ' ]));
111
+ $ this ->assertSame (['sugar ' , 'salt ' ], $ this ->rawExtension ->getFieldValue ($ this ->view ->children ['choice_multiple ' ]));
98
112
}
99
113
100
114
public function testFieldLabel ()
@@ -234,4 +248,40 @@ public function testFieldTranslatedChoicesGrouped()
234
248
$ this ->assertSame ('jp ' , $ choicesArray [1 ]['choices ' ][1 ]['value ' ]);
235
249
$ this ->assertSame ('[trans]base.jp[/trans] ' , $ choicesArray [1 ]['choices ' ][1 ]['label ' ]);
236
250
}
251
+
252
+ public function testFieldChoicesMultiple ()
253
+ {
254
+ $ choices = $ this ->rawExtension ->getFieldChoices ($ this ->view ->children ['choice_multiple ' ]);
255
+
256
+ $ choicesArray = [];
257
+ foreach ($ choices as $ label => $ value ) {
258
+ $ choicesArray [] = ['label ' => $ label , 'value ' => $ value ];
259
+ }
260
+
261
+ $ this ->assertCount (2 , $ choicesArray );
262
+
263
+ $ this ->assertSame ('sugar ' , $ choicesArray [0 ]['value ' ]);
264
+ $ this ->assertSame ('base.sugar ' , $ choicesArray [0 ]['label ' ]);
265
+
266
+ $ this ->assertSame ('salt ' , $ choicesArray [1 ]['value ' ]);
267
+ $ this ->assertSame ('base.salt ' , $ choicesArray [1 ]['label ' ]);
268
+ }
269
+
270
+ public function testFieldTranslatedChoicesMultiple ()
271
+ {
272
+ $ choices = $ this ->translatorExtension ->getFieldChoices ($ this ->view ->children ['choice_multiple ' ]);
273
+
274
+ $ choicesArray = [];
275
+ foreach ($ choices as $ label => $ value ) {
276
+ $ choicesArray [] = ['label ' => $ label , 'value ' => $ value ];
277
+ }
278
+
279
+ $ this ->assertCount (2 , $ choicesArray );
280
+
281
+ $ this ->assertSame ('sugar ' , $ choicesArray [0 ]['value ' ]);
282
+ $ this ->assertSame ('[trans]base.sugar[/trans] ' , $ choicesArray [0 ]['label ' ]);
283
+
284
+ $ this ->assertSame ('salt ' , $ choicesArray [1 ]['value ' ]);
285
+ $ this ->assertSame ('[trans]base.salt[/trans] ' , $ choicesArray [1 ]['label ' ]);
286
+ }
237
287
}
0 commit comments