function MenuUiJavascriptTest::addCustomMenu

Same name in other branches
  1. 9 core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::addCustomMenu()
  2. 8.9.x core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::addCustomMenu()
  3. 10 core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php \Drupal\Tests\menu_ui\FunctionalJavascript\MenuUiJavascriptTest::addCustomMenu()

Creates a custom menu.

Return value

\Drupal\system\Entity\Menu The custom menu that has been created.

1 call to MenuUiJavascriptTest::addCustomMenu()
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 77

Class

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

Namespace

Drupal\Tests\menu_ui\FunctionalJavascript

Code

protected function addCustomMenu() {
    // Try adding a menu using a menu_name that is too long.
    $label = $this->randomMachineName(16);
    $menu_id = $this->randomMachineName(MenuStorage::MAX_ID_LENGTH + 1);
    $this->drupalGet('admin/structure/menu/add');
    $page = $this->getSession()
        ->getPage();
    // Type the label to activate the machine name field and the edit button.
    $page->fillField('Title', $label);
    // Wait for the machine name widget to be activated.
    $this->assertSession()
        ->waitForElementVisible('css', 'button[type=button].link:contains(Edit)');
    // Activate the machine name text field.
    $page->pressButton('Edit');
    // Try to fill a text longer than the allowed limit.
    $page->fillField('Menu name', $menu_id);
    $page->pressButton('Save');
    // Check that the menu was saved with the ID truncated to the max length.
    $menu = Menu::load(substr($menu_id, 0, MenuStorage::MAX_ID_LENGTH));
    $this->assertEquals($label, $menu->label());
    // Check that the menu was added.
    $this->drupalGet('admin/structure/menu');
    $this->assertSession()
        ->pageTextContains($label);
    // Confirm that the custom menu block is available.
    $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')
        ->get('default'));
    $this->clickLink('Place block');
    // Wait for the modal dialog to be loaded.
    $this->assertSession()
        ->waitForElement('css', "div[aria-describedby=drupal-modal]");
    // Check that the block is available to be placed.
    $this->assertSession()
        ->pageTextContains($label);
    return $menu;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.