diff --git a/tests/Feature/HydePageTest.php b/tests/Feature/HydePageTest.php index 6e24facf..ac6d2051 100644 --- a/tests/Feature/HydePageTest.php +++ b/tests/Feature/HydePageTest.php @@ -27,51 +27,106 @@ */ class HydePageTest extends TestCase { - protected function tearDown(): void + // Section: Baseline tests + + public function testSourceDirectory() { - BladePage::$sourceDirectory = '_pages'; - MarkdownPage::$sourceDirectory = '_pages'; - MarkdownPost::$sourceDirectory = '_posts'; - DocumentationPage::$sourceDirectory = '_docs'; - MarkdownPage::$fileExtension = '.md'; + $this->assertSame( + 'source', + HandlesPageFilesystemTestClass::sourceDirectory() + ); + } - parent::tearDown(); + public function testOutputDirectory() + { + $this->assertSame( + 'output', + HandlesPageFilesystemTestClass::outputDirectory() + ); } + public function testFileExtension() + { + $this->assertSame( + '.md', + HandlesPageFilesystemTestClass::fileExtension() + ); + } + + public function testSourcePath() + { + $this->assertSame( + 'source/hello-world.md', + HandlesPageFilesystemTestClass::sourcePath('hello-world') + ); + } + + public function testOutputPath() + { + $this->assertSame( + 'output/hello-world.html', + HandlesPageFilesystemTestClass::outputPath('hello-world') + ); + } + + public function testGetSourcePath() + { + $this->assertSame( + 'source/hello-world.md', + (new HandlesPageFilesystemTestClass('hello-world'))->getSourcePath() + ); + } + + public function testGetOutputPath() + { + $this->assertSame( + 'output/hello-world.html', + (new HandlesPageFilesystemTestClass('hello-world'))->getOutputPath() + ); + } + + // Section: In-depth tests + public function test_get_source_directory_returns_static_property() { MarkdownPage::$sourceDirectory = 'foo'; $this->assertEquals('foo', MarkdownPage::sourceDirectory()); + $this->resetDirectoryConfiguration(); } public function test_get_source_directory_trims_trailing_slashes() { MarkdownPage::$sourceDirectory = '/foo/\\'; $this->assertEquals('foo', MarkdownPage::sourceDirectory()); + $this->resetDirectoryConfiguration(); } public function test_get_output_directory_returns_static_property() { MarkdownPage::$outputDirectory = 'foo'; $this->assertEquals('foo', MarkdownPage::outputDirectory()); + $this->resetDirectoryConfiguration(); } public function test_get_output_directory_trims_trailing_slashes() { MarkdownPage::$outputDirectory = '/foo/\\'; $this->assertEquals('foo', MarkdownPage::outputDirectory()); + $this->resetDirectoryConfiguration(); } public function test_get_file_extension_returns_static_property() { MarkdownPage::$fileExtension = '.foo'; $this->assertEquals('.foo', MarkdownPage::fileExtension()); + $this->resetDirectoryConfiguration(); } public function test_get_file_extension_forces_leading_period() { MarkdownPage::$fileExtension = 'foo'; $this->assertEquals('.foo', MarkdownPage::fileExtension()); + $this->resetDirectoryConfiguration(); } public function test_get_identifier_returns_identifier_property() @@ -128,6 +183,7 @@ public function test_qualify_basename_uses_the_static_properties() MarkdownPage::$sourceDirectory = 'foo'; MarkdownPage::$fileExtension = 'txt'; $this->assertEquals('foo/bar.txt', MarkdownPage::sourcePath('bar')); + $this->resetDirectoryConfiguration(); } public function test_get_output_location_returns_the_file_output_path_for_the_supplied_basename() @@ -139,12 +195,14 @@ public function test_get_output_location_returns_the_configured_location() { MarkdownPage::$outputDirectory = 'foo'; $this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar')); + $this->resetDirectoryConfiguration(); } public function test_get_output_location_trims_trailing_slashes_from_directory_setting() { MarkdownPage::$outputDirectory = '/foo/\\'; $this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar')); + $this->resetDirectoryConfiguration(); } public function test_get_output_location_trims_trailing_slashes_from_basename() @@ -163,6 +221,7 @@ public function test_get_current_page_path_returns_output_directory_and_basename MarkdownPage::$outputDirectory = 'foo'; $page = new MarkdownPage('bar'); $this->assertEquals('foo/bar', $page->getRouteKey()); + $this->resetDirectoryConfiguration(); } public function test_get_current_page_path_trims_trailing_slashes_from_directory_setting() @@ -170,6 +229,7 @@ public function test_get_current_page_path_trims_trailing_slashes_from_directory MarkdownPage::$outputDirectory = '/foo/\\'; $page = new MarkdownPage('bar'); $this->assertEquals('foo/bar', $page->getRouteKey()); + $this->resetDirectoryConfiguration(); } public function test_get_output_path_returns_current_page_path_with_html_extension_appended() @@ -675,4 +735,26 @@ public function test_save_method_writes_page_body_to_file_with_front_matter() ); unlink(Hyde::path('_pages/foo.md')); } + + protected function resetDirectoryConfiguration(): void + { + BladePage::$sourceDirectory = '_pages'; + MarkdownPage::$sourceDirectory = '_pages'; + MarkdownPost::$sourceDirectory = '_posts'; + DocumentationPage::$sourceDirectory = '_docs'; + MarkdownPage::$fileExtension = '.md'; + } +} + +class HandlesPageFilesystemTestClass extends HydePage +{ + public static string $sourceDirectory = 'source'; + public static string $outputDirectory = 'output'; + public static string $fileExtension = '.md'; + public static string $template = 'template'; + + public function compile(): string + { + return ''; + } } diff --git a/tests/Unit/HydePageFileHelpersTest.php b/tests/Unit/HydePageFileHelpersTest.php deleted file mode 100644 index e98c407e..00000000 --- a/tests/Unit/HydePageFileHelpersTest.php +++ /dev/null @@ -1,81 +0,0 @@ -assertSame( - 'source', - HandlesPageFilesystemTestClass::sourceDirectory() - ); - } - - public function testOutputDirectory() - { - $this->assertSame( - 'output', - HandlesPageFilesystemTestClass::outputDirectory() - ); - } - - public function testFileExtension() - { - $this->assertSame( - '.md', - HandlesPageFilesystemTestClass::fileExtension() - ); - } - - public function testSourcePath() - { - $this->assertSame( - 'source/hello-world.md', - HandlesPageFilesystemTestClass::sourcePath('hello-world') - ); - } - - public function testOutputPath() - { - $this->assertSame( - 'output/hello-world.html', - HandlesPageFilesystemTestClass::outputPath('hello-world') - ); - } - - public function testGetSourcePath() - { - $this->assertSame( - 'source/hello-world.md', - (new HandlesPageFilesystemTestClass('hello-world'))->getSourcePath() - ); - } - - public function testGetOutputPath() - { - $this->assertSame( - 'output/hello-world.html', - (new HandlesPageFilesystemTestClass('hello-world'))->getOutputPath() - ); - } -} - -class HandlesPageFilesystemTestClass extends HydePage -{ - public static string $sourceDirectory = 'source'; - public static string $outputDirectory = 'output'; - public static string $fileExtension = '.md'; - public static string $template = 'template'; - - public function compile(): string - { - return ''; - } -}