function MenuUiTest::addCustomMenu

Same name and namespace in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addCustomMenu()
  2. 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addCustomMenu()
  3. 11.x 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
Test the "expand all items" feature.
MenuUiTest::testMenu 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
Test that menu links with pending revisions can not be re-parented.

File

core/modules/menu_ui/tests/src/Functional/MenuUiTest.php, line 204

Class

MenuUiTest
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\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 = strtolower($this->randomMachineName(MenuStorage::MAX_ID_LENGTH + 1));
    $label = $this->randomMachineName(16);
    $edit = [
        'id' => $menu_name,
        'description' => '',
        'label' => $label,
    ];
    $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
    // Verify that using a menu_name that is too long results in a validation
    // message.
    $this->assertRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [
        '@name' => t('Menu name'),
        '%max' => MenuStorage::MAX_ID_LENGTH,
        '%length' => mb_strlen($menu_name),
    ]));
    // Change the menu_name so it no longer exceeds the maximum length.
    $menu_name = strtolower($this->randomMachineName(MenuStorage::MAX_ID_LENGTH));
    $edit['id'] = $menu_name;
    $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
    // Verify that no validation error is given for menu_name length.
    $this->assertNoRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [
        '@name' => t('Menu name'),
        '%max' => MenuStorage::MAX_ID_LENGTH,
        '%length' => mb_strlen($menu_name),
    ]));
    // Verify that the confirmation message is displayed.
    $this->assertRaw(t('Menu %label has been added.', [
        '%label' => $label,
    ]));
    $this->drupalGet('admin/structure/menu');
    $this->assertText($label, 'Menu created');
    // 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->assertText($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.