From 4b9420db5a676dfa3be8c288e07102c0dccc2896 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 19:16:25 +0100 Subject: [PATCH 1/5] Add tests for HtmlPages --- packages/framework/tests/Feature/HydePageTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index 43e53f63449..03dde8de876 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -10,6 +10,7 @@ use Hyde\Pages\Concerns\BaseMarkdownPage; use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\DocumentationPage; +use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Support\Models\Route; @@ -122,6 +123,7 @@ public function testShowInNavigation() $this->assertTrue((new MarkdownPage())->showInNavigation()); $this->assertTrue((new DocumentationPage())->showInNavigation()); $this->assertFalse((new MarkdownPost())->showInNavigation()); + $this->assertTrue((new HtmlPage())->showInNavigation()); } public function testNavigationMenuPriority() @@ -130,6 +132,7 @@ public function testNavigationMenuPriority() $this->assertSame(999, (new MarkdownPage())->navigationMenuPriority()); $this->assertSame(999, (new DocumentationPage())->navigationMenuPriority()); $this->assertSame(10, (new MarkdownPost())->navigationMenuPriority()); + $this->assertSame(999, (new HtmlPage())->navigationMenuPriority()); } public function testNavigationMenuLabel() @@ -138,6 +141,7 @@ public function testNavigationMenuLabel() $this->assertSame('Foo', (new MarkdownPage('foo'))->navigationMenuLabel()); $this->assertSame('Foo', (new MarkdownPost('foo'))->navigationMenuLabel()); $this->assertSame('Foo', (new DocumentationPage('foo'))->navigationMenuLabel()); + $this->assertSame('Foo', (new HtmlPage('foo'))->navigationMenuLabel()); } public function testNavigationMenuGroup() @@ -145,6 +149,7 @@ public function testNavigationMenuGroup() $this->assertNull((new BladePage('foo'))->navigationMenuGroup()); $this->assertNull((new MarkdownPage())->navigationMenuGroup()); $this->assertNull((new MarkdownPost())->navigationMenuGroup()); + $this->assertNull((new HtmlPage())->navigationMenuGroup()); $this->assertSame('other', (new DocumentationPage())->navigationMenuGroup()); $this->assertSame('foo', DocumentationPage::make(matter: ['navigation' => ['group' => 'foo']])->navigationMenuGroup()); } From d525f69d648243016826c0d92db7fa10c310114a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 19:27:07 +0100 Subject: [PATCH 2/5] Test all pages are routable --- .../framework/tests/Feature/HydePageTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index 03dde8de876..a620809be30 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -875,6 +875,34 @@ public function test_path_helpers_return_same_result_as_fluent_filesystem_helper $this->assertSameIgnoringDirSeparatorType(DocumentationPage::path('foo'), Hyde::getDocumentationPagePath('foo')); } + public function test_all_pages_are_routable() + { + $pages = [ + BladePage::class, + MarkdownPage::class, + MarkdownPost::class, + DocumentationPage::class, + HtmlPage::class, + ]; + + /** @var HydePage $page */ + foreach ($pages as $page) { + $page = new $page('foo'); + + $this->assertInstanceOf(Route::class, $page->getRoute()); + $this->assertEquals(new Route($page), $page->getRoute()); + $this->assertSame($page->getRoute()->getLink(), $page->getLink()); + + Hyde::touch($page::sourcePath('foo')); + Hyde::boot(); + + $this->assertArrayHasKey($page->getSourcePath(), Hyde::pages()); + $this->assertArrayHasKey($page->getRouteKey(), Hyde::routes()); + + unlink($page::sourcePath('foo')); + } + } + protected function assertSameIgnoringDirSeparatorType(string $expected, string $actual): void { $this->assertSame( From ca6cedac37d0319f7b96f6587329393c8f9872da Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 19:28:43 +0100 Subject: [PATCH 3/5] Test HtmlPages are added to the sitemap --- .../tests/Feature/Services/SitemapServiceTest.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/Services/SitemapServiceTest.php b/packages/framework/tests/Feature/Services/SitemapServiceTest.php index e4acad13d47..bd47835b3ae 100644 --- a/packages/framework/tests/Feature/Services/SitemapServiceTest.php +++ b/packages/framework/tests/Feature/Services/SitemapServiceTest.php @@ -134,6 +134,7 @@ public function test_all_route_types_are_discovered() $files = [ '_pages/blade.blade.php', '_pages/markdown.md', + '_pages/html.html', '_posts/post.md', '_docs/doc.md', ]; @@ -143,12 +144,13 @@ public function test_all_route_types_are_discovered() $service = new SitemapGenerator(); $service->generate(); - $this->assertCount(4, $service->getXmlElement()->url); + $this->assertCount(5, $service->getXmlElement()->url); - $this->assertEquals('foo/blade.html', $service->getXmlElement()->url[0]->loc); - $this->assertEquals('foo/markdown.html', $service->getXmlElement()->url[1]->loc); - $this->assertEquals('foo/posts/post.html', $service->getXmlElement()->url[2]->loc); - $this->assertEquals('foo/docs/doc.html', $service->getXmlElement()->url[3]->loc); + $this->assertEquals('foo/html.html', $service->getXmlElement()->url[0]->loc); + $this->assertEquals('foo/blade.html', $service->getXmlElement()->url[1]->loc); + $this->assertEquals('foo/markdown.html', $service->getXmlElement()->url[2]->loc); + $this->assertEquals('foo/posts/post.html', $service->getXmlElement()->url[3]->loc); + $this->assertEquals('foo/docs/doc.html', $service->getXmlElement()->url[4]->loc); Hyde::unlink($files); From e7dca55208c506719bf8d159e09b028ffc657b7a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 19:32:11 +0100 Subject: [PATCH 4/5] Inline property for test paths --- packages/framework/tests/Feature/HtmlPageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/HtmlPageTest.php b/packages/framework/tests/Feature/HtmlPageTest.php index 5d9752f4fa8..d71e6d24735 100644 --- a/packages/framework/tests/Feature/HtmlPageTest.php +++ b/packages/framework/tests/Feature/HtmlPageTest.php @@ -14,7 +14,7 @@ class HtmlPageTest extends TestCase { public function testHtmlPageCanBeCompiled() { - $this->file(HtmlPage::$sourceDirectory.'/foo.html', 'bar'); + $this->file('_pages/foo.html', 'bar'); $page = new HtmlPage('foo'); @@ -23,7 +23,7 @@ public function testHtmlPageCanBeCompiled() public function testCompileMethodUsesContents() { - $this->file(HtmlPage::$sourceDirectory.'/foo.html', 'bar'); + $this->file('_pages/foo.html', 'bar'); $page = new HtmlPage('foo'); From 5b2f0db4c88541c829bcb1234fd5d453a749587d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 19:32:41 +0100 Subject: [PATCH 5/5] Move unit test to unit tests namespace --- packages/framework/tests/{Feature => Unit}/HtmlPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/framework/tests/{Feature => Unit}/HtmlPageTest.php (93%) diff --git a/packages/framework/tests/Feature/HtmlPageTest.php b/packages/framework/tests/Unit/HtmlPageTest.php similarity index 93% rename from packages/framework/tests/Feature/HtmlPageTest.php rename to packages/framework/tests/Unit/HtmlPageTest.php index d71e6d24735..7e51c645577 100644 --- a/packages/framework/tests/Feature/HtmlPageTest.php +++ b/packages/framework/tests/Unit/HtmlPageTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Feature; +namespace Hyde\Framework\Testing\Unit; use Hyde\Pages\HtmlPage; use Hyde\Testing\TestCase;