function CookieCacheContextTest::testGetContext

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Cache/Context/CookieCacheContextTest.php \Drupal\Tests\Core\Cache\Context\CookieCacheContextTest::testGetContext()
  2. 11.x 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 21

Class

CookieCacheContextTest
@coversDefaultClass \Drupal\Core\Cache\Context\CookiesCacheContext @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

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);
}

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