function WriteSafeSessionHandlerTest::testConstructWriteSafeSessionHandlerDefaultArgs

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

Tests creating a WriteSafeSessionHandler with default arguments.

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

File

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

Class

WriteSafeSessionHandlerTest
Tests <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21WriteSafeSessionHandler.php/class/WriteSafeSessionHandler/9" 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 testConstructWriteSafeSessionHandlerDefaultArgs() {
    $session_id = 'some-id';
    $session_data = 'serialized-session-data';
    $this->assertTrue($this->sessionHandler
        ->isSessionWritable());
    // Writing should be enabled, return value passed to the caller by default.
    $this->wrappedSessionHandler
        ->expects($this->exactly(2))
        ->method('write')
        ->with($session_id, $session_data)
        ->willReturnOnConsecutiveCalls(TRUE, FALSE);
    $result = $this->sessionHandler
        ->write($session_id, $session_data);
    $this->assertTrue($result);
    $result = $this->sessionHandler
        ->write($session_id, $session_data);
    $this->assertFalse($result);
}

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