Parcourir la source

ZF-8453: constraints should merge, not overwrite

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23928 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew il y a 14 ans
Parent
commit
5eb7ae640a

+ 2 - 0
library/Zend/Dojo/Form/Element/ValidationTextBox.php

@@ -132,6 +132,8 @@ class Zend_Dojo_Form_Element_ValidationTextBox extends Zend_Dojo_Form_Element_Te
      */
     public function setConstraints(array $constraints)
     {
+        $tmp = $this->getConstraints();
+        $constraints = array_merge($tmp, $constraints);
         array_walk_recursive($constraints, array($this, '_castBoolToString'));
         $this->setDijitParam('constraints', $constraints);
         return $this;

+ 9 - 0
tests/Zend/Dojo/Form/Element/ValidationTextBoxTest.php

@@ -178,6 +178,15 @@ class Zend_Dojo_Form_Element_ValidationTextBoxTest extends PHPUnit_Framework_Tes
         $html = $this->element->render();
         $this->assertContains('dojoType="dijit.form.ValidationTextBox"', $html);
     }
+    
+    public function testSettingMultipleConstraintsShouldNotOverridePreviousConstraints()
+    {
+        $this->element->setConstraint('foo', 'bar');
+        
+        $this->element->setConstraints(array('spam' => 'ham'));
+        
+        $this->assertEquals('bar', $this->element->getConstraint('foo'));
+    }
 }
 
 // Call Zend_Dojo_Form_Element_ValidationTextBoxTest::main() if this source file is executed directly.