Version 1
[yaffs-website] / web / core / modules / system / src / Tests / Ajax / ElementValidationTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Ajax;
4
5 /**
6  * Various tests of AJAX behavior.
7  *
8  * @group Ajax
9  */
10 class ElementValidationTest extends AjaxTestBase {
11   /**
12    * Tries to post an Ajax change to a form that has a validated element.
13    *
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.
18    */
19   public function testAjaxElementValidation() {
20     $edit = ['drivertext' => t('some dumb text')];
21
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');
27
28     $this->drupalGet('ajax_validation_test');
29     $edit = ['drivernumber' => 12345];
30
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');
36   }
37
38 }