public function DrupalRolesIntegrationTest::testRevocation in Authorization 8
Previously granted roles are removed, when no longer applicable.
File
- authorization_drupal_roles/
tests/ src/ Kernel/ DrupalRolesIntegrationTest.php, line 63
Class
- DrupalRolesIntegrationTest
- Integration tests for authorization_drupal_roles.
Namespace
Drupal\Tests\authorization_drupal_roles\KernelCode
public function testRevocation() : void {
$profile = AuthorizationProfile::create([
'status' => 'true',
'description' => 'test',
'id' => 'test',
'provider' => 'dummy',
'consumer' => 'authorization_drupal_roles',
]);
$consumer = $profile
->getConsumer();
$account = User::create([
'name' => 'hpotter',
]);
$roles_granted = [
'student',
'gryffindor',
'staff',
];
$account
->set('authorization_drupal_roles_roles', $roles_granted);
$account
->addRole('student');
$account
->addRole('gryffindor');
$account
->addRole('staff');
// User was in student, gryffindor and is now only in staff, according to
// the provider and removal is presumed enabled.
$active_roles = [
'staff',
];
$consumer
->revokeGrants($account, $active_roles);
self::assertEquals([
0 => [
'value' => 'staff',
],
], $account
->get('authorization_drupal_roles_roles')
->getValue());
self::assertEquals([
'anonymous',
'staff',
], $account
->getRoles());
}