function LibraryDiscoveryIntegrationTest::testLibrariesOverride

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverride()
  2. 10 core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverride()
  3. 11.x 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 56

Class

LibraryDiscoveryIntegrationTest
Tests the library discovery and library discovery parser.

Namespace

Drupal\KernelTests\Core\Asset

Code

public function testLibrariesOverride() {
    // Assert some starterkit_theme libraries that will be overridden or
    // removed.
    $this->activateTheme('starterkit_theme');
    $this->assertAssetInLibrary('core/themes/starterkit_theme/css/components/button.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('core/themes/starterkit_theme/css/components/collapse-processed.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('core/themes/starterkit_theme/css/components/container-inline.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('core/themes/starterkit_theme/css/components/details.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('core/themes/starterkit_theme/css/components/dialog.css', 'starterkit_theme', '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->assertEquals($this->libraryDiscovery
        ->getLibraryByName('core', 'drupal.collapse'), $this->libraryDiscovery
        ->getLibraryByName('test_theme', 'collapse'), 'Entire library correctly overridden.');
    // Assert that starterkit_theme library assets were correctly overridden or
    // removed.
    $this->assertNoAssetInLibrary('core/themes/starterkit_theme/css/components/button.css', 'starterkit_theme', 'base', 'css');
    $this->assertNoAssetInLibrary('core/themes/starterkit_theme/css/components/collapse-processed.css', 'starterkit_theme', 'base', 'css');
    $this->assertNoAssetInLibrary('core/themes/starterkit_theme/css/components/container-inline.css', 'starterkit_theme', 'base', 'css');
    $this->assertNoAssetInLibrary('core/themes/starterkit_theme/css/components/details.css', 'starterkit_theme', 'base', 'css');
    $this->assertNoAssetInLibrary('core/themes/starterkit_theme/css/components/dialog.css', 'starterkit_theme', 'dialog', 'css');
    $this->assertAssetInLibrary('core/modules/system/tests/themes/test_theme/css/my-button.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('core/modules/system/tests/themes/test_theme/css/my-collapse-processed.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('themes/my_theme/css/my-container-inline.css', 'starterkit_theme', 'base', 'css');
    $this->assertAssetInLibrary('themes/my_theme/css/my-details.css', 'starterkit_theme', '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']);
            $this->assertSame(-20, $definition['weight'], 'Previous attributes retained');
            break;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.