Skip to content
Permalink
Browse files

#9848 PaginatorComponent.php ignores maxLimit

  • Loading branch information...
gorogoroyasu committed Dec 7, 2016
1 parent f8ea642 commit 03960de4415e851e96065ff86bd83e78d2a27fb1
@@ -299,13 +299,22 @@ public function getDefaults($alias, $defaults)
if (isset($defaults[$alias])) {
$defaults = $defaults[$alias];
}
if (isset($defaults['limit']) &&
(empty($defaults['maxLimit']) || $defaults['limit'] > $defaults['maxLimit'])
) {
$defaults['maxLimit'] = $defaults['limit'];
$config = $this->config();
$maxLimit = isset($defaults['maxLimit']) ? $defaults['maxLimit'] : $config['maxLimit'];
$limit = isset($defaults['limit']) ? $defaults['limit'] : $config['limit'];
if ($limit > $maxLimit) {
$limit = $maxLimit;
}
if (empty($defaults['limit'])) {
$defaults['maxLimit'] = $maxLimit;
$defaults['limit'] = $limit;
}
return $defaults + $this->config();
$defaults['maxLimit'] = $maxLimit;
$defaults['limit'] = $limit;
return $defaults + $config;
}
/**
@@ -480,8 +480,8 @@ public function testMergeOptionsMaxLimit()
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
'page' => 1,
'limit' => 200,
'maxLimit' => 200,
'limit' => 100,
'maxLimit' => 100,
'paramType' => 'named',
'whitelist' => ['limit', 'sort', 'page', 'direction']
];
@@ -494,14 +494,62 @@ public function testMergeOptionsMaxLimit()
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
'page' => 1,
'limit' => 20,
'limit' => 10,
'maxLimit' => 10,
'paramType' => 'named',
'whitelist' => ['limit', 'sort', 'page', 'direction']
];
$this->assertEquals($expected, $result);
}
/**
* test getDefaults with limit > maxLimit in code.
*
* @return void
*/
public function testGetDefaultMaxLimit()
{
$settings = [
'page' => 1,
'limit' => 2,
'maxLimit' => 10,
'order' => [
'Users.username' => 'asc'
],
];
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
'page' => 1,
'limit' => 2,
'maxLimit' => 10,
'order' => [
'Users.username' => 'asc'
],
'whitelist' => ['limit', 'sort', 'page', 'direction']
];
$this->assertEquals($expected, $result);
$settings = [
'page' => 1,
'limit' => 100,
'maxLimit' => 10,
'order' => [
'Users.username' => 'asc'
],
];
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
'page' => 1,
'limit' => 10,
'maxLimit' => 10,
'order' => [
'Users.username' => 'asc'
],
'whitelist' => ['limit', 'sort', 'page', 'direction']
];
$this->assertEquals($expected, $result);
}
/**
* Integration test to ensure that validateSort is being used by paginate()
*

0 comments on commit 03960de

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