X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FForm%2FFormValidationMessageOrderTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FForm%2FFormValidationMessageOrderTest.php;h=1d20340819ea50e91c4388f4f999fd7ec8b9db1f;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php b/web/core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php new file mode 100644 index 000000000..1d2034081 --- /dev/null +++ b/web/core/tests/Drupal/KernelTests/Core/Form/FormValidationMessageOrderTest.php @@ -0,0 +1,92 @@ + 'textfield', + '#title' => 'One', + '#required' => TRUE, + '#weight' => 40, + ]; + $form['two'] = [ + '#type' => 'textfield', + '#title' => 'Two', + '#required' => TRUE, + '#weight' => 30, + ]; + $form['three'] = [ + '#type' => 'textfield', + '#title' => 'Three', + '#required' => TRUE, + '#weight' => 10, + ]; + $form['four'] = [ + '#type' => 'textfield', + '#title' => 'Four', + '#required' => TRUE, + '#weight' => 20, + ]; + $form['actions'] = [ + '#type' => 'actions', + 'submit' => [ + '#type' => 'submit', + '#value' => 'Submit', + ], + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + } + + /** + * Tests that fields validation messages are sorted in the fields order. + */ + public function testLimitValidationErrors() { + $form_state = new FormState(); + $form_builder = $this->container->get('form_builder'); + $form_builder->submitForm($this, $form_state); + + $messages = drupal_get_messages(); + $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.'); + } + +}