function CssOptimizerUnitTest::testOptimize

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php \Drupal\Tests\Core\Asset\CssOptimizerUnitTest::testOptimize()
  2. 10 core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php \Drupal\Tests\Core\Asset\CssOptimizerUnitTest::testOptimize()
  3. 11.x core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php \Drupal\Tests\Core\Asset\CssOptimizerUnitTest::testOptimize()

Tests optimizing a CSS asset group containing 'type' => 'file'.

@dataProvider providerTestOptimize

File

core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php, line 231

Class

CssOptimizerUnitTest
Tests the CSS asset optimizer.

Namespace

Drupal\Tests\Core\Asset

Code

public function testOptimize($css_asset, $expected) {
    global $base_path;
    $original_base_path = $base_path;
    $base_path = '/';
    // \Drupal\Core\Asset\CssOptimizer::loadFile() relies on the current working
    // directory being the one that is used when index.php is the entry point.
    // Note: PHPUnit automatically restores the original working directory.
    chdir(realpath(__DIR__ . '/../../../../../../'));
    $this->assertEquals($expected, $this->optimizer
        ->optimize($css_asset), 'Group of file CSS assets optimized correctly.');
    $base_path = $original_base_path;
}

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