function MenuUiTest::checkInvalidParentMenuLinks
Same name in other branches
- 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::checkInvalidParentMenuLinks()
- 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::checkInvalidParentMenuLinks()
- 11.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::checkInvalidParentMenuLinks()
Tests that parent options are limited by depth when adding menu links.
1 call to MenuUiTest::checkInvalidParentMenuLinks()
- MenuUiTest::doMenuTests in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests menu functionality.
File
-
core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 810
Class
- MenuUiTest
- Tests the menu UI.
Namespace
Drupal\Tests\menu_ui\FunctionalCode
public function checkInvalidParentMenuLinks() {
$last_link = NULL;
$plugin_ids = [];
// Get the max depth of the tree.
$menu_link_tree = \Drupal::service('menu.link_tree');
$max_depth = $menu_link_tree->maxDepth();
// Create a maximum number of menu links, each a child of the previous.
for ($i = 0; $i <= $max_depth - 1; $i++) {
$parent = $last_link ? 'tools:' . $last_link->getPluginId() : 'tools:';
$title = 'title' . $i;
$edit = [
'link[0][uri]' => '/',
'title[0][value]' => $title,
'menu_parent' => $parent,
'description[0][value]' => '',
'enabled[value]' => 1,
'expanded[value]' => FALSE,
'weight[0][value]' => '0',
];
$this->drupalGet("admin/structure/menu/manage/tools/add");
$this->submitForm($edit, 'Save');
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
->loadByProperties([
'title' => $title,
]);
$last_link = reset($menu_links);
$plugin_ids[] = $last_link->getPluginId();
}
$last_plugin_id = array_pop($plugin_ids);
// The last link cannot be a parent in the new menu link form.
$this->drupalGet('admin/structure/menu/manage/tools/add');
$value = 'tools:' . $last_plugin_id;
$this->assertSession()
->optionNotExists('edit-menu-parent', $value);
// All but the last link can be parents in the new menu link form.
foreach ($plugin_ids as $plugin_id) {
$this->assertSession()
->optionExists('edit-menu-parent', 'tools:' . $plugin_id);
}
// The last link does not have an "Add child" operation.
$this->drupalGet('admin/structure/menu/manage/tools');
$this->assertSession()
->linkByHrefNotExists('parent=' . urlencode($last_plugin_id));
// All but the last link do have an "Add child" operation.
foreach ($plugin_ids as $plugin_id) {
$this->assertSession()
->linkByHrefExists('parent=' . urlencode($plugin_id));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.