mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing empty arrays being dropped with Set::sort(). Fixed #67
This commit is contained in:
parent
b5a38d69a5
commit
4f4411126c
2 changed files with 16 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue