@@ -50,6 +50,43 @@ private function cancelAllRequests()
50
50
);
51
51
}
52
52
53
+ private function approveUserByAdmin ($ gid , $ uid )
54
+ {
55
+ http_post (
56
+ __DIR__ . "/../../webroot/admin/pi-mgmt.php " ,
57
+ [
58
+ "form_type " => "reqChild " ,
59
+ "action " => "Approve " ,
60
+ "pi " => $ gid ,
61
+ "uid " => $ uid ,
62
+ ]
63
+ );
64
+ }
65
+
66
+ private function approveUserByPI ($ uid )
67
+ {
68
+ http_post (
69
+ __DIR__ . "/../../webroot/panel/pi.php " ,
70
+ [
71
+ "form_type " => "userReq " ,
72
+ "action " => "Approve " ,
73
+ "uid " => $ uid ,
74
+ ]
75
+ );
76
+ }
77
+
78
+ private function approveGroup ($ uid )
79
+ {
80
+ http_post (
81
+ __DIR__ . "/../../webroot/admin/pi-mgmt.php " ,
82
+ [
83
+ "form_type " => "req " ,
84
+ "action " => "Approve " ,
85
+ "uid " => $ uid ,
86
+ ]
87
+ );
88
+ }
89
+
53
90
// delete requests made by that user
54
91
// delete user entry
55
92
// remove user from org group
@@ -109,13 +146,80 @@ private function ensurePIGroupDoesNotExist()
109
146
}
110
147
}
111
148
112
- public function testCreateUserByJoinGoup ()
149
+ public function testCreateUserByJoinGoupByPI ()
150
+ {
151
+ global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
152
+ $ pi_user_args = getUserIsPIHasNoMembersNoMemberRequests ();
153
+ switchUser (...$ pi_user_args );
154
+ $ pi_group = $ USER ->getPIGroup ();
155
+ $ gid = $ pi_group ->gid ;
156
+ $ user_to_create_args = getNonExistentUser ();
157
+ switchUser (...$ user_to_create_args );
158
+ $ this ->assertTrue (!$ USER ->exists ());
159
+ $ newOrg = new UnityOrg ($ SSO ["org " ], $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK );
160
+ $ this ->assertTrue (!$ newOrg ->exists ());
161
+ $ this ->assertTrue ($ pi_group ->exists ());
162
+ $ this ->assertTrue (!$ pi_group ->userExists ($ USER ));
163
+ $ this ->assertRequestedMembership (false , $ gid );
164
+ try {
165
+ $ this ->requestGroupMembership ($ pi_group ->gid );
166
+ $ this ->assertRequestedMembership (true , $ gid );
167
+
168
+ // $second_request_failed = false;
169
+ // try {
170
+ $ this ->requestGroupMembership ($ pi_group ->gid );
171
+ // } catch(Exception) {
172
+ // $second_request_failed = true;
173
+ // }
174
+ // $this->assertTrue($second_request_failed);
175
+ $ this ->assertRequestedMembership (true , $ gid );
176
+
177
+ $ this ->cancelAllRequests ();
178
+ $ this ->assertRequestedMembership (false , $ gid );
179
+
180
+ $ this ->requestGroupMembership ($ pi_group ->gid );
181
+ $ this ->assertTrue ($ pi_group ->requestExists ($ USER ));
182
+ $ this ->assertRequestedMembership (true , $ gid );
183
+
184
+ $ REDIS ->flushAll (); // regression test: flush used to break requests
185
+
186
+ $ approve_uid = $ SSO ["user " ];
187
+ switchUser (...$ pi_user_args );
188
+ $ this ->approveUserByPI ($ approve_uid );
189
+ switchUser (...$ user_to_create_args );
190
+
191
+ $ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
192
+ $ this ->assertRequestedMembership (false , $ gid );
193
+ $ this ->assertTrue ($ pi_group ->userExists ($ USER ));
194
+ $ this ->assertTrue ($ USER ->exists ());
195
+ $ this ->assertTrue ($ newOrg ->exists ());
196
+
197
+ // $third_request_failed = false;
198
+ // try {
199
+ $ this ->requestGroupMembership ($ pi_group ->gid );
200
+ // } catch(Exception) {
201
+ // $third_request_failed = true;
202
+ // }
203
+ // $this->assertTrue($third_request_failed);
204
+ $ this ->assertRequestedMembership (false , $ gid );
205
+ $ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
206
+ } finally {
207
+ switchUser (...$ user_to_create_args );
208
+ $ this ->ensureOrgGroupDoesNotExist ();
209
+ $ this ->ensureUserNotInPIGroup ($ pi_group );
210
+ $ this ->ensureUserDoesNotExist ();
211
+ }
212
+ }
213
+
214
+
215
+ public function testCreateUserByJoinGoupByAdmin ()
113
216
{
114
217
global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
115
218
switchUser (...getUserIsPIHasNoMembersNoMemberRequests ());
116
219
$ pi_group = $ USER ->getPIGroup ();
117
220
$ gid = $ pi_group ->gid ;
118
- switchUser (...getNonExistentUser ());
221
+ $ user_to_create_args = getNonExistentUser ();
222
+ switchUser (...$ user_to_create_args );
119
223
$ this ->assertTrue (!$ USER ->exists ());
120
224
$ newOrg = new UnityOrg ($ SSO ["org " ], $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK );
121
225
$ this ->assertTrue (!$ newOrg ->exists ());
@@ -144,7 +248,11 @@ public function testCreateUserByJoinGoup()
144
248
145
249
$ REDIS ->flushAll (); // regression test: flush used to break requests
146
250
147
- $ pi_group ->approveUser ($ USER );
251
+ $ approve_uid = $ SSO ["user " ];
252
+ switchUser (...getAdminUser ());
253
+ $ this ->approveUserByAdmin ($ gid , $ approve_uid );
254
+ switchUser (...$ user_to_create_args );
255
+
148
256
$ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
149
257
$ this ->assertRequestedMembership (false , $ gid );
150
258
$ this ->assertTrue ($ pi_group ->userExists ($ USER ));
@@ -161,16 +269,19 @@ public function testCreateUserByJoinGoup()
161
269
$ this ->assertRequestedMembership (false , $ gid );
162
270
$ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
163
271
} finally {
272
+ switchUser (...$ user_to_create_args );
164
273
$ this ->ensureOrgGroupDoesNotExist ();
165
274
$ this ->ensureUserNotInPIGroup ($ pi_group );
166
275
$ this ->ensureUserDoesNotExist ();
167
276
}
168
277
}
169
278
279
+
170
280
public function testCreateUserByCreateGroup ()
171
281
{
172
282
global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
173
- switchuser (...getNonExistentUser ());
283
+ $ user_to_create_args = getNonExistentUser ();
284
+ switchuser (...$ user_to_create_args );
174
285
$ pi_group = $ USER ->getPIGroup ();
175
286
$ this ->assertTrue (!$ USER ->exists ());
176
287
$ this ->assertTrue (!$ pi_group ->exists ());
@@ -197,7 +308,11 @@ public function testCreateUserByCreateGroup()
197
308
198
309
$ REDIS ->flushAll (); // regression test: flush used to break requests
199
310
200
- $ pi_group ->approveGroup ();
311
+ $ approve_uid = $ SSO ["user " ];
312
+ switchUser (...getAdminUser ());
313
+ $ this ->approveGroup ($ approve_uid );
314
+ switchUser (...$ user_to_create_args );
315
+
201
316
$ this ->assertRequestedPIGroup (false );
202
317
$ this ->assertTrue ($ pi_group ->exists ());
203
318
$ this ->assertTrue ($ USER ->exists ());
0 commit comments