You are here

protected function ToolbarCacheContextsTest::assertToolbarCacheContexts in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::assertToolbarCacheContexts()

Tests that cache contexts are applied for both users.

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 111

Class

ToolbarCacheContextsTest
Tests the cache contexts for toolbar.

Namespace

Drupal\Tests\toolbar\Functional

Code

protected function assertToolbarCacheContexts(array $cache_contexts, $message = NULL) {

  // 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);
}