From 10e145ea345d2aca22c81ec15d7af073c5ee803c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 15 May 2022 20:30:07 +0200 Subject: [PATCH] Add helpers to make it easier to refactor source paths --- src/Concerns/Internal/SourcePathHelpers.php | 56 ++++++++++++ src/Hyde.php | 2 + tests/Unit/SourcePathHelpersTest.php | 97 +++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 src/Concerns/Internal/SourcePathHelpers.php create mode 100644 tests/Unit/SourcePathHelpersTest.php diff --git a/src/Concerns/Internal/SourcePathHelpers.php b/src/Concerns/Internal/SourcePathHelpers.php new file mode 100644 index 00000000..43da80b3 --- /dev/null +++ b/src/Concerns/Internal/SourcePathHelpers.php @@ -0,0 +1,56 @@ +assertEquals( + Hyde::path('_posts'), + Hyde::getModelSourcePath(MarkdownPost::class) + ); + + $this->assertEquals( + Hyde::path('_pages'), + Hyde::getModelSourcePath(MarkdownPage::class) + ); + + $this->assertEquals( + Hyde::path('_docs'), + Hyde::getModelSourcePath(DocumentationPage::class) + ); + + $this->assertEquals( + Hyde::path('_pages'), + Hyde::getModelSourcePath(BladePage::class) + ); + } + + public function test_get_model_source_path_method_returns_path_to_file_for_model_classes() + { + $this->assertEquals( + Hyde::path('_posts'.DIRECTORY_SEPARATOR.'foo.md'), + Hyde::getModelSourcePath(MarkdownPost::class, 'foo.md') + ); + + $this->assertEquals( + Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), + Hyde::getModelSourcePath(MarkdownPage::class, 'foo.md') + ); + + $this->assertEquals( + Hyde::path('_docs'.DIRECTORY_SEPARATOR.'foo.md'), + Hyde::getModelSourcePath(DocumentationPage::class, 'foo.md') + ); + + $this->assertEquals( + Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), + Hyde::getModelSourcePath(BladePage::class, 'foo.md') + ); + } + + public function test_helper_for_blade_pages() + { + $this->assertEquals( + Hyde::path('_pages'), + Hyde::getBladePagePath() + ); + } + + public function test_helper_for_markdown_pages() + { + $this->assertEquals( + Hyde::path('_pages'), + Hyde::getMarkdownPagePath() + ); + } + + public function test_helper_for_markdown_posts() + { + $this->assertEquals( + Hyde::path('_posts'), + Hyde::getMarkdownPostPath() + ); + } + + public function test_helper_for_documentation_pages() + { + $this->assertEquals( + Hyde::path('_docs'), + Hyde::getDocumentationPagePath() + ); + } +}