You are here

public function EntityExtraEventTest::testEntityExtraFieldInfoAlterEvent in Hook Event Dispatcher 8

Test EntityExtraFieldInfoAlterEvent.

File

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

Class

EntityExtraEventTest
Class EntityExtraEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityExtra

Code

public function testEntityExtraFieldInfoAlterEvent() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_EXTRA_FIELD_INFO_ALTER => function (EntityExtraFieldInfoAlterEvent $event) {
      $info =& $event
        ->getFieldInfo();
      $info['taxonomy_term']['sheep']['display']['field_herd']['sheep'] = 'herd';
    },
  ]);
  $fieldInfo = $expectedFieldInfo = [
    'node' => [
      'test' => [
        'display' => [
          'field_test' => [
            'test' => 'node',
          ],
        ],
      ],
    ],
    'entity' => [
      'test_entity' => [
        'form' => [
          'field_node' => [
            'test' => 'entity',
          ],
        ],
      ],
    ],
  ];
  $expectedFieldInfo['taxonomy_term']['sheep']['display']['field_herd']['sheep'] = 'herd';
  hook_event_dispatcher_entity_extra_field_info_alter($fieldInfo);

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