3 namespace Drupal\FunctionalJavascriptTests\Ajax;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8 * Various tests of AJAX behavior.
12 class ElementValidationTest extends WebDriverTestBase {
17 public static $modules = ['ajax_test', 'ajax_forms_test'];
20 * Tries to post an Ajax change to a form that has a validated element.
22 * Drupal AJAX commands update the DOM echoing back the validated values in
23 * the form of messages that appear on the page.
25 public function testAjaxElementValidation() {
26 $this->drupalGet('ajax_validation_test');
27 $page = $this->getSession()->getPage();
28 $assert = $this->assertSession();
30 // Partially complete the form with a string.
31 $page->fillField('drivertext', 'some dumb text');
32 // Move focus away from this field to trigger AJAX.
33 $page->findField('spare_required_field')->focus();
35 // When the AJAX command updates the DOM a <ul> unsorted list
36 // "message__list" structure will appear on the page echoing back the
37 // "some dumb text" message.
38 $placeholder_text = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')");
39 $this->assertNotNull($placeholder_text, 'A callback successfully echoed back a string.');
41 $this->drupalGet('ajax_validation_test');
42 // Partialy complete the form with a number.
43 $page->fillField('drivernumber', '12345');
44 $page->findField('spare_required_field')->focus();
46 // The AJAX request/resonse will complete successfully when a InsertCommand
47 // injects a message with a placeholder element into the DOM with the
49 $placeholder_number = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('12345')");
50 $this->assertNotNull($placeholder_number, 'A callback successfully echoed back a number.');