You are here

public function CacheContextsManagerTest::testOptimizeTokens in Drupal 10

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

@covers ::optimizeTokens

@dataProvider providerTestOptimizeTokens

File

core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php, line 29
Contains \Drupal\Tests\Core\Cache\Context\CacheContextsManagerTest.

Class

CacheContextsManagerTest
@coversDefaultClass \Drupal\Core\Cache\Context\CacheContextsManager @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function testOptimizeTokens(array $context_tokens, array $optimized_context_tokens) {
  $container = $this
    ->getMockBuilder('Drupal\\Core\\DependencyInjection\\Container')
    ->disableOriginalConstructor()
    ->getMock();
  $container
    ->expects($this
    ->any())
    ->method('get')
    ->willReturnMap([
    [
      'cache_context.a',
      Container::EXCEPTION_ON_INVALID_REFERENCE,
      new FooCacheContext(),
    ],
    [
      'cache_context.a.b',
      Container::EXCEPTION_ON_INVALID_REFERENCE,
      new FooCacheContext(),
    ],
    [
      'cache_context.a.b.c',
      Container::EXCEPTION_ON_INVALID_REFERENCE,
      new BazCacheContext(),
    ],
    [
      'cache_context.x',
      Container::EXCEPTION_ON_INVALID_REFERENCE,
      new BazCacheContext(),
    ],
    [
      'cache_context.a.b.no-optimize',
      Container::EXCEPTION_ON_INVALID_REFERENCE,
      new NoOptimizeCacheContext(),
    ],
  ]);
  $cache_contexts_manager = new CacheContextsManager($container, $this
    ->getContextsFixture());
  $this
    ->assertSame($optimized_context_tokens, $cache_contexts_manager
    ->optimizeTokens($context_tokens));
}