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
This commit is contained in:
mark_story 2009-02-24 03:01:06 +00:00
parent b1d05222b8
commit 082ef2e4b0
2 changed files with 49 additions and 1 deletions

View file

@ -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;

View file

@ -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