Browse Source

ZF-9710: Omit empty unordered list on subforms with no errors

- Applied test and patch from B. Charbonneau

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23757 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 years ago
parent
commit
c80124aeb6

+ 7 - 3
library/Zend/Form/Decorator/FormErrors.php

@@ -451,9 +451,13 @@ class Zend_Form_Decorator_FormErrors extends Zend_Form_Decorator_Abstract
                              .  $this->getMarkupListItemEnd();
                 }
             } else if ($subitem instanceof Zend_Form && !$this->ignoreSubForms()) {
-                $content .= $this->getMarkupListStart()
-                          . $this->_recurseForm($subitem, $view)
-                          . $this->getMarkupListEnd();
+                $markup = $this->_recurseForm($subitem, $view);
+
+                if (!empty($markup)) {
+                    $content .= $this->getMarkupListStart()
+                              . $markup
+                              . $this->getMarkupListEnd();
+                }
             }
         }
         return $content;

+ 13 - 0
tests/Zend/Form/Decorator/FormErrorsTest.php

@@ -138,6 +138,18 @@ class Zend_Form_Decorator_FormErrorsTest extends PHPUnit_Framework_TestCase
         $this->assertSame($content, $this->decorator->render($content));
     }
 
+    public function testNotGeneratingSubformErrorMarkupWrappingWhenNoErrors()
+    {
+        $form1 = new Zend_Form_SubForm();
+        $form2 = new Zend_Form();
+        $form2->addSubForm($form1, 'sub');
+        $form2->setView($this->getView());
+        $this->decorator->setElement($form2);
+
+        $content = 'test content';
+        $this->assertSame($content, $this->decorator->render($content));
+    }
+
     public function testRenderRendersAllErrorMessages()
     {
         $this->setupForm();
@@ -289,6 +301,7 @@ class Zend_Form_Decorator_FormErrorsTest extends PHPUnit_Framework_TestCase
         $this->assertNotContains('form-badness', $html);
     }
 
+
     /**
      * @dataProvider markupOptionMethodsProvider
      */