Skip to content

Commit

Permalink
Merge branch 'torifat-set' into 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 28, 2011
2 parents 169c330 + 03ffa3d commit 5273080
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cake/libs/set.php
Expand Up @@ -431,6 +431,13 @@ function extract($path, $data = null, $options = array()) {
'key' => $key,
'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'])) {
$items = $context['item'][$token];
if (!is_array($items)) {
Expand Down Expand Up @@ -470,13 +477,6 @@ function extract($path, $data = null, $options = array()) {
'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) {
Expand Down
34 changes: 34 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -939,6 +939,40 @@ function testExtract() {
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$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);
}

/**
Expand Down

0 comments on commit 5273080

Please sign in to comment.