CanonicalRedirectService example


class CanonicalRedirectServiceTest extends TestCase
{
    final public const CONFIG_KEY = 'core.seo.redirectToCanonicalUrl';

    /** * @dataProvider requestDataProvider */
    public function testGetRedirect(Request $request, ?Response $response): void
    {
        $shouldRedirect = $response->getStatusCode() === Response::HTTP_MOVED_PERMANENTLY;
        $canonicalRedirectService = new CanonicalRedirectService($this->getSystemConfigService($shouldRedirect));

        /** @var RedirectResponse|null $actual */
        $actual = $canonicalRedirectService->getRedirect($request);

        if ($shouldRedirect) {
            static::assertNotNull($actual);
            static::assertInstanceOf(
                RedirectResponse::class,
                $actual
            );
            static::assertEquals(
                
Home | Imprint | This part of the site doesn't use cookies.