You are here

public function CacheabilityMetadataConfigOverrideTest::testConfigOverride in Drupal 8

Same name and namespace in other branches
  1. 9 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 40

Class

CacheabilityMetadataConfigOverrideTest
Tests if configuration overrides correctly affect cacheability metadata.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigOverride() {

  // 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
    ->assertEqual('pirate', $theme);

  // Check that the cacheability metadata is correct.
  $this
    ->assertEqual([
    'pirate_day',
  ], $config
    ->getCacheContexts());
  $this
    ->assertEqual([
    'config:system.theme',
    'pirate-day-tag',
  ], $config
    ->getCacheTags());
  $this
    ->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $config
    ->getCacheMaxAge());
}