Skip to content

Commit

Permalink
bug #25926 [Form] Fixed Button::setParent() when already submitted (H…
Browse files Browse the repository at this point in the history
…eahDude)

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
  • Loading branch information
fabpot committed Jan 26, 2018
2 parents 0cd675c + 9f0c7bf commit ba8fb60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Form/Button.php
Expand Up @@ -106,6 +106,10 @@ public function offsetUnset($offset)
*/
public function setParent(FormInterface $parent = null)
{
if ($this->submitted) {
throw new AlreadySubmittedException('You cannot set the parent of a submitted button');
}

$this->parent = $parent;
}

Expand Down
20 changes: 18 additions & 2 deletions src/Symfony/Component/Form/Tests/ButtonTest.php
Expand Up @@ -30,18 +30,34 @@ protected function setUp()
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
}

/**
* @expectedException \Symfony\Component\Form\Exception\AlreadySubmittedException
*/
public function testSetParentOnSubmittedButton()
{
$button = $this->getButtonBuilder('button')
->getForm()
;

$button->submit('');

$button->setParent($this->getFormBuilder('form')->getForm());
}

/**
* @dataProvider getDisabledStates
*/
public function testDisabledIfParentIsDisabled($parentDisabled, $buttonDisabled, $result)
{
$form = $this->getFormBuilder('form')
->setDisabled($parentDisabled)
->getForm();
->getForm()
;

$button = $this->getButtonBuilder('button')
->setDisabled($buttonDisabled)
->getForm();
->getForm()
;

$button->setParent($form);

Expand Down

0 comments on commit ba8fb60

Please sign in to comment.