File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 33namespace Tests \Feature ;
44
55use App \Models \Article ;
6+ use App \Models \User ;
67use Illuminate \Foundation \Testing \RefreshDatabase ;
8+ use Illuminate \Support \Facades \Config ;
79use PHPUnit \Framework \Attributes \Test ;
810use 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}
You can’t perform that action at this time.
0 commit comments