@@ -231,6 +231,29 @@ public function testSingleChoice()
231
231
);
232
232
}
233
233
234
+ public function testSingleChoiceAttributes ()
235
+ {
236
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
237
+ 'choices ' => array ('&a ' => 'Choice&A ' , '&b ' => 'Choice&B ' ),
238
+ 'choice_attr ' => array ('Choice&B ' => array ('class ' => 'foo&bar ' )),
239
+ 'multiple ' => false ,
240
+ 'expanded ' => false ,
241
+ ));
242
+
243
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array ('attr ' => array ('class ' => 'my&class ' )),
244
+ '/select
245
+ [@name="name"]
246
+ [@class="my&class form-control"]
247
+ [not(@required)]
248
+ [
249
+ ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
250
+ /following-sibling::option[@value="&b"][@class="foo&bar"][not(@selected)][.="[trans]Choice&B[/trans]"]
251
+ ]
252
+ [count(./option)=2]
253
+ '
254
+ );
255
+ }
256
+
234
257
public function testSingleChoiceWithPreferred ()
235
258
{
236
259
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
@@ -496,6 +519,31 @@ public function testMultipleChoice()
496
519
);
497
520
}
498
521
522
+ public function testMultipleChoiceAttributes ()
523
+ {
524
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
525
+ 'choices ' => array ('&a ' => 'Choice&A ' , '&b ' => 'Choice&B ' ),
526
+ 'choice_attr ' => array ('Choice&B ' => array ('class ' => 'foo&bar ' )),
527
+ 'required ' => true ,
528
+ 'multiple ' => true ,
529
+ 'expanded ' => false ,
530
+ ));
531
+
532
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array ('attr ' => array ('class ' => 'my&class ' )),
533
+ '/select
534
+ [@name="name[]"]
535
+ [@class="my&class form-control"]
536
+ [@required="required"]
537
+ [@multiple="multiple"]
538
+ [
539
+ ./option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
540
+ /following-sibling::option[@value="&b"][@class="foo&bar"][not(@selected)][.="[trans]Choice&B[/trans]"]
541
+ ]
542
+ [count(./option)=2]
543
+ '
544
+ );
545
+ }
546
+
499
547
public function testMultipleChoiceSkipsPlaceholder ()
500
548
{
501
549
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' ), array (
@@ -577,6 +625,42 @@ public function testSingleChoiceExpanded()
577
625
);
578
626
}
579
627
628
+ public function testSingleChoiceExpandedAttributes ()
629
+ {
630
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
631
+ 'choices ' => array ('&a ' => 'Choice&A ' , '&b ' => 'Choice&B ' ),
632
+ 'choice_attr ' => array ('Choice&B ' => array ('class ' => 'foo&bar ' )),
633
+ 'multiple ' => false ,
634
+ 'expanded ' => true ,
635
+ ));
636
+
637
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
638
+ '/div
639
+ [
640
+ ./div
641
+ [@class="radio"]
642
+ [
643
+ ./label
644
+ [.="[trans]Choice&A[/trans]"]
645
+ [
646
+ ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
647
+ ]
648
+ ]
649
+ /following-sibling::div
650
+ [@class="radio"]
651
+ [
652
+ ./label
653
+ [.="[trans]Choice&B[/trans]"]
654
+ [
655
+ ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)][@class="foo&bar"]
656
+ ]
657
+ ]
658
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
659
+ ]
660
+ '
661
+ );
662
+ }
663
+
580
664
public function testSingleChoiceExpandedWithPlaceholder ()
581
665
{
582
666
$ form = $ this ->factory ->createNamed ('name ' , 'choice ' , '&a ' , array (
@@ -702,6 +786,52 @@ public function testMultipleChoiceExpanded()
702
786
);
703
787
}
704
788
789
+ public function testMultipleChoiceExpandedAttributes ()
790
+ {
791
+ $ form = $ this ->factory ->createNamed ('name ' , 'choice ' , array ('&a ' , '&c ' ), array (
792
+ 'choices ' => array ('&a ' => 'Choice&A ' , '&b ' => 'Choice&B ' , '&c ' => 'Choice&C ' ),
793
+ 'choice_attr ' => array ('Choice&B ' => array ('class ' => 'foo&bar ' )),
794
+ 'multiple ' => true ,
795
+ 'expanded ' => true ,
796
+ 'required ' => true ,
797
+ ));
798
+
799
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), array (),
800
+ '/div
801
+ [
802
+ ./div
803
+ [@class="checkbox"]
804
+ [
805
+ ./label
806
+ [.="[trans]Choice&A[/trans]"]
807
+ [
808
+ ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
809
+ ]
810
+ ]
811
+ /following-sibling::div
812
+ [@class="checkbox"]
813
+ [
814
+ ./label
815
+ [.="[trans]Choice&B[/trans]"]
816
+ [
817
+ ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)][@class="foo&bar"]
818
+ ]
819
+ ]
820
+ /following-sibling::div
821
+ [@class="checkbox"]
822
+ [
823
+ ./label
824
+ [.="[trans]Choice&C[/trans]"]
825
+ [
826
+ ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
827
+ ]
828
+ ]
829
+ /following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
830
+ ]
831
+ '
832
+ );
833
+ }
834
+
705
835
public function testCountry ()
706
836
{
707
837
$ form = $ this ->factory ->createNamed ('name ' , 'country ' , 'AT ' );
0 commit comments