/
RolesTest.php
115 lines (93 loc) · 3.3 KB
/
RolesTest.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace GeometriaLabTest\Permissions\Roles;
use GeometriaLab\Permissions\Roles\ResourceRoles;
class RolesTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SampleRoles\Roles
*/
protected static $roles;
public static function setUpBeforeClass()
{
static::$roles = new SampleRoles\Roles(array(
'id' => 1,
'resourceRoles' => array(
new ResourceRoles(array(
'resourceName' => 'Foo',
'resourcesRoles' => array(
1 => 'manager',
2 => 'admin',
),
'citiesRoles' => array(
0 => 'admin',
),
)),
new ResourceRoles(array(
'resourceName' => 'Bar',
'resourcesRoles' => array(
0 => 'admin',
),
'citiesRoles' => array(
1 => 'manager',
2 => 'admin',
),
)),
),
));
static::$roles->save();
}
public function testHasRolesForResource()
{
$foo1 = new SampleModel\Foo(array('id' => 1));
$foo2 = new SampleModel\Foo(array('id' => 2));
$this->assertTrue(static::$roles->hasRole('manager', $foo1));
$this->assertTrue(static::$roles->hasRole('admin', $foo2));
}
public function testHasNonExistentRoleForResource()
{
$foo = new SampleModel\Foo(array('id' => 1));
$this->assertFalse(static::$roles->hasRole('badRole', $foo));
}
public function testHasRoleForNonExistentResource()
{
$baz = new SampleModel\Baz(array('id' => 1));
$this->assertFalse(static::$roles->hasRole('admin', $baz));
}
public function testHasRoleForResourceWithNonExistentId()
{
$foo = new SampleModel\Foo(array('id' => 3));
$this->assertFalse(static::$roles->hasRole('admin', $foo));
}
public function testHasRoleForBadResource()
{
$this->setExpectedException('\\RuntimeException');
$badModel = new SampleModel\ModelWithoutId();
static::$roles->hasRole('admin', $badModel);
}
public function testHasSuperManagerRoleForResource()
{
$bar = new SampleModel\Bar(array('id' => 1));
$this->assertTrue(static::$roles->hasRole('admin', $bar));
}
public function testHasRolesForResourceInCity()
{
$this->assertTrue(static::$roles->hasRoleInCity('manager', 1, 'Bar'));
$this->assertTrue(static::$roles->hasRoleInCity('admin', 2, 'Bar'));
}
public function testHasNonExistentRoleForResourceInCity()
{
$this->assertFalse(static::$roles->hasRoleInCity('badRole', 1, 'Bar'));
}
public function testHasRoleForNonExistentResourceInCity()
{
$this->assertFalse(static::$roles->hasRoleInCity('admin', 1, 'Baz'));
}
public function testHasRoleForResourceWithNonExistentCityIdInCity()
{
$this->assertFalse(static::$roles->hasRoleInCity('admin', 3, 'Bar'));
}
public function testHasSuperManagerRoleForResourceInCity()
{
$this->assertTrue(static::$roles->hasRoleInCity('admin', 1, 'Foo'));
}
}