Skip to content

Commit 5933ced

Browse files
authored
refactor tests (#479)
1 parent a380c5a commit 5933ced

19 files changed

+267
-303
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"phpunit/phpunit": ">=12",
99
"robiningelbrecht/phpunit-coverage-tools": "<2",
1010
"squizlabs/php_codesniffer": "*",
11-
"phpstan/phpstan": "^2.1"
11+
"phpstan/phpstan": "^2.1",
12+
"rawr/phpunit-data-provider": "^3.3"
1213
},
1314
"config": {
1415
"platform": {

composer.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/custom_user_mappings/test.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
user2001_org998_test,555
1+
user2002_org998_test,555
22
foobar0,1000000
33
foobar1,1000001
44
foobar2,1000002

test/functional/AccountDeletionRequestTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class AccountDeletionRequestTest extends UnityWebPortalTestCase
55
public function testRequestAccountDeletionUserHasNoGroups()
66
{
77
global $USER, $SQL;
8-
switchUser(...getBlankUser());
8+
$this->switchUser("Blank");
99
$this->assertEmpty($USER->getPIGroupGIDs());
1010
$this->assertNumberAccountDeletionRequests(0);
1111
try {
@@ -27,7 +27,7 @@ public function testRequestAccountDeletionUserHasGroup()
2727
{
2828
// FIXME this should be an error
2929
global $USER, $SQL;
30-
switchUser(...getUserHasNotRequestedAccountDeletionHasGroup());
30+
$this->switchUser("HasNotRequestedAccountDeletionHasGroup");
3131
$this->assertNotEmpty($USER->getPIGroupGIDs());
3232
$this->assertNumberAccountDeletionRequests(0);
3333
try {
@@ -45,13 +45,11 @@ public function testRequestAccountDeletionUserHasGroup()
4545
public function testRequestAccountDeletionUserHasRequest()
4646
{
4747
global $USER, $SQL;
48-
$pi_args = getUserIsPIHasNoMembersNoMemberRequests();
49-
switchUser(...$pi_args);
48+
$this->switchUser("IsPIHasNoMembersNoMemberRequests");
5049
$pi = $USER;
5150
$pi_group = $USER->getPIGroup();
5251
$this->assertEqualsCanonicalizing([$pi->uid], $pi_group->getMemberUIDs());
53-
$user_args = getBlankUser();
54-
switchUser(...$user_args);
52+
$this->switchUser("Blank");
5553
$this->assertEmpty($USER->getPIGroupGIDs());
5654
$this->assertNumberAccountDeletionRequests(0);
5755
$this->assertNumberRequests(0);
@@ -73,7 +71,7 @@ public function testRequestAccountDeletionUserHasRequest()
7371
public function testRequestAccountDeletionCancel()
7472
{
7573
global $USER;
76-
switchUser(...getBlankUser());
74+
$this->switchUser("Blank");
7775
$this->assertEmpty($USER->getPIGroupGIDs());
7876
$this->assertNumberAccountDeletionRequests(0);
7977
$this->assertNumberRequests(0);

test/functional/DeleteMessageTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
43
use UnityWebPortal\lib\UnityHTTPD;
54
use UnityWebPortal\lib\UnityHTTPDMessageLevel;
65

7-
class DeleteMessageTest extends TestCase
6+
class DeleteMessageTest extends UnityWebPortalTestCase
87
{
98
public function testDeleteMessage(): void
109
{
11-
switchUser(...getBlankUser());
10+
$this->switchUser("Blank");
1211
$initial = UnityHTTPD::getMessages();
1312
$this->assertEmpty($initial);
1413
UnityHTTPD::messageDebug("foo1", "bar1");

test/functional/LoginShellSetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ class LoginShellSetTest extends UnityWebPortalTestCase
66
{
77
private static $_initialLoginShell;
88

9-
public static function setUpBeforeClass(): void
9+
public function setUp(): void
1010
{
1111
global $USER;
12-
switchUser(...getNormalUser());
12+
parent::setUp();
13+
$this->switchUser("Normal");
1314
self::$_initialLoginShell = $USER->getLoginShell();
1415
}
1516

test/functional/PIBecomeApproveTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ private function approveGroup($uid)
3232
public function testApprovePI()
3333
{
3434
global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK;
35-
$user_to_qualify_args = getUnqualifiedUser();
36-
switchuser(...$user_to_qualify_args);
35+
$this->switchUser("Unqualified");
3736
$pi_group = $USER->getPIGroup();
3837
$this->assertTrue($USER->exists());
3938
$this->assertFalse($pi_group->exists());
@@ -57,9 +56,9 @@ public function testApprovePI()
5756
$this->assertRequestedPIGroup(true);
5857

5958
$approve_uid = $SSO["user"];
60-
switchUser(...getAdminUser());
59+
$this->switchUser("Admin");
6160
$this->approveGroup($approve_uid);
62-
switchUser(...$user_to_qualify_args);
61+
$this->switchUser("Unqualified");
6362

6463
$this->assertRequestedPIGroup(false);
6564
$this->assertTrue($pi_group->exists());
@@ -74,7 +73,7 @@ public function testApprovePI()
7473
// $this->assertTrue($third_request_failed);
7574
$this->assertRequestedPIGroup(false);
7675
} finally {
77-
switchUser(...$user_to_qualify_args);
76+
$this->switchUser("Unqualified");
7877
ensurePIGroupDoesNotExist();
7978
}
8079
}

test/functional/PIMemberRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ private function cancelRequest(string $gid)
2626
public function testRequestMembership()
2727
{
2828
global $USER, $SQL;
29-
switchUser(...getUserIsPIHasNoMembersNoMemberRequests());
29+
$this->switchUser("IsPIHasNoMembersNoMemberRequests");
3030
$pi = $USER;
3131
$pi_group = $USER->getPIGroup();
3232
$gid = $pi_group->gid;
3333
$this->assertTrue($USER->isPI());
3434
$this->assertTrue($pi_group->exists());
3535
$this->assertEqualsCanonicalizing([$pi], $pi_group->getGroupMembers());
3636
$this->assertEqualsCanonicalizing([], $SQL->getRequests($gid));
37-
switchUser(...getBlankUser());
37+
$this->switchUser("Blank");
3838
$uid = $USER->uid;
3939
$this->assertFalse($USER->isPI());
4040
$this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI));

test/functional/PageLoadTest.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,24 @@ class PageLoadTest extends UnityWebPortalTestCase
66
{
77
public static function provider()
88
{
9-
$admin = getAdminUser();
10-
$nonexistent_user = getNonExistentUser();
11-
$normal_user = getNormalUser();
12-
$pi = getUserIsPIHasNoMembersNoMemberRequests();
139
return [
14-
[$admin, __DIR__ . "/../../webroot/admin/pi-mgmt.php"],
15-
[$admin, __DIR__ . "/../../webroot/admin/user-mgmt.php"],
16-
[$admin, __DIR__ . "/../../webroot/admin/content.php"],
17-
[$admin, __DIR__ . "/../../webroot/admin/notices.php"],
18-
[$nonexistent_user, __DIR__ . "/../../webroot/panel/new_account.php"],
19-
[$normal_user, __DIR__ . "/../../webroot/panel/account.php"],
20-
[$normal_user, __DIR__ . "/../../webroot/panel/groups.php"],
21-
[$normal_user, __DIR__ . "/../../webroot/panel/support.php"],
22-
[$pi, __DIR__ . "/../../webroot/panel/pi.php"],
10+
["Admin", __DIR__ . "/../../webroot/admin/pi-mgmt.php"],
11+
["Admin", __DIR__ . "/../../webroot/admin/user-mgmt.php"],
12+
["Admin", __DIR__ . "/../../webroot/admin/content.php"],
13+
["Admin", __DIR__ . "/../../webroot/admin/notices.php"],
14+
["NonExistent", __DIR__ . "/../../webroot/panel/new_account.php"],
15+
["Normal", __DIR__ . "/../../webroot/panel/account.php"],
16+
["Normal", __DIR__ . "/../../webroot/panel/groups.php"],
17+
["Normal", __DIR__ . "/../../webroot/panel/support.php"],
18+
["IsPIHasNoMembersNoMemberRequests", __DIR__ . "/../../webroot/panel/pi.php"],
2319
];
2420
}
2521

2622
#[DataProvider("provider")]
27-
public function testLoadPage($user, $path)
23+
public function testLoadPage($nickname, $path)
2824
{
2925
global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK;
30-
switchuser(...$user);
26+
$this->switchUser($nickname);
3127
http_get($path);
3228
$this->assertTrue(true); // assert there were no errors
3329
}

test/functional/PiBecomeRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PIBecomeRequestTest extends UnityWebPortalTestCase
77
public function testRequestBecomePi()
88
{
99
global $USER, $SQL;
10-
switchUser(...getBlankUser());
10+
$this->switchUser("Blank");
1111
$this->assertFalse($USER->isPI());
1212
$this->assertNumberPiBecomeRequests(0);
1313
try {
@@ -43,7 +43,7 @@ public function testRequestBecomePi()
4343
public function testRequestBecomePiUserRequestedAccountDeletion()
4444
{
4545
global $USER, $SQL;
46-
switchUser(...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion());
46+
$this->switchUser("NotPiNotRequestedBecomePiRequestedAccountDeletion");
4747
$this->assertFalse($USER->isPI());
4848
$this->assertNumberPiBecomeRequests(0);
4949
$this->assertTrue($SQL->accDeletionRequestExists($USER->uid));

0 commit comments

Comments
 (0)