You are here

public function ViewEventTest::testPostRenderEvent in Hook Event Dispatcher 8

Post render event.

File

tests/src/Unit/Views/ViewEventTest.php, line 139

Class

ViewEventTest
Class ViewEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Views

Code

public function testPostRenderEvent() {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $this
    ->createMock(ViewExecutable::class);
  $output = "<h1>test</h1>";

  /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
  $cache = $this
    ->createMock(CachePluginBase::class);
  $cache->options['results_lifespan'] = 0;
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::VIEWS_POST_RENDER => function (ViewsPostRenderEvent $event) {
      $output =& $event
        ->getOutput();
      $output = "<h2>Test</h2>";
      $cache = $event
        ->getCache();
      $cache->options['results_lifespan'] = 10;
    },
  ]);
  hook_event_dispatcher_views_post_render($view, $output, $cache);
  self::assertEquals("<h2>Test</h2>", $output);
  self::assertEquals(10, $cache->options['results_lifespan']);
}