|
11 | 11 | use Illuminate\Support\Facades\Request;
|
12 | 12 | use Inertia\Tests\Stubs\ExampleMiddleware;
|
13 | 13 | use Illuminate\Contracts\Support\Arrayable;
|
| 14 | +use Illuminate\Http\Request as HttpRequest; |
14 | 15 | use Illuminate\Session\Middleware\StartSession;
|
| 16 | +use Illuminate\Session\NullSessionHandler; |
| 17 | +use Illuminate\Session\Store; |
15 | 18 |
|
16 | 19 | class ResponseFactoryTest extends TestCase
|
17 | 20 | {
|
@@ -75,6 +78,30 @@ public function test_location_response_for_non_inertia_requests_using_redirect_r
|
75 | 78 | $this->assertEquals('https://inertiajs.com', $response->headers->get('location'));
|
76 | 79 | }
|
77 | 80 |
|
| 81 | + public function test_location_redirects_are_not_modified(): void |
| 82 | + { |
| 83 | + $response = (new ResponseFactory())->location('/foo'); |
| 84 | + |
| 85 | + $this->assertInstanceOf(RedirectResponse::class, $response); |
| 86 | + $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode()); |
| 87 | + $this->assertEquals('/foo', $response->headers->get('location')); |
| 88 | + } |
| 89 | + |
| 90 | + public function test_location_response_for_non_inertia_requests_using_redirect_response_with_existing_session_and_request_properties(): void |
| 91 | + { |
| 92 | + $redirect = new RedirectResponse('https://inertiajs.com'); |
| 93 | + $redirect->setSession($session = new Store('test', new NullSessionHandler)); |
| 94 | + $redirect->setRequest($request = new HttpRequest); |
| 95 | + $response = (new ResponseFactory())->location($redirect); |
| 96 | + |
| 97 | + $this->assertInstanceOf(RedirectResponse::class, $response); |
| 98 | + $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode()); |
| 99 | + $this->assertEquals('https://inertiajs.com', $response->headers->get('location')); |
| 100 | + $this->assertSame($session, $response->getSession()); |
| 101 | + $this->assertSame($request, $response->getRequest()); |
| 102 | + $this->assertSame($response, $redirect); |
| 103 | + } |
| 104 | + |
78 | 105 | public function test_the_version_can_be_a_closure(): void
|
79 | 106 | {
|
80 | 107 | Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
|
|
0 commit comments