@@ -53,9 +53,54 @@ private function cancelAllRequests()
5353 $ this ->assertTrue ($ redirectedOrDied );
5454 }
5555
56+ // delete requests made by that user
57+ // delete user entry
58+ // remove user from org group
59+ // remove user from "all users" group
60+ // does not remove user from PI groups
61+ private function ensureUserDoesNotExist ()
62+ {
63+ $ SQL ->deleteRequestsByUser ($ USER ->getUID ());
64+ if ($ USER ->exists ()) {
65+ $ USER ->getLDAPUser ()->delete ();
66+ assert (!$ USER ->exists ());
67+ }
68+ $ org = $ USER ->getOrgGroup ();
69+ if ($ org ->inOrg ($ USER )) {
70+ $ org ->removeUser ($ USER );
71+ assert (!$ org ->inOrg ($ USER ));
72+ }
73+ $ all_users_group = $ LDAP ->getUserGroup ();
74+ $ all_member_uids = $ all_users_group ->getAttribute ("memberUid " );
75+ if (in_array ($ USER ->getUID (), $ all_member_uids )) {
76+ $ all_users_group ->setAttribute (
77+ "memberUid " ,
78+ array_diff ($ all_member_uids , [$ USER ->getUID ()])
79+ );
80+ $ all_users_group ->write ();
81+ assert (!in_array ($ USER ->getUID (), $ all_users_group ->getAttribute ("memberUid " )));
82+ }
83+ }
84+
85+ private function ensureUserNotInPIGroup ($ gid )
86+ {
87+ if ($ pi_group ->userExists ($ USER )) {
88+ $ pi_group ->removeUser ($ USER );
89+ assert (!$ pi_group ->userExists ($ USER ));
90+ }
91+ }
92+
93+ private function ensurePIGroupDoesNotExist ()
94+ {
95+ if ($ USER ->getPIGroup ()->exists ()) {
96+ $ USER ->getPIGroup ()->getLDAPPIGroup ()->delete ();
97+ assert (!$ USER ->getPIGroup ()->exists ());
98+ }
99+ }
100+
56101 public function testCreateUserByJoinGoup ()
57102 {
58- global $ USER , $ SQL ;
103+ global $ USER , $ SQL , $ LDAP ;
59104 switchUser (...getUserIsPIHasNoMembersNoMemberRequests ());
60105 $ pi_group = $ USER ->getPIGroup ();
61106 switchUser (...getNonExistentUser ());
@@ -67,13 +112,13 @@ public function testCreateUserByJoinGoup()
67112 $ this ->requestGroupMembership ($ pi_group ->getPIUID ());
68113 $ this ->assertNumberGroupRequests (1 );
69114
70- $ second_request_failed = false ;
71- try {
115+ // $second_request_failed = false;
116+ // try {
72117 $ this ->requestGroupMembership ($ pi_group ->getPIUID ());
73- } catch (Exception ) {
74- $ second_request_failed = true ;
75- }
76- $ this ->assertTrue ($ second_request_failed );
118+ // } catch(Exception) {
119+ // $second_request_failed = true;
120+ // }
121+ // $this->assertTrue($second_request_failed);
77122 $ this ->assertNumberGroupRequests (1 );
78123
79124 $ this ->cancelAllRequests ();
@@ -89,30 +134,24 @@ public function testCreateUserByJoinGoup()
89134 $ this ->assertTrue ($ pi_group ->userExists ($ USER ));
90135 $ this ->assertTrue ($ USER ->exists ());
91136
92- $ third_request_failed = false ;
93- try {
137+ // $third_request_failed = false;
138+ // try {
94139 $ this ->requestGroupMembership ($ pi_group ->getPIUID ());
95- } catch (Exception ) {
96- $ third_request_failed = true ;
97- }
98- $ this ->assertTrue ($ third_request_failed );
140+ // } catch(Exception) {
141+ // $third_request_failed = true;
142+ // }
143+ // $this->assertTrue($third_request_failed);
99144 $ this ->assertNumberGroupRequests (0 );
100145 $ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
101146 } finally {
102- $ SQL ->deleteRequestsByUser ($ USER ->getUID ());
103- if ($ pi_group ->userExists ($ USER )) {
104- $ pi_group ->removeUser ($ USER );
105- }
106- if ($ USER ->exists ()) {
107- $ USER ->getLDAPUser ->delete ();
108- assert (!$ USER ->exists ());
109- }
147+ $ this ->ensureUserNotInPIGroup ($ pi_group ->getPIUID ());
148+ $ this ->ensureUserDoesNotExist ();
110149 }
111150 }
112151
113152 public function testCreateUserByCreateGroup ()
114153 {
115- global $ USER , $ SQL ;
154+ global $ USER , $ SQL , $ LDAP ;
116155 switchuser (...getNonExistentUser ());
117156 $ pi_group = $ USER ->getPIGroup ();
118157 $ this ->assertTrue (!$ USER ->exists ());
@@ -122,13 +161,13 @@ public function testCreateUserByCreateGroup()
122161 $ this ->assertNumberGroupRequests (1 );
123162 $ this ->assertNumberGroupRequests (0 );
124163
125- $ second_request_failed = false ;
126- try {
127- $ this ->requestGroupCreation ();
128- } catch (Exception ) {
164+ // $second_request_failed = false;
165+ // try {
166+ // $this->requestGroupCreation();
167+ // } catch(Exception) {
129168 $ second_request_failed = true ;
130- }
131- $ this ->assertTrue ($ second_request_failed );
169+ // }
170+ // $this->assertTrue($second_request_failed);
132171 $ this ->assertNumberGroupRequests (1 );
133172
134173 $ this ->cancelAllRequests ();
@@ -142,24 +181,17 @@ public function testCreateUserByCreateGroup()
142181 $ this ->assertTrue ($ pi_group ->exists ());
143182 $ this ->assertTrue ($ USER ->exists ());
144183
145- $ third_request_failed = false ;
146- try {
184+ // $third_request_failed = false;
185+ // try {
147186 $ this ->requestGroupCreation ();
148- } catch (Exception ) {
149- $ third_request_failed = true ;
150- }
151- $ this ->assertTrue ($ third_request_failed );
187+ // } catch(Exception) {
188+ // $third_request_failed = true;
189+ // }
190+ // $this->assertTrue($third_request_failed);
152191 $ this ->assertNumberGroupRequests (0 );
153192 } finally {
154- $ SQL ->deleteRequestsByUser ($ USER ->getUID ());
155- if ($ pi_group ->exists ()) {
156- $ pi_group ->getLDAPPIGroup ()->delete ();
157- assert (!$ pi_group ->exists ());
158- }
159- if ($ USER ->exists ()) {
160- $ USER ->getLDAPUser ->delete ();
161- assert (!$ USER ->exists ());
162- }
193+ $ this ->ensurePIGroupDoesNotExist ();
194+ $ this ->ensureUserDoesNotExist ();
163195 }
164196 }
165197}
0 commit comments