Browse Source

[Form] bind() is ignored if a form is read-only

Bernhard Schussek 14 years ago
parent
commit
4f39234741

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

@@ -380,6 +380,10 @@ class Form implements \IteratorAggregate, FormInterface
      */
     public function bind($clientData)
     {
+        if ($this->readOnly) {
+            return;
+        }
+
         if (is_scalar($clientData) || null === $clientData) {
             $clientData = (string)$clientData;
         }

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

@@ -145,6 +145,18 @@ class FormTest extends \PHPUnit_Framework_TestCase
         $this->form->bind(array());
     }
 
+    public function testBindIsIgnoredIfReadOnly()
+    {
+        $form = $this->getBuilder()
+            ->setReadOnly(true)
+            ->setData('initial')
+            ->getForm();
+
+        $form->bind('new');
+
+        $this->assertEquals('initial', $form->getData());
+    }
+
     public function testNeverRequiredIfParentNotRequired()
     {
         $parent = $this->getBuilder()->setRequired(false)->getForm();