function FormStateTest::testSetErrorByName

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

@covers ::setErrorByName

@dataProvider providerTestSetErrorByName

File

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

Class

FormStateTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormState.php/class/FormState/11.x" title="Stores information about the state of a form." class="local">\Drupal\Core\Form\FormState</a>

Namespace

Drupal\Tests\Core\Form

Code

public function testSetErrorByName($limit_validation_errors, $expected_errors) : void {
    $form_state = new FormState();
    $form_state->setLimitValidationErrors($limit_validation_errors);
    $form_state->clearErrors();
    $form_state->setErrorByName('test', 'Fail 1');
    $form_state->setErrorByName('test', 'Fail 2');
    $form_state->setErrorByName('options');
    $this->assertSame(!empty($expected_errors), $form_state::hasAnyErrors());
    $this->assertSame($expected_errors, $form_state->getErrors());
}

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