You are here

protected function SessionHttpsTest::loginHttp 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::loginHttp()

Log in a user via HTTP.

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

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

File

core/modules/system/src/Tests/Session/SessionHttpsTest.php, line 118
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 loginHttp(AccountInterface $account) {
  $this
    ->drupalGet('user/login');

  // Alter the form action to submit the login form through http.php, which
  // creates a mock HTTP request on HTTPS test environments.
  $form = $this
    ->xpath('//form[@id="user-login-form"]');
  $form[0]['action'] = $this
    ->httpUrl('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;

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