Skip to content

Commit

Permalink
Unit test the accessor method on all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 23, 2024
1 parent 781e387 commit f9236a4
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/BladePageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,21 @@ public function testMatter()
{
$this->assertInstanceOf(FrontMatter::class, (new BladePage('foo'))->matter());
}

public function testGetCanonicalUrl()
{
$page = new BladePage('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/foo', $page->getCanonicalUrl());

$page = new BladePage('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/DocumentationPageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,21 @@ public function testSave()
$this->assertFileExists('_docs/foo.md');
Filesystem::unlink('_docs/foo.md');
}

public function testGetCanonicalUrl()
{
$page = new DocumentationPage('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/docs/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/docs/foo', $page->getCanonicalUrl());

$page = new DocumentationPage('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/HtmlPageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,21 @@ public function testMatter()
{
$this->assertInstanceOf(FrontMatter::class, (new HtmlPage('404'))->matter());
}

public function testGetCanonicalUrl()
{
$page = new HtmlPage('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/foo', $page->getCanonicalUrl());

$page = new HtmlPage('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/InMemoryPageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,21 @@ public function testMatter()
{
$this->assertInstanceOf(FrontMatter::class, (new InMemoryPage('404'))->matter());
}

public function testGetCanonicalUrl()
{
$page = new InMemoryPage('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/foo', $page->getCanonicalUrl());

$page = new InMemoryPage('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/MarkdownPageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,21 @@ public function testSave()
$this->assertFileExists('_pages/foo.md');
Filesystem::unlink('_pages/foo.md');
}

public function testGetCanonicalUrl()
{
$page = new MarkdownPage('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/foo', $page->getCanonicalUrl());

$page = new MarkdownPage('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}
17 changes: 17 additions & 0 deletions packages/framework/tests/Unit/Pages/MarkdownPostUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,21 @@ public function testSave()
$this->assertFileExists('_posts/foo.md');
Filesystem::unlink('_posts/foo.md');
}

public function testGetCanonicalUrl()
{
$page = new MarkdownPost('foo');
$this->assertNull($page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com']);

$this->assertSame('https://example.com/posts/foo.html', $page->getCanonicalUrl());

self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);

$this->assertSame('https://example.com/posts/foo', $page->getCanonicalUrl());

$page = new MarkdownPost('foo', ['canonicalUrl' => 'foo']);
$this->assertSame('foo', $page->getCanonicalUrl());
}
}

0 comments on commit f9236a4

Please sign in to comment.