public function DrupalRolesIntegrationTest::testGrant in Authorization 8
Tests granting new roles.
File
- authorization_drupal_roles/
tests/ src/ Kernel/ DrupalRolesIntegrationTest.php, line 31
Class
- DrupalRolesIntegrationTest
- Integration tests for authorization_drupal_roles.
Namespace
Drupal\Tests\authorization_drupal_roles\KernelCode
public function testGrant() : void {
$profile = AuthorizationProfile::create([
'status' => 'true',
'description' => 'test',
'id' => 'test',
'provider' => 'dummy',
'consumer' => 'authorization_drupal_roles',
]);
$consumer = $profile
->getConsumer();
$account = User::create([
'name' => 'hpotter',
]);
$account
->set('authorization_drupal_roles_roles', [
'student',
'gryffindor',
]);
$consumer
->grantSingleAuthorization($account, 'student');
$savedData = [
0 => [
'value' => 'student',
],
1 => [
'value' => 'gryffindor',
],
];
// No duplicate information in authorization record, only one role because
// nothing else assigned, yet.
self::assertEquals($savedData, $account
->get('authorization_drupal_roles_roles')
->getValue());
self::assertEquals([
'anonymous',
'student',
], $account
->getRoles());
$consumer
->grantSingleAuthorization($account, 'wizard');
$savedData = [
0 => [
'value' => 'student',
],
1 => [
'value' => 'gryffindor',
],
2 => [
'value' => 'wizard',
],
];
self::assertEquals($account
->get('authorization_drupal_roles_roles')
->getValue(), $savedData);
}