function WorkspaceSwitcherTest::testToolbarSwitcherDynamicPageCache

Same name in other branches
  1. 10 core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest::testToolbarSwitcherDynamicPageCache()

Tests that the toolbar workspace switcher doesn't disable the page cache.

File

core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php, line 106

Class

WorkspaceSwitcherTest
Tests workspace switching functionality.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testToolbarSwitcherDynamicPageCache() : void {
    $node_type = $this->drupalCreateContentType();
    $node = $this->drupalCreateNode([
        'type' => $node_type->id(),
    ]);
    $this->drupalLogin($this->drupalCreateUser([
        'access toolbar',
        'view any workspace',
    ]));
    $this->drupalGet($node->toUrl());
    $this->assertSession()
        ->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
    // Reload the page, it should be cached now.
    $this->drupalGet($node->toUrl());
    $this->assertSession()
        ->elementExists('css', '.workspaces-toolbar-tab');
    $this->assertSession()
        ->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.