function LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings

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

Class

LibraryDiscoveryIntegrationTest
Tests the library discovery and library discovery parser.

Namespace

Drupal\KernelTests\Core\Asset

Code

public function testLibrariesOverrideDrupalSettings() {
    // 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.