ProtocolVersionCacheContextTest.php

Same filename and directory in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/Context/ProtocolVersionCacheContextTest.php
  2. 10 core/tests/Drupal/Tests/Core/Cache/Context/ProtocolVersionCacheContextTest.php
  3. 11.x core/tests/Drupal/Tests/Core/Cache/Context/ProtocolVersionCacheContextTest.php

Namespace

Drupal\Tests\Core\Cache\Context

File

core/tests/Drupal/Tests/Core/Cache/Context/ProtocolVersionCacheContextTest.php

View source
<?php

namespace Drupal\Tests\Core\Cache\Context;

use Drupal\Core\Cache\Context\ProtocolVersionCacheContext;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * @coversDefaultClass \Drupal\Core\Cache\Context\ProtocolVersionCacheContext
 * @group Cache
 */
class ProtocolVersionCacheContextTest extends UnitTestCase {
  
  /**
   * @covers ::getContext
   *
   * @dataProvider providerTestGetContext
   */
  public function testGetContext($protocol, $context) {
    $request_stack = new RequestStack();
    $request = Request::create('/');
    $request->server
      ->set('SERVER_PROTOCOL', $protocol);
    $request_stack->push($request);
    $cache_context = new ProtocolVersionCacheContext($request_stack);
    $this->assertSame($cache_context->getContext(), $context);
  }
  
  /**
   * Provides a list of query arguments and expected cache contexts.
   */
  public function providerTestGetContext() {
    return [
      [
        'HTTP/1.0',
        'HTTP/1.0',
      ],
      [
        'HTTP/1.1',
        'HTTP/1.1',
      ],
      [
        'HTTP/2.0',
        'HTTP/2.0',
      ],
      [
        'HTTP/3.0',
        'HTTP/3.0',
      ],
    ];
  }

}

Classes

Title Deprecated Summary
ProtocolVersionCacheContextTest @coversDefaultClass \Drupal\Core\Cache\Context\ProtocolVersionCacheContext[[api-linebreak]] @group Cache

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