function JqueryUiLibraryAssetsTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Libraries/JqueryUiLibraryAssetsTest.php \Drupal\FunctionalTests\Libraries\JqueryUiLibraryAssetsTest::setUp()
  2. 11.x core/tests/Drupal/FunctionalTests/Libraries/JqueryUiLibraryAssetsTest.php \Drupal\FunctionalTests\Libraries\JqueryUiLibraryAssetsTest::setUp()

Overrides BrowserTestBase::setUp

File

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

Class

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

Namespace

Drupal\FunctionalTests\Libraries

Code

protected function setUp() : void {
    parent::setUp();
    $this->libraryDiscovery = $this->container
        ->get('library.discovery');
    $core_libraries = $this->libraryDiscovery
        ->getLibrariesByExtension('core');
    // All the core libraries that use jQuery UI assets.
    $libraries_to_check = [
        'internal.jquery_ui',
        'drupal.autocomplete',
        'drupal.dialog',
    ];
    $this->coreLibrariesWithJqueryUiAssets = array_filter($core_libraries, function ($key) use ($libraries_to_check) {
        return in_array($key, $libraries_to_check);
    }, ARRAY_FILTER_USE_KEY);
    // Loop through the core libraries with jQuery assets to build an array that
    // groups assets by their weight value.
    foreach ($this->coreLibrariesWithJqueryUiAssets as $library) {
        foreach ([
            'js',
            'css',
        ] as $type) {
            foreach ($library[$type] as $asset) {
                $file = $asset['data'];
                if (!str_contains($file, 'jquery.ui')) {
                    continue;
                }
                $weight = $asset['weight'];
                $this->weightGroupedAssets["{$weight}"][] = $file;
            }
        }
    }
    $this->weightGroupedAssets = array_map(function ($item) {
        return array_unique($item);
    }, $this->weightGroupedAssets);
    ksort($this->weightGroupedAssets);
}

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