Permalink
Browse files

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
  • Loading branch information...
1 parent e0a8ffe commit 6d9b000aeeffd17811a0c774ce02638b6360fc7e @markstory markstory committed Nov 21, 2010
View
8 cake/libs/controller/controller.php
@@ -430,15 +430,15 @@ function __mergeVars() {
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) {
$this->{$var} = Set::merge($app, $normal);
}
} else {
$this->{$var} = Set::merge(
- $this->{$var}, array_diff($appVars[$var], $this->{$var})
+ array_diff($appVars[$var], $this->{$var}), $this->{$var}
);
}
}
@@ -456,15 +456,15 @@ function __mergeVars() {
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) {
$this->{$var} = Set::merge($app, $normal);
}
} else {
$this->{$var} = Set::merge(
- $this->{$var}, array_diff($appVars[$var], $this->{$var})
+ array_diff($appVars[$var], $this->{$var}), $this->{$var}
);
}
}
View
2 cake/tests/cases/libs/controller/controller.test.php
@@ -1149,7 +1149,7 @@ function testMergeVars() {
? 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
23 cake/tests/cases/libs/controller/controller_merge_vars.test.php
@@ -186,6 +186,25 @@ function testHelperSettingMergingNoDuplication() {
}
/**
+ * 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
*
* @return void
@@ -204,8 +223,8 @@ function testMergeVarsWithPlugin() {
$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');

0 comments on commit 6d9b000

Please sign in to comment.