File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,18 @@ public function hasPermission(
51
51
return false ;
52
52
}
53
53
54
+ /**
55
+ * Check if the current user has a permission by its name.
56
+ * Alias to hasPermission.
57
+ */
58
+ public function isAbleTo (
59
+ string |array |BackedEnum $ permission ,
60
+ mixed $ team = null ,
61
+ bool $ requireAll = false
62
+ ): bool {
63
+ return $ this ->hasPermission ($ permission , $ team , $ requireAll );
64
+ }
65
+
54
66
/**
55
67
* Check if the current user has a role or permission by its name.
56
68
*
Original file line number Diff line number Diff line change 2
2
3
3
declare (strict_types=1 );
4
4
5
- use Mockery as m ;
6
5
use Laratrust \Laratrust ;
7
- use Laratrust \Tests \Models \User ;
8
6
use Laratrust \Tests \LaratrustTestCase ;
7
+ use Laratrust \Tests \Models \User ;
8
+ use Mockery as m ;
9
9
10
10
class LaratrustFacadeTest extends LaratrustTestCase
11
11
{
12
12
protected $ laratrust ;
13
+
13
14
protected $ user ;
14
15
15
16
protected function setUp (): void
@@ -45,6 +46,18 @@ public function testHasPermission()
45
46
$ this ->assertFalse ($ this ->laratrust ->hasPermission ('any_permission ' ));
46
47
}
47
48
49
+ public function testIsAbleTo ()
50
+ {
51
+ $ this ->laratrust ->shouldReceive ('user ' )->andReturn ($ this ->user )->twice ()->ordered ();
52
+ $ this ->laratrust ->shouldReceive ('user ' )->andReturn (null )->once ()->ordered ();
53
+ $ this ->user ->shouldReceive ('hasPermission ' )->with ('user_can ' , null , false )->andReturn (true )->once ();
54
+ $ this ->user ->shouldReceive ('hasPermission ' )->with ('user_cannot ' , null , false )->andReturn (false )->once ();
55
+
56
+ $ this ->assertTrue ($ this ->laratrust ->isAbleTo ('user_can ' ));
57
+ $ this ->assertFalse ($ this ->laratrust ->isAbleTo ('user_cannot ' ));
58
+ $ this ->assertFalse ($ this ->laratrust ->isAbleTo ('any_permission ' ));
59
+ }
60
+
48
61
public function testAbility ()
49
62
{
50
63
$ this ->laratrust ->shouldReceive ('user ' )->andReturn ($ this ->user )->twice ()->ordered ();
You can’t perform that action at this time.
0 commit comments