You are here

public function EntityTypeBuildEventTest::testEntityTypeBuildEvent in Hook Event Dispatcher 8

Test the EntityTypeBuildEvent.

File

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

Class

EntityTypeBuildEventTest
Class EntityTypeBuildEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityType

Code

public function testEntityTypeBuildEvent() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_TYPE_BUILD => static function (EntityTypeBuildEvent $event) {
      $entityTypes =& $event
        ->getEntityTypes();
      $entityTypes['my_custom_entity']
        ->set('admin_permission', 'my custom permission');
    },
  ]);
  $entityType = $this
    ->createMock(EntityTypeInterface::class);
  $entityType
    ->expects($this
    ->once())
    ->method('set')
    ->with($this
    ->equalTo('admin_permission'), $this
    ->equalTo('my custom permission'));
  $entityTypes = [
    'my_custom_entity' => $entityType,
  ];
  hook_event_dispatcher_entity_type_build($entityTypes);

  /** @var \Drupal\hook_event_dispatcher\Event\EntityType\EntityTypeBuildEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_TYPE_BUILD);
  self::assertEquals($entityTypes, $event
    ->getEntityTypes());
}