function MenuTreeStorageTest::assertMenuLink
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::assertMenuLink()
- 8.9.x core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::assertMenuLink()
- 10 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::assertMenuLink()
Tests that a link's stored representation matches the expected values.
@internal
Parameters
string $id: The ID of the menu link to test
array $expected_properties: A keyed array of column names and values like has_children and depth.
array $parents: An ordered array of the IDs of the menu links that are the parents.
array $children: Array of child IDs that are visible (enabled == 1).
3 calls to MenuTreeStorageTest::assertMenuLink()
- MenuTreeStorageTest::testMenuDisabledChildLinks in core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php - Tests with disabled child links.
- MenuTreeStorageTest::testMenuLinkMoving in core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php - Tests the tree with moving links inside the hierarchy.
- MenuTreeStorageTest::testSimpleHierarchy in core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php - Tests with a simple linear hierarchy.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php, line 422
Class
- MenuTreeStorageTest
- Tests the menu tree storage.
Namespace
Drupal\KernelTests\Core\MenuCode
protected function assertMenuLink(string $id, array $expected_properties, array $parents = [], array $children = []) : void {
$query = $this->connection
->select('menu_tree');
$query->fields('menu_tree');
$query->condition('id', $id);
foreach ($expected_properties as $field => $value) {
$query->condition($field, $value);
}
$all = $query->execute()
->fetchAll(\PDO::FETCH_ASSOC);
$this->assertCount(1, $all, "Found link {$id} matching all the expected properties");
$raw = reset($all);
// Put the current link onto the front.
array_unshift($parents, $raw['id']);
$query = $this->connection
->select('menu_tree');
$query->fields('menu_tree', [
'id',
'mlid',
]);
$query->condition('id', $parents, 'IN');
$found_parents = $query->execute()
->fetchAllKeyed(0, 1);
$this->assertSameSize($parents, $found_parents, 'Found expected number of parents');
$this->assertCount((int) $raw['depth'], $found_parents, 'Number of parents is the same as the depth');
$materialized_path = $this->treeStorage
->getRootPathIds($id);
$this->assertEquals(array_values($parents), array_values($materialized_path), 'Parents match the materialized path');
// Check that the selected mlid values of the parents are in the correct
// column, including the link's own.
for ($i = $raw['depth']; $i >= 1; $i--) {
$parent_id = array_shift($parents);
$this->assertEquals($found_parents[$parent_id], $raw["p{$i}"], "mlid of parent matches at column p{$i}");
}
for ($i = $raw['depth'] + 1; $i <= $this->treeStorage
->maxDepth(); $i++) {
$this->assertEquals(0, $raw["p{$i}"], "parent is 0 at column p{$i} greater than depth");
}
if ($parents) {
$this->assertEquals(end($parents), $raw['parent'], 'Ensure that the parent field is set properly');
}
// Verify that the child IDs match.
$this->assertEqualsCanonicalizing($children, array_keys($this->treeStorage
->loadAllChildren($id)));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.