You are here

protected function SessionHttpsTest::getPathFromLocationHeader in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php \Drupal\Tests\system\Functional\Session\SessionHttpsTest::getPathFromLocationHeader()

Extracts internal path from the location header on the response.

Parameters

\Psr\Http\Message\ResponseInterface $response: The response from logging in.

bool $https: Whether the log in was via HTTPS. Defaults to FALSE.

Return value

string The internal path from the location header on the response.

2 calls to SessionHttpsTest::getPathFromLocationHeader()
SessionHttpsTest::loginHttp in core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php
Log in a user via HTTP.
SessionHttpsTest::loginHttps in core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php
Log in a user via HTTPS.

File

core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php, line 233

Class

SessionHttpsTest
Ensure that when running under HTTPS two session cookies are generated.

Namespace

Drupal\Tests\system\Functional\Session

Code

protected function getPathFromLocationHeader(ResponseInterface $response, $https = FALSE) {
  if ($https) {
    $base_url = str_replace('http://', 'https://', $this->baseUrl);
  }
  else {
    $base_url = str_replace('https://', 'http://', $this->baseUrl);
  }

  // The mock front controllers (http.php and https.php) add the script name
  // to $_SERVER['REQUEST_URI'] and friends. Therefore it is necessary to
  // strip that also.
  $base_url .= '/index.php/';

  // Extract relative path from location header.
  $this
    ->assertSame(303, $response
    ->getStatusCode());
  $location = $response
    ->getHeader('location')[0];
  $this
    ->assertStringStartsWith($base_url, $location, 'Location header contains expected base URL');
  return substr($location, strlen($base_url));
}