public function JqueryUiLibraryAssetsTest::testAssetLoadingUnchanged in Drupal 9
Confirms jQuery UI assets load as expected.
Compares the jQuery assets that currently load against a list of the assets that loaded prior to the the deprecation of all remaining core jQuery UI libraries.
While this is similar to testLibraryAssetLoadingOrder(), it is a separate test so it can be run in a test-only context, thus confirming that asset loading is truly unchanged before and after the deprecations.
@dataProvider providerTestAssetLoading
Parameters
string $library: A pipe delimited list of libraries to check.
string[] $expected_css: The jQuery UI CSS files expected to load.
string[] $expected_js: The jQuery UI JavaScript files expected to load.
File
- core/
tests/ Drupal/ FunctionalTests/ Libraries/ JqueryUiLibraryAssetsTest.php, line 308
Class
- JqueryUiLibraryAssetsTest
- Tests the loading of jQuery UI CSS and JS assets.
Namespace
Drupal\FunctionalTests\LibrariesCode
public function testAssetLoadingUnchanged($library, array $expected_css, array $expected_js) {
$this
->drupalGet("jqueryui_library_assets_test/{$library}");
$this
->assertSession()
->statusCodeEquals(200);
// Find all jQuery UI CSS files loaded to the page.
$css = $this
->getSession()
->getPage()
->findAll('css', 'link[href*="jquery.ui"]');
$css_loaded_by_page = [];
foreach ($css as $item) {
$file = $this
->trimFilePath($item
->getAttribute('href'));
$css_loaded_by_page[] = $file;
}
$this
->assertEmpty(array_diff($css_loaded_by_page, $expected_css));
// Find all jQuery UI JavaScript files loaded to the page.
$js = $this
->getSession()
->getPage()
->findAll('css', 'script[src*="jquery.ui"]');
$js_loaded_by_page = [];
foreach ($js as $item) {
$file = $this
->trimFilePath($item
->getAttribute('src'));
$js_loaded_by_page[] = $file;
}
// assertEmpty() is used instead of assertSame() because we can only test
// for the presence of assets, not their loading order. The test is designed
// to pass before and after the jQuery UI asset changes in
// http://drupal.org/node/3113400, which, by necessity, results in loading
// order changes.
$this
->assertEmpty(array_diff($js_loaded_by_page, $expected_js));
}