Skip to content

Commit 709ac51

Browse files
committed
Added some unit tests to verify that translations are disabled when translation_domain is set to false on form.
1 parent bc63700 commit 709ac51

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,32 @@ public function testSingleChoiceWithoutTranslation()
254254
);
255255
}
256256

257+
public function testSingleChoiceWithPlaceholderWithoutTranslation()
258+
{
259+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
260+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
261+
'multiple' => false,
262+
'expanded' => false,
263+
'required' => false,
264+
'translation_domain' => false,
265+
'placeholder' => 'Placeholder&Not&Translated',
266+
));
267+
268+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
269+
'/select
270+
[@name="name"]
271+
[@class="my&class form-control"]
272+
[not(@required)]
273+
[
274+
./option[@value=""][not(@selected)][not(@disabled)][.="Placeholder&Not&Translated"]
275+
/following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"]
276+
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
277+
]
278+
[count(./option)=3]
279+
'
280+
);
281+
}
282+
257283
public function testSingleChoiceAttributes()
258284
{
259285
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
@@ -771,6 +797,52 @@ public function testSingleChoiceExpandedWithPlaceholder()
771797
);
772798
}
773799

800+
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
801+
{
802+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
803+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
804+
'multiple' => false,
805+
'expanded' => true,
806+
'translation_domain' => false,
807+
'placeholder' => 'Placeholder&Not&Translated',
808+
));
809+
810+
$this->assertWidgetMatchesXpath($form->createView(), array(),
811+
'/div
812+
[
813+
./div
814+
[@class="radio"]
815+
[
816+
./label
817+
[.=" Placeholder&Not&Translated"]
818+
[
819+
./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)]
820+
]
821+
]
822+
/following-sibling::div
823+
[@class="radio"]
824+
[
825+
./label
826+
[.=" Choice&A"]
827+
[
828+
./input[@type="radio"][@name="name"][@id="name_0"][@checked]
829+
]
830+
]
831+
/following-sibling::div
832+
[@class="radio"]
833+
[
834+
./label
835+
[.=" Choice&B"]
836+
[
837+
./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
838+
]
839+
]
840+
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
841+
]
842+
'
843+
);
844+
}
845+
774846
public function testSingleChoiceExpandedWithBooleanValue()
775847
{
776848
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
@@ -2023,6 +2095,17 @@ public function testButton()
20232095
);
20242096
}
20252097

2098+
public function testButtonlabelWithoutTranslation()
2099+
{
2100+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, array(
2101+
'translation_domain' => false,
2102+
));
2103+
2104+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
2105+
'/button[@type="button"][@name="name"][.="Name"][@class="my&class btn"]'
2106+
);
2107+
}
2108+
20262109
public function testSubmit()
20272110
{
20282111
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ public function testLabelFormatOverriddenOption()
381381
);
382382
}
383383

384+
public function testLabelWithoutTranslationOnButton()
385+
{
386+
$form = $this->factory->createNamedBuilder('myform', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
387+
'translation_domain' => false,
388+
))
389+
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType')
390+
->getForm();
391+
$view = $form->get('mybutton')->createView();
392+
$html = $this->renderWidget($view);
393+
394+
$this->assertMatchesXpath($html,
395+
'/button
396+
[@type="button"]
397+
[@name="myform[mybutton]"]
398+
[.="Mybutton"]
399+
'
400+
);
401+
}
402+
384403
public function testLabelFormatOnButton()
385404
{
386405
$form = $this->factory->createNamedBuilder('myform')
@@ -549,6 +568,31 @@ public function testSingleChoiceWithoutTranslation()
549568
);
550569
}
551570

571+
public function testSingleChoiceWithPlaceholderWithoutTranslation()
572+
{
573+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
574+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
575+
'multiple' => false,
576+
'expanded' => false,
577+
'required' => false,
578+
'translation_domain' => false,
579+
'placeholder' => 'Placeholder&Not&Translated',
580+
));
581+
582+
$this->assertWidgetMatchesXpath($form->createView(), array(),
583+
'/select
584+
[@name="name"]
585+
[not(@required)]
586+
[
587+
./option[@value=""][not(@selected)][not(@disabled)][.="Placeholder&Not&Translated"]
588+
/following-sibling::option[@value="&a"][@selected="selected"][.="Choice&A"]
589+
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
590+
]
591+
[count(./option)=3]
592+
'
593+
);
594+
}
595+
552596
public function testSingleChoiceAttributes()
553597
{
554598
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
@@ -998,6 +1042,32 @@ public function testSingleChoiceExpandedWithPlaceholder()
9981042
);
9991043
}
10001044

1045+
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
1046+
{
1047+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
1048+
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
1049+
'multiple' => false,
1050+
'expanded' => true,
1051+
'translation_domain' => false,
1052+
'placeholder' => 'Placeholder&Not&Translated',
1053+
));
1054+
1055+
$this->assertWidgetMatchesXpath($form->createView(), array(),
1056+
'/div
1057+
[
1058+
./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)]
1059+
/following-sibling::label[@for="name_placeholder"][.="Placeholder&Not&Translated"]
1060+
/following-sibling::input[@type="radio"][@name="name"][@id="name_0"][@checked]
1061+
/following-sibling::label[@for="name_0"][.="Choice&A"]
1062+
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][not(@checked)]
1063+
/following-sibling::label[@for="name_1"][.="Choice&B"]
1064+
/following-sibling::input[@type="hidden"][@id="name__token"]
1065+
]
1066+
[count(./input)=4]
1067+
'
1068+
);
1069+
}
1070+
10011071
public function testSingleChoiceExpandedWithBooleanValue()
10021072
{
10031073
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
@@ -2141,6 +2211,17 @@ public function testButtonLabelIsEmpty()
21412211
$this->assertSame('', $this->renderLabel($form->createView()));
21422212
}
21432213

2214+
public function testButtonlabelWithoutTranslation()
2215+
{
2216+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, array(
2217+
'translation_domain' => false,
2218+
));
2219+
2220+
$this->assertWidgetMatchesXpath($form->createView(), array(),
2221+
'/button[@type="button"][@name="name"][.="Name"]'
2222+
);
2223+
}
2224+
21442225
public function testSubmit()
21452226
{
21462227
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');
@@ -2349,4 +2430,20 @@ public function testTranslatedAttributes()
23492430
$this->assertMatchesXpath($html, '/form//input[@title="[trans]Foo[/trans]"]');
23502431
$this->assertMatchesXpath($html, '/form//input[@placeholder="[trans]Bar[/trans]"]');
23512432
}
2433+
2434+
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
2435+
{
2436+
$view = $this->factory->createNamedBuilder('name', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
2437+
'translation_domain' => false,
2438+
))
2439+
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', array('attr' => array('title' => 'Foo')))
2440+
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType', array('attr' => array('placeholder' => 'Bar')))
2441+
->getForm()
2442+
->createView();
2443+
2444+
$html = $this->renderForm($view);
2445+
2446+
$this->assertMatchesXpath($html, '/form//input[@title="Foo"]');
2447+
$this->assertMatchesXpath($html, '/form//input[@placeholder="Bar"]');
2448+
}
23522449
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy