mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making filtering of extracted arrays remember their key. This fixes attribute selectors followed by parent selectors returning seemingly random results. Fixes #502
This commit is contained in:
parent
b559be5822
commit
35446a42a9
2 changed files with 75 additions and 1 deletions
|
@ -486,7 +486,7 @@ class Set extends Object {
|
||||||
$length = count($matches);
|
$length = count($matches);
|
||||||
foreach ($matches as $i => $match) {
|
foreach ($matches as $i => $match) {
|
||||||
if (Set::matches(array($condition), $match['item'], $i + 1, $length)) {
|
if (Set::matches(array($condition), $match['item'], $i + 1, $length)) {
|
||||||
$filtered[] = $match;
|
$filtered[$i] = $match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$matches = $filtered;
|
$matches = $filtered;
|
||||||
|
|
|
@ -974,6 +974,80 @@ class SetTest extends CakeTestCase {
|
||||||
$expected = array('Second');
|
$expected = array('Second');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* test parent selectors with extract
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testExtractParentSelector() {
|
||||||
|
$a = array(
|
||||||
|
'Model' => array(
|
||||||
|
'0' => array(
|
||||||
|
'id' => 18,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 1,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 18,
|
||||||
|
'type' => 1
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'1' => array(
|
||||||
|
'id' => 0,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 2,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 0,
|
||||||
|
'type' => 1
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'2' => array(
|
||||||
|
'id' => 17,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 3,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 17,
|
||||||
|
'type' => 2
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'3' => array(
|
||||||
|
'id' => 0,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 4,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 0,
|
||||||
|
'type' => 2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
array(
|
||||||
|
'Model' => array(
|
||||||
|
'id' => 17,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 3,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 17,
|
||||||
|
'type' => 2
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'Model' => array(
|
||||||
|
'id' => 0,
|
||||||
|
'SubModelsModel' => array(
|
||||||
|
'id' => 4,
|
||||||
|
'submodel_id' => 66,
|
||||||
|
'model_id' => 0,
|
||||||
|
'type' => 2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$r = Set::extract('/Model/SubModelsModel[type=2]/..', $a);
|
||||||
|
$this->assertEqual($r, $expected);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* test that extract() still works when arrays don't contain a 0 index.
|
* test that extract() still works when arrays don't contain a 0 index.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue