@@ -292,4 +292,119 @@ public function testRenderReturnResponseWithLazyProps()
292
292
$ this ->assertSame ($ validJson , $ jsonResponse );
293
293
}
294
294
295
+ public function testLocationReturnResponseWithLocationAsStringWithNotExistingInertiaHeader ()
296
+ {
297
+ $ request = $ this ->prophesize (ServerRequestInterface::class);
298
+ $ htmlResponse = null ;
299
+
300
+ $ response = $ this ->prophesize (ResponseInterface::class);
301
+ $ responseFactory = $ this ->prophesize (ResponseFactoryInterface::class);
302
+ $ responseFactory ->createResponse ()->willReturn ($ response );
303
+
304
+ $ stream = $ this ->prophesize (StreamInterface::class);
305
+ $ streamFactory = $ this ->prophesize (StreamFactoryInterface::class);
306
+ $ streamFactory ->createStream (Argument::type ('string ' ))->will (function () use ($ stream ){
307
+ return $ stream ;
308
+ });
309
+
310
+ $ rootViewProvider = $ this ->prophesize (RootViewProviderInterface::class);
311
+
312
+ $ response ->withBody ($ stream ->reveal ())->willReturn ($ response );
313
+ $ response ->withHeader ('X-Inertia ' , true )->willReturn ($ response );
314
+ $ response ->withHeader ('Content-Type ' , 'text/html; charset=UTF-8 ' )->willReturn ($ response );
315
+ $ response ->withStatus (302 )->willReturn ($ response );
316
+ $ response ->withHeader ('Location ' , 'new-location ' )->willReturn ($ response );
317
+
318
+ $ inertia = new Inertia (
319
+ $ request ->reveal (),
320
+ $ responseFactory ->reveal (),
321
+ $ streamFactory ->reveal (),
322
+ $ rootViewProvider ->reveal ()
323
+ );
324
+
325
+
326
+ $ returnedResponse = $ inertia ->location ('new-location ' );
327
+
328
+ $ this ->assertInstanceOf (ResponseInterface::class, $ returnedResponse );
329
+ $ this ->assertNotSame ('' , $ htmlResponse );
330
+ }
331
+
332
+ public function testLocationReturnResponseWithLocationAsStringWithExistingInertiaHeader ()
333
+ {
334
+ $ request = $ this ->prophesize (ServerRequestInterface::class);
335
+ $ request ->hasHeader ('X-Inertia ' )->willReturn (true );
336
+ $ htmlResponse = null ;
337
+
338
+ $ response = $ this ->prophesize (ResponseInterface::class);
339
+ $ responseFactory = $ this ->prophesize (ResponseFactoryInterface::class);
340
+ $ responseFactory ->createResponse ()->willReturn ($ response );
341
+
342
+ $ stream = $ this ->prophesize (StreamInterface::class);
343
+ $ streamFactory = $ this ->prophesize (StreamFactoryInterface::class);
344
+ $ streamFactory ->createStream (Argument::type ('string ' ))->will (function () use ($ stream ){
345
+ return $ stream ;
346
+ });
347
+
348
+ $ rootViewProvider = $ this ->prophesize (RootViewProviderInterface::class);
349
+
350
+ $ response ->withBody ($ stream ->reveal ())->willReturn ($ response );
351
+ $ response ->withHeader ('X-Inertia ' , true )->willReturn ($ response );
352
+ $ response ->withHeader ('Content-Type ' , 'text/html; charset=UTF-8 ' )->willReturn ($ response );
353
+ $ response ->withStatus (409 )->willReturn ($ response );
354
+ $ response ->withHeader ('X-Inertia-Location ' , 'new-location ' )->willReturn ($ response );
355
+
356
+ $ inertia = new Inertia (
357
+ $ request ->reveal (),
358
+ $ responseFactory ->reveal (),
359
+ $ streamFactory ->reveal (),
360
+ $ rootViewProvider ->reveal ()
361
+ );
362
+
363
+ $ returnedResponse = $ inertia ->location ('new-location ' );
364
+
365
+ $ this ->assertInstanceOf (ResponseInterface::class, $ returnedResponse );
366
+ $ this ->assertNotSame ('' , $ htmlResponse );
367
+ }
368
+
369
+ public function testLocationReturnResponseWithLocationAsResponseInterfaceWithExistingInertiaHeader ()
370
+ {
371
+ $ request = $ this ->prophesize (ServerRequestInterface::class);
372
+ $ request ->hasHeader ('X-Inertia ' )->willReturn (true );
373
+ $ htmlResponse = null ;
374
+
375
+ $ response = $ this ->prophesize (ResponseInterface::class);
376
+ $ responseFactory = $ this ->prophesize (ResponseFactoryInterface::class);
377
+ $ responseFactory ->createResponse ()->willReturn ($ response );
378
+
379
+ $ stream = $ this ->prophesize (StreamInterface::class);
380
+ $ streamFactory = $ this ->prophesize (StreamFactoryInterface::class);
381
+ $ streamFactory ->createStream (Argument::type ('string ' ))->will (function () use ($ stream ){
382
+ return $ stream ;
383
+ });
384
+
385
+ $ rootViewProvider = $ this ->prophesize (RootViewProviderInterface::class);
386
+
387
+ $ response ->withBody ($ stream ->reveal ())->willReturn ($ response );
388
+ $ response ->withHeader ('X-Inertia ' , true )->willReturn ($ response );
389
+ $ response ->withHeader ('Content-Type ' , 'text/html; charset=UTF-8 ' )->willReturn ($ response );
390
+
391
+ $ locationResponse = $ this ->prophesize (ResponseInterface::class);
392
+ $ locationResponse ->getHeaderLine ('Location ' )->willReturn ('new-location ' );
393
+
394
+ $ response ->withStatus (409 )->willReturn ($ response );
395
+ $ response ->withHeader ('X-Inertia-Location ' , $ locationResponse instanceof ResponseInterface ? $ locationResponse ->getHeaderLine ('Location ' ) : $ locationResponse )->willReturn ($ response );
396
+
397
+ $ inertia = new Inertia (
398
+ $ request ->reveal (),
399
+ $ responseFactory ->reveal (),
400
+ $ streamFactory ->reveal (),
401
+ $ rootViewProvider ->reveal ()
402
+ );
403
+
404
+ $ returnedResponse = $ inertia ->location ($ locationResponse );
405
+
406
+ $ this ->assertInstanceOf (ResponseInterface::class, $ returnedResponse );
407
+ $ this ->assertNotSame ('' , $ htmlResponse );
408
+ }
409
+
295
410
}
0 commit comments