You are here

private function ClientsideValidationTest::validateAssertions in Clientside Validation 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/ClientsideValidationTest.php \Drupal\Tests\clientside_validation\FunctionalJavascript\ClientsideValidationTest::validateAssertions()
  2. 3.0.x tests/src/FunctionalJavascript/ClientsideValidationTest.php \Drupal\Tests\clientside_validation\FunctionalJavascript\ClientsideValidationTest::validateAssertions()
  3. 2.0.x tests/src/FunctionalJavascript/ClientsideValidationTest.php \Drupal\Tests\clientside_validation\FunctionalJavascript\ClientsideValidationTest::validateAssertions()

Helper function to validate assertions.

Parameters

array $assertions: Assertions to validate.

Throws

\Exception Exception if element not found.

1 call to ClientsideValidationTest::validateAssertions()
ClientsideValidationTest::testValidations in tests/src/FunctionalJavascript/ClientsideValidationTest.php
Validate error messages.

File

tests/src/FunctionalJavascript/ClientsideValidationTest.php, line 162

Class

ClientsideValidationTest
Test Clientside Validations.

Namespace

Drupal\Tests\clientside_validation\FunctionalJavascript

Code

private function validateAssertions(array $assertions) {

  // Trigger click of submit button.
  $this->page
    ->findButton('Submit')
    ->click();
  foreach ($assertions as $key => $expected) {
    $errorElement = $this->page
      ->findById($key . '-error');
    if (empty($errorElement)) {

      // We will fail this scenario.
      $this
        ->assertEquals($expected, '');
      continue;
    }
    $actual = $errorElement
      ->getText();
    $this
      ->assertEquals($expected, $actual);
  }
}