You are here

public function SessionCacheContextTest::testDifferentContextForDifferentSession in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest::testDifferentContextForDifferentSession()
  2. 10 core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest::testDifferentContextForDifferentSession()

@covers ::getContext

File

core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php, line 68

Class

SessionCacheContextTest
@coversDefaultClass \Drupal\Core\Cache\Context\SessionCacheContext @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function testDifferentContextForDifferentSession() {
  $this->request
    ->setSession($this->session);
  $cache_context = new SessionCacheContext($this->requestStack);
  $session1_id = 'pjH_8aSoofyCDQiuVYXJcbfyr-CPtkUY';
  $this->session
    ->expects($this
    ->at(0))
    ->method('getId')
    ->will($this
    ->returnValue($session1_id));
  $session2_id = 'aSebeZ52bbM6SvADurQP89SFnEpxY6j8';
  $this->session
    ->expects($this
    ->at(1))
    ->method('getId')
    ->will($this
    ->returnValue($session2_id));
  $context1 = $cache_context
    ->getContext();
  $context2 = $cache_context
    ->getContext();
  $this
    ->assertNotEquals($context1, $context2);
  $this
    ->assertStringNotContainsString($session1_id, $context1, 'Session ID not contained in cache context');
  $this
    ->assertStringNotContainsString($session2_id, $context2, 'Session ID not contained in cache context');
}