Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / CacheabilityMetadataConfigOverrideTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config;
4
5 use Drupal\config_override_test\Cache\PirateDayCacheContext;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests if configuration overrides correctly affect cacheability metadata.
10  *
11  * @group config
12  */
13 class CacheabilityMetadataConfigOverrideTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = [
19     'block',
20     'block_content',
21     'config',
22     'config_override_test',
23     'system',
24     'user'
25   ];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32     $this->installEntitySchema('block_content');
33     $this->installConfig(['config_override_test']);
34   }
35
36   /**
37    * Tests if config overrides correctly set cacheability metadata.
38    */
39   public function testConfigOverride() {
40     // It's pirate day today!
41     $GLOBALS['it_is_pirate_day'] = TRUE;
42
43     $config_factory = $this->container->get('config.factory');
44     $config = $config_factory->get('system.theme');
45
46     // Check that we are using the Pirate theme.
47     $theme = $config->get('default');
48     $this->assertEqual('pirate', $theme);
49
50     // Check that the cacheability metadata is correct.
51     $this->assertEqual(['pirate_day'], $config->getCacheContexts());
52     $this->assertEqual(['config:system.theme', 'pirate-day-tag'], $config->getCacheTags());
53     $this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $config->getCacheMaxAge());
54   }
55
56   /**
57    * Tests if config overrides set cacheability metadata on config entities.
58    */
59   public function testConfigEntityOverride() {
60     // It's pirate day today!
61     $GLOBALS['it_is_pirate_day'] = TRUE;
62
63     // Load the User login block and check that its cacheability metadata is
64     // overridden correctly. This verifies that the metadata is correctly
65     // applied to config entities.
66     /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
67     $entity_manager = $this->container->get('entity.manager');
68     $block = $entity_manager->getStorage('block')->load('call_to_action');
69
70     // Check that our call to action message is appealing to filibusters.
71     $this->assertEqual($block->label(), 'Draw yer cutlasses!');
72
73     // Check that the cacheability metadata is correct.
74     $this->assertEqual(['pirate_day'], $block->getCacheContexts());
75     $this->assertEqual(['config:block.block.call_to_action', 'pirate-day-tag'], $block->getCacheTags());
76     $this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block->getCacheMaxAge());
77
78     // Check that duplicating a config entity does not have the original config
79     // entity's cache tag.
80     $this->assertEqual(['config:block.block.', 'pirate-day-tag'], $block->createDuplicate()->getCacheTags());
81
82     // Check that renaming a config entity does not have the original config
83     // entity's cache tag.
84     $block->set('id', 'call_to_looting')->save();
85     $this->assertEqual(['pirate_day'], $block->getCacheContexts());
86     $this->assertEqual(['config:block.block.call_to_looting', 'pirate-day-tag'], $block->getCacheTags());
87     $this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block->getCacheMaxAge());
88   }
89
90 }