88
99class PIMemberApproveTest extends UnityWebPortalTestCase
1010{
11- // two different ways to accept a user into a PI group
12- public static function approveUserProvider (): TRegxDataProvider
11+ private function approveUserByPI (string $ uid , string $ gid )
1312 {
14- return TRegxDataProvider::list (
15- function ($ uid , $ gid ) {
16- global $ USER ;
17- assert ($ USER ->getPIGroup ()->gid === $ gid , "signed in user must be the group owner " );
18- http_post (__DIR__ . "/../../webroot/panel/pi.php " , [
19- "form_type " => "userReq " ,
20- "action " => "Approve " ,
21- "uid " => $ uid ,
22- ]);
23- },
24- function ($ uid , $ gid ) {
25- http_post (__DIR__ . "/../../webroot/admin/pi-mgmt.php " , [
26- "form_type " => "reqChild " ,
27- "action " => "Approve " ,
28- "pi " => $ gid ,
29- "uid " => $ uid ,
30- ]);
31- },
32- );
13+ global $ USER ;
14+ assert ($ USER ->getPIGroup ()->gid === $ gid , "signed in user must be the group owner " );
15+ http_post (__DIR__ . "/../../webroot/panel/pi.php " , [
16+ "form_type " => "userReq " ,
17+ "action " => "Approve " ,
18+ "uid " => $ uid ,
19+ ]);
20+ }
21+
22+ private function approveUserByAdmin (string $ uid , string $ gid )
23+ {
24+ $ this ->switchUser ("Admin " );
25+ try {
26+ http_post (__DIR__ . "/../../webroot/admin/pi-mgmt.php " , [
27+ "form_type " => "reqChild " ,
28+ "action " => "Approve " ,
29+ "pi " => $ gid ,
30+ "uid " => $ uid ,
31+ ]);
32+ } finally {
33+ $ this ->switchBackUser ();
34+ }
35+ }
36+
37+ public static function provider (): TRegxDataProvider
38+ {
39+ return TRegxDataProvider::list ("approveUserByPI " , "approveUserByAdmin " );
3340 }
3441
35- #[DataProvider("approveUserProvider " )]
36- public function testApproveNonexistentRequest ($ approveUserFunc )
42+ #[DataProvider("provider " )]
43+ public function testApproveNonexistentRequest ($ methodName )
3744 {
3845 global $ USER ;
3946 $ this ->switchUser ("Blank " );
@@ -42,15 +49,15 @@ public function testApproveNonexistentRequest($approveUserFunc)
4249 $ piGroup = $ USER ->getPIGroup ();
4350 try {
4451 $ this ->expectException (Exception::class); // FIXME more specific exception type
45- $ approveUserFunc ( $ uid , $ piGroup ->gid );
52+ call_user_func ([ self ::class, $ methodName ], $ uid , $ piGroup ->gid );
4653 } finally {
4754 $ this ->switchUser ("Blank " , validate: false );
4855 ensureUserNotInPIGroup ($ piGroup );
4956 }
5057 }
5158
52- #[DataProvider("approveUserProvider " )]
53- public function testApproveMember ($ func )
59+ #[DataProvider("provider " )]
60+ public function testApproveMember ($ methodName )
5461 {
5562 global $ USER , $ SSO , $ LDAP , $ SQL , $ MAILER , $ WEBHOOK ;
5663 $ this ->switchUser ("EmptyPIGroupOwner " );
@@ -65,7 +72,7 @@ public function testApproveMember($func)
6572
6673 $ approve_uid = $ SSO ["user " ];
6774 $ this ->switchUser ("EmptyPIGroupOwner " , validate: false );
68- $ func ( $ approve_uid , $ gid );
75+ call_user_func ([ self ::class, $ methodName ], $ approve_uid , $ gid );
6976 $ this ->switchUser ("Blank " , validate: false );
7077
7178 $ this ->assertFalse ($ pi_group ->requestExists ($ USER ));
0 commit comments