Skip to content
Permalink
Browse files

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

  • Loading branch information...
markstory committed Sep 4, 2009
1 parent b5a38d6 commit 4f4411126c2e2096ed4f2f7c27846936198247ec
Showing with 16 additions and 1 deletion.
  1. +1 −1 cake/libs/set.php
  2. +15 −0 cake/tests/cases/libs/set.test.php
@@ -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.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.