protected function ToolbarCacheContextsTest::assertToolbarCacheContexts in Drupal 10
Same name and namespace in other branches
- 8 core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::assertToolbarCacheContexts()
- 9 core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::assertToolbarCacheContexts()
Tests that cache contexts are applied for both users.
@internal
Parameters
string[] $cache_contexts: Expected cache contexts for both users.
string $message: (optional) A verbose message to output.
File
- core/
modules/ toolbar/ tests/ src/ Functional/ ToolbarCacheContextsTest.php, line 115
Class
- ToolbarCacheContextsTest
- Tests the cache contexts for toolbar.
Namespace
Drupal\Tests\toolbar\FunctionalCode
protected function assertToolbarCacheContexts(array $cache_contexts, string $message = NULL) : void {
// 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);
}