mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
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:
parent
e0a8ffe8a3
commit
6d9b000aee
3 changed files with 26 additions and 7 deletions
|
@ -430,7 +430,7 @@ class Controller extends Object {
|
||||||
|
|
||||||
foreach ($merge as $var) {
|
foreach ($merge as $var) {
|
||||||
if (!empty($appVars[$var]) && is_array($this->{$var})) {
|
if (!empty($appVars[$var]) && is_array($this->{$var})) {
|
||||||
if ($var === 'components') {
|
if ($var !== 'uses') {
|
||||||
$normal = Set::normalize($this->{$var});
|
$normal = Set::normalize($this->{$var});
|
||||||
$app = Set::normalize($appVars[$var]);
|
$app = Set::normalize($appVars[$var]);
|
||||||
if ($app !== $normal) {
|
if ($app !== $normal) {
|
||||||
|
@ -438,7 +438,7 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->{$var} = Set::merge(
|
$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) {
|
foreach ($merge as $var) {
|
||||||
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
|
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
|
||||||
if ($var === 'components') {
|
if ($var !== 'uses') {
|
||||||
$normal = Set::normalize($this->{$var});
|
$normal = Set::normalize($this->{$var});
|
||||||
$app = Set::normalize($appVars[$var]);
|
$app = Set::normalize($appVars[$var]);
|
||||||
if ($app !== $normal) {
|
if ($app !== $normal) {
|
||||||
|
@ -464,7 +464,7 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->{$var} = Set::merge(
|
$this->{$var} = Set::merge(
|
||||||
$this->{$var}, array_diff($appVars[$var], $this->{$var})
|
array_diff($appVars[$var], $this->{$var}), $this->{$var}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1149,7 +1149,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
? array_merge($appVars['uses'], $testVars['uses'])
|
? array_merge($appVars['uses'], $testVars['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($TestController->uses, $uses)), 0);
|
||||||
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
|
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,25 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
$this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s');
|
$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
|
* test merging of vars with plugin
|
||||||
*
|
*
|
||||||
|
@ -204,8 +223,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
$this->assertEqual($Controller->components, $expected, 'Components are unexpected %s');
|
$this->assertEqual($Controller->components, $expected, 'Components are unexpected %s');
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Javascript',
|
'MergeVar' => array('format' => 'html', 'terse'),
|
||||||
'MergeVar' => array('format' => 'html', 'terse')
|
'Javascript' => null
|
||||||
);
|
);
|
||||||
$this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s');
|
$this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue