function UserCreationTrait::checkPermissions

Same name in other branches
  1. 9 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::checkPermissions()
  2. 10 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::checkPermissions()
  3. 11.x 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.

1 call to UserCreationTrait::checkPermissions()
UserCreationTrait::createRole in core/modules/user/tests/src/Traits/UserCreationTrait.php
Creates a role with specified permissions.

File

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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.