function FormStateTest::testSetError

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

Tests the setError() method.

@covers ::setError

File

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

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 testSetError() : void {
    $form_state = new FormState();
    $element['#parents'] = [
        'foo',
        'bar',
    ];
    $form_state->setError($element, 'Fail');
    $this->assertSame([
        'foo][bar' => 'Fail',
    ], $form_state->getErrors());
}

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