function CacheabilityMetadataConfigOverrideTest::testConfigOverride

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/CacheabilityMetadataConfigOverrideTest.php \Drupal\KernelTests\Core\Config\CacheabilityMetadataConfigOverrideTest::testConfigOverride()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/CacheabilityMetadataConfigOverrideTest.php \Drupal\KernelTests\Core\Config\CacheabilityMetadataConfigOverrideTest::testConfigOverride()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/CacheabilityMetadataConfigOverrideTest.php \Drupal\KernelTests\Core\Config\CacheabilityMetadataConfigOverrideTest::testConfigOverride()

Tests if config overrides correctly set cacheability metadata.

File

core/tests/Drupal/KernelTests/Core/Config/CacheabilityMetadataConfigOverrideTest.php, line 43

Class

CacheabilityMetadataConfigOverrideTest
Tests if configuration overrides correctly affect cacheability metadata.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigOverride() : void {
    // It's pirate day today!
    $GLOBALS['it_is_pirate_day'] = TRUE;
    $config_factory = $this->container
        ->get('config.factory');
    $config = $config_factory->get('system.theme');
    // Check that we are using the Pirate theme.
    $theme = $config->get('default');
    $this->assertEquals('pirate', $theme);
    // Check that the cacheability metadata is correct.
    $this->assertEquals([
        'pirate_day',
    ], $config->getCacheContexts());
    $this->assertEquals([
        'config:system.theme',
        'pirate-day-tag',
    ], $config->getCacheTags());
    $this->assertEquals(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $config->getCacheMaxAge());
}

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