function CssCollectionOptimizerLazyUnitTest::testCssImport

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerLazyUnitTest.php \Drupal\Tests\Core\Asset\CssCollectionOptimizerLazyUnitTest::testCssImport()
  2. 10 core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerLazyUnitTest.php \Drupal\Tests\Core\Asset\CssCollectionOptimizerLazyUnitTest::testCssImport()

Tests that CSS imports with strange letters do not destroy the CSS output.

File

core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerLazyUnitTest.php, line 57

Class

CssCollectionOptimizerLazyUnitTest
Tests the CSS asset optimizer.

Namespace

Drupal\Tests\Core\Asset

Code

public function testCssImport() : void {
  $mock_grouper = $this->createStub(AssetCollectionGrouperInterface::class);
  $mock_grouper->method('group')
    ->willReturnCallback(function ($assets) : array {
    return [
      [
        'items' => $assets,
        'type' => 'file',
        'preprocess' => TRUE,
      ],
    ];
  });
  $mock_optimizer = $this->createStub(AssetOptimizerInterface::class);
  $mock_optimizer->method('optimize')
    ->willReturn(file_get_contents(__DIR__ . '/css_test_files/css_input_with_import.css.optimized.css'), file_get_contents(__DIR__ . '/css_test_files/css_subfolder/css_input_with_import.css.optimized.css'));
  $optimizer = new CssCollectionOptimizerLazy($mock_grouper, $mock_optimizer, $this->createStub(ThemeManagerInterface::class), $this->createStub(LibraryDependencyResolverInterface::class), new RequestStack(), $this->createStub(FileSystemInterface::class), $this->createStub(ConfigFactoryInterface::class), $this->createStub(FileUrlGeneratorInterface::class), $this->createStub(TimeInterface::class), $this->createStub(LanguageManagerInterface::class));
  $gpl_license = [
    'name' => 'GPL-2.0-or-later',
    'url' => 'https://www.drupal.org/licensing/faq',
    'gpl-compatible' => TRUE,
  ];
  $aggregate = $optimizer->optimizeGroup([
    'items' => [
      'core/modules/system/tests/modules/common_test/common_test_css_import.css' => [
        'type' => 'file',
        'data' => 'core/modules/system/tests/modules/common_test/common_test_css_import.css',
        'preprocess' => TRUE,
        'license' => $gpl_license,
      ],
      'core/modules/system/tests/modules/common_test/common_test_css_import_not_preprocessed.css' => [
        'type' => 'file',
        'data' => 'core/modules/system/tests/modules/common_test/common_test_css_import.css',
        'preprocess' => TRUE,
        'license' => $gpl_license,
      ],
    ],
  ]);
  self::assertStringEqualsFile(__DIR__ . '/css_test_files/css_input_with_import.css.optimized.aggregated.css', $aggregate);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.