function ToolbarCacheContextsTest::testCacheIntegration

Same name in other branches
  1. 8.9.x core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testCacheIntegration()
  2. 10 core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testCacheIntegration()
  3. 11.x core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testCacheIntegration()

Tests toolbar cache integration.

@group legacy

File

core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php, line 71

Class

ToolbarCacheContextsTest
Tests the cache contexts for toolbar.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testCacheIntegration() {
    $this->expectDeprecation('Route requirement _access_rest_csrf is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Use _csrf_request_header_token instead. See https://www.drupal.org/node/2772399');
    $this->installExtraModules([
        'csrf_test',
        'dynamic_page_cache',
    ]);
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('test-page');
    $this->assertSession()
        ->responseHeaderEquals('X-Drupal-Dynamic-Cache', 'MISS');
    $this->assertCacheContexts([
        'session',
        'user',
        'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    ], 'Expected cache contexts found with CSRF token link.');
    $this->drupalGet('test-page');
    $this->assertSession()
        ->responseHeaderEquals('X-Drupal-Dynamic-Cache', 'HIT');
    $this->assertCacheContexts([
        'session',
        'user',
        'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    ], 'Expected cache contexts found with CSRF token link.');
}

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