Skip to content

Commit 98bcc3e

Browse files
Pieterfabpot
authored andcommitted
[WIP] [Form] [TwigBridge] Bootstrap horizontal theme missing tests
1 parent be26fd1 commit 98bcc3e

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests;
13+
14+
abstract class AbstractBootstrap3HorizontalLayoutTest extends AbstractBootstrap3LayoutTest
15+
{
16+
public function testLabelOnForm()
17+
{
18+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
19+
$view = $form->createView();
20+
$this->renderWidget($view, array('label' => 'foo'));
21+
$html = $this->renderLabel($view);
22+
23+
$this->assertMatchesXpath($html,
24+
'/label
25+
[@class="col-sm-2 control-label required"]
26+
[.="[trans]Name[/trans]"]
27+
'
28+
);
29+
}
30+
31+
public function testLabelDoesNotRenderFieldAttributes()
32+
{
33+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
34+
$html = $this->renderLabel($form->createView(), null, array(
35+
'attr' => array(
36+
'class' => 'my&class',
37+
),
38+
));
39+
40+
$this->assertMatchesXpath($html,
41+
'/label
42+
[@for="name"]
43+
[@class="col-sm-2 control-label required"]
44+
'
45+
);
46+
}
47+
48+
public function testLabelWithCustomAttributesPassedDirectly()
49+
{
50+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
51+
$html = $this->renderLabel($form->createView(), null, array(
52+
'label_attr' => array(
53+
'class' => 'my&class',
54+
),
55+
));
56+
57+
$this->assertMatchesXpath($html,
58+
'/label
59+
[@for="name"]
60+
[@class="my&class col-sm-2 control-label required"]
61+
'
62+
);
63+
}
64+
65+
public function testLabelWithCustomTextAndCustomAttributesPassedDirectly()
66+
{
67+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
68+
$html = $this->renderLabel($form->createView(), 'Custom label', array(
69+
'label_attr' => array(
70+
'class' => 'my&class',
71+
),
72+
));
73+
74+
$this->assertMatchesXpath($html,
75+
'/label
76+
[@for="name"]
77+
[@class="my&class col-sm-2 control-label required"]
78+
[.="[trans]Custom label[/trans]"]
79+
'
80+
);
81+
}
82+
83+
public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly()
84+
{
85+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
86+
'label' => 'Custom label',
87+
));
88+
$html = $this->renderLabel($form->createView(), null, array(
89+
'label_attr' => array(
90+
'class' => 'my&class',
91+
),
92+
));
93+
94+
$this->assertMatchesXpath($html,
95+
'/label
96+
[@for="name"]
97+
[@class="my&class col-sm-2 control-label required"]
98+
[.="[trans]Custom label[/trans]"]
99+
'
100+
);
101+
}
102+
103+
public function testStartTag()
104+
{
105+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
106+
'method' => 'get',
107+
'action' => 'http://example.com/directory',
108+
));
109+
110+
$html = $this->renderStart($form->createView());
111+
112+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal">', $html);
113+
}
114+
115+
public function testStartTagWithOverriddenVars()
116+
{
117+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
118+
'method' => 'put',
119+
'action' => 'http://example.com/directory',
120+
));
121+
122+
$html = $this->renderStart($form->createView(), array(
123+
'method' => 'post',
124+
'action' => 'http://foo.com/directory',
125+
));
126+
127+
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" class="form-horizontal">', $html);
128+
}
129+
130+
public function testStartTagForMultipartForm()
131+
{
132+
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
133+
'method' => 'get',
134+
'action' => 'http://example.com/directory',
135+
))
136+
->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType')
137+
->getForm();
138+
139+
$html = $this->renderStart($form->createView());
140+
141+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" enctype="multipart/form-data">', $html);
142+
}
143+
144+
public function testStartTagWithExtraAttributes()
145+
{
146+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
147+
'method' => 'get',
148+
'action' => 'http://example.com/directory',
149+
));
150+
151+
$html = $this->renderStart($form->createView(), array(
152+
'attr' => array('class' => 'foobar'),
153+
));
154+
155+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);
156+
}
157+
}

0 commit comments

Comments
 (0)