function CookieCacheContextTest::testGetContext

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

@covers ::getContext

@dataProvider providerTestGetContext

File

core/tests/Drupal/Tests/Core/Cache/Context/CookieCacheContextTest.php, line 23

Class

CookieCacheContextTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21Context%21CookiesCacheContext.php/class/CookiesCacheContext/11.x" title="Defines the CookiesCacheContext service, for &quot;per cookie&quot; caching." class="local">\Drupal\Core\Cache\Context\CookiesCacheContext</a> @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function testGetContext($cookies, $cookie_name, $context) : void {
    $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);
}

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