@@ -690,6 +690,129 @@ public function testSingleChoiceExpanded()
690
690
);
691
691
}
692
692
693
+ public function testSingleChoiceExpandedWithLabelsAsFalse ()
694
+ {
695
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
696
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
697
+ 'choices_as_values ' => true ,
698
+ 'choice_label ' => false ,
699
+ 'multiple ' => false ,
700
+ 'expanded ' => true ,
701
+ ));
702
+
703
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
704
+ '/div
705
+ [
706
+ ./div
707
+ [@class="radio"]
708
+ [
709
+ ./label
710
+ [
711
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
712
+ ]
713
+ ]
714
+ /following-sibling::div
715
+ [@class="radio"]
716
+ [
717
+ ./label
718
+ [
719
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
720
+ ]
721
+ ]
722
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
723
+ ]
724
+ '
725
+ );
726
+ }
727
+
728
+ public function testSingleChoiceExpandedWithLabelsSetByCallable ()
729
+ {
730
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
731
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
732
+ 'choices_as_values ' => true ,
733
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
734
+ if ('&b ' === $ choice ) {
735
+ return false ;
736
+ }
737
+
738
+ return 'label. ' .$ value ;
739
+ },
740
+ 'multiple ' => false ,
741
+ 'expanded ' => true ,
742
+ ));
743
+
744
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
745
+ '/div
746
+ [
747
+ ./div
748
+ [@class="radio"]
749
+ [
750
+ ./label
751
+ [.=" [trans]label.&a[/trans]"]
752
+ [
753
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
754
+ ]
755
+ ]
756
+ /following-sibling::div
757
+ [@class="radio"]
758
+ [
759
+ ./label
760
+ [
761
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
762
+ ]
763
+ ]
764
+ /following-sibling::div
765
+ [@class="radio"]
766
+ [
767
+ ./label
768
+ [.=" [trans]label.&c[/trans]"]
769
+ [
770
+ ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)]
771
+ ]
772
+ ]
773
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
774
+ ]
775
+ '
776
+ );
777
+ }
778
+
779
+ public function testSingleChoiceExpandedWithLabelsSetFalseByCallable ()
780
+ {
781
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
782
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
783
+ 'choices_as_values ' => true ,
784
+ 'choice_label ' => function () {
785
+ return false ;
786
+ },
787
+ 'multiple ' => false ,
788
+ 'expanded ' => true ,
789
+ ));
790
+
791
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
792
+ '/div
793
+ [
794
+ ./div
795
+ [@class="radio"]
796
+ [
797
+ ./label
798
+ [
799
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
800
+ ]
801
+ ]
802
+ /following-sibling::div
803
+ [@class="radio"]
804
+ [
805
+ ./label
806
+ [
807
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
808
+ ]
809
+ ]
810
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
811
+ ]
812
+ '
813
+ );
814
+ }
815
+
693
816
public function testSingleChoiceExpandedWithoutTranslation ()
694
817
{
695
818
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
@@ -895,6 +1018,129 @@ public function testMultipleChoiceExpanded()
895
1018
);
896
1019
}
897
1020
1021
+ public function testMultipleChoiceExpandedWithLabelsAsFalse ()
1022
+ {
1023
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1024
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1025
+ 'choices_as_values ' => true ,
1026
+ 'choice_label ' => false ,
1027
+ 'multiple ' => true ,
1028
+ 'expanded ' => true ,
1029
+ ));
1030
+
1031
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1032
+ '/div
1033
+ [
1034
+ ./div
1035
+ [@class="checkbox"]
1036
+ [
1037
+ ./label
1038
+ [
1039
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1040
+ ]
1041
+ ]
1042
+ /following-sibling::div
1043
+ [@class="checkbox"]
1044
+ [
1045
+ ./label
1046
+ [
1047
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1048
+ ]
1049
+ ]
1050
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1051
+ ]
1052
+ '
1053
+ );
1054
+ }
1055
+
1056
+ public function testMultipleChoiceExpandedWithLabelsSetByCallable ()
1057
+ {
1058
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1059
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
1060
+ 'choices_as_values ' => true ,
1061
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
1062
+ if ('&b ' === $ choice ) {
1063
+ return false ;
1064
+ }
1065
+
1066
+ return 'label. ' .$ value ;
1067
+ },
1068
+ 'multiple ' => true ,
1069
+ 'expanded ' => true ,
1070
+ ));
1071
+
1072
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1073
+ '/div
1074
+ [
1075
+ ./div
1076
+ [@class="checkbox"]
1077
+ [
1078
+ ./label
1079
+ [.=" [trans]label.&a[/trans]"]
1080
+ [
1081
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1082
+ ]
1083
+ ]
1084
+ /following-sibling::div
1085
+ [@class="checkbox"]
1086
+ [
1087
+ ./label
1088
+ [
1089
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1090
+ ]
1091
+ ]
1092
+ /following-sibling::div
1093
+ [@class="checkbox"]
1094
+ [
1095
+ ./label
1096
+ [.=" [trans]label.&c[/trans]"]
1097
+ [
1098
+ ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)]
1099
+ ]
1100
+ ]
1101
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1102
+ ]
1103
+ '
1104
+ );
1105
+ }
1106
+
1107
+ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable ()
1108
+ {
1109
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1110
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1111
+ 'choices_as_values ' => true ,
1112
+ 'choice_label ' => function () {
1113
+ return false ;
1114
+ },
1115
+ 'multiple ' => true ,
1116
+ 'expanded ' => true ,
1117
+ ));
1118
+
1119
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1120
+ '/div
1121
+ [
1122
+ ./div
1123
+ [@class="checkbox"]
1124
+ [
1125
+ ./label
1126
+ [
1127
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1128
+ ]
1129
+ ]
1130
+ /following-sibling::div
1131
+ [@class="checkbox"]
1132
+ [
1133
+ ./label
1134
+ [
1135
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1136
+ ]
1137
+ ]
1138
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1139
+ ]
1140
+ '
1141
+ );
1142
+ }
1143
+
898
1144
public function testMultipleChoiceExpandedWithoutTranslation ()
899
1145
{
900
1146
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' , '&c ' ), array (
0 commit comments