Index: tests/Zend/Form/FormTest.php =================================================================== --- tests/Zend/Form/FormTest.php (revision 25211) +++ tests/Zend/Form/FormTest.php (working copy) @@ -4729,8 +4729,8 @@ $form = new Zend_Form(); $form->setElementDecorators( array( - new Zend_Form_Decorator_ViewHelper, - new Zend_Form_Decorator_Label, + new Zend_Form_Decorator_ViewHelper(), + new Zend_Form_Decorator_Label(), ) ); $element = $form->createElement('text', 'foo'); @@ -4748,6 +4748,73 @@ $this->assertEquals($expected, $actual); } + + /** + * @group ZF-12387 + */ + public function testAddElementAsObjectWithDecoratorsShouldNotLoseDecorators() + { + // Init form + $form = new Zend_Form(); + $form->setElementDecorators( + array( + new Zend_Form_Decorator_ViewHelper(), + new Zend_Form_Decorator_Label(), + ) + ); + + $element = new Zend_Form_Element_Text('foo'); + $element->setDecorators(array('Errors', 'Description')); + $form->addElement($element); + + // Test + $expected = array( + 'Zend_Form_Decorator_Errors', + 'Zend_Form_Decorator_Description', + ); + + $actual = array(); + foreach ($form->getElement('foo')->getDecorators() as $decorator) { + $actual[] = get_class($decorator); + } + + $this->assertEquals($expected, $actual); + } + + /** + * @group ZF-12387 + */ + public function testAddElementAsObjectGetsElementDecoratorsIfNoneIsExplicitlySet() + { + // Init form + $form = new Zend_Form(); + $form->setElementDecorators( + array( + new Zend_Form_Decorator_ViewHelper(), + new Zend_Form_Decorator_Label(), + ) + ); + + // Add element + $element = new Zend_Form_Element_Text( + 'foo', + array('disableLoadDefaultDecorators' => true) + ); + $form->addElement($element); + + // Test + $expected = array( + 'Zend_Form_Decorator_ViewHelper', + 'Zend_Form_Decorator_Label', + ); + + $actual = array(); + foreach ($form->getElement('foo')->getDecorators() as $decorator) { + $actual[] = get_class($decorator); + } + + $this->assertEquals($expected, $actual); + } } class Zend_Form_FormTest_DisplayGroup extends Zend_Form_DisplayGroup