You are here

protected function UserCreationTrait::grantPermissions in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::grantPermissions()
  2. 9 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::grantPermissions()

Grant permissions to a user role.

Parameters

\Drupal\user\RoleInterface $role: The user role entity to alter.

array $permissions: (optional) A list of permission names to grant.

File

core/modules/user/tests/src/Traits/UserCreationTrait.php, line 321

Class

UserCreationTrait
Provides methods to create additional test users and switch the currently logged in one.

Namespace

Drupal\Tests\user\Traits

Code

protected function grantPermissions(RoleInterface $role, array $permissions) {
  foreach ($permissions as $permission) {
    $role
      ->grantPermission($permission);
  }
  $role
    ->trustData()
    ->save();
}