function SubmitDrivenTest::testSubmitDriven

Same name in other branches
  1. 3.x modules/ajax_example/tests/src/FunctionalJavascript/SubmitDrivenTest.php \Drupal\Tests\ajax_example\FunctionalJavascript\SubmitDrivenTest::testSubmitDriven()

Test the behavior of the submit-driven AJAX example.

Behaviors to test:

  • GET the route ajax_example.submit_driven_ajax.
  • Examine the DOM to make sure our change hasn't happened yet.
  • Submit the form.
  • Wait for the AJAX request to complete.
  • Examine the DOM to see if our expected change happened.

File

modules/ajax_example/tests/src/FunctionalJavascript/SubmitDrivenTest.php, line 35

Class

SubmitDrivenTest
Tests the behavior of the submit-driven AJAX example.

Namespace

Drupal\Tests\ajax_example\FunctionalJavascript

Code

public function testSubmitDriven() {
    // Get the session assertion object.
    $assert = $this->assertSession();
    // Get the page.
    $this->drupalGet(Url::fromRoute('ajax_example.submit_driven_ajax'));
    // Examine the DOM to make sure our change hasn't happened yet.
    $assert->pageTextNotContains('Clicked submit (Submit):');
    // Submit the form.
    $this->submitForm([], 'Submit');
    // Wait on the AJAX request.
    $assert->assertWaitOnAjaxRequest();
    // Compare DOM to our expectations.
    $assert->pageTextContains('Clicked submit (Submit):');
}