Skip to content
Permalink
Browse files

Avoiding specifying 'maxLimit' too when setting 'limit' greater than …

…default 'maxLimit' in code.
  • Loading branch information...
ADmad committed Nov 28, 2012
1 parent 68976a0 commit 1de8ed18de6883da976cd3fba0bfee4bd5942bda
@@ -322,6 +322,11 @@ public function getDefaults($alias) {
if (isset($this->settings[$alias])) {
$defaults = $this->settings[$alias];
}
if (isset($defaults['limit']) &&
(empty($defaults['maxLimit']) || $defaults['limit'] > $defaults['maxLimit'])
) {
$defaults['maxLimit'] = $defaults['limit'];
}
return array_merge(
array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named'),
$defaults
@@ -820,6 +820,40 @@ public function testMergeOptionsExtraWhitelist() {
$this->assertEquals($expected, $result);
}
/**
* test mergeOptions with limit > maxLimit in code.
*
* @return void
*/
public function testMergeOptionsMaxLimit() {
$this->Paginator->settings = array(
'limit' => 200,
'paramType' => 'named',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 1, 'limit' => 200, 'maxLimit' => 200, 'paramType' => 'named');
$this->assertEquals($expected, $result);
$this->Paginator->settings = array(
'maxLimit' => 10,
'paramType' => 'named',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 10, 'paramType' => 'named');
$this->assertEquals($expected, $result);
$this->request->params['named'] = array(
'limit' => 500
);
$this->Paginator->settings = array(
'limit' => 150,
'paramType' => 'named',
);
$result = $this->Paginator->mergeOptions('Post');
$expected = array('page' => 1, 'limit' => 500, 'maxLimit' => 150, 'paramType' => 'named');
$this->assertEquals($expected, $result);
}
/**
* test that invalid directions are ignored.
*
@@ -1311,8 +1311,8 @@ public function testPaginateBackwardsCompatibility() {
$this->assertEquals(array(1, 2, 3), $results);
$Controller->passedArgs = array();
$Controller->paginate = array('limit' => '-1');
$this->assertEquals(array('limit' => '-1'), $Controller->paginate);
$Controller->paginate = array('limit' => '1');
$this->assertEquals(array('limit' => '1'), $Controller->paginate);
$Controller->paginate('ControllerPost');
$this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3);

0 comments on commit 1de8ed1

Please sign in to comment.
You can’t perform that action at this time.