public function ElementTreeTest::testApplyRecursivelyPreOrder in Little helpers 7.2
Test reading and modifying the element tree.
File
- tests/
ElementTreeTest.php, line 15
Class
- ElementTreeTest
- Test the element tree utility functions.
Namespace
Drupal\little_helpersCode
public function testApplyRecursivelyPreOrder() {
$test_array = [
'a' => [
'a1' => [],
],
'b' => [],
'#no-element' => 'test',
];
$element_keys = [];
$count = 0;
ElementTree::applyRecursively($test_array, function (&$element, $key) use (&$element_keys, &$count) {
if ($key) {
$element_keys[] = $key;
}
$element['#index'] = $count++;
});
$this
->assertEqual([
'a',
'a1',
'b',
], $element_keys);
$this
->assertEqual([
'a' => [
'a1' => [
'#index' => 2,
],
'#index' => 1,
],
'b' => [
'#index' => 3,
],
'#no-element' => 'test',
'#index' => 0,
], $test_array);
}