@@ -106,4 +106,185 @@ public function it_can_override_choices()
106106
107107 $ this ->assertEquals ('test ' , $ choice ->getOption ('selected ' ));
108108 }
109+
110+ /** @test */
111+ public function it_disables_select ()
112+ {
113+ $ options = [
114+ 'attr ' => ['class ' => 'choice-class ' ],
115+ 'choices ' => ['yes ' => 'Yes ' , 'no ' => 'No ' ],
116+ 'selected ' => 'yes '
117+ ];
118+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
119+ $ children = $ field ->getChildren ();
120+
121+ // there shall be no 'disabled' attribute set beforehand
122+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
123+ foreach ($ children as $ child ) {
124+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
125+ }
126+
127+ $ field ->disable ();
128+
129+ // there shall be 'disabled' attribute set after
130+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
131+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
132+ foreach ($ children as $ child ) {
133+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
134+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
135+ }
136+ }
137+
138+ /** @test */
139+ public function it_disables_checkbox_list ()
140+ {
141+ $ options = [
142+ 'attr ' => ['class ' => 'choice-class-something ' ],
143+ 'choices ' => [1 => 'monday ' , 2 => 'tuesday ' ],
144+ 'selected ' => 'tuesday ' ,
145+ 'multiple ' => true ,
146+ 'expanded ' => true
147+ ];
148+
149+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
150+ $ children = $ field ->getChildren ();
151+
152+ // there shall be no 'disabled' attribute set beforehand
153+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
154+ foreach ($ children as $ child ) {
155+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
156+ }
157+
158+ $ field ->disable ();
159+
160+ // there shall be 'disabled' attribute set after
161+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
162+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
163+ foreach ($ children as $ child ) {
164+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
165+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
166+ }
167+ }
168+
169+ /** @test */
170+ public function it_disables_radios_list ()
171+ {
172+ $ options = [
173+ 'attr ' => ['class ' => 'choice-class-something ' ],
174+ 'choices ' => [1 => 'yes ' , 2 => 'no ' ],
175+ 'selected ' => 'no ' ,
176+ 'expanded ' => true
177+ ];
178+
179+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
180+ $ children = $ field ->getChildren ();
181+
182+ // there shall be no 'disabled' attribute set beforehand
183+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
184+ foreach ($ children as $ child ) {
185+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
186+ }
187+
188+ $ field ->disable ();
189+
190+ // there shall be 'disabled' attribute set after
191+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
192+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
193+ foreach ($ children as $ child ) {
194+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
195+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
196+ }
197+ }
198+
199+ /** @test */
200+ public function it_enables_select ()
201+ {
202+ $ options = [
203+ 'attr ' => ['class ' => 'choice-class ' , 'disabled ' => 'disabled ' ],
204+ 'choices ' => ['yes ' => 'Yes ' , 'no ' => 'No ' ],
205+ 'selected ' => 'yes '
206+ ];
207+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
208+ $ children = $ field ->getChildren ();
209+
210+ // there shall be 'disabled' attribute set beforehand
211+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
212+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
213+ foreach ($ children as $ child ) {
214+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
215+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
216+ }
217+
218+
219+ $ field ->enable ();
220+
221+ // there shall be no 'disabled' attribute set after
222+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
223+ foreach ($ children as $ child ) {
224+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
225+ }
226+ }
227+
228+ /** @test */
229+ public function it_enables_checkbox_list ()
230+ {
231+ $ options = [
232+ 'attr ' => ['class ' => 'choice-class-something ' , 'disabled ' => 'disabled ' ],
233+ 'choices ' => [1 => 'monday ' , 2 => 'tuesday ' ],
234+ 'selected ' => 'tuesday ' ,
235+ 'multiple ' => true ,
236+ 'expanded ' => true
237+ ];
238+
239+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
240+ $ children = $ field ->getChildren ();
241+
242+ // there shall be 'disabled' attribute set beforehand
243+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
244+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
245+ foreach ($ children as $ child ) {
246+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
247+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
248+ }
249+
250+
251+ $ field ->enable ();
252+
253+ // there shall be no 'disabled' attribute set after
254+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
255+ foreach ($ children as $ child ) {
256+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
257+ }
258+ }
259+
260+ /** @test */
261+ public function it_enables_radios_list ()
262+ {
263+ $ options = [
264+ 'attr ' => ['class ' => 'choice-class-something ' , 'disabled ' => 'disabled ' ],
265+ 'choices ' => [1 => 'yes ' , 2 => 'no ' ],
266+ 'selected ' => 'no ' ,
267+ 'expanded ' => true
268+ ];
269+
270+ $ field = new ChoiceType ('some_choice ' , 'choice ' , $ this ->plainForm , $ options );
271+ $ children = $ field ->getChildren ();
272+
273+ // there shall be 'disabled' attribute set beforehand
274+ $ this ->assertArrayHasKey ('disabled ' , $ field ->getOption ('attr ' ));
275+ $ this ->assertEquals ('disabled ' , $ field ->getOption ('attr ' )['disabled ' ]);
276+ foreach ($ children as $ child ) {
277+ $ this ->assertArrayHasKey ('disabled ' , $ child ->getOption ('attr ' ));
278+ $ this ->assertEquals ('disabled ' , $ child ->getOption ('attr ' )['disabled ' ]);
279+ }
280+
281+
282+ $ field ->enable ();
283+
284+ // there shall be no 'disabled' attribute set after
285+ $ this ->assertArrayNotHasKey ('disabled ' , $ field ->getOption ('attr ' ));
286+ foreach ($ children as $ child ) {
287+ $ this ->assertArrayNotHasKey ('disabled ' , $ child ->getOption ('attr ' ));
288+ }
289+ }
109290}
0 commit comments