Merge branch 'torifat-set' into 1.3

This commit is contained in:
mark_story 2011-04-27 22:42:02 -04:00
commit 5273080962
2 changed files with 41 additions and 7 deletions

View file

@ -431,6 +431,13 @@ class Set {
'key' => $key, 'key' => $key,
'item' => array_keys($context['item']), 'item' => array_keys($context['item']),
); );
} elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.')) {
$context['trace'][] = $key;
$matches[] = array(
'trace' => $context['trace'],
'key' => $key,
'item' => $context['item'],
);
} elseif (is_array($context['item']) && array_key_exists($token, $context['item'])) { } elseif (is_array($context['item']) && array_key_exists($token, $context['item'])) {
$items = $context['item'][$token]; $items = $context['item'][$token];
if (!is_array($items)) { if (!is_array($items)) {
@ -470,13 +477,6 @@ class Set {
'item' => $item, 'item' => $item,
); );
} }
} elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.')) {
$context['trace'][] = $key;
$matches[] = array(
'trace' => $context['trace'],
'key' => $key,
'item' => $context['item'],
);
} }
} }
if ($conditions) { if ($conditions) {

View file

@ -939,6 +939,40 @@ class SetTest extends CakeTestCase {
$result = Set::extract('/ParentNode/name', $hasMany); $result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second'); $expected = array('Second');
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$data = array(
array(
'Category' => array(
'id' => 1,
'name' => 'First'
),
0 => array(
'value' => 50
)
),
array(
'Category' => array(
'id' => 2,
'name' => 'Second'
),
0 => array(
'value' => 60
)
)
);
$expected = array(
array(
'Category' => array(
'id' => 1,
'name' => 'First'
),
0 => array(
'value' => 50
)
)
);
$result = Set::extract('/Category[id=1]/..', $data);
$this->assertEqual($result, $expected);
} }
/** /**