-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from hydephp/371-add-test-to-ensure-pre-compu…
…ted-relative-links-are-retained-when-rendering-new-pages Add test to ensure pre-computed relative links are retained when rendering new pages
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
packages/framework/tests/Feature/RelativeLinksAcrossPagesRetainsIntegrityTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Testing\Feature; | ||
|
||
use Hyde\Framework\Concerns\InteractsWithDirectories; | ||
use Hyde\Framework\Hyde; | ||
use Hyde\Testing\TestCase; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class RelativeLinksAcrossPagesRetainsIntegrityTest extends TestCase | ||
{ | ||
use InteractsWithDirectories; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->needsDirectory('_pages/nested'); | ||
$this->file('_pages/root.md'); | ||
$this->file('_pages/root1.md'); | ||
Hyde::touch('_pages/nested/level1.md'); | ||
Hyde::touch('_pages/nested/level1b.md'); | ||
|
||
$this->file('_docs/index.md'); | ||
$this->file('_docs/docs.md'); | ||
|
||
$this->mockConsoleOutput = false; | ||
$this->artisan('make:post -n'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
File::deleteDirectory(Hyde::path('_pages/nested')); | ||
Hyde::unlink('_site/root.html'); | ||
Hyde::unlink('_site/root1.html'); | ||
$this->resetSite(); | ||
$this->resetPosts(); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
protected function assertSee(string $page, string|array $text): void | ||
{ | ||
if (is_array($text)) { | ||
foreach ($text as $string) { | ||
$this->assertSee($page, $string); | ||
} | ||
|
||
return; | ||
} | ||
|
||
$this->assertStringContainsString($text, | ||
file_get_contents(Hyde::path("_site/$page.html")), | ||
"Failed asserting that the page '$page' contains the text '$text'"); | ||
} | ||
|
||
public function test_relative_links_across_pages_retains_integrity() | ||
{ | ||
$this->artisan('build'); | ||
|
||
$this->assertSee('root', [ | ||
'<link rel="stylesheet" href="media/app.css">', | ||
'<a href="index.html"', | ||
'<a href="docs/index.html"', | ||
'<a href="root.html" aria-current="page"', | ||
'<a href="root1.html"', | ||
'<a href="nested/level1.html"', | ||
'<a href="nested/level1b.html"', | ||
]); | ||
|
||
$this->assertSee('nested/level1', [ | ||
'<link rel="stylesheet" href="../media/app.css">', | ||
'<a href="../index.html"', | ||
'<a href="../docs/index.html"', | ||
'<a href="../root.html"', | ||
'<a href="../root1.html"', | ||
'<a href="../nested/level1.html" aria-current="page"', | ||
'<a href="../nested/level1b.html"', | ||
]); | ||
|
||
$this->assertSee('docs/index', [ | ||
'<link rel="stylesheet" href="../media/app.css">', | ||
'<a href="../docs/index.html">', | ||
'<a href="../docs/docs.html"', | ||
'<a href="../index.html">Back to home page</a>', | ||
]); | ||
} | ||
} |