public function MenuUiTest::addCustomMenuCRUD 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::addCustomMenuCRUD()
- 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addCustomMenuCRUD()
Adds a custom menu using CRUD functions.
File
- core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 180
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 addCustomMenuCRUD() {
// Add a new custom menu.
$menu_name = strtolower($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.");
}