You are here

public function EntityExtraEventTest::testEntityExtraFieldInfoEventWithHelperFunctions in Hook Event Dispatcher 8

Test EntityExtraFieldInfoEvent with helper functions.

File

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

Class

EntityExtraEventTest
Class EntityExtraEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityExtra

Code

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

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