<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CmsBundle\Tests\EventListener;

use Ferienpass\CmsBundle\EventListener\LocalizeResponseListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

final class LocalizeResponseListenerTest extends TestCase
{
    public function testDoesNothingForSubRequest(): void
    {
        $kernel = $this->createMock(HttpKernelInterface::class);
        $request = Request::create('/test');

        $event = new RequestEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);

        // No exception means listener returned early
        new LocalizeResponseListener()->onKernelRequest($event);
        $this->addToAssertionCount(1);
    }

    public function testDoesNothingWhenNoPageModelAttribute(): void
    {
        $kernel = $this->createMock(HttpKernelInterface::class);
        $request = Request::create('/test');

        $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST);

        // No pageModel attribute, so listener returns early
        new LocalizeResponseListener()->onKernelRequest($event);
        $this->addToAssertionCount(1);
    }
}
