public function CasAttributesSubscriberTest::testRoleMappingOnLogin in CAS Attributes 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Subscriber/CasAttributesSubscriberTest.php \Drupal\Tests\cas_attributes\Unit\Subscriber\CasAttributesSubscriberTest::testRoleMappingOnLogin()
Tests that role mapping works as expected during login.
File
- tests/
src/ Unit/ Subscriber/ CasAttributesSubscriberTest.php, line 546
Class
- CasAttributesSubscriberTest
- CasAttributesSubscriber unit tests.
Namespace
Drupal\Tests\cas_attributes\Unit\SubscriberCode
public function testRoleMappingOnLogin() {
$role_map = [
[
'rid' => 'bananarole',
'method' => 'exact_single',
'attribute' => 'fruit',
'value' => 'banana',
'remove_without_match' => FALSE,
],
[
'rid' => 'orangerole',
'method' => 'exact_single',
'attribute' => 'fruit',
'value' => 'orange',
'remove_without_match' => FALSE,
],
];
$config_factory = $this
->getConfigFactoryStub([
'cas_attributes.settings' => [
'role.sync_frequency' => CasAttributesSettings::SYNC_FREQUENCY_EVERY_LOGIN,
'role.mappings' => $role_map,
],
]);
// Just one role should be added to the user, since the other
// doesn't have an attribute match.
$account = $this
->createMock('\\Drupal\\user\\UserInterface');
$account
->expects($this
->once())
->method('addRole')
->with('bananarole');
$propertyBag = new CasPropertyBag('test');
$propertyBag
->setAttribute('fruit', [
'banana',
]);
$subscriber = new CasAttributesSubscriber($config_factory, $this->tokenService, $this->requestStack);
$event = new CasPreLoginEvent($account, $propertyBag);
$subscriber
->onPreLogin($event);
}