From c8cf1a2c5bed17c6c24df5484a957abf354bde3a Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 28 Apr 2009 01:32:20 +0000 Subject: [PATCH] Updating __mergeVars to correctly merge parent and child component configurations. Applied patch from 'neilcrookes'. Test case added. Fixes #6325 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8157 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 2 +- .../cases/libs/controller/controller.test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 19a9aef76..5c33e1a49 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -393,7 +393,7 @@ class Controller extends Object { if ($var === 'components') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); - $this->{$var} = Set::merge($normal, $app); + $this->{$var} = Set::merge($app, $normal); } else { $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 53b1663ed..8c7b3204c 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -940,6 +940,22 @@ class ControllerTest extends CakeTestCase { $this->assertTrue(isset($TestController->ControllerPost)); $this->assertTrue(isset($TestController->ControllerComment)); } +/** + * test that options from child classes replace those in the parent classes. + * + * @access public + * @return void + **/ + function testChildComponentOptionsSupercedeParents() { + if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { + return; + } + $TestController =& new TestController(); + $expected = array('foo'); + $TestController->components = array('Cookie' => $expected); + $TestController->constructClasses(); + $this->assertEqual($TestController->components['Cookie'], $expected); + } /** * Ensure that __mergeVars is not being greedy and merging with * AppController when you make an instance of Controller