fix for Set::reverse() with _name_

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7495 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-08-24 22:08:13 +00:00
parent d8e1778a0d
commit 921a5770db
2 changed files with 18 additions and 3 deletions

View file

@ -98,7 +98,10 @@ class Set extends Object {
* @access public
*/
function pushDiff($array, $array2) {
if (!empty($array2)) {
if (empty($array) && !empty($array2)) {
return $array2;
}
if (!empty($array) && !empty($array2)) {
foreach ($array2 as $key => $value) {
if (!array_key_exists($key, $array)) {
$array[$key] = $value;
@ -915,7 +918,7 @@ class Set extends Object {
$new[$key] = (array)Set::reverse($value);
} else {
if (isset($value->_name_)) {
$new = Set::reverse($value);
$new = array_merge($new, Set::reverse($value));
} else {
$new[$key] = Set::reverse($value);
}

View file

@ -1361,6 +1361,18 @@ class SetTest extends CakeTestCase {
$result = Set::reverse($class);
$expected = array('User' => array('id' => '100'), 'someString'=> 'this is some string', 'Profile' => array('name' => 'Joe Mamma'));
$this->assertEqual($result, $expected);
$class = new stdClass;
$class->User = new stdClass;
$class->User->id = 100;
$class->User->_name_ = 'User';
$class->Profile = new stdClass;
$class->Profile->name = 'Joe Mamma';
$class->Profile->_name_ = 'Profile';
$result = Set::reverse($class);
$expected = array('User' => array('id' => '100'), 'Profile' => array('name' => 'Joe Mamma'));
$this->assertEqual($result, $expected);
}
/**
* testFormatting method