You are here

protected function ThemeNotUsingClassyLibraryTest::confirmMatchingAssets in Drupal 8

Confirms that the assets of a copied Classy library match the original's.

Parameters

string $classy_library_name: The name of the Classy library.

array[] $classy_library_data: The Classy library's data.

array[] $theme_copy_of_classy_library: The theme's copy of the Classy library.

string $theme_path: The path to the current theme.

string $type: The asset type, either 'js' or 'css'.

1 call to ThemeNotUsingClassyLibraryTest::confirmMatchingAssets()
ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries in core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
Ensures that a theme is decoupled from Classy libraries.

File

core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php, line 353

Class

ThemeNotUsingClassyLibraryTest
Tests that themes do not depend on Classy libraries.

Namespace

Drupal\KernelTests\Core\Theme

Code

protected function confirmMatchingAssets($classy_library_name, array $classy_library_data, array $theme_copy_of_classy_library, $theme_path, $type) {
  $this
    ->assertArrayHasKey($type, $theme_copy_of_classy_library);
  $theme_assets = [];
  $classy_assets = [];

  // Create arrays of Classy and copied assets with a structure that
  // facilitates easy comparison.
  foreach ($theme_copy_of_classy_library[$type] as $item) {
    $key = str_replace("{$theme_path}/{$type}/classy/", '', $item['data']);
    $theme_assets[$key] = $item;

    // Remove the data key as it's the only one that shouldn't match.
    unset($theme_assets[$key]['data']);
  }
  foreach ($classy_library_data[$type] as $item) {
    $key = str_replace("core/themes/classy/{$type}/", '', $item['data']);
    $classy_assets[$key] = $item;

    // Remove the data key as it's the only one that shouldn't match.
    unset($classy_assets[$key]['data']);
  }
  $this
    ->assertNotEmpty($theme_assets);
  $this
    ->assertNotEmpty($classy_assets);
  $this
    ->assertEmpty(array_diff_key($theme_assets, $classy_assets), "Missing the inclusion of one or more files from classy/{$classy_library_name}.");

  // Confirm the properties of each copied file are identical.
  foreach ($classy_assets as $file => $properties) {
    foreach ($properties as $property => $value) {
      $this
        ->assertEqual($theme_assets[$file][$property], $value, "The copied file: {$file} from classy/{$classy_library_name} has a non-matching property: {$property}");
    }
  }
}