@@ -693,6 +693,129 @@ public function testSingleChoiceExpanded()
693
693
);
694
694
}
695
695
696
+ public function testSingleChoiceExpandedWithLabelsAsFalse ()
697
+ {
698
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , array (
699
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
700
+ 'choices_as_values ' => true ,
701
+ 'choice_label ' => false ,
702
+ 'multiple ' => false ,
703
+ 'expanded ' => true ,
704
+ ));
705
+
706
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
707
+ '/div
708
+ [
709
+ ./div
710
+ [@class="radio"]
711
+ [
712
+ ./label
713
+ [
714
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
715
+ ]
716
+ ]
717
+ /following-sibling::div
718
+ [@class="radio"]
719
+ [
720
+ ./label
721
+ [
722
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
723
+ ]
724
+ ]
725
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
726
+ ]
727
+ '
728
+ );
729
+ }
730
+
731
+ public function testSingleChoiceExpandedWithLabelsSetByCallable ()
732
+ {
733
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , array (
734
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
735
+ 'choices_as_values ' => true ,
736
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
737
+ if ('&b ' === $ choice ) {
738
+ return false ;
739
+ }
740
+
741
+ return 'label. ' .$ value ;
742
+ },
743
+ 'multiple ' => false ,
744
+ 'expanded ' => true ,
745
+ ));
746
+
747
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
748
+ '/div
749
+ [
750
+ ./div
751
+ [@class="radio"]
752
+ [
753
+ ./label
754
+ [.=" [trans]label.&a[/trans]"]
755
+ [
756
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
757
+ ]
758
+ ]
759
+ /following-sibling::div
760
+ [@class="radio"]
761
+ [
762
+ ./label
763
+ [
764
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
765
+ ]
766
+ ]
767
+ /following-sibling::div
768
+ [@class="radio"]
769
+ [
770
+ ./label
771
+ [.=" [trans]label.&c[/trans]"]
772
+ [
773
+ ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)]
774
+ ]
775
+ ]
776
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
777
+ ]
778
+ '
779
+ );
780
+ }
781
+
782
+ public function testSingleChoiceExpandedWithLabelsSetFalseByCallable ()
783
+ {
784
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , array (
785
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
786
+ 'choices_as_values ' => true ,
787
+ 'choice_label ' => function () {
788
+ return false ;
789
+ },
790
+ 'multiple ' => false ,
791
+ 'expanded ' => true ,
792
+ ));
793
+
794
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
795
+ '/div
796
+ [
797
+ ./div
798
+ [@class="radio"]
799
+ [
800
+ ./label
801
+ [
802
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
803
+ ]
804
+ ]
805
+ /following-sibling::div
806
+ [@class="radio"]
807
+ [
808
+ ./label
809
+ [
810
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
811
+ ]
812
+ ]
813
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
814
+ ]
815
+ '
816
+ );
817
+ }
818
+
696
819
public function testSingleChoiceExpandedWithoutTranslation ()
697
820
{
698
821
$ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , array (
@@ -938,6 +1061,129 @@ public function testMultipleChoiceExpanded()
938
1061
);
939
1062
}
940
1063
1064
+ public function testMultipleChoiceExpandedWithLabelsAsFalse ()
1065
+ {
1066
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , array ('&a ' ), array (
1067
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1068
+ 'choices_as_values ' => true ,
1069
+ 'choice_label ' => false ,
1070
+ 'multiple ' => true ,
1071
+ 'expanded ' => true ,
1072
+ ));
1073
+
1074
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1075
+ '/div
1076
+ [
1077
+ ./div
1078
+ [@class="checkbox"]
1079
+ [
1080
+ ./label
1081
+ [
1082
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1083
+ ]
1084
+ ]
1085
+ /following-sibling::div
1086
+ [@class="checkbox"]
1087
+ [
1088
+ ./label
1089
+ [
1090
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1091
+ ]
1092
+ ]
1093
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1094
+ ]
1095
+ '
1096
+ );
1097
+ }
1098
+
1099
+ public function testMultipleChoiceExpandedWithLabelsSetByCallable ()
1100
+ {
1101
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , array ('&a ' ), array (
1102
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
1103
+ 'choices_as_values ' => true ,
1104
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
1105
+ if ('&b ' === $ choice ) {
1106
+ return false ;
1107
+ }
1108
+
1109
+ return 'label. ' .$ value ;
1110
+ },
1111
+ 'multiple ' => true ,
1112
+ 'expanded ' => true ,
1113
+ ));
1114
+
1115
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1116
+ '/div
1117
+ [
1118
+ ./div
1119
+ [@class="checkbox"]
1120
+ [
1121
+ ./label
1122
+ [.=" [trans]label.&a[/trans]"]
1123
+ [
1124
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1125
+ ]
1126
+ ]
1127
+ /following-sibling::div
1128
+ [@class="checkbox"]
1129
+ [
1130
+ ./label
1131
+ [
1132
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1133
+ ]
1134
+ ]
1135
+ /following-sibling::div
1136
+ [@class="checkbox"]
1137
+ [
1138
+ ./label
1139
+ [.=" [trans]label.&c[/trans]"]
1140
+ [
1141
+ ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)]
1142
+ ]
1143
+ ]
1144
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1145
+ ]
1146
+ '
1147
+ );
1148
+ }
1149
+
1150
+ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable ()
1151
+ {
1152
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , array ('&a ' ), array (
1153
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1154
+ 'choices_as_values ' => true ,
1155
+ 'choice_label ' => function () {
1156
+ return false ;
1157
+ },
1158
+ 'multiple ' => true ,
1159
+ 'expanded ' => true ,
1160
+ ));
1161
+
1162
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1163
+ '/div
1164
+ [
1165
+ ./div
1166
+ [@class="checkbox"]
1167
+ [
1168
+ ./label
1169
+ [
1170
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1171
+ ]
1172
+ ]
1173
+ /following-sibling::div
1174
+ [@class="checkbox"]
1175
+ [
1176
+ ./label
1177
+ [
1178
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1179
+ ]
1180
+ ]
1181
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1182
+ ]
1183
+ '
1184
+ );
1185
+ }
1186
+
941
1187
public function testMultipleChoiceExpandedWithoutTranslation ()
942
1188
{
943
1189
$ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , array ('&a ' , '&c ' ), array (
0 commit comments