You are here

public function HeadersCacheContextTest::testGetContext in Drupal 10

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

@covers ::getContext

@dataProvider providerTestGetContext

File

core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php, line 21

Class

HeadersCacheContextTest
@coversDefaultClass \Drupal\Core\Cache\Context\HeadersCacheContext @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function testGetContext($headers, $header_name, $context) {
  $request_stack = new RequestStack();
  $request = Request::create('/', 'GET');

  // Request defaults could change, so compare with default values instead of
  // passed in context value.
  $request->headers
    ->replace($headers);
  $request_stack
    ->push($request);
  $cache_context = new HeadersCacheContext($request_stack);
  $this
    ->assertSame($cache_context
    ->getContext($header_name), $context);
}