-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPIBecomeApproveTest.php
More file actions
101 lines (89 loc) · 3.15 KB
/
PIBecomeApproveTest.php
File metadata and controls
101 lines (89 loc) · 3.15 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
<?php
use UnityWebPortal\lib\UserFlag;
class PIBecomeApproveTest extends UnityWebPortalTestCase
{
private function requestGroupCreation()
{
http_post(__DIR__ . "/../../webroot/panel/account.php", [
"form_type" => "pi_request",
"tos" => "agree",
"account_policy" => "agree",
]);
}
private function cancelRequestGroupCreation()
{
http_post(__DIR__ . "/../../webroot/panel/account.php", [
"form_type" => "cancel_pi_request",
]);
}
private function approveGroup($uid)
{
http_post(__DIR__ . "/../../webroot/admin/pi-mgmt.php", [
"form_type" => "req",
"action" => "Approve",
"uid" => $uid,
]);
}
public function testApprovePI()
{
global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK;
$this->switchUser("Blank");
$pi_group = $USER->getPIGroup();
try {
$this->requestGroupCreation();
$this->assertRequestedPIGroup(true);
// $second_request_failed = false;
// try {
$this->requestGroupCreation();
// } catch(Exception) {
// $second_request_failed = true;
// }
// $this->assertTrue($second_request_failed);
$this->assertRequestedPIGroup(true);
$this->cancelRequestGroupCreation();
$this->assertRequestedPIGroup(false);
$this->requestGroupCreation();
$this->assertRequestedPIGroup(true);
$approve_uid = $SSO["user"];
$this->switchUser("Admin");
$this->approveGroup($approve_uid);
$this->switchUser("Blank", validate: false);
$this->assertRequestedPIGroup(false);
$this->assertTrue($pi_group->exists());
$this->assertTrue($USER->getFlag(UserFlag::QUALIFIED));
// $third_request_failed = false;
// try {
$this->requestGroupCreation();
// } catch(Exception) {
// $third_request_failed = true;
// }
// $this->assertTrue($third_request_failed);
$this->assertRequestedPIGroup(false);
} finally {
ensurePIGroupDoesNotExist($pi_group->gid);
$this->assertFalse($USER->getFlag(UserFlag::QUALIFIED));
}
}
public function testReenableGroup()
{
global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK;
$this->switchUser("ReenabledOwnerOfDisabledPIGroup");
$this->assertFalse($USER->isPI());
$user = $USER;
$pi_group = $USER->getPIGroup();
$approve_uid = $USER->uid;
try {
$this->requestGroupCreation();
$this->assertRequestedPIGroup(true);
$this->switchUser("Admin");
$this->approveGroup($approve_uid);
$this->assertTrue($user->isPI());
} finally {
if ($pi_group->memberUIDExists($approve_uid)) {
$pi_group->removeMemberUID($approve_uid);
callPrivateMethod($pi_group, "setIsDisabled", true);
assert(!$user->isPI());
}
}
}
}