Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkael committed Jul 15, 2010
3 parents 381012a + 70bccda + a96d3c6 commit 46a9a43
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/AdapterAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface AdapterAggregate
/**
* Return a fully configured Paginator Adapter from this method.
*
* @return Zend_Paginator_Adapter_Abstract
* @return Zend_Paginator_Adapter_Interface
*/
public function getPaginatorAdapter();
}
14 changes: 10 additions & 4 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ public function clearPageItemCache($pageNumber = null)
}

if (null === $pageNumber) {
$cleanTags = self::CACHE_TAG_PREFIX;
foreach (self::$_cache->getIdsMatchingTags(array($this->_getCacheInternalId())) as $id) {
if (preg_match('|'.self::CACHE_TAG_PREFIX."(\d+)_.*|", $id, $page)) {
self::$_cache->remove($this->_getCacheId($page[1]));
Expand Down Expand Up @@ -686,11 +685,11 @@ public function getItemCountPerPage()
* @param integer $itemCountPerPage
* @return \Zend\Paginator\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;
Expand Down Expand Up @@ -882,6 +881,8 @@ public function setView(View\ViewEngine $view = null)
*/
public function normalizeItemNumber($itemNumber)
{
$itemNumber = (integer) $itemNumber;

if ($itemNumber < 1) {
$itemNumber = 1;
}
Expand All @@ -901,6 +902,8 @@ public function normalizeItemNumber($itemNumber)
*/
public function normalizePageNumber($pageNumber)
{
$pageNumber = (integer) $pageNumber;

if ($pageNumber < 1) {
$pageNumber = 1;
}
Expand Down Expand Up @@ -986,7 +989,10 @@ protected function _getCacheId($page = null)
*/
protected function _getCacheInternalId()
{
return md5(serialize($this->getAdapter()) . $this->getItemCountPerPage());
return md5(serialize(array(
spl_object_hash($this->getAdapter()),
$this->getItemCountPerPage()
)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Adapter/DbSelect/OracleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Zend\DB\Statement\OracleException;

require_once 'Zend/Paginator/Adapter/DbSelectTest.php';
require_once dirname(__FILE__) . '/../../_files/TestTable.php';
require_once __DIR__ . '/../../_files/TestTable.php';

/**
* @category Zend
Expand Down
6 changes: 3 additions & 3 deletions test/Adapter/DbSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Zend\DB;
use Zend\DB\Select;

require_once dirname(__FILE__) . '/../_files/TestTable.php';
require_once __DIR__ . '/../_files/TestTable.php';

/**
* @category Zend
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function setUp()
parent::setUp();

$this->_db = new PDO\SQLite(array(
'dbname' => dirname(__FILE__) . '/../_files/test.sqlite'
'dbname' => __DIR__ . '/../_files/test.sqlite'
));

$this->_table = new \ZendTest\Paginator\TestAsset\TestTable($this->_db);
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testGroupByQueryReturnsOneRow()
public function testGroupByQueryOnEmptyTableReturnsRowCountZero()
{
$db = new PDO\SQLite(array(
'dbname' => dirname(__FILE__) . '/../_files/testempty.sqlite'
'dbname' => __DIR__ . '/../_files/testempty.sqlite'
));

$query = $db->select()->from('test')
Expand Down
68 changes: 66 additions & 2 deletions test/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public function testRendersWithPartial()
{
$view = new View\View();
$view->addBasePath(__DIR__ . '/_files');
$view->addHelperPath(dirname(__FILE__) . '/../../../trunk/library/Zend/View/Helper', 'Zend\View\Helper');
$view->addHelperPath(__DIR__ . '/../../../trunk/library/Zend/View/Helper', 'Zend\View\Helper');

Helper\PaginationControl::setDefaultViewPartial('partial.phtml');

Expand All @@ -448,7 +448,43 @@ public function testGetsAndSetsItemCountPerPage()
$this->_paginator->setItemCountPerPage(15);
$this->assertEquals(15, $this->_paginator->getItemCountPerPage());
$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 testGetsAndSetsItemCounterPerPageOfNegativeOne()
{
Paginator\Paginator::setConfig(new Config\Config(array()));
$this->_paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter(range(1, 101)));
$this->_paginator->setItemCountPerPage(-1);
$this->assertEquals(101, $this->_paginator->getItemCountPerPage());
$this->_paginator->setItemCountPerPage(10);
}

/**
* @group ZF-5376
*/
public function testGetsAndSetsItemCounterPerPageOfZero()
{
Paginator\Paginator::setConfig(new Config\Config(array()));
$this->_paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter(range(1, 101)));
$this->_paginator->setItemCountPerPage(0);
$this->assertEquals(101, $this->_paginator->getItemCountPerPage());
$this->_paginator->setItemCountPerPage(10);
}

/**
* @group ZF-5376
*/
public function testGetsAndSetsItemCounterPerPageOfNull()
{
Paginator\Paginator::setConfig(new Config\Config(array()));
$this->_paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter(range(1, 101)));
$this->_paginator->setItemCountPerPage();
$this->assertEquals(101, $this->_paginator->getItemCountPerPage());
$this->_paginator->setItemCountPerPage(10);
}

Expand Down Expand Up @@ -565,6 +601,34 @@ public function testNormalizesItemNumber()
$this->assertEquals(10, $this->_paginator->normalizeItemNumber(11));
}

/**
* @group ZF-8656
*/
public function testNormalizesPageNumberWhenGivenAFloat()
{
$this->assertEquals(1, $this->_paginator->normalizePageNumber(0.5));
$this->assertEquals(1, $this->_paginator->normalizePageNumber(1.99));
$this->assertEquals(2, $this->_paginator->normalizePageNumber(2.3));
$this->assertEquals(5, $this->_paginator->normalizePageNumber(5.1));
$this->assertEquals(10, $this->_paginator->normalizePageNumber(10.06));
$this->assertEquals(11, $this->_paginator->normalizePageNumber(11.5));
$this->assertEquals(11, $this->_paginator->normalizePageNumber(12.7889));
}

/**
* @group ZF-8656
*/
public function testNormalizesItemNumberWhenGivenAFloat()
{
$this->assertEquals(1, $this->_paginator->normalizeItemNumber(0.5));
$this->assertEquals(1, $this->_paginator->normalizeItemNumber(1.99));
$this->assertEquals(2, $this->_paginator->normalizeItemNumber(2.3));
$this->assertEquals(5, $this->_paginator->normalizeItemNumber(5.1));
$this->assertEquals(9, $this->_paginator->normalizeItemNumber(9.06));
$this->assertEquals(10, $this->_paginator->normalizeItemNumber(10.5));
$this->assertEquals(10, $this->_paginator->normalizeItemNumber(11.7889));
}

public function testGetsPagesInSubsetRange()
{
$actual = $this->_paginator->getPagesInRange(3, 8);
Expand Down

0 comments on commit 46a9a43

Please sign in to comment.