Permalink
Browse files

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

  • Loading branch information...
1 parent b5a38d6 commit 4f4411126c2e2096ed4f2f7c27846936198247ec @markstory markstory committed Sep 4, 2009
Showing with 16 additions and 1 deletion.
  1. +1 −1 cake/libs/set.php
  2. +15 −0 cake/tests/cases/libs/set.test.php
View
@@ -1073,7 +1073,7 @@ function __flatten($results, $key = null) {
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);
@@ -336,6 +336,21 @@ function testSort() {
);
$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

0 comments on commit 4f44111

Please sign in to comment.