diff --git a/cake/console/shells/shell.php b/cake/console/shells/shell.php index dd0e2079b8b..11cb62d119f 100644 --- a/cake/console/shells/shell.php +++ b/cake/console/shells/shell.php @@ -164,15 +164,13 @@ function __construct($stdout = null, $stderr = null, $stdin = null) { if ($this->stdin == null) { $this->stdin = new ConsoleInput('php://stdin'); } - $merge = array(); + + $parent = get_parent_class($this); if ($this->tasks !== null && $this->tasks !== false) { - $merge[] = 'tasks'; + $this->_mergeVars(array('tasks'), $parent, true); } if ($this->uses !== null && $this->uses !== false) { - $merge[] = 'uses'; - } - if (!empty($merge)) { - $this->_mergeVars($merge, get_parent_class($this)); + $this->_mergeVars(array('uses'), $parent, false); } } diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 4f6d21098d2..d4341655b4b 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -441,31 +441,18 @@ protected function __mergeVars() { array_unshift($this->uses, $plugin . $this->modelClass); } } elseif ($this->uses !== null || $this->uses !== false) { - $merge[] = 'uses'; - } - - $this->_mergeVars($merge, 'AppController'); - foreach ($merge as $prop) { - if ($prop !== 'components') { - $this->{$prop} = array_unique((array)$this->{$prop}); - } + $this->_mergeVars(array('uses'), 'AppController', false); } + $this->_mergeVars($merge, 'AppController', true); } if ($pluginController && $pluginName != null) { - $appVars = get_class_vars($pluginController); - $uses = $appVars['uses']; $merge = array('components', 'helpers'); if ($this->uses !== null || $this->uses !== false) { - $merge[] = 'uses'; + $this->_mergeVars(array('uses'), $pluginController, false); } $this->_mergeVars($merge, $pluginController); - foreach ($merge as $prop) { - if ($prop !== 'components') { - $this->{$prop} = array_unique((array)$this->{$prop}); - } - } } } diff --git a/cake/libs/object.php b/cake/libs/object.php index e103b853ef3..0f1d4903070 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -207,9 +207,10 @@ function _persist($name, $return = null, &$object, $type = null) { * * @param array $properties The name of the properties to merge. * @param sting $class The class to merge the property with. + * @param boolean $normalize Set to true to run the properties through Set::normalize() before merging. * @return void */ - protected function _mergeVars($properties, $class) { + protected function _mergeVars($properties, $class, $normalize = true) { $classProperties = get_class_vars($class); foreach ($properties as $var) { if ( @@ -218,6 +219,10 @@ protected function _mergeVars($properties, $class) { is_array($this->{$var}) && $this->{$var} != $classProperties[$var] ) { + if ($normalize) { + $classProperties[$var] = Set::normalize($classProperties[$var]); + $this->{$var} = Set::normalize($this->{$var}); + } $this->{$var} = Set::merge($classProperties[$var], $this->{$var}); } } diff --git a/cake/tests/cases/console/shells/shell.test.php b/cake/tests/cases/console/shells/shell.test.php index b7bc7098a82..ff341468bc6 100644 --- a/cake/tests/cases/console/shells/shell.test.php +++ b/cake/tests/cases/console/shells/shell.test.php @@ -70,8 +70,8 @@ protected function no_access() { } - public function mergeVars($properties, $class) { - return $this->_mergeVars($properties, $class); + public function mergeVars($properties, $class, $normalize = true) { + return $this->_mergeVars($properties, $class, $normalize); } } @@ -156,9 +156,12 @@ public function testConstruct() { function testMergeVars() { $this->Shell->tasks = array('DbConfig' => array('one', 'two')); $this->Shell->uses = array('Posts'); - $this->Shell->mergeVars(array('tasks', 'uses'), 'TestMergeShell'); + $this->Shell->mergeVars(array('tasks'), 'TestMergeShell'); + $this->Shell->mergeVars(array('uses'), 'TestMergeShell', false); + + $expected = array('DbConfig' => null, 'Fixture' => null, 'DbConfig' => array('one', 'two')); + $this->assertEquals($expected, $this->Shell->tasks); - $this->assertEquals(array('DbConfig', 'Fixture', 'DbConfig' => array('one', 'two')), $this->Shell->tasks); $expected = array('Fixture' => null, 'DbConfig' => array('one', 'two')); $this->assertEquals($expected, Set::normalize($this->Shell->tasks), 'Normalized results are wrong.'); $this->assertEquals(array('Comment', 'Posts'), $this->Shell->uses, 'Merged models are wrong.'); diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php index 4784707d496..431caa8ff7c 100644 --- a/cake/tests/cases/libs/controller/controller_merge_vars.test.php +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -201,7 +201,7 @@ function testHelperOrderPrecedence() { 'Custom' => null, 'Foo' => array('something') ); - $this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s'); + $this->assertSame($Controller->helpers, $expected, 'Order is incorrect.'); } /** @@ -239,7 +239,7 @@ function testMergeVarsWithPlugin() { 'MergeVar' => array('flag', 'otherFlag', 'redirect' => false), 'Auth' => array('setting' => 'val', 'otherVal'), ); - $this->assertEqual($expected, $Controller->components, 'Components are unexpected.'); + $this->assertEquals($expected, $Controller->components, 'Components are unexpected.'); } /**