Changing how mergeVars are handled, so the difference of app/current is used as a base.

Also fixing issues where passing settings to helpers in AppController could result in them not being correctly merged.
Thanks to hashmich for the partial patch.
Fixes #1183
This commit is contained in:
mark_story 2010-11-20 22:34:24 -05:00
parent e0a8ffe8a3
commit 6d9b000aee
3 changed files with 26 additions and 7 deletions

View file

@ -430,7 +430,7 @@ class Controller extends Object {
foreach ($merge as $var) {
if (!empty($appVars[$var]) && is_array($this->{$var})) {
if ($var === 'components') {
if ($var !== 'uses') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
if ($app !== $normal) {
@ -438,7 +438,7 @@ class Controller extends Object {
}
} else {
$this->{$var} = Set::merge(
$this->{$var}, array_diff($appVars[$var], $this->{$var})
array_diff($appVars[$var], $this->{$var}), $this->{$var}
);
}
}
@ -456,7 +456,7 @@ class Controller extends Object {
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if ($var === 'components') {
if ($var !== 'uses') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
if ($app !== $normal) {
@ -464,7 +464,7 @@ class Controller extends Object {
}
} else {
$this->{$var} = Set::merge(
$this->{$var}, array_diff($appVars[$var], $this->{$var})
array_diff($appVars[$var], $this->{$var}), $this->{$var}
);
}
}

View file

@ -1149,7 +1149,7 @@ class ControllerTest extends CakeTestCase {
? array_merge($appVars['uses'], $testVars['uses'])
: $testVars['uses'];
$this->assertEqual(count(array_diff($TestController->helpers, $helpers)), 0);
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->helpers), Set::normalize($helpers))), 0);
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);

View file

@ -185,6 +185,25 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
$this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s');
}
/**
* Test that helpers declared in appcontroller come before those in the subclass
* orderwise
*
* @return void
*/
function testHelperOrderPrecedence() {
$Controller =& new MergeVariablesController();
$Controller->helpers = array('Custom', 'Foo' => array('something'));
$Controller->constructClasses();
$expected = array(
'MergeVar' => array('format' => 'html', 'terse'),
'Custom' => null,
'Foo' => array('something')
);
$this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s');
}
/**
* test merging of vars with plugin
*
@ -204,8 +223,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
$this->assertEqual($Controller->components, $expected, 'Components are unexpected %s');
$expected = array(
'Javascript',
'MergeVar' => array('format' => 'html', 'terse')
'MergeVar' => array('format' => 'html', 'terse'),
'Javascript' => null
);
$this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s');