Skip to content
Snippets Groups Projects
Commit f2daf512 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
parent 5cce3470
No related branches found
No related tags found
30 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8323Fix source code editing and in place front page site studio editing.,!6278Issue #3187770 by godotislate, smustgrave, catch, quietone: Views Rendered...,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #70159 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');
......
......@@ -40,6 +40,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