-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
123 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,8 @@ | |
|
||
class AlwaysProp | ||
{ | ||
/** @var mixed */ | ||
protected $value; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,72 +434,6 @@ public function test_exclude_props_from_partial_response(): void | |
$this->assertSame('123', $page->version); | ||
} | ||
|
||
public function test_nested_partial_props(): void | ||
{ | ||
$request = Request::create('/user/123', 'GET'); | ||
$request->headers->add(['X-Inertia' => 'true']); | ||
$request->headers->add(['X-Inertia-Partial-Component' => 'User/Edit']); | ||
$request->headers->add(['X-Inertia-Partial-Data' => 'auth.user,auth.refresh_token']); | ||
|
||
$props = [ | ||
'auth' => [ | ||
'user' => new LazyProp(function () { | ||
return [ | ||
'name' => 'Jonathan Reinink', | ||
'email' => '[email protected]', | ||
]; | ||
}), | ||
'refresh_token' => 'value', | ||
'token' => 'value', | ||
], | ||
'shared' => [ | ||
'flash' => 'value', | ||
], | ||
]; | ||
|
||
$response = new Response('User/Edit', $props); | ||
$response = $response->toResponse($request); | ||
$page = $response->getData(); | ||
|
||
$this->assertFalse(isset($page->props->shared)); | ||
$this->assertFalse(isset($page->props->auth->token)); | ||
$this->assertSame('Jonathan Reinink', $page->props->auth->user->name); | ||
$this->assertSame('[email protected]', $page->props->auth->user->email); | ||
$this->assertSame('value', $page->props->auth->refresh_token); | ||
} | ||
|
||
public function test_exclude_nested_props_from_partial_response(): void | ||
{ | ||
$request = Request::create('/user/123', 'GET'); | ||
$request->headers->add(['X-Inertia' => 'true']); | ||
$request->headers->add(['X-Inertia-Partial-Component' => 'User/Edit']); | ||
$request->headers->add(['X-Inertia-Partial-Data' => 'auth']); | ||
$request->headers->add(['X-Inertia-Partial-Except' => 'auth.user']); | ||
|
||
$props = [ | ||
'auth' => [ | ||
'user' => new LazyProp(function () { | ||
return [ | ||
'name' => 'Jonathan Reinink', | ||
'email' => '[email protected]', | ||
]; | ||
}), | ||
'refresh_token' => 'value', | ||
], | ||
'shared' => [ | ||
'flash' => 'value', | ||
], | ||
]; | ||
|
||
$response = new Response('User/Edit', $props); | ||
$response = $response->toResponse($request); | ||
$page = $response->getData(); | ||
|
||
$this->assertFalse(isset($page->props->auth->user)); | ||
$this->assertFalse(isset($page->props->shared)); | ||
$this->assertSame('value', $page->props->auth->refresh_token); | ||
} | ||
|
||
public function test_lazy_props_are_not_included_by_default(): void | ||
{ | ||
$request = Request::create('/users', 'GET'); | ||
|
@@ -678,4 +612,85 @@ public function test_the_page_url_doesnt_double_up(): void | |
|
||
$this->assertSame('/subpath/product/123', $page->url); | ||
} | ||
|
||
public function test_prop_as_basic_array(): void | ||
{ | ||
$request = Request::create('/years', 'GET'); | ||
|
||
$response = new Response('Years', ['years' => [2022, 2023, 2024]], 'app', '123'); | ||
$response = $response->toResponse($request); | ||
$view = $response->getOriginalContent(); | ||
$page = $view->getData()['page']; | ||
|
||
$this->assertSame([2022, 2023, 2024], $page['props']['years']); | ||
} | ||
|
||
public function test_dot_notation_props_are_merged_with_shared_props(): void | ||
{ | ||
$request = Request::create('/test', 'GET'); | ||
|
||
$response = new Response('Test', [ | ||
'auth' => ['user' => ['name' => 'Jonathan']], | ||
'auth.user.is_super' => true, | ||
], 'app', '123'); | ||
$response = $response->toResponse($request); | ||
$view = $response->getOriginalContent(); | ||
$page = $view->getData()['page']; | ||
|
||
$this->assertSame([ | ||
'auth' => [ | ||
'user' => [ | ||
'name' => 'Jonathan', | ||
'is_super' => true, | ||
], | ||
], | ||
], $page['props']); | ||
} | ||
|
||
public function test_dot_notation_props_are_merged_with_lazy_shared_props(): void | ||
{ | ||
$request = Request::create('/test', 'GET'); | ||
|
||
$response = new Response('Test', [ | ||
'auth' => function () { | ||
return ['user' => ['name' => 'Jonathan']]; | ||
}, | ||
'auth.user.is_super' => true, | ||
], 'app', '123'); | ||
|
||
$response = $response->toResponse($request); | ||
$view = $response->getOriginalContent(); | ||
$page = $view->getData()['page']; | ||
|
||
$this->assertSame([ | ||
'auth' => [ | ||
'user' => [ | ||
'name' => 'Jonathan', | ||
'is_super' => true, | ||
], | ||
], | ||
], $page['props']); | ||
} | ||
|
||
public function test_dot_notation_props_are_merged_with_other_dot_notation_props(): void | ||
{ | ||
$request = Request::create('/test', 'GET'); | ||
|
||
$response = new Response('Test', [ | ||
'auth.user' => ['name' => 'Jonathan'], | ||
'auth.user.is_super' => true, | ||
], 'app', '123'); | ||
$response = $response->toResponse($request); | ||
$view = $response->getOriginalContent(); | ||
$page = $view->getData()['page']; | ||
|
||
$this->assertSame([ | ||
'auth' => [ | ||
'user' => [ | ||
'name' => 'Jonathan', | ||
'is_super' => true, | ||
], | ||
], | ||
], $page['props']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,6 @@ | |
|
||
class ExampleMiddleware extends Middleware | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
protected $version; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters