function FormValidationMessageOrderTest::testValidationErrorMessagesSortedWithWeight
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php \Drupal\KernelTests\Core\Form\FormValidationMessageOrderTest::testValidationErrorMessagesSortedWithWeight()
Tests that fields validation messages are sorted in the fields order.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Form/ FormValidationMessageOrderTest.php, line 80
Class
- FormValidationMessageOrderTest
- Tests form validation messages are displayed in the same order as the fields.
Namespace
Drupal\KernelTests\Core\FormCode
public function testValidationErrorMessagesSortedWithWeight() : void {
$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]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.