Explorar o código

Merge r25202 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25203 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch %!s(int64=13) %!d(string=hai) anos
pai
achega
36223b759d

+ 4 - 0
library/Zend/View/Helper/Partial.php

@@ -71,6 +71,10 @@ class Zend_View_Helper_Partial extends Zend_View_Helper_Abstract
         if (isset($this->partialCounter)) {
             $view->partialCounter = $this->partialCounter;
         }
+        if (isset($this->partialTotalCount)) {
+            $view->partialTotalCount = $this->partialTotalCount;
+        }
+
         if ((null !== $module) && is_string($module)) {
             require_once 'Zend/Controller/Front.php';
             $moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module);

+ 3 - 1
library/Zend/View/Helper/PartialLoop.php

@@ -85,7 +85,9 @@ class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial
 
         $content = '';
         // reset the counter if it's call again
-        $this->partialCounter = 0;
+        $this->partialCounter    = 0;
+        $this->partialTotalCount = count($model);
+
         foreach ($model as $item) {
             // increment the counter variable
             $this->partialCounter++;

+ 27 - 0
tests/Zend/View/Helper/PartialLoopTest.php

@@ -373,6 +373,33 @@ class Zend_View_Helper_PartialLoopTest extends PHPUnit_Framework_TestCase
             $this->assertContains($string, $result);
         }
     }
+
+    /**
+     * @see ZF-7157
+     */
+    public function testPartialLoopSetsTotalCount()
+    {
+        $data = array(
+            array('message' => 'foo'),
+            array('message' => 'bar'),
+            array('message' => 'baz'),
+            array('message' => 'bat')
+        );
+
+        $view = new Zend_View(
+            array(
+                 'scriptPath' =>
+                 $this->basePath . '/default/views/scripts'
+            )
+        );
+        $this->helper->setView($view);
+
+        $result = $this->helper->partialLoop('partialLoopCouter.phtml', $data);
+        foreach ($data as $key => $item) {
+            $string = 'Total count: ' . count($data);
+            $this->assertContains($string, $result);
+        }
+    }
 }
 
 class Zend_View_Helper_PartialLoop_IteratorTest implements Iterator

+ 1 - 0
tests/Zend/View/Helper/_files/modules/default/views/scripts/partialLoopCouter.phtml

@@ -1,2 +1,3 @@
 This is an iteration: <?php echo $this->message ?>, pointer at <?php echo $this->partialCounter ?>
+Total count: <?php echo $this->partialTotalCount ?>