public function CacheabilityMetadataConfigOverrideTest::testConfigEntityOverride in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideTest.php \Drupal\config\Tests\CacheabilityMetadataConfigOverrideTest::testConfigEntityOverride()
Tests if config overrides set cacheability metadata on config entities.
File
- core/
modules/ config/ src/ Tests/ CacheabilityMetadataConfigOverrideTest.php, line 64 - Contains \Drupal\config\Tests\CacheabilityMetadataConfigOverrideTest.
Class
- CacheabilityMetadataConfigOverrideTest
- Tests if configuration overrides correctly affect cacheability metadata.
Namespace
Drupal\config\TestsCode
public function testConfigEntityOverride() {
// 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 EntityManagerInterface $entity_manager */
$entity_manager = $this->container
->get('entity.manager');
$block = $entity_manager
->getStorage('block')
->load('call_to_action');
// Check that our call to action message is appealing to filibusters.
$this
->assertEqual($block
->label(), 'Draw yer cutlasses!');
// Check that the cacheability metadata is correct.
$this
->assertEqual([
'pirate_day',
], $block
->getCacheContexts());
$this
->assertEqual([
'config:block.block.call_to_action',
'pirate-day-tag',
], $block
->getCacheTags());
$this
->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block
->getCacheMaxAge());
// Check that duplicating a config entity does not have the original config
// entity's cache tag.
$this
->assertEqual([
'config:block.block.',
'pirate-day-tag',
], $block
->createDuplicate()
->getCacheTags());
// Check that renaming a config entity does not have the original config
// entity's cache tag.
$block
->set('id', 'call_to_looting')
->save();
$this
->assertEqual([
'pirate_day',
], $block
->getCacheContexts());
$this
->assertEqual([
'config:block.block.call_to_looting',
'pirate-day-tag',
], $block
->getCacheTags());
$this
->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block
->getCacheMaxAge());
}