function UserRoleEntityTest::testOrderOfPermissions

Same name in other branches
  1. 8.9.x core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testOrderOfPermissions()
  2. 10 core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testOrderOfPermissions()
  3. 11.x core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testOrderOfPermissions()

File

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

Class

UserRoleEntityTest
@group user @coversDefaultClass \Drupal\user\Entity\Role

Namespace

Drupal\Tests\user\Kernel

Code

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

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