function UserRoleEntityTest::testGrantingNonExistentPermission
Same name in other branches
- 10 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()
@group legacy
File
-
core/
modules/ user/ tests/ src/ Kernel/ UserRoleEntityTest.php, line 34
Class
- UserRoleEntityTest
- @group user @coversDefaultClass \Drupal\user\Entity\Role
Namespace
Drupal\Tests\user\KernelCode
public function testGrantingNonExistentPermission() {
$role = Role::create([
'id' => 'test_role',
'label' => 'Test role',
]);
// A single permission that does not exist.
$this->expectDeprecation('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "does not exist". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348');
$role->grantPermission('does not exist')
->save();
// A multiple permissions that do not exist.
$this->expectDeprecation('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "does not exist", "also does not exist". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348');
$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.