public function PageTopEventTest::testPageTopEventByReference in Hook Event Dispatcher 8
Test the PageTopEvent by reference.
File
- tests/
src/ Unit/ Page/ PageTopEventTest.php, line 42
Class
- PageTopEventTest
- Class PageTopEventTest.
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\PageCode
public function testPageTopEventByReference() {
$pageTop = $expectedBuild = [];
$renderArray = [
'#markup' => 'Top!',
];
$expectedBuild['new'] = $renderArray;
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::PAGE_TOP => function (PageTopEvent $event) use ($renderArray) {
$build =& $event
->getBuild();
$build['new'] = $renderArray;
},
]);
hook_event_dispatcher_page_top($pageTop);
/** @var \Drupal\hook_event_dispatcher\Event\Page\PageTopEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::PAGE_TOP);
self::assertSame($expectedBuild, $event
->getBuild());
}