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(
5151 return false ;
5252 }
5353
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+
5466 /**
5567 * Check if the current user has a role or permission by its name.
5668 *
Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5- use Mockery as m ;
65use Laratrust \Laratrust ;
7- use Laratrust \Tests \Models \User ;
86use Laratrust \Tests \LaratrustTestCase ;
7+ use Laratrust \Tests \Models \User ;
8+ use Mockery as m ;
99
1010class LaratrustFacadeTest extends LaratrustTestCase
1111{
1212 protected $ laratrust ;
13+
1314 protected $ user ;
1415
1516 protected function setUp (): void
@@ -45,6 +46,18 @@ public function testHasPermission()
4546 $ this ->assertFalse ($ this ->laratrust ->hasPermission ('any_permission ' ));
4647 }
4748
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+
4861 public function testAbility ()
4962 {
5063 $ this ->laratrust ->shouldReceive ('user ' )->andReturn ($ this ->user )->twice ()->ordered ();
You can’t perform that action at this time.
0 commit comments