You are here

public function FormEventTest::testFormAlterEvent in Hook Event Dispatcher 8

Test FormAlterEvent.

File

tests/src/Unit/Form/FormEventTest.php, line 43

Class

FormEventTest
Class FormEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Form

Code

public function testFormAlterEvent() {
  $form = [
    'test' => 'form',
  ];
  $formState = $this
    ->createMock(FormStateInterface::class);
  $formId = 'test_form';
  $this->manager
    ->setMaxEventCount(2);
  hook_event_dispatcher_form_alter($form, $formState, $formId);

  /** @var \Drupal\hook_event_dispatcher\Event\Form\FormAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::FORM_ALTER);
  self::assertEquals($form, $event
    ->getForm());
  self::assertEquals($formState, $event
    ->getFormState());
  self::assertEquals($formId, $event
    ->getFormId());
  $newForm = [
    'NewForm',
  ];
  $event
    ->setForm($newForm);
  self::assertEquals($newForm, $event
    ->getForm());
}