You are here

public function LibraryDiscoveryIntegrationTest::testLibrariesOverrideDrupalSettings in Drupal 8

Same name and namespace in other branches
  1. 9 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()

Tests libraries-override on drupalSettings.

File

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

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
      ->assertEqual($e
      ->getMessage(), $expected_message, 'Throw Exception when trying to override drupalSettings');
  }
}