3 namespace Drupal\system\Tests\Ajax;
6 * Various tests of AJAX behavior.
10 class ElementValidationTest extends AjaxTestBase {
12 * Tries to post an Ajax change to a form that has a validated element.
14 * The drivertext field is Ajax-enabled. An additional field is not, but
15 * is set to be a required field. In this test the required field is not
16 * filled in, and we want to see if the activation of the "drivertext"
17 * Ajax-enabled field fails due to the required field being empty.
19 public function testAjaxElementValidation() {
20 $edit = ['drivertext' => t('some dumb text')];
22 // Post with 'drivertext' as the triggering element.
23 $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivertext');
24 // Look for a validation failure in the resultant JSON.
25 $this->assertNoText(t('Error message'), 'No error message in resultant JSON');
26 $this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked');
28 $this->drupalGet('ajax_validation_test');
29 $edit = ['drivernumber' => 12345];
31 // Post with 'drivernumber' as the triggering element.
32 $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivernumber');
33 // Look for a validation failure in the resultant JSON.
34 $this->assertNoText(t('Error message'), 'No error message in resultant JSON');
35 $this->assertText('ajax_forms_test_validation_number_form_callback invoked', 'The correct callback was invoked');