class ElementValidationTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php \Drupal\FunctionalJavascriptTests\Ajax\ElementValidationTest
- 10 core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php \Drupal\FunctionalJavascriptTests\Ajax\ElementValidationTest
- 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php \Drupal\FunctionalJavascriptTests\Ajax\ElementValidationTest
Various tests of AJAX behavior.
@group Ajax
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\FunctionalJavascriptTests\Ajax\ElementValidationTest extends \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ElementValidationTest
File
-
core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ ElementValidationTest.php, line 12
Namespace
Drupal\FunctionalJavascriptTests\AjaxView source
class ElementValidationTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'ajax_test',
'ajax_forms_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* Tries to post an Ajax change to a form that has a validated element.
*
* Drupal AJAX commands update the DOM echoing back the validated values in
* the form of messages that appear on the page.
*/
public function testAjaxElementValidation() {
$this->drupalGet('ajax_validation_test');
$page = $this->getSession()
->getPage();
$assert = $this->assertSession();
// Partially complete the form with a string.
$page->fillField('drivertext', 'some dumb text');
// Move focus away from this field to trigger AJAX.
$page->findField('spare_required_field')
->focus();
// When the AJAX command updates the DOM a <ul> unsorted list
// "message__list" structure will appear on the page echoing back the
// "some dumb text" message.
$placeholder_text = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')");
$this->assertNotNull($placeholder_text, 'A callback successfully echoed back a string.');
$this->drupalGet('ajax_validation_test');
// Partially complete the form with a number.
$page->fillField('drivernumber', '12345');
$page->findField('spare_required_field')
->focus();
// The AJAX request/response will complete successfully when an
// InsertCommand injects a message with a placeholder element into the DOM
// with the submitted number.
$placeholder_number = $assert->waitForElement('css', "ul.messages__list li.messages__item em:contains('12345')");
$this->assertNotNull($placeholder_number, 'A callback successfully echoed back a number.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.