class MenuUiTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest
Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.
@group menu_ui
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses FunctionalTestSetupTrait, TestSetupTrait, AssertLegacyTrait, BlockCreationTrait, ConfigTestTrait, ContentTypeCreationTrait, NodeCreationTrait, PhpunitCompatibilityTrait, RandomGeneratorTrait, TestRequirementsTrait, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\menu_ui\Functional\MenuUiTest uses MenuUiTrait
Expanded class hierarchy of MenuUiTest
File
- core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 23
Namespace
Drupal\Tests\menu_ui\FunctionalView source
class MenuUiTest extends BrowserTestBase {
use MenuUiTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'block',
'contextual',
'help',
'menu_link_content',
'menu_ui',
'node',
'path',
'test_page_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with administration rights.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* An authenticated user.
*
* @var \Drupal\user\UserInterface
*/
protected $authenticatedUser;
/**
* Array of placed menu blocks keyed by block ID.
*
* @var array
*/
protected $blockPlacements;
/**
* A test menu.
*
* @var \Drupal\system\Entity\Menu
*/
protected $menu;
/**
* An array of test menu links.
*
* @var \Drupal\menu_link_content\MenuLinkContentInterface[]
*/
protected $items;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
// Create users.
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer blocks',
'administer menu',
'create article content',
]);
$this->authenticatedUser = $this
->drupalCreateUser([]);
}
/**
* Tests menu functionality using the admin and user interfaces.
*/
public function testMenu() {
// Log in the user.
$this
->drupalLogin($this->adminUser);
$this->items = [];
$this->menu = $this
->addCustomMenu();
$this
->doMenuTests();
$this
->doTestMenuBlock();
$this
->addInvalidMenuLink();
$this
->addCustomMenuCRUD();
// Verify that the menu links rebuild is idempotent and leaves the same
// number of links in the table.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$before_count = $menu_link_manager
->countMenuLinks(NULL);
$menu_link_manager
->rebuild();
$after_count = $menu_link_manager
->countMenuLinks(NULL);
$this
->assertIdentical($before_count, $after_count, 'MenuLinkManager::rebuild() does not add more links');
// Do standard user tests.
// Log in the user.
$this
->drupalLogin($this->authenticatedUser);
$this
->verifyAccess(403);
foreach ($this->items as $item) {
// Menu link URIs are stored as 'internal:/node/$nid'.
$node = Node::load(str_replace('internal:/node/', '', $item->link->uri));
$this
->verifyMenuLink($item, $node);
}
// Log in the administrator.
$this
->drupalLogin($this->adminUser);
// Verify delete link exists and reset link does not exist.
$this
->drupalGet('admin/structure/menu/manage/' . $this->menu
->id());
$this
->assertLinkByHref(Url::fromRoute('entity.menu_link_content.delete_form', [
'menu_link_content' => $this->items[0]
->id(),
])
->toString());
$this
->assertNoLinkByHref(Url::fromRoute('menu_ui.link_reset', [
'menu_link_plugin' => $this->items[0]
->getPluginId(),
])
->toString());
// Check delete and reset access.
$this
->drupalGet('admin/structure/menu/item/' . $this->items[0]
->id() . '/delete');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/structure/menu/link/' . $this->items[0]
->getPluginId() . '/reset');
$this
->assertSession()
->statusCodeEquals(403);
// Delete menu links.
foreach ($this->items as $item) {
$this
->deleteMenuLink($item);
}
// Delete custom menu.
$this
->deleteCustomMenu();
// Modify and reset a standard menu link.
$instance = $this
->getStandardMenuLink();
$old_weight = $instance
->getWeight();
// Edit the static menu link.
$edit = [];
$edit['weight'] = 10;
$id = $instance
->getPluginId();
$this
->drupalPostForm("admin/structure/menu/link/{$id}/edit", $edit, t('Save'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('The menu link has been saved.');
$menu_link_manager
->resetDefinitions();
$instance = $menu_link_manager
->createInstance($instance
->getPluginId());
$this
->assertEqual($edit['weight'], $instance
->getWeight(), 'Saving an existing link updates the weight.');
$this
->resetMenuLink($instance, $old_weight);
}
/**
* Adds a custom menu using CRUD functions.
*/
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
->assertRaw($label, 'Custom menu was added.');
// Edit the menu.
$new_label = $this
->randomMachineName(16);
$menu
->set('label', $new_label);
$menu
->save();
$this
->drupalGet('admin/structure/menu/manage/' . $menu_name);
$this
->assertRaw($new_label, 'Custom menu was edited.');
}
/**
* Creates a custom menu.
*
* @return \Drupal\system\Entity\Menu
* The custom menu that has been created.
*/
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
->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.', [
'@name' => t('Menu name'),
'%max' => MenuStorage::MAX_ID_LENGTH,
'%length' => mb_strlen($menu_name),
]));
// 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
->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.', [
'@name' => t('Menu name'),
'%max' => MenuStorage::MAX_ID_LENGTH,
'%length' => mb_strlen($menu_name),
]));
// Verify that the confirmation message is displayed.
$this
->assertRaw(t('Menu %label has been added.', [
'%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
->clickLink('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);
}
/**
* 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.
*/
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.'));
}
/**
* Tests menu functionality.
*/
public function doMenuTests() {
$menu_name = $this->menu
->id();
// Test the 'Add link' local action.
$this
->drupalGet(Url::fromRoute('entity.menu.edit_form', [
'menu' => $menu_name,
]));
$this
->clickLink(t('Add link'));
$link_title = $this
->randomString();
$this
->drupalPostForm(NULL, [
'link[0][uri]' => '/',
'title[0][value]' => $link_title,
], t('Save'));
$this
->assertUrl(Url::fromRoute('entity.menu.edit_form', [
'menu' => $menu_name,
]));
// Test the 'Edit' operation.
$this
->clickLink(t('Edit'));
$this
->assertFieldByName('title[0][value]', $link_title);
$link_title = $this
->randomString();
$this
->drupalPostForm(NULL, [
'title[0][value]' => $link_title,
], t('Save'));
$this
->assertUrl(Url::fromRoute('entity.menu.edit_form', [
'menu' => $menu_name,
]));
// Test the 'Delete' operation.
$this
->clickLink(t('Delete'));
$this
->assertRaw(t('Are you sure you want to delete the custom menu link %item?', [
'%item' => $link_title,
]));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertUrl(Url::fromRoute('entity.menu.edit_form', [
'menu' => $menu_name,
]));
// Add nodes to use as links for menu links.
$node1 = $this
->drupalCreateNode([
'type' => 'article',
]);
$node2 = $this
->drupalCreateNode([
'type' => 'article',
]);
$node3 = $this
->drupalCreateNode([
'type' => 'article',
]);
$node4 = $this
->drupalCreateNode([
'type' => 'article',
]);
// Create a node with an alias.
$node5 = $this
->drupalCreateNode([
'type' => 'article',
'path' => [
'alias' => '/node5',
],
]);
// Verify add link button.
$this
->drupalGet('admin/structure/menu');
$this
->assertLinkByHref('admin/structure/menu/manage/' . $menu_name . '/add', 0, "The add menu link button URL is correct");
// Verify form defaults.
$this
->doMenuLinkFormDefaultsTest();
// Add menu links.
$item1 = $this
->addMenuLink('', '/node/' . $node1
->id(), $menu_name, TRUE);
$item2 = $this
->addMenuLink($item1
->getPluginId(), '/node/' . $node2
->id(), $menu_name, FALSE);
$item3 = $this
->addMenuLink($item2
->getPluginId(), '/node/' . $node3
->id(), $menu_name);
// Hierarchy
// <$menu_name>
// - item1
// -- item2
// --- item3
$this
->assertMenuLink([
'children' => [
$item2
->getPluginId(),
$item3
->getPluginId(),
],
'parents' => [
$item1
->getPluginId(),
],
// We assert the language code here to make sure that the language
// selection element degrades gracefully without the Language module.
'langcode' => 'en',
], $item1
->getPluginId());
$this
->assertMenuLink([
'children' => [
$item3
->getPluginId(),
],
'parents' => [
$item2
->getPluginId(),
$item1
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item2
->getPluginId());
$this
->assertMenuLink([
'children' => [],
'parents' => [
$item3
->getPluginId(),
$item2
->getPluginId(),
$item1
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item3
->getPluginId());
// Verify menu links.
$this
->verifyMenuLink($item1, $node1);
$this
->verifyMenuLink($item2, $node2, $item1, $node1);
$this
->verifyMenuLink($item3, $node3, $item2, $node2);
// Add more menu links.
$item4 = $this
->addMenuLink('', '/node/' . $node4
->id(), $menu_name);
$item5 = $this
->addMenuLink($item4
->getPluginId(), '/node/' . $node5
->id(), $menu_name);
// Create a menu link pointing to an alias.
$item6 = $this
->addMenuLink($item4
->getPluginId(), '/node5', $menu_name, TRUE, '0');
// Hierarchy
// <$menu_name>
// - item1
// -- item2
// --- item3
// - item4
// -- item5
// -- item6
$this
->assertMenuLink([
'children' => [
$item5
->getPluginId(),
$item6
->getPluginId(),
],
'parents' => [
$item4
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item4
->getPluginId());
$this
->assertMenuLink([
'children' => [],
'parents' => [
$item5
->getPluginId(),
$item4
->getPluginId(),
],
'langcode' => 'en',
], $item5
->getPluginId());
$this
->assertMenuLink([
'children' => [],
'parents' => [
$item6
->getPluginId(),
$item4
->getPluginId(),
],
'route_name' => 'entity.node.canonical',
'route_parameters' => [
'node' => $node5
->id(),
],
'url' => '',
// See above.
'langcode' => 'en',
], $item6
->getPluginId());
// Modify menu links.
$this
->modifyMenuLink($item1);
$this
->modifyMenuLink($item2);
// Toggle menu links.
$this
->toggleMenuLink($item1);
$this
->toggleMenuLink($item2);
// Move link and verify that descendants are updated.
$this
->moveMenuLink($item2, $item5
->getPluginId(), $menu_name);
// Hierarchy
// <$menu_name>
// - item1
// - item4
// -- item5
// --- item2
// ---- item3
// -- item6
$this
->assertMenuLink([
'children' => [],
'parents' => [
$item1
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item1
->getPluginId());
$this
->assertMenuLink([
'children' => [
$item5
->getPluginId(),
$item6
->getPluginId(),
$item2
->getPluginId(),
$item3
->getPluginId(),
],
'parents' => [
$item4
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item4
->getPluginId());
$this
->assertMenuLink([
'children' => [
$item2
->getPluginId(),
$item3
->getPluginId(),
],
'parents' => [
$item5
->getPluginId(),
$item4
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item5
->getPluginId());
$this
->assertMenuLink([
'children' => [
$item3
->getPluginId(),
],
'parents' => [
$item2
->getPluginId(),
$item5
->getPluginId(),
$item4
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item2
->getPluginId());
$this
->assertMenuLink([
'children' => [],
'parents' => [
$item3
->getPluginId(),
$item2
->getPluginId(),
$item5
->getPluginId(),
$item4
->getPluginId(),
],
// See above.
'langcode' => 'en',
], $item3
->getPluginId());
// Add 102 menu links with increasing weights, then make sure the last-added
// item's weight doesn't get changed because of the old hardcoded delta=50.
$items = [];
for ($i = -50; $i <= 51; $i++) {
$items[$i] = $this
->addMenuLink('', '/node/' . $node1
->id(), $menu_name, TRUE, strval($i));
}
$this
->assertMenuLink([
'weight' => '51',
], $items[51]
->getPluginId());
// Disable a link and then re-enable the link via the overview form.
$this
->disableMenuLink($item1);
$edit = [];
$edit['links[menu_plugin_id:' . $item1
->getPluginId() . '][enabled]'] = TRUE;
$this
->drupalPostForm('admin/structure/menu/manage/' . $item1
->getMenuName(), $edit, t('Save'));
// Mark item2, item4 and item5 as expanded.
// This is done in order to show them on the frontpage.
$item2->expanded->value = 1;
$item2
->save();
$item4->expanded->value = 1;
$item4
->save();
$item5->expanded->value = 1;
$item5
->save();
// Verify in the database.
$this
->assertMenuLink([
'enabled' => 1,
], $item1
->getPluginId());
// Add an external link.
$item7 = $this
->addMenuLink('', 'https://www.drupal.org', $menu_name);
$this
->assertMenuLink([
'url' => 'https://www.drupal.org',
], $item7
->getPluginId());
// Add <front> menu item.
$item8 = $this
->addMenuLink('', '/', $menu_name);
$this
->assertMenuLink([
'route_name' => '<front>',
], $item8
->getPluginId());
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
// Make sure we get routed correctly.
$this
->clickLink($item8
->getTitle());
$this
->assertSession()
->statusCodeEquals(200);
// Check invalid menu link parents.
$this
->checkInvalidParentMenuLinks();
// Save menu links for later tests.
$this->items[] = $item1;
$this->items[] = $item2;
}
/**
* Ensures that the proper default values are set when adding a menu link
*/
protected function doMenuLinkFormDefaultsTest() {
$this
->drupalGet("admin/structure/menu/manage/tools/add");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertFieldByName('title[0][value]', '');
$this
->assertFieldByName('link[0][uri]', '');
$this
->assertNoFieldChecked('edit-expanded-value');
$this
->assertFieldChecked('edit-enabled-value');
$this
->assertFieldByName('description[0][value]', '');
$this
->assertFieldByName('weight[0][value]', 0);
}
/**
* Adds and removes a menu link with a query string and fragment.
*/
public function testMenuQueryAndFragment() {
$this
->drupalLogin($this->adminUser);
// Make a path with query and fragment on.
$path = '/test-page?arg1=value1&arg2=value2';
$item = $this
->addMenuLink('', $path);
$this
->drupalGet('admin/structure/menu/item/' . $item
->id() . '/edit');
$this
->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
// Now change the path to something without query and fragment.
$path = '/test-page';
$this
->drupalPostForm('admin/structure/menu/item/' . $item
->id() . '/edit', [
'link[0][uri]' => $path,
], t('Save'));
$this
->drupalGet('admin/structure/menu/item/' . $item
->id() . '/edit');
$this
->assertFieldByName('link[0][uri]', $path, 'Path no longer has query or fragment.');
// Use <front>#fragment and ensure that saving it does not lose its content.
$path = '<front>?arg1=value#fragment';
$item = $this
->addMenuLink('', $path);
$this
->drupalGet('admin/structure/menu/item/' . $item
->id() . '/edit');
$this
->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
$this
->drupalPostForm('admin/structure/menu/item/' . $item
->id() . '/edit', [], t('Save'));
$this
->drupalGet('admin/structure/menu/item/' . $item
->id() . '/edit');
$this
->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
}
/**
* Tests renaming the built-in menu.
*/
public function testSystemMenuRename() {
$this
->drupalLogin($this->adminUser);
$edit = [
'label' => $this
->randomMachineName(16),
];
$this
->drupalPostForm('admin/structure/menu/manage/main', $edit, t('Save'));
// Make sure menu shows up with new name in block addition.
$default_theme = $this
->config('system.theme')
->get('default');
$this
->drupalget('admin/structure/block/list/' . $default_theme);
$this
->clickLink('Place block');
$this
->assertText($edit['label']);
}
/**
* Tests that menu items pointing to unpublished nodes are editable.
*/
public function testUnpublishedNodeMenuItem() {
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'administer blocks',
'administer menu',
'create article content',
'bypass node access',
]));
// Create an unpublished node.
$node = $this
->drupalCreateNode([
'type' => 'article',
'status' => NodeInterface::NOT_PUBLISHED,
]);
$item = $this
->addMenuLink('', '/node/' . $node
->id());
$this
->modifyMenuLink($item);
// Test that a user with 'administer menu' but without 'bypass node access'
// cannot see the menu item.
$this
->drupalLogout();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/menu/manage/' . $item
->getMenuName());
$this
->assertNoText($item
->getTitle(), "Menu link pointing to unpublished node is only visible to users with 'bypass node access' permission");
// The cache contexts associated with the (in)accessible menu links are
// bubbled. See DefaultMenuLinkTreeManipulators::menuLinkCheckAccess().
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
}
/**
* Adds a menu link using the UI.
*
* @param string $parent
* Optional parent menu link id.
* @param string $path
* The path to enter on the form. Defaults to the front page.
* @param string $menu_name
* Menu name. Defaults to 'tools'.
* @param bool $expanded
* Whether or not this menu link is expanded. Setting this to TRUE should
* test whether it works when we do the authenticatedUser tests. Defaults
* to FALSE.
* @param string $weight
* Menu weight. Defaults to 0.
*
* @return \Drupal\menu_link_content\Entity\MenuLinkContent
* A menu link entity.
*/
public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') {
// View add menu link page.
$this
->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
$this
->assertSession()
->statusCodeEquals(200);
$title = '!link_' . $this
->randomMachineName(16);
$edit = [
'link[0][uri]' => $path,
'title[0][value]' => $title,
'description[0][value]' => '',
'enabled[value]' => 1,
'expanded[value]' => $expanded,
'menu_parent' => $menu_name . ':' . $parent,
'weight[0][value]' => $weight,
];
// Add menu link.
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('The menu link has been saved.');
$menu_links = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->loadByProperties([
'title' => $title,
]);
$menu_link = reset($menu_links);
$this
->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this
->assertMenuLink([
'menu_name' => $menu_name,
'children' => [],
'parent' => $parent,
], $menu_link
->getPluginId());
return $menu_link;
}
/**
* Attempts to add menu link with invalid path or no access permission.
*/
public function addInvalidMenuLink() {
foreach ([
'access' => '/admin/people/permissions',
] as $type => $link_path) {
$edit = [
'link[0][uri]' => $link_path,
'title[0][value]' => 'title',
];
$this
->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save'));
$this
->assertRaw(t("The path '@link_path' is inaccessible.", [
'@link_path' => $link_path,
]), 'Menu link was not created');
}
}
/**
* Tests that parent options are limited by depth when adding menu links.
*/
public function checkInvalidParentMenuLinks() {
$last_link = NULL;
$created_links = [];
// Get the max depth of the tree.
$menu_link_tree = \Drupal::service('menu.link_tree');
$max_depth = $menu_link_tree
->maxDepth();
// Create a maximum number of menu links, each a child of the previous.
for ($i = 0; $i <= $max_depth - 1; $i++) {
$parent = $last_link ? 'tools:' . $last_link
->getPluginId() : 'tools:';
$title = 'title' . $i;
$edit = [
'link[0][uri]' => '/',
'title[0][value]' => $title,
'menu_parent' => $parent,
'description[0][value]' => '',
'enabled[value]' => 1,
'expanded[value]' => FALSE,
'weight[0][value]' => '0',
];
$this
->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save'));
$menu_links = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->loadByProperties([
'title' => $title,
]);
$last_link = reset($menu_links);
$created_links[] = 'tools:' . $last_link
->getPluginId();
}
// The last link cannot be a parent in the new menu link form.
$this
->drupalGet('admin/structure/menu/manage/admin/add');
$value = 'tools:' . $last_link
->getPluginId();
$this
->assertNoOption('edit-menu-parent', $value, 'The invalid option is not there.');
// All but the last link can be parents in the new menu link form.
array_pop($created_links);
foreach ($created_links as $key => $link) {
$this
->assertOption('edit-menu-parent', $link, 'The valid option number ' . ($key + 1) . ' is there.');
}
}
/**
* Verifies a menu link using the UI.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
* @param object $item_node
* Menu link content node.
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $parent
* Parent menu link.
* @param object $parent_node
* Parent menu link content node.
*/
public function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) {
// View home page.
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
// Verify parent menu link.
if (isset($parent)) {
// Verify menu link.
$title = $parent
->getTitle();
$this
->assertSession()
->linkExists($title, 0, 'Parent menu link was displayed');
// Verify menu link link.
$this
->clickLink($title);
$title = $parent_node
->label();
$this
->assertTitle("{$title} | Drupal");
}
// Verify menu link.
$title = $item
->getTitle();
$this
->assertSession()
->linkExists($title, 0, 'Menu link was displayed');
// Verify menu link link.
$this
->clickLink($title);
$title = $item_node
->label();
$this
->assertTitle("{$title} | Drupal");
}
/**
* Changes the parent of a menu link using the UI.
*
* @param \Drupal\menu_link_content\MenuLinkContentInterface $item
* The menu link item to move.
* @param int $parent
* The id of the new parent.
* @param string $menu_name
* The menu the menu link will be moved to.
*/
public function moveMenuLink(MenuLinkContent $item, $parent, $menu_name) {
$mlid = $item
->id();
$edit = [
'menu_parent' => $menu_name . ':' . $parent,
];
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
$this
->assertSession()
->statusCodeEquals(200);
}
/**
* Modifies a menu link using the UI.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link entity.
*/
public function modifyMenuLink(MenuLinkContent $item) {
$item->title->value = $this
->randomMachineName(16);
$mlid = $item
->id();
$title = $item
->getTitle();
// Edit menu link.
$edit = [];
$edit['title[0][value]'] = $title;
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('The menu link has been saved.');
// Verify menu link.
$this
->drupalGet('admin/structure/menu/manage/' . $item
->getMenuName());
$this
->assertText($title, 'Menu link was edited');
}
/**
* Resets a standard menu link using the UI.
*
* @param \Drupal\Core\Menu\MenuLinkInterface $menu_link
* The Menu link.
* @param int $old_weight
* Original title for menu link.
*/
public function resetMenuLink(MenuLinkInterface $menu_link, $old_weight) {
// Reset menu link.
$this
->drupalPostForm("admin/structure/menu/link/{$menu_link->getPluginId()}/reset", [], t('Reset'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertRaw(t('The menu link was reset to its default settings.'), 'Menu link was reset');
// Verify menu link.
$instance = \Drupal::service('plugin.manager.menu.link')
->createInstance($menu_link
->getPluginId());
$this
->assertEqual($old_weight, $instance
->getWeight(), 'Resets to the old weight.');
}
/**
* Deletes a menu link using the UI.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
*/
public function deleteMenuLink(MenuLinkContent $item) {
$mlid = $item
->id();
$title = $item
->getTitle();
// Delete menu link.
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/delete", [], t('Delete'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertRaw(t('The menu link %title has been deleted.', [
'%title' => $title,
]), 'Menu link was deleted');
// Verify deletion.
$this
->drupalGet('');
$this
->assertNoText($title, 'Menu link was deleted');
}
/**
* Alternately disables and enables a menu link.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
*/
public function toggleMenuLink(MenuLinkContent $item) {
$this
->disableMenuLink($item);
// Verify menu link is absent.
$this
->drupalGet('');
$this
->assertNoText($item
->getTitle(), 'Menu link was not displayed');
$this
->enableMenuLink($item);
// Verify menu link is displayed.
$this
->drupalGet('');
$this
->assertText($item
->getTitle(), 'Menu link was displayed');
}
/**
* Disables a menu link.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
*/
public function disableMenuLink(MenuLinkContent $item) {
$mlid = $item
->id();
$edit['enabled[value]'] = FALSE;
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
// Unlike most other modules, there is no confirmation message displayed.
// Verify in the database.
$this
->assertMenuLink([
'enabled' => 0,
], $item
->getPluginId());
}
/**
* Enables a menu link.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
*/
public function enableMenuLink(MenuLinkContent $item) {
$mlid = $item
->id();
$edit['enabled[value]'] = TRUE;
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
// Verify in the database.
$this
->assertMenuLink([
'enabled' => 1,
], $item
->getPluginId());
}
/**
* Tests if admin users, other than UID1, can access parents AJAX callback.
*/
public function testMenuParentsJsAccess() {
$this
->drupalLogin($this
->drupalCreateUser([
'administer menu',
]));
// Just check access to the callback overall, the POST data is irrelevant.
$this
->drupalGet('admin/structure/menu/parents', [
'query' => [
MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
],
], [
'X-Requested-With: XMLHttpRequest',
]);
$this
->assertSession()
->statusCodeEquals(200);
// Log in as authenticated user.
$this
->drupalLogin($this
->drupalCreateUser());
// Check that a simple user is not able to access the menu.
$this
->drupalGet('admin/structure/menu/parents', [
'query' => [
MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
],
], [
'X-Requested-With: XMLHttpRequest',
]);
$this
->assertSession()
->statusCodeEquals(403);
}
/**
* Test the "expand all items" feature.
*/
public function testExpandAllItems() {
$this
->drupalLogin($this->adminUser);
$menu = $this
->addCustomMenu();
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
// Create three menu items, none of which are expanded.
$parent = $this
->addMenuLink('', $node
->toUrl()
->toString(), $menu
->id(), FALSE);
$child_1 = $this
->addMenuLink($parent
->getPluginId(), $node
->toUrl()
->toString(), $menu
->id(), FALSE);
$child_2 = $this
->addMenuLink($parent
->getPluginId(), $node
->toUrl()
->toString(), $menu
->id(), FALSE);
// The menu will not automatically show all levels of depth.
$this
->drupalGet('<front>');
$this
->assertSession()
->linkExists($parent
->getTitle());
$this
->assertSession()
->linkNotExists($child_1
->getTitle());
$this
->assertSession()
->linkNotExists($child_2
->getTitle());
// Update the menu block to show all levels of depth as expanded.
$block_id = $this->blockPlacements[$menu
->id()];
$this
->drupalGet('admin/structure/block/manage/' . $block_id);
$this
->assertSession()
->checkboxNotChecked('settings[expand_all_items]');
$this
->drupalPostForm(NULL, [
'settings[depth]' => 2,
'settings[level]' => 1,
'settings[expand_all_items]' => 1,
], t('Save block'));
// Ensure the setting is persisted.
$this
->drupalGet('admin/structure/block/manage/' . $block_id);
$this
->assertSession()
->checkboxChecked('settings[expand_all_items]');
// Ensure all three links are shown, including the children which would
// usually be hidden without the "expand all items" setting.
$this
->drupalGet('<front>');
$this
->assertSession()
->linkExists($parent
->getTitle());
$this
->assertSession()
->linkExists($child_1
->getTitle());
$this
->assertSession()
->linkExists($child_2
->getTitle());
}
/**
* Returns standard menu link.
*
* @return \Drupal\Core\Menu\MenuLinkInterface
* A menu link plugin.
*/
private function getStandardMenuLink() {
// Retrieve menu link id of the Log out menu link, which will always be on
// the front page.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$instance = $menu_link_manager
->getInstance([
'id' => 'user.logout',
]);
$this
->assertTrue((bool) $instance, 'Standard menu link was loaded');
return $instance;
}
/**
* Verifies the logged in user has the desired access to various menu pages.
*
* @param int $response
* (optional) The expected HTTP response code. Defaults to 200.
*/
private function verifyAccess($response = 200) {
// View menu help page.
$this
->drupalGet('admin/help/menu');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertText(t('Menu'), 'Menu help was displayed');
}
// View menu build overview page.
$this
->drupalGet('admin/structure/menu');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertText(t('Menus'), 'Menu build overview page was displayed');
}
// View tools menu customization page.
$this
->drupalGet('admin/structure/menu/manage/' . $this->menu
->id());
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertText(t('Tools'), 'Tools menu page was displayed');
}
// View menu edit page for a static link.
$item = $this
->getStandardMenuLink();
$this
->drupalGet('admin/structure/menu/link/' . $item
->getPluginId() . '/edit');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertText(t('Edit menu item'), 'Menu edit page was displayed');
}
// View add menu page.
$this
->drupalGet('admin/structure/menu/add');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertText(t('Menus'), 'Add menu page was displayed');
}
}
/**
* Tests menu block settings.
*/
protected function doTestMenuBlock() {
$menu_id = $this->menu
->id();
$block_id = $this->blockPlacements[$menu_id];
$this
->drupalGet('admin/structure/block/manage/' . $block_id);
$this
->drupalPostForm(NULL, [
'settings[depth]' => 3,
'settings[level]' => 2,
], t('Save block'));
$block = Block::load($block_id);
$settings = $block
->getPlugin()
->getConfiguration();
$this
->assertEqual($settings['depth'], 3);
$this
->assertEqual($settings['level'], 2);
// Reset settings.
$block
->getPlugin()
->setConfigurationValue('depth', 0);
$block
->getPlugin()
->setConfigurationValue('level', 1);
$block
->save();
}
/**
* Test that menu links with pending revisions can not be re-parented.
*/
public function testMenuUiWithPendingRevisions() {
$this
->drupalLogin($this->adminUser);
$assert_session = $this
->assertSession();
// Add four menu links in two separate menus.
$menu_1 = $this
->addCustomMenu();
$root_1 = $this
->addMenuLink('', '/', $menu_1
->id());
$this
->addMenuLink($root_1
->getPluginId(), '/', $menu_1
->id());
$menu_2 = $this
->addCustomMenu();
$root_2 = $this
->addMenuLink('', '/', $menu_2
->id());
$child_2 = $this
->addMenuLink($root_2
->getPluginId(), '/', $menu_2
->id());
$this
->drupalGet('admin/structure/menu/manage/' . $menu_2
->id());
$assert_session
->pageTextNotContains($menu_2
->label() . ' contains 1 menu link with pending revisions. Manipulation of a menu tree having links with pending revisions is not supported, but you can re-enable manipulation by getting each menu link to a published state.');
$this
->drupalGet('admin/structure/menu/manage/' . $menu_1
->id());
$assert_session
->pageTextNotContains($menu_1
->label() . ' contains 1 menu link with pending revisions. Manipulation of a menu tree having links with pending revisions is not supported, but you can re-enable manipulation by getting each menu link to a published state.');
// Create a pending revision for one of the menu links and check that it can
// no longer be re-parented in the UI. We can not create pending revisions
// through the UI yet so we have to use API calls.
\Drupal::entityTypeManager()
->getStorage('menu_link_content')
->createRevision($child_2, FALSE)
->save();
$this
->drupalGet('admin/structure/menu/manage/' . $menu_2
->id());
$assert_session
->pageTextContains($menu_2
->label() . ' contains 1 menu link with pending revisions. Manipulation of a menu tree having links with pending revisions is not supported, but you can re-enable manipulation by getting each menu link to a published state.');
// Check that the 'Enabled' checkbox is hidden for a pending revision.
$this
->assertNotEmpty($this
->cssSelect('input[name="links[menu_plugin_id:' . $root_2
->getPluginId() . '][enabled]"]'), 'The publishing status of a default revision can be changed.');
$this
->assertEmpty($this
->cssSelect('input[name="links[menu_plugin_id:' . $child_2
->getPluginId() . '][enabled]"]'), 'The publishing status of a pending revision can not be changed.');
$this
->drupalGet('admin/structure/menu/manage/' . $menu_1
->id());
$assert_session
->pageTextNotContains($menu_1
->label() . ' contains 1 menu link with pending revisions. Manipulation of a menu tree having links with pending revisions is not supported, but you can re-enable manipulation by getting each menu link to a published state.');
// Check that the menu overview form can be saved without errors when there
// are pending revisions.
$this
->drupalPostForm('admin/structure/menu/manage/' . $menu_2
->id(), [], 'Save');
$this
->assertSession()
->elementNotExists('xpath', '//div[contains(@class, "messages--error")]');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was present in the last response. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is not present. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is present. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertLegacyTrait:: |
protected | function | Checks that current response header equals value. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was absent in the last response. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text is not found escaped on the loaded page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does NOT exist with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option does NOT exist in the current page. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is not found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS not found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Asserts the page responds with the specified response code. | 1 |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertLegacyTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Passes if the internal browser's URL matches the given path. | |
AssertLegacyTrait:: |
protected | function | Builds an XPath query. | |
AssertLegacyTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertLegacyTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertLegacyTrait:: |
protected | function | Gets the current raw content. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
BlockCreationTrait:: |
protected | function | Creates a block instance based on default settings. Aliased as: drupalPlaceBlock | |
BrowserHtmlDebugTrait:: |
protected | property | The Base URI to use for links to the output files. | |
BrowserHtmlDebugTrait:: |
protected | property | Class name for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Counter for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Counter storage for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Directory name for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | HTML output output enabled. | |
BrowserHtmlDebugTrait:: |
protected | property | The file name to write the list of URLs to. | |
BrowserHtmlDebugTrait:: |
protected | property | HTML output test ID. | |
BrowserHtmlDebugTrait:: |
protected | function | Formats HTTP headers as string for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | function | Returns headers in HTML output format. | 1 |
BrowserHtmlDebugTrait:: |
protected | function | Logs a HTML output message in a text file. | |
BrowserHtmlDebugTrait:: |
protected | function | Creates the directory to store browser output. | |
BrowserTestBase:: |
protected | property | The base URL. | |
BrowserTestBase:: |
protected | property | The config importer that can be used in a test. | |
BrowserTestBase:: |
protected | property | An array of custom translations suitable for drupal_rewrite_settings(). | |
BrowserTestBase:: |
protected | property | The database prefix of this test run. | |
BrowserTestBase:: |
protected | property | Mink session manager. | |
BrowserTestBase:: |
protected | property | ||
BrowserTestBase:: |
protected | property | 1 | |
BrowserTestBase:: |
protected | property | The original container. | |
BrowserTestBase:: |
protected | property | The original array of shutdown function callbacks. | |
BrowserTestBase:: |
protected | property | ||
BrowserTestBase:: |
protected | property | The profile to install as a basis for testing. | 39 |
BrowserTestBase:: |
protected | property | The app root. | |
BrowserTestBase:: |
protected | property | Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests. | |
BrowserTestBase:: |
protected | property | Time limit in seconds for the test. | |
BrowserTestBase:: |
protected | property | The translation file directory for the test environment. | |
BrowserTestBase:: |
protected | function | Clean up the Simpletest environment. | |
BrowserTestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
BrowserTestBase:: |
protected | function | Translates a CSS expression to its XPath equivalent. | |
BrowserTestBase:: |
protected | function | Gets the value of an HTTP response header. | |
BrowserTestBase:: |
protected | function | Returns all response headers. | |
BrowserTestBase:: |
public static | function | Ensures test files are deletable. | |
BrowserTestBase:: |
protected | function | Gets an instance of the default Mink driver. | |
BrowserTestBase:: |
protected | function | Gets the JavaScript drupalSettings variable for the currently-loaded page. | 1 |
BrowserTestBase:: |
protected | function | Obtain the HTTP client for the system under test. | |
BrowserTestBase:: |
protected | function | Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. | 1 |
BrowserTestBase:: |
protected | function | Helper function to get the options of select field. | |
BrowserTestBase:: |
protected | function |
Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait:: |
|
BrowserTestBase:: |
public | function | Returns Mink session. | |
BrowserTestBase:: |
protected | function | Get session cookies from current session. | |
BrowserTestBase:: |
protected | function |
Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait:: |
|
BrowserTestBase:: |
protected | function | Visits the front page when initializing Mink. | 3 |
BrowserTestBase:: |
protected | function | Initializes Mink sessions. | 1 |
BrowserTestBase:: |
public | function | Installs Drupal into the Simpletest site. | 1 |
BrowserTestBase:: |
protected | function | Registers additional Mink sessions. | |
BrowserTestBase:: |
protected | function | 3 | |
BrowserTestBase:: |
protected | function | Transforms a nested array into a flat array suitable for drupalPostForm(). | |
BrowserTestBase:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
BrowserTestBase:: |
public | function | 1 | |
BrowserTestBase:: |
public | function | Prevents serializing any properties. | |
ConfigTestTrait:: |
protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait:: |
protected | function | Copies configuration objects from source storage to target storage. | |
ContentTypeCreationTrait:: |
protected | function | Creates a custom content type based on default settings. Aliased as: drupalCreateContentType | 1 |
FunctionalTestSetupTrait:: |
protected | property | The flag to set 'apcu_ensure_unique_prefix' setting. | 1 |
FunctionalTestSetupTrait:: |
protected | property | The class loader to use for installation and initialization of setup. | |
FunctionalTestSetupTrait:: |
protected | property | The config directories used in this test. | |
FunctionalTestSetupTrait:: |
protected | property | The "#1" admin user. | |
FunctionalTestSetupTrait:: |
protected | function | Execute the non-interactive installer. | 1 |
FunctionalTestSetupTrait:: |
protected | function | Returns all supported database driver installer objects. | |
FunctionalTestSetupTrait:: |
protected | function | Initialize various configurations post-installation. | 2 |
FunctionalTestSetupTrait:: |
protected | function | Initializes the kernel after installation. | |
FunctionalTestSetupTrait:: |
protected | function | Initialize settings created during install. | |
FunctionalTestSetupTrait:: |
protected | function | Initializes user 1 for the site to be installed. | |
FunctionalTestSetupTrait:: |
protected | function | Installs the default theme defined by `static::$defaultTheme` when needed. | |
FunctionalTestSetupTrait:: |
protected | function | Install modules defined by `static::$modules`. | 1 |
FunctionalTestSetupTrait:: |
protected | function | Returns the parameters that will be used when Simpletest installs Drupal. | 9 |
FunctionalTestSetupTrait:: |
protected | function | Prepares the current environment for running the test. | 23 |
FunctionalTestSetupTrait:: |
protected | function | Creates a mock request and sets it on the generator. | |
FunctionalTestSetupTrait:: |
protected | function | Prepares site settings and services before installation. | 2 |
FunctionalTestSetupTrait:: |
protected | function | Resets and rebuilds the environment after setup. | |
FunctionalTestSetupTrait:: |
protected | function | Rebuilds \Drupal::getContainer(). | |
FunctionalTestSetupTrait:: |
protected | function | Resets all data structures after having enabled new modules. | |
FunctionalTestSetupTrait:: |
protected | function | Changes parameters in the services.yml file. | |
FunctionalTestSetupTrait:: |
protected | function | Sets up the base URL based upon the environment variable. | |
FunctionalTestSetupTrait:: |
protected | function | Rewrites the settings.php file of the test site. | |
MenuUiTest:: |
protected | property | A user with administration rights. | |
MenuUiTest:: |
protected | property | An authenticated user. | |
MenuUiTest:: |
protected | property | Array of placed menu blocks keyed by block ID. | |
MenuUiTest:: |
protected | property |
The theme to install as the default for testing. Overrides BrowserTestBase:: |
|
MenuUiTest:: |
protected | property | An array of test menu links. | |
MenuUiTest:: |
protected | property | A test menu. | |
MenuUiTest:: |
protected static | property |
Modules to enable. Overrides BrowserTestBase:: |
|
MenuUiTest:: |
public | function | Creates a custom menu. | |
MenuUiTest:: |
public | function | Adds a custom menu using CRUD functions. | |
MenuUiTest:: |
public | function | Attempts to add menu link with invalid path or no access permission. | |
MenuUiTest:: |
public | function | Adds a menu link using the UI. | |
MenuUiTest:: |
public | function | Tests that parent options are limited by depth when adding menu links. | |
MenuUiTest:: |
public | function | Deletes the locally stored custom menu. | |
MenuUiTest:: |
public | function | Deletes a menu link using the UI. | |
MenuUiTest:: |
public | function | Disables a menu link. | |
MenuUiTest:: |
protected | function | Ensures that the proper default values are set when adding a menu link | |
MenuUiTest:: |
public | function | Tests menu functionality. | |
MenuUiTest:: |
protected | function | Tests menu block settings. | |
MenuUiTest:: |
public | function | Enables a menu link. | |
MenuUiTest:: |
private | function | Returns standard menu link. | |
MenuUiTest:: |
public | function | Modifies a menu link using the UI. | |
MenuUiTest:: |
public | function | Changes the parent of a menu link using the UI. | |
MenuUiTest:: |
public | function | Resets a standard menu link using the UI. | |
MenuUiTest:: |
protected | function |
Overrides BrowserTestBase:: |
|
MenuUiTest:: |
public | function | Test the "expand all items" feature. | |
MenuUiTest:: |
public | function | Tests menu functionality using the admin and user interfaces. | |
MenuUiTest:: |
public | function | Tests if admin users, other than UID1, can access parents AJAX callback. | |
MenuUiTest:: |
public | function | Adds and removes a menu link with a query string and fragment. | |
MenuUiTest:: |
public | function | Test that menu links with pending revisions can not be re-parented. | |
MenuUiTest:: |
public | function | Tests renaming the built-in menu. | |
MenuUiTest:: |
public | function | Tests that menu items pointing to unpublished nodes are editable. | |
MenuUiTest:: |
public | function | Alternately disables and enables a menu link. | |
MenuUiTest:: |
private | function | Verifies the logged in user has the desired access to various menu pages. | |
MenuUiTest:: |
public | function | Verifies a menu link using the UI. | |
MenuUiTrait:: |
protected | function | Asserts that a menu fetched from the database matches an expected one. | |
NodeCreationTrait:: |
protected | function | Creates a node based on default settings. Aliased as: drupalCreateNode | |
NodeCreationTrait:: |
public | function | Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
RefreshVariablesTrait:: |
protected | function | Refreshes in-memory configuration and state information. | 3 |
SessionTestTrait:: |
protected | property | The name of the session cookie. | |
SessionTestTrait:: |
protected | function | Generates a session cookie name. | |
SessionTestTrait:: |
protected | function | Returns the session name in use on the child site. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. | |
TestRequirementsTrait:: |
private | function | Checks missing module requirements. | |
TestRequirementsTrait:: |
protected | function | Check module requirements for the Drupal use case. | 1 |
TestRequirementsTrait:: |
protected static | function | Returns the Drupal root directory. | |
TestSetupTrait:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
TestSetupTrait:: |
protected | property | The dependency injection container used in the test. | |
TestSetupTrait:: |
protected | property | The DrupalKernel instance used in the test. | |
TestSetupTrait:: |
protected | property | The site directory of the original parent site. | |
TestSetupTrait:: |
protected | property | The private file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The public file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The site directory of this test run. | |
TestSetupTrait:: |
protected | property | Set to TRUE to strict check all configuration saved. | 2 |
TestSetupTrait:: |
protected | property | The temporary file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The test run ID. | |
TestSetupTrait:: |
protected | function | Changes the database connection to the prefixed one. | |
TestSetupTrait:: |
protected | function | Gets the config schema exclusions for this test. | |
TestSetupTrait:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestSetupTrait:: |
protected | function | Generates a database prefix for running tests. | 2 |
UiHelperTrait:: |
protected | property | The current user logged in using the Mink controlled browser. | |
UiHelperTrait:: |
protected | property | The number of meta refresh redirects to follow, or NULL if unlimited. | |
UiHelperTrait:: |
protected | property | The number of meta refresh redirects followed during ::drupalGet(). | |
UiHelperTrait:: |
public | function | Returns WebAssert object. | 1 |
UiHelperTrait:: |
protected | function | Builds an a absolute URL from a system path or a URL object. | |
UiHelperTrait:: |
protected | function | Checks for meta refresh tag and if found call drupalGet() recursively. | |
UiHelperTrait:: |
protected | function | Clicks the element with the given CSS selector. | |
UiHelperTrait:: |
protected | function | Follows a link by complete name. | |
UiHelperTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
UiHelperTrait:: |
protected | function | Retrieves a Drupal path or an absolute path. | 3 |
UiHelperTrait:: |
protected | function | Logs in a user using the Mink controlled browser. | |
UiHelperTrait:: |
protected | function | Logs a user out of the Mink controlled browser and confirms. | |
UiHelperTrait:: |
protected | function | Executes a form submission. | |
UiHelperTrait:: |
protected | function | Returns whether a given user account is logged in. | |
UiHelperTrait:: |
protected | function | Takes a path and returns an absolute path. | |
UiHelperTrait:: |
protected | function | Retrieves the plain-text content from the current page. | |
UiHelperTrait:: |
protected | function | Get the current URL from the browser. | |
UiHelperTrait:: |
protected | function | Prepare for a request to testing site. | 1 |
UiHelperTrait:: |
protected | function | Fills and submits a form. | |
UserCreationTrait:: |
protected | function | Checks whether a given list of permission names is valid. | |
UserCreationTrait:: |
protected | function | Creates an administrative role. | |
UserCreationTrait:: |
protected | function | Creates a role with specified permissions. Aliased as: drupalCreateRole | |
UserCreationTrait:: |
protected | function | Create a user with a given set of permissions. Aliased as: drupalCreateUser | |
UserCreationTrait:: |
protected | function | Grant permissions to a user role. | |
UserCreationTrait:: |
protected | function | Switch the current logged in user. | |
UserCreationTrait:: |
protected | function | Creates a random user account and sets it as current user. | |
XdebugRequestTrait:: |
protected | function | Adds xdebug cookies, from request setup. |