-
-
Save jippi/40565a21c21ebafbaf5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/app/tmp/cache/views/empty w/app/tmp/cache/views/empty | |
deleted file mode 100644 | |
index e69de29..0000000 | |
diff --git i/lib/Cake/Controller/Component/PaginatorComponent.php w/lib/Cake/Controller/Component/PaginatorComponent.php | |
index dcefbe7..0745920 100644 | |
--- i/lib/Cake/Controller/Component/PaginatorComponent.php | |
+++ w/lib/Cake/Controller/Component/PaginatorComponent.php | |
@@ -112,6 +112,14 @@ class PaginatorComponent extends Component { | |
public function __construct(ComponentCollection $collection, $settings = array()) { | |
$settings = array_merge($this->settings, (array)$settings); | |
$this->Controller = $collection->getController(); | |
+ | |
+ if (isset($this->Controller->paginate)) { | |
+ $settings = array_merge($this->settings, $this->Controller->paginate); | |
+ unset($this->Controller->paginate); | |
+ } | |
+ | |
+ $settings = new ArrayObject($settings); | |
+ | |
parent::__construct($collection, $settings); | |
} | |
@@ -339,7 +347,7 @@ class PaginatorComponent extends Component { | |
} | |
return array_merge( | |
array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named'), | |
- $defaults | |
+ (array)$defaults | |
); | |
} | |
diff --git i/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php w/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php | |
index 61206f1..b7bf660 100644 | |
--- i/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php | |
+++ w/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php | |
@@ -41,6 +41,53 @@ class PaginatorTestController extends Controller { | |
} | |
/** | |
+ * PaginatorTestControllerWithPaginate class | |
+ * | |
+ * @package Cake.Test.Case.Controller.Component | |
+ */ | |
+class PaginatorTestControllerWithPaginate extends Controller { | |
+ | |
+/** | |
+ * Paginate property | |
+ * | |
+ * @var array | |
+ */ | |
+ public $paginate = array( | |
+ 'Model' => array( | |
+ 'conditions' => array('id' => 1) | |
+ ) | |
+ ); | |
+ | |
+/** | |
+ * components property | |
+ * | |
+ * @var array | |
+ */ | |
+ public $components = array('Paginator'); | |
+ | |
+ public function index() { | |
+ $this->paginate = array( | |
+ 'PaginatorControllerPost.conditions' => array( | |
+ 'id' => 2 | |
+ ) | |
+ ); | |
+ | |
+ $this->paginate(); | |
+ } | |
+ | |
+ public function index_2() { | |
+ $this->paginate['fields'] = array( | |
+ 'id', 'title' | |
+ ); | |
+ | |
+ $this->paginate['conditions']['is_active'] = 1; | |
+ | |
+ // $this->paginate(); | |
+ } | |
+ | |
+} | |
+ | |
+/** | |
* PaginatorControllerPost class | |
* | |
* @package Cake.Test.Case.Controller.Component | |
@@ -403,6 +450,91 @@ class PaginatorComponentTest extends CakeTestCase { | |
} | |
/** | |
+ * testPaginateWithControllerPaginateDefined method | |
+ * | |
+ * @return void | |
+ */ | |
+ public function testPaginateWithControllerPaginateDefined() { | |
+ $Controller = new PaginatorTestControllerWithPaginate($this->request); | |
+ $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); | |
+ $Controller->constructClasses(); | |
+ | |
+ $result = (array)$Controller->Paginator->settings; | |
+ $expected = array( | |
+ 'page' => 1, | |
+ 'limit' => 20, | |
+ 'maxLimit' => 100, | |
+ 'paramType' => 'named', | |
+ 'Model' => array( | |
+ 'conditions' => array( | |
+ 'id' => 1 | |
+ ) | |
+ ) | |
+ ); | |
+ $this->assertEqual($result, $expected, 'Controller::$paginate settings was not copied into Paginator::$settings'); | |
+ } | |
+ | |
+/** | |
+ * testPaginateWithControllerPaginateDefinedModifiedDirectly method | |
+ * | |
+ * Modifying Controller::$paginate should reflect in Paginator::$settings correctly | |
+ * even though the controller property was defined | |
+ * | |
+ * @return void | |
+ */ | |
+ public function testPaginateWithControllerPaginateDefinedModifiedDirectly() { | |
+ $Controller = new PaginatorTestControllerWithPaginate($this->request); | |
+ $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); | |
+ $Controller->constructClasses(); | |
+ $Controller->index(); | |
+ | |
+ $result = $Controller->Paginator->settings; | |
+ $expected = array( | |
+ 'PaginatorControllerPost.conditions' => array( | |
+ 'id' => 2 | |
+ ) | |
+ ); | |
+ | |
+ $this->assertEqual($result, $expected, 'Modifying controller::$paginate inside an action did not work'); | |
+ } | |
+ | |
+/** | |
+ * testPaginateWithControllerPaginateDefinedModifiedDirectly method | |
+ * | |
+ * Modifying Controller::$paginate should reflect in Paginator::$settings correctly | |
+ * even though the controller property was defined | |
+ * | |
+ * @return void | |
+ */ | |
+ public function testPaginateWithControllerPaginateDefinedModifiedDirectly2() { | |
+ $Controller = new PaginatorTestControllerWithPaginate($this->request); | |
+ $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); | |
+ $Controller->constructClasses(); | |
+ $Controller->index_2(); | |
+ | |
+ $result = (array)$Controller->Paginator->settings; | |
+ $expected = array( | |
+ 'page' => 1, | |
+ 'limit' => 20, | |
+ 'maxLimit' => 100, | |
+ 'paramType' => 'named', | |
+ 'Model' => array( | |
+ 'conditions' => array( | |
+ 'id' => 1 | |
+ ) | |
+ ), | |
+ 'fields' => array( | |
+ 'id', 'title' | |
+ ), | |
+ 'conditions' => array( | |
+ 'is_active' => 1 | |
+ ) | |
+ ); | |
+ | |
+ $this->assertEqual($result, $expected, 'Modifying controller::$paginate inside an action did not work'); | |
+ } | |
+ | |
+/** | |
* Test that non-numeric values are rejected for page, and limit | |
* | |
* @return void |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment