NotFoundPageTagsEvent example


class NotFoundPageTagsEventTest extends TestCase
{
    public function testEvent(): void
    {
        $request = new Request();
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getContext')->willReturn(Context::createDefaultContext());

        $event = new NotFoundPageTagsEvent(['test']$request$context);

        static::assertSame(['test']$event->getTags());
        static::assertSame($context->getContext()$event->getContext());
        static::assertSame($context$event->getSalesChannelContext());
        static::assertSame($request$event->getRequest());

        $event->addTags(['test2']);
        static::assertSame(['test', 'test2']$event->getTags());
    }
}
/** * @return array<string> */
    private function generateTags(string $name, Request $request, SalesChannelContext $context): array
    {
        $tags = array_merge(
            $this->cacheTracer->get($name),
            [$name, self::ALL_TAG]
        );

        $event = new NotFoundPageTagsEvent($tags$request$context);

        $this->eventDispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }

    private function setSalesChannelContext(Request $request): void
    {
        $salesChannelId = (string) $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);

        $context = $this->contextService->get(
            
Home | Imprint | This part of the site doesn't use cookies.