You are here

public function DelegatableRolesTest::testDeleteRole in Role Delegation 8

Deleting a role revokes the permission allowing users to assign the role.

File

tests/src/Kernel/DelegatableRolesTest.php, line 85

Class

DelegatableRolesTest
@coversDefaultClass \Drupal\role_delegation\DelegatableRoles

Namespace

Drupal\Tests\role_delegation\Kernel

Code

public function testDeleteRole() {
  $rid = $this
    ->createRole([]);
  $permission = "assign {$rid} role";
  $account = $this
    ->createUser([
    $permission,
  ]);
  $this
    ->assertTrue($account
    ->hasPermission($permission), sprintf('User has "%s" permission.', $permission));

  // Delete the role and ensure the user no longer has the permission.
  Role::load($rid)
    ->delete();
  $this
    ->assertFalse($account
    ->hasPermission($permission), sprintf('User no longer has "%s" permission.', $permission));
}