class CssCollectionOptimizerUnitTest in Drupal 10
Tests the CSS asset optimizer.
@group Asset
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Asset\CssCollectionOptimizerUnitTest
Expanded class hierarchy of CssCollectionOptimizerUnitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Asset/ CssCollectionOptimizerUnitTest.php, line 18
Namespace
Drupal\Tests\Core\AssetView source
class CssCollectionOptimizerUnitTest extends UnitTestCase {
/**
* The data from the dumper.
*
* @var string
*/
protected $dumperData;
/**
* A CSS Collection optimizer.
*
* @var \Drupal\Core\Asset\AssetCollectionOptimizerInterface
*/
protected $optimizer;
protected function setUp() : void {
parent::setUp();
$mock_grouper = $this
->createMock(AssetCollectionGrouperInterface::class);
$mock_grouper
->method('group')
->willReturnCallback(function ($assets) {
return [
[
'items' => $assets,
'type' => 'file',
'preprocess' => TRUE,
],
];
});
$mock_optimizer = $this
->createMock(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'));
$mock_dumper = $this
->createMock(AssetDumperInterface::class);
$mock_dumper
->method('dump')
->willReturnCallback(function ($css) {
$this->dumperData = $css;
});
$mock_state = $this
->createMock(StateInterface::class);
$mock_file_system = $this
->createMock(FileSystemInterface::class);
$this->optimizer = new CssCollectionOptimizer($mock_grouper, $mock_optimizer, $mock_dumper, $mock_state, $mock_file_system);
}
/**
* Test that css imports with strange letters do not destroy the css output.
*/
public function testCssImport() {
$this->optimizer
->optimize([
'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,
],
'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,
],
]);
self::assertEquals(file_get_contents(__DIR__ . '/css_test_files/css_input_with_import.css.optimized.aggregated.css'), $this->dumperData);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CssCollectionOptimizerUnitTest:: |
protected | property | The data from the dumper. | |
CssCollectionOptimizerUnitTest:: |
protected | property | A CSS Collection optimizer. | |
CssCollectionOptimizerUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CssCollectionOptimizerUnitTest:: |
public | function | Test that css imports with strange letters do not destroy the css output. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |