function WriteSafeSessionHandlerTest::testSetSessionWritable

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

Tests using setSessionWritable to enable/disable session writing.

@covers ::setSessionWritable
@covers ::write

File

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

Class

WriteSafeSessionHandlerTest
Tests \Drupal\Core\Session\WriteSafeSessionHandler.

Namespace

Drupal\Tests\Core\Session

Code

public function testSetSessionWritable() {
  $session_id = 'some-id';
  $session_data = 'serialized-session-data';
  $this->assertSame(TRUE, $this->sessionHandler
    ->isSessionWritable());
  // Disable writing after construction.
  $this->sessionHandler
    ->setSessionWritable(FALSE);
  $this->assertSame(FALSE, $this->sessionHandler
    ->isSessionWritable());
  $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);
  // Enable writing again.
  $this->sessionHandler
    ->setSessionWritable(TRUE);
  $this->assertSame(TRUE, $this->sessionHandler
    ->isSessionWritable());
  // Writing should be enabled, return value passed to the caller by default.
  $this->wrappedSessionHandler
    ->expects($this->at(0))
    ->method('write')
    ->with($session_id, $session_data)
    ->will($this->returnValue(TRUE));
  $this->wrappedSessionHandler
    ->expects($this->at(1))
    ->method('write')
    ->with($session_id, $session_data)
    ->will($this->returnValue(FALSE));
  $result = $this->sessionHandler
    ->write($session_id, $session_data);
  $this->assertSame(TRUE, $result);
  $result = $this->sessionHandler
    ->write($session_id, $session_data);
  $this->assertSame(FALSE, $result);
}

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