You are here

public function PageTopEventTest::testPageTopEventBySet in Hook Event Dispatcher 8

Test the PageTopEvent by set.

File

tests/src/Unit/Page/PageTopEventTest.php, line 66

Class

PageTopEventTest
Class PageTopEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Page

Code

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