@@ -31,6 +31,47 @@ public function it_can_check_wildcard_permission()
31
31
$ this ->assertFalse ($ user1 ->hasPermissionTo ('projects.view ' ));
32
32
}
33
33
34
+ /** @test */
35
+ public function it_can_check_wildcard_permission_for_a_non_default_guard ()
36
+ {
37
+ app ('config ' )->set ('permission.enable_wildcard_permission ' , true );
38
+
39
+ $ user1 = User::
create ([
'email ' =>
'[email protected] ' ]);
40
+
41
+ $ permission1 = Permission::create (['name ' => 'articles.edit,view,create ' , 'guard_name ' => 'api ' ]);
42
+ $ permission2 = Permission::create (['name ' => 'news.* ' , 'guard_name ' => 'api ' ]);
43
+ $ permission3 = Permission::create (['name ' => 'posts.* ' , 'guard_name ' => 'api ' ]);
44
+
45
+ $ user1 ->givePermissionTo ([$ permission1 , $ permission2 , $ permission3 ]);
46
+
47
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ('posts.create ' , 'api ' ));
48
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ('posts.create.123 ' , 'api ' ));
49
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ('posts.* ' , 'api ' ));
50
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ('articles.view ' , 'api ' ));
51
+ $ this ->assertFalse ($ user1 ->hasPermissionTo ('projects.view ' , 'api ' ));
52
+ }
53
+
54
+ /** @test */
55
+ public function it_can_check_wildcard_permission_from_instance_without_explicit_guard_argument ()
56
+ {
57
+ app ('config ' )->set ('permission.enable_wildcard_permission ' , true );
58
+
59
+ $ user1 = User::
create ([
'email ' =>
'[email protected] ' ]);
60
+
61
+ $ permission2 = Permission::create (['name ' => 'articles.view ' ]);
62
+ $ permission1 = Permission::create (['name ' => 'articles.edit ' , 'guard_name ' => 'api ' ]);
63
+ $ permission3 = Permission::create (['name ' => 'news.* ' , 'guard_name ' => 'api ' ]);
64
+ $ permission4 = Permission::create (['name ' => 'posts.* ' , 'guard_name ' => 'api ' ]);
65
+
66
+ $ user1 ->givePermissionTo ([$ permission1 , $ permission2 , $ permission3 ]);
67
+
68
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ($ permission1 ));
69
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ($ permission2 ));
70
+ $ this ->assertTrue ($ user1 ->hasPermissionTo ($ permission3 ));
71
+ $ this ->assertFalse ($ user1 ->hasPermissionTo ($ permission4 ));
72
+ $ this ->assertFalse ($ user1 ->hasPermissionTo ('articles.edit ' ));
73
+ }
74
+
34
75
/**
35
76
* @test
36
77
*
0 commit comments