Permalink
Browse files

Fix page 0 issue.

Refs #2929
  • Loading branch information...
1 parent 15a423a commit d1819dcabb31108751ff5fb630965b9b660fb65b @markstory markstory committed Jun 3, 2012
View
4 lib/Cake/Controller/Component/PaginatorComponent.php
@@ -184,7 +184,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
$count = $object->find('count', array_merge($parameters, $extra));
}
$pageCount = intval(ceil($count / $limit));
- $page = min($page, $pageCount);
+ $page = max(min($page, $pageCount), 1);
$paging = array(
'page' => $page,
@@ -375,7 +375,7 @@ public function checkLimit($options) {
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
- $options['limit'] = min((int)$options['limit'], $options['maxLimit']);
+ $options['limit'] = min($options['limit'], $options['maxLimit']);
return $options;
}
View
16 lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
@@ -725,7 +725,21 @@ public function testOutOfRangePageNumberGetsClamped() {
$Controller->constructClasses();
$Controller->PaginatorControllerPost->recursive = 0;
$Controller->Paginator->paginate('PaginatorControllerPost');
- $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Super big page number should be capped to max number of pages'
+ );
+
+ $Controller->paginate = array(
+ 'conditions' => array('PaginatorControllerPost.id >' => 100)
+ );
+ $Controller->Paginator->paginate('PaginatorControllerPost');
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Page number should not be 0'
+ );
}
/**

0 comments on commit d1819dc

Please sign in to comment.