You are here

public function WebformCardsValidationJavaScriptTest::testValidation in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsValidationJavaScriptTest.php \Drupal\Tests\webform_cards\FunctionalJavaScript\WebformCardsValidationJavaScriptTest::testValidation()

Test webform cards validation.

File

modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsValidationJavaScriptTest.php, line 24

Class

WebformCardsValidationJavaScriptTest
Tests for webform cards validation.

Namespace

Drupal\Tests\webform_cards\FunctionalJavaScript

Code

public function testValidation() {
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();

  /**************************************************************************/
  $this
    ->drupalGet('/webform/test_cards_validation_errors');

  // Submit form with server-side validation errors.
  $page
    ->pressButton('edit-cards-next');
  $page
    ->pressButton('edit-cards-next');
  $page
    ->pressButton('edit-submit');

  // Check that only the card with validation error is visible.
  $assert_session
    ->waitForElement('css', '.messages.messages--error');
  $this
    ->assertElementNotVisible('[data-webform-key="card_1"]');
  $this
    ->assertElementVisible('[data-webform-key="card_2"]');
  $this
    ->assertElementNotVisible('[data-webform-key="card_3"]');
  $this
    ->assertElementNotVisible('[data-webform-key="card_1"]');
  $this
    ->assertElementNotVisible('#edit-cards-prev');
  $this
    ->assertElementNotVisible('#edit-cards-next');
  $this
    ->assertElementVisible('#edit-submit');
  $assert_session
    ->responseContains('<strong>The email address <em class="placeholder">{email_multiple not valid}</em> is not valid.</strong>');
}