fix(portal): preserve territorial totals and legacy redirect context
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
class PortalLegacyNavigationTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
DB::shouldReceive('connection')->never();
|
||||
}
|
||||
|
||||
public static function aliases(): array
|
||||
{
|
||||
return [
|
||||
'simulator' => ['/simulador', '/simulador-fiscal'],
|
||||
'simulator trailing slash' => ['/simulador/', '/simulador-fiscal'],
|
||||
'contacts' => ['/contactos', '/apoio'],
|
||||
'contacts trailing slash' => ['/contactos/', '/apoio'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('aliases')]
|
||||
public function test_legacy_links_redirect_to_existing_pages_without_database_access(string $path, string $destination): void
|
||||
{
|
||||
$route = app('router')->getRoutes()->match(Request::create($path));
|
||||
$response = $route->run();
|
||||
|
||||
$this->assertSame(301, $response->getStatusCode());
|
||||
$this->assertSame($destination, parse_url($response->headers->get('Location'), PHP_URL_PATH));
|
||||
}
|
||||
|
||||
public function test_simulator_redirect_preserves_context_without_accepting_an_external_destination(): void
|
||||
{
|
||||
$query = ['dossier' => 'qa-context', 'opportunity' => 'qa-opportunity', 'redirect' => 'https://example.invalid'];
|
||||
$request = Request::create('/simulador?'.http_build_query($query));
|
||||
app()->instance('request', $request);
|
||||
$route = app('router')->getRoutes()->match($request);
|
||||
$response = $route->run();
|
||||
$location = $response->headers->get('Location');
|
||||
|
||||
$this->assertSame('/simulador-fiscal', parse_url($location, PHP_URL_PATH));
|
||||
$this->assertSame($request->getHost(), parse_url($location, PHP_URL_HOST));
|
||||
parse_str(parse_url($location, PHP_URL_QUERY), $actual);
|
||||
$this->assertSame($query, $actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user