3 namespace Drupal\Tests\config\Functional;
5 use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests if configuration overrides correctly affect cacheability metadata.
13 class CacheabilityMetadataConfigOverrideIntegrationTest extends BrowserTestBase {
15 use AssertPageCacheContextsAndTagsTrait;
20 public static $modules = [
22 'config_override_integration_test',
28 protected function setUp() {
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');
36 $this->drupalLogin($this->drupalCreateUser());
40 * Tests if config overrides correctly set cacheability metadata.
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');
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');
52 // Flip the state of the cache context. The block label should now be
54 \Drupal::state()->set('config_override_integration_test.enabled', TRUE);
55 $this->drupalGet('<front>');
56 $this->assertText('Overridden block label');
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');