Skip to content
Snippets Groups Projects
Verified Commit ddb687ea authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3370930 by catch, Amber Himes Matz, kevinquillen, mherchel: Aggregation...

Issue #3370930 by catch, Amber Himes Matz, kevinquillen, mherchel: Aggregation URL hashes should be built from normalized list of libraries

(cherry picked from commit 9a66ffce)
parent 94f26747
No related branches found
No related tags found
21 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4788Issue #3272985: RSS Feed header reverts to text/html when cached,!4716Issue #3362929: Improve 400 responses for broken/invalid image style routes,!4553Draft: Issue #2980951: Permission to see own unpublished comments in comment thread,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!2851Issue #2264739: Allow multiple field widgets to not use tabledrag,!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
......@@ -101,8 +101,18 @@ public function __construct(LibraryDiscoveryInterface $library_discovery, Librar
* loaded, excluding any libraries that have already been loaded.
*/
protected function getLibrariesToLoad(AttachedAssetsInterface $assets) {
// The order of libraries passed in via assets can differ, so to reduce
// variation, first normalize the requested libraries to the minimal
// representative set before then expanding the list to include all
// dependencies.
// @see Drupal\FunctionalTests\Core\Asset\AssetOptimizationTestUmami
// @todo: https://www.drupal.org/project/drupal/issues/1945262
$libraries = $assets->getLibraries();
if ($libraries) {
$libraries = $this->libraryDependencyResolver->getMinimalRepresentativeSubset($libraries);
}
return array_diff(
$this->libraryDependencyResolver->getLibrariesWithDependencies($assets->getLibraries()),
$this->libraryDependencyResolver->getLibrariesWithDependencies($libraries),
$this->libraryDependencyResolver->getLibrariesWithDependencies($assets->getAlreadyLoadedLibraries())
);
}
......
......@@ -56,6 +56,15 @@ public function testAssetAggregation(): void {
$this->doTestAggregation($settings);
}
/**
* Creates a user and requests a page.
*/
protected function requestPage(): void {
$user = $this->createUser();
$this->drupalLogin($user);
$this->drupalGet('');
}
/**
* Helper to test aggregate file URLs.
*
......@@ -73,44 +82,35 @@ protected function doTestAggregation(array $settings): void {
'preprocess' => TRUE,
'gzip' => TRUE,
])->save();
$user = $this->createUser();
$this->drupalLogin($user);
$this->drupalGet('');
$this->requestPage();
$session = $this->getSession();
$page = $session->getPage();
$elements = $page->findAll('xpath', '//link[@rel="stylesheet"]');
$urls = [];
foreach ($elements as $element) {
// Collect all the URLs for all the script and styles prior to making any
// more requests.
$style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]');
$script_elements = $page->findAll('xpath', '//script');
$style_urls = [];
foreach ($style_elements as $element) {
if ($element->hasAttribute('href')) {
$urls[] = $element->getAttribute('href');
$style_urls[] = $element->getAttribute('href');
}
}
foreach ($urls as $url) {
$this->assertAggregate($url);
$script_urls = [];
foreach ($script_elements as $element) {
if ($element->hasAttribute('src')) {
$script_urls[] = $element->getAttribute('src');
}
}
foreach ($urls as $url) {
foreach ($style_urls as $url) {
$this->assertAggregate($url);
$this->assertAggregate($url, FALSE);
}
foreach ($urls as $url) {
$this->assertInvalidAggregates($url);
}
$elements = $page->findAll('xpath', '//script');
$urls = [];
foreach ($elements as $element) {
if ($element->hasAttribute('src')) {
$urls[] = $element->getAttribute('src');
}
}
foreach ($urls as $url) {
foreach ($script_urls as $url) {
$this->assertAggregate($url);
}
foreach ($urls as $url) {
$this->assertAggregate($url, FALSE);
}
foreach ($urls as $url) {
$this->assertInvalidAggregates($url);
}
}
......@@ -125,16 +125,20 @@ protected function doTestAggregation(array $settings): void {
*/
protected function assertAggregate(string $url, bool $from_php = TRUE): void {
$url = $this->getAbsoluteUrl($url);
$this->assertStringContainsString($this->fileAssetsPath, $url);
// Not every script or style on a page is aggregated.
if (!str_contains($url, $this->fileAssetsPath)) {
return;
}
$session = $this->getSession();
$session->visit($url);
$this->assertSession()->statusCodeEquals(200);
$headers = $session->getResponseHeaders();
if ($from_php) {
$this->assertEquals(['no-store, private'], $headers['Cache-Control']);
$this->assertArrayHasKey('X-Generator', $headers);
}
else {
$this->assertArrayNotHasKey('Cache-Control', $headers);
$this->assertArrayNotHasKey('X-Generator', $headers);
}
}
......@@ -147,6 +151,11 @@ protected function assertAggregate(string $url, bool $from_php = TRUE): void {
* @throws \Behat\Mink\Exception\ExpectationException
*/
protected function assertInvalidAggregates(string $url): void {
$url = $this->getAbsoluteUrl($url);
// Not every script or style on a page is aggregated.
if (!str_contains($url, $this->fileAssetsPath)) {
return;
}
$session = $this->getSession();
$session->visit($this->replaceGroupDelta($url));
$this->assertSession()->statusCodeEquals(200);
......
<?php
namespace Drupal\FunctionalTests\Asset;
/**
* Tests asset aggregation with the Umami install profile.
*
* Umami includes several core modules as well as the Claro theme, this
* results in a more complex asset dependency tree to test than the testing
* profile.
*
* @group asset
*/
class AssetOptimizationTestUmami extends AssetOptimizationTest {
/**
* {@inheritdoc}
*/
protected $profile = 'demo_umami';
/**
* {@inheritdoc}
*/
protected function requestPage(): void {
$user = $this->createUser([], NULL, TRUE);
$this->drupalLogin($user);
$this->drupalGet('node/add/article');
}
}
......@@ -92,6 +92,9 @@ protected function setUp(): void {
$this->libraryDependencyResolver->expects($this->any())
->method('getLibrariesWithDependencies')
->willReturnArgument(0);
$this->libraryDependencyResolver->expects($this->any())
->method('getMinimalRepresentativeSubset')
->willReturnArgument(0);
$this->moduleHandler = $this->createMock('\Drupal\Core\Extension\ModuleHandlerInterface');
$this->themeManager = $this->createMock('\Drupal\Core\Theme\ThemeManagerInterface');
$active_theme = $this->getMockBuilder('\Drupal\Core\Theme\ActiveTheme')
......
......@@ -52,12 +52,12 @@ global-styling:
js:
js/checkbox.js: {}
js/navigation-utils.js: {}
dependencies:
- core/drupal
- core/once
- core/tabbable
- olivero/navigation-base
book:
version: VERSION
......@@ -213,6 +213,15 @@ messages:
dependencies:
- olivero/global-styling
navigation-base:
version: VERSION
js:
js/navigation-utils.js: {}
dependencies:
- core/drupal
- core/once
- core/tabbable
navigation-primary:
version: VERSION
css:
......@@ -225,8 +234,7 @@ navigation-primary:
js/second-level-navigation.js: {}
js/nav-resize.js: {}
dependencies:
- core/drupal
- core/once
- olivero/navigation-base
navigation-secondary:
version: VERSION
......@@ -265,6 +273,8 @@ search-wide:
css/components/header-search-wide.css: {}
js:
js/search.js: {}
dependencies:
- olivero/navigation-primary
sidebar:
version: VERSION
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment