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

Merge r25254 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25255 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch пре 13 година
родитељ
комит
528f3f5123

+ 10 - 3
library/Zend/View/Helper/Placeholder/Container/Abstract.php

@@ -93,7 +93,7 @@ abstract class Zend_View_Helper_Placeholder_Container_Abstract extends ArrayObje
     /**
      * Constructor - This is needed so that we can attach a class member as the ArrayObject container
      *
-     * @return void
+     * @return \Zend_View_Helper_Placeholder_Container_Abstract
      */
     public function __construct()
     {
@@ -252,9 +252,10 @@ abstract class Zend_View_Helper_Placeholder_Container_Abstract extends ArrayObje
     /**
      * Start capturing content to push into placeholder
      *
-     * @param  int $type How to capture content into placeholder; append, prepend, or set
+     * @param int|string $type How to capture content into placeholder; append, prepend, or set
+     * @param null       $key
+     * @throws Zend_View_Helper_Placeholder_Container_Exception
      * @return void
-     * @throws Zend_View_Helper_Placeholder_Exception if nested captures detected
      */
     public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $key = null)
     {
@@ -349,10 +350,16 @@ abstract class Zend_View_Helper_Placeholder_Container_Abstract extends ArrayObje
     /**
      * Render the placeholder
      *
+     * @param null $indent
      * @return string
      */
     public function toString($indent = null)
     {
+        // Check items
+        if (0 === $this->count()) {
+            return '';
+        }
+
         $indent = ($indent !== null)
                 ? $this->getWhitespace($indent)
                 : $this->getIndent();

+ 20 - 0
tests/Zend/View/Helper/Placeholder/ContainerTest.php

@@ -442,6 +442,26 @@ class Zend_View_Helper_Placeholder_ContainerTest extends PHPUnit_Framework_TestC
         $this->assertTrue((strstr($string, "    <ul>\n")) ? true : false, $string);
         $this->assertTrue((strstr($string, "\n    </ul>")) ? true : false);
     }
+
+    /**
+     * @group ZF-12044
+     */
+    public function testContainerWithoutItemsShouldAlwaysReturnEmptyString()
+    {
+        $this->assertEquals('', (string) $this->container);
+
+        $this->container->setIndent(4);
+        $this->assertEquals('', (string) $this->container);
+
+        $this->container->setPrefix('<ul><li>');
+        $this->assertEquals('', (string) $this->container);
+
+        $this->container->setSeparator('</li><li>');
+        $this->assertEquals('', (string) $this->container);
+
+        $this->container->setPrefix('</li></ul>');
+        $this->assertEquals('', (string) $this->container);
+    }
 }
 
 // Call Zend_View_Helper_Placeholder_ContainerTest::main() if this source file is executed directly.