You are here

public function MenuUiTest::deleteCustomMenu in Drupal 9

Same name and namespace in other branches
  1. 8 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::testMenu 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 254

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 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()
    ->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.');
}