Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Framework/Services/MarkdownService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function addFeature(string $feature): static

public function isDocumentationPage(): bool
{
return isset($this->pageClass) && $this->pageClass === DocumentationPage::class;
return isset($this->pageClass) && is_a($this->pageClass, DocumentationPage::class, true);
}

public function withTableOfContents(): static
Expand Down
59 changes: 59 additions & 0 deletions tests/Feature/MarkdownServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,57 @@ public function testTorchlightIntegrationInjectsAttribution()
.'rel="noopener nofollow">Torchlight.dev</a>', $html);
}

public function testTorchlightAttributionIsNotInjectedForDocumentationPages()
{
$markdown = '# Hello World! <!-- Syntax highlighted by torchlight.dev -->';

$service = new MarkdownService($markdown, DocumentationPage::class);

$html = $service->parse();

$this->assertStringNotContainsString('Syntax highlighting by <a href="https://torchlight.dev/" '
.'rel="noopener nofollow">Torchlight.dev</a>', $html,
'Torchlight attribution should not be injected for documentation pages as it is handled by SemanticDocumentationArticle');
}

public function testTorchlightAttributionIsNotInjectedForDocumentationPageSubclasses()
{
$markdown = '# Hello World! <!-- Syntax highlighted by torchlight.dev -->';

$service = new MarkdownService($markdown, TestDocumentationPageSubclass::class);

$html = $service->parse();

$this->assertStringNotContainsString('Syntax highlighting by <a href="https://torchlight.dev/" '
.'rel="noopener nofollow">Torchlight.dev</a>', $html,
'Torchlight attribution should not be injected for documentation page subclasses as it is handled by SemanticDocumentationArticle');
}

public function testIsDocumentationPageReturnsTrueForDocumentationPageClass()
{
$service = new MarkdownService('', DocumentationPage::class);
$this->assertTrue($service->isDocumentationPage());
}

public function testIsDocumentationPageReturnsTrueForDocumentationPageSubclass()
{
$service = new MarkdownService('', TestDocumentationPageSubclass::class);
$this->assertTrue($service->isDocumentationPage(),
'isDocumentationPage should return true for subclasses of DocumentationPage using instanceof check');
}

public function testIsDocumentationPageReturnsFalseForOtherPageClasses()
{
$service = new MarkdownService('', MarkdownPage::class);
$this->assertFalse($service->isDocumentationPage());
}

public function testIsDocumentationPageReturnsFalseWhenNoPageClassIsSet()
{
$service = new MarkdownService('');
$this->assertFalse($service->isDocumentationPage());
}

public function testBladedownIsNotEnabledByDefault()
{
$service = new MarkdownService('[Blade]: {{ "Hello World!" }}');
Expand Down Expand Up @@ -287,3 +338,11 @@ public function __construct(string $markdown = '', ?string $pageClass = null)
parent::__construct($markdown, $pageClass);
}
}

/**
* Mock subclass of DocumentationPage for testing instanceof checks.
*/
class TestDocumentationPageSubclass extends DocumentationPage
{
//
}