annotate core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\FunctionalJavascriptTests\Ajax;
Chris@17 4
Chris@17 5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
Chris@17 6
Chris@17 7 /**
Chris@17 8 * Various tests of AJAX behavior.
Chris@17 9 *
Chris@17 10 * @group Ajax
Chris@17 11 */
Chris@17 12 class ElementValidationTest extends WebDriverTestBase {
Chris@17 13
Chris@17 14 /**
Chris@17 15 * {@inheritdoc}
Chris@17 16 */
Chris@17 17 public static $modules = ['ajax_test', 'ajax_forms_test'];
Chris@17 18
Chris@17 19 /**
Chris@17 20 * Tries to post an Ajax change to a form that has a validated element.
Chris@17 21 *
Chris@17 22 * Drupal AJAX commands update the DOM echoing back the validated values in
Chris@17 23 * the form of messages that appear on the page.
Chris@17 24 */
Chris@17 25 public function testAjaxElementValidation() {
Chris@17 26 $this->drupalGet('ajax_validation_test');
Chris@17 27 $page = $this->getSession()->getPage();
Chris@17 28 $assert = $this->assertSession();
Chris@17 29
Chris@17 30 // Partially complete the form with a string.
Chris@17 31 $page->fillField('drivertext', 'some dumb text');
Chris@17 32 // Move focus away from this field to trigger AJAX.
Chris@17 33 $page->findField('spare_required_field')->focus();
Chris@17 34
Chris@17 35 // When the AJAX command updates the DOM a <ul> unsorted list
Chris@17 36 // "message__list" structure will appear on the page echoing back the
Chris@17 37 // "some dumb text" message.
Chris@17 38 $placeholder_text = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')");
Chris@17 39 $this->assertNotNull($placeholder_text, 'A callback successfully echoed back a string.');
Chris@17 40
Chris@17 41 $this->drupalGet('ajax_validation_test');
Chris@17 42 // Partialy complete the form with a number.
Chris@17 43 $page->fillField('drivernumber', '12345');
Chris@17 44 $page->findField('spare_required_field')->focus();
Chris@17 45
Chris@17 46 // The AJAX request/resonse will complete successfully when a InsertCommand
Chris@17 47 // injects a message with a placeholder element into the DOM with the
Chris@17 48 // submitted number.
Chris@17 49 $placeholder_number = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('12345')");
Chris@17 50 $this->assertNotNull($placeholder_number, 'A callback successfully echoed back a number.');
Chris@17 51 }
Chris@17 52
Chris@17 53 }