File tree Expand file tree Collapse file tree 6 files changed +71
-5
lines changed Expand file tree Collapse file tree 6 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -81,11 +81,14 @@ public function updatePassword(?string $new_password = '')
8181 }
8282 }
8383
84- public function canAccessPanel (Panel $ panel ): bool
84+ public function canAccessPanel (? Panel $ panel = null ): bool
8585 {
8686 return $ this ->hasRole (Role::SUPER_ADMIN ->value );
8787 }
8888
89+ /**
90+ * @codeCoverageIgnore
91+ */
8992 public function getFilamentName (): string
9093 {
9194 return $ this ->fullName ;
Original file line number Diff line number Diff line change @@ -24,12 +24,14 @@ public function boot(): void
2424 {
2525 JsonResource::withoutWrapping ();
2626
27+ // @codeCoverageIgnoreStart
2728 Pulse::users (function ($ ids ) {
2829 return User::findMany ($ ids )->map (fn ($ user ) => [
2930 'id ' => $ user ->id ,
3031 'name ' => $ user ->fullName ,
3132 'extra ' => "{$ user ->email } ( {$ user ->roles ->pluck ('name ' )->implode (', ' )}) " ,
3233 ]);
3334 });
35+ // @codeCoverageIgnoreEnd
3436 }
3537}
Original file line number Diff line number Diff line change 1414 <directory suffix =" .php" >./app</directory >
1515 </include >
1616 <exclude >
17- <directory suffix =" .php" >app/Filament</directory >
17+ <directory suffix =" .php" >./app/Filament</directory >
18+ <directory suffix =" .php" >./app/Providers/Filament</directory >
19+ <file >./app/Providers/HorizonServiceProvider.php</file >
1820 </exclude >
1921 </source >
2022</phpunit >
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use App \Models \User ;
4+ use Illuminate \Support \Facades \Notification ;
5+ use Inertia \Testing \AssertableInertia as Assert ;
6+
7+ use function Pest \Laravel \actingAs ;
8+ use function Pest \Laravel \get ;
9+
10+ describe ('Users ' , function () {
11+ test ('Can access the verification page ' , function () {
12+ actingAs (User::factory ()->unverified ()->create ())
13+ ->get (route ('verification.notice ' ))
14+ ->assertInertia (
15+ fn (Assert $ page ) => $ page
16+ ->component ('EmailVerification/Show ' )
17+ );
18+ });
19+
20+ test ('Can send the verificaiton notice ' , function () {
21+ Notification::fake ();
22+
23+ $ user = User::factory ()->unverified ()->create ();
24+
25+ actingAs ($ user )
26+ ->post (route ('verification.send ' ))
27+ ->assertRedirect ();
28+
29+ Notification::assertSentTo ($ user , Illuminate \Auth \Notifications \VerifyEmail::class);
30+ });
31+ });
32+
33+ describe ('Guests ' , function () {
34+ test ("Can't access the verification page " , function () {
35+ get (route ('verification.notice ' ))
36+ ->assertRedirect (route ('login ' ));
37+ });
38+ });
Original file line number Diff line number Diff line change 22
33use App \Models \User ;
44use Illuminate \Auth \Notifications \ResetPassword ;
5- use Illuminate \Support \Facades \Hash ;
65use Illuminate \Support \Facades \Notification ;
76use Illuminate \Support \Facades \Password ;
87use Inertia \Testing \AssertableInertia as Assert ;
7776 'password_confirmation ' => $ newPassword ,
7877 ]))
7978 ->assertRedirect ();
80-
81- expect (Hash::check ($ newPassword , $ user ->refresh ()->password ))->toBeTrue ();
8279});
Original file line number Diff line number Diff line change 11<?php
22
33use App \Models \User ;
4+ use Database \Seeders \RolesAndPermissionsSeeder ;
45use Illuminate \Support \Facades \Hash ;
56
7+ it ("can get it's \"full_name \" correctly " , function () {
8+ $ user = User::factory ()->create ([
9+ 'first_name ' => 'John ' ,
10+ 'last_name ' => 'Doe ' ,
11+ ]);
12+
13+ expect ($ user ->full_name )->toBe ('John Doe ' );
14+ });
15+
616it ("can update it's password " , function () {
717 $ user = User::factory ()->create ([
818 'password ' => 'oldPassword#123 ' ,
3040
3141 expect (Hash::check ('oldPassword#123 ' , $ user ->refresh ()->password ))->toBeTrue ();
3242});
43+
44+ describe ('With Roles and Permissions ' , function () {
45+ beforeEach (function () {
46+ $ this ->seed (RolesAndPermissionsSeeder::class);
47+ });
48+
49+ it ("can only access Filament if it's a \"super-admin \"" , function () {
50+ $ superAdminUser = User::factory ()->superAdmin ()->create ();
51+ $ adminUser = User::factory ()->admin ()->create ();
52+
53+ expect ($ superAdminUser ->canAccessPanel ())->toBeTrue ();
54+ expect ($ adminUser ->canAccessPanel ())->toBeFalse ();
55+ });
56+ });
You can’t perform that action at this time.
0 commit comments