public function LibraryDiscoveryIntegrationTest::testLibrariesOverride in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverride()
- 10 core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverride()
Tests that libraries-override are applied to library definitions.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Asset/ LibraryDiscoveryIntegrationTest.php, line 50
Class
- LibraryDiscoveryIntegrationTest
- Tests the library discovery and library discovery parser.
Namespace
Drupal\KernelTests\Core\AssetCode
public function testLibrariesOverride() {
// Assert some classy libraries that will be overridden or removed.
$this
->activateTheme('classy');
$this
->assertAssetInLibrary('core/themes/classy/css/components/button.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('core/themes/classy/css/components/collapse-processed.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('core/themes/classy/css/components/container-inline.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('core/themes/classy/css/components/details.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('core/themes/classy/css/components/dialog.css', 'classy', 'dialog', 'css');
// Confirmatory assert on core library to be removed.
$this
->assertNotEmpty($this->libraryDiscovery
->getLibraryByName('core', 'drupal.progress'), 'Confirmatory test on "core/drupal.progress"');
// Activate test theme that defines libraries overrides.
$this
->activateTheme('test_theme');
// Assert that entire library was correctly overridden.
$this
->assertEqual($this->libraryDiscovery
->getLibraryByName('core', 'drupal.collapse'), $this->libraryDiscovery
->getLibraryByName('test_theme', 'collapse'), 'Entire library correctly overridden.');
// Assert that classy library assets were correctly overridden or removed.
$this
->assertNoAssetInLibrary('core/themes/classy/css/components/button.css', 'classy', 'base', 'css');
$this
->assertNoAssetInLibrary('core/themes/classy/css/components/collapse-processed.css', 'classy', 'base', 'css');
$this
->assertNoAssetInLibrary('core/themes/classy/css/components/container-inline.css', 'classy', 'base', 'css');
$this
->assertNoAssetInLibrary('core/themes/classy/css/components/details.css', 'classy', 'base', 'css');
$this
->assertNoAssetInLibrary('core/themes/classy/css/components/dialog.css', 'classy', 'dialog', 'css');
$this
->assertAssetInLibrary('core/modules/system/tests/themes/test_theme/css/my-button.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('core/modules/system/tests/themes/test_theme/css/my-collapse-processed.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('themes/my_theme/css/my-container-inline.css', 'classy', 'base', 'css');
$this
->assertAssetInLibrary('themes/my_theme/css/my-details.css', 'classy', 'base', 'css');
// Assert that entire library was correctly removed.
$this
->assertFalse($this->libraryDiscovery
->getLibraryByName('core', 'drupal.progress'), 'Entire library correctly removed.');
// Assert that overridden library asset still retains attributes.
$library = $this->libraryDiscovery
->getLibraryByName('core', 'jquery');
foreach ($library['js'] as $definition) {
if ($definition['data'] == 'core/modules/system/tests/themes/test_theme/js/collapse.js') {
$this
->assertTrue($definition['minified'] && $definition['weight'] == -20, 'Previous attributes retained');
break;
}
}
}