From aa812fad4b738653ff8066777327c7ac717bd8ea Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 2 Dec 2024 11:35:11 +0100 Subject: [PATCH] Implement the high level feature test --- .../Feature/MarkdownHeadingRendererTest.php | 136 +++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php index 11b5075f75e..a4c4f94f2dc 100644 --- a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php +++ b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php @@ -5,13 +5,145 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Testing\TestCase; +use Hyde\Framework\Services\MarkdownService; +use Hyde\Pages\DocumentationPage; +use Hyde\Pages\MarkdownPage; /** * @covers \Hyde\Markdown\Processing\HeadingRenderer - * + * * @see \Hyde\Framework\Testing\Unit\HeadingRendererUnitTest */ class MarkdownHeadingRendererTest extends TestCase { - // + public function testBasicHeadingRendering() + { + $markdown = <<<'MARKDOWN' + # Heading 1 + ## Heading 2 + ### Heading 3 + #### Heading 4 + ##### Heading 5 + ###### Heading 6 + MARKDOWN; + + $html = (new MarkdownService($markdown))->parse(); + + $this->assertStringContainsString('

Heading 1

', $html); + $this->assertStringContainsString('

Heading 2

', $html); + $this->assertStringContainsString('

Heading 3

', $html); + $this->assertStringContainsString('

Heading 4

', $html); + $this->assertStringContainsString('
Heading 5
', $html); + $this->assertStringContainsString('
Heading 6
', $html); + } + + public function testPermalinksInDocumentationPages() + { + $markdown = '## Documentation Heading'; + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertStringContainsString('heading-permalink', $html); + $this->assertStringContainsString('id="documentation-heading"', $html); + $this->assertStringContainsString('href="#documentation-heading"', $html); + } + + public function testPermalinksAreNotAddedToRegularMarkdownPages() + { + $markdown = '## Regular Page Heading'; + $html = (new MarkdownService($markdown, MarkdownPage::class))->parse(); + + $this->assertStringNotContainsString('heading-permalink', $html); + } + + public function testSetextStyleHeadings() + { + $markdown = <<<'MARKDOWN' + Heading 1 + ========= + + Heading 2 + --------- + MARKDOWN; + + $html = (new MarkdownService($markdown))->parse(); + + $this->assertStringContainsString('

Heading 1

', $html); + $this->assertStringContainsString('

Heading 2

', $html); + } + + public function testHeadingsWithCustomAttributes() + { + $markdown = <<<'MARKDOWN' + ## Heading {.custom-class #custom-id} + ### Another Heading {data-test="value"} + MARKDOWN; + + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertStringContainsString('class="custom-class"', $html); + $this->assertStringContainsString('id="custom-id"', $html); + $this->assertStringContainsString('data-test="value"', $html); + } + + public function testPermalinkConfigurationLevels() + { + config(['markdown.permalinks.min_level' => 2]); + config(['markdown.permalinks.max_level' => 4]); + + $markdown = <<<'MARKDOWN' + # H1 No Permalink + ## H2 Has Permalink + ### H3 Has Permalink + #### H4 Has Permalink + ##### H5 No Permalink + ###### H6 No Permalink + MARKDOWN; + + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertStringNotContainsString('

H1 No Permalink

assertStringContainsString('

H2 Has PermalinkassertStringContainsString('

H3 Has PermalinkassertStringContainsString('

H4 Has PermalinkassertStringNotContainsString('
H5 No Permalink
assertStringNotContainsString('
H6 No Permalink
false]); + + $markdown = '## Heading'; + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertStringNotContainsString('heading-permalink', $html); + } + + public function testHeadingsWithSpecialCharacters() + { + $markdown = <<<'MARKDOWN' + ## Heading with & special < > "characters" + ### Heading with émojis 🎉 + MARKDOWN; + + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertStringContainsString('Heading with & special < > "characters"', $html); + $this->assertStringContainsString('Heading with émojis 🎉', $html); + } + + public function testCustomPageClassConfiguration() + { + config(['markdown.permalinks.pages' => [MarkdownPage::class]]); + + $markdown = '## Test Heading'; + + // Should now have permalinks + $html = (new MarkdownService($markdown, MarkdownPage::class))->parse(); + $this->assertStringContainsString('heading-permalink', $html); + + // Should not have permalinks + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + $this->assertStringNotContainsString('heading-permalink', $html); + } }