function FrameworkTest::testLazyLoadOverriddenCSS

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php \Drupal\Tests\system\FunctionalJavascript\FrameworkTest::testLazyLoadOverriddenCSS()
  2. 8.9.x core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php \Drupal\Tests\system\FunctionalJavascript\FrameworkTest::testLazyLoadOverriddenCSS()
  3. 11.x core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php \Drupal\Tests\system\FunctionalJavascript\FrameworkTest::testLazyLoadOverriddenCSS()

Tests that overridden CSS files are not added during lazy load.

File

core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php, line 104

Class

FrameworkTest
Tests the off-canvas dialog functionality.

Namespace

Drupal\Tests\system\FunctionalJavascript

Code

public function testLazyLoadOverriddenCSS() : void {
  // The test_theme throws a few JavaScript errors. Since we're only
  // interested in CSS for this test, we're not letting this test fail on
  // those.
  $this->failOnJavascriptConsoleErrors = FALSE;
  // The test theme overrides js.module.css without an implementation,
  // thereby removing it.
  \Drupal::service('theme_installer')->install([
    'test_theme',
  ]);
  $this->config('system.theme')
    ->set('default', 'test_theme')
    ->save();
  // This gets the form, and does an Ajax submission on it.
  $this->drupalGet('ajax_forms_test_lazy_load_form');
  $page = $this->getSession()
    ->getPage();
  $assert = $this->assertSession();
  $page_load_hash_1 = $this->getSession()
    ->evaluateScript('window.performance.timeOrigin');
  $page->checkField('add_files');
  $page->pressButton('Submit');
  $assert->assertExpectedAjaxRequest(1);
  // Verify that the resulting HTML does not load the overridden CSS file.
  // We add a "?" to the assertion, because drupalSettings may include
  // information about the file; we only really care about whether it appears
  // in a LINK or STYLE tag, for which Drupal always adds a query string for
  // cache control.
  $assert->responseNotContains('js.module.css?');
  $page_load_hash_2 = $this->getSession()
    ->evaluateScript('window.performance.timeOrigin');
  $this->assertSame($page_load_hash_1, $page_load_hash_2, 'Page was not reloaded; AJAX update occurred.');
}

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