You are here

public function EntityTypeAlterEventTest::testEntityTypeAlterEvent in Hook Event Dispatcher 8

Test the EntityTypeAlterEvent.

File

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

Class

EntityTypeAlterEventTest
Class EntityTypeAlterEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityType

Code

public function testEntityTypeAlterEvent() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_TYPE_ALTER => static function (EntityTypeAlterEvent $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_alter($entityTypes);

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