function MenuUiTest::addCustomMenu

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

Creates a custom menu.

Return value

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

3 calls to MenuUiTest::addCustomMenu()
MenuUiTest::testExpandAllItems in core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
Tests the "expand all items" feature.
MenuUiTest::testMenuAdministration in core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
Tests menu functionality using the admin and user interfaces.
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 277

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function addCustomMenu() {
    // Try adding a menu using a menu_name that is too long.
    $this->drupalGet('admin/structure/menu/add');
    $menu_name = $this->randomMachineName(MenuStorage::MAX_ID_LENGTH + 1);
    $label = $this->randomMachineName(16);
    $edit = [
        'id' => $menu_name,
        'description' => '',
        'label' => $label,
    ];
    $this->drupalGet('admin/structure/menu/add');
    $this->submitForm($edit, 'Save');
    // Verify that using a menu_name that is too long results in a validation
    // message.
    $this->assertSession()
        ->pageTextContains("Menu name cannot be longer than " . MenuStorage::MAX_ID_LENGTH . " characters but is currently " . mb_strlen($menu_name) . " characters long.");
    // Change the menu_name so it no longer exceeds the maximum length.
    $menu_name = $this->randomMachineName(MenuStorage::MAX_ID_LENGTH);
    $edit['id'] = $menu_name;
    $this->drupalGet('admin/structure/menu/add');
    $this->submitForm($edit, 'Save');
    // Verify that no validation error is given for menu_name length.
    $this->assertSession()
        ->pageTextNotContains("Menu name cannot be longer than " . MenuStorage::MAX_ID_LENGTH . " characters but is currently " . mb_strlen($menu_name) . " characters long.");
    // Verify that the confirmation message is displayed.
    $this->assertSession()
        ->pageTextContains("Menu {$label} has been 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');
    $this->assertSession()
        ->pageTextContains($label);
    // Enable the block.
    $block = $this->drupalPlaceBlock('system_menu_block:' . $menu_name);
    $this->blockPlacements[$menu_name] = $block->id();
    return Menu::load($menu_name);
}

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