Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / config / tests / src / Functional / CacheabilityMetadataConfigOverrideIntegrationTest.php
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests if configuration overrides correctly affect cacheability metadata.
10  *
11  * @group config
12  */
13 class CacheabilityMetadataConfigOverrideIntegrationTest extends BrowserTestBase {
14
15   use AssertPageCacheContextsAndTagsTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = [
21     'block_test',
22     'config_override_integration_test',
23   ];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30
31     // @todo If our block does not contain any content then the cache context
32     //   is not bubbling up and the test fails. Remove this line once the cache
33     //   contexts are properly set. See https://www.drupal.org/node/2529980.
34     \Drupal::state()->set('block_test.content', 'Needs to have some content');
35
36     $this->drupalLogin($this->drupalCreateUser());
37   }
38
39   /**
40    * Tests if config overrides correctly set cacheability metadata.
41    */
42   public function testConfigOverride() {
43     // Check the default (disabled) state of the cache context. The block label
44     // should not be overridden.
45     $this->drupalGet('<front>');
46     $this->assertNoText('Overridden block label');
47
48     // Both the cache context and tag should be present.
49     $this->assertCacheContext('config_override_integration_test');
50     $this->assertCacheTag('config_override_integration_test_tag');
51
52     // Flip the state of the cache context. The block label should now be
53     // overridden.
54     \Drupal::state()->set('config_override_integration_test.enabled', TRUE);
55     $this->drupalGet('<front>');
56     $this->assertText('Overridden block label');
57
58     // Both the cache context and tag should still be present.
59     $this->assertCacheContext('config_override_integration_test');
60     $this->assertCacheTag('config_override_integration_test_tag');
61   }
62
63 }