function JqueryUiLibraryAssetsTest::testSameAssetSameWeight

Same name and namespace in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Libraries/JqueryUiLibraryAssetsTest.php \Drupal\FunctionalTests\Libraries\JqueryUiLibraryAssetsTest::testSameAssetSameWeight()
  2. 11.x 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 177

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']);
                    }
                }
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.