function HeadersCacheContextTest::testGetContext

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

Class

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

Namespace

Drupal\Tests\Core\Cache\Context

Code

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

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