Loading core/lib/Drupal/Core/Asset/CssCollectionOptimizerLazy.php +8 −1 Original line number Diff line number Diff line Loading @@ -148,8 +148,15 @@ public function optimizeGroup(array $group): string { $data .= "/* @license " . $css_asset['license']['name'] . " " . $css_asset['license']['url'] . " */\n"; } $current_license = $css_asset['license']; // Append this file if already minified; otherwise optimize it. if (isset($css_asset['minified']) && $css_asset['minified']) { $data .= file_get_contents($css_asset['data']); } else { $data .= $this->optimizer->optimize($css_asset); } } // Per the W3C specification at // https://www.w3.org/TR/REC-CSS2/cascade.html#at-import, @import rules must // precede any other style, so we move those to the top. The regular Loading core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerLazyUnitTest.php +36 −0 Original line number Diff line number Diff line Loading @@ -148,4 +148,40 @@ public function testCssLicenseAggregation(): void { self::assertStringEqualsFile(__DIR__ . '/css_test_files/css_license.css.optimized.aggregated.css', $aggregate); } /** * Test that external minified CSS assets do not trigger optimization. * * This ensures that fully external asset groups do not result in a * CssOptimizer exception and are safely ignored. */ public function testExternalMinifiedCssAssetOptimizationIsSkipped(): void { $mock_grouper = $this->createMock(AssetCollectionGrouperInterface::class); $mock_optimizer = $this->createMock(AssetOptimizerInterface::class); $mock_optimizer->expects($this->never())->method('optimize'); $optimizer = new CssCollectionOptimizerLazy( $mock_grouper, $mock_optimizer, $this->createMock(ThemeManagerInterface::class), $this->createMock(LibraryDependencyResolverInterface::class), new RequestStack(), $this->createMock(FileSystemInterface::class), $this->createMock(ConfigFactoryInterface::class), $this->createMock(FileUrlGeneratorInterface::class), $this->createMock(TimeInterface::class), $this->createMock(LanguageManagerInterface::class) ); $optimizer->optimizeGroup([ 'items' => [ [ 'type' => 'external', 'data' => __DIR__ . '/css_test_files/css_external.optimized.aggregated.css', 'license' => FALSE, 'preprocess' => TRUE, 'minified' => TRUE, ], ], ]); } } core/tests/Drupal/Tests/Core/Asset/css_test_files/css_external.optimized.aggregated.css 0 → 100644 +1 −0 Original line number Diff line number Diff line /* Placeholder external CSS file. */ Loading
core/lib/Drupal/Core/Asset/CssCollectionOptimizerLazy.php +8 −1 Original line number Diff line number Diff line Loading @@ -148,8 +148,15 @@ public function optimizeGroup(array $group): string { $data .= "/* @license " . $css_asset['license']['name'] . " " . $css_asset['license']['url'] . " */\n"; } $current_license = $css_asset['license']; // Append this file if already minified; otherwise optimize it. if (isset($css_asset['minified']) && $css_asset['minified']) { $data .= file_get_contents($css_asset['data']); } else { $data .= $this->optimizer->optimize($css_asset); } } // Per the W3C specification at // https://www.w3.org/TR/REC-CSS2/cascade.html#at-import, @import rules must // precede any other style, so we move those to the top. The regular Loading
core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerLazyUnitTest.php +36 −0 Original line number Diff line number Diff line Loading @@ -148,4 +148,40 @@ public function testCssLicenseAggregation(): void { self::assertStringEqualsFile(__DIR__ . '/css_test_files/css_license.css.optimized.aggregated.css', $aggregate); } /** * Test that external minified CSS assets do not trigger optimization. * * This ensures that fully external asset groups do not result in a * CssOptimizer exception and are safely ignored. */ public function testExternalMinifiedCssAssetOptimizationIsSkipped(): void { $mock_grouper = $this->createMock(AssetCollectionGrouperInterface::class); $mock_optimizer = $this->createMock(AssetOptimizerInterface::class); $mock_optimizer->expects($this->never())->method('optimize'); $optimizer = new CssCollectionOptimizerLazy( $mock_grouper, $mock_optimizer, $this->createMock(ThemeManagerInterface::class), $this->createMock(LibraryDependencyResolverInterface::class), new RequestStack(), $this->createMock(FileSystemInterface::class), $this->createMock(ConfigFactoryInterface::class), $this->createMock(FileUrlGeneratorInterface::class), $this->createMock(TimeInterface::class), $this->createMock(LanguageManagerInterface::class) ); $optimizer->optimizeGroup([ 'items' => [ [ 'type' => 'external', 'data' => __DIR__ . '/css_test_files/css_external.optimized.aggregated.css', 'license' => FALSE, 'preprocess' => TRUE, 'minified' => TRUE, ], ], ]); } }
core/tests/Drupal/Tests/Core/Asset/css_test_files/css_external.optimized.aggregated.css 0 → 100644 +1 −0 Original line number Diff line number Diff line /* Placeholder external CSS file. */