فهرست منبع

[Form] Fixed: Form::bind() throws an exception if form is anonymous

Bernhard Schussek 14 سال پیش
والد
کامیت
bd3e6c6b49
2فایلهای تغییر یافته به همراه14 افزوده شده و 0 حذف شده
  1. 4 0
      src/Symfony/Component/Form/Form.php
  2. 10 0
      tests/Symfony/Tests/Component/Form/FormTest.php

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

@@ -713,6 +713,10 @@ class Form extends Field implements \IteratorAggregate, FormInterface
      */
     public function bind(Request $request, $data = null)
     {
+        if (!$this->getName()) {
+            throw new FormException('You cannot bind anonymous forms. Please give this form a name');
+        }
+
         // Store object from which to read the default values and where to
         // write the submitted values
         if (null !== $data) {

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

@@ -276,6 +276,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(array('group2'), $childForm->getValidationGroups());
     }
 
+    /**
+     * @expectedException Symfony\Component\Form\Exception\FormException
+     */
+    public function testBindThrowsExceptionIfAnonymous()
+    {
+        $form = new Form(null, array('validator' => $this->createMockValidator()));
+
+        $form->bind($this->createPostRequest());
+    }
+
     public function testBindValidatesData()
     {
         $form = new Form('author', array(