Skip to content

Commit 83db940

Browse files
committed
[Form] adjust tests for deprecated read_only option
1 parent 052168f commit 83db940

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
7878
}
7979

8080
// Complex fields are read-only if they themselves or their parents are.
81-
if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly'])) {
81+
if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly']) {
8282
$view->vars['attr']['readonly'] = true;
8383
}
8484
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,10 @@ public function testHidden()
13421342
);
13431343
}
13441344

1345-
public function testReadOnly()
1345+
/**
1346+
* @group legacy
1347+
*/
1348+
public function testLegacyReadOnly()
13461349
{
13471350
$form = $this->factory->createNamed('name', 'text', null, array(
13481351
'read_only' => true,
@@ -1907,14 +1910,13 @@ public function testWidgetAttributes()
19071910
$form = $this->factory->createNamed('text', 'text', 'value', array(
19081911
'required' => true,
19091912
'disabled' => true,
1910-
'read_only' => true,
1911-
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
1913+
'attr' => array('readonly' => true, 'maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
19121914
));
19131915

19141916
$html = $this->renderWidget($form->createView());
19151917

19161918
// compare plain HTML to check the whitespace
1917-
$this->assertSame('<input type="text" id="text" name="text" readonly="readonly" disabled="disabled" required="required" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
1919+
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
19181920
}
19191921

19201922
public function testWidgetAttributeNameRepeatedIfTrue()

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,10 @@ public function testHidden()
15121512
);
15131513
}
15141514

1515-
public function testReadOnly()
1515+
/**
1516+
* @group legacy
1517+
*/
1518+
public function testLegacyReadOnly()
15161519
{
15171520
$form = $this->factory->createNamed('name', 'text', null, array(
15181521
'read_only' => true,
@@ -2119,14 +2122,13 @@ public function testWidgetAttributes()
21192122
$form = $this->factory->createNamed('text', 'text', 'value', array(
21202123
'required' => true,
21212124
'disabled' => true,
2122-
'read_only' => true,
2123-
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
2125+
'attr' => array('readonly' => true, 'maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
21242126
));
21252127

21262128
$html = $this->renderWidget($form->createView());
21272129

21282130
// compare plain HTML to check the whitespace
2129-
$this->assertSame('<input type="text" id="text" name="text" readonly="readonly" disabled="disabled" required="required" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
2131+
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
21302132
}
21312133

21322134
public function testWidgetAttributeNameRepeatedIfTrue()

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
9999
$this->assertEquals('reverse[ a ]', $form->getData());
100100
}
101101

102-
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
102+
/**
103+
* @group legacy
104+
*/
105+
public function testLegacyNonReadOnlyFormWithReadOnlyParentIsReadOnly()
103106
{
104107
$view = $this->factory->createNamedBuilder('parent', 'form', null, array('read_only' => true))
105108
->add('child', 'form')
@@ -109,7 +112,20 @@ public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
109112
$this->assertTrue($view['child']->vars['read_only']);
110113
}
111114

112-
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
115+
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
116+
{
117+
$view = $this->factory->createNamedBuilder('parent', 'form', null, array('attr' => array('readonly' => true)))
118+
->add('child', 'form')
119+
->getForm()
120+
->createView();
121+
122+
$this->assertTrue($view['child']->vars['attr']['readonly']);
123+
}
124+
125+
/**
126+
* @group legacy
127+
*/
128+
public function testLegacyReadOnlyFormWithNonReadOnlyParentIsReadOnly()
113129
{
114130
$view = $this->factory->createNamedBuilder('parent', 'form')
115131
->add('child', 'form', array('read_only' => true))
@@ -119,7 +135,20 @@ public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
119135
$this->assertTrue($view['child']->vars['read_only']);
120136
}
121137

122-
public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
138+
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
139+
{
140+
$view = $this->factory->createNamedBuilder('parent', 'form')
141+
->add('child', 'form', array('attr' => array('readonly' => true)))
142+
->getForm()
143+
->createView();
144+
145+
$this->assertTrue($view['child']->vars['attr']['readonly']);
146+
}
147+
148+
/**
149+
* @group legacy
150+
*/
151+
public function testLegacyNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
123152
{
124153
$view = $this->factory->createNamedBuilder('parent', 'form')
125154
->add('child', 'form')
@@ -129,6 +158,16 @@ public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
129158
$this->assertFalse($view['child']->vars['read_only']);
130159
}
131160

161+
public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
162+
{
163+
$view = $this->factory->createNamedBuilder('parent', 'form')
164+
->add('child', 'form')
165+
->getForm()
166+
->createView();
167+
168+
$this->assertArrayNotHasKey('readonly', $view['child']->vars['attr']);
169+
}
170+
132171
public function testPassMaxLengthToView()
133172
{
134173
$form = $this->factory->create('form', null, array('attr' => array('maxlength' => 10)));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy