annotate core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php @ 19:fa3358dc1485 tip

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