diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 78a5468a24e..408ef6b6d22 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -4,15 +4,11 @@ namespace Hyde\Framework\Actions; -use function file_exists; -use function file_get_contents; use Hyde\Framework\Concerns\InvokableAction; use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Framework\Features\Publications\PublicationService; -use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Illuminate\Support\Facades\Blade; -use InvalidArgumentException; use function view; /** @@ -46,9 +42,7 @@ public function compilePublicationPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return Blade::render( - file_get_contents(Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php")), $data - ); + return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data); } public function compilePublicationListPage(): string @@ -63,13 +57,6 @@ public function compilePublicationListPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php'; - if (! file_exists($viewPath)) { - throw new InvalidArgumentException("View [$viewPath] not found."); - } - - return Blade::render( - file_get_contents($viewPath), $data - ); + return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data); } } diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index f254c3a8cea..a873becfb74 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature\Actions; use Hyde\Framework\Actions\PublicationPageCompiler; +use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Pages\PublicationPage; @@ -15,7 +16,7 @@ */ class PublicationPageCompilerTest extends TestCase { - public function testCanCompilePublicationPages() + public function test_can_compile_publication_pages() { $this->directory('test-publication'); $this->setupTestPublication(); @@ -27,7 +28,7 @@ public function testCanCompilePublicationPages() $this->assertEquals('Detail: My Publication', $string); } - public function testCanCompilePublicationListPages() + public function test_can_compile_publication_list_pages() { $this->directory('test-publication'); $this->setupTestPublication(); @@ -39,4 +40,26 @@ public function testCanCompilePublicationListPages() $this->assertEquals('List: My Publication', $string); } + + public function test_with_missing_detail_blade_view() + { + $this->directory('test-publication'); + $this->setupTestPublication(); + + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('File test-publication/test-publication_detail.blade.php not found.'); + + PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication'))); + } + + public function test_with_missing_list_blade_view() + { + $this->directory('test-publication'); + $this->setupTestPublication(); + + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('File test-publication/test-publication_list.blade.php not found.'); + + PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); + } }