class CookieCacheContextTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Cache/Context/CookieCacheContextTest.php \Drupal\Tests\Core\Cache\Context\CookieCacheContextTest
- 10 core/tests/Drupal/Tests/Core/Cache/Context/CookieCacheContextTest.php \Drupal\Tests\Core\Cache\Context\CookieCacheContextTest
@coversDefaultClass \Drupal\Core\Cache\Context\CookiesCacheContext
@group Cache
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Cache\Context\CookieCacheContextTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of CookieCacheContextTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ CookieCacheContextTest.php, line 14
Namespace
Drupal\Tests\Core\Cache\ContextView source
class CookieCacheContextTest extends UnitTestCase {
/**
* @covers ::getContext
*
* @dataProvider providerTestGetContext
*/
public function testGetContext($cookies, $cookie_name, $context) {
$request_stack = new RequestStack();
$request = Request::create('/', 'GET');
foreach ($cookies as $cookie => $value) {
$request->cookies
->set($cookie, $value);
}
$request_stack->push($request);
$cache_context = new CookiesCacheContext($request_stack);
$this->assertSame($cache_context->getContext($cookie_name), $context);
}
/**
* Provides a list of cookies and expected cache contexts.
*/
public function providerTestGetContext() {
return [
[
[
'foo' => 1,
'bar' => 2,
'baz' => 3,
],
'foo',
1,
],
// Context is ordered by cookie name.
[
[
'foo' => 1,
'bar' => 2,
'baz' => 3,
],
NULL,
'bar=2&baz=3&foo=1',
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.