You are here

protected function JqueryUiLibraryAssetsTest::setUp in Drupal 9

Overrides BrowserTestBase::setUp

File

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

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 = [
    'drupal.autocomplete',
    'drupal.dialog',
    'jquery.ui',
    'jquery.ui.autocomplete',
    'jquery.ui.button',
    'jquery.ui.dialog',
    'jquery.ui.menu',
    'jquery.ui.mouse',
    'jquery.ui.resizable',
    'jquery.ui.widget',
  ];
  $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 (strpos($file, 'jquery.ui') === FALSE) {
          continue;
        }
        $weight = $asset['weight'];
        $this->weightGroupedAssets["{$weight}"][] = $file;
      }
    }
  }
  $this->weightGroupedAssets = array_map(function ($item) {
    return array_unique($item);
  }, $this->weightGroupedAssets);
  ksort($this->weightGroupedAssets);
}