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. 8.9.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::checkPermissions()
  3. 10 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 293

Class

UserCreationTrait
Provides test methods for user creation and authentication.

Namespace

Drupal\Tests\user\Traits

Code

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

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