@@ -100,6 +100,14 @@ public function testChoiceLoaderOptionExpectsChoiceLoaderInterface()
100100 ]);
101101 }
102102
103+ public function testPlaceholderAttrOptionExpectsArray ()
104+ {
105+ $ this ->expectException (InvalidOptionsException::class);
106+ $ this ->factory ->create (static ::TESTED_TYPE , null , [
107+ 'placeholder_attr ' => new \stdClass (),
108+ ]);
109+ }
110+
103111 public function testChoiceListAndChoicesCanBeEmpty ()
104112 {
105113 $ this ->assertInstanceOf (FormInterface::class, $ this ->factory ->create (static ::TESTED_TYPE , null , []));
@@ -189,15 +197,19 @@ public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetDa
189197
190198 public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice ()
191199 {
200+ $ placeholderAttr = ['attr ' => 'value ' ];
201+
192202 $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
193203 'multiple ' => false ,
194204 'expanded ' => true ,
195205 'required ' => false ,
196206 'choices ' => $ this ->choices ,
207+ 'placeholder_attr ' => $ placeholderAttr ,
197208 ]);
198209
199210 $ this ->assertArrayHasKey ('placeholder ' , $ form );
200211 $ this ->assertCount (\count ($ this ->choices ) + 1 , $ form , 'Each choice should become a new field ' );
212+ $ this ->assertSame ($ placeholderAttr , $ form ->createView ()->children ['placeholder ' ]->vars ['attr ' ]);
201213 }
202214
203215 public function testPlaceholderNotPresentIfRequired ()
@@ -1669,80 +1681,84 @@ public function testPlaceholderIsEmptyStringByDefaultIfNotRequired()
16691681 /**
16701682 * @dataProvider getOptionsWithPlaceholder
16711683 */
1672- public function testPassPlaceholderToView ($ multiple , $ expanded , $ required , $ placeholder , $ viewValue )
1684+ public function testPassPlaceholderToView ($ multiple , $ expanded , $ required , $ placeholder , $ placeholderViewValue , $ placeholderAttr , $ placeholderAttrViewValue )
16731685 {
16741686 $ view = $ this ->factory ->create (static ::TESTED_TYPE , null , [
16751687 'multiple ' => $ multiple ,
16761688 'expanded ' => $ expanded ,
16771689 'required ' => $ required ,
16781690 'placeholder ' => $ placeholder ,
1691+ 'placeholder_attr ' => $ placeholderAttr ,
16791692 'choices ' => $ this ->choices ,
16801693 ])
16811694 ->createView ();
16821695
1683- $ this ->assertSame ($ viewValue , $ view ->vars ['placeholder ' ]);
1696+ $ this ->assertSame ($ placeholderViewValue , $ view ->vars ['placeholder ' ]);
1697+ $ this ->assertSame ($ placeholderAttrViewValue , $ view ->vars ['placeholder_attr ' ]);
16841698 $ this ->assertFalse ($ view ->vars ['placeholder_in_choices ' ]);
16851699 }
16861700
16871701 /**
16881702 * @dataProvider getOptionsWithPlaceholder
16891703 */
1690- public function testDontPassPlaceholderIfContainedInChoices ($ multiple , $ expanded , $ required , $ placeholder , $ viewValue )
1704+ public function testDontPassPlaceholderIfContainedInChoices ($ multiple , $ expanded , $ required , $ placeholder , $ placeholderViewValue , $ placeholderAttr , $ placeholderAttrViewValue )
16911705 {
16921706 $ view = $ this ->factory ->create (static ::TESTED_TYPE , null , [
16931707 'multiple ' => $ multiple ,
16941708 'expanded ' => $ expanded ,
16951709 'required ' => $ required ,
16961710 'placeholder ' => $ placeholder ,
1711+ 'placeholder_attr ' => $ placeholderAttr ,
16971712 'choices ' => ['Empty ' => '' , 'A ' => 'a ' ],
16981713 ])
16991714 ->createView ();
17001715
17011716 $ this ->assertNull ($ view ->vars ['placeholder ' ]);
1717+ $ this ->assertSame ([], $ view ->vars ['placeholder_attr ' ]);
17021718 $ this ->assertTrue ($ view ->vars ['placeholder_in_choices ' ]);
17031719 }
17041720
17051721 public function getOptionsWithPlaceholder ()
17061722 {
17071723 return [
17081724 // single non-expanded
1709- [false , false , false , 'foobar ' , 'foobar ' ],
1710- [false , false , false , '' , '' ],
1711- [false , false , false , null , null ],
1712- [false , false , false , false , null ],
1713- [false , false , true , 'foobar ' , 'foobar ' ],
1714- [false , false , true , '' , '' ],
1715- [false , false , true , null , null ],
1716- [false , false , true , false , null ],
1725+ [false , false , false , 'foobar ' , 'foobar ' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
1726+ [false , false , false , '' , '' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
1727+ [false , false , false , null , null , [ ' attr ' => ' value ' ], [] ],
1728+ [false , false , false , false , null , [ ' attr ' => ' value ' ], [] ],
1729+ [false , false , true , 'foobar ' , 'foobar ' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
1730+ [false , false , true , '' , '' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
1731+ [false , false , true , null , null , [ ' attr ' => ' value ' ], [] ],
1732+ [false , false , true , false , null , [ ' attr ' => ' value ' ], [] ],
17171733 // single expanded
1718- [false , true , false , 'foobar ' , 'foobar ' ],
1734+ [false , true , false , 'foobar ' , 'foobar ' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
17191735 // radios should never have an empty label
1720- [false , true , false , '' , 'None ' ],
1721- [false , true , false , null , null ],
1722- [false , true , false , false , null ],
1736+ [false , true , false , '' , 'None ' , [ ' attr ' => ' value ' ], [ ' attr ' => ' value ' ] ],
1737+ [false , true , false , null , null , [ ' attr ' => ' value ' ], [] ],
1738+ [false , true , false , false , null , [ ' attr ' => ' value ' ], [] ],
17231739 // required radios should never have a placeholder
1724- [false , true , true , 'foobar ' , null ],
1725- [false , true , true , '' , null ],
1726- [false , true , true , null , null ],
1727- [false , true , true , false , null ],
1740+ [false , true , true , 'foobar ' , null , [ ' attr ' => ' value ' ], [] ],
1741+ [false , true , true , '' , null , [ ' attr ' => ' value ' ], [] ],
1742+ [false , true , true , null , null , [ ' attr ' => ' value ' ], [] ],
1743+ [false , true , true , false , null , [ ' attr ' => ' value ' ], [] ],
17281744 // multiple non-expanded
1729- [true , false , false , 'foobar ' , null ],
1730- [true , false , false , '' , null ],
1731- [true , false , false , null , null ],
1732- [true , false , false , false , null ],
1733- [true , false , true , 'foobar ' , null ],
1734- [true , false , true , '' , null ],
1735- [true , false , true , null , null ],
1736- [true , false , true , false , null ],
1745+ [true , false , false , 'foobar ' , null , [ ' attr ' => ' value ' ], [] ],
1746+ [true , false , false , '' , null , [ ' attr ' => ' value ' ], [] ],
1747+ [true , false , false , null , null , [ ' attr ' => ' value ' ], [] ],
1748+ [true , false , false , false , null , [ ' attr ' => ' value ' ], [] ],
1749+ [true , false , true , 'foobar ' , null , [ ' attr ' => ' value ' ], [] ],
1750+ [true , false , true , '' , null , [ ' attr ' => ' value ' ], [] ],
1751+ [true , false , true , null , null , [ ' attr ' => ' value ' ], [] ],
1752+ [true , false , true , false , null , [ ' attr ' => ' value ' ], [] ],
17371753 // multiple expanded
1738- [true , true , false , 'foobar ' , null ],
1739- [true , true , false , '' , null ],
1740- [true , true , false , null , null ],
1741- [true , true , false , false , null ],
1742- [true , true , true , 'foobar ' , null ],
1743- [true , true , true , '' , null ],
1744- [true , true , true , null , null ],
1745- [true , true , true , false , null ],
1754+ [true , true , false , 'foobar ' , null , [ ' attr ' => ' value ' ], [] ],
1755+ [true , true , false , '' , null , [ ' attr ' => ' value ' ], [] ],
1756+ [true , true , false , null , null , [ ' attr ' => ' value ' ], [] ],
1757+ [true , true , false , false , null , [ ' attr ' => ' value ' ], [] ],
1758+ [true , true , true , 'foobar ' , null , [ ' attr ' => ' value ' ], [] ],
1759+ [true , true , true , '' , null , [ ' attr ' => ' value ' ], [] ],
1760+ [true , true , true , null , null , [ ' attr ' => ' value ' ], [] ],
1761+ [true , true , true , false , null , [ ' attr ' => ' value ' ], [] ],
17461762 ];
17471763 }
17481764
0 commit comments