public function RoleAssignTest::testRoleDelegationPageAccess in Role Delegation 8
Test that the user has access to the role delegation page.
File
- tests/
src/ Functional/ RoleAssignTest.php, line 165
Class
- RoleAssignTest
- Functional tests for assigning roles.
Namespace
Drupal\Tests\role_delegation\FunctionalCode
public function testRoleDelegationPageAccess() {
$regular_user = $this
->drupalCreateUser();
// Anonymous users can never access the roles page.
$this
->drupalGet(sprintf('/user/%s/roles', $regular_user
->id()));
$this
->assertSession()
->statusCodeEquals(403);
// Users with 'administer permissions' cannot view the page, they must use
// the normal user edit page or also 'have assign all roles'.
$account = $this
->createUser([
'administer permissions',
]);
$this
->drupalLogin($account);
$this
->drupalGet(sprintf('/user/%s/roles', $regular_user
->id()));
$this
->assertSession()
->statusCodeEquals(403);
// Users with a custom 'assign %custom role' permission should be able to
// see the role admin page.
$role = $this
->createRole([]);
$account = $this
->createUser([
sprintf('assign %s role', $role),
]);
$this
->drupalLogin($account);
$this
->drupalGet(sprintf('/user/%s/roles', $regular_user
->id()));
$this
->assertSession()
->statusCodeEquals(200);
// Users with 'assign all roles' can view the page.
$account = $this
->createUser([
'assign all roles',
]);
$this
->drupalLogin($account);
$this
->drupalGet(sprintf('/user/%s/roles', $regular_user
->id()));
$this
->assertSession()
->statusCodeEquals(200);
}