diff --git a/src/Paginator.php b/src/Paginator.php index 93dcc42..d3c04a8 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -916,10 +916,13 @@ protected function _createPages($scrollingStyle = null) // Item numbers if ($this->getCurrentItems() !== null) { $pages->currentItemCount = $this->getCurrentItemCount(); - $pages->itemCountPerPage = $this->getItemCountPerPage(); $pages->totalItemCount = $this->getTotalItemCount(); - $pages->firstItemNumber = (($currentPageNumber - 1) * $this->getItemCountPerPage()) + 1; - $pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1; + $pages->firstItemNumber = $pages->totalItemCount + ? (($currentPageNumber - 1) * $pages->itemCountPerPage) + 1 + : 0; + $pages->lastItemNumber = $pages->totalItemCount + ? $pages->firstItemNumber + $pages->currentItemCount - 1 + : 0; } return $pages; diff --git a/test/PaginatorTest.php b/test/PaginatorTest.php index df8c2f2..95827cb 100644 --- a/test/PaginatorTest.php +++ b/test/PaginatorTest.php @@ -791,4 +791,32 @@ public function testGetCacheId() $this->assertEquals($outputGetCacheId, 'Zend_Paginator_1_' . $outputGetCacheInternalId); } + + /** + * @group 6808 + * @group 6809 + */ + public function testItemCountsForEmptyItemSet() + { + $paginator = new Paginator\Paginator(new Adapter\ArrayAdapter(array())); + $paginator->setCurrentPageNumber(1); + + $expected = new stdClass(); + $expected->pageCount = 0; + $expected->itemCountPerPage = 10; + $expected->first = 1; + $expected->current = 1; + $expected->last = 0; + $expected->pagesInRange = array(1 => 1); + $expected->firstPageInRange = 1; + $expected->lastPageInRange = 1; + $expected->currentItemCount = 0; + $expected->totalItemCount = 0; + $expected->firstItemNumber = 0; + $expected->lastItemNumber = 0; + + $actual = $paginator->getPages(); + + $this->assertEquals($expected, $actual); + } }