class SubmitDrivenTest

Tests the behavior of the submit-driven AJAX example.

@group ajax_example

Hierarchy

  • class \Drupal\Tests\ajax_example\FunctionalJavascript\SubmitDrivenTest extends \Drupal\FunctionalJavascriptTests\WebDriverTestBase

Expanded class hierarchy of SubmitDrivenTest

File

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

Namespace

Drupal\Tests\ajax_example\FunctionalJavascript
View source
class SubmitDrivenTest extends WebDriverTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'ajax_example',
  ];
  
  /**
   * 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.
   */
  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):');
  }

}

Members

Title Sort descending Modifiers Object type Summary
SubmitDrivenTest::$defaultTheme protected property
SubmitDrivenTest::$modules protected static property
SubmitDrivenTest::testSubmitDriven public function Test the behavior of the submit-driven AJAX example.