Fixed Button::setParent() when already submitted
This commit is contained in:
parent
e52d977d12
commit
9f0c7bf549
@ -106,6 +106,10 @@ class Button implements \IteratorAggregate, FormInterface
|
|||||||
*/
|
*/
|
||||||
public function setParent(FormInterface $parent = null)
|
public function setParent(FormInterface $parent = null)
|
||||||
{
|
{
|
||||||
|
if ($this->submitted) {
|
||||||
|
throw new AlreadySubmittedException('You cannot set the parent of a submitted button');
|
||||||
|
}
|
||||||
|
|
||||||
$this->parent = $parent;
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,20 @@ class ButtonTest extends TestCase
|
|||||||
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
|
$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
|
* @dataProvider getDisabledStates
|
||||||
*/
|
*/
|
||||||
@ -37,11 +51,13 @@ class ButtonTest extends TestCase
|
|||||||
{
|
{
|
||||||
$form = $this->getFormBuilder('form')
|
$form = $this->getFormBuilder('form')
|
||||||
->setDisabled($parentDisabled)
|
->setDisabled($parentDisabled)
|
||||||
->getForm();
|
->getForm()
|
||||||
|
;
|
||||||
|
|
||||||
$button = $this->getButtonBuilder('button')
|
$button = $this->getButtonBuilder('button')
|
||||||
->setDisabled($buttonDisabled)
|
->setDisabled($buttonDisabled)
|
||||||
->getForm();
|
->getForm()
|
||||||
|
;
|
||||||
|
|
||||||
$button->setParent($form);
|
$button->setParent($form);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user