diff --git a/src/Symfony/Component/Form/ButtonBuilder.php b/src/Symfony/Component/Form/ButtonBuilder.php index 9146c69352..f9b0546b1f 100644 --- a/src/Symfony/Component/Form/ButtonBuilder.php +++ b/src/Symfony/Component/Form/ButtonBuilder.php @@ -252,6 +252,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface public function setAttribute($name, $value) { $this->attributes[$name] = $value; + + return $this; } /** @@ -260,6 +262,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface public function setAttributes(array $attributes) { $this->attributes = $attributes; + + return $this; } /** @@ -286,6 +290,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface public function setDisabled($disabled) { $this->disabled = $disabled; + + return $this; } /** @@ -410,6 +416,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface public function setType(ResolvedFormTypeInterface $type) { $this->type = $type; + + return $this; } /** diff --git a/src/Symfony/Component/Form/Tests/ButtonTest.php b/src/Symfony/Component/Form/Tests/ButtonTest.php new file mode 100644 index 0000000000..b0c766c73c --- /dev/null +++ b/src/Symfony/Component/Form/Tests/ButtonTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests; + +use Symfony\Component\Form\ButtonBuilder; +use Symfony\Component\Form\FormBuilder; + +/** + * @author Bernhard Schussek + */ +class ButtonTest extends \PHPUnit_Framework_TestCase +{ + private $dispatcher; + + private $factory; + + protected function setUp() + { + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); + } + + /** + * @dataProvider getDisabledStates + */ + public function testDisabledIfParentIsDisabled($parentDisabled, $buttonDisabled, $result) + { + $form = $this->getFormBuilder('form') + ->setDisabled($parentDisabled) + ->getForm(); + + $button = $this->getButtonBuilder('button') + ->setDisabled($buttonDisabled) + ->getForm(); + + $button->setParent($form); + + $this->assertSame($result, $button->isDisabled()); + } + + public function getDisabledStates() + { + return array( + // parent, button, result + array(true, true, true), + array(true, false, true), + array(false, true, true), + array(false, false, false), + ); + } + + private function getButtonBuilder($name) + { + return new ButtonBuilder($name); + } + + private function getFormBuilder($name) + { + return new FormBuilder($name, null, $this->dispatcher, $this->factory); + } +} diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index bedad6761f..d6d3238b42 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -170,34 +170,28 @@ class SimpleFormTest extends AbstractFormTest $this->assertFalse($child->isRequired()); } - public function testAlwaysDisabledIfParentDisabled() + /** + * @dataProvider getDisabledStates + */ + public function testAlwaysDisabledIfParentDisabled($parentDisabled, $disabled, $result) { - $parent = $this->getBuilder()->setDisabled(true)->getForm(); - $child = $this->getBuilder()->setDisabled(false)->getForm(); + $parent = $this->getBuilder()->setDisabled($parentDisabled)->getForm(); + $child = $this->getBuilder()->setDisabled($disabled)->getForm(); $child->setParent($parent); - $this->assertTrue($child->isDisabled()); + $this->assertSame($result, $child->isDisabled()); } - public function testDisabled() + public function getDisabledStates() { - $parent = $this->getBuilder()->setDisabled(false)->getForm(); - $child = $this->getBuilder()->setDisabled(true)->getForm(); - - $child->setParent($parent); - - $this->assertTrue($child->isDisabled()); - } - - public function testNotDisabled() - { - $parent = $this->getBuilder()->setDisabled(false)->getForm(); - $child = $this->getBuilder()->setDisabled(false)->getForm(); - - $child->setParent($parent); - - $this->assertFalse($child->isDisabled()); + return array( + // parent, button, result + array(true, true, true), + array(true, false, true), + array(false, true, true), + array(false, false, false), + ); } public function testGetRootReturnsRootOfParent()