You are here

public function OpenIdConnectClaimsTest::testUserInfoMappingScopes in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/OpenIdConnectClaimsTest.php \Drupal\Tests\openid_connect\Unit\OpenIdConnectClaimsTest::testUserInfoMappingScopes()

Test the scopes based on the user mappings.

@dataProvider defaultClaimsProvider The data profiled for the claims test.

Parameters

string $key: The key for the claim.

string $scope: The scope for the claim.

string $type: The data type for the claim.

File

tests/src/Unit/OpenIdConnectClaimsTest.php, line 183

Class

OpenIdConnectClaimsTest
Test the OpenIdConnectClaims class.

Namespace

Drupal\Tests\openid_connect\Unit

Code

public function testUserInfoMappingScopes(string $key, string $scope, string $type) : void {
  $mappings = self::USERINFO_MAPPINGS;

  // Append the provided key to the mappings.
  $mappings[$key] = $this
    ->randomMachineName();
  $userInfoMapping = $this
    ->createMock(ImmutableConfig::class);
  $userInfoMapping
    ->expects($this
    ->once())
    ->method('get')
    ->willReturn($mappings);
  $this->configFactory
    ->expects($this
    ->once())
    ->method('getEditable')
    ->willReturn($userInfoMapping);
  $actualScopes = $this->openIdConnectClaims
    ->getScopes();
  switch ($scope) {
    case 'email':
    case 'address':
    case 'phone':
      $this
        ->assertEquals("openid email profile", $actualScopes);
      break;
    default:
      $this
        ->assertEquals("openid email {$scope}", $actualScopes);
      break;
  }
}