You are here

public function PageBottomEventTest::testPageBottomEventBySet in Hook Event Dispatcher 8

Test the PageBottomEvent by set.

File

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

Class

PageBottomEventTest
Class PageBottomEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Page

Code

public function testPageBottomEventBySet() {
  $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;
      $event
        ->setBuild($build);
    },
  ]);
  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());
}