function FormStateTest::testFormErrorsDuringSubmission

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/FormStateTest.php \Drupal\Tests\Core\Form\FormStateTest::testFormErrorsDuringSubmission()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/FormStateTest.php \Drupal\Tests\Core\Form\FormStateTest::testFormErrorsDuringSubmission()
  3. 10 core/tests/Drupal/Tests/Core/Form/FormStateTest.php \Drupal\Tests\Core\Form\FormStateTest::testFormErrorsDuringSubmission()

Tests that form errors during submission throw an exception.

@covers ::setErrorByName

File

core/tests/Drupal/Tests/Core/Form/FormStateTest.php, line 133

Class

FormStateTest
@coversDefaultClass \Drupal\Core\Form\FormState[[api-linebreak]]

Namespace

Drupal\Tests\Core\Form

Code

public function testFormErrorsDuringSubmission() : void {
  $form_state = new FormState();
  $form_state->setValidationComplete();
  $this->expectException(\LogicException::class);
  $this->expectExceptionMessage('Form errors cannot be set after form validation has finished.');
  $form_state->setErrorByName('test', 'message');
}

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