function MenuUiTest::addMenuLink
Same name in other branches
- 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addMenuLink()
- 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addMenuLink()
- 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addMenuLink()
Adds a menu link using the UI.
Parameters
string $parent: Optional parent menu link id.
string $path: The path to enter on the form. Defaults to the front page.
string $menu_name: Menu name. Defaults to 'tools'.
bool $expanded: Whether or not this menu link is expanded. Setting this to TRUE should test whether it works when we do the authenticatedUser tests. Defaults to FALSE.
string $weight: Menu weight. Defaults to 0.
Return value
\Drupal\menu_link_content\Entity\MenuLinkContent A menu link entity.
6 calls to MenuUiTest::addMenuLink()
- MenuUiTest::doMenuTests in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests menu functionality.
- MenuUiTest::testExpandAllItems in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests the "expand all items" feature.
- MenuUiTest::testLogoutLinkVisibility in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Test logout link isn't displayed when the user is logged out.
- MenuUiTest::testMenuQueryAndFragment in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Adds and removes a menu link with a query string and fragment.
- MenuUiTest::testMenuUiWithPendingRevisions in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests that menu links with pending revisions can not be re-parented.
File
-
core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 759
Class
- MenuUiTest
- Tests the menu UI.
Namespace
Drupal\Tests\menu_ui\FunctionalCode
public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') {
// View add menu link page.
$this->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
$this->assertSession()
->statusCodeEquals(200);
$title = '!link_' . $this->randomMachineName(16);
$edit = [
'link[0][uri]' => $path,
'title[0][value]' => $title,
'description[0][value]' => '',
'enabled[value]' => 1,
'expanded[value]' => $expanded,
'menu_parent' => $menu_name . ':' . $parent,
'weight[0][value]' => $weight,
];
// Add menu link.
$this->submitForm($edit, 'Save');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('The menu link has been saved.');
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
->loadByProperties([
'title' => $title,
]);
$menu_link = reset($menu_links);
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertMenuLink([
'menu_name' => $menu_name,
'children' => [],
'parent' => $parent,
], $menu_link->getPluginId());
return $menu_link;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.