You are here

protected function BrowserTestBase::checkPermissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::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 BrowserTestBase::checkPermissions()
BrowserTestBase::drupalCreateRole in core/modules/simpletest/src/BrowserTestBase.php
Creates a role with specified permissions.

File

core/modules/simpletest/src/BrowserTestBase.php, line 648
Contains \Drupal\simpletest\BrowserTestBase.

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\simpletest

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(SafeMarkup::format('Invalid permission %permission.', array(
        '%permission' => $permission,
      )));
      $valid = FALSE;
    }
  }
  return $valid;
}