@@ -856,6 +856,56 @@ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable()
856856 );
857857 }
858858
859+ public function testSingleChoiceWithoutDuplicatePreferredIsSelected ()
860+ {
861+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&d ' , [
862+ 'choices ' => ['Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' , 'Choice&D ' => '&d ' ],
863+ 'preferred_choices ' => ['&b ' , '&d ' ],
864+ 'duplicate_preferred_choices ' => false ,
865+ 'multiple ' => false ,
866+ 'expanded ' => false ,
867+ ]);
868+
869+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), ['separator ' => '-- sep -- ' ],
870+ '/select
871+ [@name="name"]
872+ [
873+ ./option[@value="&d"][@selected="selected"]
874+ /following-sibling::option[@disabled="disabled"][.="-- sep --"]
875+ /following-sibling::option[@value="&a"][not(@selected)]
876+ /following-sibling::option[@value="&c"][not(@selected)]
877+ ]
878+ [count(./option)=5]
879+ '
880+ );
881+ }
882+
883+ public function testSingleChoiceWithoutDuplicateNotPreferredIsSelected ()
884+ {
885+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&d ' , [
886+ 'choices ' => ['Choice&A ' => '&a ' , 'Choice&B ' => '&b ' , 'Choice&C ' => '&c ' , 'Choice&D ' => '&d ' ],
887+ 'preferred_choices ' => ['&b ' , '&d ' ],
888+ 'duplicate_preferred_choices ' => true ,
889+ 'multiple ' => false ,
890+ 'expanded ' => false ,
891+ ]);
892+
893+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), ['separator ' => '-- sep -- ' ],
894+ '/select
895+ [@name="name"]
896+ [
897+ ./option[@value="&d"][not(@selected)]
898+ /following-sibling::option[@disabled="disabled"][.="-- sep --"]
899+ /following-sibling::option[@value="&a"][not(@selected)]
900+ /following-sibling::option[@value="&b"][not(@selected)]
901+ /following-sibling::option[@value="&c"][not(@selected)]
902+ /following-sibling::option[@value="&d"][@selected="selected"]
903+ ]
904+ [count(./option)=7]
905+ '
906+ );
907+ }
908+
859909 public function testFormEndWithRest ()
860910 {
861911 $ view = $ this ->factory ->createNamedBuilder ('name ' , 'Symfony\Component\Form\Extension\Core\Type\FormType ' )
0 commit comments