Files
myep-team/tests/Twig/ForwardedReturnUrlTest.php

53 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Twig;
use App\Twig\AppRuntime;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class ForwardedReturnUrlTest extends KernelTestCase
{
private RequestStack $requestStack;
private AppRuntime $appRuntime;
protected function setUp(): void
{
self::bootKernel();
$this->requestStack = self::getContainer()->get(RequestStack::class);
$this->appRuntime = self::getContainer()->get(AppRuntime::class);
}
public function testTheReturnUrlIsPassedOnUntouched(): void
{
$encoded = rawurlencode('/administrative/assignment?page=3');
$this->requestStack->push(Request::create('/administrative/assignment/detail/abc?r='.$encoded));
// The raw query value, handed straight back to the url generator, which
// re-encodes it. No decoding of its own, that stays the consumer's job.
self::assertSame('/administrative/assignment?page=3', $this->appRuntime->getForwardedReturnUrl());
}
/**
* Null rather than an empty string, so the url generator drops the parameter
* instead of emitting "r=".
*/
public function testNothingIsPassedOnWithoutAReturnUrl(): void
{
$this->requestStack->push(Request::create('/administrative/assignment/detail/abc'));
self::assertNull($this->appRuntime->getForwardedReturnUrl());
}
public function testNothingIsPassedOnForAnEmptyReturnUrl(): void
{
$this->requestStack->push(Request::create('/administrative/assignment/detail/abc?r='));
self::assertNull($this->appRuntime->getForwardedReturnUrl());
}
}