function MenuUiTest::deleteCustomMenu

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

Deletes the locally stored custom menu.

This deletes the custom menu that is stored in $this->menu and performs tests on the menu delete user interface.

1 call to MenuUiTest::deleteCustomMenu()
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 328

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function deleteCustomMenu() {
    $menu_name = $this->menu
        ->id();
    $label = $this->menu
        ->label();
    // Delete custom menu.
    $this->drupalGet("admin/structure/menu/manage/{$menu_name}/delete");
    $this->submitForm([], 'Delete');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->addressEquals("admin/structure/menu");
    $this->assertSession()
        ->pageTextContains("The menu {$label} has been deleted.");
    $this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
    // Test if all menu links associated with the menu were removed from
    // database.
    $result = \Drupal::entityTypeManager()->getStorage('menu_link_content')
        ->loadByProperties([
        'menu_name' => $menu_name,
    ]);
    $this->assertEmpty($result, 'All menu links associated with the custom menu were deleted.');
    // Make sure there's no delete button on system menus.
    $this->drupalGet('admin/structure/menu/manage/main');
    $this->assertSession()
        ->responseNotContains('edit-delete');
    // Try to delete the main menu.
    $this->drupalGet('admin/structure/menu/manage/main/delete');
    $this->assertSession()
        ->pageTextContains('You are not authorized to access this page.');
}

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