You are here

public function JqueryUiLibraryAssetsTest::testSameAssetSameWeight in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Libraries/JqueryUiLibraryAssetsTest.php \Drupal\FunctionalTests\Libraries\JqueryUiLibraryAssetsTest::testSameAssetSameWeight()

Confirm that uses of a jQuery UI asset are configured with the same weight.

File

core/tests/Drupal/FunctionalTests/Libraries/JqueryUiLibraryAssetsTest.php, line 169

Class

JqueryUiLibraryAssetsTest
Tests the loading of jQuery UI CSS and JS assets.

Namespace

Drupal\FunctionalTests\Libraries

Code

public function testSameAssetSameWeight() {
  $asset_weights = [];
  $libraries_to_check = $this->coreLibrariesWithJqueryUiAssets;
  foreach ($libraries_to_check as $library) {
    foreach ([
      'js',
      'css',
    ] as $type) {
      foreach ($library[$type] as $asset) {
        $file = $asset['data'];
        if (strpos($file, 'jquery.ui') !== FALSE) {

          // If this is the first time a given file is checked, add the weight
          // value to an array.
          if (!isset($asset_weights[$file])) {
            $asset_weights[$file] = $asset['weight'];
          }
          else {

            // Confirm the weight of the file being loaded matches the weight
            // of when it was loaded by a library that was checked earlier.
            $this
              ->assertEquals($asset_weights[$file], $asset['weight']);
          }
        }
      }
    }
  }
}