View source
<?php
namespace Drupal\Tests\advagg_css_minify\Kernel\Asset;
use Drupal\KernelTests\KernelTestBase;
class CssMinifierUnitTest extends KernelTestBase {
public static $modules = [
'advagg_css_minify',
];
protected $optimizer;
protected function setUp() {
parent::setUp();
$this
->installConfig('advagg_css_minify');
$this->optimizer = \Drupal::service('advagg.css_minifier');
}
public function testNoMinifier() {
$this
->config('advagg_css_minify.settings')
->set('minifier', 0)
->save();
$file = dirname(__FILE__) . '/css_test_files/css_input_without_import.css';
$contents = file_get_contents($file);
$this
->assertSame($contents, $this->optimizer
->optimize($contents, [], []));
}
public function providerTestMinifyYui() {
$path = 'core/tests/Drupal/Tests/Core/Asset/css_test_files/';
$absolute_path = dirname(__FILE__) . '/css_test_files/';
return [
[
[
'data' => $path . 'css_input_without_import.css',
],
file_get_contents($absolute_path . 'css_input_without_import.css'),
file_get_contents($absolute_path . 'css_input_without_import.css.optimized.css'),
],
[
[
'data' => $path . 'comment_hacks.css',
],
file_get_contents($absolute_path . 'comment_hacks.css'),
file_get_contents($absolute_path . 'comment_hacks.css.optimized.css'),
],
[
[
'data' => $path . 'charset_sameline.css',
],
file_get_contents($absolute_path . 'charset_sameline.css'),
file_get_contents($absolute_path . 'charset.css.optimized.css'),
],
[
[
'data' => $path . 'charset_newline.css',
],
file_get_contents($absolute_path . 'charset_newline.css'),
file_get_contents($absolute_path . 'charset.css.optimized.css'),
],
[
[
'data' => $path . 'css_input_with_bom.css',
],
file_get_contents($absolute_path . 'css_input_with_bom.css'),
'.byte-order-mark-test{content:"☃"}',
],
[
[
'data' => $path . 'css_input_with_charset.css',
],
file_get_contents($absolute_path . 'css_input_with_charset.css'),
'.charset-test{content:"€"}',
],
[
[
'data' => $path . 'css_input_with_bom_and_charset.css',
],
file_get_contents($absolute_path . 'css_input_with_bom_and_charset.css'),
'.byte-order-mark-charset-test{content:"☃"}',
],
[
[
'data' => $path . 'css_input_with_utf16_bom.css',
],
file_get_contents($absolute_path . 'css_input_with_utf16_bom.css'),
'.utf16-byte-order-mark-test{content:"☃"}',
],
[
[
'data' => $path . 'quotes.css',
],
file_get_contents($absolute_path . 'quotes.css'),
file_get_contents($absolute_path . 'quotes.css.optimized.css'),
],
];
}
public function testMinifyYui(array $css_asset, $original, $expected) {
$this
->assertEquals($expected, $this->optimizer
->optimize($original, $css_asset, []));
}
}