You are here

public function StableLibraryOverrideTest::testStableLibraryOverrides in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Theme/StableLibraryOverrideTest.php \Drupal\system\Tests\Theme\StableLibraryOverrideTest::testStableLibraryOverrides()

Ensures that Stable overrides all relevant core library assets.

File

core/modules/system/src/Tests/Theme/StableLibraryOverrideTest.php, line 84
Contains \Drupal\system\Tests\Theme\StableLibraryOverrideTest.

Class

StableLibraryOverrideTest
Tests Stable's library overrides.

Namespace

Drupal\system\Tests\Theme

Code

public function testStableLibraryOverrides() {

  // First get the clean library definitions with no active theme.
  $libraries_before = $this
    ->getAllLibraries();
  $libraries_before = $this
    ->removeVendorAssets($libraries_before);
  $this->themeManager
    ->setActiveTheme($this->themeInitialization
    ->getActiveThemeByName('stable'));
  $this->libraryDiscovery
    ->clearCachedDefinitions();

  // Now get the library definitions with Stable as the active theme.
  $libraries_after = $this
    ->getAllLibraries();
  $libraries_after = $this
    ->removeVendorAssets($libraries_after);
  $root = \Drupal::root();
  foreach ($libraries_before as $extension => $libraries) {
    foreach ($libraries as $library_name => $library) {

      // Allow skipping libraries.
      if (in_array("{$extension}/{$library_name}", $this->librariesToSkip)) {
        continue;
      }
      $library_after = $libraries_after[$extension][$library_name];

      // Check that all the CSS assets are overridden.
      foreach ($library['css'] as $index => $asset) {
        $clean_path = $asset['data'];
        $stable_path = $library_after['css'][$index]['data'];

        // Make core/misc assets look like they are coming from a "core"
        // module.
        $replacements = [
          'core/misc/' => "core/modules/core/css/",
        ];
        $expected_path = strtr($clean_path, $replacements);

        // Adjust the module asset paths to correspond with the Stable folder
        // structure.
        $expected_path = str_replace("core/modules/{$extension}/css/", "core/themes/stable/css/{$extension}/", $expected_path);
        $assert_path = str_replace("core/modules/{$extension}/", '', $clean_path);
        $this
          ->assertEqual($expected_path, $stable_path, "{$assert_path} from the {$extension}/{$library_name} library is overridden in Stable.");
      }
    }
  }
}