function CacheabilityMetadataConfigOverrideTest::testConfigEntityOverride

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

Tests if config overrides set cacheability metadata on config entities.

File

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

Class

CacheabilityMetadataConfigOverrideTest
Tests if configuration overrides correctly affect cacheability metadata.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigEntityOverride() : void {
  // It's pirate day today!
  $GLOBALS['it_is_pirate_day'] = TRUE;
  // Load the User login block and check that its cacheability metadata is
  // overridden correctly. This verifies that the metadata is correctly
  // applied to config entities.
  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $block = $entity_type_manager->getStorage('block')
    ->load('call_to_action');
  // Check that our call to action message is appealing to filibusters.
  $this->assertEquals('Draw yer cutlasses!', $block->label());
  // Check that the cacheability metadata is correct.
  $this->assertEquals([
    'pirate_day',
  ], $block->getCacheContexts());
  $this->assertEquals([
    'config:block_list',
    'pirate-day-tag',
  ], $block->getCacheTags());
  $this->assertEquals(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block->getCacheMaxAge());
}

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