public function MenuUiTest::addCustomMenu in Drupal 9
Same name and namespace in other branches
- 8 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::addCustomMenu()
Creates a custom menu.
Return value
\Drupal\system\Entity\Menu The custom menu that has been created.
3 calls to MenuUiTest::addCustomMenu()
- MenuUiTest::testExpandAllItems in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests the "expand all items" feature.
- MenuUiTest::testMenu in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests menu functionality using the admin and user interfaces.
- MenuUiTest::testMenuUiWithPendingRevisions in core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php - Tests that menu links with pending revisions can not be re-parented.
File
- core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 206
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 addCustomMenu() {
// Try adding a menu using a menu_name that is too long.
$this
->drupalGet('admin/structure/menu/add');
$menu_name = strtolower($this
->randomMachineName(MenuStorage::MAX_ID_LENGTH + 1));
$label = $this
->randomMachineName(16);
$edit = [
'id' => $menu_name,
'description' => '',
'label' => $label,
];
$this
->drupalGet('admin/structure/menu/add');
$this
->submitForm($edit, 'Save');
// Verify that using a menu_name that is too long results in a validation
// message.
$this
->assertSession()
->pageTextContains("Menu name cannot be longer than " . MenuStorage::MAX_ID_LENGTH . " characters but is currently " . mb_strlen($menu_name) . " characters long.");
// Change the menu_name so it no longer exceeds the maximum length.
$menu_name = strtolower($this
->randomMachineName(MenuStorage::MAX_ID_LENGTH));
$edit['id'] = $menu_name;
$this
->drupalGet('admin/structure/menu/add');
$this
->submitForm($edit, 'Save');
// Verify that no validation error is given for menu_name length.
$this
->assertSession()
->pageTextNotContains("Menu name cannot be longer than " . MenuStorage::MAX_ID_LENGTH . " characters but is currently " . mb_strlen($menu_name) . " characters long.");
// Verify that the confirmation message is displayed.
$this
->assertSession()
->pageTextContains("Menu {$label} has been added.");
$this
->drupalGet('admin/structure/menu');
$this
->assertSession()
->pageTextContains($label);
// Confirm that the custom menu block is available.
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLink('Place block');
$this
->assertSession()
->pageTextContains($label);
// Enable the block.
$block = $this
->drupalPlaceBlock('system_menu_block:' . $menu_name);
$this->blockPlacements[$menu_name] = $block
->id();
return Menu::load($menu_name);
}