class MenuTest in Zircon Profile 8
Same name in this branch
- 8 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest
- 8 core/modules/views/src/Tests/Wizard/MenuTest.php \Drupal\views\Tests\Wizard\MenuTest
- 8 core/modules/system/tests/src/Unit/Plugin/migrate/source/MenuTest.php \Drupal\Tests\system\Unit\Plugin\migrate\source\MenuTest
Same name and namespace in other branches
- 8.0 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest
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\simpletest\TestBase uses AssertHelperTrait, RandomGeneratorTrait, SessionTestTrait
- class \Drupal\simpletest\WebTestBase uses AssertContentTrait, UserCreationTrait
- class \Drupal\menu_ui\Tests\MenuWebTestBase
- class \Drupal\menu_ui\Tests\MenuTest
- class \Drupal\menu_ui\Tests\MenuWebTestBase
- class \Drupal\simpletest\WebTestBase uses AssertContentTrait, UserCreationTrait
Expanded class hierarchy of MenuTest
File
- core/
modules/ menu_ui/ src/ Tests/ MenuTest.php, line 25 - Contains \Drupal\menu_ui\Tests\MenuTest.
Namespace
Drupal\menu_ui\TestsView source
class MenuTest extends MenuWebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'node',
'block',
'contextual',
'help',
'path',
'test_page_test',
);
/**
* 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(array(
'type' => 'article',
'name' => 'Article',
));
// Create users.
$this->adminUser = $this
->drupalCreateUser(array(
'access administration pages',
'administer blocks',
'administer menu',
'create article content',
));
$this->authenticatedUser = $this
->drupalCreateUser(array());
}
/**
* Tests menu functionality using the admin and user interfaces.
*/
function testMenu() {
// Login the user.
$this
->drupalLogin($this->adminUser);
$this->items = array();
$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.
// Login 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);
}
// Login 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
->assertResponse(200);
$this
->drupalGet('admin/structure/menu/link/' . $this->items[0]
->getPluginId() . '/reset');
$this
->assertResponse(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 = array();
$edit['weight'] = 10;
$id = $instance
->getPluginId();
$this
->drupalPostForm("admin/structure/menu/link/{$id}/edit", $edit, t('Save'));
$this
->assertResponse(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.
*/
function addCustomMenuCRUD() {
// Add a new custom menu.
$menu_name = substr(hash('sha256', $this
->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
$label = $this
->randomMachineName(16);
$menu = entity_create('menu', array(
'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.
*/
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);
}
/**
* 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.
*/
function deleteCustomMenu() {
$menu_name = $this->menu
->id();
$label = $this->menu
->label();
// Delete custom menu.
$this
->drupalPostForm("admin/structure/menu/manage/{$menu_name}/delete", array(), t('Delete'));
$this
->assertResponse(200);
$this
->assertRaw(t('The menu %title has been deleted.', array(
'%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 = entity_load_multiple_by_properties('menu_link_content', array(
'menu_name' => $menu_name,
));
$this
->assertFalse($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.
*/
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, array(
'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, array(
'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?', array(
'%item' => $link_title,
)));
$this
->drupalPostForm(NULL, array(), 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(array(
'type' => 'article',
));
$node2 = $this
->drupalCreateNode(array(
'type' => 'article',
));
$node3 = $this
->drupalCreateNode(array(
'type' => 'article',
));
$node4 = $this
->drupalCreateNode(array(
'type' => 'article',
));
// Create a node with an alias.
$node5 = $this
->drupalCreateNode(array(
'type' => 'article',
'path' => array(
'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($item1
->getPluginId(), array(
'children' => array(
$item2
->getPluginId(),
$item3
->getPluginId(),
),
'parents' => array(
$item1
->getPluginId(),
),
// We assert the language code here to make sure that the language
// selection element degrades gracefully without the Language module.
'langcode' => 'en',
));
$this
->assertMenuLink($item2
->getPluginId(), array(
'children' => array(
$item3
->getPluginId(),
),
'parents' => array(
$item2
->getPluginId(),
$item1
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item3
->getPluginId(), array(
'children' => array(),
'parents' => array(
$item3
->getPluginId(),
$item2
->getPluginId(),
$item1
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
// 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($item4
->getPluginId(), array(
'children' => array(
$item5
->getPluginId(),
$item6
->getPluginId(),
),
'parents' => array(
$item4
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item5
->getPluginId(), array(
'children' => array(),
'parents' => array(
$item5
->getPluginId(),
$item4
->getPluginId(),
),
'langcode' => 'en',
));
$this
->assertMenuLink($item6
->getPluginId(), array(
'children' => array(),
'parents' => array(
$item6
->getPluginId(),
$item4
->getPluginId(),
),
'route_name' => 'entity.node.canonical',
'route_parameters' => array(
'node' => $node5
->id(),
),
'url' => '',
// See above.
'langcode' => 'en',
));
// 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($item1
->getPluginId(), array(
'children' => array(),
'parents' => array(
$item1
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item4
->getPluginId(), array(
'children' => array(
$item5
->getPluginId(),
$item6
->getPluginId(),
$item2
->getPluginId(),
$item3
->getPluginId(),
),
'parents' => array(
$item4
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item5
->getPluginId(), array(
'children' => array(
$item2
->getPluginId(),
$item3
->getPluginId(),
),
'parents' => array(
$item5
->getPluginId(),
$item4
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item2
->getPluginId(), array(
'children' => array(
$item3
->getPluginId(),
),
'parents' => array(
$item2
->getPluginId(),
$item5
->getPluginId(),
$item4
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
$this
->assertMenuLink($item3
->getPluginId(), array(
'children' => array(),
'parents' => array(
$item3
->getPluginId(),
$item2
->getPluginId(),
$item5
->getPluginId(),
$item4
->getPluginId(),
),
// See above.
'langcode' => 'en',
));
// 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 = array();
for ($i = -50; $i <= 51; $i++) {
$items[$i] = $this
->addMenuLink('', '/node/' . $node1
->id(), $menu_name, TRUE, strval($i));
}
$this
->assertMenuLink($items[51]
->getPluginId(), array(
'weight' => '51',
));
// Disable a link and then re-enable the link via the overview form.
$this
->disableMenuLink($item1);
$edit = array();
$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($item1
->getPluginId(), array(
'enabled' => 1,
));
// Add an external link.
$item7 = $this
->addMenuLink('', 'https://www.drupal.org', $menu_name);
$this
->assertMenuLink($item7
->getPluginId(), array(
'url' => 'https://www.drupal.org',
));
// Add <front> menu item.
$item8 = $this
->addMenuLink('', '/', $menu_name);
$this
->assertMenuLink($item8
->getPluginId(), array(
'route_name' => '<front>',
));
$this
->drupalGet('');
$this
->assertResponse(200);
// Make sure we get routed correctly.
$this
->clickLink($item8
->getTitle());
$this
->assertResponse(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
->assertResponse(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.
*/
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', array(
'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', array(), 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.
*/
function testSystemMenuRename() {
$this
->drupalLogin($this->adminUser);
$edit = array(
'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
->clickLinkPartialName('Place block');
$this
->assertText($edit['label']);
}
/**
* Tests that menu items pointing to unpublished nodes are editable.
*/
function testUnpublishedNodeMenuItem() {
$this
->drupalLogin($this
->drupalCreateUser(array(
'access administration pages',
'administer blocks',
'administer menu',
'create article content',
'bypass node access',
)));
// Create an unpublished node.
$node = $this
->drupalCreateNode(array(
'type' => 'article',
'status' => NODE_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
->assertCacheContext('user.permissions');
}
/**
* Tests the contextual links on a menu block.
*/
public function testBlockContextualLinks() {
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer menu',
'access contextual links',
'administer blocks',
)));
$custom_menu = $this
->addCustomMenu();
$this
->addMenuLink('', '/', $custom_menu
->id());
$block = $this
->drupalPlaceBlock('system_menu_block:' . $custom_menu
->id(), array(
'label' => 'Custom menu',
'provider' => 'system',
));
$this
->drupalGet('test-page');
$id = 'block:block=' . $block
->id() . ':langcode=en|menu:menu=' . $custom_menu
->id() . ':langcode=en';
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
$this
->assertRaw('<div data-contextual-id="' . $id . '"></div>', format_string('Contextual link placeholder with id @id exists.', array(
'@id' => $id,
)));
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
$post = array(
'ids[0]' => $id,
);
$response = $this
->drupalPost('contextual/render', 'application/json', $post, array(
'query' => array(
'destination' => 'test-page',
),
));
$this
->assertResponse(200);
$json = Json::decode($response);
$this
->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block
->id() . '">Configure block</a></li><li class="entitymenuedit-form"><a href="' . base_path() . 'admin/structure/menu/manage/' . $custom_menu
->id() . '">Edit menu</a></li></ul>');
}
/**
* 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.
*/
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
->assertResponse(200);
$title = '!link_' . $this
->randomMachineName(16);
$edit = array(
'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
->assertResponse(200);
$this
->assertText('The menu link has been saved.');
$menu_links = entity_load_multiple_by_properties('menu_link_content', array(
'title' => $title,
));
$menu_link = reset($menu_links);
$this
->assertTrue($menu_link, 'Menu link was found in database.');
$this
->assertMenuLink($menu_link
->getPluginId(), array(
'menu_name' => $menu_name,
'children' => array(),
'parent' => $parent,
));
return $menu_link;
}
/**
* Attempts to add menu link with invalid path or no access permission.
*/
function addInvalidMenuLink() {
foreach (array(
'access' => '/admin/people/permissions',
) as $type => $link_path) {
$edit = array(
'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.", array(
'@link_path' => $link_path,
)), 'Menu link was not created');
}
}
/**
* Tests that parent options are limited by depth when adding menu links.
*/
function checkInvalidParentMenuLinks() {
$last_link = null;
$created_links = array();
// 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 = array(
'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 = entity_load_multiple_by_properties('menu_link_content', array(
'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.
*/
function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) {
// View home page.
$this
->drupalGet('');
$this
->assertResponse(200);
// Verify parent menu link.
if (isset($parent)) {
// Verify menu link.
$title = $parent
->getTitle();
$this
->assertLink($title, 0, 'Parent menu link was displayed');
// Verify menu link link.
$this
->clickLink($title);
$title = $parent_node
->label();
$this
->assertTitle(t("@title | Drupal", array(
'@title' => $title,
)), 'Parent menu link link target was correct');
}
// Verify menu link.
$title = $item
->getTitle();
$this
->assertLink($title, 0, 'Menu link was displayed');
// Verify menu link link.
$this
->clickLink($title);
$title = $item_node
->label();
$this
->assertTitle(t("@title | Drupal", array(
'@title' => $title,
)), 'Menu link link target was correct');
}
/**
* 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.
*/
function moveMenuLink(MenuLinkContent $item, $parent, $menu_name) {
$mlid = $item
->id();
$edit = array(
'menu_parent' => $menu_name . ':' . $parent,
);
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
$this
->assertResponse(200);
}
/**
* Modifies a menu link using the UI.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link entity.
*/
function modifyMenuLink(MenuLinkContent $item) {
$item->title->value = $this
->randomMachineName(16);
$mlid = $item
->id();
$title = $item
->getTitle();
// Edit menu link.
$edit = array();
$edit['title[0][value]'] = $title;
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
$this
->assertResponse(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.
*/
function resetMenuLink(MenuLinkInterface $menu_link, $old_weight) {
// Reset menu link.
$this
->drupalPostForm("admin/structure/menu/link/{$menu_link->getPluginId()}/reset", array(), t('Reset'));
$this
->assertResponse(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.
*/
function deleteMenuLink(MenuLinkContent $item) {
$mlid = $item
->id();
$title = $item
->getTitle();
// Delete menu link.
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/delete", array(), t('Delete'));
$this
->assertResponse(200);
$this
->assertRaw(t('The menu link %title has been deleted.', array(
'%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.
*/
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.
*/
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($item
->getPluginId(), array(
'enabled' => 0,
));
}
/**
* Enables a menu link.
*
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
* Menu link.
*/
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($item
->getPluginId(), array(
'enabled' => 1,
));
}
/**
* Tests if administrative users other than user 1 can access the menu parents
* AJAX callback.
*/
public function testMenuParentsJsAccess() {
$admin = $this
->drupalCreateUser(array(
'administer menu',
));
$this
->drupalLogin($admin);
// Just check access to the callback overall, the POST data is irrelevant.
$this
->drupalGetAjax('admin/structure/menu/parents');
$this
->assertResponse(200);
// Do standard user tests.
// Login the user.
$this
->drupalLogin($this->authenticatedUser);
$this
->drupalGetAjax('admin/structure/menu/parents');
$this
->assertResponse(403);
}
/**
* 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 integer $response
* The expected HTTP response code. Defaults to 200.
*/
private function verifyAccess($response = 200) {
// View menu help page.
$this
->drupalGet('admin/help/menu');
$this
->assertResponse($response);
if ($response == 200) {
$this
->assertText(t('Menu'), 'Menu help was displayed');
}
// View menu build overview page.
$this
->drupalGet('admin/structure/menu');
$this
->assertResponse($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
->assertResponse($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
->assertResponse($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
->assertResponse($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();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertContentTrait:: |
protected | property | The current raw content. | |
AssertContentTrait:: |
protected | property | The drupalSettings value from the current raw $content. | |
AssertContentTrait:: |
protected | property | The XML structure parsed from the current raw $content. | 2 |
AssertContentTrait:: |
protected | property | The plain-text content of raw $content (text nodes). | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertContentTrait:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href is not found in the main region. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page does not exist. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text is NOT found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | |
AssertContentTrait:: |
protected | function | Pass if the page title is not the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | |
AssertContentTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertContentTrait:: |
protected | function | Asserts that a Perl regex pattern is found in the plain-text content. | |
AssertContentTrait:: |
protected | function | Asserts themed output. | |
AssertContentTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
AssertContentTrait:: |
protected | function | Builds an XPath query. | |
AssertContentTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertContentTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
AssertContentTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertContentTrait:: |
protected | function | Gets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Gets the current raw content. | |
AssertContentTrait:: |
protected | function | Get the selected value from a select field. | |
AssertContentTrait:: |
protected | function | Retrieves the plain-text content from the current raw content. | |
AssertContentTrait:: |
protected | function | Get the current URL from the cURL handler. | 1 |
AssertContentTrait:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
AssertContentTrait:: |
protected | function | Removes all white-space between HTML tags from the raw content. | |
AssertContentTrait:: |
protected | function | Sets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Sets the raw content (e.g. HTML). | |
AssertContentTrait:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
AssertHelperTrait:: |
protected | function | Casts MarkupInterface objects into strings. | |
MenuTest:: |
protected | property | A user with administration rights. | |
MenuTest:: |
protected | property | An authenticated user. | |
MenuTest:: |
protected | property | Array of placed menu blocks keyed by block ID. | |
MenuTest:: |
protected | property | An array of test menu links. | |
MenuTest:: |
protected | property | A test menu. | |
MenuTest:: |
public static | property |
Modules to enable. Overrides MenuWebTestBase:: |
|
MenuTest:: |
function | Creates a custom menu. | ||
MenuTest:: |
function | Adds a custom menu using CRUD functions. | ||
MenuTest:: |
function | Attempts to add menu link with invalid path or no access permission. | ||
MenuTest:: |
function | Adds a menu link using the UI. | ||
MenuTest:: |
function | Tests that parent options are limited by depth when adding menu links. | ||
MenuTest:: |
function | Deletes the locally stored custom menu. | ||
MenuTest:: |
function | Deletes a menu link using the UI. | ||
MenuTest:: |
function | Disables a menu link. | ||
MenuTest:: |
protected | function | Ensures that the proper default values are set when adding a menu link | |
MenuTest:: |
function | Tests menu functionality. | ||
MenuTest:: |
protected | function | Tests menu block settings. | |
MenuTest:: |
function | Enables a menu link. | ||
MenuTest:: |
private | function | Returns standard menu link. | |
MenuTest:: |
function | Modifies a menu link using the UI. | ||
MenuTest:: |
function | Changes the parent of a menu link using the UI. | ||
MenuTest:: |
function | Resets a standard menu link using the UI. | ||
MenuTest:: |
protected | function |
Sets up a Drupal site for running functional and integration tests. Overrides WebTestBase:: |
|
MenuTest:: |
public | function | Tests the contextual links on a menu block. | |
MenuTest:: |
function | Tests menu functionality using the admin and user interfaces. | ||
MenuTest:: |
public | function | Tests if administrative users other than user 1 can access the menu parents AJAX callback. | |
MenuTest:: |
function | Adds and removes a menu link with a query string and fragment. | ||
MenuTest:: |
function | Tests renaming the built-in menu. | ||
MenuTest:: |
function | Tests that menu items pointing to unpublished nodes are editable. | ||
MenuTest:: |
function | Alternately disables and enables a menu link. | ||
MenuTest:: |
private | function | Verifies the logged in user has the desired access to various menu pages. | |
MenuTest:: |
function | Verifies a menu link using the UI. | ||
MenuWebTestBase:: |
function | Fetches the menu item from the database and compares it to expected item. | ||
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. | |
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. | |
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. | |
TestBase:: |
protected | property | Assertions thrown in that test case. | |
TestBase:: |
protected | property | The config importer that can used in a test. | 5 |
TestBase:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
TestBase:: |
protected | property | The dependency injection container used in the test. | |
TestBase:: |
protected | property | The database prefix of this test run. | |
TestBase:: |
public | property | Whether to die in case any test assertion fails. | |
TestBase:: |
protected | property | HTTP authentication credentials (<username>:<password>). | |
TestBase:: |
protected | property | HTTP authentication method (specified as a CURLAUTH_* constant). | |
TestBase:: |
protected | property | The original configuration (variables), if available. | |
TestBase:: |
protected | property | The original configuration (variables). | |
TestBase:: |
protected | property | The original configuration directories. | |
TestBase:: |
protected | property | The original container. | |
TestBase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
TestBase:: |
protected | property | The original language. | |
TestBase:: |
protected | property | The original database prefix when running inside Simpletest. | |
TestBase:: |
protected | property | The original installation profile. | |
TestBase:: |
protected | property | The name of the session cookie of the test-runner. | |
TestBase:: |
protected | property | The settings array. | |
TestBase:: |
protected | property | The site directory of the original parent site. | |
TestBase:: |
protected | property | The private file directory for the test environment. | |
TestBase:: |
protected | property | The public file directory for the test environment. | |
TestBase:: |
public | property | Current results of this test case. | |
TestBase:: |
protected | property | The site directory of this test run. | |
TestBase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
TestBase:: |
protected | property | Set to TRUE to strict check all configuration saved. | 4 |
TestBase:: |
protected | property | The temporary file directory for the test environment. | |
TestBase:: |
protected | property | The test run ID. | |
TestBase:: |
protected | property | Time limit for the test. | |
TestBase:: |
protected | property | The translation file directory for the test environment. | |
TestBase:: |
public | property | TRUE if verbose debugging is enabled. | |
TestBase:: |
protected | property | Safe class name for use in verbose output filenames. | |
TestBase:: |
protected | property | Directory where verbose output files are put. | |
TestBase:: |
protected | property | URL to the verbose output file directory. | |
TestBase:: |
protected | property | Incrementing identifier for verbose output filenames. | |
TestBase:: |
protected | function | Internal helper: stores the assert. | |
TestBase:: |
protected | function | Check to see if two values are equal. | |
TestBase:: |
protected | function | Asserts that a specific error has been logged to the PHP error log. | |
TestBase:: |
protected | function | Check to see if a value is false. | |
TestBase:: |
protected | function | Check to see if two values are identical. | |
TestBase:: |
protected | function | Checks to see if two objects are identical. | |
TestBase:: |
protected | function | Asserts that no errors have been logged to the PHP error.log thus far. | |
TestBase:: |
protected | function | Check to see if two values are not equal. | |
TestBase:: |
protected | function | Check to see if two values are not identical. | |
TestBase:: |
protected | function | Check to see if a value is not NULL. | |
TestBase:: |
protected | function | Check to see if a value is NULL. | |
TestBase:: |
protected | function | Check to see if a value is not false. | |
TestBase:: |
protected | function | Act on global state information before the environment is altered for a test. | 1 |
TestBase:: |
private | function | Changes the database connection to the prefixed one. | |
TestBase:: |
protected | function | Checks the matching requirements for Test. | 2 |
TestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
TestBase:: |
public | function | Returns a ConfigImporter object to import test importing of configuration. | 5 |
TestBase:: |
public | function | Copies configuration objects from source storage to target storage. | |
TestBase:: |
public static | function | Delete an assertion record by message ID. | |
TestBase:: |
protected | function | Fire an error assertion. | 3 |
TestBase:: |
public | function | Handle errors during test runs. | |
TestBase:: |
protected | function | Handle exceptions. | |
TestBase:: |
protected | function | Fire an assertion that is always negative. | |
TestBase:: |
public static | function | Ensures test files are deletable within file_unmanaged_delete_recursive(). | |
TestBase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
TestBase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
TestBase:: |
protected | function | Gets the config schema exclusions for this test. | |
TestBase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestBase:: |
public | function | Gets the database prefix. | |
TestBase:: |
public | function | Gets the temporary files directory. | |
TestBase:: |
public static | function | Store an assertion from outside the testing context. | |
TestBase:: |
protected | function | Fire an assertion that is always positive. | |
TestBase:: |
private | function | Generates a database prefix for running tests. | |
TestBase:: |
private | function | Prepares the current environment for running the test. | |
TestBase:: |
private | function | Cleans up the test environment and restores the original environment. | |
TestBase:: |
public | function | Run all tests in this class. | 1 |
TestBase:: |
protected | function | Changes in memory settings. | |
TestBase:: |
protected | function | Helper method to store an assertion record in the configured database. | |
TestBase:: |
protected | function | Logs a verbose message in a text file. | |
UserCreationTrait:: |
protected | function | Checks whether a given list of permission names is valid. | |
UserCreationTrait:: |
protected | function | Creates an administrative role. Aliased as: drupalCreateAdminRole | |
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. | |
WebTestBase:: |
protected | property | Additional cURL options. | |
WebTestBase:: |
protected | property | Whether or not to assert the presence of the X-Drupal-Ajax-Token. | |
WebTestBase:: |
protected | property | The class loader to use for installation and initialization of setup. | |
WebTestBase:: |
protected | property | The config directories used in this test. | |
WebTestBase:: |
protected | property | The current cookie file used by cURL. | |
WebTestBase:: |
protected | property | The cookies of the page currently loaded in the internal browser. | |
WebTestBase:: |
protected | property | Cookies to set on curl requests. | |
WebTestBase:: |
protected | property | The handle of the current cURL connection. | |
WebTestBase:: |
protected | property | An array of custom translations suitable for drupal_rewrite_settings(). | |
WebTestBase:: |
protected | property | Indicates that headers should be dumped if verbose output is enabled. | 12 |
WebTestBase:: |
protected | property | Whether the files were copied to the test files directory. | |
WebTestBase:: |
protected | property | The headers of the page currently loaded in the internal browser. | |
WebTestBase:: |
protected | property |
The kernel used in this test. Overrides TestBase:: |
|
WebTestBase:: |
protected | property | The current user logged in using the internal browser. | |
WebTestBase:: |
protected | property | The number of meta refresh redirects to follow, or NULL if unlimited. | |
WebTestBase:: |
protected | property | The maximum number of redirects to follow when handling responses. | |
WebTestBase:: |
protected | property | The number of meta refresh redirects followed during ::drupalGet(). | |
WebTestBase:: |
protected | property | The original batch, before it was changed for testing purposes. | |
WebTestBase:: |
protected | property |
The original shutdown handlers array, before it was cleaned for testing. Overrides TestBase:: |
|
WebTestBase:: |
protected | property |
The original user, before it was changed to a clean uid = 1 for testing. Overrides TestBase:: |
|
WebTestBase:: |
protected | property | The profile to install as a basis for testing. | 30 |
WebTestBase:: |
protected | property | The number of redirects followed during the handling of a request. | |
WebTestBase:: |
protected | property | The "#1" admin user. | |
WebTestBase:: |
protected | property | The current session ID, if available. | |
WebTestBase:: |
protected | property | The URL currently loaded in the internal browser. | |
WebTestBase:: |
protected | function | Queues custom translations to be written to settings.php. | |
WebTestBase:: |
protected | function | Checks to see whether a block appears on the page. | |
WebTestBase:: |
protected | function | Asserts whether an expected cache context was present in the last response. | |
WebTestBase:: |
protected | function | Asserts whether an expected cache tag was present in the last response. | |
WebTestBase:: |
protected | function | Check if a HTTP response header exists and has the expected value. | |
WebTestBase:: |
protected | function | Asserts that the most recently sent email message has the given value. | |
WebTestBase:: |
protected | function | Asserts that the most recently sent email message has the pattern in it. | |
WebTestBase:: |
protected | function | Asserts that the most recently sent email message has the string in it. | |
WebTestBase:: |
protected | function | Checks to see whether a block does not appears on the page. | |
WebTestBase:: |
protected | function | Asserts that a cache context was not present in the last response. | |
WebTestBase:: |
protected | function | Asserts whether an expected cache tag was absent in the last response. | |
WebTestBase:: |
protected | function | Asserts the page did not return the specified response code. | |
WebTestBase:: |
protected | function | Asserts the page responds with the specified response code. | |
WebTestBase:: |
protected | function | Passes if the internal browser's URL matches the given path. | |
WebTestBase:: |
protected | function | Builds an a absolute URL from a system path or a URL object. | |
WebTestBase:: |
protected | function | Checks for meta refresh tag and if found call drupalGet() recursively. | |
WebTestBase:: |
protected | function | Follows a link by complete name. | |
WebTestBase:: |
protected | function | Provides a helper for ::clickLink() and ::clickLinkPartialName(). | |
WebTestBase:: |
protected | function | Follows a link by partial name. | |
WebTestBase:: |
protected | function | Runs cron in the Drupal installed by Simpletest. | |
WebTestBase:: |
protected | function | Close the cURL handler and unset the handler. | |
WebTestBase:: |
protected | function | Initializes and executes a cURL request. | 2 |
WebTestBase:: |
protected | function | Reads headers and registers errors received from the tested site. | |
WebTestBase:: |
protected | function | Initializes the cURL connection. | |
WebTestBase:: |
protected | function | Execute the non-interactive installer. | |
WebTestBase:: |
protected | function | Builds the renderable view of an entity. | |
WebTestBase:: |
protected | function | Compare two files based on size and file name. | |
WebTestBase:: |
protected | function | Creates a custom content type based on default settings. | |
WebTestBase:: |
protected | function | Creates a node based on default settings. | |
WebTestBase:: |
protected | function | Retrieves a Drupal path or an absolute path. | 1 |
WebTestBase:: |
protected | function | Requests a path or URL in drupal_ajax format and JSON-decodes the response. | |
WebTestBase:: |
protected | function | Gets the value of an HTTP response header. | |
WebTestBase:: |
protected | function | Gets the HTTP response headers of the requested page. | |
WebTestBase:: |
protected | function | Retrieves a Drupal path or an absolute path and JSON decodes the result. | |
WebTestBase:: |
protected | function | Gets an array containing all emails sent during this test case. | |
WebTestBase:: |
function | Get a node from the database based on its title. | ||
WebTestBase:: |
protected | function | Gets a list of files that can be used in tests. | |
WebTestBase:: |
protected | function | Retrieves a Drupal path or an absolute path for a given format. | |
WebTestBase:: |
protected | function | Requests a Drupal path or an absolute path as if it is a XMLHttpRequest. | |
WebTestBase:: |
protected | function | Retrieves only the headers for a Drupal path or an absolute path. | |
WebTestBase:: |
protected | function | Log in a user with the internal browser. | |
WebTestBase:: |
protected | function | Logs a user out of the internal browser and confirms. | |
WebTestBase:: |
protected | function | Creates a block instance based on default settings. | |
WebTestBase:: |
protected | function | Perform a POST HTTP request. | |
WebTestBase:: |
protected | function | Executes an Ajax form submission. | |
WebTestBase:: |
protected | function | Executes a form submission. | |
WebTestBase:: |
protected | function | Performs a POST HTTP request with a specific format. | |
WebTestBase:: |
protected | function | Processes an AJAX response into current content. | |
WebTestBase:: |
protected | function | Returns whether a given user account is logged in. | |
WebTestBase:: |
protected | function | Find a block instance on the page. | |
WebTestBase:: |
protected | function | Takes a path and returns an absolute path. | |
WebTestBase:: |
protected | function | Get the Ajax page state from drupalSettings and prepare it for POSTing. | |
WebTestBase:: |
protected | function | Returns all supported database driver installer objects. | |
WebTestBase:: |
protected | function | Handles form input related to drupalPostForm(). | |
WebTestBase:: |
protected | function | Initialize various configurations post-installation. | |
WebTestBase:: |
protected | function | Initializes the kernel after installation. | |
WebTestBase:: |
protected | function | Initialize settings created during install. | |
WebTestBase:: |
protected | function | Initializes user 1 for the site to be installed. | |
WebTestBase:: |
protected | function | Install modules defined by `static::$modules`. | |
WebTestBase:: |
protected | function | Returns the parameters that will be used when Simpletest installs Drupal. | 2 |
WebTestBase:: |
protected | function | Returns whether the test is being executed from within a test site. | |
WebTestBase:: |
protected | function | Creates a mock request and sets it on the generator. | |
WebTestBase:: |
protected | function | Prepares site settings and services before installation. | 1 |
WebTestBase:: |
protected | function | Reset and rebuild the environment after setup. | |
WebTestBase:: |
protected | function | Rebuilds \Drupal::getContainer(). | |
WebTestBase:: |
protected | function | Refreshes in-memory configuration and state information. | 1 |
WebTestBase:: |
protected | function | Resets all data structures after having enabled new modules. | |
WebTestBase:: |
protected | function | Restore the original batch. | |
WebTestBase:: |
protected | function | Serialize POST HTTP request values. | |
WebTestBase:: |
protected | function | Preserve the original batch, and instantiate the test batch. | |
WebTestBase:: |
protected | function | Changes parameters in the services.yml file. | |
WebTestBase:: |
protected | function | Enables/disables the cacheability headers. | |
WebTestBase:: |
protected | function |
Cleans up after testing. Overrides TestBase:: |
2 |
WebTestBase:: |
protected | function | Transforms a nested array into a flat array suitable for WebTestBase::drupalPostForm(). | |
WebTestBase:: |
protected | function | Outputs to verbose the most recent $count emails sent. | |
WebTestBase:: |
protected | function | Writes custom translations to the test site's settings.php. | |
WebTestBase:: |
protected | function | Rewrites the settings.php file of the test site. | |
WebTestBase:: |
function |
Constructor for \Drupal\simpletest\WebTestBase. Overrides TestBase:: |
1 |