Skip to content

Commit bf94875

Browse files
MaximeZumsteinneilime
authored andcommitted
Add testInitializeAnHorizontalFormClassWithFieldset
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent ca92283 commit bf94875

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/TestSuite/TwbsHelper/Form/View/Helper/FormTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,76 @@ public function prepare()
8787
);
8888
}
8989

90+
public function testInitializeAnHorizontalFormClassWithFieldset()
91+
{
92+
$factory = new \Laminas\Form\Factory();
93+
94+
$form = $factory->create([
95+
'type' => 'form',
96+
'elements' => [
97+
[
98+
'spec' => [
99+
'name' => 'displayname',
100+
'options' => [
101+
'label' => 'Display name',
102+
'column' => 'sm-10',
103+
],
104+
'attributes' => [
105+
'type' => 'text',
106+
'id' => 'inputDisplayname1',
107+
'placeholder' => 'Display name',
108+
],
109+
],
110+
],
111+
[
112+
'spec' => [
113+
'name' => 'credentials',
114+
'type' => \Laminas\Form\Fieldset::class,
115+
'elements' => [
116+
[
117+
'spec' => [
118+
'name' => 'email',
119+
'options' => [
120+
'label' => 'Email',
121+
'column' => 'sm-10',
122+
],
123+
'attributes' => [
124+
'type' => 'email',
125+
'id' => 'inputEmail3',
126+
'placeholder' => 'Email',
127+
],
128+
],
129+
],
130+
],
131+
],
132+
],
133+
],
134+
]);
135+
$form->setOption('layout', \TwbsHelper\Form\View\Helper\Form::LAYOUT_HORIZONTAL);
136+
$this->assertEquals(
137+
'<form id="form" method="POST" name="form" role="form">' . PHP_EOL .
138+
' <div class="mb-3&#x20;row">' . PHP_EOL .
139+
' <label class="col-form-label&#x20;col-sm-2" for="inputDisplayname1">'.
140+
'Display name</label>' . PHP_EOL .
141+
' <div class="col-sm-10">' . PHP_EOL .
142+
' <input class="form-control" id="inputDisplayname1" name="displayname" placeholder="Display&#x20;name" ' .
143+
'type="text" value=""/>' . PHP_EOL .
144+
' </div>' . PHP_EOL .
145+
' </div>' . PHP_EOL .
146+
' <fieldset class="mb-3&#x20;row">' . PHP_EOL .
147+
' <div class="mb-3&#x20;row">' . PHP_EOL .
148+
' <label class="col-form-label&#x20;col-sm-2" for="inputEmail3">' .
149+
'Email</label>' . PHP_EOL .
150+
' <div class="col-sm-10">' . PHP_EOL .
151+
' <input class="form-control" id="inputEmail3" name="credentials&#x5B;email&#x5D;" placeholder="Email" ' .
152+
'type="email" value=""/>' . PHP_EOL .
153+
' </div>' . PHP_EOL .
154+
' </div>' . PHP_EOL .
155+
' </fieldset>' . PHP_EOL .
156+
'</form>',
157+
$this->formHelper->__invoke($form)
158+
);
159+
}
90160

91161
public function testRenderSpecWithWrongFormElementThrowsAnException()
92162
{

website/docs/usage/forms/layout.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,4 @@ echo $this->form($factory->create([
10721072

10731073
</TabItem>
10741074
</Tabs>
1075+

0 commit comments

Comments
 (0)