Skip to content

Commit

Permalink
Applying patch from 'mcurry' Fixes Set::extract with mixed numeric an…
Browse files Browse the repository at this point in the history
…d stringKeys. Tests added. Fixes #6072

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8038 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Feb 17, 2009
1 parent 5bb9223 commit 27c3211
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cake/libs/set.php
Expand Up @@ -449,6 +449,8 @@ function extract($path, $data = null, $options = array()) {
'item' => $item,
);
break;
} else {
array_unshift($tokens, $token);
}
} else {
$key = $token;
Expand Down
22 changes: 18 additions & 4 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -435,10 +435,6 @@ function testExtract() {
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');

// $expected = array(
// array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)
// );

$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
Expand Down Expand Up @@ -859,6 +855,24 @@ function testExtract() {
$expected = array(array('children' => $tree[1]['children'][0]), array('children' => $tree[1]['children'][1]));
$r = Set::extract('/Category[name=Category 2]/../children', $tree);
$this->assertEqual($r, $expected);

$mixedKeys = array(
'User' => array(
0 => array(
'id' => 4,
'name' => 'Neo'
),
1 => array(
'id' => 5,
'name' => 'Morpheus'
),
'stringKey' => array()
)
);

$expected = array('Neo', 'Morpheus');
$r = Set::extract('/User/name', $mixedKeys);
$this->assertEqual($r, $expected);
}
/**
* testMatches method
Expand Down

0 comments on commit 27c3211

Please sign in to comment.