-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorizationTest.php
More file actions
100 lines (76 loc) · 3.19 KB
/
AuthorizationTest.php
File metadata and controls
100 lines (76 loc) · 3.19 KB
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
<?php // vim:ts=3:sts=3:sw=3:et:
/**
* Test class for MindFrame2_Authorization
*
* PHP Version 5
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @copyright 2005-2011 Bryan C. Geraghty
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
/**
* Test class for MindFrame2_Authorization
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
class MindFrame2_AuthorizationTest extends PHPUnit_Framework_TestCase
{
private $_instance;
public function setUp()
{
$this->_instance = new MindFrame2_Authorization();
$this->_instance->setUser(
new MindFrame2_UserModel(1, 'test', 'Foo Bar', 'bryan@localhost')
);
}
public function testDirectPermission()
{
$acme = new MindFrame2_OrganizationModel(1, 'Acme');
$read_only = new MindFrame2_RoleModel(rand(), 'Acme - Read-only', $acme);
$read_only->addPermission(new MindFrame2_PermissionModel(1, 'List Users'));
$this->_instance->getUser()->addRole($read_only);
$this->assertEquals(TRUE,
$this->_instance->checkForPermission($acme, 1));
$this->assertEquals(FALSE,
$this->_instance->checkForPermission($acme, 2));
}
public function testInheritedPermission()
{
$acme = new MindFrame2_OrganizationModel(1, 'Acme');
$read_only = new MindFrame2_RoleModel(rand(), 'Acme - Read-only', $acme);
$read_only->addPermission(new MindFrame2_PermissionModel(1, 'List Users'));
$this->_instance->getUser()->addRole($read_only);
$acme_tools = new MindFrame2_OrganizationModel(2, 'Acme Tools');
$acme_tools->setParentOrganization($acme);
$admin = new MindFrame2_RoleModel(rand(), 'Acme Tools - Admin', $acme_tools);
$admin->addPermission(new MindFrame2_PermissionModel(2, 'Edit Users'));
$this->_instance->getUser()->addRole($admin);
$acme_tools_sales = new MindFrame2_OrganizationModel(3, 'Acme Tools - Sales');
$acme_tools_sales->setParentOrganization($acme_tools);
// Check Acme for List Users permission. This check should pass.
$this->assertEquals(TRUE,
$this->_instance->checkForPermission($acme, 1));
// Check Acme for Edit Users function. It has been assigned to
// Acme Tools, so this check should fail.
$this->assertEquals(FALSE,
$this->_instance->checkForPermission($acme, 2));
// Check Acme for an undefined function. This check should fail.
$this->assertEquals(FALSE,
$this->_instance->checkForPermission($acme, 3));
// Check Acme Tools for List Users functionality which should be
// inherited from Acme.
$this->assertEquals(TRUE,
$this->_instance->checkForPermission($acme_tools, 1));
$this->assertEquals(TRUE,
$this->_instance->checkForPermission($acme_tools, 2));
$this->assertEquals(FALSE,
$this->_instance->checkForPermission($acme_tools, 3));
}
}