@@ -670,6 +670,129 @@ public function testSingleChoiceExpanded()
670
670
);
671
671
}
672
672
673
+ public function testSingleChoiceExpandedWithLabelsAsFalse ()
674
+ {
675
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
676
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
677
+ 'choices_as_values ' => true ,
678
+ 'choice_label ' => false ,
679
+ 'multiple ' => false ,
680
+ 'expanded ' => true ,
681
+ ));
682
+
683
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
684
+ '/div
685
+ [
686
+ ./div
687
+ [@class="radio"]
688
+ [
689
+ ./label
690
+ [
691
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
692
+ ]
693
+ ]
694
+ /following-sibling::div
695
+ [@class="radio"]
696
+ [
697
+ ./label
698
+ [
699
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
700
+ ]
701
+ ]
702
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
703
+ ]
704
+ '
705
+ );
706
+ }
707
+
708
+ public function testSingleChoiceExpandedWithLabelsSetByCallable ()
709
+ {
710
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
711
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
712
+ 'choices_as_values ' => true ,
713
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
714
+ if ('&b ' === $ choice ) {
715
+ return false ;
716
+ }
717
+
718
+ return 'label. ' .$ value ;
719
+ },
720
+ 'multiple ' => false ,
721
+ 'expanded ' => true ,
722
+ ));
723
+
724
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
725
+ '/div
726
+ [
727
+ ./div
728
+ [@class="radio"]
729
+ [
730
+ ./label
731
+ [.=" [trans]label.&a[/trans]"]
732
+ [
733
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
734
+ ]
735
+ ]
736
+ /following-sibling::div
737
+ [@class="radio"]
738
+ [
739
+ ./label
740
+ [
741
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
742
+ ]
743
+ ]
744
+ /following-sibling::div
745
+ [@class="radio"]
746
+ [
747
+ ./label
748
+ [.=" [trans]label.&c[/trans]"]
749
+ [
750
+ ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)]
751
+ ]
752
+ ]
753
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
754
+ ]
755
+ '
756
+ );
757
+ }
758
+
759
+ public function testSingleChoiceExpandedWithLabelsSetFalseByCallable ()
760
+ {
761
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
762
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
763
+ 'choices_as_values ' => true ,
764
+ 'choice_label ' => function () {
765
+ return false ;
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
+ [
779
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
780
+ ]
781
+ ]
782
+ /following-sibling::div
783
+ [@class="radio"]
784
+ [
785
+ ./label
786
+ [
787
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
788
+ ]
789
+ ]
790
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
791
+ ]
792
+ '
793
+ );
794
+ }
795
+
673
796
public function testSingleChoiceExpandedWithoutTranslation ()
674
797
{
675
798
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
@@ -874,6 +997,129 @@ public function testMultipleChoiceExpanded()
874
997
);
875
998
}
876
999
1000
+ public function testMultipleChoiceExpandedWithLabelsAsFalse ()
1001
+ {
1002
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1003
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1004
+ 'choices_as_values ' => true ,
1005
+ 'choice_label ' => false ,
1006
+ 'multiple ' => true ,
1007
+ 'expanded ' => true ,
1008
+ ));
1009
+
1010
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1011
+ '/div
1012
+ [
1013
+ ./div
1014
+ [@class="checkbox"]
1015
+ [
1016
+ ./label
1017
+ [
1018
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1019
+ ]
1020
+ ]
1021
+ /following-sibling::div
1022
+ [@class="checkbox"]
1023
+ [
1024
+ ./label
1025
+ [
1026
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1027
+ ]
1028
+ ]
1029
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1030
+ ]
1031
+ '
1032
+ );
1033
+ }
1034
+
1035
+ public function testMultipleChoiceExpandedWithLabelsSetByCallable ()
1036
+ {
1037
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1038
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' ),
1039
+ 'choices_as_values ' => true ,
1040
+ 'choice_label ' => function ($ choice , $ label , $ value ) {
1041
+ if ('&b ' === $ choice ) {
1042
+ return false ;
1043
+ }
1044
+
1045
+ return 'label. ' .$ value ;
1046
+ },
1047
+ 'multiple ' => true ,
1048
+ 'expanded ' => true ,
1049
+ ));
1050
+
1051
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1052
+ '/div
1053
+ [
1054
+ ./div
1055
+ [@class="checkbox"]
1056
+ [
1057
+ ./label
1058
+ [.=" [trans]label.&a[/trans]"]
1059
+ [
1060
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1061
+ ]
1062
+ ]
1063
+ /following-sibling::div
1064
+ [@class="checkbox"]
1065
+ [
1066
+ ./label
1067
+ [
1068
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1069
+ ]
1070
+ ]
1071
+ /following-sibling::div
1072
+ [@class="checkbox"]
1073
+ [
1074
+ ./label
1075
+ [.=" [trans]label.&c[/trans]"]
1076
+ [
1077
+ ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)]
1078
+ ]
1079
+ ]
1080
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1081
+ ]
1082
+ '
1083
+ );
1084
+ }
1085
+
1086
+ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable ()
1087
+ {
1088
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
1089
+ 'choices ' => array ('Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ),
1090
+ 'choices_as_values ' => true ,
1091
+ 'choice_label ' => function () {
1092
+ return false ;
1093
+ },
1094
+ 'multiple ' => true ,
1095
+ 'expanded ' => true ,
1096
+ ));
1097
+
1098
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
1099
+ '/div
1100
+ [
1101
+ ./div
1102
+ [@class="checkbox"]
1103
+ [
1104
+ ./label
1105
+ [
1106
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked]
1107
+ ]
1108
+ ]
1109
+ /following-sibling::div
1110
+ [@class="checkbox"]
1111
+ [
1112
+ ./label
1113
+ [
1114
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
1115
+ ]
1116
+ ]
1117
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
1118
+ ]
1119
+ '
1120
+ );
1121
+ }
1122
+
877
1123
public function testMultipleChoiceExpandedWithoutTranslation ()
878
1124
{
879
1125
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' , '&c ' ), array (
0 commit comments