]> BookStack Code Mirror - bookstack/commitdiff
Reviewed #4533, formatting and tweaks
authorDan Brown <redacted>
Wed, 13 Sep 2023 09:09:33 +0000 (10:09 +0100)
committerDan Brown <redacted>
Wed, 13 Sep 2023 09:09:33 +0000 (10:09 +0100)
- Updating formatting.
- Tweaked truncation to roughly match elipsis char to width used.
- Updated testing to use existing helpers, and ran check as admin user
  to avoid name conflicts.

app/Users/Models/User.php
tests/Entity/CommentTest.php

index 3efbeec70a87bed60ca700551799ebdabc9d04b3..2479521a2e91d86f046490ef346a488534001c7f 100644 (file)
@@ -345,7 +345,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
             return $splitName[0];
         }
 
-        return mb_substr($this->name, 0, $chars-3) . '…';
+        return mb_substr($this->name, 0, max($chars - 2, 0)) . '…';
     }
 
     /**
index d2ed3513679350e5ff85e4a1f918e04c33251255..23fc68197411c220ccd4a173d14b11edee5aeed1 100644 (file)
@@ -154,18 +154,14 @@ class CommentTest extends TestCase
     }
 
     public function test_comment_creator_name_truncated()
-    {   
-        $longNamedUser = $this->users->admin();
-        $longNamedUser->name = 'Wolfeschlegelsteinhausenbergerdorff';
-        $longNamedUser->save();
-        $this->actingAs($longNamedUser);
-
+    {
+        [$longNamedUser] = $this->users->newUserWithRole(['name' => 'Wolfeschlegelsteinhausenbergerdorff'], ['comment-create-all', 'page-view-all']);
         $page = $this->entities->page();
 
         $comment = Comment::factory()->make();
-        $this->postJson("/comment/$page->id", $comment->getAttributes());
+        $this->actingAs($longNamedUser)->postJson("/comment/$page->id", $comment->getAttributes());
 
-        $pageResp = $this->get($page->getUrl());
-        $pageResp->assertSee('Wolfeschlegel…');
+        $pageResp = $this->asAdmin()->get($page->getUrl());
+        $pageResp->assertSee('Wolfeschlegels…');
     }
 }