You are here

public function SessionTest::testSessionBag in Drupal 8

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

Test session bag.

File

core/modules/system/tests/src/Functional/Session/SessionTest.php, line 310

Class

SessionTest
Drupal session handling tests.

Namespace

Drupal\Tests\system\Functional\Session

Code

public function testSessionBag() {

  // Ensure the flag is absent to start with.
  $this
    ->drupalGet('/session-test/has-bag-flag');
  $this
    ->assertSessionCookie(FALSE);
  $this
    ->assertSessionEmpty(TRUE);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Set the flag.
  $this
    ->drupalGet('/session-test/set-bag-flag');
  $this
    ->assertSessionCookie(TRUE);
  $this
    ->assertSessionEmpty(TRUE);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Ensure the flag is set.
  $this
    ->drupalGet('/session-test/has-bag-flag');
  $this
    ->assertSessionCookie(TRUE);
  $this
    ->assertSessionEmpty(FALSE);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Clear the flag.
  $this
    ->drupalGet('/session-test/clear-bag-flag');
  $this
    ->assertSessionCookie(FALSE);
  $this
    ->assertSessionEmpty(FALSE);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Ensure the flag is absent again.
  $this
    ->drupalGet('/session-test/has-bag-flag');
  $this
    ->assertSessionCookie(FALSE);
  $this
    ->assertSessionEmpty(TRUE);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}