You are here

public function PageEventTest::testPageTopEvent in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Theme/PageEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Page\PageEventTest::testPageTopEvent()

Test the PageTopEvent.

File

modules/core_event_dispatcher/tests/src/Unit/Theme/PageEventTest.php, line 97

Class

PageEventTest
Class PageEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Page

Code

public function testPageTopEvent() : void {
  $pageTop = [];
  $renderArray = [
    '#markup' => 'Top!',
  ];
  $expectedBuild = [
    'new' => $renderArray,
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::PAGE_TOP => static function (PageTopEvent $event) use ($renderArray) {
      $build =& $event
        ->getBuild();
      $build['new'] = $renderArray;
    },
  ]);
  core_event_dispatcher_page_top($pageTop);

  /** @var \Drupal\core_event_dispatcher\Event\Theme\PageTopEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::PAGE_TOP);
  self::assertSame($expectedBuild, $pageTop);
  self::assertSame($expectedBuild, $event
    ->getBuild());
}