[Form] fixed isValid() on readOnly forms that have children

This commit is contained in:
Kris Wallsmith 2011-06-10 07:11:50 -07:00
parent 44816ebca0
commit 8d55df42de
2 changed files with 21 additions and 3 deletions

View File

@ -679,10 +679,12 @@ class Form implements \IteratorAggregate, FormInterface
return false;
}
foreach ($this->children as $child) {
if (!$child->isValid()) {
if (!$this->readOnly) {
foreach ($this->children as $child) {
if (!$child->isValid()) {
return false;
return false;
}
}
}

View File

@ -306,6 +306,22 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($form->isValid());
}
public function testValidIfBoundAndReadOnlyWithChildren()
{
$this->factory->expects($this->once())
->method('createNamedBuilder')
->with('text', 'name', null, array())
->will($this->returnValue($this->getBuilder('name')));
$form = $this->getBuilder('person')
->setReadOnly(true)
->add('name', 'text')
->getForm();
$form->bind(array('name' => 'Jacques Doe'));
$this->assertTrue($form->isValid());
}
public function testNotValidIfNotBound()
{
$this->assertFalse($this->form->isValid());