Skip to content

Commit

Permalink
Updating __mergeVars to correctly merge parent and child component co…
Browse files Browse the repository at this point in the history
…nfigurations.

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
  • Loading branch information
markstory committed Apr 28, 2009
1 parent b68c78f commit c8cf1a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -393,7 +393,7 @@ function __mergeVars() {
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}));
}
Expand Down
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -940,6 +940,22 @@ function testMergeVars() {
$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
Expand Down

0 comments on commit c8cf1a2

Please sign in to comment.