You are here

public function OpenIdConnectSessionTest::testSaveDestination in OpenID Connect / OAuth client 2.x

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

Test the saveDestination method.

File

tests/src/Unit/OpenIdConnectSessionTest.php, line 96

Class

OpenIdConnectSessionTest
@coversDefaultClass \Drupal\openid_connect\OpenIDConnectSession @group openid_connect

Namespace

Drupal\Tests\openid_connect\Unit

Code

public function testSaveDestination() : void {

  // Get the expected destination.
  $expectedDestination = self::TEST_PATH . '?' . self::TEST_QUERY;

  // Mock the get method for the 'redirect.destination' service.
  $this->redirectDestination
    ->expects($this
    ->once())
    ->method('get')
    ->willReturn($expectedDestination);

  // Mock the get method for the 'session' service.
  $this->session
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->willReturnOnConsecutiveCalls($expectedDestination, 'und');
  $language = $this
    ->createMock(LanguageInterface::class);
  $language
    ->expects($this
    ->once())
    ->method('getId')
    ->willReturn('und');
  $this->languageManager
    ->expects($this
    ->once())
    ->method('getCurrentLanguage')
    ->willReturn($language);

  // Create a new OpenIDConnectSession class.
  $session = new OpenIDConnectSession($this->configFactory, $this->redirectDestination, $this->session, $this->languageManager);

  // Call the saveDestination() method.
  $session
    ->saveDestination();

  // Call the retrieveDestination method.
  $destination = $session
    ->retrieveDestination();

  // Assert the destination matches our expectation.
  $this
    ->assertEquals($destination, [
    'destination' => $expectedDestination,
    'langcode' => 'und',
  ]);
}