8000 add tests · symfony/symfony@18fd85e · GitHub
[go: up one dir, main page]

Skip to content

Commit 18fd85e

Browse files
committed
add tests
1 parent 745ee6b commit 18fd85e

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@
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') }}>
98-
{{- choice_translation_domain is same as(false) ? empty_choices : empty_choices|trans({}, choice_translation_domain) -}}
100+
<p>
101+
{{- choice_translation_domain is same as(false) ? empty_choices : empty_choices|trans({}, choice_translation_domain) -}}
102+
</p>
99103
</div>
100104
{%- endif %}
101105
{%- endblock %}

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

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

234+
public function testSingleChoiceWithoutChoices()
235+
{
236+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
237+
'choices' => array(),
238+
'multiple' => false,
239+
'expanded' => false,
240+
'attr' => array('class' => 'my&class')
241+
));
242+
243+
$this->assertMatchesXpath($this->renderWidget($form->createView()),
244+
'/div
245+
[@class="my&class form-control"]
246+
[
247+
./p[.="[trans]No choice available[/trans]"]
248+
]
249+
'
250+
);
251+
}
252+
234253
public function testSingleChoiceWithoutTranslation()
235254
{
236255
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
@@ -674,6 +693,25 @@ public function testSingleChoiceExpanded()
674693
);
675694
}
676695

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+
677715
public function testSingleChoiceExpandedWithoutTranslation()
678716
{
679717
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,22 @@ public function testSingleChoice()
517517
);
518518
}
519519

520+
public function testSingleChoiceWithoutChoices()
521+
{
522+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
523+
'choices' => array(),
524+
'multiple' => false,
525+
'expanded' => false,
526+
));
527+
528+
$this->assertWidgetMatchesXpath($form->createView(), array(),
529+
'/div
530+
[not(@required)]
531+
[.="[trans]No choice available[/trans]"]
532+
'
533+
);
534+
}
535+
520536
public function testSingleChoiceWithoutTranslation()
521537
{
522538
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
@@ -936,6 +952,22 @@ public function testSingleChoiceExpanded()
936952
);
937953
}
938954

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+
939971
public function testSingleChoiceExpandedWithoutTranslation()
940972
{
941973
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(

0 commit comments

Comments
 (0)
0