function DevelToolbarTest::testCacheHeaders

Same name in other branches
  1. 4.x tests/src/Functional/DevelToolbarTest.php \Drupal\Tests\devel\Functional\DevelToolbarTest::testCacheHeaders()

Tests cache metadata headers.

File

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

Class

DevelToolbarTest
Tests devel toolbar module functionality.

Namespace

Drupal\Tests\devel\Functional

Code

public function testCacheHeaders() : void {
    // 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);
    // Dont go to the user/n page as thats uncacheable per https://gitlab.com/drupalspoons/devel/-/issues/541#note_2113393769
    $node_type = $this->drupalCreateContentType();
    $node = $this->drupalCreateNode([
        'type' => $node_type->id(),
    ]);
    $this->drupalGet($node->toUrl());
    $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($node->toUrl());
    $this->assertSession()
        ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'HIT');
}