function FormStateTest::testSetErrorByName

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Form/FormStateTest.php \Drupal\Tests\Core\Form\FormStateTest::testSetErrorByName()
  2. 10 core/tests/Drupal/Tests/Core/Form/FormStateTest.php \Drupal\Tests\Core\Form\FormStateTest::testSetErrorByName()
  3. 11.x 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 106

Class

FormStateTest
@coversDefaultClass \Drupal\Core\Form\FormState

Namespace

Drupal\Tests\Core\Form

Code

public function testSetErrorByName($limit_validation_errors, $expected_errors) {
    $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.