You are here

public function FormValidationMessageOrderTest::testLimitValidationErrors in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php \Drupal\KernelTests\Core\Form\FormValidationMessageOrderTest::testLimitValidationErrors()

Tests that fields validation messages are sorted in the fields order.

File

core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php, line 78

Class

FormValidationMessageOrderTest
Tests form validation messages are displayed in the same order as the fields.

Namespace

Drupal\KernelTests\Core\Form

Code

public function testLimitValidationErrors() {
  $form_state = new FormState();
  $form_builder = $this->container
    ->get('form_builder');
  $form_builder
    ->submitForm($this, $form_state);
  $messages = \Drupal::messenger()
    ->all();
  \Drupal::messenger()
    ->deleteAll();
  $this
    ->assertTrue(isset($messages['error']));
  $error_messages = $messages['error'];
  $this
    ->assertEquals('Three field is required.', $error_messages[0]);
  $this
    ->assertEquals('Four field is required.', $error_messages[1]);
  $this
    ->assertEquals('Two field is required.', $error_messages[2]);
  $this
    ->assertEquals('One field is required.', $error_messages[3]);
}