From 082ef2e4b0cbf1c4adf70b85270b3ff43ce57e43 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 24 Feb 2009 03:01:06 +0000 Subject: [PATCH] Adding patch from 'mattcurry' Fixes Set::extract and parent selectors that with more than one element in the source array. Fixes #6043 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8055 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/set.php | 4 ++- cake/tests/cases/libs/set.test.php | 46 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index 4dd36cd6d..84b663c0f 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -411,8 +411,10 @@ class Set extends Object { $context['key'] = array_pop($context['trace']); if (isset($context['trace'][1]) && $context['trace'][1] > 0) { $context['item'] = $context['item'][0]; - } else { + } else if(!empty($context['item'][$key])){ $context['item'] = $context['item'][$key]; + } else { + $context['item'] = array_shift($context['item']); } $matches[] = $context; continue; diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 8efd2efe9..7d9ed51f6 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -873,6 +873,52 @@ class SetTest extends CakeTestCase { $expected = array('Neo', 'Morpheus'); $r = Set::extract('/User/name', $mixedKeys); $this->assertEqual($r, $expected); + + $single = array( + array( + 'CallType' => array( + 'name' => 'Internal Voice' + ), + 'x' => array( + 'hour' => 7 + ) + ) + ); + + $expected = array(7); + $r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $single); + $this->assertEqual($r, $expected); + + $multiple = array( + array( + 'CallType' => array( + 'name' => 'Internal Voice' + ), + 'x' => array( + 'hour' => 7 + ) + ), + array( + 'CallType' => array( + 'name' => 'Internal Voice' + ), + 'x' => array( + 'hour' => 2 + ) + ), + array( + 'CallType' => array( + 'name' => 'Internal Voice' + ), + 'x' => array( + 'hour' => 1 + ) + ) + ); + + $expected = array(7,2,1); + $r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $multiple); + $this->assertEqual($r, $expected); } /** * testMatches method