You are here

public function FormDefaultHandlersTest::testDefaultAndCustomHandlers in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Form/FormDefaultHandlersTest.php \Drupal\KernelTests\Core\Form\FormDefaultHandlersTest::testDefaultAndCustomHandlers()
  2. 10 core/tests/Drupal/KernelTests/Core/Form/FormDefaultHandlersTest.php \Drupal\KernelTests\Core\Form\FormDefaultHandlersTest::testDefaultAndCustomHandlers()

Tests that default handlers are added even if custom are specified.

File

core/tests/Drupal/KernelTests/Core/Form/FormDefaultHandlersTest.php, line 73

Class

FormDefaultHandlersTest
Tests automatically added form handlers.

Namespace

Drupal\KernelTests\Core\Form

Code

public function testDefaultAndCustomHandlers() {
  $form_state = new FormState();
  $form_builder = $this->container
    ->get('form_builder');
  $form_builder
    ->submitForm($this, $form_state);
  $handlers = $form_state
    ->get('test_handlers');
  $this
    ->assertCount(2, $handlers['validate']);
  $this
    ->assertSame('customValidateForm', $handlers['validate'][0]);
  $this
    ->assertSame('validateForm', $handlers['validate'][1]);
  $this
    ->assertCount(2, $handlers['submit']);
  $this
    ->assertSame('customSubmitForm', $handlers['submit'][0]);
  $this
    ->assertSame('submitForm', $handlers['submit'][1]);
}