function AjaxTest::testPropertyUrl

Same name and namespace in other branches
  1. main core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxTest::testPropertyUrl()

Tests URLs that are also a JS object property are not mistakenly trusted.

File

core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php, line 375

Class

AjaxTest
Tests AJAX responses.

Namespace

Drupal\FunctionalJavascriptTests\Ajax

Code

public function testPropertyUrl() : void {
  $this->drupalGet('ajax-test/property-link');
  $this->clickLink('Ajax constructor');
  // The AJAX request should fail because the URL is not trusted.
  $this->failOnJavascriptConsoleErrors = FALSE;
  $this->assertSession()
    ->statusMessageContainsAfterWait("Oops, something went wrong. Check your browser's developer console for more details.", 'error');
  // This is needed to avoid an unfinished AJAX request error from tearDown()
  // because this test intentionally does not complete all AJAX requests.
  $this->getSession()
    ->executeScript("delete window.drupalActiveXhrCount");
}

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