function MenuUiTest::addCustomMenuCRUD

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

Adds a custom menu using CRUD functions.

1 call to MenuUiTest::addCustomMenuCRUD()
MenuUiTest::testMenuAdministration in core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
Tests menu functionality using the admin and user interfaces.

File

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

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function addCustomMenuCRUD() {
    // Add a new custom menu.
    $menu_name = $this->randomMachineName(MenuStorage::MAX_ID_LENGTH);
    $label = $this->randomMachineName(16);
    $menu = Menu::create([
        'id' => $menu_name,
        'label' => $label,
        'description' => 'Description text',
    ]);
    $menu->save();
    // Assert the new menu.
    $this->drupalGet('admin/structure/menu/manage/' . $menu_name);
    $this->assertSession()
        ->pageTextContains($label);
    // Edit the menu.
    $new_label = $this->randomMachineName(16);
    $menu->set('label', $new_label);
    $menu->save();
    $this->drupalGet('admin/structure/menu/manage/' . $menu_name);
    $this->assertSession()
        ->pageTextContains($new_label);
    // Delete the custom menu via the UI to testing destination handling.
    $this->drupalGet('admin/structure/menu');
    $this->assertSession()
        ->pageTextContains($new_label);
    // Click the "Delete menu" operation in the Tools row.
    $links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [
        ':menu_label' => $new_label,
        ':link_label' => 'Delete menu',
    ]);
    $links[0]->click();
    $this->submitForm([], 'Delete');
    $this->assertSession()
        ->addressEquals('admin/structure/menu');
    $this->assertSession()
        ->responseContains("The menu <em class=\"placeholder\">{$new_label}</em> has been deleted.");
}

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