diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index b209428aa..bc408a595 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -74,7 +74,7 @@ class Component extends Object { 'base' => $controller->base ); - if (!in_array('Session', $controller->components)) { + if (!in_array('Session', $controller->components) && !array_key_exists('Session', $controller->components)) { array_unshift($controller->components, 'Session'); } $this->_loadComponents($controller); diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 6673dbec1..4b595920e 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -375,7 +375,7 @@ class Controller extends Object { } } - if ($pluginController) { + if ($pluginController && $pluginName != null) { $appVars = get_class_vars($pluginController); $uses = $appVars['uses']; $merge = array('components', 'helpers'); diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index ec639c197..f8e2a1a73 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -443,6 +443,19 @@ class ComponentTest extends CakeTestCase { 'ComponentTestController' )); } +/** + * test that SessionComponent doesn't get added if its already in the components array. + * + * @return void + **/ + function testDoubleLoadingOfSessionComponent() { + $Controller =& new ComponentTestController(); + $Controller->uses = array(); + $Controller->components = array('Session'); + $Controller->constructClasses(); + + $this->assertEqual($Controller->components, array('Session' => '', 'Orange' => array('colour' => 'blood orange'))); + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 859e320a9..75e4e096c 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -851,7 +851,20 @@ class ControllerTest extends CakeTestCase { $this->assertTrue(isset($TestController->ControllerPost)); $this->assertTrue(isset($TestController->ControllerComment)); + } +/** + * Ensure that __mergeVars is not being greedy and merging with + * AppController when you make an instance of Controller + * + * @return void + **/ + function testMergeVarsNotGreedy() { + $Controller =& new Controller(); + $Controller->components = array(); + $Controller->uses = array(); + $Controller->constructClasses(); + $this->assertEqual($Controller->components, array('Session')); } /** * testReferer method