From ab232dbb053b55d3f6786a35536b8251bd451dac Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 30 Aug 2023 14:24:19 +0100 Subject: [PATCH 1/3] Adds integration tests with `render` --- tests/Feature/ClassFolioTest.php | 17 ++++++++++++++ tests/Feature/FunctionalFolioTest.php | 17 ++++++++++++++ .../authorization-on-render.blade.php | 17 ++++++++++++++ .../authorization-with-mount.blade.php | 2 +- .../page-with-view-content.blade.php | 22 +++++++++++++++++++ .../authorization-on-render.blade.php | 14 ++++++++++++ .../page-with-view-content.blade.php | 18 +++++++++++++++ 7 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/resources/views/class-api-pages/authorization-on-render.blade.php create mode 100644 tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php create mode 100644 tests/Feature/resources/views/functional-api-pages/authorization-on-render.blade.php create mode 100644 tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php diff --git a/tests/Feature/ClassFolioTest.php b/tests/Feature/ClassFolioTest.php index 757f6b1..82874cc 100644 --- a/tests/Feature/ClassFolioTest.php +++ b/tests/Feature/ClassFolioTest.php @@ -113,3 +113,20 @@ $response->assertStatus(200)->assertSee('Page Livewire Styles and Scripts'); }); + +test('page with view content', function () { + Folio::route(__DIR__.'/resources/views/class-api-pages'); + + $response = $this->get('page-with-view-content'); + + $response->assertStatus(200) + ->assertSee('Hello from view.'); +}); + +test('page with authorization on render', function () { + Folio::route(__DIR__.'/resources/views/class-api-pages'); + + $response = $this->get('authorization-on-render'); + + $response->assertStatus(403); +}); diff --git a/tests/Feature/FunctionalFolioTest.php b/tests/Feature/FunctionalFolioTest.php index 92b6b87..ed51d12 100644 --- a/tests/Feature/FunctionalFolioTest.php +++ b/tests/Feature/FunctionalFolioTest.php @@ -139,3 +139,20 @@ ->assertSeeVolt('fragment-component') ->assertOk(); }); + +test('page with view content', function () { + Folio::route(__DIR__.'/resources/views/functional-api-pages'); + + $response = $this->get('page-with-view-content'); + + $response->assertStatus(200) + ->assertSee('Hello from view.'); +}); + +test('page with authorization on render', function () { + Folio::route(__DIR__.'/resources/views/functional-api-pages'); + + $response = $this->get('authorization-on-render'); + + $response->assertStatus(403); +}); diff --git a/tests/Feature/resources/views/class-api-pages/authorization-on-render.blade.php b/tests/Feature/resources/views/class-api-pages/authorization-on-render.blade.php new file mode 100644 index 0000000..c4b6304 --- /dev/null +++ b/tests/Feature/resources/views/class-api-pages/authorization-on-render.blade.php @@ -0,0 +1,17 @@ + abort(403, 'Unauthorized action from middleware')); + +new class extends Component +{ + public string $content = 'Hello world'; +} ?> + +
+ @volt + {{ $content }} + @endvolt +
diff --git a/tests/Feature/resources/views/class-api-pages/authorization-with-mount.blade.php b/tests/Feature/resources/views/class-api-pages/authorization-with-mount.blade.php index cce6013..d507db0 100644 --- a/tests/Feature/resources/views/class-api-pages/authorization-with-mount.blade.php +++ b/tests/Feature/resources/views/class-api-pages/authorization-with-mount.blade.php @@ -1,6 +1,6 @@ abort(403, 'Unauthorized action from middleware')); diff --git a/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php b/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php new file mode 100644 index 0000000..2b48614 --- /dev/null +++ b/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php @@ -0,0 +1,22 @@ + $view->with('name', 'from view')); + +new class extends Component +{ + public string $name = 'from component'; +} + +?> + +
+ @volt('fragment-component') +
+ Hello {{ $name }}. +
+ @endvolt +
diff --git a/tests/Feature/resources/views/functional-api-pages/authorization-on-render.blade.php b/tests/Feature/resources/views/functional-api-pages/authorization-on-render.blade.php new file mode 100644 index 0000000..47b6926 --- /dev/null +++ b/tests/Feature/resources/views/functional-api-pages/authorization-on-render.blade.php @@ -0,0 +1,14 @@ + abort(403, 'Unauthorized action from middleware')); + +state('content', 'Hello world'); ?> + +
+ @volt + {{ $content }} + @endvolt +
diff --git a/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php b/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php new file mode 100644 index 0000000..003b2c6 --- /dev/null +++ b/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php @@ -0,0 +1,18 @@ + $view->with('name', 'from view')); + +state('name', 'from component'); ?> + +
+ @volt('fragment-component') +
+ Hello {{ $name }}. +
+ @endvolt +
From dd662861eb2f2556b720dde37e696e393f39f6f0 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 30 Aug 2023 14:27:23 +0100 Subject: [PATCH 2/3] Increase Folio's requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1d88ec4..9cd78f8 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "livewire/livewire": "^3.0" }, "require-dev": { - "laravel/folio": "^1.0", + "laravel/folio": "^1.1", "mockery/mockery": "^1.6", "orchestra/testbench": "^8.6.2", "pestphp/pest": "^2.9.5", From d003dda3bbc98453b7596e4f99d4c7c601c2271b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 30 Aug 2023 16:33:47 +0100 Subject: [PATCH 3/3] Fixes duplicated component name in tests --- .../views/class-api-pages/page-with-view-content.blade.php | 2 +- .../views/functional-api-pages/page-with-view-content.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php b/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php index 2b48614..0a06ea8 100644 --- a/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php +++ b/tests/Feature/resources/views/class-api-pages/page-with-view-content.blade.php @@ -14,7 +14,7 @@ ?>
- @volt('fragment-component') + @volt
Hello {{ $name }}.
diff --git a/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php b/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php index 003b2c6..1457c72 100644 --- a/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php +++ b/tests/Feature/resources/views/functional-api-pages/page-with-view-content.blade.php @@ -10,7 +10,7 @@ state('name', 'from component'); ?>
- @volt('fragment-component') + @volt
Hello {{ $name }}.