Fixing empty arrays being dropped with Set::sort(). Fixed #67

This commit is contained in:
mark_story 2009-09-03 23:09:27 -04:00
parent b5a38d69a5
commit 4f4411126c
2 changed files with 16 additions and 1 deletions

View file

@ -1073,7 +1073,7 @@ class Set extends Object {
if (!is_null($key)) {
$id = $key;
}
if (is_array($r)) {
if (is_array($r) && count($r)) {
$stack = array_merge($stack, Set::__flatten($r, $id));
} else {
$stack[] = array('id' => $id, 'value' => $r);

View file

@ -336,6 +336,21 @@ class SetTest extends CakeTestCase {
);
$a = Set::sort($a, '{n}.Person.name', 'ASC');
$this->assertIdentical($a, $b);
$names = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$result = Set::sort($names, '{n}.employees.0.name', 'asc', 1);
$expected = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$this->assertEqual($result, $expected);
}
/**
* testExtract method