You are here

public function CleanerTestBase::cleanerCreateUserWithRole in Cleaner 7

Create a user with specific role.

Parameters

string $role: Role name.

Return value

false|object User account.

1 call to CleanerTestBase::cleanerCreateUserWithRole()
CleanerTestBase::cleanerAdminSetUp in tests/cleaner_base.test
Basic SetUp method for administrator.

File

tests/cleaner_base.test, line 25
File with a base class for the Cleaner test cases.

Class

CleanerTestBase
Class CleanerTestBase.

Code

public function cleanerCreateUserWithRole($role) {
  $this
    ->assertTrue(!empty($role));

  // Get specific role key.
  $role_key = array_search($role, user_roles());

  // Get all permissions by role key => name.
  $perms = user_role_permissions(array(
    $role_key => $role,
  ));
  $this
    ->assertTrue(is_array($perms));
  $this
    ->assertTrue(isset($perms[$role_key]));
  $perms = $perms[$role_key];

  // Create a user with a permissions specified by role.
  return $this
    ->drupalCreateUser(array_keys($perms));
}