function UserCreationTrait::grantPermissions

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

25 calls to UserCreationTrait::grantPermissions()
BasicAuthTest::testCacheabilityOf401Response in core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
Tests the cacheability of Basic Auth's 401 response.
ConfigAccessTest::testBlockConfigAccess in core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php
Tests access to block forms with related configuration is correct.
ContextualLinksTest::testContextualLinksClick in core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
Test clicking contextual links.
ContextualLinksTest::testContextualLinksDestination in core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
Test the contextual links destination.
ContextualLinksTest::testContextualLinksVisibility in core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
Tests the visibility of contextual links.

... See full list

File

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

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

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