You are here

public function EntityBaseFieldInfoAlterEventTest::testEntityBaseFieldInfoAlterEvent in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityBaseFieldInfoAlterEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityBaseFieldInfoAlterEventTest::testEntityBaseFieldInfoAlterEvent()

Test the EntityBaseFieldInfoAlterEvent.

File

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

Class

EntityBaseFieldInfoAlterEventTest
Class EntityBaseFieldInfoAlterEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity

Code

public function testEntityBaseFieldInfoAlterEvent() : void {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_BASE_FIELD_INFO_ALTER => static function (EntityBaseFieldInfoAlterEvent $event) {
      $fields =& $event
        ->getFields();
      $fields['field_test'] = 'test_altered';
    },
  ]);
  $fields = $expectedFields = [
    'field_test' => 'test',
  ];
  $entityType = $this
    ->createMock(EntityTypeInterface::class);
  core_event_dispatcher_entity_base_field_info_alter($fields, $entityType);
  $expectedFields['field_test'] = 'test_altered';
  self::assertSame($expectedFields, $fields);

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