mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
a1046de895
commit
4dbd8e6791
2 changed files with 64 additions and 7 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue