|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class ACLActionTest extends PHPUnit_Framework_TestCase{ |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
public function testACLAction(){ |
|
8
|
|
|
|
|
9
|
|
|
//execute the contructor and check for the Object type and type attribute |
|
10
|
|
|
$aclAction = new ACLAction(); |
|
11
|
|
|
$this->assertInstanceOf('ACLAction',$aclAction); |
|
12
|
|
|
$this->assertInstanceOf('SugarBean',$aclAction); |
|
13
|
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('ACLActions', 'module_dir', $aclAction); |
|
15
|
|
|
$this->assertAttributeEquals('ACLAction', 'object_name', $aclAction); |
|
16
|
|
|
$this->assertAttributeEquals('acl_actions', 'table_name', $aclAction); |
|
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $aclAction); |
|
18
|
|
|
$this->assertAttributeEquals(true, 'disable_custom_fields', $aclAction); |
|
19
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
public function testaddActions(){ |
|
24
|
|
|
|
|
25
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
26
|
|
|
|
|
27
|
|
|
//take count of actions initially and then after method execution and test if action count increases |
|
28
|
|
|
$action_count = count(ACLAction::getDefaultActions()); |
|
29
|
|
|
ACLAction::addActions("Test"); |
|
30
|
|
|
$actual = ACLAction::getDefaultActions(); |
|
31
|
|
|
$this->assertGreaterThan($action_count, count($actual)); |
|
32
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function testremoveActions(){ |
|
37
|
|
|
|
|
38
|
|
|
//take count of actions initially and then after method execution and test if action count decreases |
|
39
|
|
|
$action_count = count(ACLAction::getDefaultActions()); |
|
40
|
|
|
ACLAction::removeActions("Test"); |
|
41
|
|
|
$actual = ACLAction::getDefaultActions(); |
|
42
|
|
|
$this->assertLessThan($action_count, count($actual)); |
|
43
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function testAccessName(){ |
|
48
|
|
|
|
|
49
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertFalse(ACLAction::AccessName('')); //test with invalid value |
|
52
|
|
|
$this->assertEquals('All', ACLAction::AccessName(90)); //test with a valid value |
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function testgetDefaultActions(){ |
|
59
|
|
|
global $beanList; |
|
60
|
|
|
$actual = ACLAction::getDefaultActions(); |
|
61
|
|
|
$this->assertTrue(is_array($actual)); //verify that it returns an array |
|
62
|
|
|
foreach($actual as $acl){ |
|
63
|
|
|
$this->assertInstanceOf("ACLAction",$acl); |
|
64
|
|
|
} |
|
65
|
|
|
$actual = ACLAction::getDefaultActions("module","list"); |
|
66
|
|
|
$this->assertTrue(is_array($actual)); //verify that it returns an array |
|
67
|
|
|
foreach($actual as $acl){ |
|
68
|
|
|
$this->assertInstanceOf("ACLAction",$acl); |
|
69
|
|
|
$this->assertEquals("list",$acl->name); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testgetUserActions(){ |
|
75
|
|
|
|
|
76
|
|
|
$result1 = ACLAction::getUserActions('1'); |
|
77
|
|
|
$result2 = ACLAction::getUserActions('1',false,'Accounts'); |
|
78
|
|
|
$result3 = ACLAction::getUserActions('1',false,'Accounts','list'); |
|
79
|
|
|
|
|
80
|
|
|
//verify that all three results retunred are different |
|
81
|
|
|
$this->assertNotSame($result1,$result2); |
|
82
|
|
|
$this->assertNotSame($result1,$result3); |
|
83
|
|
|
$this->assertNotSame($result2,$result3); |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
public function testhasAccess(){ |
|
89
|
|
|
|
|
90
|
|
|
$this->assertFalse(ACLAction::hasAccess()); //check with defaults |
|
91
|
|
|
$this->assertTrue(ACLAction::hasAccess(false,false,90)); //access All with is owner false |
|
92
|
|
|
$this->assertTrue(ACLAction::hasAccess(true,true,90)); //access All with is owner true |
|
93
|
|
|
$this->assertFalse(ACLAction::hasAccess(false,false,-98));// check access disabled |
|
94
|
|
|
$this->assertFalse(ACLAction::hasAccess(true,true,89)); //check access enabled |
|
95
|
|
|
$this->assertTrue(ACLAction::hasAccess(true,true,75)); //check owner access with is owner true |
|
96
|
|
|
$this->assertFalse(ACLAction::hasAccess(false,true,75)); //check owner access with is owner false |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testuserNeedsSecurityGroup(){ |
|
101
|
|
|
|
|
102
|
|
|
$this->assertFalse( ACLAction::userNeedsSecurityGroup('1','',''));//test with empty module and action |
|
103
|
|
|
$this->assertFalse( ACLAction::userNeedsSecurityGroup('1','Accounts','list')); //test with valid module and action |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
public function testuserHasAccess(){ |
|
109
|
|
|
|
|
110
|
|
|
$this->assertFalse(ACLAction::userHasAccess('', '','')); //test with empty module and action |
|
111
|
|
|
$this->assertTrue(ACLAction::userHasAccess('', 'Accounts','list')); //test with e,pty user and valid module and action |
|
112
|
|
|
$this->assertTrue(ACLAction::userHasAccess('1', 'Accounts','list')); //test with valid User, module and action |
|
113
|
|
|
$this->assertTrue(ACLAction::userHasAccess('1', 'SecurityGroups','list')); //test with valid User, module and action |
|
114
|
|
|
$this->assertTrue(ACLAction::userHasAccess('1', 'Users','list')); //test with valid User, module and action |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
public function testgetUserAccessLevel(){ |
|
120
|
|
|
|
|
121
|
|
|
//tes for accoounts module with two different actions |
|
122
|
|
|
$this->assertEquals(90,ACLAction::getUserAccessLevel('1', 'Accounts','list')); |
|
123
|
|
|
$this->assertEquals(89,ACLAction::getUserAccessLevel('1', 'Accounts','access')); |
|
124
|
|
|
|
|
125
|
|
|
//tes for users module with two different actions |
|
126
|
|
|
$this->assertEquals(90,ACLAction::getUserAccessLevel('1', 'Users','list')); |
|
127
|
|
|
$this->assertEquals(89,ACLAction::getUserAccessLevel('1', 'Users','access')); |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
public function testuserNeedsOwnership(){ |
|
133
|
|
|
|
|
134
|
|
|
//test with invalid values |
|
135
|
|
|
$this->assertFalse(ACLAction::userNeedsOwnership('', '','')); |
|
136
|
|
|
|
|
137
|
|
|
//test with valid values for different module and action combination |
|
138
|
|
|
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Accounts','list')); |
|
139
|
|
|
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Accounts','delete')); |
|
140
|
|
|
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Users','delete')); |
|
141
|
|
|
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Users','list')); |
|
142
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
public function testsetupCategoriesMatrix(){ |
|
147
|
|
|
|
|
148
|
|
|
//preset required data |
|
149
|
|
|
$categories = Array(); |
|
150
|
|
|
$categories["Accounts"]["module"]["list"][] = "list"; |
|
151
|
|
|
$categories["Accounts"]["module"]["edit"][] = "edit"; |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
$names_expected = Array("list"=> "List", "edit"=>"Edit"); |
|
155
|
|
|
|
|
156
|
|
|
$categories_expected = array ( |
|
157
|
|
|
'Accounts' => |
|
158
|
|
|
array ( |
|
159
|
|
|
'module' => |
|
160
|
|
|
array ( |
|
161
|
|
|
'list' => array ( 'list', 'accessColor' => false, 'accessName' => false, 'accessLabel' => false, 'accessOptions' => array ( 90 => 'All', 80 => 'Group', 75 => 'Owner', 0 => 'Not Set', -99 => 'None', ), ), |
|
162
|
|
|
'edit' => array ( 'edit', 'accessColor' => false, 'accessName' => false, 'accessLabel' => false, 'accessOptions' => array ( 90 => 'All', 80 => 'Group', 75 => 'Owner', 0 => 'Not Set', -99 => 'None' ), ), |
|
163
|
|
|
), |
|
164
|
|
|
), |
|
165
|
|
|
); |
|
166
|
|
|
|
|
167
|
|
|
//execute the method and verify that it retunrs expected results |
|
168
|
|
|
$result = ACLAction::setupCategoriesMatrix($categories); |
|
169
|
|
|
$this->assertSame($names_expected, $result); |
|
170
|
|
|
$this->assertSame($categories, $categories_expected); |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
public function testtoArray(){ |
|
176
|
|
|
|
|
177
|
|
|
$aclAction = new ACLAction(); |
|
178
|
|
|
|
|
179
|
|
|
//wihout any fields set |
|
180
|
|
|
$expected = Array("id"=> NULL, "aclaccess"=> NULL); |
|
181
|
|
|
$actual = $aclAction->toArray(); |
|
182
|
|
|
$this->assertSame($expected,$actual); |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
//with fileds pre populated |
|
186
|
|
|
$aclAction->populateFromRow(Array("id"=>"1234","aclaccess"=>"9999")); |
|
187
|
|
|
$expected = Array("id"=>"1234","aclaccess"=>"9999"); |
|
188
|
|
|
$actual = $aclAction->toArray(); |
|
189
|
|
|
$this->assertSame($expected,$actual); |
|
190
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function testfromArray(){ |
|
194
|
|
|
|
|
195
|
|
|
$aclAction = new ACLAction(); |
|
196
|
|
|
$arr = Array("id"=>"1234","name"=>"test"); |
|
197
|
|
|
|
|
198
|
|
|
//execute the method and verify that it retunrs expected results |
|
199
|
|
|
$aclAction->fromArray($arr); |
|
200
|
|
|
$this->assertSame($aclAction->id,"1234"); |
|
201
|
|
|
$this->assertSame($aclAction->name,"test"); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
public function testclearSessionCache(){ |
|
206
|
|
|
|
|
207
|
|
|
$aclAction = new ACLAction(); |
|
208
|
|
|
|
|
209
|
|
|
//execute the method and verify that it unsets the session cache |
|
210
|
|
|
$aclAction->clearSessionCache(); |
|
211
|
|
|
$this->assertFalse(isset($_SESSION['ACL'])); |
|
212
|
|
|
|
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
} |
|
217
|
|
|
|