function LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings()
  3. 10 core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php \Drupal\KernelTests\Core\Asset\LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings()

Tests libraries-override on drupalSettings.

File

core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php, line 99

Class

LibraryDiscoveryIntegrationTest
Tests the library discovery and library discovery parser.

Namespace

Drupal\KernelTests\Core\Asset

Code

public function testLibrariesOverrideDrupalSettings() : void {
    // Activate test theme that attempts to override drupalSettings.
    $this->activateTheme('test_theme_libraries_override_with_drupal_settings');
    // Assert that drupalSettings cannot be overridden and throws an exception.
    try {
        $this->libraryDiscovery
            ->getLibraryByName('core', 'drupal.ajax');
        $this->fail('Throw Exception when trying to override drupalSettings');
    } catch (InvalidLibrariesOverrideSpecificationException $e) {
        $expected_message = 'drupalSettings may not be overridden in libraries-override. Trying to override core/drupal.ajax/drupalSettings. Use hook_library_info_alter() instead.';
        $this->assertEquals($expected_message, $e->getMessage(), 'Throw Exception when trying to override drupalSettings');
    }
}

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