class SessionCacheContextTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest
- 8.9.x core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest
- 11.x core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest
@coversDefaultClass \Drupal\Core\Cache\Context\SessionCacheContext @group Cache
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of SessionCacheContextTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ SessionCacheContextTest.php, line 16
Namespace
Drupal\Tests\Core\Cache\ContextView source
class SessionCacheContextTest extends UnitTestCase {
/**
* The request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The session object.
*
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $session;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->request = new Request();
$this->requestStack = new RequestStack();
$this->requestStack
->push($this->request);
$this->session = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\SessionInterface')
->getMock();
}
/**
* @covers ::getContext
*/
public function testSameContextForSameSession() : void {
$this->request
->setSession($this->session);
$cache_context = new SessionCacheContext($this->requestStack);
// cspell:disable-next-line
$session_id = 'aSebeZ52bbM6SvADurQP89SFnEpxY6j8';
$this->session
->expects($this->exactly(2))
->method('getId')
->willReturn($session_id);
$context1 = $cache_context->getContext();
$context2 = $cache_context->getContext();
$this->assertSame($context1, $context2);
$this->assertStringNotContainsString($session_id, $context1, 'Session ID not contained in cache context');
}
/**
* @covers ::getContext
*/
public function testDifferentContextForDifferentSession() : void {
$this->request
->setSession($this->session);
$cache_context = new SessionCacheContext($this->requestStack);
// cspell:disable-next-line
$session1_id = 'pjH_8aSoofyCDQiuVYXJcbfyr-CPtkUY';
// cspell:disable-next-line
$session2_id = 'aSebeZ52bbM6SvADurQP89SFnEpxY6j8';
$this->session
->expects($this->exactly(2))
->method('getId')
->willReturnOnConsecutiveCalls($session1_id, $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');
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
SessionCacheContextTest::$request | protected | property | The request. | |||
SessionCacheContextTest::$requestStack | protected | property | The request stack. | |||
SessionCacheContextTest::$session | protected | property | The session object. | |||
SessionCacheContextTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
SessionCacheContextTest::testDifferentContextForDifferentSession | public | function | @covers ::getContext | |||
SessionCacheContextTest::testSameContextForSameSession | public | function | @covers ::getContext | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.