function UserRoleEntityTest::testGrantingNonExistentPermission
Same name in other branches
- 9 core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testGrantingNonExistentPermission()
- 11.x core/modules/user/tests/src/Kernel/UserRoleEntityTest.php \Drupal\Tests\user\Kernel\UserRoleEntityTest::testGrantingNonExistentPermission()
File
-
core/
modules/ user/ tests/ src/ Kernel/ UserRoleEntityTest.php, line 36
Class
- UserRoleEntityTest
- @group user @coversDefaultClass \Drupal\user\Entity\Role
Namespace
Drupal\Tests\user\KernelCode
public function testGrantingNonExistentPermission() : void {
$role = Role::create([
'id' => 'test_role',
'label' => 'Test role',
]);
// A single permission that does not exist.
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist".');
$role->grantPermission('does not exist')
->save();
// A multiple permissions that do not exist.
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist, also does not exist".');
$role->grantPermission('does not exist')
->grantPermission('also does not exist')
->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.