function UserRoleEntityTest::testPermissionRevokeAndConfigSync

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testPermissionRevokeAndConfigSync()
  2. 11.x core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testPermissionRevokeAndConfigSync()

File

core/modules/user/tests/src/Kernel/UserRoleEntityTest.php, line 53

Class

UserRoleEntityTest
@group user @coversDefaultClass \Drupal\user\Entity\Role[[api-linebreak]]

Namespace

Drupal\Tests\user\Kernel

Code

public function testPermissionRevokeAndConfigSync() : void {
  $role = Role::create([
    'id' => 'test_role',
    'label' => 'Test role',
  ]);
  $role->setSyncing(TRUE);
  $role->grantPermission('a')
    ->grantPermission('b')
    ->grantPermission('c')
    ->save();
  $this->assertSame([
    'a',
    'b',
    'c',
  ], $role->getPermissions());
  $role->revokePermission('b')
    ->save();
  $this->assertSame([
    'a',
    'c',
  ], $role->getPermissions());
}

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