public function ViewEventTest::testQuerySubstitutionsByAdd in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x 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\ViewsCode
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);
}