class CacheabilityMetadataConfigOverrideIntegrationTest
Same name and namespace in other branches
- 11.x core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php \Drupal\Tests\config\Functional\CacheabilityMetadataConfigOverrideIntegrationTest
- 10 core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php \Drupal\Tests\config\Functional\CacheabilityMetadataConfigOverrideIntegrationTest
- 8.9.x core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php \Drupal\Tests\config\Functional\CacheabilityMetadataConfigOverrideIntegrationTest
Tests if configuration overrides correctly affect cacheability metadata.
@group config
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\config\Functional\CacheabilityMetadataConfigOverrideIntegrationTest uses \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CacheabilityMetadataConfigOverrideIntegrationTest
File
-
core/
modules/ config/ tests/ src/ Functional/ CacheabilityMetadataConfigOverrideIntegrationTest.php, line 13
Namespace
Drupal\Tests\config\FunctionalView source
class CacheabilityMetadataConfigOverrideIntegrationTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'block_test',
'config_override_integration_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// @todo If our block does not contain any content then the cache context
// is not bubbling up and the test fails. Remove this line once the cache
// contexts are properly set. See https://www.drupal.org/node/2529980.
\Drupal::state()->set('block_test.content', 'Needs to have some content');
$this->drupalLogin($this->drupalCreateUser());
}
/**
* Tests if config overrides correctly set cacheability metadata.
*/
public function testConfigOverride() {
// Check the default (disabled) state of the cache context. The block label
// should not be overridden.
$this->drupalGet('<front>');
$this->assertSession()
->pageTextNotContains('Overridden block label');
// Both the cache context and tag should be present.
$this->assertCacheContext('config_override_integration_test');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config_override_integration_test_tag');
// Flip the state of the cache context. The block label should now be
// overridden.
\Drupal::state()->set('config_override_integration_test.enabled', TRUE);
$this->drupalGet('<front>');
$this->assertSession()
->pageTextContains('Overridden block label');
// Both the cache context and tag should still be present.
$this->assertCacheContext('config_override_integration_test');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config_override_integration_test_tag');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.