You are here

protected function RoleAssignPermissionTest::setUp in RoleAssign 8

Overrides BrowserTestBase::setUp

File

tests/src/Functional/RoleAssignPermissionTest.php, line 52

Class

RoleAssignPermissionTest
Tests that users can (un)assign roles based on the RoleAssign settings.

Namespace

Drupal\Tests\roleassign\Functional

Code

protected function setUp() {
  parent::setUp();

  // Add Editor role.
  $this
    ->drupalCreateRole([], 'editor', 'Editor');

  // Add Webmaster role.
  $this
    ->drupalCreateRole([
    'administer users',
    'assign roles',
  ], 'webmaster', 'Webmaster');

  // Add 'protected' SiteAdmin role.
  $this
    ->drupalCreateRole([
    'administer users',
    'administer permissions',
  ], 'siteadmin', 'SiteAdmin');

  // Configure RoleAssign module - only editor & webmaster roles are
  // assignable by restricted users (i.e. webmasters)
  $this
    ->config('roleassign.settings')
    ->set('roleassign_roles', [
    'editor' => 'editor',
    'webmaster' => 'webmaster',
  ])
    ->save();

  // Create a testAccount that we will be trying to assign roles.
  $this->testAccount = $this
    ->drupalCreateUser();

  // Create a test restricted user without "administer permissions" permission
  // but with "assign roles" permission provided by RoleAssign.
  $this->restrictedUser = $this
    ->drupalCreateUser([
    'administer users',
    'assign roles',
  ]);

  // Create a test admin user with "administer users " &
  // "administer permissions" permissions, where RoleAssign will have no
  // effect on.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer users',
    'administer permissions',
  ]);
}