You are here

public function PageBottomEventTest::testPageBottomEventByReference in Hook Event Dispatcher 8

Test the PageBottomEvent by reference.

File

tests/src/Unit/Page/PageBottomEventTest.php, line 41

Class

PageBottomEventTest
Class PageBottomEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Page

Code

public function testPageBottomEventByReference() {
  $pageBottom = $expectedBuild = [];
  $renderArray = [
    '#markup' => 'Bottom!',
  ];
  $expectedBuild['new'] = $renderArray;
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::PAGE_BOTTOM => function (PageBottomEvent $event) use ($renderArray) {
      $build =& $event
        ->getBuild();
      $build['new'] = $renderArray;
    },
  ]);
  hook_event_dispatcher_page_bottom($pageBottom);

  /** @var \Drupal\hook_event_dispatcher\Event\Page\PageBottomEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::PAGE_BOTTOM);
  self::assertSame($expectedBuild, $event
    ->getBuild());
}