Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d132bbe

Browse files
committed
fix tests with bootstrap
1 parent acf2556 commit d132bbe

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@
9191
{% if empty_choices is not defined -%}
9292
{{- parent() -}}
9393
{%- else -%}
94-
{% set empty_choices = 'No choice available' %}
95-
{% set choice_translation_domain = 'sf_form' -%}
96-
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
94+
{%- if empty_choices is empty -%}
95+
{%- set empty_choices = 'No choice available' %}
96+
{%- set choice_translation_domain = 'sf_form' %}
97+
{%- endif -%}
98+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
9799
<div {{ block('widget_container_attributes') }}>
98100
<p>
99101
{{- choice_translation_domain is same as(false) ? empty_choices : empty_choices|trans({}, choice_translation_domain) -}}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ public function testSingleChoiceWithoutChoices()
237237
'choices' => array(),
238238
'multiple' => false,
239239
'expanded' => false,
240+
'attr' => array('class' => 'my&class')
240241
));
241242

242-
$this->assertWidgetMatchesXpath($form->createView(), array(),
243+
$this->assertMatchesXpath($this->renderWidget($form->createView()),
243244
'/div
244-
[@class="my&amp;class form-control"]
245-
[not(@required)]
245+
[@class="my&class form-control"]
246246
[
247-
/p[.="[trans]No choice available[/trans]"]
247+
./p[.="[trans]No choice available[/trans]"]
248248
]
249249
'
250250
);
@@ -693,6 +693,25 @@ public function testSingleChoiceExpanded()
693693
);
694694
}
695695

696+
public function testSingleChoiceExpandedWithoutChoices()
697+
{
698+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
699+
'choices' => array(),
700+
'multiple' => false,
701+
'expanded' => true,
702+
));
703+
704+
$this->assertMatchesXpath($this->renderWidget($form->createView()),
705+
'/div
706+
[@class="form-control"]
707+
[not(@required)]
708+
[
709+
./p[.="[trans]No choice available[/trans]"]
710+
]
711+
'
712+
);
713+
}
714+
696715
public function testSingleChoiceExpandedWithoutTranslation()
697716
{
698717
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ public function testSingleChoiceWithoutChoices()
529529
'/div
530530
[not(@required)]
531531
[.="[trans]No choice available[/trans]"]
532-
[count(./div)=1]
533532
'
534533
);
535534
}
@@ -953,6 +952,22 @@ public function testSingleChoiceExpanded()
953952
);
954953
}
955954

955+
public function testSingleChoiceExpandedWithoutChoices()
956+
{
957+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
958+
'choices' => array(),
959+
'multiple' => false,
960+
'expanded' => true,
961+
));
962+
963+
$this->assertWidgetMatchesXpath($form->createView(), array(),
964+
'/div
965+
[not(@required)]
966+
[.="[trans]No choice available[/trans]"]
967+
'
968+
);
969+
}
970+
956971
public function testSingleChoiceExpandedWithoutTranslation()
957972
{
958973
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(

0 commit comments

Comments
 (0)