class JsOptimizerUnitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php \Drupal\Tests\Core\Asset\JsOptimizerUnitTest
Tests the JS asset optimizer.
@group Asset
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Asset\JsOptimizerUnitTest
Expanded class hierarchy of JsOptimizerUnitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Asset/ JsOptimizerUnitTest.php, line 18 - Contains \Drupal\Tests\Core\Asset\JsOptimizerUnitTest.
Namespace
Drupal\Tests\Core\AssetView source
class JsOptimizerUnitTest extends UnitTestCase {
/**
* A JS asset optimizer.
*
* @var \Drupal\Core\Asset\JsOptimizer object.
*/
protected $optimizer;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->optimizer = new JsOptimizer();
}
/**
* Provides data for the JS asset cleaning test.
*
* @see \Drupal\Core\Asset\JsOptimizer::clean().
*
* @returns array
* An array of test data.
*/
function providerTestClean() {
$path = dirname(__FILE__) . '/js_test_files/';
return array(
// File. Tests:
// - Stripped sourceMappingURL with comment # syntax.
0 => array(
file_get_contents($path . 'source_mapping_url.min.js'),
file_get_contents($path . 'source_mapping_url.min.js.optimized.js'),
),
// File. Tests:
// - Stripped sourceMappingURL with comment @ syntax.
1 => array(
file_get_contents($path . 'source_mapping_url_old.min.js'),
file_get_contents($path . 'source_mapping_url_old.min.js.optimized.js'),
),
// File. Tests:
// - Stripped sourceURL with comment # syntax.
2 => array(
file_get_contents($path . 'source_url.min.js'),
file_get_contents($path . 'source_url.min.js.optimized.js'),
),
// File. Tests:
// - Stripped sourceURL with comment @ syntax.
3 => array(
file_get_contents($path . 'source_url_old.min.js'),
file_get_contents($path . 'source_url_old.min.js.optimized.js'),
),
);
}
/**
* Tests cleaning of a JS asset group containing 'type' => 'file'.
*
* @dataProvider providerTestClean
*/
function testClean($js_asset, $expected) {
$this
->assertEquals($expected, $this->optimizer
->clean($js_asset));
}
/**
* Provides data for the JS asset optimize test.
*
* @see \Drupal\Core\Asset\JsOptimizer::optimize().
*
* @returns array
* An array of test data.
*/
function providerTestOptimize() {
$path = dirname(__FILE__) . '/js_test_files/';
return array(
0 => array(
array(
'type' => 'file',
'preprocess' => TRUE,
'data' => $path . 'utf8_bom.js',
),
file_get_contents($path . 'utf8_bom.js.optimized.js'),
),
1 => array(
array(
'type' => 'file',
'preprocess' => TRUE,
'data' => $path . 'utf16_bom.js',
),
file_get_contents($path . 'utf16_bom.js.optimized.js'),
),
2 => array(
array(
'type' => 'file',
'preprocess' => TRUE,
'data' => $path . 'latin_9.js',
'attributes' => array(
'charset' => 'ISO-8859-15',
),
),
file_get_contents($path . 'latin_9.js.optimized.js'),
),
);
}
/**
* Tests cleaning of a JS asset group containing 'type' => 'file'.
*
* @dataProvider providerTestOptimize
*/
function testOptimize($js_asset, $expected) {
$this
->assertEquals($expected, $this->optimizer
->optimize($js_asset));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsOptimizerUnitTest:: |
protected | property | A JS asset optimizer. | |
JsOptimizerUnitTest:: |
function | Provides data for the JS asset cleaning test. | ||
JsOptimizerUnitTest:: |
function | Provides data for the JS asset optimize test. | ||
JsOptimizerUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
JsOptimizerUnitTest:: |
function | Tests cleaning of a JS asset group containing 'type' => 'file'. | ||
JsOptimizerUnitTest:: |
function | Tests cleaning of a JS asset group containing 'type' => 'file'. | ||
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |