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
This commit is contained in:
mark_story 2009-04-28 01:32:20 +00:00
parent b68c78fc0f
commit c8cf1a2c5b
2 changed files with 17 additions and 1 deletions

View file

@ -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}));
}

View file

@ -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