// Create a new role, which implicitly checks if the permission exists.
$mediaOverviewRole = $this->createRole(['access content overview', 'access media overview']); $this->nonAdminUser->addRole($mediaOverviewRole); $this->nonAdminUser->save();
$this->drupalGet('admin/content'); $assert_session->linkByHrefExists('/admin/content/media'); $this->clickLink('Media'); $this->assertCacheContext('user'); $assert_session->statusCodeEquals(200); $assert_session->elementExists('css', '.views-element-container'); // First row of the View contains media created by admin user.
$assert_session->elementTextEquals('xpath', '//div[@class="views-element-container"]//tbody/tr[1]/td[contains(@class, "views-field-uid")]/a', $this->adminUser->getDisplayName());
/**
* Tests Toolbar's responses to installing and uninstalling modules.
*
* @see toolbar_modules_installed()
* @see toolbar_modules_uninstalled()
*/ publicfunctiontestModuleStatusChangeSubtreesHashCacheClear(){ // Use an admin role to ensure the user has all available permissions. This
// results in the admin menu links changing as the taxonomy module is
// installed and uninstalled because the role will always have the
// 'administer taxonomy' permission if it exists.
$role = Role::load($this->createRole([])); $role->setIsAdmin(TRUE); $role->save(); $this->adminUser->addRole($role->id()); $this->adminUser->save();
// Uninstall a module.
$edit = []; $edit['uninstall[taxonomy]'] = TRUE; $this->drupalGet('admin/modules/uninstall'); $this->submitForm($edit, 'Uninstall'); // Confirm the uninstall form.
/**
* {@inheritdoc}
*/ protectedfunctioncreateRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL){ // The parent method uses random strings by default, which may include HTML
// entities for the entity label. Since in this test the entity label is
// used to generate a link, and AssertContentTrait::assertLink() is not
// designed to deal with links potentially containing HTML entities this
// causes random failures. Use a random HTML safe string instead.
$name = $name ?: $this->randomMachineName(); return parent::createRole($permissions, $rid, $name, $weight); }
/**
* Tests the generated title of a user: roles argument.
*/ publicfunctiontestArgumentTitle(){ $role_id = $this->createRole([], 'markup_role_name', '<em>Role name with markup</em>'); $this->createRole([], 'second_role_name', 'Second role name'); $user = $this->createUser([], 'User with role one'); $user->addRole($role_id); $user->save(); $second_user = $this->createUser([], 'User with role two'); $second_user->addRole('second_role_name'); $second_user->save();