|
2 | 2 |
|
3 | 3 | namespace Inertia\Tests;
|
4 | 4 |
|
| 5 | +use Illuminate\Filesystem\Filesystem; |
5 | 6 | use Illuminate\Http\Request;
|
6 | 7 | use Illuminate\Session\Middleware\StartSession;
|
7 | 8 | use Illuminate\Support\Facades\Route;
|
|
13 | 14 | use Inertia\Middleware;
|
14 | 15 | use Inertia\Tests\Stubs\ExampleMiddleware;
|
15 | 16 | use LogicException;
|
| 17 | +use PHPUnit\Framework\Attributes\After; |
16 | 18 |
|
17 | 19 | class MiddlewareTest extends TestCase
|
18 | 20 | {
|
| 21 | + #[After] |
| 22 | + public function cleanupPublicFolder(): void |
| 23 | + { |
| 24 | + (new Filesystem)->cleanDirectory(public_path()); |
| 25 | + } |
| 26 | + |
19 | 27 | public function test_no_response_value_by_default_means_automatically_redirecting_back_for_inertia_requests(): void
|
20 | 28 | {
|
21 | 29 | $fooCalled = false;
|
@@ -241,6 +249,49 @@ public function rootView(Request $request): string
|
241 | 249 | $response->assertViewIs('welcome');
|
242 | 250 | }
|
243 | 251 |
|
| 252 | + public function test_determine_the_version_by_a_hash_of_the_asset_url(): void |
| 253 | + { |
| 254 | + config(['app.asset_url' => $url = 'https://example.com/assets']); |
| 255 | + |
| 256 | + $this->prepareMockEndpoint(middleware: new Middleware); |
| 257 | + |
| 258 | + $response = $this->get('/'); |
| 259 | + $response->assertOk(); |
| 260 | + $response->assertViewHas('page.version', hash('xxh128', $url)); |
| 261 | + } |
| 262 | + |
| 263 | + public function test_determine_the_version_by_a_hash_of_the_vite_manifest(): void |
| 264 | + { |
| 265 | + $filesystem = new Filesystem; |
| 266 | + $filesystem->ensureDirectoryExists(public_path('build')); |
| 267 | + $filesystem->put( |
| 268 | + public_path('build/manifest.json'), |
| 269 | + $contents = json_encode(['vite' => true]) |
| 270 | + ); |
| 271 | + |
| 272 | + $this->prepareMockEndpoint(middleware: new Middleware); |
| 273 | + |
| 274 | + $response = $this->get('/'); |
| 275 | + $response->assertOk(); |
| 276 | + $response->assertViewHas('page.version', hash('xxh128', $contents)); |
| 277 | + } |
| 278 | + |
| 279 | + public function test_determine_the_version_by_a_hash_of_the_mix_manifest(): void |
| 280 | + { |
| 281 | + $filesystem = new Filesystem; |
| 282 | + $filesystem->ensureDirectoryExists(public_path()); |
| 283 | + $filesystem->put( |
| 284 | + public_path('mix-manifest.json'), |
| 285 | + $contents = json_encode(['mix' => true]) |
| 286 | + ); |
| 287 | + |
| 288 | + $this->prepareMockEndpoint(middleware: new Middleware); |
| 289 | + |
| 290 | + $response = $this->get('/'); |
| 291 | + $response->assertOk(); |
| 292 | + $response->assertViewHas('page.version', hash('xxh128', $contents)); |
| 293 | + } |
| 294 | + |
244 | 295 | private function prepareMockEndpoint($version = null, $shared = [], $middleware = null): \Illuminate\Routing\Route
|
245 | 296 | {
|
246 | 297 | if (is_null($middleware)) {
|
|
0 commit comments