You are here

public function SessionTest::testSessionBag in Drupal 9

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

Tests session bag.

File

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

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);
}