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