function ToolbarCacheContextsTest::assertToolbarCacheContexts

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

Tests that cache contexts are applied for both users.

@internal

Parameters

string[] $cache_contexts: Expected cache contexts for both users.

string $message: (optional) A verbose message to output.

1 call to ToolbarCacheContextsTest::assertToolbarCacheContexts()
ToolbarCacheContextsTest::testToolbarCacheContextsCaller in core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php
Tests toolbar cache contexts.

File

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

Class

ToolbarCacheContextsTest
Tests the cache contexts for toolbar.

Namespace

Drupal\Tests\toolbar\Functional

Code

protected function assertToolbarCacheContexts(array $cache_contexts, ?string $message = NULL) : void {
    // Default cache contexts that should exist on all test cases.
    $default_cache_contexts = [
        'languages:language_interface',
        'theme',
        'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    ];
    $cache_contexts = Cache::mergeContexts($default_cache_contexts, $cache_contexts);
    // Assert contexts for user1 which has only default permissions.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('test-page');
    $this->assertCacheContexts($cache_contexts, $message);
    $this->drupalLogout();
    // Assert contexts for user2 which has some additional permissions.
    $this->drupalLogin($this->adminUser2);
    $this->drupalGet('test-page');
    $this->assertCacheContexts($cache_contexts, $message);
}

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