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

Issue #3414173 by joelpittet, anybody, nicxvan: Add support for minified external CSS libraries

(cherry picked from commit 8986a105)
parent cf7c02a6
No related branches found
No related tags found
12 merge requests!12812Issue #3527142 by andypost, catch, longwave, xjm: Update Composer and...,!12811Issue #3527142 by andypost, catch, longwave, xjm: Update Composer and...,!12686Draft: Issue #3535330: Assets paths in CSS no longer rewritten when aggregation is enabled,!12661Issue #3255804 by godotislate, longwave, berdir, alexpott, catch, andypost,...,!12660Issue #3255804 by godotislate, longwave, berdir, alexpott, catch, andypost,...,!12618Issue #3522970 by longwave, smustgrave: Remove unused BrowserTestBase::$originalContainer,!12486Resolve #3532360 "Check for session",!12473Issue #3521639 by mstrelan, smustgrave for 11.2,!12462Issue #3523109 by ghost of drupal past, donquixote, nicxvan, dww, larowlan,...,!9103Issue #3150540 by kriboogh: Configuration langcode is forced to site default language,!8811Issue #3129179: Provide some way to rebuild the persistent bundle field map,!7916Remove taxonomy dependency on node module - 11.x
Pipeline #526900 passed
Pipeline: drupal

#526901

    ......@@ -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
    ......
    ......@@ -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,
    ],
    ],
    ]);
    }
    }
    /* Placeholder external CSS file. */
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment