diff --git a/src/Framework/Services/MarkdownService.php b/src/Framework/Services/MarkdownService.php index e8220e4c..45633b7e 100644 --- a/src/Framework/Services/MarkdownService.php +++ b/src/Framework/Services/MarkdownService.php @@ -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 diff --git a/tests/Feature/MarkdownServiceTest.php b/tests/Feature/MarkdownServiceTest.php index a20bd32b..33a514cd 100644 --- a/tests/Feature/MarkdownServiceTest.php +++ b/tests/Feature/MarkdownServiceTest.php @@ -89,6 +89,57 @@ public function testTorchlightIntegrationInjectsAttribution() .'rel="noopener nofollow">Torchlight.dev', $html); } + public function testTorchlightAttributionIsNotInjectedForDocumentationPages() + { + $markdown = '# Hello World! '; + + $service = new MarkdownService($markdown, DocumentationPage::class); + + $html = $service->parse(); + + $this->assertStringNotContainsString('Syntax highlighting by Torchlight.dev', $html, + 'Torchlight attribution should not be injected for documentation pages as it is handled by SemanticDocumentationArticle'); + } + + public function testTorchlightAttributionIsNotInjectedForDocumentationPageSubclasses() + { + $markdown = '# Hello World! '; + + $service = new MarkdownService($markdown, TestDocumentationPageSubclass::class); + + $html = $service->parse(); + + $this->assertStringNotContainsString('Syntax highlighting by Torchlight.dev', $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!" }}'); @@ -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 +{ + // +}