|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Inertia\Tests; |
| 4 | + |
| 5 | +use Illuminate\Session\Middleware\StartSession; |
| 6 | +use Illuminate\Support\Facades\Config; |
| 7 | +use Illuminate\Support\Facades\Route; |
| 8 | +use Inertia\Inertia; |
| 9 | +use Inertia\Tests\Stubs\ExampleMiddleware; |
| 10 | + |
| 11 | +class HistoryTest extends TestCase |
| 12 | +{ |
| 13 | + public function test_the_history_is_not_encrypted_or_cleared_by_default(): void |
| 14 | + { |
| 15 | + Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () { |
| 16 | + return Inertia::render('User/Edit'); |
| 17 | + }); |
| 18 | + |
| 19 | + $response = $this->withoutExceptionHandling()->get('/', [ |
| 20 | + 'X-Inertia' => 'true', |
| 21 | + ]); |
| 22 | + |
| 23 | + $response->assertSuccessful(); |
| 24 | + $response->assertJson([ |
| 25 | + 'component' => 'User/Edit', |
| 26 | + 'encryptHistory' => false, |
| 27 | + 'clearHistory' => false, |
| 28 | + ]); |
| 29 | + } |
| 30 | + |
| 31 | + public function test_the_history_can_be_encrypted(): void |
| 32 | + { |
| 33 | + Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () { |
| 34 | + Inertia::encryptHistory(); |
| 35 | + |
| 36 | + return Inertia::render('User/Edit'); |
| 37 | + }); |
| 38 | + |
| 39 | + $response = $this->withoutExceptionHandling()->get('/', [ |
| 40 | + 'X-Inertia' => 'true', |
| 41 | + ]); |
| 42 | + |
| 43 | + $response->assertSuccessful(); |
| 44 | + $response->assertJson([ |
| 45 | + 'component' => 'User/Edit', |
| 46 | + 'encryptHistory' => true, |
| 47 | + ]); |
| 48 | + } |
| 49 | + |
| 50 | + public function test_the_history_can_be_encrypted_globally(): void |
| 51 | + { |
| 52 | + Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () { |
| 53 | + Config::set('inertia.history.encrypt', true); |
| 54 | + |
| 55 | + return Inertia::render('User/Edit'); |
| 56 | + }); |
| 57 | + |
| 58 | + $response = $this->withoutExceptionHandling()->get('/', [ |
| 59 | + 'X-Inertia' => 'true', |
| 60 | + ]); |
| 61 | + |
| 62 | + $response->assertSuccessful(); |
| 63 | + $response->assertJson([ |
| 64 | + 'component' => 'User/Edit', |
| 65 | + 'encryptHistory' => true, |
| 66 | + ]); |
| 67 | + } |
| 68 | + |
| 69 | + public function test_the_history_can_be_encrypted_globally_and_overridden(): void |
| 70 | + { |
| 71 | + Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () { |
| 72 | + Config::set('inertia.history.encrypt', true); |
| 73 | + |
| 74 | + Inertia::encryptHistory(false); |
| 75 | + |
| 76 | + return Inertia::render('User/Edit'); |
| 77 | + }); |
| 78 | + |
| 79 | + $response = $this->withoutExceptionHandling()->get('/', [ |
| 80 | + 'X-Inertia' => 'true', |
| 81 | + ]); |
| 82 | + |
| 83 | + $response->assertSuccessful(); |
| 84 | + $response->assertJson([ |
| 85 | + 'component' => 'User/Edit', |
| 86 | + 'encryptHistory' => false, |
| 87 | + ]); |
| 88 | + } |
| 89 | + |
| 90 | + public function test_the_history_can_be_cleared(): void |
| 91 | + { |
| 92 | + Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () { |
| 93 | + Inertia::clearHistory(); |
| 94 | + |
| 95 | + return Inertia::render('User/Edit'); |
| 96 | + }); |
| 97 | + |
| 98 | + $response = $this->withoutExceptionHandling()->get('/', [ |
| 99 | + 'X-Inertia' => 'true', |
| 100 | + ]); |
| 101 | + |
| 102 | + $response->assertSuccessful(); |
| 103 | + $response->assertJson([ |
| 104 | + 'component' => 'User/Edit', |
| 105 | + 'clearHistory' => true, |
| 106 | + ]); |
| 107 | + } |
| 108 | +} |
0 commit comments