public function EntityViewEventTest::testEntityViewEventByReference in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityViewEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityViewEventTest::testEntityViewEventByReference()
Test EntityViewEvent by reference.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityViewEventTest.php, line 46
Class
- EntityViewEventTest
- Class EntityViewEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\EntityCode
public function testEntityViewEventByReference() : void {
$build = $expectedBuild = [
'testBuild' => [
'someBuild',
],
];
$entity = $this
->createMock(EntityInterface::class);
$display = $this
->createMock(EntityViewDisplayInterface::class);
$viewMode = 'testViewMode';
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::ENTITY_VIEW => static function (EntityViewEvent $event) {
$event
->getBuild()['otherBuild'] = [
'aBuild',
];
},
]);
$expectedBuild['otherBuild'] = [
'aBuild',
];
core_event_dispatcher_entity_view($build, $entity, $display, $viewMode);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityViewEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_VIEW);
self::assertSame($build, $event
->getBuild());
self::assertSame($expectedBuild, $event
->getBuild());
self::assertSame($entity, $event
->getEntity());
self::assertSame($display, $event
->getDisplay());
self::assertSame($viewMode, $event
->getViewMode());
}