Explorar o código

[Form] Form::isBound() and Form::isValid() work correctly now for read-only forms

Bernhard Schussek %!s(int64=14) %!d(string=hai) anos
pai
achega
13a964ae6d

+ 2 - 0
src/Symfony/Component/Form/Form.php

@@ -452,6 +452,8 @@ class Form implements \IteratorAggregate, FormInterface
     public function bind($clientData)
     {
         if ($this->readOnly) {
+            $this->bound = true;
+
             return $this;
         }
 

+ 9 - 0
tests/Symfony/Tests/Component/Form/FormTest.php

@@ -159,6 +159,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
         $form->bind('new');
 
         $this->assertEquals('initial', $form->getData());
+        $this->assertTrue($form->isBound());
     }
 
     public function testNeverRequiredIfParentNotRequired()
@@ -297,6 +298,14 @@ class FormTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($this->form->isValid());
     }
 
+    public function testValidIfBoundAndReadOnly()
+    {
+        $form = $this->getBuilder()->setReadOnly(true)->getForm();
+        $form->bind('foobar');
+
+        $this->assertTrue($form->isValid());
+    }
+
     public function testNotValidIfNotBound()
     {
         $this->assertFalse($this->form->isValid());