public function MenuUiTest::deleteCustomMenu in Drupal 10
Same name and namespace in other branches
- 8 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::deleteCustomMenu()
- 9 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.
File
- core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 268
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\FunctionalCode
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.');
}