NotFoundPageCacheKeyEvent example



    private static function buildName(string $salesChannelId, string $domainId, string $languageId): string
    {
        return 'error-page-' . $salesChannelId . $domainId . $languageId;
    }

    private function generateKey(string $salesChannelId, string $domainId, string $languageId, Request $request, SalesChannelContext $context): string
    {
        $key = self::buildName($salesChannelId$domainId$languageId) . md5($this->generator->getSalesChannelContextHash($context));

        $event = new NotFoundPageCacheKeyEvent($key$request$context);

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

        return $event->getKey();
    }

    /** * @return array<string> */
    private function generateTags(string $name, Request $request, SalesChannelContext $context): array
    {
        

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

        $event = new NotFoundPageCacheKeyEvent('test', $request$context);

        static::assertSame('test', $event->getKey());
        static::assertSame($context->getContext()$event->getContext());
        static::assertSame($context$event->getSalesChannelContext());
        static::assertSame($request$event->getRequest());

        $event->setKey('test2');
        static::assertSame('test2', $event->getKey());
    }
}
Home | Imprint | This part of the site doesn't use cookies.