@@ -112,11 +112,12 @@ private function ensureUserDoesNotExist()
112112 }
113113 $ all_users_group = $ LDAP ->getUserGroup ();
114114 $ all_member_uids = $ all_users_group ->getAttribute ("memberuid " );
115- $ new_uids = array_diff ($ all_member_uids , [$ USER ->uid ]);
116115 if (in_array ($ USER ->uid , $ all_member_uids )) {
117116 $ all_users_group ->setAttribute (
118117 "memberuid " ,
119- array_diff ($ all_member_uids , [$ USER ->uid ])
118+ // array_diff will break the contiguity of the array indexes
119+ // ldap_mod_replace requires contiguity, array_values restores contiguity
120+ array_values (array_diff ($ all_member_uids , [$ USER ->uid ]))
120121 );
121122 $ all_users_group ->write ();
122123 assert (!in_array ($ USER ->uid , $ all_users_group ->getAttribute ("memberuid " )));
@@ -221,6 +222,41 @@ public function testCreateUserByJoinGoupByPI()
221222 }
222223 }
223224
225+ public function testCreateMultipleUsersByJoinGoupByPI ()
226+ {
227+ global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK ;
228+ $ pi_user_args = getUserIsPIHasNoMembersNoMemberRequests ();
229+ switchUser (...$ pi_user_args );
230+ $ pi_group = $ USER ->getPIGroup ();
231+ $ gid = $ pi_group ->gid ;
232+ $ this ->assertTrue ($ pi_group ->exists ());
233+ $ users_to_create_args = getNonexistentUsersWithExistentOrg ();
234+ try {
235+ foreach ($ users_to_create_args as $ user_to_create_args ) {
236+ switchUser (...$ user_to_create_args );
237+ $ this ->assertTrue (!$ USER ->exists ());
238+ $ this ->assertTrue (!$ pi_group ->userExists ($ USER ));
239+ $ this ->assertRequestedMembership (false , $ gid );
240+ $ this ->requestGroupMembership ($ pi_group ->gid );
241+ $ this ->assertRequestedMembership (true , $ gid );
242+ $ approve_uid = $ USER ->uid ;
243+ switchUser (...$ pi_user_args );
244+ // $this->assertTrue(!$pi_group->userExists($USER));
245+ $ this ->approveUserByPI ($ approve_uid );
246+ switchUser (...$ user_to_create_args );
247+ $ this ->assertTrue (!$ pi_group ->requestExists ($ USER ));
248+ $ this ->assertRequestedMembership (false , $ gid );
249+ $ this ->assertTrue ($ pi_group ->userExists ($ USER ));
250+ $ this ->assertTrue ($ USER ->exists ());
251+ }
252+ } finally {
253+ foreach ($ users_to_create_args as $ user_to_create_args ) {
254+ switchUser (...$ user_to_create_args );
255+ $ this ->ensureUserNotInPIGroup ($ pi_group );
256+ $ this ->ensureUserDoesNotExist ();
257+ }
258+ }
259+ }
224260
225261 public function testCreateUserByJoinGoupByAdmin ()
226262 {
0 commit comments