updating to Set::extract() to fix containable test fails, added set cases to match usage in containable.test

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7934 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-12-17 21:33:11 +00:00
parent a1046de895
commit 4dbd8e6791
2 changed files with 64 additions and 7 deletions

View file

@ -434,10 +434,29 @@ class Set extends Object {
$items = array($items);
}
}
foreach ($items as $item) {
foreach ($items as $key => $item) {
$ctext = array($context['key']);
if (!is_numeric($key)) {
$ctext[] = $token;
$token = array_shift($tokens);
if (isset($items[$token])) {
$ctext[] = $token;
$item = $items[$token];
$matches[] = array(
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item,
);
break;
}
} else {
$key = $token;
}
$matches[] = array(
'trace' => array_merge($context['trace'], array($context['key'])),
'key' => $token,
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item,
);
}

View file

@ -403,7 +403,7 @@ class SetTest extends CakeTestCase {
),
array('a' => array('II' => array('a' => 3, 'III' => array('a' => array('foo' => 4))))),
);
$nonSequential = array(
'User' => array(
0 => array('id' => 1),
@ -413,7 +413,7 @@ class SetTest extends CakeTestCase {
3 => array('id' => 5),
),
);
$nonZero = array(
'User' => array(
2 => array('id' => 1),
@ -423,7 +423,7 @@ class SetTest extends CakeTestCase {
3 => array('id' => 5),
),
);
$expected = array(array('a' => $c[2]['a']));
$r = Set::extract('/a/II[a=3]/..', $c);
$this->assertEqual($r, $expected);
@ -892,6 +892,44 @@ class SetTest extends CakeTestCase {
$this->assertTrue(Set::matches('/Article[id=2]', $a));
$this->assertFalse(Set::matches('/Article[id=4]', $a));
$this->assertTrue(Set::matches(array(), $a));
$r = array(
'Attachment' => array(
'keep' => array()
),
'Comment' => array(
'keep' => array(
'Attachment' => array(
'fields' => array(
0 => 'attachment',
),
),
)
),
'User' => array(
'keep' => array()
),
'Article' => array(
'keep' => array(
'Comment' => array(
'fields' => array(
0 => 'comment',
1 => 'published',
),
),
'User' => array(
'fields' => array(
0 => 'user',
),
),
)
)
);
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
$this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published'));
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
}
/**
* testClassicExtract method
@ -1604,7 +1642,7 @@ class SetTest extends CakeTestCase {
ksort($result);
ksort($expected);
$this->assertIdentical($result, $expected);
$class = new stdClass;