protected function ToolbarCacheContextsTest::assertToolbarCacheContexts in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/toolbar/src/Tests/ToolbarCacheContextsTest.php \Drupal\toolbar\Tests\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/ src/ Tests/ ToolbarCacheContextsTest.php - Tests toolbar cache contexts.
File
- core/
modules/ toolbar/ src/ Tests/ ToolbarCacheContextsTest.php, line 108 - Contains \Drupal\toolbar\Tests\ToolbarCacheContextsTest.
Class
- ToolbarCacheContextsTest
- Tests the cache contexts for toolbar.
Namespace
Drupal\toolbar\TestsCode
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);
if ($return) {
$this
->pass($message);
}
else {
$this
->fail($message);
}
return $return;
}