You are here

protected function UserCreationTrait::checkPermissions 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::checkPermissions()
  2. 9 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::checkPermissions()

Checks whether a given list of permission names is valid.

Parameters

array $permissions: The permission names to check.

Return value

bool TRUE if the permissions are valid, FALSE otherwise.

File

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

Class

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

Namespace

Drupal\Tests\user\Traits

Code

protected function checkPermissions(array $permissions) {
  $available = array_keys(\Drupal::service('user.permissions')
    ->getPermissions());
  $valid = TRUE;
  foreach ($permissions as $permission) {
    if (!in_array($permission, $available)) {
      $this
        ->fail(new FormattableMarkup('Invalid permission %permission.', [
        '%permission' => $permission,
      ]), 'Role');
      $valid = FALSE;
    }
  }
  return $valid;
}