"Fixes #3786, Missing keys when Model merges actsAs.

Added additional test for Set::merge();
Refactored Controller::_mergeVars."

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6292 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-01-01 01:07:24 +00:00
parent 013133457c
commit 1aa2324e8e
3 changed files with 44 additions and 9 deletions

View file

@ -314,7 +314,8 @@ class Controller extends Object {
* @access protected
*/
function _mergeVars () {
$pluginController = Inflector::camelize($this->plugin) . 'AppController';
$pluginName = Inflector::camelize($this->plugin);
$pluginController = $pluginName . 'AppController';
if (is_subclass_of($this, 'AppController') || is_subclass_of($this, $pluginController)) {
$appVars = get_class_vars('AppController');
@ -322,22 +323,26 @@ class Controller extends Object {
$merge = array('components', 'helpers');
$plugin = null;
if (isset($this->plugin)) {
$plugin = $this->plugin . '.';
if (!empty($this->plugin)) {
$plugin = $pluginName . '.';
if (!is_subclass_of($this, $pluginController)) {
$pluginController = null;
}
} else {
$pluginController = null;
}
if ($uses == $this->uses && !empty($this->uses)) {
array_unshift($this->uses, $plugin . $this->modelClass);
if (!in_array($plugin . $this->modelClass, $this->uses)) {
array_unshift($this->uses, $plugin . $this->modelClass);
}
} elseif ($this->uses !== null || $this->uses !== false) {
$merge[] = 'uses';
}
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
$this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
$this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
}
}
}
@ -353,7 +358,7 @@ class Controller extends Object {
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
$this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
$this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
}
}
}

View file

@ -383,8 +383,7 @@ class Model extends Overloadable {
if (is_subclass_of($this, 'AppModel')) {
$appVars = get_class_vars('AppModel');
$actsAs = $appVars['actsAs'];
$merge = array('actsAs');
$merge = array();
if ($this->actsAs !== null || $this->actsAs !== false) {
$merge[] = 'actsAs';
@ -392,7 +391,7 @@ class Model extends Overloadable {
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
$this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
$this->{$var} = Set::merge($appVars[$var], $this->{$var});
}
}
}

View file

@ -99,6 +99,37 @@ class SetTest extends UnitTestCase {
$r = $Set->merge($SetA, $SetB, $SetC);
$this->assertIdentical($r, $expected);
$this->assertIdentical($Set->value, $expected);
$a = array('Tree', 'CounterCache',
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')));
$b = array('Cacheable' => array('enabled' => false),
'Limit',
'Bindable',
'Validator',
'Transactional');
$expected = array('Tree', 'CounterCache',
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')),
'Cacheable' => array('enabled' => false),
'Limit',
'Bindable',
'Validator',
'Transactional');
$this->assertIdentical(Set::merge($a, $b), $expected);
$expected = array('Tree' => null, 'CounterCache' => null,
'Upload' => array('folder' => 'products',
'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')),
'Cacheable' => array('enabled' => false),
'Limit' => null,
'Bindable' => null,
'Validator' => null,
'Transactional' => null);
$this->assertIdentical(Set::normalize(Set::merge($a, $b)), $expected);
}
function testExtract() {