mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
b1d05222b8
commit
082ef2e4b0
2 changed files with 49 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue