public function OpenIdConnectSessionTest::testSaveDestinationUserPath in OpenID Connect / OAuth client 2.x
Same name and namespace in other branches
- 8 tests/src/Unit/OpenIdConnectSessionTest.php \Drupal\Tests\openid_connect\Unit\OpenIdConnectSessionTest::testSaveDestinationUserPath()
 
Test the saveDestination() method with the /user/login path.
File
- tests/
src/ Unit/ OpenIdConnectSessionTest.php, line 137  
Class
- OpenIdConnectSessionTest
 - @coversDefaultClass \Drupal\openid_connect\OpenIDConnectSession @group openid_connect
 
Namespace
Drupal\Tests\openid_connect\UnitCode
public function testSaveDestinationUserPath() : void {
  // Setup our expected results.
  $expectedDestination = 'user';
  $immutableConfig = $this
    ->createMock(ImmutableConfig::class);
  $this->configFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with('openid_connect.settings')
    ->willReturn($immutableConfig);
  // Mock the get method with the user login path.
  $this->redirectDestination
    ->expects($this
    ->once())
    ->method('get')
    ->willReturn(self::TEST_USER_PATH);
  // 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 class to test with.
  $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 expectations.
  $this
    ->assertEquals($destination, [
    'destination' => $expectedDestination,
    'langcode' => 'und',
  ]);
}