Procházet zdrojové kódy

ZF-5376: Allow Zend_Paginator::setItemCountPerPage() to accept -1, 0, or null as triggers to set an item count per page equal to the total item count

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22299 44c647ce-9c0f-0410-b52a-842ac1e357ba
bradley.holt před 15 roky
rodič
revize
be0d6fbee1
2 změnil soubory, kde provedl 37 přidání a 3 odebrání
  1. 2 2
      library/Zend/Paginator.php
  2. 35 1
      tests/Zend/PaginatorTest.php

+ 2 - 2
library/Zend/Paginator.php

@@ -703,11 +703,11 @@ class Zend_Paginator implements Countable, IteratorAggregate
      * @param  integer $itemCountPerPage
      * @return Zend_Paginator $this
      */
-    public function setItemCountPerPage($itemCountPerPage)
+    public function setItemCountPerPage($itemCountPerPage = -1)
     {
         $this->_itemCountPerPage = (integer) $itemCountPerPage;
         if ($this->_itemCountPerPage < 1) {
-            $this->_itemCountPerPage = $this->getItemCountPerPage();
+            $this->_itemCountPerPage = $this->getTotalItemCount();
         }
         $this->_pageCount        = $this->_calculatePageCount();
         $this->_currentItems     = null;

+ 35 - 1
tests/Zend/PaginatorTest.php

@@ -514,8 +514,42 @@ class Zend_PaginatorTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(10, $this->_paginator->getItemCountPerPage());
         $this->_paginator->setItemCountPerPage(15);
         $this->assertEquals(15, $this->_paginator->getItemCountPerPage());
+        $this->_paginator->setItemCountPerPage(10);
+    }
+
+    /**
+     * @group ZF-5376
+     */
+    public function testGetsAndSetsItemCounterPerPageOfNegativeOne()
+    {
+        Zend_Paginator::setConfig(new Zend_Config(array()));
+        $this->_paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array(range(1, 101)));
+        $this->_paginator->setItemCountPerPage(-1);
+        $this->assertEquals(101, $this->_paginator->getItemCountPerPage());
+        $this->_paginator->setItemCountPerPage(10);
+    }
+
+    /**
+     * @group ZF-5376
+     */
+    public function testGetsAndSetsItemCounterPerPageOfZero()
+    {
+        Zend_Paginator::setConfig(new Zend_Config(array()));
+        $this->_paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array(range(1, 101)));
         $this->_paginator->setItemCountPerPage(0);
-        $this->assertEquals(10, $this->_paginator->getItemCountPerPage());
+        $this->assertEquals(101, $this->_paginator->getItemCountPerPage());
+        $this->_paginator->setItemCountPerPage(10);
+    }
+
+    /**
+     * @group ZF-5376
+     */
+    public function testGetsAndSetsItemCounterPerPageOfNull()
+    {
+        Zend_Paginator::setConfig(new Zend_Config(array()));
+        $this->_paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array(range(1, 101)));
+        $this->_paginator->setItemCountPerPage();
+        $this->assertEquals(101, $this->_paginator->getItemCountPerPage());
         $this->_paginator->setItemCountPerPage(10);
     }