@@ -65,22 +65,56 @@ public function testCreateChoiceListWithValueCallback()
6565 $ this ->assertSame (array (1 => ':foo ' , 2 => ':baz ' ), $ choiceList ->getValuesForChoices (array (1 => 'foo ' , 2 => 'baz ' )));
6666 }
6767
68+ public function testCreateChoiceListWithoutValueCallbackAndDuplicateFreeToStringChoices ()
69+ {
70+ $ choiceList = new ArrayChoiceList (array (2 => 'foo ' , 7 => 'bar ' , 10 => 123 ));
71+
72+ $ this ->assertSame (array ('foo ' , 'bar ' , '123 ' ), $ choiceList ->getValues ());
73+ $ this ->assertSame (array ('foo ' => 'foo ' , 'bar ' => 'bar ' , '123 ' => 123 ), $ choiceList ->getChoices ());
74+ $ this ->assertSame (array ('foo ' => 2 , 'bar ' => 7 , '123 ' => 10 ), $ choiceList ->getOriginalKeys ());
75+ $ this ->assertSame (array (1 => 'foo ' , 2 => 123 ), $ choiceList ->getChoicesForValues (array (1 => 'foo ' , 2 => '123 ' )));
76+ $ this ->assertSame (array (1 => 'foo ' , 2 => '123 ' ), $ choiceList ->getValuesForChoices (array (1 => 'foo ' , 2 => 123 )));
77+ }
78+
79+ public function testCreateChoiceListWithoutValueCallbackAndToStringDuplicates ()
80+ {
81+ $ choiceList = new ArrayChoiceList (array (2 => 'foo ' , 7 => '123 ' , 10 => 123 ));
82+
83+ $ this ->assertSame (array ('0 ' , '1 ' , '2 ' ), $ choiceList ->getValues ());
84+ $ this ->assertSame (array ('0 ' => 'foo ' , '1 ' => '123 ' , '2 ' => 123 ), $ choiceList ->getChoices ());
85+ $ this ->assertSame (array ('0 ' => 2 , '1 ' => 7 , '2 ' => 10 ), $ choiceList ->getOriginalKeys ());
86+ $ this ->assertSame (array (1 => 'foo ' , 2 => 123 ), $ choiceList ->getChoicesForValues (array (1 => '0 ' , 2 => '2 ' )));
87+ $ this ->assertSame (array (1 => '0 ' , 2 => '2 ' ), $ choiceList ->getValuesForChoices (array (1 => 'foo ' , 2 => 123 )));
88+ }
89+
90+ public function testCreateChoiceListWithoutValueCallbackAndMixedChoices ()
91+ {
92+ $ object = new \stdClass ();
93+ $ choiceList = new ArrayChoiceList (array (2 => 'foo ' , 5 => array (7 => '123 ' ), 10 => $ object ));
94+
95+ $ this ->assertSame (array ('0 ' , '1 ' , '2 ' ), $ choiceList ->getValues ());
96+ $ this ->assertSame (array ('0 ' => 'foo ' , '1 ' => '123 ' , '2 ' => $ object ), $ choiceList ->getChoices ());
97+ $ this ->assertSame (array ('0 ' => 2 , '1 ' => 7 , '2 ' => 10 ), $ choiceList ->getOriginalKeys ());
98+ $ this ->assertSame (array (1 => 'foo ' , 2 => $ object ), $ choiceList ->getChoicesForValues (array (1 => '0 ' , 2 => '2 ' )));
99+ $ this ->assertSame (array (1 => '0 ' , 2 => '2 ' ), $ choiceList ->getValuesForChoices (array (1 => 'foo ' , 2 => $ object )));
100+ }
101+
68102 public function testCreateChoiceListWithGroupedChoices ()
69103 {
70104 $ choiceList = new ArrayChoiceList (array (
71105 'Group 1 ' => array ('A ' => 'a ' , 'B ' => 'b ' ),
72106 'Group 2 ' => array ('C ' => 'c ' , 'D ' => 'd ' ),
73107 ));
74108
75- $ this ->assertSame (array ('0 ' , '1 ' , '2 ' , '3 ' ), $ choiceList ->getValues ());
109+ $ this ->assertSame (array ('a ' , 'b ' , 'c ' , 'd ' ), $ choiceList ->getValues ());
76110 $ this ->assertSame (array (
77- 'Group 1 ' => array ('A ' => '0 ' , 'B ' => '1 ' ),
78- 'Group 2 ' => array ('C ' => '2 ' , 'D ' => '3 ' ),
111+ 'Group 1 ' => array ('A ' => 'a ' , 'B ' => 'b ' ),
112+ 'Group 2 ' => array ('C ' => 'c ' , 'D ' => 'd ' ),
79113 ), $ choiceList ->getStructuredValues ());
80- $ this ->assertSame (array (0 => 'a ' , 1 => 'b ' , 2 => 'c ' , 3 => 'd ' ), $ choiceList ->getChoices ());
81- $ this ->assertSame (array (0 => 'A ' , 1 => 'B ' , 2 => 'C ' , 3 => 'D ' ), $ choiceList ->getOriginalKeys ());
82- $ this ->assertSame (array (1 => 'a ' , 2 => 'b ' ), $ choiceList ->getChoicesForValues (array (1 => '0 ' , 2 => '1 ' )));
83- $ this ->assertSame (array (1 => '0 ' , 2 => '1 ' ), $ choiceList ->getValuesForChoices (array (1 => 'a ' , 2 => 'b ' )));
114+ $ this ->assertSame (array (' a ' => 'a ' , ' b ' => 'b ' , ' c ' => 'c ' , ' d ' => 'd ' ), $ choiceList ->getChoices ());
115+ $ this ->assertSame (array (' a ' => 'A ' , ' b ' => 'B ' , ' c ' => 'C ' , ' d ' => 'D ' ), $ choiceList ->getOriginalKeys ());
116+ $ this ->assertSame (array (1 => 'a ' , 2 => 'b ' ), $ choiceList ->getChoicesForValues (array (1 => 'a ' , 2 => 'b ' )));
117+ $ this ->assertSame (array (1 => 'a ' , 2 => 'b ' ), $ choiceList ->getValuesForChoices (array (1 => 'a ' , 2 => 'b ' )));
84118 }
85119
86120 public function testCompareChoicesByIdentityByDefault ()
0 commit comments