You are here

protected function SessionHttpsTest::loginHttps in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Session/SessionHttpsTest.php \Drupal\system\Tests\Session\SessionHttpsTest::loginHttps()

Log in a user via HTTPS.

Note that the parents $session_id and $loggedInUser is not updated.

1 call to SessionHttpsTest::loginHttps()
SessionHttpsTest::testHttpsSession in core/modules/system/src/Tests/Session/SessionHttpsTest.php

File

core/modules/system/src/Tests/Session/SessionHttpsTest.php, line 149
Contains \Drupal\system\Tests\Session\SessionHttpsTest.

Class

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

Namespace

Drupal\system\Tests\Session

Code

protected function loginHttps(AccountInterface $account) {
  $this
    ->drupalGet('user/login');

  // Alter the form action to submit the login form through https.php, which
  // creates a mock HTTPS request on HTTP test environments.
  $form = $this
    ->xpath('//form[@id="user-login-form"]');
  $form[0]['action'] = $this
    ->httpsUrl('user/login');
  $edit = array(
    'name' => $account
      ->getUsername(),
    'pass' => $account->pass_raw,
  );

  // When posting directly to the HTTP or HTTPS mock front controller, the
  // location header on the returned response is an absolute URL. That URL
  // needs to be converted into a request to the respective mock front
  // controller in order to retrieve the target page. Because the URL in the
  // location header needs to be modified, it is necessary to disable the
  // automatic redirects normally performed by parent::curlExec().
  $maximum_redirects = $this->maximumRedirects;
  $this->maximumRedirects = 0;
  $this
    ->drupalPostForm(NULL, $edit, t('Log in'));
  $this->maximumRedirects = $maximum_redirects;

  // When logging in via the HTTPS mock, the child site will issue a session
  // cookie with the secure attribute set. While this cookie will be stored in
  // the curl handle, it will not be used on subsequent requests via the HTTPS
  // mock, unless when operating in a true HTTPS environment. Therefore it is
  // necessary to manually collect the session cookie and add it to the
  // curlCookies property such that it will be used on subsequent requests via
  // the HTTPS mock.
  $this->curlCookies = array(
    $this->secureSessionName . '=' . $this->cookies[$this->secureSessionName]['value'],
  );

  // Follow the location header.
  $path = $this
    ->getPathFromLocationHeader(TRUE);
  $this
    ->drupalGet($this
    ->httpsUrl($path));
  $this
    ->assertResponse(200);
}