function CookieCacheContextTest::testGetContext

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

Tests get context.

@legacy-covers ::getContext

Attributes

#[DataProvider('providerTestGetContext')]

File

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

Class

CookieCacheContextTest
Tests Drupal\Core\Cache\Context\CookiesCacheContext.

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.