Преглед изворни кода

Merge r25252 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25253 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch пре 13 година
родитељ
комит
85454a3d1e
2 измењених фајлова са 78 додато и 1 уклоњено
  1. 9 1
      library/Zend/Form/Decorator/Errors.php
  2. 69 0
      tests/Zend/Form/Decorator/ErrorsTest.php

+ 9 - 1
library/Zend/Form/Decorator/Errors.php

@@ -50,7 +50,15 @@ class Zend_Form_Decorator_Errors extends Zend_Form_Decorator_Abstract
             return $content;
         }
 
-        $errors = $element->getMessages();
+        // Get error messages
+        if ($element instanceof Zend_Form
+            && null !== $element->getElementsBelongTo()
+        ) {
+            $errors = $element->getMessages(null, true);
+        } else {
+            $errors = $element->getMessages();
+        }
+
         if (empty($errors)) {
             return $content;
         }

+ 69 - 0
tests/Zend/Form/Decorator/ErrorsTest.php

@@ -28,6 +28,7 @@ if (!defined("PHPUnit_MAIN_METHOD")) {
 require_once 'Zend/Form/Decorator/Errors.php';
 
 require_once 'Zend/Form/Element.php';
+require_once 'Zend/Form/SubForm.php';
 require_once 'Zend/View.php';
 
 /**
@@ -145,6 +146,74 @@ class Zend_Form_Decorator_ErrorsTest extends PHPUnit_Framework_TestCase
         $test = $this->decorator->render($content);
         $this->assertContains($content . $this->decorator->getSeparator() . '<ul', $test, $test);
     }
+
+    /**
+     * @group ZF-11476?
+     */
+    public function testRenderingWithFormAsElement()
+    {
+        // Set up form
+        $form = new Zend_Form(
+            array(
+                 'elements'         => array(
+                     'foo' => new Zend_Form_Element('foo'),
+                     'bar' => new Zend_Form_Element('bar'),
+                 ),
+                 'view'             => $this->getView(),
+                 'elementsBelongTo' => 'foobar',
+            )
+        );
+
+        $this->decorator->setElement($form);
+
+        // Tests
+        $this->assertEquals(
+            array('foobar' => array()),
+            $form->getMessages()
+        );
+        $this->assertEquals(
+            array(),
+            $form->getMessages(null, true)
+        );
+        $this->assertEquals(
+            'test content',
+            $this->decorator->render('test content')
+        );
+    }
+
+    /**
+     * @group ZF-11476?
+     */
+    public function testRenderingWithSubFormAsElement()
+    {
+        // Set up sub form
+        $subForm = new Zend_Form_SubForm(
+            array(
+                 'elements' => array(
+                     'foo' => new Zend_Form_Element('foo'),
+                     'bar' => new Zend_Form_Element('bar'),
+                 ),
+                 'view'     => $this->getView(),
+                 'name'     => 'foobar',
+            )
+        );
+
+        $this->decorator->setElement($subForm);
+
+        // Tests
+        $this->assertEquals(
+            array('foobar' => array()),
+            $subForm->getMessages()
+        );
+        $this->assertEquals(
+            array(),
+            $subForm->getMessages(null, true)
+        );
+        $this->assertEquals(
+            'test content',
+            $this->decorator->render('test content')
+        );
+    }
 }
 
 // Call Zend_Form_Decorator_ErrorsTest::main() if this source file is executed directly.