Quellcode durchsuchen

ZF-10865
Updated Zend_Form::addElement to throw exception if $element is not a string or instance of Zend_Form_Element


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23881 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan vor 14 Jahren
Ursprung
Commit
25778c299d
2 geänderte Dateien mit 14 neuen und 0 gelöschten Zeilen
  1. 4 0
      library/Zend/Form.php
  2. 10 0
      tests/Zend/Form/FormTest.php

+ 4 - 0
library/Zend/Form.php

@@ -1013,6 +1013,7 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
      * @param  string|Zend_Form_Element $element
      * @param  string $name
      * @param  array|Zend_Config $options
+     * @throws Zend_Form_Exception on invalid element
      * @return Zend_Form
      */
     public function addElement($element, $name = null, $options = null)
@@ -1050,6 +1051,9 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
 
             $this->_elements[$name] = $element;
             $this->_elements[$name]->addPrefixPaths($prefixPaths);
+        } else {
+            require_once 'Zend/Form/Exception.php';
+            throw new Zend_Form_Exception('Element must be specified by string or Zend_Form_Element instance');
         }
 
         $this->_order[$name] = $this->_elements[$name]->getOrder();

+ 10 - 0
tests/Zend/Form/FormTest.php

@@ -4451,6 +4451,16 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
         $this->assertSame(1, count($errorMessages2));
         $this->assertSame($errorString, $errorMessages2[0]);
     }
+    
+    /**
+     * @group ZF-10865
+     * @expectedException Zend_Form_Exception
+     */
+    public function testExceptionThrownWhenAddElementsIsGivenNullValue()
+    {
+        $form = new Zend_Form();
+        $form->addElement(NULL);
+    }
 }
 
 class Zend_Form_FormTest_DisplayGroup extends Zend_Form_DisplayGroup