public function EntityViewEventTest::testEntityBuildDefaultsAlter in Hook Event Dispatcher 8
Test EntityBuildDefaultsAlter.
File
- tests/
src/ Unit/ Entity/ EntityViewEventTest.php, line 127
Class
- EntityViewEventTest
- Class EntityViewEventTest.
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\EntityCode
public function testEntityBuildDefaultsAlter() {
$build = $expectedBuild = [
'testBuild' => [
'someBuild',
],
];
$entity = $this
->createMock(EntityInterface::class);
$viewMode = 'entity_view_mode';
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::ENTITY_BUILD_DEFAULTS_ALTER => static function (EntityBuildDefaultsAlterEvent $event) {
$event
->getBuild()['otherBuild'] = [
'aBuild',
];
},
]);
$expectedBuild['otherBuild'] = [
'aBuild',
];
hook_event_dispatcher_entity_build_defaults_alter($build, $entity, $viewMode);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityBuildDefaultsAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_BUILD_DEFAULTS_ALTER);
self::assertSame($build, $event
->getBuild());
self::assertSame($expectedBuild, $event
->getBuild());
self::assertSame($entity, $event
->getEntity());
self::assertSame($viewMode, $event
->getViewMode());
}