function BrowserTestBaseTest::testSessionOnRequest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testSessionOnRequest()

Tests that a usable session is on the request in test-runner.

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 560

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

public function testSessionOnRequest() : void {
  /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
  $session = $this->container
    ->get('request_stack')
    ->getSession();
  $session->set('some-val', 'do-not-cleanup');
  $this->assertEquals('do-not-cleanup', $session->get('some-val'));
  $session->set('some-other-val', 'do-cleanup');
  $this->assertEquals('do-cleanup', $session->remove('some-other-val'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.