You are here

public function EntityExtraEventTest::testEntityExtraFieldInfoEventWithSetFunction in Hook Event Dispatcher 8

Test EntityExtraFieldInfoEvent with set function.

File

tests/src/Unit/EntityExtra/EntityExtraEventTest.php, line 81

Class

EntityExtraEventTest
Class EntityExtraEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityExtra

Code

public function testEntityExtraFieldInfoEventWithSetFunction() {
  $fieldInfo = [
    'node' => [
      'test' => [
        'display' => [
          'field_test' => [
            'test' => 'node',
          ],
        ],
      ],
    ],
    'entity' => [
      'test_entity' => [
        'form' => [
          'field_node' => [
            'test' => 'entity',
          ],
        ],
      ],
    ],
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_EXTRA_FIELD_INFO => function (EntityExtraFieldInfoEvent $event) use ($fieldInfo) {
      $event
        ->setFieldInfo($fieldInfo);
    },
  ]);
  $hookFieldInfoResult = hook_event_dispatcher_entity_extra_field_info();
  self::assertEquals($fieldInfo, $hookFieldInfoResult);

  /** @var \Drupal\hook_event_dispatcher\Event\EntityExtra\EntityExtraFieldInfoEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_EXTRA_FIELD_INFO);
  self::assertEquals($fieldInfo, $event
    ->getFieldInfo());
}