You are here

public function FormErrorHandlerTest::testSetElementErrorsFromFormState in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php \Drupal\Tests\Core\Form\FormErrorHandlerTest::testSetElementErrorsFromFormState()
  2. 8 core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php \Drupal\Tests\inline_form_errors\Unit\FormErrorHandlerTest::testSetElementErrorsFromFormState()
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php \Drupal\Tests\Core\Form\FormErrorHandlerTest::testSetElementErrorsFromFormState()

@covers ::handleFormErrors @covers ::setElementErrorsFromFormState

File

core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php, line 97
Contains \Drupal\Tests\Core\Form\FormErrorHandlerTest.

Class

FormErrorHandlerTest
@coversDefaultClass \Drupal\Core\Form\FormErrorHandler @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testSetElementErrorsFromFormState() {
  $form_error_handler = $this
    ->getMockBuilder('Drupal\\Core\\Form\\FormErrorHandler')
    ->setMethods([
    'drupalSetMessage',
  ])
    ->getMock();
  $form = [
    '#parents' => [],
  ];
  $form['test'] = [
    '#type' => 'textfield',
    '#title' => 'Test',
    '#parents' => [
      'test',
    ],
    '#id' => 'edit-test',
  ];
  $form_state = new FormState();
  $form_state
    ->setErrorByName('test', 'invalid');
  $form_error_handler
    ->handleFormErrors($form, $form_state);
  $this
    ->assertSame('invalid', $form['test']['#errors']);
}