You are here

public function EntityViewEventTest::testEntityViewEventBySet in Hook Event Dispatcher 8

Test EntityViewEvent by set.

File

tests/src/Unit/Entity/EntityViewEventTest.php, line 75

Class

EntityViewEventTest
Class EntityViewEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Entity

Code

public function testEntityViewEventBySet() {
  $build = [
    'testBuild' => [
      'someBuild',
    ],
  ];
  $otherBuild = [
    'otherBuild' => [
      'lalala',
    ],
  ];
  $entity = $this
    ->createMock(EntityInterface::class);
  $display = $this
    ->createMock(EntityViewDisplayInterface::class);
  $viewMode = 'testViewMode';
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_VIEW => static function (EntityViewEvent $event) use ($otherBuild) {
      $event
        ->setBuild($otherBuild);
    },
  ]);
  hook_event_dispatcher_entity_view($build, $entity, $display, $viewMode);

  /** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityViewEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_VIEW);
  self::assertSame($build, $event
    ->getBuild());
  self::assertSame($otherBuild, $event
    ->getBuild());
  self::assertSame($entity, $event
    ->getEntity());
  self::assertSame($display, $event
    ->getDisplay());
  self::assertSame($viewMode, $event
    ->getViewMode());
}