function MenuTest::addCustomMenu in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest::addCustomMenu()
Creates a custom menu.
Return value
\Drupal\system\Entity\Menu The custom menu that has been created.
2 calls to MenuTest::addCustomMenu()
- MenuTest::testBlockContextualLinks in core/
modules/ menu_ui/ src/ Tests/ MenuTest.php - Tests the contextual links on a menu block.
- MenuTest::testMenu in core/
modules/ menu_ui/ src/ Tests/ MenuTest.php - Tests menu functionality using the admin and user interfaces.
File
- core/
modules/ menu_ui/ src/ Tests/ MenuTest.php, line 185 - Contains \Drupal\menu_ui\Tests\MenuTest.
Class
- MenuTest
- 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\menu_ui\TestsCode
function addCustomMenu() {
// Try adding a menu using a menu_name that is too long.
$this
->drupalGet('admin/structure/menu/add');
$menu_name = substr(hash('sha256', $this
->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1);
$label = $this
->randomMachineName(16);
$edit = array(
'id' => $menu_name,
'description' => '',
'label' => $label,
);
$this
->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
// Verify that using a menu_name that is too long results in a validation
// message.
$this
->assertRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', array(
'@name' => t('Menu name'),
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
'%length' => Unicode::strlen($menu_name),
)));
// Change the menu_name so it no longer exceeds the maximum length.
$menu_name = substr(hash('sha256', $this
->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
$edit['id'] = $menu_name;
$this
->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
// Verify that no validation error is given for menu_name length.
$this
->assertNoRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', array(
'@name' => t('Menu name'),
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
'%length' => Unicode::strlen($menu_name),
)));
// Verify that the confirmation message is displayed.
$this
->assertRaw(t('Menu %label has been added.', array(
'%label' => $label,
)));
$this
->drupalGet('admin/structure/menu');
$this
->assertText($label, 'Menu created');
// Confirm that the custom menu block is available.
$this
->drupalGet('admin/structure/block/list/' . $this
->config('system.theme')
->get('default'));
$this
->clickLinkPartialName('Place block');
$this
->assertText($label);
// Enable the block.
$block = $this
->drupalPlaceBlock('system_menu_block:' . $menu_name);
$this->blockPlacements[$menu_name] = $block
->id();
return Menu::load($menu_name);
}