Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Cache / Context / HeadersCacheContextTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Cache\Context;
4
5 use Drupal\Core\Cache\Context\HeadersCacheContext;
6 use Drupal\Tests\UnitTestCase;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpFoundation\RequestStack;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\Cache\Context\HeadersCacheContext
12  * @group Cache
13  */
14 class HeadersCacheContextTest extends UnitTestCase {
15
16   /**
17    * @covers ::getContext
18    *
19    * @dataProvider providerTestGetContext
20    */
21   public function testGetContext($headers, $header_name, $context) {
22     $request_stack = new RequestStack();
23     $request = Request::create('/', 'GET');
24     // Request defaults could change, so compare with default values instead of
25     // passed in context value.
26     $request->headers->replace($headers);
27     $request_stack->push($request);
28     $cache_context = new HeadersCacheContext($request_stack);
29     $this->assertSame($cache_context->getContext($header_name), $context);
30   }
31
32   /**
33    * Provides a list of headers and expected cache contexts.
34    */
35   public function providerTestGetContext() {
36     return [
37       [[], NULL, ''],
38       [[], 'foo', ''],
39       // Non-empty headers.
40       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], NULL, 'alpaca=&llama=rocks&panda=drools&z=0'],
41       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'llama', 'rocks'],
42       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'alpaca', '?valueless?'],
43       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'panda', 'drools'],
44       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'z', '0'],
45       [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', ''],
46       // Header value could be an array.
47       [['z' => ['0', '1']], NULL, 'z=0,1'],
48       // Values are sorted to minimize cache variations.
49       [['z' => ['1', '0'], 'a' => []], NULL, 'a=&z=0,1'],
50       [['a' => [], 'z' => ['1', '0']], NULL, 'a=&z=0,1'],
51     ];
52   }
53
54 }