annotate core/modules/system/src/Tests/Ajax/ElementValidationTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\system\Tests\Ajax;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Various tests of AJAX behavior.
Chris@0 7 *
Chris@0 8 * @group Ajax
Chris@0 9 */
Chris@0 10 class ElementValidationTest extends AjaxTestBase {
Chris@0 11 /**
Chris@0 12 * Tries to post an Ajax change to a form that has a validated element.
Chris@0 13 *
Chris@0 14 * The drivertext field is Ajax-enabled. An additional field is not, but
Chris@0 15 * is set to be a required field. In this test the required field is not
Chris@0 16 * filled in, and we want to see if the activation of the "drivertext"
Chris@0 17 * Ajax-enabled field fails due to the required field being empty.
Chris@0 18 */
Chris@0 19 public function testAjaxElementValidation() {
Chris@0 20 $edit = ['drivertext' => t('some dumb text')];
Chris@0 21
Chris@0 22 // Post with 'drivertext' as the triggering element.
Chris@0 23 $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivertext');
Chris@0 24 // Look for a validation failure in the resultant JSON.
Chris@0 25 $this->assertNoText(t('Error message'), 'No error message in resultant JSON');
Chris@0 26 $this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked');
Chris@0 27
Chris@0 28 $this->drupalGet('ajax_validation_test');
Chris@0 29 $edit = ['drivernumber' => 12345];
Chris@0 30
Chris@0 31 // Post with 'drivernumber' as the triggering element.
Chris@0 32 $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivernumber');
Chris@0 33 // Look for a validation failure in the resultant JSON.
Chris@0 34 $this->assertNoText(t('Error message'), 'No error message in resultant JSON');
Chris@0 35 $this->assertText('ajax_forms_test_validation_number_form_callback invoked', 'The correct callback was invoked');
Chris@0 36 }
Chris@0 37
Chris@0 38 }