set('admin_access.site_host', $host ?? ''); $router = new Router(app('events'), app()); Route::swap($router); require base_path('routes/web.php'); $router->getRoutes()->refreshNameLookups(); return $router; } it('does not serve the website on the portal’s hostname', function () { $router = routerWithSiteHost('www.example.test'); $action = fn (string $host) => $router->getRoutes() ->match(Request::create("http://{$host}/", 'GET')) ->getActionName(); expect($action('www.example.test'))->toContain('LandingController') ->and($action('app.example.test'))->not->toContain('LandingController'); }); it('sends a signed-out visitor on the portal host to the sign-in page', function () { $router = routerWithSiteHost('www.example.test'); $response = $router->dispatch(Request::create('http://app.example.test/', 'GET')); expect($response->getStatusCode())->toBe(302) ->and($response->headers->get('Location'))->toContain('/login'); }); it('sends a signed-in customer on the portal host to their dashboard', function () { $this->actingAs(User::factory()->create()); $router = routerWithSiteHost('www.example.test'); $response = $router->dispatch(Request::create('http://app.example.test/', 'GET')); expect($response->getStatusCode())->toBe(302) ->and($response->headers->get('Location'))->toContain('/dashboard'); }); it('leaves the imprint reachable from wherever the reader is standing', function () { // Deliberately not bound to the website's host: an imprint is a legal // requirement, and a mail footer links to it from whichever host sent the // mail. $router = routerWithSiteHost('www.example.test'); $action = fn (string $host) => $router->getRoutes() ->match(Request::create("http://{$host}/legal/impressum", 'GET')) ->getActionName(); expect($action('app.example.test'))->toBe($action('www.example.test')); }); it('keeps the landing page on every host while no website host is configured', function () { // The installed base, and every development machine reached by IP. $router = routerWithSiteHost(null); $action = fn (string $host) => $router->getRoutes() ->match(Request::create("http://{$host}/", 'GET')) ->getActionName(); expect($action('app.example.test'))->toContain('LandingController') ->and($action('anything.example.test'))->toContain('LandingController'); });