You are here

protected function ToolbarCacheContextsTest::assertToolbarCacheContexts in Drupal 8

Same name and namespace in other branches
  1. 9 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.

Return value

TRUE if the assertion succeeded, FALSE otherwise.

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 114

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');
  $return = $this
    ->assertCacheContexts($cache_contexts);
  $this
    ->drupalLogout();

  // Assert contexts for user2 which has some additional permissions.
  $this
    ->drupalLogin($this->adminUser2);
  $this
    ->drupalGet('test-page');
  $return = $return && $this
    ->assertCacheContexts($cache_contexts);
  $this
    ->assertTrue($return, $message);
  return $return;
}