Permalink
Browse files

Merge branch 'torifat-set' into 1.3

  • Loading branch information...
markstory committed Apr 28, 2011
2 parents 169c330 + 03ffa3d commit 5273080962bcde87374696c219569a5d4498fe29
Showing with 41 additions and 7 deletions.
  1. +7 −7 cake/libs/set.php
  2. +34 −0 cake/tests/cases/libs/set.test.php
View
@@ -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)) {
@@ -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) {
@@ -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);
}
/**

0 comments on commit 5273080

Please sign in to comment.