You are here

public function ToolbarCacheContextsTest::testToolbarCacheContextsCaller 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::testToolbarCacheContextsCaller()
  2. 10 core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testToolbarCacheContextsCaller()

Tests toolbar cache contexts.

File

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

Class

ToolbarCacheContextsTest
Tests the cache contexts for toolbar.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testToolbarCacheContextsCaller() {

  // Test with default combination and permission to see toolbar.
  $this
    ->assertToolbarCacheContexts([
    'user',
  ], 'Expected cache contexts found for default combination and permission to see toolbar.');

  // Test without user toolbar tab. User module is a required module so we have to
  // manually remove the user toolbar tab.
  $this
    ->installExtraModules([
    'toolbar_disable_user_toolbar',
  ]);
  $this
    ->assertToolbarCacheContexts([
    'user.permissions',
  ], 'Expected cache contexts found without user toolbar tab.');

  // Test with the toolbar and contextual enabled.
  $this
    ->installExtraModules([
    'contextual',
  ]);
  $this->adminUser2 = $this
    ->drupalCreateUser(array_merge($this->perms, [
    'access contextual links',
  ]));
  $this
    ->assertToolbarCacheContexts([
    'user.permissions',
  ], 'Expected cache contexts found with contextual module enabled.');
  \Drupal::service('module_installer')
    ->uninstall([
    'contextual',
  ]);

  // Test with the tour module enabled.
  $this
    ->installExtraModules([
    'tour',
  ]);
  $this->adminUser2 = $this
    ->drupalCreateUser(array_merge($this->perms, [
    'access tour',
  ]));
  $this
    ->assertToolbarCacheContexts([
    'user.permissions',
  ], 'Expected cache contexts found with tour module enabled.');
  \Drupal::service('module_installer')
    ->uninstall([
    'tour',
  ]);
}