You are here

protected function JqueryUiLibraryAssetsTest::setUp in Drupal 10

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

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