Same name in other branches
- 5.0.x tests/src/Kernel/Asset/CssOptimizerUnitTest.php \Drupal\Tests\advagg\Kernel\Asset\CssOptimizerUnitTest
- 8.x-3.x tests/src/Kernel/Asset/CssOptimizerUnitTest.php \Drupal\Tests\advagg\Kernel\Asset\CssOptimizerUnitTest
- 8.x-4.x tests/src/Kernel/Asset/CssOptimizerUnitTest.php \Drupal\Tests\advagg\Kernel\Asset\CssOptimizerUnitTest
Tests the CSS asset optimizer.
@group advagg
Hierarchy
- class \Drupal\Tests\advagg\Kernel\Asset\CssOptimizerUnitTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CssOptimizerUnitTest
Fichier
-
tests/
src/ Kernel/ Asset/ CssOptimizerUnitTest.php, line 12
Namespace
Drupal\Tests\advagg\Kernel\AssetView source
class CssOptimizerUnitTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'advagg',
];
/**
* The Optimizer.
*
* @var \Drupal\advagg\Asset\CssOptimizer
*/
protected $optimizer;
/**
* The directory for comparison/getting CSS files from.
*
* @var string
*/
protected $dir;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig('advagg');
$this->optimizer = \Drupal::service('advagg.optimizer.css');
$this->dir = base_path() . 'modules/contrib/advagg/tests/src/Kernel/Asset/';
}
/**
* Provides data for the url update test.
*/
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',
],
];
}
/**
* Tests the urlUpdate() method.
*
* @param string $file
* The file to test.
* @param string $expected
* The expected url string.
*
* @dataProvider providerTestUrlUpdate
*/
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->assertNotFalse(strstr($replaced_urls, $expected));
}
}
Members
Titre Trier par ordre décroissant | Modifiers | Object type | Résumé |
---|---|---|---|
CssOptimizerUnitTest::$dir | protected | property | The directory for comparison/getting CSS files from. |
CssOptimizerUnitTest::$modules | protected static | property | Modules to enable. |
CssOptimizerUnitTest::$optimizer | protected | property | The Optimizer. |
CssOptimizerUnitTest::providerTestUrlUpdate | public | function | Provides data for the url update test. |
CssOptimizerUnitTest::setUp | protected | function | |
CssOptimizerUnitTest::testUrlUpdate | public | function | Tests the urlUpdate() method. |