You are here

public function DevelToolbarTest::testCacheHeaders in Devel 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/DevelToolbarTest.php \Drupal\Tests\devel\Functional\DevelToolbarTest::testCacheHeaders()
  2. 8.2 tests/src/Functional/DevelToolbarTest.php \Drupal\Tests\devel\Functional\DevelToolbarTest::testCacheHeaders()
  3. 4.x tests/src/Functional/DevelToolbarTest.php \Drupal\Tests\devel\Functional\DevelToolbarTest::testCacheHeaders()

Tests cache metadata headers.

File

tests/src/Functional/DevelToolbarTest.php, line 118

Class

DevelToolbarTest
Tests devel toolbar module functionality.

Namespace

Drupal\Tests\devel\Functional

Code

public function testCacheHeaders() {

  // Disable user toolbar tab so we can test properly if the devel toolbar
  // implementation interferes with the page cacheability.
  \Drupal::service('module_installer')
    ->install([
    'toolbar_disable_user_toolbar',
  ]);

  // The menu is not loaded for users without the adequate permission,
  // so no cache tags for configuration are added.
  $this
    ->drupalLogin($this->toolbarUser);
  $this
    ->assertSession()
    ->responseHeaderNotContains('X-Drupal-Cache-Tags', 'config:devel.toolbar.settings');
  $this
    ->assertSession()
    ->responseHeaderNotContains('X-Drupal-Cache-Tags', 'config:system.menu.devel');

  // Make sure that the configuration cache tags are present for users with
  // the adequate permission.
  $this
    ->drupalLogin($this->develUser);
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Tags', 'config:devel.toolbar.settings');
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.menu.devel');

  // The Devel toolbar implementation should not interfere with the page
  // cacheability, so you expect a MISS value in the X-Drupal-Dynamic-Cache
  // header the first time.
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'MISS');

  // Triggers a page reload and verify that the page is served from the
  // cache.
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'HIT');
}