You are here

public function ThemeTest::testThemeSettingsRenderCacheClear in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testThemeSettingsRenderCacheClear()

Tests the 'rendered' cache tag is cleared when saving theme settings.

File

core/modules/system/tests/src/Functional/System/ThemeTest.php, line 257

Class

ThemeTest
Tests the theme interface functionality by enabling and switching themes, and using an administration theme.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testThemeSettingsRenderCacheClear() {
  $this->container
    ->get('theme_installer')
    ->install([
    'bartik',
  ]);

  // Ensure the frontpage is cached for anonymous users. The render cache will
  // cleared by installing a theme.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', 'MISS');
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', 'HIT');
  $this
    ->drupalLogin($this->adminUser);

  // Save Bartik's theme settings which should invalidate the 'rendered' cache
  // tag in \Drupal\system\EventSubscriber\ConfigCacheTag.
  $this
    ->drupalGet('admin/appearance/settings/bartik');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Drupal-Cache', 'MISS');
}