-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestAuthGeneral.php
More file actions
170 lines (164 loc) · 4.42 KB
/
TestAuthGeneral.php
File metadata and controls
170 lines (164 loc) · 4.42 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* TestAuthGeneral
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AuthComponent', 'Controller/Component');
App::uses('Role', 'Roles.Model');
App::uses('UserRole', 'UserRoles.Model');
/**
* TestAuthGeneral
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\AuthGeneral\TestSuite
* @codeCoverageIgnore
*/
class TestAuthGeneral {
/**
* Roles data for testing
*
* @var array
*/
public static $roles = [
Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR => [
'id' => '1',
'username' => 'admin',
'password' => 'admin',
'role_key' => 'system_administrator',
'handlename' => 'handle of admin',
'email' => 'system_admin@exapmle.com',
'UserRoleSetting' => [
'id' => '1',
'role_key' => 'system_administrator',
'origin_role_key' => 'system_administrator',
'use_private_room' => '1',
],
],
Role::ROOM_ROLE_KEY_CHIEF_EDITOR => [
'id' => '2',
'username' => 'chief_editor',
'password' => 'chief_editor',
'role_key' => 'administrator',
'handlename' => 'chief_editor of admin',
'UserRoleSetting' => [
'id' => '2',
'role_key' => 'administrator',
'origin_role_key' => 'administrator',
'use_private_room' => '1',
],
],
Role::ROOM_ROLE_KEY_EDITOR => [
'id' => '3',
'username' => 'editor',
'password' => 'editor',
'role_key' => 'common_user',
'handlename' => 'editor of admin',
'UserRoleSetting' => [
'id' => '3',
'role_key' => 'common_user',
'origin_role_key' => 'common_user',
'use_private_room' => '1',
],
],
Role::ROOM_ROLE_KEY_GENERAL_USER => [
'id' => '4',
'username' => 'general_user',
'password' => 'general_user',
'role_key' => 'common_user',
'handlename' => 'general_user of admin',
'UserRoleSetting' => [
'id' => '3',
'role_key' => 'common_user',
'origin_role_key' => 'common_user',
'use_private_room' => '1',
],
],
Role::ROOM_ROLE_KEY_VISITOR => [
'id' => '5',
'username' => 'visitor',
'password' => 'visitor',
'role_key' => 'common_user',
'handlename' => 'visitor of admin',
'UserRoleSetting' => [
'id' => '3',
'role_key' => 'common_user',
'origin_role_key' => 'common_user',
'use_private_room' => '1',
],
],
UserRole::USER_ROLE_KEY_SYSTEM_ADMINISTRATOR => [
'id' => '1',
'username' => 'admin',
'password' => 'admin',
'role_key' => 'system_administrator',
'handlename' => 'handle of admin',
'UserRoleSetting' => [
'id' => '1',
'role_key' => 'system_administrator',
'origin_role_key' => 'system_administrator',
'use_private_room' => '1',
],
],
UserRole::USER_ROLE_KEY_ADMINISTRATOR => [
'id' => '2',
'username' => 'chief_editor',
'password' => 'chief_editor',
'role_key' => 'administrator',
'handlename' => 'chief_editor of admin',
'UserRoleSetting' => [
'id' => '2',
'role_key' => 'administrator',
'origin_role_key' => 'administrator',
'use_private_room' => '1',
],
],
UserRole::USER_ROLE_KEY_COMMON_USER => [
'id' => '4',
'username' => 'general_user',
'password' => 'general_user',
'role_key' => 'common_user',
'handlename' => 'general_user of admin',
'UserRoleSetting' => [
'id' => '3',
'role_key' => 'common_user',
'origin_role_key' => 'common_user',
'use_private_room' => '1',
],
],
];
/**
* Call logout action
*
* @param CakeTestCase $test CakeTestCase instance
* @return void
*/
public static function logout($test) {
$reflectionClass = new ReflectionClass('AuthComponent');
$property = $reflectionClass->getProperty('_user');
$property->setAccessible(true);
if (isset($test->controller)) {
$property->setValue($test->controller->Components->Auth, []);
}
}
/**
* Login as given roles
*
* @param CakeTestCase $test CakeTestCase instance
* @param string $role role key
* @return void
*/
public static function login(CakeTestCase $test, $role = Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR) {
$reflectionClass = new ReflectionClass('AuthComponent');
$property = $reflectionClass->getProperty('_user');
$property->setAccessible(true);
if (isset(self::$roles[$role])) {
$property->setValue($test->controller->Components->Auth, self::$roles[$role]);
} else {
$property->setValue($test->controller->Components->Auth, []);
}
}
}