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. 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::deleteCustomMenu()
  3. 11.x 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 257

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->drupalPostForm("admin/structure/menu/manage/{$menu_name}/delete", [], t('Delete'));
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertRaw(t('The menu %title has been deleted.', [
    '%title' => $label,
  ]), 'Custom menu was 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->assertNoRaw('edit-delete', 'The delete button was not found');
  // Try to delete the main menu.
  $this->drupalGet('admin/structure/menu/manage/main/delete');
  $this->assertText(t('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.