function CacheContextsManagerTest::testOptimizeTokens

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

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) : void {
    $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));
}

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