Make sure invalid arrays return empty array instead of throwing notices.

This commit is contained in:
euromark 2014-05-14 23:53:58 +02:00
parent ef96724bc8
commit 143e8e4c56
2 changed files with 21 additions and 0 deletions

View file

@ -2242,6 +2242,25 @@ class HashTest extends CakeTestCase {
$this->assertEquals($input, $result);
}
/**
* Tests that nest() returns an empty array for invalid input instead of throwing notices.
*
* @return void
*/
public function testNestInvalid() {
$input = array(
array(
'ParentCategory' => array(
'id' => '1',
'name' => 'Lorem ipsum dolor sit amet',
'parent_id' => '1'
)
)
);
$result = Hash::nest($input);
$this->assertSame(array(), $result);
}
/**
* testMergeDiff method
*

View file

@ -1037,6 +1037,8 @@ class Hash {
if ($options['root']) {
$root = $options['root'];
} elseif (!$return) {
return array();
} else {
$root = self::get($return[0], $parentKeys);
}