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

Skip to content

Commit b4c0924

Browse files
Added label tests
1 parent 1f4d866 commit b4c0924

4 files changed

+157
-0
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3HorizontalLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
100100
);
101101
}
102102

103+
public function testLabelHtmlDefaultIsFalse()
104+
{
105+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
106+
'label' => '<b>Click here</b>',
107+
]);
108+
109+
$html = $this->renderLabel($form->createView(), null, [
110+
'label_attr' => [
111+
'class' => 'my&class',
112+
],
113+
]);
114+
115+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-sm-2 control-label required"][.="[trans]<b>Click here</b>[/trans]"]');
116+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-sm-2 control-label required"]/b[.="Click here"]', 0);
117+
}
118+
119+
public function testLabelHtmlIsTrue()
120+
{
121+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
122+
'label' => '<b>Click here</b>',
123+
'label_html' => true,
124+
]);
125+
126+
$html = $this->renderLabel($form->createView(), null, [
127+
'label_attr' => [
128+
'class' => 'my&class',
129+
],
130+
]);
131+
132+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-sm-2 control-label required"][.="[trans]<b>Click here</b>[/trans]"]', 0);
133+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-sm-2 control-label required"]/b[.="Click here"]');
134+
}
135+
103136
public function testStartTag()
104137
{
105138
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, [

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
106106
);
107107
}
108108

109+
public function testLabelHtmlDefaultIsFalse()
110+
{
111+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
112+
'label' => '<b>Click here</b>',
113+
]);
114+
115+
$html = $this->renderLabel($form->createView(), null, [
116+
'label_attr' => [
117+
'class' => 'my&class',
118+
],
119+
]);
120+
121+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class control-label required"][.="[trans]<b>Click here</b>[/trans]"]');
122+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class control-label required"]/b[.="Click here"]', 0);
123+
}
124+
125+
public function testLabelHtmlIsTrue()
126+
{
127+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
128+
'label' => '<b>Click here</b>',
129+
'label_html' => true,
130+
]);
131+
132+
$html = $this->renderLabel($form->createView(), null, [
133+
'label_attr' => [
134+
'class' => 'my&class',
135+
],
136+
]);
137+
138+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class control-label required"][.="[trans]<b>Click here</b>[/trans]"]', 0);
139+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class control-label required"]/b[.="Click here"]');
140+
}
141+
109142
public function testHelp()
110143
{
111144
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
@@ -2663,6 +2696,31 @@ public function testButtonlabelWithoutTranslation()
26632696
);
26642697
}
26652698

2699+
public function testButtonLabelHtmlDefaultIsFalse()
2700+
{
2701+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, [
2702+
'label' => '<b>Click here</b>',
2703+
]);
2704+
2705+
$html = $this->renderWidget($form->createView(), ['attr' => ['class' => 'my&class']]);
2706+
2707+
$this->assertMatchesXpath($html, '/button[@type="button"][@name="name"][.="[trans]<b>Click here</b>[/trans]"][@class="my&class btn"]');
2708+
$this->assertMatchesXpath($html, '/button[@type="button"][@name="name"][@class="my&class btn"]/b[.="Click here"]', 0);
2709+
}
2710+
2711+
public function testButtonLabelHtmlIsTrue()
2712+
{
2713+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', null, [
2714+
'label' => '<b>Click here</b>',
2715+
'label_html' => true,
2716+
]);
2717+
2718+
$html = $this->renderWidget($form->createView(), ['attr' => ['class' => 'my&class']]);
2719+
2720+
$this->assertMatchesXpath($html, '/button[@type="button"][@name="name"][.="[trans]<b>Click here</b>[/trans]"][@class="my&class btn"]', 0);
2721+
$this->assertMatchesXpath($html, '/button[@type="button"][@name="name"][@class="my&class btn"]/b[.="Click here"]');
2722+
}
2723+
26662724
public function testSubmit()
26672725
{
26682726
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4HorizontalLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
132132
);
133133
}
134134

135+
public function testLabelHtmlDefaultIsFalse()
136+
{
137+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
138+
'label' => '<b>Click here</b>',
139+
]);
140+
141+
$html = $this->renderLabel($form->createView(), null, [
142+
'label_attr' => [
143+
'class' => 'my&class',
144+
],
145+
]);
146+
147+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-form-label col-sm-2 required"][.="[trans]<b>Click here</b>[/trans]"]');
148+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-form-label col-sm-2 required"]/b[.="Click here"]', 0);
149+
}
150+
151+
public function testLabelHtmlIsTrue()
152+
{
153+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
154+
'label' => '<b>Click here</b>',
155+
'label_html' => true,
156+
]);
157+
158+
$html = $this->renderLabel($form->createView(), null, [
159+
'label_attr' => [
160+
'class' => 'my&class',
161+
],
162+
]);
163+
164+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-form-label col-sm-2 required"][.="[trans]<b>Click here</b>[/trans]"]', 0);
165+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class col-form-label col-sm-2 required"]/b[.="Click here"]');
166+
}
167+
135168
public function testLegendOnExpandedType()
136169
{
137170
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, [

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
141141
);
142142
}
143143

144+
public function testLabelHtmlDefaultIsFalse()
145+
{
146+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
147+
'label' => '<b>Click here</b>',
148+
]);
149+
150+
$html = $this->renderLabel($form->createView(), null, [
151+
'label_attr' => [
152+
'class' => 'my&class',
153+
],
154+
]);
155+
156+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class required"][.="[trans]<b>Click here</b>[/trans]"]');
157+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class required"]/b[.="Click here"]', 0);
158+
}
159+
160+
public function testLabelHtmlIsTrue()
161+
{
162+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
163+
'label' => '<b>Click here</b>',
164+
'label_html' => true,
165+
]);
166+
167+
$html = $this->renderLabel($form->createView(), null, [
168+
'label_attr' => [
169+
'class' => 'my&class',
170+
],
171+
]);
172+
173+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class required"][.="[trans]<b>Click here</b>[/trans]"]', 0);
174+
$this->assertMatchesXpath($html, '/label[@for="name"][@class="my&class required"]/b[.="Click here"]');
175+
}
176+
144177
public function testLegendOnExpandedType()
145178
{
146179
$form = $this->factory->createNamed('name', ChoiceType::class, null, [

0 commit comments

Comments
 (0)