function JqueryUiLibraryAssetsTest::testAssetLoadingUnchanged

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

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 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 302

Class

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

Namespace

Drupal\FunctionalTests\Libraries

Code

public function testAssetLoadingUnchanged($library, array $expected_css, array $expected_js) : void {
    $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));
}

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