function WriteSafeSessionHandlerTest::testConstructWriteSafeSessionHandlerDisableWriting

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Session/WriteSafeSessionHandlerTest.php \Drupal\Tests\Core\Session\WriteSafeSessionHandlerTest::testConstructWriteSafeSessionHandlerDisableWriting()
  2. 10 core/tests/Drupal/Tests/Core/Session/WriteSafeSessionHandlerTest.php \Drupal\Tests\Core\Session\WriteSafeSessionHandlerTest::testConstructWriteSafeSessionHandlerDisableWriting()
  3. 11.x core/tests/Drupal/Tests/Core/Session/WriteSafeSessionHandlerTest.php \Drupal\Tests\Core\Session\WriteSafeSessionHandlerTest::testConstructWriteSafeSessionHandlerDisableWriting()

Tests creating a WriteSafeSessionHandler with session writing disabled.

@covers ::__construct @covers ::isSessionWritable @covers ::write

File

core/tests/Drupal/Tests/Core/Session/WriteSafeSessionHandlerTest.php, line 73

Class

WriteSafeSessionHandlerTest
Tests <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21WriteSafeSessionHandler.php/class/WriteSafeSessionHandler/8.9.x" title="Wraps the session handler to prevent writes when not necessary or allowed." class="local">\Drupal\Core\Session\WriteSafeSessionHandler</a>.

Namespace

Drupal\Tests\Core\Session

Code

public function testConstructWriteSafeSessionHandlerDisableWriting() {
    $session_id = 'some-id';
    $session_data = 'serialized-session-data';
    // Disable writing upon construction.
    $this->sessionHandler = new WriteSafeSessionHandler($this->wrappedSessionHandler, FALSE);
    $this->assertSame(FALSE, $this->sessionHandler
        ->isSessionWritable());
    $result = $this->sessionHandler
        ->write($session_id, $session_data);
    $this->assertSame(TRUE, $result);
}

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