You are here

function MenuTest::addMenuLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest::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.

4 calls to MenuTest::addMenuLink()
MenuTest::doMenuTests in core/modules/menu_ui/src/Tests/MenuTest.php
Tests menu functionality.
MenuTest::testBlockContextualLinks in core/modules/menu_ui/src/Tests/MenuTest.php
Tests the contextual links on a menu block.
MenuTest::testMenuQueryAndFragment in core/modules/menu_ui/src/Tests/MenuTest.php
Adds and removes a menu link with a query string and fragment.
MenuTest::testUnpublishedNodeMenuItem in core/modules/menu_ui/src/Tests/MenuTest.php
Tests that menu items pointing to unpublished nodes are editable.

File

core/modules/menu_ui/src/Tests/MenuTest.php, line 609
Contains \Drupal\menu_ui\Tests\MenuTest.

Class

MenuTest
Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.

Namespace

Drupal\menu_ui\Tests

Code

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
    ->assertResponse(200);
  $title = '!link_' . $this
    ->randomMachineName(16);
  $edit = array(
    '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
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertText('The menu link has been saved.');
  $menu_links = entity_load_multiple_by_properties('menu_link_content', array(
    'title' => $title,
  ));
  $menu_link = reset($menu_links);
  $this
    ->assertTrue($menu_link, 'Menu link was found in database.');
  $this
    ->assertMenuLink($menu_link
    ->getPluginId(), array(
    'menu_name' => $menu_name,
    'children' => array(),
    'parent' => $parent,
  ));
  return $menu_link;
}