You are here

protected function UserProtectCreationTrait::createUserWithProtectedRole in User protect 8

Creates an user with a protected role.

Parameters

array $protections: (optional) The active protections. Defaults to an empty array.

Return value

object The created user.

File

tests/src/Traits/UserProtectCreationTrait.php, line 71

Class

UserProtectCreationTrait
Provides methods to create protection rules.

Namespace

Drupal\Tests\userprotect\Traits

Code

protected function createUserWithProtectedRole(array $protections = []) {

  // Create a protected role.
  $rid = $this
    ->createProtectedRole($protections);

  // Create an account with this protected role.
  $protected_account = $this
    ->drupalCreateUser();
  $protected_account
    ->addRole($rid);
  $protected_account
    ->save();
  return $protected_account;
}