Skip to content

Commit

Permalink
Applying patch from 'SkieDr' to fix custom find type pagination. Remo…
Browse files Browse the repository at this point in the history
…ves parameters from exiting paginate(). Test case added.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8137 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Apr 7, 2009
1 parent 5f4cdf9 commit 9491e46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cake/libs/controller/controller.php
Expand Up @@ -1030,6 +1030,14 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
if (!isset($defaults['conditions'])) {
$defaults['conditions'] = array();
}

$type = 'all';

if (isset($defaults[0])) {
$type = $defaults[0];
unset($defaults[0]);
}

extract($options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options));

if (is_array($scope) && !empty($scope)) {
Expand All @@ -1040,12 +1048,7 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
if ($recursive === null) {
$recursive = $object->recursive;
}
$type = 'all';

if (isset($defaults[0])) {
$type = $defaults[0];
unset($defaults[0]);
}
$extra = array_diff_key($defaults, compact(
'conditions', 'fields', 'order', 'limit', 'page', 'recursive'
));
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -604,6 +604,26 @@ function testPaginatePassedArgs() {
);
$this->assertEqual($Controller->params['paging']['ControllerPost']['options'],$expected);
}
/**
* Test that special paginate types are called and that the type param doesn't leak out into defaults or options.
*
* @return void
**/
function testPaginateSpecialType() {
$Controller =& new Controller();
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();

$Controller->paginate = array('ControllerPost' => array('popular', 'fields' => array('id', 'title')));
$result = $Controller->paginate('ControllerPost');

$this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(2, 3));
$this->assertEqual($Controller->ControllerPost->lastQuery['conditions'], array('ControllerPost.id > ' => '1'));
$this->assertFalse(isset($Controller->params['paging']['ControllerPost']['defaults'][0]));
$this->assertFalse(isset($Controller->params['paging']['ControllerPost']['options'][0]));
}
/**
* testDefaultPaginateParams method
*
Expand Down

0 comments on commit 9491e46

Please sign in to comment.