public function MenuTreeStorageTest::testMenuDisabledChildLinks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php \Drupal\system\Tests\Menu\MenuTreeStorageTest::testMenuDisabledChildLinks()
Tests with disabled child links.
File
- core/
modules/ system/ src/ Tests/ Menu/ MenuTreeStorageTest.php, line 185 - Contains \Drupal\system\Tests\Menu\MenuTreeStorageTest.
Class
- MenuTreeStorageTest
- Tests the menu tree storage.
Namespace
Drupal\system\Tests\MenuCode
public function testMenuDisabledChildLinks() {
// Add some links with parent on the previous one and test some values.
// <tools>
// - test1
// -- test2 (disabled)
$this
->addMenuLink('test1', '');
$this
->assertMenuLink('test1', array(
'has_children' => 0,
'depth' => 1,
));
$this
->addMenuLink('test2', 'test1', '<front>', array(), 'tools', array(
'enabled' => 0,
));
// The 1st link does not have any visible children, so has_children is 0.
$this
->assertMenuLink('test1', array(
'has_children' => 0,
'depth' => 1,
));
$this
->assertMenuLink('test2', array(
'has_children' => 0,
'depth' => 2,
'enabled' => 0,
), array(
'test1',
));
// Add more links with parent on the previous one.
// <footer>
// - footerA
// ===============
// <tools>
// - test1
// -- test2 (disabled)
// --- test3
// ---- test4
// ----- test5
// ------ test6
// ------- test7
// -------- test8
// --------- test9
$this
->addMenuLink('footerA', '', '<front>', array(), 'footer');
$visible_children = array();
for ($i = 3; $i <= $this->treeStorage
->maxDepth(); $i++) {
$parent = $i - 1;
$this
->addMenuLink("test{$i}", "test{$parent}");
$visible_children[] = "test{$i}";
}
// The 1st link does not have any visible children, so has_children is still
// 0. However, it has visible links below it that will be found.
$this
->assertMenuLink('test1', array(
'has_children' => 0,
'depth' => 1,
), array(), $visible_children);
// This should fail since test9 would end up at greater than max depth.
try {
$this
->moveMenuLink('test1', 'footerA');
$this
->fail('Exception was not thrown');
} catch (PluginException $e) {
$this
->pass($e
->getMessage());
}
// The opposite move should work, and change the has_children flag.
$this
->moveMenuLink('footerA', 'test1');
$visible_children[] = 'footerA';
$this
->assertMenuLink('test1', array(
'has_children' => 1,
'depth' => 1,
), array(), $visible_children);
}