@@ -256,6 +256,29 @@ public function test_xhr_partial_response(): void
256
256
$ this ->assertSame ('123 ' , $ page ->version );
257
257
}
258
258
259
+ public function test_exclude_props_from_partial_response (): void
260
+ {
261
+ $ request = Request::create ('/user/123 ' , 'GET ' );
262
+ $ request ->headers ->add (['X-Inertia ' => 'true ' ]);
263
+ $ request ->headers ->add (['X-Inertia-Partial-Component ' => 'User/Edit ' ]);
264
+ $ request ->headers ->add (['X-Inertia-Partial-Except ' => 'user ' ]);
265
+
266
+ $ user = (object ) ['name ' => 'Jonathan ' ];
267
+ $ response = new Response ('User/Edit ' , ['user ' => $ user , 'partial ' => 'partial-data ' ], 'app ' , '123 ' );
268
+ $ response = $ response ->toResponse ($ request );
269
+ $ page = $ response ->getData ();
270
+
271
+ $ props = get_object_vars ($ page ->props );
272
+
273
+ $ this ->assertInstanceOf (JsonResponse::class, $ response );
274
+ $ this ->assertSame ('User/Edit ' , $ page ->component );
275
+ $ this ->assertFalse (isset ($ props ['user ' ]));
276
+ $ this ->assertCount (1 , $ props );
277
+ $ this ->assertSame ('partial-data ' , $ page ->props ->partial );
278
+ $ this ->assertSame ('/user/123 ' , $ page ->url );
279
+ $ this ->assertSame ('123 ' , $ page ->version );
280
+ }
281
+
259
282
public function test_nested_partial_props (): void
260
283
{
261
284
$ request = Request::create ('/user/123 ' , 'GET ' );
@@ -275,8 +298,8 @@ public function test_nested_partial_props(): void
275
298
'token ' => 'value ' ,
276
299
],
277
300
'shared ' => [
278
- 'flash ' => 'Value ' ,
279
- ]
301
+ 'flash ' => 'value ' ,
302
+ ],
280
303
];
281
304
282
305
$ response = new Response ('User/Edit ' , $ props );
@@ -290,6 +313,38 @@ public function test_nested_partial_props(): void
290
313
$ this ->assertSame ('value ' , $ page ->props ->auth ->refresh_token );
291
314
}
292
315
316
+ public function test_exclude_nested_props_from_partial_response (): void
317
+ {
318
+ $ request = Request::create ('/user/123 ' , 'GET ' );
319
+ $ request ->headers ->add (['X-Inertia ' => 'true ' ]);
320
+ $ request ->headers ->add (['X-Inertia-Partial-Component ' => 'User/Edit ' ]);
321
+ $ request ->headers ->add (['X-Inertia-Partial-Data ' => 'auth ' ]);
322
+ $ request ->headers ->add (['X-Inertia-Partial-Except ' => 'auth.user ' ]);
323
+
324
+ $ props = [
325
+ 'auth ' => [
326
+ 'user ' => new LazyProp (function () {
327
+ return [
328
+ 'name ' => 'Jonathan Reinink ' ,
329
+ 'email ' => 'jonathan@example.com ' ,
330
+ ];
331
+ }),
332
+ 'refresh_token ' => 'value ' ,
333
+ ],
334
+ 'shared ' => [
335
+ 'flash ' => 'value ' ,
336
+ ],
337
+ ];
338
+
339
+ $ response = new Response ('User/Edit ' , $ props );
340
+ $ response = $ response ->toResponse ($ request );
341
+ $ page = $ response ->getData ();
342
+
343
+ $ this ->assertFalse (isset ($ page ->props ->auth ->user ));
344
+ $ this ->assertFalse (isset ($ page ->props ->shared ));
345
+ $ this ->assertSame ('value ' , $ page ->props ->auth ->refresh_token );
346
+ }
347
+
293
348
public function test_lazy_props_are_not_included_by_default (): void
294
349
{
295
350
$ request = Request::create ('/users ' , 'GET ' );
0 commit comments