AjaxTest.php

Same filename in this branch
  1. main core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
Same filename and directory in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
  3. 9 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
  4. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php
  5. 11.x core/themes/olivero/tests/src/FunctionalJavascript/AjaxTest.php

Namespace

Drupal\Tests\olivero\FunctionalJavascript

File

core/themes/olivero/tests/src/FunctionalJavascript/AjaxTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\olivero\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests AJAX responses.
 */
class AjaxTest extends WebDriverTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'ajax_test',
    'ajax_forms_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'olivero';
  
  /**
   * Tests that Ajax errors are visible in the UI.
   */
  public function testUiAjaxException() : void {
    $this->drupalGet('ajax-test/exception-link');
    $page = $this->getSession()
      ->getPage();
    // We don't want the test to error out because of an expected Javascript
    // console error.
    $this->failOnJavascriptConsoleErrors = FALSE;
    // Click on the AJAX link.
    $this->clickLink('Ajax Exception');
    $this->assertSession()
      ->statusMessageContainsAfterWait("Oops, something went wrong. Check your browser's developer console for more details.", 'error');
    // Check that the message can be closed.
    $this->click('.messages__close');
    $this->assertTrue($page->find('css', '.messages--error')
      ->hasClass('hidden'));
    // 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");
  }

}

Classes

Title Deprecated Summary
AjaxTest Tests AJAX responses.

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