60 lines
2.5 KiB
PHP
60 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Illuminate\Foundation\Testing\TestCase;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
class JointDeliveryContextTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
DB::shouldReceive('connection')->never();
|
|
}
|
|
|
|
/** @return array<string, array{string, string, string, string}> */
|
|
public static function entries(): array
|
|
{
|
|
$entries = [];
|
|
foreach (['GET', 'HEAD'] as $method) {
|
|
foreach ([
|
|
'/simulador' => ['/simulador-fiscal', 'services.simulator'],
|
|
'/simulador/' => ['/simulador-fiscal', 'services.simulator'],
|
|
'/contactos' => ['/apoio', 'services.support'],
|
|
'/contactos/' => ['/apoio', 'services.support'],
|
|
] as $path => [$destination, $name]) {
|
|
$entries[$method.' '.$path] = [$method, $path, $destination, $name];
|
|
}
|
|
}
|
|
|
|
return $entries;
|
|
}
|
|
|
|
#[DataProvider('entries')]
|
|
public function test_both_aliases_preserve_context_and_resolve_the_existing_main_destination(string $method, string $path, string $destination, string $name): void
|
|
{
|
|
$query = [
|
|
'locale' => 'en', 'dossier' => 'qa-existing-dossier', 'opportunity_id' => '42',
|
|
'context' => ['territory_id' => 'qa-territory', 'origin' => 'carteira', 'return_to' => '/investidor/dossiers/qa-existing-dossier?stage=S08'],
|
|
'q' => 'Maputo & Zambézia / investimento',
|
|
'redirect' => 'https://example.invalid/untrusted-destination',
|
|
];
|
|
$request = Request::create('https://portal-investidor.test'.$path.'?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986), $method);
|
|
app()->instance('request', $request);
|
|
$routes = app('router')->getRoutes();
|
|
$response = $routes->match($request)->run();
|
|
$location = $response->headers->get('Location');
|
|
|
|
$this->assertSame(301, $response->getStatusCode());
|
|
$this->assertSame('https', parse_url($location, PHP_URL_SCHEME));
|
|
$this->assertSame('portal-investidor.test', parse_url($location, PHP_URL_HOST));
|
|
$this->assertSame($destination, parse_url($location, PHP_URL_PATH));
|
|
parse_str(parse_url($location, PHP_URL_QUERY), $actual);
|
|
$this->assertEquals($query, $actual);
|
|
$this->assertSame($name, $routes->match(Request::create($location, $method))->getName());
|
|
}
|
|
}
|