diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 116e993d8..19a9aef76 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -1030,6 +1030,14 @@ class Controller extends Object { 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)) { @@ -1040,12 +1048,7 @@ class Controller extends Object { 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' )); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 753717ec8..53b1663ed 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -604,6 +604,26 @@ class ControllerTest extends CakeTestCase { ); $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 *