40fe75d9b7
Add an optional `$limit` parameter to `CommentPresenter::markdownBody()` that truncates the comment body before rendering Markdown. The comment partial now passes a default limit of 250 characters, preventing long comments from dominating the layout. Unit tests cover rendering with and without a limit.
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\Comment;
|
|
use Tests\TestCase;
|
|
|
|
class CommentPresenterTest extends TestCase
|
|
{
|
|
public function test_markdown_body_renders_full_comment_without_limit(): void
|
|
{
|
|
$comment = new Comment(['body' => 'Hello **world**']);
|
|
|
|
$result = (string) $comment->presenter()->markdownBody();
|
|
|
|
$this->assertStringContainsString('Hello', $result);
|
|
$this->assertStringContainsString('world', $result);
|
|
}
|
|
|
|
public function test_markdown_body_is_truncated_when_limit_is_provided(): void
|
|
{
|
|
$body = str_repeat('a very long comment. ', 50);
|
|
$comment = new Comment(['body' => $body]);
|
|
|
|
$result = (string) $comment->presenter()->markdownBody(40);
|
|
|
|
$this->assertLessThan(strlen($body), strlen($result));
|
|
$this->assertStringContainsString('...', $result);
|
|
}
|
|
|
|
public function test_markdown_body_is_not_truncated_when_body_is_shorter_than_limit(): void
|
|
{
|
|
$comment = new Comment(['body' => 'Short']);
|
|
|
|
$result = (string) $comment->presenter()->markdownBody(100);
|
|
|
|
$this->assertStringContainsString('Short', $result);
|
|
$this->assertStringNotContainsString('...', $result);
|
|
}
|
|
}
|