public function EntityViewEventTest::testEntityBuildDefaultsAlter 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::testEntityBuildDefaultsAlter()
Test EntityBuildDefaultsAlter.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityViewEventTest.php, line 98
Class
- EntityViewEventTest
- Class EntityViewEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\EntityCode
public function testEntityBuildDefaultsAlter() : void {
$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',
];
core_event_dispatcher_entity_build_defaults_alter($build, $entity, $viewMode);
/** @var \Drupal\core_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());
}