function UserAuthenticationTest::testAddCheckToUrlForTrustedRedirectResponseWithFragment

Tests the auth that ends in a redirect from subdomain with a fragment to TLD.

File

core/modules/user/tests/src/Unit/UserAuthenticationTest.php, line 259

Class

UserAuthenticationTest
Tests Drupal\user\UserAuthentication.

Namespace

Drupal\Tests\user\Unit

Code

public function testAddCheckToUrlForTrustedRedirectResponseWithFragment() : void {
  $this->userStorage
    ->expects($this->never())
    ->method('loadByProperties');
  $site_domain = 'site.com';
  $frontend_url = "https://{$site_domain}";
  $backend_url = "https://api.{$site_domain}";
  $request = Request::create($backend_url);
  $response = new TrustedRedirectResponse($frontend_url . '#a_fragment');
  $request_context = $this->createStub(RequestContext::class);
  $request_context->method('getCompleteBaseUrl')
    ->willReturn($backend_url);
  $container = new ContainerBuilder();
  $container->set('router.request_context', $request_context);
  \Drupal::setContainer($container);
  $session_mock = $this->createMock(SessionInterface::class);
  $session_mock->expects($this->once())
    ->method('has')
    ->with('check_logged_in')
    ->willReturn(TRUE);
  $session_mock->expects($this->once())
    ->method('remove')
    ->with('check_logged_in');
  $event = new ResponseEvent($this->createStub(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, $response);
  $request->setSession($session_mock);
  $cookie = new Cookie($this->createStub(SessionConfigurationInterface::class), $this->createStub(Connection::class), $this->createStub(MessengerInterface::class));
  $cookie->addCheckToUrl($event);
  $this->assertSame("{$frontend_url}?check_logged_in=1#a_fragment", $response->getTargetUrl());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.