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