8000 bug #25926 [Form] Fixed Button::setParent() when already submitted (H… · symfony/symfony@ba8fb60 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba8fb60

Browse files
committed
bug #25926 [Form] Fixed Button::setParent() when already submitted (HeahDude)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fixed Button::setParent() when already submitted | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ The `Button` does not respect the [FormInterface](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/FormInterface.php#L28), by extension the `SubmitButton` neither. Commits ------- 9f0c7bf Fixed Button::setParent() when already submitted
2 parents 0cd675c + 9f0c7bf commit ba8fb60

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/Form/Button.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function offsetUnset($offset)
106106
*/
107107
public function setParent(FormInterface $parent = null)
108108
{
109+
if ($this->submitted) {
110+
throw new AlreadySubmittedException('You cannot set the parent of a submitted button');
111+
}
112+
109113
$this->parent = $parent;
110114
}
111115

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,34 @@ protected function setUp()
3030
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
3131
}
3232

33+
/**
34+
* @expectedException \Symfony\Component\Form\Exception\AlreadySubmittedException
35+
*/
36+
public function testSetParentOnSubmittedButton()
37+
{
38+
$button = $this->getButtonBuilder('button')
39+
->getForm()
40+
;
41+
42+
$button->submit('');
43+
44+
$button->setParent($this->getFormBuilder('form')->getForm());
45+
}
46+
3347
/**
3448
* @dataProvider getDisabledStates
3549
*/
3650
public function testDisabledIfParentIsDisabled($parentDisabled, $buttonDisabled, $result)
3751
{
3852
$form = $this->getFormBuilder('form')
3953
->setDisabled($parentDisabled)
40-
->getForm();
54+
->getForm()
55+
;
4156

4257
$button = $this->getButtonBuilder('button')
4358
->setDisabled($buttonDisabled)
44-
->getForm();
59+
->getForm()
60+
;
4561

4662
$button->setParent($form);
4763

0 commit comments

Comments
 (0)
0