You are here

public function ViewEventTest::testQuerySubstitutionsByAdd in Hook Event Dispatcher 3.x

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

Query substitutions event by add test.

File

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

Class

ViewEventTest
Class ViewEventTest.

Namespace

Drupal\Tests\views_event_dispatcher\Unit\Views

Code

public function testQuerySubstitutionsByAdd() : void {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $this
    ->createMock(ViewExecutable::class);
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::VIEWS_QUERY_SUBSTITUTIONS => static function (ViewsQuerySubstitutionsEvent $event) {
      $event
        ->addSubstitution('test', 'replacement');
    },
  ]);
  $expected = [
    'test' => 'replacement',
  ];
  $result = views_event_dispatcher_views_query_substitutions($view);

  /** @var \Drupal\views_event_dispatcher\Event\Views\ViewsQuerySubstitutionsEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::VIEWS_QUERY_SUBSTITUTIONS);
  self::assertSame($view, $event
    ->getView());
  self::assertSame($expected, $event
    ->getSubstitutions());
  self::assertSame($expected, $result);
}