Skip to content

Commit

Permalink
Reapplying changes in [33d2f9a] as they got lost when the paginator c…
Browse files Browse the repository at this point in the history
…omponent was extracted.
  • Loading branch information
markstory committed Dec 18, 2010
1 parent a6cca7c commit 6b9d9f4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cake/libs/controller/components/paginator.php
Expand Up @@ -43,7 +43,7 @@ class PaginatorComponent extends Component {
* @param array $settings Array of configuration settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
$settings = array_merge(array('page' => 1, 'limit' => 20), (array)$settings);
$settings = array_merge(array('page' => 1, 'limit' => 20, 'maxLimit' => 100), (array)$settings);
$this->Controller = $collection->getController();
parent::__construct($collection, $settings);
}
Expand Down Expand Up @@ -146,6 +146,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);

extract($options);

Expand Down Expand Up @@ -181,7 +182,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
} elseif (intval($page) < 1) {
$options['page'] = $page = 1;
}
$page = $options['page'] = (integer)$page;
$page = $options['page'] = (int)$page;

if (method_exists($object, 'paginate')) {
$results = $object->paginate(
Expand Down
39 changes: 39 additions & 0 deletions cake/tests/cases/libs/controller/components/paginator.test.php
Expand Up @@ -486,4 +486,43 @@ function testPaginateMissingModel() {
$Controller->constructClasses();
$Controller->Paginator->paginate('MissingModel');
}

/**
* testPaginateMaxLimit
*
* @return void
* @access public
*/
function testPaginateMaxLimit() {
$request = new CakeRequest('controller_posts/index');
$request->params['pass'] = $request->params['named'] = array();

$Controller = new Controller($request);

$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();

$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);

$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);

$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '10');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 10);

$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
$Controller->paginate = array('maxLimit' => 2000);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 1000);

$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '5000');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 2000);
}
}

0 comments on commit 6b9d9f4

Please sign in to comment.