From 95b74bd9efee7e3c63e08bb9f983cfdec72c3cb2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jul 2013 09:08:24 -0400 Subject: [PATCH] Make sure ComponentCollection has the controller dependency. Add setter method as changing ComponentCollection's constructor now is not possible. This fixes issues where components that rely on Collection->getController() in their constructor can work properly. Fixes #3946 --- lib/Cake/Controller/ComponentCollection.php | 10 ++++++++++ lib/Cake/TestSuite/ControllerTestCase.php | 1 + 2 files changed, 11 insertions(+) diff --git a/lib/Cake/Controller/ComponentCollection.php b/lib/Cake/Controller/ComponentCollection.php index caad0f839..d1499eeda 100644 --- a/lib/Cake/Controller/ComponentCollection.php +++ b/lib/Cake/Controller/ComponentCollection.php @@ -54,6 +54,16 @@ class ComponentCollection extends ObjectCollection implements CakeEventListener } } +/** + * Set the controller associated with the collection. + * + * @param Controller $Controller Controller to set + * @return void + */ + public function setController(Controller $Controller) { + $this->_Controller = $Controller; + } + /** * Get the controller associated with the collection. * diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php index 4d224f5f0..28227a437 100644 --- a/lib/Cake/TestSuite/ControllerTestCase.php +++ b/lib/Cake/TestSuite/ControllerTestCase.php @@ -334,6 +334,7 @@ abstract class ControllerTestCase extends CakeTestCase { $request = $this->getMock('CakeRequest'); $response = $this->getMock('CakeResponse', array('_sendHeader')); $controllerObj->__construct($request, $response); + $controllerObj->Components->setController($controllerObj); $config = ClassRegistry::config('Model'); foreach ($mocks['models'] as $model => $methods) {