Skip to content

Commit 802f69c

Browse files
committed
Comments: Fixed missing comment timestamps
Due to deleted code during Laravel 11 upgrade. Added test to cover. Closes #5555
1 parent 0ec0913 commit 802f69c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

resources/views/comments/comment.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class="comment-box">
2424
@else
2525
{{ trans('common.deleted_user') }}
2626
@endif
27-
<span title="{{ $comment->created_at }}">&nbsp;{{ trans('entities.comment_created', ['createDiff' => $comment->created]) }}</span>
27+
<span title="{{ $comment->created_at }}">&nbsp;{{ trans('entities.comment_created', ['createDiff' => $comment->created_at->diffForHumans() ]) }}</span>
2828
@if($comment->isUpdated())
2929
<span class="mx-xs">&bull;</span>
3030
<span title="{{ trans('entities.comment_updated', ['updateDiff' => $comment->updated_at, 'username' => $comment->updatedBy->name ?? trans('common.deleted_user')]) }}">

tests/Entity/CommentTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,21 @@ public function test_comment_editor_js_loaded_with_create_or_edit_permissions()
214214
$resp->assertSee('window.editor_translations', false);
215215
$resp->assertSee('component="entity-selector"', false);
216216
}
217+
218+
public function test_comment_displays_relative_times()
219+
{
220+
$page = $this->entities->page();
221+
$comment = Comment::factory()->create(['entity_id' => $page->id, 'entity_type' => $page->getMorphClass()]);
222+
$comment->created_at = now()->subWeek();
223+
$comment->updated_at = now()->subDay();
224+
$comment->save();
225+
226+
$pageResp = $this->asAdmin()->get($page->getUrl());
227+
$html = $this->withHtml($pageResp);
228+
229+
// Create date shows relative time as text to user
230+
$html->assertElementContains('.comment-box', 'commented 1 week ago');
231+
// Updated indicator has full time as title
232+
$html->assertElementContains('.comment-box span[title^="Updated ' . $comment->updated_at->format('Y-m-d') . '"]', 'Updated');
233+
}
217234
}

0 commit comments

Comments
 (0)