You are here

public function OpenIDConnectTest::testHasSetPasswordAccess in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/OpenIDConnectTest.php \Drupal\Tests\openid_connect\Unit\OpenIDConnectTest::testHasSetPasswordAccess()

Test for the hasSetPassword method.

@dataProvider dataProviderForHasSetPasswordAccess

Parameters

\Drupal\Tests\openid_connect\Unit\MockObject|null $account: The account to test or null if none provided.

bool $hasPermission: Whether the account should have the correct permission to change their own password.

array $connectedAccounts: The connected accounts array from the authMap method.

bool $expectedResult: The result expected.

File

tests/src/Unit/OpenIDConnectTest.php, line 343

Class

OpenIDConnectTest
Provides tests for the OpenID Connect module.

Namespace

Drupal\Tests\openid_connect\Unit

Code

public function testHasSetPasswordAccess(?MockObject $account, bool $hasPermission, array $connectedAccounts, bool $expectedResult) : void {
  if (empty($account)) {
    $this->currentUser
      ->expects($this
      ->once())
      ->method('hasPermission')
      ->with('openid connect set own password')
      ->willReturn($hasPermission);
    if (!$hasPermission) {
      $this->authMap
        ->expects($this
        ->once())
        ->method('getConnectedAccounts')
        ->with($this->currentUser)
        ->willReturn($connectedAccounts);
    }
  }
  else {
    $account
      ->expects($this
      ->once())
      ->method('hasPermission')
      ->with('openid connect set own password')
      ->willReturn($hasPermission);
    if (!$hasPermission) {
      $this->authMap
        ->expects($this
        ->once())
        ->method('getConnectedAccounts')
        ->with($account)
        ->willReturn($connectedAccounts);
    }
  }
  $actualResult = $this->openIdConnect
    ->hasSetPasswordAccess($account);
  $this
    ->assertEquals($expectedResult, $actualResult);
}