You are here

public function SessionAuthenticationTest::testBasicAuthSession in Drupal 8

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

Tests if a session can be initiated through basic authentication.

File

core/modules/system/tests/src/Functional/Session/SessionAuthenticationTest.php, line 86

Class

SessionAuthenticationTest
Tests if sessions are correctly handled when a user authenticates.

Namespace

Drupal\Tests\system\Functional\Session

Code

public function testBasicAuthSession() {

  // Set a session value on a request through basic auth.
  $test_value = 'alpaca';
  $response = $this
    ->basicAuthGet('session-test/set-session/' . $test_value, $this->user
    ->getAccountName(), $this->user->pass_raw);
  $this
    ->assertSessionData($response, $test_value);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test that on a subsequent request the session value is still present.
  $response = $this
    ->basicAuthGet('session-test/get-session', $this->user
    ->getAccountName(), $this->user->pass_raw);
  $this
    ->assertSessionData($response, $test_value);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}