Skip to content

Commit 1afbdf9

Browse files
committed
add article preview tests
1 parent 53c3927 commit 1afbdf9

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

resources/views/article.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class="size-5 shrink-0"
8282
datetime="2025-04-09"
8383
class="text-sm"
8484
>
85-
{{ $article->published_at->format('F j, Y') }}
85+
{{ $article->published_at?->format('F j, Y') }}
8686
</time>
8787
</div>
8888
</header>

tests/Feature/BlogTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Tests\Feature;
44

55
use App\Models\Article;
6+
use App\Models\User;
67
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Illuminate\Support\Facades\Config;
79
use PHPUnit\Framework\Attributes\Test;
810
use Tests\TestCase;
911

@@ -74,4 +76,39 @@ public function scheduled_articles_return_a_404()
7476
$this->get(route('article', $article))
7577
->assertStatus(404);
7678
}
79+
80+
#[Test]
81+
public function articles_can_be_previewed_by_admin_users()
82+
{
83+
$article = Article::factory()->create([
84+
'published_at' => null,
85+
]);
86+
87+
$admin = User::factory()->create();
88+
Config::set('filament.users', [$admin->email]);
89+
90+
// Visitors
91+
$this->get(route('article', $article))
92+
->assertStatus(404);
93+
94+
// Admins
95+
$this->actingAs($admin)
96+
->get(route('article', $article))
97+
->assertOk();
98+
}
99+
100+
#[Test]
101+
public function articles_cant_be_previewed_by_regular_users()
102+
{
103+
$article = Article::factory()->create([
104+
'published_at' => null,
105+
]);
106+
107+
$user = User::factory()->create();
108+
109+
// Non-admin users
110+
$this->actingAs($user)
111+
->get(route('article', $article))
112+
->assertStatus(404);
113+
}
77114
}

0 commit comments

Comments
 (0)