@@ -870,6 +870,56 @@ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable()
870
870
);
871
871
}
872
872
873
+ public function testSingleChoiceWithoutDuplicatePreferredIsSelected ()
874
+ {
875
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&d ' , [
876
+ 'choices ' => ['Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' , 'Choice&D ' => '&d ' ],
877
+ 'preferred_choices ' => ['&b ' , '&d ' ],
878
+ 'duplicate_preferred_choices ' => false ,
879
+ 'multiple ' => false ,
880
+ 'expanded ' => false ,
881
+ ]);
882
+
883
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), ['separator ' => '-- sep -- ' ],
884
+ '/select
885
+ [@name="name"]
886
+ [
887
+ ./option[@value="&d"][@selected="selected"]
888
+ /following-sibling::option[@disabled="disabled"][.="-- sep --"]
889
+ /following-sibling::option[@value="&a"][not(@selected)]
890
+ /following-sibling::option[@value="&c"][not(@selected)]
891
+ ]
892
+ [count(./option)=5]
893
+ '
894
+ );
895
+ }
896
+
897
+ public function testSingleChoiceWithoutDuplicateNotPreferredIsSelected ()
898
+ {
899
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&d ' , [
900
+ 'choices ' => ['Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' , 'Choice&D ' => '&d ' ],
901
+ 'preferred_choices ' => ['&b ' , '&d ' ],
902
+ 'duplicate_preferred_choices ' => true ,
903
+ 'multiple ' => false ,
904
+ 'expanded ' => false ,
905
+ ]);
906
+
907
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), ['separator ' => '-- sep -- ' ],
908
+ '/select
909
+ [@name="name"]
910
+ [
911
+ ./option[@value="&d"][not(@selected)]
912
+ /following-sibling::option[@disabled="disabled"][.="-- sep --"]
913
+ /following-sibling::option[@value="&a"][not(@selected)]
914
+ /following-sibling::option[@value="&b"][not(@selected)]
915
+ /following-sibling::option[@value="&c"][not(@selected)]
916
+ /following-sibling::option[@value="&d"][@selected="selected"]
917
+ ]
918
+ [count(./option)=7]
919
+ '
920
+ );
921
+ }
922
+
873
923
public function testFormEndWithRest ()
874
924
{
875
925
$ view = $ this ->factory ->createNamedBuilder ('name ' , 'Symfony\Component\Form\Extension\Core\Type\FormType ' )
0 commit comments