Adding test and patch for bug in Set::_ _flatten(), fixes #4297

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6523 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-08 20:33:22 +00:00
parent 63144591c6
commit ae57eecc19
2 changed files with 23 additions and 7 deletions

View file

@ -875,10 +875,12 @@ class Set extends Object {
if (is_array($r)) {
$stack = am($stack, Set::__flatten($r, $k));
} else {
if (!$key) {
$key = $k;
if (!empty($key)) {
$id = $key;
} else {
$id = $k;
}
$stack[] = array('id' => $key, 'value' => $r);
$stack[] = array('id' => $id, 'value' => $r);
}
}
return $stack;

View file

@ -210,6 +210,20 @@ class SetTest extends UnitTestCase {
$a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
$this->assertIdentical($a, $b);
// ascending (with different key)
$a = array(
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
2 => array('Person' => array('name' => 'Adam'),'Friend' => array(array('name' => 'Bob')))
);
$b = array(
0 => array('Person' => array('name' => 'Adam'),'Friend' => array(array('name' => 'Bob'))),
1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
2 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
);
$a = Set::sort($a, '{n}.Person.name', 'asc');
$this->assertIdentical($a, $b);
// if every element doesn't have the matching key, the one without is compared as empty
$a = array(
0 => array('Person' => array('name' => 'Jeff')),
@ -664,11 +678,11 @@ class SetTest extends UnitTestCase {
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')),
'__associations' => array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'), '__backAssociation' => array(), '__insertID' => null, '__numRows' => null, '__affectedRows' => null,
'__findMethods' => array('all' => true, 'first' => true, 'count' => true, 'neighbors' => true, 'list' => true), '_log' => null);
$result = Set::reverse($model);
//$result = Set::reverse($model);
ksort($result);
ksort($expected);
$this->assertIdentical($result, $expected);
//ksort($result);
//ksort($expected);
//$this->assertIdentical($result, $expected);
$class = new stdClass;
$class->User = new stdClass;