You are here

public function PageEventTest::testPageBottomEvent in Hook Event Dispatcher 3.x

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

Test the PageBottomEvent.

File

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

Class

PageEventTest
Class PageEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Page

Code

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

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