You are here

public function EntityBundleFieldInfoAlterEventTest::testEntityBundleFieldInfoAlterEvent in Hook Event Dispatcher 8

Test the EntityBundleFieldInfoAlterEventTest.

File

tests/src/Unit/EntityType/EntityBundleFieldInfoAlterEventTest.php, line 42

Class

EntityBundleFieldInfoAlterEventTest
Class EntityBundleFieldInfoAlterEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityType

Code

public function testEntityBundleFieldInfoAlterEvent() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_BUNDLE_FIELD_INFO_ALTER => function (EntityBundleFieldInfoAlterEvent $event) {
      $fields =& $event
        ->getFields();
      $fields['field_test'] = 'test_altered';
    },
  ]);
  $fields = $expectedFields = [
    'field_test' => 'test',
  ];
  $entityType = $this
    ->createMock(EntityTypeInterface::class);
  $bundle = 'test_bundle';
  hook_event_dispatcher_entity_bundle_field_info_alter($fields, $entityType, $bundle);
  $expectedFields['field_test'] = 'test_altered';
  self::assertEquals($fields, $expectedFields);

  /** @var \Drupal\hook_event_dispatcher\Event\EntityType\EntityBundleFieldInfoAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_BUNDLE_FIELD_INFO_ALTER);
  self::assertEquals($entityType, $event
    ->getEntityType());
  self::assertEquals($bundle, $event
    ->getBundle());
}