You are here

public function ViewEventTest::testPreViewEvent in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/views_event_dispatcher/tests/src/Unit/Views/ViewEventTest.php \Drupal\Tests\views_event_dispatcher\Unit\Views\ViewEventTest::testPreViewEvent()

Pre view event.

File

modules/views_event_dispatcher/tests/src/Unit/Views/ViewEventTest.php, line 53

Class

ViewEventTest
Class ViewEventTest.

Namespace

Drupal\Tests\views_event_dispatcher\Unit\Views

Code

public function testPreViewEvent() : void {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $this
    ->createMock(ViewExecutable::class);
  $displayId = 'test';
  $arguments = [
    'test',
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::VIEWS_PRE_VIEW => static function (ViewsPreViewEvent $event) {
      $arguments =& $event
        ->getArguments();
      $arguments[0] = 'test2';
    },
  ]);
  views_event_dispatcher_views_pre_view($view, $displayId, $arguments);

  /** @var \Drupal\views_event_dispatcher\Event\Views\ViewsPreViewEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::VIEWS_PRE_VIEW);
  self::assertSame($view, $event
    ->getView());
  self::assertSame($displayId, $event
    ->getDisplayId());
  self::assertSame('test2', $arguments[0]);
}