Skip to content
Snippets Groups Projects
Commit 16ff3a44 authored by catch's avatar catch
Browse files

Issue #3379220 by kristiaanvandeneynde, smustgrave, Wim Leers:...

Issue #3379220 by kristiaanvandeneynde, smustgrave, Wim Leers: system_page_attachments() varies by authenticated user role but does not add said cache context

(cherry picked from commit abfa5641)
parent 35b420b9
No related branches found
Tags 8.x-1.0 8.x-1.0-alpha8
15 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump
Pipeline #70161 passed
......@@ -672,6 +672,7 @@ function system_page_attachments(array &$page) {
// @see \Drupal\Core\Utility\LinkGenerator::generate()
// @see template_preprocess_links()
// @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter
$page['#cache']['contexts'][] = 'user.roles:authenticated';
if (\Drupal::currentUser()->isAuthenticated()) {
$page['#attached']['library'][] = 'core/drupal.active-link';
}
......
......@@ -130,10 +130,19 @@ protected function assertCacheTags(array $expected_tags, $include_default_tags =
protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) {
if ($include_default_contexts) {
$default_contexts = ['languages:language_interface', 'theme'];
// Add the user.permission context to the list of default contexts except
// when user is already there.
// Add the user based contexts to the list of default contexts except when
// user is already there.
if (!in_array('user', $expected_contexts)) {
$default_contexts[] = 'user.permissions';
if (!in_array('user.roles', $expected_contexts)) {
// The system_page_attachments() hook is only called when dealing with
// the HtmlRenderer, so check the Content-Type header.
// @see \Drupal\Core\Render\MainContent\HtmlRenderer::invokePageAttachmentHooks()
if ($this->getSession()->getResponseHeader('Content-Type') === 'text/html; charset=UTF-8') {
$default_contexts[] = 'user.roles:authenticated';
}
}
}
$expected_contexts = Cache::mergeContexts($expected_contexts, $default_contexts);
}
......
......@@ -322,7 +322,7 @@ public function testReferencedEntity() {
// The default cache contexts for rendered entities.
$default_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
$entity_cache_contexts = Cache::mergeContexts($default_cache_contexts, ['url.site']);
$page_cache_contexts = Cache::mergeContexts($default_cache_contexts, ['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT]);
$page_cache_contexts = Cache::mergeContexts($default_cache_contexts, ['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user.roles:authenticated']);
// Cache tags present on every rendered page.
// 'user.permissions' is a required cache context, and responses that vary
......
......@@ -35,7 +35,7 @@ class RouterTest extends BrowserTestBase {
*/
public function testFinishResponseSubscriber() {
$renderer_required_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
$expected_cache_contexts = Cache::mergeContexts($renderer_required_cache_contexts, ['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT]);
$expected_cache_contexts = Cache::mergeContexts($renderer_required_cache_contexts, ['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user.roles:authenticated']);
sort($expected_cache_contexts);
// Confirm that the router can get to a controller.
......@@ -69,7 +69,7 @@ public function testFinishResponseSubscriber() {
// X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags headers.
// 1. controller result: render array, globally cacheable route access.
$this->drupalGet('router_test/test18');
$expected_cache_contexts = Cache::mergeContexts($renderer_required_cache_contexts, ['url']);
$expected_cache_contexts = Cache::mergeContexts($renderer_required_cache_contexts, ['url', 'user.roles:authenticated']);
sort($expected_cache_contexts);
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Contexts', implode(' ', $expected_cache_contexts));
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'config:user.role.anonymous foo http_response rendered');
......
......@@ -39,6 +39,22 @@ class BrowserTestBaseTest extends BrowserTestBase {
*/
protected $defaultTheme = 'stark';
/**
* Tests that JavaScript Drupal settings can be read.
*/
public function testDrupalSettings() {
// Trigger a 403 because those pages have very little else going on.
$this->drupalGet('admin');
$this->assertSame([], $this->getDrupalSettings());
// Now try the same 403 as an authenticated user and verify that Drupal
// settings do show up.
$account = $this->drupalCreateUser();
$this->drupalLogin($account);
$this->drupalGet('admin');
$this->assertNotSame([], $this->getDrupalSettings());
}
/**
* Tests basic page test.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment