You are here

public function FormEventTest::testFormBaseAlterEvent in Hook Event Dispatcher 8

Test FormBaseAlterEvent.

File

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

Class

FormEventTest
Class FormEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Form

Code

public function testFormBaseAlterEvent() {
  $baseFormId = 'test_base_form';
  $form = [
    'test' => 'form',
  ];
  $buildInfo = [
    'base_form_id' => $baseFormId,
  ];
  $formState = $this
    ->createMock(FormStateInterface::class);
  $formState
    ->method('getBuildInfo')
    ->willReturn($buildInfo);
  $formId = 'test_form';
  $this->manager
    ->setMaxEventCount(3);
  hook_event_dispatcher_form_alter($form, $formState, $formId);

  /** @var \Drupal\hook_event_dispatcher\Event\Form\FormBaseAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent("hook_event_dispatcher.form_base_{$baseFormId}.alter");
  self::assertEquals($form, $event
    ->getForm());
  self::assertEquals($formState, $event
    ->getFormState());
  self::assertEquals($formId, $event
    ->getFormId());
  self::assertEquals($baseFormId, $event
    ->getBaseFormId());
}