You are here

public function EntityBundleFieldInfoAlterEventTest::testEntityBundleFieldInfoAlterEvent in Hook Event Dispatcher 8.2

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

Test the EntityBundleFieldInfoAlterEventTest.

File

modules/core_event_dispatcher/tests/src/Unit/Entity/EntityBundleFieldInfoAlterEventTest.php, line 42

Class

EntityBundleFieldInfoAlterEventTest
Class EntityBundleFieldInfoAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity

Code

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

  /** @var \Drupal\core_event_dispatcher\Event\Entity\EntityBundleFieldInfoAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_BUNDLE_FIELD_INFO_ALTER);
  self::assertSame($expectedFields, $event
    ->getFields());
  self::assertSame($entityType, $event
    ->getEntityType());
  self::assertSame($bundle, $event
    ->getBundle());
}