@@ -292,26 +292,58 @@ public function test_lazy_props_are_included_in_partial_reload(): void
292
292
$ this ->assertSame ('A lazy value ' , $ page ->props ->lazy );
293
293
}
294
294
295
- public function test_can_nest_props_using_dot_notation (): void
295
+ public function test_top_level_dot_props_get_unpacked (): void
296
296
{
297
+ $ props = [
298
+ 'auth ' => [
299
+ 'user ' => [
300
+ 'name ' => 'Jonathan Reinink ' ,
301
+ ],
302
+ ],
303
+ 'auth.user.can ' => [
304
+ 'do.stuff ' => true ,
305
+ ],
306
+ 'product ' => ['name ' => 'My example product ' ],
307
+ ];
308
+
297
309
$ request = Request::create ('/products/123 ' , 'GET ' );
310
+ $ request ->headers ->add (['X-Inertia ' => 'true ' ]);
311
+
312
+ $ response = new Response ('User/Edit ' ,$ props , 'app ' , '123 ' );
313
+ $ response = $ response ->toResponse ($ request );
314
+ $ page = $ response ->getData (true );
315
+
316
+ $ user = $ page ['props ' ]['auth ' ]['user ' ];
317
+ $ this ->assertSame ('Jonathan Reinink ' , $ user ['name ' ]);
318
+ $ this ->assertTrue ($ user ['can ' ]['do.stuff ' ]);
319
+ $ this ->assertFalse (array_key_exists ('auth.user.can ' , $ page ['props ' ]));
320
+ }
298
321
322
+ public function test_nested_dot_props_do_not_get_unpacked (): void
323
+ {
299
324
$ props = [
300
325
'auth ' => [
326
+ 'user.can ' => [
327
+ 'do.stuff ' => true ,
328
+ ],
301
329
'user ' => [
302
330
'name ' => 'Jonathan Reinink ' ,
303
331
],
304
332
],
305
- 'auth.user.can.deleteProducts ' => true ,
306
333
'product ' => ['name ' => 'My example product ' ],
307
334
];
308
- $ response = new Response ('Products/Edit ' , $ props , 'app ' , '123 ' );
335
+
336
+ $ request = Request::create ('/products/123 ' , 'GET ' );
337
+ $ request ->headers ->add (['X-Inertia ' => 'true ' ]);
338
+
339
+ $ response = new Response ('User/Edit ' ,$ props , 'app ' , '123 ' );
309
340
$ response = $ response ->toResponse ($ request );
310
- $ view = $ response ->getOriginalContent ();
311
- $ user = $ view ->getData ()['page ' ]['props ' ]['auth ' ]['user ' ];
341
+ $ page = $ response ->getData (true );
312
342
313
- $ this ->assertSame ('Jonathan Reinink ' , $ user ['name ' ]);
314
- $ this ->assertTrue ($ user ['can ' ]['deleteProducts ' ]);
343
+ $ auth = $ page ['props ' ]['auth ' ];
344
+ $ this ->assertSame ('Jonathan Reinink ' , $ auth ['user ' ]['name ' ]);
345
+ $ this ->assertTrue ($ auth ['user.can ' ]['do.stuff ' ]);
346
+ $ this ->assertFalse (array_key_exists ('can ' , $ auth ));
315
347
}
316
348
317
349
public function test_responsable_with_invalid_key (): void
0 commit comments