From bdfb50e6bb72cb95bd96dfe143335bf63a109142 Mon Sep 17 00:00:00 2001 From: real34 Date: Mon, 14 Dec 2009 11:02:35 +0100 Subject: [PATCH] Fixed a bug in Set::extract. Wrong key returned when two arrays are at the extraction level. Signed-off-by: Mark Story --- cake/libs/set.php | 2 +- cake/tests/cases/libs/set.test.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index 4646387b8..cb9990c07 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -454,7 +454,7 @@ class Set extends Object { $item = $items[$token]; $matches[] = array( 'trace' => array_merge($context['trace'], $ctext), - 'key' => $key, + 'key' => $token, 'item' => $item, ); break; diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index d8da44451..082f0055a 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -1027,6 +1027,20 @@ class SetTest extends CakeTestCase { $expected = array('Second'); $this->assertEqual($result, $expected); } +/** + * testExtractWithArrays method + * + * @access public + * @return void + */ + function testExtractWithArrays() { + $data = array( + 'Level1' => array( + 'Level2' => array('test1', 'test2'), + 'Level2bis' => array('test3', 'test4'))); + $this->assertEqual(Set::extract('/Level1/Level2', $data), array(array('Level2' => array('test1', 'test2')))); + $this->assertEqual(Set::extract('/Level1/Level2bis', $data), array(array('Level2bis' => array('test3', 'test4')))); + } /** * testMatches method * @@ -1099,6 +1113,7 @@ class SetTest extends CakeTestCase { } + /** * testSetExtractReturnsEmptyArray method *