assertToolbarCacheContexts example

$this->assertCacheContexts(['session', 'user', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT], 'Expected cache contexts found with CSRF token link.');
    $this->drupalGet('test-page');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Dynamic-Cache', 'HIT');
    $this->assertCacheContexts(['session', 'user', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT], 'Expected cache contexts found with CSRF token link.');
  }

  /** * Tests toolbar cache contexts. */
  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']);

    
Home | Imprint | This part of the site doesn't use cookies.