|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\FunctionalJavascriptTests\Ajax; |
| 4 | + |
| 5 | +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; |
| 6 | + |
| 7 | +/** |
| 8 | + * Various tests of AJAX behavior. |
| 9 | + * |
| 10 | + * @group Ajax |
| 11 | + */ |
| 12 | +class ElementValidationTest extends WebDriverTestBase { |
| 13 | + |
| 14 | + /** |
| 15 | + * {@inheritdoc} |
| 16 | + */ |
| 17 | + public static $modules = ['ajax_test', 'ajax_forms_test']; |
| 18 | + |
| 19 | + /** |
| 20 | + * Tries to post an Ajax change to a form that has a validated element. |
| 21 | + * |
| 22 | + * Drupal AJAX commands update the DOM echoing back the validated values in |
| 23 | + * the form of messages that appear on the page. |
| 24 | + */ |
| 25 | + public function testAjaxElementValidation() { |
| 26 | + $this->drupalGet('ajax_validation_test'); |
| 27 | + $page = $this->getSession()->getPage(); |
| 28 | + $assert = $this->assertSession(); |
| 29 | + |
| 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(); |
| 34 | + |
| 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.'); |
| 40 | + |
| 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(); |
| 45 | + |
| 46 | + // The AJAX request/resonse will complete successfully when a InsertCommand |
| 47 | + // injects a message with a placeholder element into the DOM with the |
| 48 | + // submitted number. |
| 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.'); |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments