function FormValidationMessageOrderTest::testLimitValidationErrors

Same name and namespace in other branches
  1. 9 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->assertEqual($error_messages[0], 'Three field is required.');
  $this->assertEqual($error_messages[1], 'Four field is required.');
  $this->assertEqual($error_messages[2], 'Two field is required.');
  $this->assertEqual($error_messages[3], 'One field is required.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.