You are here

public function OpenIDConnectAuthmapTest::testGetConnectedAccounts in OpenID Connect / OAuth client 8

Test the getConnectedAccounts method.

@dataProvider getConnectedAccountsParameters

Parameters

array $results: The results returned from the database query.

File

tests/src/Unit/OpenIDConnectAuthmapTest.php, line 301

Class

OpenIDConnectAuthmapTest
Test the OpenIdConnectAuthmap class.

Namespace

Drupal\Tests\openid_connect\Unit

Code

public function testGetConnectedAccounts(array $results) : void {
  $account = $this
    ->createMock(User::class);
  $account
    ->expects($this
    ->once())
    ->method('id')
    ->willReturn(self::USER_ID);
  $selectInterface = $this
    ->createMock(SelectInterface::class);
  $selectInterface
    ->expects($this
    ->once())
    ->method('fields')
    ->with('a', [
    'client_name',
    'sub',
  ])
    ->willReturnSelf();
  $selectInterface
    ->expects($this
    ->once())
    ->method('condition')
    ->with('uid', self::USER_ID)
    ->willReturnSelf();
  $selectInterface
    ->expects($this
    ->once())
    ->method('execute')
    ->willReturn($results);
  $this->connection
    ->expects($this
    ->once())
    ->method('select')
    ->willReturn($selectInterface);
  $authMapClass = new OpenIDConnectAuthmap($this->connection, $this->entityTypeManager);
  $actualResult = $authMapClass
    ->getConnectedAccounts($account);
  if (!empty($results)) {
    $record = array_shift($results);
    $expected = [
      $record->client_name => $record->sub,
    ];
    $this
      ->assertArrayEquals($expected, $actualResult);
  }
  else {
    $this
      ->assertEmpty($actualResult);
  }
}