mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge pull request #935 from bar/master-hash-flatten
Set::flatten() fails to generate keys when 'tip' value is an empty array.
This commit is contained in:
commit
4c6c3b0554
3 changed files with 32 additions and 2 deletions
|
@ -298,7 +298,6 @@ class HashTest extends CakeTestCase {
|
||||||
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
|
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = Hash::flatten($data);
|
$result = Hash::flatten($data);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'0.Post.id' => '1',
|
'0.Post.id' => '1',
|
||||||
|
@ -317,6 +316,21 @@ class HashTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEquals($expected, $result);
|
$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(
|
$data = array(
|
||||||
array('Post' => array('id' => 1)),
|
array('Post' => array('id' => 1)),
|
||||||
array('Post' => array('id' => 2)),
|
array('Post' => array('id' => 2)),
|
||||||
|
|
|
@ -3054,6 +3054,7 @@ class SetTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* Tests Set::flatten
|
* Tests Set::flatten
|
||||||
*
|
*
|
||||||
|
* @see Hash test cases, as Set::flatten() is just a proxy.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testFlatten() {
|
public function testFlatten() {
|
||||||
|
@ -3064,6 +3065,21 @@ class SetTest extends CakeTestCase {
|
||||||
$data[9] = 'Shemp';
|
$data[9] = 'Shemp';
|
||||||
$result = Set::flatten($data);
|
$result = Set::flatten($data);
|
||||||
$this->assertEquals($data, $result);
|
$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 @@ class Hash {
|
||||||
$element = $data[$key];
|
$element = $data[$key];
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
|
|
||||||
if (is_array($element)) {
|
if (is_array($element) && !empty($element)) {
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
$stack[] = array($data, $path);
|
$stack[] = array($data, $path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue