Skip to content

Commit

Permalink
Clean up test code to remove focus from implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 2, 2024
1 parent 2f31b9b commit 3c3661a
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions packages/framework/tests/Unit/HeadingRendererUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ public function testCanAddPermalinkReturnsFalseForExistingPermalink(): void
public function testCanAddPermalinkReturnsFalseForNotEnabledPageClass(): void
{
$renderer = new HeadingRenderer(MarkdownPage::class);
$result = $renderer->canAddPermalink('Test Content', 2);

$this->assertFalse($result);
$this->assertFalse($renderer->canAddPermalink('Test Content', 2));
}

public function testCanAddPermalinkWithCustomPageClasses(): void
Expand All @@ -177,15 +176,12 @@ public function testCanAddPermalinkWithCustomPageClasses(): void
]);

$renderer = new HeadingRenderer(MarkdownPage::class);
$result = $renderer->canAddPermalink('Test Content', 2);

$this->assertTrue($result);
$this->assertTrue($renderer->canAddPermalink('Test Content', 2));
}

public function testPostProcessMethodNormalizesInputToMatchCommonMark()
{
$renderer = new HeadingRenderer(DocumentationPage::class);

// Actual HTML output returned from Blade
$html = <<<'HTML'
<h2 >
Expand All @@ -197,53 +193,42 @@ public function testPostProcessMethodNormalizesInputToMatchCommonMark()
// What CommonMark would generate from the same input Markdown
$expected = '<h2>Test Heading<a id="test-heading" href="#test-heading" class="heading-permalink" title="Permalink"></a></h2>';

$processedHtml = $renderer->postProcess($html);
$this->assertSame($expected, $processedHtml);
$this->assertSame($expected, (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessRemovesSpacesCausedByNoExtraBladeAttributes()
{
$renderer = new HeadingRenderer();
$html = "<h1 >Title</h1>\n<h2 >Subtitle</h2>";
$processedHtml = $renderer->postProcess($html);

$this->assertSame('<h1>Title</h1><h2>Subtitle</h2>', $processedHtml);
$this->assertSame('<h1>Title</h1><h2>Subtitle</h2>', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessRemovesSpacesCausedByNoExtraBladeAttributesButLeavesExtraAttributesAlone()
{
$renderer = new HeadingRenderer();
$html = "<h1 class=\"foo-bar baz\">Title</h1>\n<h2 >Subtitle</h2>";
$processedHtml = $renderer->postProcess($html);

$this->assertSame('<h1 class="foo-bar baz">Title</h1><h2>Subtitle</h2>', $processedHtml);
$this->assertSame('<h1 class="foo-bar baz">Title</h1><h2>Subtitle</h2>', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessTrimsWhitespaceAndIndentationFromLines()
{
$renderer = new HeadingRenderer();
$html = " <h1>Title</h1> \n <h2>Subtitle</h2> ";
$processedHtml = $renderer->postProcess($html);

$this->assertSame('<h1>Title</h1><h2>Subtitle</h2>', $processedHtml);
$this->assertSame('<h1>Title</h1><h2>Subtitle</h2>', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessHandlesEmptyString()
{
$renderer = new HeadingRenderer();
$html = '';
$processedHtml = $renderer->postProcess($html);

$this->assertSame('', $processedHtml);
$this->assertSame('', (new HeadingRenderer())->postProcess($html));
}

public function testPostProcessHandlesNoHeadingTags()
{
$renderer = new HeadingRenderer();
$html = '<p>Paragraph</p>';
$processedHtml = $renderer->postProcess($html);

$this->assertSame('<p>Paragraph</p>', $processedHtml);
$this->assertSame('<p>Paragraph</p>', (new HeadingRenderer())->postProcess($html));
}

protected function createRealBladeCompilerEnvironment(): void
Expand Down

0 comments on commit 3c3661a

Please sign in to comment.