mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Reapplying changes in [33d2f9a6ed
] as they got lost when the paginator component was extracted.
This commit is contained in:
parent
a6cca7c036
commit
6b9d9f4aea
2 changed files with 42 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
@ -146,6 +146,7 @@ class PaginatorComponent extends Component {
|
|||
if (empty($options['limit']) || $options['limit'] < 1) {
|
||||
$options['limit'] = 1;
|
||||
}
|
||||
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);
|
||||
|
||||
extract($options);
|
||||
|
||||
|
@ -181,7 +182,7 @@ class PaginatorComponent extends Component {
|
|||
} 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(
|
||||
|
|
|
@ -486,4 +486,43 @@ class PaginatorTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue