Skip to content

Commit daac882

Browse files
committed
Initial commit for Bootstrap 4 form theme, based on Bootstrap 3 form theme
Fixed Bootstrap 4 error output Updated form errors to look correctly Cranked Twig Bridge Composer version to ~3.2 Added @ author PHPdoc tag to BS 4 test classes Fixed small items, and added fieldset/legend support - Fixed form class for File type - Added fieldset element for expanded form types - Added legend element as label for expanded form types - Fixed horizontal form classes for labels Added test for legend form label Fixed form label coloring on validation errors Fixed concrete Bootstrap layout test classes to use new code Fixed tests for form-control-label class on form labels Fixed a typo in using old Bootstrap 4 concrete test code Processed proposed changes from stof Processed proposed changes in bootstrap base layout from stof Updated margin-top for error list in the alpha-5 version of BS 4 Fixed {% endblock ... %} and fixed BS error class in test Fixed TwigRenderer => FormRenderer code change Minor fixed for radio/checkboxes and fixed validation feedback Added ~3.4 require of symfony/form (and <3.4 conflict) to Twig Bridge composer.json Updated Boostrap 4 file input to have class .form-control-file
1 parent bf17bcb commit daac882

File tree

2 files changed

+1159
-0
lines changed

2 files changed

+1159
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
/**
15+
* Abstract class providing test cases for the Bootstrap 4 horizontal Twig form theme.
16+
*
17+
* @author Hidde Wieringa <[email protected]>
18+
*/
19+
abstract class AbstractBootstrap4HorizontalLayoutTest extends AbstractBootstrap4LayoutTest
20+
{
21+
public function testLabelOnForm()
22+
{
23+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
24+
$view = $form->createView();
25+
$this->renderWidget($view, array('label' => 'foo'));
26+
$html = $this->renderLabel($view);
27+
28+
$this->assertMatchesXpath($html,
29+
'/label
30+
[@class="col-form-label col-sm-2 form-control-label required"]
31+
[.="[trans]Name[/trans]"]
32+
'
33+
);
34+
}
35+
36+
public function testLabelDoesNotRenderFieldAttributes()
37+
{
38+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
39+
$html = $this->renderLabel($form->createView(), null, array(
40+
'attr' => array(
41+
'class' => 'my&class',
42+
),
43+
));
44+
45+
$this->assertMatchesXpath($html,
46+
'/label
47+
[@for="name"]
48+
[@class="col-form-label col-sm-2 form-control-label required"]
49+
'
50+
);
51+
}
52+
53+
public function testLabelWithCustomAttributesPassedDirectly()
54+
{
55+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
56+
$html = $this->renderLabel($form->createView(), null, array(
57+
'label_attr' => array(
58+
'class' => 'my&class',
59+
),
60+
));
61+
62+
$this->assertMatchesXpath($html,
63+
'/label
64+
[@for="name"]
65+
[@class="my&class col-form-label col-sm-2 form-control-label required"]
66+
'
67+
);
68+
}
69+
70+
public function testLabelWithCustomTextAndCustomAttributesPassedDirectly()
71+
{
72+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
73+
$html = $this->renderLabel($form->createView(), 'Custom label', array(
74+
'label_attr' => array(
75+
'class' => 'my&class',
76+
),
77+
));
78+
79+
$this->assertMatchesXpath($html,
80+
'/label
81+
[@for="name"]
82+
[@class="my&class col-form-label col-sm-2 form-control-label required"]
83+
[.="[trans]Custom label[/trans]"]
84+
'
85+
);
86+
}
87+
88+
public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly()
89+
{
90+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
91+
'label' => 'Custom label',
92+
));
93+
$html = $this->renderLabel($form->createView(), null, array(
94+
'label_attr' => array(
95+
'class' => 'my&class',
96+
),
97+
));
98+
99+
$this->assertMatchesXpath($html,
100+
'/label
101+
[@for="name"]
102+
[@class="my&class col-form-label col-sm-2 form-control-label required"]
103+
[.="[trans]Custom label[/trans]"]
104+
'
105+
);
106+
}
107+
108+
public function testLegendOnExpandedType()
109+
{
110+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
111+
'label' => 'Custom label',
112+
'expanded' => true,
113+
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
114+
));
115+
$view = $form->createView();
116+
$this->renderWidget($view);
117+
$html = $this->renderLabel($view);
118+
119+
$this->assertMatchesXpath($html,
120+
'/legend
121+
[@class="col-sm-2 col-form-legend form-control-label required"]
122+
[.="[trans]Custom label[/trans]"]
123+
'
124+
);
125+
}
126+
127+
public function testStartTag()
128+
{
129+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
130+
'method' => 'get',
131+
'action' => 'http://example.com/directory',
132+
));
133+
134+
$html = $this->renderStart($form->createView());
135+
136+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory">', $html);
137+
}
138+
139+
public function testStartTagWithOverriddenVars()
140+
{
141+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
142+
'method' => 'put',
143+
'action' => 'http://example.com/directory',
144+
));
145+
146+
$html = $this->renderStart($form->createView(), array(
147+
'method' => 'post',
148+
'action' => 'http://foo.com/directory',
149+
));
150+
151+
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory">', $html);
152+
}
153+
154+
public function testStartTagForMultipartForm()
155+
{
156+
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
157+
'method' => 'get',
158+
'action' => 'http://example.com/directory',
159+
))
160+
->add('file', 'Symfony\Component\Form\Extension\Core\Type\FileType')
161+
->getForm();
162+
163+
$html = $this->renderStart($form->createView());
164+
165+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" enctype="multipart/form-data">', $html);
166+
}
167+
168+
public function testStartTagWithExtraAttributes()
169+
{
170+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
171+
'method' => 'get',
172+
'action' => 'http://example.com/directory',
173+
));
174+
175+
$html = $this->renderStart($form->createView(), array(
176+
'attr' => array('class' => 'foobar'),
177+
));
178+
179+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);
180+
}
181+
}

0 commit comments

Comments
 (0)