Skip to content

Commit

Permalink
Improve the test
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 3, 2024
1 parent ce21d66 commit 3d3ed48
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/framework/tests/Feature/MarkdownServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hyde\Framework\Services\MarkdownService;
use Hyde\Pages\DocumentationPage;
use Hyde\Pages\MarkdownPage;
use Hyde\Testing\TestCase;
use Illuminate\Support\Facades\Config;

Expand All @@ -25,18 +26,39 @@ public function testServiceCanParseMarkdownToHtml()
$this->assertSame("<h1>Hello World!</h1>\n", $html);
}

public function testServiceCanParseMarkdownToHtmlWithPermalinks()
public function testServiceCanParseMarkdownToHtmlWithPermalinksDependingOnConfiguration()
{
$markdown = '## Hello World!';

$html = (new MarkdownService($markdown, DocumentationPage::class))->parse();

$this->assertIsString($html);
$this->assertStringContainsString('heading-permalink', $html, 'Permalink should be added to documentation pages by default');
$this->assertSame(
'<h2>Hello World!<a id="hello-world" href="#hello-world" class="heading-permalink" '.
'title="Permalink"></a></h2>'."\n",
$html
'<h2>Hello World!<a id="hello-world" href="#hello-world" class="heading-permalink" title="Permalink"></a></h2>'."\n", $html
);

$html = (new MarkdownService($markdown))->parse();
$this->assertStringNotContainsString('heading-permalink', $html, 'Permalink should not be be added when the page class is not set');

$html = (new MarkdownService($markdown, MarkdownPage::class))->parse();
$this->assertStringNotContainsString('heading-permalink', $html, 'Permalink should not be added to other pages by default');

Config::set('markdown.permalinks.pages', [MarkdownPage::class]);

$html = (new MarkdownService($markdown, MarkdownPage::class))->parse();
$this->assertStringContainsString('heading-permalink', $html, 'Permalink should be added to pages when configured');

$html = (new MarkdownService($markdown, DocumentationPage::class))->parse();
$this->assertStringNotContainsString('heading-permalink', $html, 'Permalink should not be added to pages when not configured');

Config::set('markdown.permalinks.pages', []);

$html = (new MarkdownService($markdown, DocumentationPage::class))->parse();
$this->assertStringNotContainsString('heading-permalink', $html, 'Permalinks should not be added to any pages when disabled');

$html = (new MarkdownService($markdown, MarkdownPage::class))->parse();
$this->assertStringNotContainsString('heading-permalink', $html, 'Permalinks should not be added to any pages when disabled');
}

public function testTorchlightExtensionIsNotEnabledByDefault()
Expand Down

0 comments on commit 3d3ed48

Please sign in to comment.