-
-
Notifications
You must be signed in to change notification settings - Fork 383
/
Copy pathLaratrustHelperTest.php
92 lines (79 loc) · 3.02 KB
/
LaratrustHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
namespace Laratrust\Test;
use Laratrust\Helper;
use Illuminate\Support\Str;
use Ramsey\Uuid\UuidInterface;
use Laratrust\Tests\Models\Role;
use Illuminate\Support\Facades\Config;
use Laratrust\Tests\LaratrustTestCase;
class LaratrustHelperTest extends LaratrustTestCase
{
protected $superadmin;
protected $admin;
protected function setUp(): void
{
parent::setUp();
$this->migrate();
$this->superadmin = Role::create(['name' => 'superadmin']);
$this->admin = Role::create(['name' => 'admin']);
}
public function testGetIdFor()
{
$this->assertFalse(Helper::getIdFor(Str::uuid(), 'user') instanceof UuidInterface);
}
public function testIfRoleIsEditable()
{
/*
|------------------------------------------------------------
| Set
|------------------------------------------------------------
*/
Config::set('laratrust.panel.roles_restrictions.not_editable', ['superadmin']);
/*
|------------------------------------------------------------
| Assertion
|------------------------------------------------------------
*/
$this->assertFalse(Helper::roleIsEditable($this->superadmin));
$this->assertFalse(Helper::roleIsEditable($this->superadmin->name));
$this->assertTrue(Helper::roleIsEditable($this->admin));
$this->assertTrue(Helper::roleIsEditable($this->admin->name));
}
public function testRoleIsDeletable()
{
/*
|------------------------------------------------------------
| Set
|------------------------------------------------------------
*/
Config::set('laratrust.panel.roles_restrictions.not_deletable', ['superadmin']);
/*
|------------------------------------------------------------
| Assertion
|------------------------------------------------------------
*/
$this->assertFalse(Helper::roleIsDeletable($this->superadmin));
$this->assertFalse(Helper::roleIsDeletable($this->superadmin->name));
$this->assertTrue(Helper::roleIsDeletable($this->admin));
$this->assertTrue(Helper::roleIsDeletable($this->admin->name));
}
public function testRoleIsRemovable()
{
/*
|------------------------------------------------------------
| Set
|------------------------------------------------------------
*/
Config::set('laratrust.panel.roles_restrictions.not_removable', ['superadmin']);
/*
|------------------------------------------------------------
| Assertion
|------------------------------------------------------------
*/
$this->assertFalse(Helper::roleIsRemovable($this->superadmin));
$this->assertFalse(Helper::roleIsRemovable($this->superadmin->name));
$this->assertTrue(Helper::roleIsRemovable($this->admin));
$this->assertTrue(Helper::roleIsRemovable($this->admin->name));
}
}