@@ -717,6 +717,129 @@ public function testSingleChoiceExpanded()
717
717
);
718
718
}
719
719
720
+ public function testSingleChoiceExpandedWithLabelsAsFalse ()
721
+ {
722
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
723
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
724
+ 'choices_as_values ' => true ,
725
+ 'choice_label ' => false ,
726
+ 'multiple ' => false ,
727
+ 'expanded ' => true ,
728
+ ));
729
+
730
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
731
+ '/div
732
+ [
733
+ ./div
734
+ [@class="radio"]
735
+ [
736
+ ./label
737
+ [
738
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
739
+ ]
740
+ ]
741
+ /following-sibling::div
742
+ [@class="radio"]
743
+ [
744
+ ./label
745
+ [
746
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
747
+ ]
748
+ ]
749
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
750
+ ]
751
+ '
752
+ );
753
+ }
754
+
755
+ public function testSingleChoiceExpandedWithLabelsSetByCallable ()
756
+ {
757
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
758
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
759
+ 'choices_as_values ' => true ,
760
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
761
+ if ('&b ' === $ choice ) {
762
+ return false ;
763
+ }
764
+
765
+ return 'label. ' .$ value ;
766
+ },
767
+ 'multiple ' => false ,
768
+ 'expanded ' => true ,
769
+ ));
770
+
771
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
772
+ '/div
773
+ [
774
+ ./div
775
+ [@class="radio"]
776
+ [
777
+ ./label
778
+ [.=" [trans]label.&a[/trans]"]
779
+ [
780
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
781
+ ]
782
+ ]
783
+ /following-sibling::div
784
+ [@class="radio"]
785
+ [
786
+ ./label
787
+ [
788
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
789
+ ]
790
+ ]
791
+ /following-sibling::div
792
+ [@class="radio"]
793
+ [
794
+ ./label
795
+ [.=" [trans]label.&c[/trans]"]
796
+ [
797
+ ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)]
798
+ ]
799
+ ]
800
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
801
+ ]
802
+ '
803
+ );
804
+ }
805
+
806
+ public function testSingleChoiceExpandedWithLabelsSetFalseByCallable ()
807
+ {
808
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
809
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
810
+ 'choices_as_values ' => true ,
811
+ 'choice_label ' => function () {
812
+ return false ;
813
+ },
814
+ 'multiple ' => false ,
815
+ 'expanded ' => true ,
816
+ ));
817
+
818
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
819
+ '/div
820
+ [
821
+ ./div
822
+ [@class="radio"]
823
+ [
824
+ ./label
825
+ [
826
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
827
+ ]
828
+ ]
829
+ /following-sibling::div
830
+ [@class="radio"]
831
+ [
832
+ ./label
833
+ [
834
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
835
+ ]
836
+ ]
837
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
838
+ ]
839
+ '
840
+ );
841
+ }
842
+
720
843
public function testSingleChoiceExpandedWithoutTranslation ()
721
844
{
722
845
$ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , array (
@@ -970,6 +1093,129 @@ public function testMultipleChoiceExpanded()
970
1093
);
971
1094
}
972
1095
1096
+ public function testMultipleChoiceExpandedWithLabelsAsFalse ()
1097
+ {
1098
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1099
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1100
+ 'choices_as_values ' => true ,
1101
+ 'choice_label ' => false ,
1102
+ 'multiple ' => true ,
1103
+ 'expanded ' => true<
F438
/span>,
1104
+ ));
1105
+
1106
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1107
+ '/div
1108
+ [
1109
+ ./div
1110
+ [@class="checkbox"]
1111
+ [
1112
+ ./label
1113
+ [
1114
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1115
+ ]
1116
+ ]
1117
+ /following-sibling::div
1118
+ [@class="checkbox"]
1119
+ [
1120
+ ./label
1121
+ [
1122
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1123
+ ]
1124
+ ]
1125
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1126
+ ]
1127
+ '
1128
+ );
1129
+ }
1130
+
1131
+ public function testMultipleChoiceExpandedWithLabelsSetByCallable ()
1132
+ {
1133
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1134
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
1135
+ 'choices_as_values ' => true ,
1136
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
1137
+ if ('&b ' === $ choice ) {
1138
+ return false ;
1139
+ }
1140
+
1141
+ return 'label. ' .$ value ;
1142
+ },
1143
+ 'multiple ' => true ,
1144
+ 'expanded ' => true ,
1145
+ ));
1146
+
1147
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1148
+ '/div
1149
+ [
1150
+ ./div
1151
+ [@class="checkbox"]
1152
+ [
1153
+ ./label
1154
+ [.=" [trans]label.&a[/trans]"]
1155
+ [
1156
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1157
+ ]
1158
+ ]
1159
+ /following-sibling::div
1160
+ [@class="checkbox"]
1161
+ [
1162
+ ./label
1163
+ [
1164
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1165
+ ]
1166
+ ]
1167
+ /following-sibling::div
1168
+ [@class="checkbox"]
1169
+ [
1170
+ ./label
1171
+ [.=" [trans]label.&c[/trans]"]
1172
+ [
1173
+ ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)]
1174
+ ]
1175
+ ]
1176
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1177
+ ]
1178
+ '
1179
+ );
1180
+ }
1181
+
1182
+ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable ()
1183
+ {
1184
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1185
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1186
+ 'choices_as_values ' => true ,
1187
+ 'choice_label ' => function () {
1188
+ return false ;
1189
+ },
1190
+ 'multiple ' => true ,
1191
+ 'expanded ' => true ,
1192
+ ));
1193
+
1194
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1195
+ '/div
1196
+ [
1197
+ ./div
1198
+ [@class="checkbox"]
1199
+ [
1200
+ ./label
1201
+ [
1202
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1203
+ ]
1204
+ ]
1205
+ /following-sibling::div
1206
+ [@class="checkbox"]
1207
+ [
1208
+ ./label
1209
+ [
1210
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1211
+ ]
1212
+ ]
1213
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1214
+ ]
1215
+ '
1216
+ );
1217
+ }
1218
+
973
1219
public function testMultipleChoiceExpandedWithoutTranslation ()
974
1220
{
975
1221
$ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , array ('&a ' , '&c ' ), array (
0 commit comments