-
-
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 #1338 from hydephp/ensure-documentation-pages-can-…
…be-compiled-to-site-root Add test for the documentation page compiler module
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
packages/framework/tests/Feature/StaticSiteBuilderDocumentationModuleTest.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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Testing\Feature; | ||
|
||
use Hyde\Framework\Actions\StaticPageBuilder; | ||
use Hyde\Hyde; | ||
use Hyde\Pages\DocumentationPage; | ||
use Hyde\Testing\TestCase; | ||
|
||
/** | ||
* Test the documentation page compiler module. | ||
*/ | ||
class StaticSiteBuilderDocumentationModuleTest extends TestCase | ||
{ | ||
protected DocumentationPage $page; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->page = DocumentationPage::make('test-page', [ | ||
'title' => 'Adventures in Wonderland', | ||
'description' => 'All in the golden afternoon, full leisurely we glide.', | ||
], <<<'MARKDOWN' | ||
## CHAPTER I. DOWN THE RABBIT-HOLE. | ||
So she was considering in her own mind, as well as she could, for the hot day made her feel very sleepy and stupid. | ||
MARKDOWN | ||
); | ||
} | ||
|
||
protected function inspectHtml(array $expectedStrings, string $path = null) | ||
{ | ||
StaticPageBuilder::handle($this->page); | ||
$stream = file_get_contents(Hyde::path($path ?? '_site/docs/test-page.html')); | ||
$this->cleanUpWhenDone($path ?? '_site/docs/test-page.html'); | ||
|
||
foreach ($expectedStrings as $expectedString) { | ||
$this->assertStringContainsString($expectedString, $stream); | ||
} | ||
} | ||
|
||
public function test_can_create_page() | ||
{ | ||
StaticPageBuilder::handle($this->page); | ||
|
||
$this->assertFileExists(Hyde::path('_site/docs/test-page.html')); | ||
|
||
unlink(Hyde::path('_site/docs/test-page.html')); | ||
} | ||
|
||
public function test_page_contains_expected_content() | ||
{ | ||
$this->inspectHtml([ | ||
'Adventures in Wonderland', | ||
'<h2>CHAPTER I. DOWN THE RABBIT-HOLE.<a id="chapter-i-down-the-rabbit-hole" href="#chapter-i-down-the-rabbit-hole" class="heading-permalink" aria-hidden="true" title="Permalink">#</a></h2>', | ||
'<p>So she was considering in her own mind, as well as she could', | ||
]); | ||
} | ||
|
||
public function test_can_compile_page_to_root_output_directory() | ||
{ | ||
DocumentationPage::setOutputDirectory(''); | ||
|
||
$this->inspectHtml([ | ||
'Adventures in Wonderland', | ||
'<h2>CHAPTER I. DOWN THE RABBIT-HOLE.<a id="chapter-i-down-the-rabbit-hole" href="#chapter-i-down-the-rabbit-hole" class="heading-permalink" aria-hidden="true" title="Permalink">#</a></h2>', | ||
'<p>So she was considering in her own mind, as well as she could', | ||
], '_site/test-page.html'); | ||
} | ||
} |