You are here

public function EntityExtraEventTest::testEntityExtraFieldInfoAlterEvent in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Entity/EntityExtraEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityExtraEventTest::testEntityExtraFieldInfoAlterEvent()

Test EntityExtraFieldInfoAlterEvent.

File

modules/core_event_dispatcher/tests/src/Unit/Entity/EntityExtraEventTest.php, line 121

Class

EntityExtraEventTest
Class EntityExtraEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity

Code

public function testEntityExtraFieldInfoAlterEvent() : void {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_EXTRA_FIELD_INFO_ALTER => static 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';
  core_event_dispatcher_entity_extra_field_info_alter($fieldInfo);

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