public function SimplesamlphpDrupalAuthTest::testRoleMatching in simpleSAMLphp Authentication 8.3
Test role matching logic.
@covers ::getMatchingRoles @covers ::evalRoleRule
@dataProvider roleMatchingDataProvider
File
- tests/
src/ Unit/ Service/ SimplesamlphpDrupalAuthTest.php, line 414
Class
- SimplesamlphpDrupalAuthTest
- SimplesamlphpDrupalAuth unit tests.
Namespace
Drupal\Tests\simplesamlphp_auth\Unit\ServiceCode
public function testRoleMatching($rolemap, $attributes, $expected_roles) {
// Set up specific configuration to test role matching.
$config_factory = $this
->getConfigFactoryStub([
'simplesamlphp_auth.settings' => [
'register_users' => TRUE,
'activate' => 1,
'role.population' => $rolemap,
],
]);
// Create a Mock SimplesamlphpAuthManager object.
$simplesaml = $this
->getMockBuilder('\\Drupal\\simplesamlphp_auth\\Service\\SimplesamlphpAuthManager')
->disableOriginalConstructor()
->setMethods([
'getAttributes',
])
->getMock();
// Mock the getAttributes() method on SimplesamlphpAuthManager.
$simplesaml
->expects($this
->any())
->method('getAttributes')
->will($this
->returnValue($attributes));
$simplesaml_drupalauth = new SimplesamlphpDrupalAuth($simplesaml, $config_factory, $this->entityTypeManager, $this->logger, $this->externalauth, $this->entityAccount, $this->messenger, $this->moduleHandler);
$matching_roles = $simplesaml_drupalauth
->getMatchingRoles();
$this
->assertEquals(count($expected_roles), count($matching_roles), 'Number of expected roles matches');
$this
->assertEquals($expected_roles, $matching_roles, 'Expected roles match');
}