CookieCacheContextTest.php in Drupal 10
File
core/tests/Drupal/Tests/Core/Cache/Context/CookieCacheContextTest.php
View source
<?php
namespace Drupal\Tests\Core\Cache\Context;
use Drupal\Core\Cache\Context\CookiesCacheContext;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class CookieCacheContextTest extends UnitTestCase {
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);
}
public function providerTestGetContext() {
return [
[
[
'foo' => 1,
'bar' => 2,
'baz' => 3,
],
'foo',
1,
],
[
[
'foo' => 1,
'bar' => 2,
'baz' => 3,
],
NULL,
'bar=2&baz=3&foo=1',
],
];
}
}