function ToolbarCacheContextsTest::testToolbarCacheContextsCaller
Tests toolbar cache contexts.
File
- 
              core/modules/ toolbar/ tests/ src/ Functional/ ToolbarCacheContextsTest.php, line 86 
Class
- ToolbarCacheContextsTest
- Tests the cache contexts for toolbar.
Namespace
Drupal\Tests\toolbar\FunctionalCode
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',
  ]);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
