function MenuUiJavascriptTest::addMenuLink

Same name in other branches
  1. 8.9.x core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::addMenuLink()
  2. 10 core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::addMenuLink()
  3. 11.x core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::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_id: Menu ID. 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.

1 call to MenuUiJavascriptTest::addMenuLink()
MenuUiJavascriptTest::testBlockContextualLinks in core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php
Tests the contextual links on a menu block.

File

core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php, line 129

Class

MenuUiJavascriptTest
Tests custom menu and menu links operations using the UI.

Namespace

Drupal\Tests\menu_ui\FunctionalJavascript

Code

protected function addMenuLink($parent = '', $path = '/', $menu_id = 'tools', $expanded = FALSE, $weight = '0') {
    // View add menu link page.
    $this->drupalGet("admin/structure/menu/manage/{$menu_id}/add");
    $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_id . ':' . $parent,
        'weight[0][value]' => $weight,
    ];
    // Add menu link.
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('The menu link has been saved.');
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('menu_link_content');
    $menu_links = $storage->loadByProperties([
        'title' => $title,
    ]);
    $menu_link = reset($menu_links);
    // Check that the stored menu link meeting the expectations.
    $this->assertNotNull($menu_link);
    $this->assertMenuLink([
        'menu_name' => $menu_id,
        '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.