Skip to content
Permalink
Browse files

Set::flatten() fails to generate keys when 'tip' value is an empty

array.
  • Loading branch information...
bar committed Nov 2, 2012
1 parent ce3aa69 commit 8b2b0771192390bd35dc327a03a50a7802a08124
Showing with 32 additions and 2 deletions.
  1. +15 −1 lib/Cake/Test/Case/Utility/HashTest.php
  2. +16 −0 lib/Cake/Test/Case/Utility/SetTest.php
  3. +1 −1 lib/Cake/Utility/Hash.php
@@ -298,7 +298,6 @@ public function testFlatten() {
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
)
);
$result = Hash::flatten($data);
$expected = array(
'0.Post.id' => '1',
@@ -317,6 +316,21 @@ public function testFlatten() {
);
$this->assertEquals($expected, $result);
$data = array(
array(
'Post' => array('id' => '1', 'author_id' => null, 'title' => 'First Post'),
'Author' => array(),
)
);
$result = Hash::flatten($data);
$expected = array(
'0.Post.id' => '1',
'0.Post.author_id' => null,
'0.Post.title' => 'First Post',
'0.Author' => array()
);
$this->assertEquals($expected, $result);
$data = array(
array('Post' => array('id' => 1)),
array('Post' => array('id' => 2)),
@@ -3054,6 +3054,7 @@ public function testStrictKeyCheck() {
/**
* Tests Set::flatten
*
* @see Hash test cases, as Set::flatten() is just a proxy.
* @return void
*/
public function testFlatten() {
@@ -3064,6 +3065,21 @@ public function testFlatten() {
$data[9] = 'Shemp';
$result = Set::flatten($data);
$this->assertEquals($data, $result);
$data = array(
array(
'Post' => array('id' => '1', 'author_id' => null, 'title' => 'First Post'),
'Author' => array(),
)
);
$result = Set::flatten($data);
$expected = array(
'0.Post.id' => '1',
'0.Post.author_id' => null,
'0.Post.title' => 'First Post',
'0.Author' => array()
);
$this->assertEquals($expected, $result);
}
/**
@@ -527,7 +527,7 @@ public static function flatten(array $data, $separator = '.') {
$element = $data[$key];
unset($data[$key]);
if (is_array($element)) {
if (is_array($element) && !empty($element)) {
if (!empty($data)) {
$stack[] = array($data, $path);
}

0 comments on commit 8b2b077

Please sign in to comment.
You can’t perform that action at this time.