diff --git a/app/Users/Models/User.php b/app/Users/Models/User.php index 92701ac13..2479521a2 100644 --- a/app/Users/Models/User.php +++ b/app/Users/Models/User.php @@ -345,7 +345,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $splitName[0]; } - return ''; + return mb_substr($this->name, 0, max($chars - 2, 0)) . '…'; } /** diff --git a/tests/Entity/CommentTest.php b/tests/Entity/CommentTest.php index 0a71bb6ef..23fc68197 100644 --- a/tests/Entity/CommentTest.php +++ b/tests/Entity/CommentTest.php @@ -152,4 +152,16 @@ class CommentTest extends TestCase $respHtml = $this->withHtml($this->get($page->getUrl('/edit'))); $respHtml->assertElementContains('.comment-box .content', 'My great comment to see in the editor'); } + + public function test_comment_creator_name_truncated() + { + [$longNamedUser] = $this->users->newUserWithRole(['name' => 'Wolfeschlegelsteinhausenbergerdorff'], ['comment-create-all', 'page-view-all']); + $page = $this->entities->page(); + + $comment = Comment::factory()->make(); + $this->actingAs($longNamedUser)->postJson("/comment/$page->id", $comment->getAttributes()); + + $pageResp = $this->asAdmin()->get($page->getUrl()); + $pageResp->assertSee('Wolfeschlegels…'); + } }