Skip to content

Commit 0fdf40e

Browse files
authored
add page load tests, fix other tests (#280)
* add page load tests * remove imports * fix class name * import DataProvider * ... * make require work for tests * add dummy assertion * use nonexistent user for new_account.php * add missing switchUser * update cache
1 parent d4309f6 commit 0fdf40e

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

test/functional/NewUserTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private function approveGroup($uid)
9494
// does not remove user from PI groups
9595
private function ensureUserDoesNotExist()
9696
{
97-
global $USER, $SQL, $LDAP;
97+
global $USER, $SQL, $LDAP, $REDIS;
9898
$SQL->deleteRequestsByUser($USER->uid);
9999
if ($USER->exists()) {
100100
$org = $USER->getOrgGroup();
@@ -116,6 +116,7 @@ private function ensureUserDoesNotExist()
116116
$all_users_group->write();
117117
assert(!in_array($USER->uid, $all_users_group->getAttribute("memberuid")));
118118
}
119+
$REDIS->removeCacheArray("sorted_users", "", $USER->uid);
119120
}
120121

121122
private function ensureOrgGroupDoesNotExist()
@@ -126,24 +127,28 @@ private function ensureOrgGroupDoesNotExist()
126127
$org_group->delete();
127128
assert(!$org_group->exists());
128129
}
130+
$REDIS->removeCacheArray("sorted_orgs", "", $SSO["org"]);
129131
}
130132

131133
private function ensureUserNotInPIGroup(UnityGroup $pi_group)
132134
{
133-
global $USER;
135+
global $USER, $REDIS;
134136
if ($pi_group->userExists($USER)) {
135137
$pi_group->removeUser($USER);
136138
assert(!$pi_group->userExists($USER));
137139
}
140+
$REDIS->removeCacheArray($pi_group->gid, "members", $USER->uid);
138141
}
139142

140143
private function ensurePIGroupDoesNotExist()
141144
{
142-
global $USER, $LDAP;
145+
global $USER, $LDAP, $REDIS;
146+
$gid = $USER->getPIGroup()->gid;
143147
if ($USER->getPIGroup()->exists()) {
144-
$LDAP->getPIGroupEntry($USER->getPIGroup()->gid)->delete();
148+
$LDAP->getPIGroupEntry($gid)->delete();
145149
assert(!$USER->getPIGroup()->exists());
146150
}
151+
$REDIS->removeCacheArray("sorted_groups", "", $gid);
147152
}
148153

149154
public function testCreateUserByJoinGoupByPI()
@@ -327,6 +332,7 @@ public function testCreateUserByCreateGroup()
327332
// $this->assertTrue($third_request_failed);
328333
$this->assertRequestedPIGroup(false);
329334
} finally {
335+
switchUser(...$user_to_create_args);
330336
$this->ensureOrgGroupDoesNotExist();
331337
$this->ensurePIGroupDoesNotExist();
332338
$this->ensureUserDoesNotExist();

test/functional/PageLoadTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use PHPUnit\Framework\Attributes\DataProvider;
5+
6+
class PageLoadTest extends TestCase
7+
{
8+
public static function provider()
9+
{
10+
$admin = getAdminUser();
11+
$nonexistent_user = getNonExistentUser();
12+
$normal_user = getNormalUser();
13+
$pi = getUserIsPIHasNoMembersNoMemberRequests();
14+
return [
15+
[$admin, __DIR__ . "/../../webroot/admin/pi-mgmt.php"],
16+
[$admin, __DIR__ . "/../../webroot/admin/user-mgmt.php"],
17+
[$admin, __DIR__ . "/../../webroot/admin/content.php"],
18+
[$admin, __DIR__ . "/../../webroot/admin/notices.php"],
19+
[$nonexistent_user, __DIR__ . "/../../webroot/panel/new_account.php"],
20+
[$normal_user, __DIR__ . "/../../webroot/panel/account.php"],
21+
[$normal_user, __DIR__ . "/../../webroot/panel/groups.php"],
22+
[$normal_user, __DIR__ . "/../../webroot/panel/support.php"],
23+
[$pi, __DIR__ . "/../../webroot/panel/pi.php"],
24+
];
25+
}
26+
27+
#[DataProvider("provider")]
28+
public function testLoadPage($user, $path)
29+
{
30+
global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK;
31+
switchuser(...$user);
32+
http_get($path);
33+
$this->assertTrue(true); // assert there were no errors
34+
}
35+
}

webroot/panel/support.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require "../../resources/autoload.php";
3+
require_once __DIR__ . "/../../resources/autoload.php";
44

55
include $LOC_HEADER;
66
?>

0 commit comments

Comments
 (0)