Skip to content

Commit

Permalink
Merge pull request #672 from hydephp/add-html-page-tests
Browse files Browse the repository at this point in the history
Add HtmlPage tests
  • Loading branch information
caendesilva authored Nov 18, 2022
2 parents 1378dc1 + 5b2f0db commit 856b52c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
33 changes: 33 additions & 0 deletions packages/framework/tests/Feature/HydePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -138,13 +141,15 @@ 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()
{
$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());
}
Expand Down Expand Up @@ -870,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(
Expand Down
12 changes: 7 additions & 5 deletions packages/framework/tests/Feature/Services/SitemapServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');

Expand All @@ -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');

Expand Down

0 comments on commit 856b52c

Please sign in to comment.