CssOptimizerUnitTest.php in Advanced CSS/JS Aggregation 8.3
File
tests/src/Kernel/Asset/CssOptimizerUnitTest.php
View source
<?php
namespace Drupal\Tests\advagg\Kernel\Asset;
use Drupal\KernelTests\KernelTestBase;
class CssOptimizerUnitTest extends KernelTestBase {
public static $modules = [
'advagg',
];
protected $optimizer;
protected $dir;
protected function setUp() {
parent::setUp();
$this
->installConfig('advagg');
$this->optimizer = \Drupal::service('advagg.optimizer.css');
$this->dir = base_path() . 'modules/contrib/advagg/tests/src/Kernel/Asset/';
}
public function providerTestUrlUpdate() {
return [
[
'url_test_same_dir.css',
$this->dir . 'css_test_files/icon-foo.svg',
],
[
'url_test_child_dir.css',
$this->dir . 'css_test_files/images/icon-foo.svg',
],
[
'url_test_parent_dir.css',
$this->dir . 'css_test_files/../images/icon-foo.svg',
],
];
}
public function testUrlUpdate($file, $expected) {
$path = $this->dir . 'css_test_files/' . $file;
$absolute_path = dirname(__FILE__) . '/css_test_files/';
$contents = file_get_contents($absolute_path . $file);
$replaced_urls = $this->optimizer
->updateUrls($contents, $path);
$this
->assertTrue(strstr($replaced_urls, $expected));
}
}