mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding tests from 'tfs' fixes inconsistencies in extracting elements with one path selector. Fixes #555
This commit is contained in:
parent
fbaabad6bb
commit
6c357ee555
2 changed files with 64 additions and 8 deletions
|
@ -447,18 +447,18 @@ class Set {
|
|||
$ctext = array($context['key']);
|
||||
if (!is_numeric($key)) {
|
||||
$ctext[] = $token;
|
||||
$token = array_shift($tokens);
|
||||
if (isset($items[$token])) {
|
||||
$ctext[] = $token;
|
||||
$item = $items[$token];
|
||||
$tok = array_shift($tokens);
|
||||
if (isset($items[$tok])) {
|
||||
$ctext[] = $tok;
|
||||
$item = $items[$tok];
|
||||
$matches[] = array(
|
||||
'trace' => array_merge($context['trace'], $ctext),
|
||||
'key' => $token,
|
||||
'key' => $tok,
|
||||
'item' => $item,
|
||||
);
|
||||
break;
|
||||
} else {
|
||||
array_unshift($tokens, $token);
|
||||
} elseif ($tok !== null) {
|
||||
array_unshift($tokens, $tok);
|
||||
}
|
||||
} else {
|
||||
$key = $token;
|
||||
|
|
|
@ -923,7 +923,6 @@ class SetTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
$expected = array(array('Category' => $tree[1]['Category']));
|
||||
$r = Set::extract('/Category[name=Category 2]', $tree);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
@ -1081,6 +1080,14 @@ class SetTest extends CakeTestCase {
|
|||
$r = Set::extract('/User/id', $nonZero);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$expected = array(
|
||||
array('User' => array('id' => 1, 'name' => 'John')),
|
||||
array('User' => array('id' => 2, 'name' => 'Bob')),
|
||||
array('User' => array('id' => 3, 'name' => 'Tony')),
|
||||
);
|
||||
$result = Set::extract('/User', $nonZero);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$nonSequential = array(
|
||||
'User' => array(
|
||||
0 => array('id' => 1),
|
||||
|
@ -1142,6 +1149,55 @@ class SetTest extends CakeTestCase {
|
|||
$this->assertEqual(Set::extract('/Level1/Level2', $data), array(array('Level2' => array('test1', 'test2'))));
|
||||
$this->assertEqual(Set::extract('/Level1/Level2bis', $data), array(array('Level2bis' => array('test3', 'test4'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* test extract() with elements that have non-array children.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testExtractWithNonArrayElements() {
|
||||
$data = array(
|
||||
'node' => array(
|
||||
array('foo'),
|
||||
'bar'
|
||||
)
|
||||
);
|
||||
$result = Set::extract('/node', $data);
|
||||
$expected = array(
|
||||
array('node' => array('foo')),
|
||||
'bar'
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array(
|
||||
'node' => array(
|
||||
'foo' => array('bar'),
|
||||
'bar' => array('foo')
|
||||
)
|
||||
);
|
||||
$result = Set::extract('/node', $data);
|
||||
$expected = array(
|
||||
array('foo' => array('bar')),
|
||||
array('bar' => array('foo')),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array(
|
||||
'node' => array(
|
||||
'foo' => array(
|
||||
'bar'
|
||||
),
|
||||
'bar' => 'foo'
|
||||
)
|
||||
);
|
||||
$result = Set::extract('/node', $data);
|
||||
$expected = array(
|
||||
array('foo' => array('bar')),
|
||||
'foo'
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMatches method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue