Skip to content

Commit

Permalink
Adding patch from 'mattcurry' Fixes Set::extract and parent selectors…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
markstory committed Feb 24, 2009
1 parent b1d0522 commit 082ef2e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cake/libs/set.php
Expand Up @@ -411,8 +411,10 @@ function extract($path, $data = null, $options = array()) {
$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;
Expand Down
46 changes: 46 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -873,6 +873,52 @@ function testExtract() {
$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
Expand Down

0 comments on commit 082ef2e

Please sign in to comment.