3
3
use PHPUnit \Framework \TestCase ;
4
4
use UnityWebPortal \lib \exceptions \PhpUnitNoDieException ;
5
5
use UnityWebPortal \lib \UnityGroup ;
6
+ use UnityWebPortal \lib \UnityOrg ;
7
+ use UnityWebPortal \lib \UnitySQL ;
6
8
7
9
class NewUserTest extends TestCase
8
10
{
9
- private function assertNumberGroupRequests ( int $ x )
11
+ private function assertRequestedPIGroup ( bool $ expected )
10
12
{
11
13
global $ USER , $ SQL ;
12
- $ this ->assertEquals ($ x , count ($ SQL ->getRequestsByUser ($ USER ->getUID ())));
14
+ $ this ->assertEquals (
15
+ $ expected ,
16
+ $ SQL ->requestExists ($ USER ->getUID (), UnitySQL::REQUEST_BECOME_PI )
17
+ );
13
18
}
14
19
15
20
private function requestGroupCreation ()
@@ -45,12 +50,12 @@ private function ensureUserDoesNotExist()
45
50
{
46
51
global $ USER , $ SQL , $ LDAP ;
47
52
$ SQL ->deleteRequestsByUser ($ USER ->getUID ());
48
- $ org = $ USER ->getOrgGroup ();
49
- if ($ org ->exists () and $ org ->inOrg ($ USER )) {
50
- $ org ->removeUser ($ USER );
51
- assert (!$ org ->inOrg ($ USER ));
52
- }
53
53
if ($ USER ->exists ()) {
54
+ $ org = $ USER ->getOrgGroup ();
55
+ if ($ org ->exists () and $ org ->inOrg ($ USER )) {
56
+ $ org ->removeUser ($ USER );
57
+ assert (!$ org ->inOrg ($ USER ));
58
+ }
54
59
$ USER ->getLDAPUser ()->delete ();
55
60
assert (!$ USER ->exists ());
56
61
}
@@ -69,8 +74,8 @@ private function ensureUserDoesNotExist()
69
74
70
75
private function ensureOrgGroupDoesNotExist ()
71
76
{
72
- global $ USER ;
73
- $ org_group = $ USER -> getOrgGroup ( );
77
+ global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
78
+ $ org_group = new UnityOrg ( $ SSO [ " org " ], $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK );
74
79
if ($ org_group ->exists ()) {
75
80
$ org_group ->getLDAPOrgGroup ()->delete ();
76
81
assert (!$ org_group ->exists ());
@@ -97,18 +102,19 @@ private function ensurePIGroupDoesNotExist()
97
102
98
103
public function testCreateUserByJoinGoup ()
99
104
{
100
- global $ USER , $ SQL , $ LDAP ;
105
+ global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
101
106
switchUser (...getUserIsPIHasNoMembersNoMemberRequests ());
102
107
$ pi_group = $ USER ->getPIGroup ();
103
108
switchUser (...getNonExistentUser ());
104
109
$ this ->assertTrue (!$ USER ->exists ());
105
- $ this ->assertTrue (!$ USER ->getOrgGroup ()->exists ());
110
+ $ newOrg = new UnityOrg ($ SSO ["org " ], $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK );
111
+ $ this ->assertTrue (!$ newOrg ->exists ());
106
112
$ this ->assertTrue ($ pi_group ->exists ());
107
113
$ this ->assertTrue (!$ pi_group ->userExists ($ USER ));
108
- $ this ->assertNumberGroupRequests ( 0 );
114
+ $ this ->assertRequestedPIGroup ( false );
109
115
try {
110
116
$ this ->requestGroupMembership ($ pi_group ->getPIUID ());
111
- $ this ->assertNumberGroupRequests ( 1 );
117
+ $ this ->assertRequestedPIGroup ( true );
112
118
113
119
// $second_request_failed = false;
114
120
// try {
@@ -117,21 +123,21 @@ public function testCreateUserByJoinGoup()
117
123
// $second_request_failed = true;
118
124
// }
119
125
// $this->assertTrue($second_request_failed);
120
- $ this ->assertNumberGroupRequests ( 1 );
126
+ $ this ->assertRequestedPIGroup ( true );
121
127
122
128
$ this ->cancelAllRequests ();
123
- $ this ->assertNumberGroupRequests ( 0 );
129
+ $ this ->assertRequestedPIGroup ( false );
124
130
125
131
$ this ->requestGroupMembership ($ pi_group ->getPIUID ());
126
132
$ this ->assertTrue ($ pi_group ->requestExists ($ USER ));
127
- $ this ->assertNumberGroupRequests ( 1 );
133
+ $ this ->assertRequestedPIGroup ( true );
128
134
129
135
$ pi_group ->approveUser ($ USER );
130
136
$ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
131
- $ this ->assertNumberGroupRequests ( 0 );
137
+ $ this ->assertRequestedPIGroup ( false );
132
138
$ this ->assertTrue ($ pi_group ->userExists ($ USER ));
133
139
$ this ->assertTrue ($ USER ->exists ());
134
- $ this ->assertTrue ($ USER -> getOrgGroup () ->exists ());
140
+ $ this ->assertTrue ($ newOrg ->exists ());
135
141
136
142
// $third_request_failed = false;
137
143
// try {
@@ -140,7 +146,7 @@ public function testCreateUserByJoinGoup()
140
146
// $third_request_failed = true;
141
147
// }
142
148
// $this->assertTrue($third_request_failed);
143
- $ this ->assertNumberGroupRequests ( 0 );
149
+ $ this ->assertRequestedPIGroup ( false );
144
150
$ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
145
151
} finally {
146
152
$ this ->ensureUserNotInPIGroup ($ pi_group );
@@ -151,15 +157,16 @@ public function testCreateUserByJoinGoup()
151
157
152
158
public function testCreateUserByCreateGroup ()
153
159
{
154
- global $ USER , $ SQL , $ LDAP ;
160
+ global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
155
161
switchuser (...getNonExistentUser ());
156
162
$ pi_group = $ USER ->getPIGroup ();
157
163
$ this ->assertTrue (!$ USER ->exists ());
158
164
$ this ->assertTrue (!$ pi_group ->exists ());
159
- $ this ->assertTrue (!$ USER ->getOrgGroup ()->exists ());
165
+ $ newOrg = new UnityOrg ($ SSO ["org " ], $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK );
166
+ $ this ->assertTrue (!$ newOrg ->exists ());
160
167
try {
161
168
$ this ->requestGroupCreation ();
162
- $ this ->assertNumberGroupRequests ( 1 );
169
+ $ this ->assertRequestedPIGroup ( true );
163
170
164
171
// $second_request_failed = false;
165
172
// try {
@@ -168,19 +175,19 @@ public function testCreateUserByCreateGroup()
168
175
// $second_request_failed = true;
169
176
// }
170
177
// $this->assertTrue($second_request_failed);
171
- $ this ->assertNumberGroupRequests ( 1 );
178
+ $ this ->assertRequestedPIGroup ( true );
172
179
173
180
$ this ->cancelAllRequests ();
174
- $ this ->assertNumberGroupRequests ( 0 );
181
+ $ this ->assertRequestedPIGroup ( false );
175
182
176
183
$ this ->requestGroupCreation ();
177
- $ this ->assertNumberGroupRequests ( 1 );
184
+ $ this ->assertRequestedPIGroup ( true );
178
185
179
186
$ pi_group ->approveGroup ();
180
- $ this ->assertNumberGroupRequests ( 0 );
187
+ $ this ->assertRequestedPIGroup ( false );
181
188
$ this ->assertTrue ($ pi_group ->exists ());
182
189
$ this ->assertTrue ($ USER ->exists ());
183
- $ this ->assertTrue ($ USER -> getOrgGroup () ->exists ());
190
+ $ this ->assertTrue ($ newOrg ->exists ());
184
191
185
192
// $third_request_failed = false;
186
193
// try {
@@ -189,7 +196,7 @@ public function testCreateUserByCreateGroup()
189
196
// $third_request_failed = true;
190
197
// }
191
198
// $this->assertTrue($third_request_failed);
192
- $ this ->assertNumberGroupRequests ( 0 );
199
+ $ this ->assertRequestedPIGroup ( false );
193
200
} finally {
194
201
$ this ->ensurePIGroupDoesNotExist ();
195
202
$ this ->ensureUserDoesNotExist ();
0 commit comments