[Form] Added test for disabling buttons
This commit is contained in:
parent
6bb355e2fd
commit
ebfee723c9
@ -252,6 +252,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
public function setAttribute($name, $value)
|
public function setAttribute($name, $value)
|
||||||
{
|
{
|
||||||
$this->attributes[$name] = $value;
|
$this->attributes[$name] = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,6 +262,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
public function setAttributes(array $attributes)
|
public function setAttributes(array $attributes)
|
||||||
{
|
{
|
||||||
$this->attributes = $attributes;
|
$this->attributes = $attributes;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,6 +290,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
public function setDisabled($disabled)
|
public function setDisabled($disabled)
|
||||||
{
|
{
|
||||||
$this->disabled = $disabled;
|
$this->disabled = $disabled;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -410,6 +416,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
public function setType(ResolvedFormTypeInterface $type)
|
public function setType(ResolvedFormTypeInterface $type)
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
70
src/Symfony/Component/Form/Tests/ButtonTest.php
Normal file
70
src/Symfony/Component/Form/Tests/ButtonTest.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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 <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -170,34 +170,28 @@ class SimpleFormTest extends AbstractFormTest
|
|||||||
$this->assertFalse($child->isRequired());
|
$this->assertFalse($child->isRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAlwaysDisabledIfParentDisabled()
|
/**
|
||||||
|
* @dataProvider getDisabledStates
|
||||||
|
*/
|
||||||
|
public function testAlwaysDisabledIfParentDisabled($parentDisabled, $disabled, $result)
|
||||||
{
|
{
|
||||||
$parent = $this->getBuilder()->setDisabled(true)->getForm();
|
$parent = $this->getBuilder()->setDisabled($parentDisabled)->getForm();
|
||||||
$child = $this->getBuilder()->setDisabled(false)->getForm();
|
$child = $this->getBuilder()->setDisabled($disabled)->getForm();
|
||||||
|
|
||||||
$child->setParent($parent);
|
$child->setParent($parent);
|
||||||
|
|
||||||
$this->assertTrue($child->isDisabled());
|
$this->assertSame($result, $child->isDisabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisabled()
|
public function getDisabledStates()
|
||||||
{
|
{
|
||||||
$parent = $this->getBuilder()->setDisabled(false)->getForm();
|
return array(
|
||||||
$child = $this->getBuilder()->setDisabled(true)->getForm();
|
// parent, button, result
|
||||||
|
array(true, true, true),
|
||||||
$child->setParent($parent);
|
array(true, false, true),
|
||||||
|
array(false, true, true),
|
||||||
$this->assertTrue($child->isDisabled());
|
array(false, false, false),
|
||||||
}
|
);
|
||||||
|
|
||||||
public function testNotDisabled()
|
|
||||||
{
|
|
||||||
$parent = $this->getBuilder()->setDisabled(false)->getForm();
|
|
||||||
$child = $this->getBuilder()->setDisabled(false)->getForm();
|
|
||||||
|
|
||||||
$child->setParent($parent);
|
|
||||||
|
|
||||||
$this->assertFalse($child->isDisabled());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRootReturnsRootOfParent()
|
public function testGetRootReturnsRootOfParent()
|
||||||
|
Reference in New Issue
Block a user