3 namespace Drupal\config\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Tests if configuration overrides correctly affect cacheability metadata.
12 class CacheabilityMetadataConfigOverrideIntegrationTest extends WebTestBase {
17 public static $modules = [
19 'config_override_integration_test',
25 protected function setUp() {
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');
33 $this->drupalLogin($this->drupalCreateUser());
37 * Tests if config overrides correctly set cacheability metadata.
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');
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');
49 // Flip the state of the cache context. The block label should now be
51 \Drupal::state()->set('config_override_integration_test.enabled', TRUE);
52 $this->drupalGet('<front>');
53 $this->assertText('Overridden block label');
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');