function UserRolesPermissionsTest::testPermissionChange

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Session/UserRolesPermissionsTest.php \Drupal\KernelTests\Core\Session\UserRolesPermissionsTest::testPermissionChange()

Tests that assigning a role grants that role's permissions.

File

core/tests/Drupal/KernelTests/Core/Session/UserRolesPermissionsTest.php, line 35

Class

UserRolesPermissionsTest
Test case for getting permissions from user roles.

Namespace

Drupal\KernelTests\Core\Session

Code

public function testPermissionChange() : void {
    // Create two accounts to avoid dealing with user 1.
    $this->createUser();
    $account = $this->createUser();
    $this->assertFalse($account->hasPermission('administer modules'));
    $account->addRole($this->createRole([
        'administer modules',
    ]))
        ->save();
    $this->assertTrue($account->hasPermission('administer modules'));
}

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