public function CasAttributesSubscriberTest::testRoleMappingOnLogin in CAS Attributes 2.x
Same name and namespace in other branches
- 8 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 599
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');
// Intentionall set a different case than the role mapping attribute name
// to ensure it doesn't matter and a match occurs either way.
$propertyBag
->setAttribute('FRUIT', [
'banana',
]);
$subscriber = new CasAttributesSubscriber($config_factory, $this->tokenService, $this->requestStack);
$event = new CasPreLoginEvent($account, $propertyBag);
$subscriber
->onPreLogin($event);
}