function MenuTreeStorageTest::testMenuRebuild
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testMenuRebuild()
- 8.9.x core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testMenuRebuild()
- 11.x core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testMenuRebuild()
Ensure hierarchy persists after a menu rebuild.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php, line 324
Class
- MenuTreeStorageTest
- Tests the menu tree storage.
Namespace
Drupal\KernelTests\Core\MenuCode
public function testMenuRebuild() : void {
// root
// - child1
// -- child2
// --- child3
// ---- child4
$this->addMenuLink('root');
$this->addMenuLink('child1', 'root');
$this->addMenuLink('child2', 'child1');
$this->addMenuLink('child3', 'child2');
$this->addMenuLink('child4', 'child3');
$this->assertEquals(5, $this->treeStorage
->getSubtreeHeight('root'));
$this->assertEquals(4, $this->treeStorage
->getSubtreeHeight('child1'));
$this->assertEquals(3, $this->treeStorage
->getSubtreeHeight('child2'));
$this->assertEquals(2, $this->treeStorage
->getSubtreeHeight('child3'));
$this->assertEquals(1, $this->treeStorage
->getSubtreeHeight('child4'));
// Intentionally leave child3 out to mimic static or external links.
$definitions = $this->treeStorage
->loadMultiple([
'root',
'child1',
'child2',
'child4',
]);
$this->treeStorage
->rebuild($definitions);
$this->assertEquals(5, $this->treeStorage
->getSubtreeHeight('root'));
$this->assertEquals(4, $this->treeStorage
->getSubtreeHeight('child1'));
$this->assertEquals(3, $this->treeStorage
->getSubtreeHeight('child2'));
$this->assertEquals(2, $this->treeStorage
->getSubtreeHeight('child3'));
$this->assertEquals(1, $this->treeStorage
->getSubtreeHeight('child4'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.