From c087576f2071503e725fbbfa4fe551b7a9feb9a7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 26 Mar 2012 22:39:13 -0400 Subject: [PATCH] Port changes done to Set into Hash See #2722 --- lib/Cake/Test/Case/Utility/HashTest.php | 22 ++++++++++++++++++++++ lib/Cake/Utility/Hash.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 761ce626f..dfe4f4940 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -1113,6 +1113,28 @@ class HashTest extends CakeTestCase { $this->assertEquals('value', $result[0]['Comment'][1]['insert']); } +/** + * Test that insert() can insert data over a string value. + * + * @return void + */ + public function testInsertOverwriteStringValue() { + $data = array( + 'Some' => array( + 'string' => 'value' + ) + ); + $result = Set::insert($data, 'Some.string.value', array('values')); + $expected = array( + 'Some' => array( + 'string' => array( + 'value' => array( 'values') + ) + ) + ); + $this->assertEquals($expected, $result); + } + /** * Test remove() method. * diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index ec1689027..4116161fe 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -270,7 +270,7 @@ class Hash { $_list =& $_list[$key]; } if (!is_array($_list)) { - return array(); + $_list = array(); } } if ($op === 'remove') {