Skip to content

Commit 93cf17e

Browse files
committed
Fix choice translation domain for expanded choice widget
1 parent 63c4964 commit 93cf17e

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,29 @@ public function testSingleChoice()
231231
);
232232
}
233233

234+
public function testSingleChoiceWithoutTranslation()
235+
{
236+
$form = $this->factory->createNamed('name', 'choice', '&a', array(
237+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
238+
'multiple' => false,
239+
'expanded' => false,
240+
'choice_translation_domain' => 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"][.="Choice&A"]
250+
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
251+
]
252+
[count(./option)=2]
253+
'
254+
);
255+
}
256+
234257
public function testSingleChoiceAttributes()
235258
{
236259
$form = $this->factory->createNamed('name', 'choice', '&a', array(
@@ -629,6 +652,42 @@ public function testSingleChoiceExpanded()
629652
);
630653
}
631654

655+
public function testSingleChoiceExpandedWithoutTranslation()
656+
{
657+
$form = $this->factory->createNamed('name', 'choice', '&a', array(
658+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
659+
'multiple' => false,
660+
'expanded' => true,
661+
'choice_translation_domain' => false,
662+
));
663+
664+
$this->assertWidgetMatchesXpath($form->createView(), array(),
665+
'/div
666+
[
667+
./div
668+
[@class="radio"]
669+
[
670+
./label
671+
[.="Choice&A"]
672+
[
673+
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
674+
]
675+
]
676+
/following-sibling::div
677+
[@class="radio"]
678+
[
679+
./label
680+
[.="Choice&B"]
681+
[
682+
./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
683+
]
684+
]
685+
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
686+
]
687+
'
688+
);
689+
}
690+
632691
public function testSingleChoiceExpandedAttributes()
633692
{
634693
$form = $this->factory->createNamed('name', 'choice', '&a', array(
@@ -792,6 +851,52 @@ public function testMultipleChoiceExpanded()
792851
);
793852
}
794853

854+
public function testMultipleChoiceExpandedWithoutTranslation()
855+
{
856+
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
857+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'),
858+
'multiple' => true,
859+
'expanded' => true,
860+
'required' => true,
861+
'choice_translation_domain' => false,
862+
));
863+
864+
$this->assertWidgetMatchesXpath($form->createView(), array(),
865+
'/div
866+
[
867+
./div
868+
[@class="checkbox"]
869+
[
870+
./label
871+
[.="Choice&A"]
872+
[
873+
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
874+
]
875+
]
876+
/following-sibling::div
877+
[@class="checkbox"]
878+
[
879+
./label
880+
[.="Choice&B"]
881+
[
882+
./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
883+
]
884+
]
885+
/following-sibling::div
886+
[@class="checkbox"]
887+
[
888+
./label
889+
[.="Choice&C"]
890+
[
891+
./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
892+
]
893+
]
894+
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
895+
]
896+
'
897+
);
898+
}
899+
795900
public function testMultipleChoiceExpandedAttributes()
796901
{
797902
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(

Tests/AbstractLayoutTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ public function testLabel()
168168
);
169169
}
170170

171+
public function testLabelWithoutTranslation()
172+
{
173+
$form = $this->factory->createNamed('name', 'text', null, array(
174+
'translation_domain' => false,
175+
));
176+
177+
$this->assertMatchesXpath($this->renderLabel($form->createView()),
178+
'/label
179+
[@for="name"]
180+
[.="Name"]
181+
'
182+
);
183+
}
184+
171185
public function testLabelOnForm()
172186
{
173187
$form = $this->factory->createNamed('name', 'date');
@@ -513,6 +527,28 @@ public function testSingleChoice()
513527
);
514528
}
515529

530+
public function testSingleChoiceWithoutTranslation()
531+
{
532+
$form = $this->factory->createNamed('name', 'choice', '&a', array(
533+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
534+
'multiple' => false,
535+
'expanded' => false,
536+
'choice_translation_domain' => false,
537+
));
538+
539+
$this->assertWidgetMatchesXpath($form->createView(), array(),
540+
'/select
541+
[@name="name"]
542+
[not(@required)]
543+
[
544+
./option[@value="&a"][@selected="selected"][.="Choice&A"]
545+
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
546+
]
547+
[count(./option)=2]
548+
'
549+
);
550+
}
551+
516552
public function testSingleChoiceAttributes()
517553
{
518554
$form = $this->factory->createNamed('name', 'choice', '&a', array(
@@ -889,6 +925,29 @@ public function testSingleChoiceExpanded()
889925
);
890926
}
891927

928+
public function testSingleChoiceExpandedWithoutTranslation()
929+
{
930+
$form = $this->factory->createNamed('name', 'choice', '&a', array(
931+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
932+
'multiple' => false,
933+
'expanded' => true,
934+
'choice_translation_domain' => false,
935+
));
936+
937+
$this->assertWidgetMatchesXpath($form->createView(), array(),
938+
'/div
939+
[
940+
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
941+
/following-sibling::label[@for="name_0"][.="Choice&A"]
942+
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
943+
/following-sibling::label[@for="name_1"][.="Choice&B"]
944+
/following-sibling::input[@type="hidden"][@id="name__token"]
945+
]
946+
[count(./input)=3]
947+
'
948+
);
949+
}
950+
892951
public function testSingleChoiceExpandedAttributes()
893952
{
894953
$form = $this->factory->createNamed('name', 'choice', '&a', array(
@@ -986,6 +1045,32 @@ public function testMultipleChoiceExpanded()
9861045
);
9871046
}
9881047

1048+
public function testMultipleChoiceExpandedWithoutTranslation()
1049+
{
1050+
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
1051+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'),
1052+
'multiple' => true,
1053+
'expanded' => true,
1054+
'required' => true,
1055+
'choice_translation_domain' => false,
1056+
));
1057+
1058+
$this->assertWidgetMatchesXpath($form->createView(), array(),
1059+
'/div
1060+
[
1061+
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
1062+
/following-sibling::label[@for="name_0"][.="Choice&A"]
1063+
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
1064+
/following-sibling::label[@for="name_1"][.="Choice&B"]
1065+
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
1066+
/following-sibling::label[@for="name_2"][.="Choice&C"]
1067+
/following-sibling::input[@type="hidden"][@id="name__token"]
1068+
]
1069+
[count(./input)=4]
1070+
'
1071+
);
1072+
}
1073+
9891074
public function testMultipleChoiceExpandedAttributes()
9901075
{
9911076
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(

0 commit comments

Comments
 (0)