Skip to content

Commit b655014

Browse files
committed
add function test for PI become request
1 parent 1c77335 commit b655014

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

resources/lib/UnityWebhook.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class UnityWebhook
88
private $override_template_dir;
99
private $url;
1010
private $MSG_LINKREF;
11+
private $Subject; // set by template
1112

1213
public function __construct(
1314
$template_dir,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class PiBecomeRequestTest extends TestCase
6+
{
7+
private function assertNumberPiBecomeRequests(int $x)
8+
{
9+
global $USER, $SQL;
10+
if ($x == 0) {
11+
$this->assertFalse($SQL->requestExists($USER->getUID()));
12+
} elseif ($x > 0) {
13+
$this->assertTrue($SQL->requestExists($USER->getUID()));
14+
} else {
15+
throw new RuntimeError("x must not be negative");
16+
}
17+
$this->assertEquals($x, $this->getNumberPiBecomeRequests());
18+
}
19+
20+
private function getNumberPiBecomeRequests()
21+
{
22+
global $USER, $SQL;
23+
// FIXME table name, "admin" are private constants in UnitySQL
24+
// FIXME "admin" should be something else
25+
$stmt = $SQL->getConn()->prepare(
26+
"SELECT * FROM requests WHERE uid=:uid and request_for='admin'"
27+
);
28+
$uid = $USER->getUID();
29+
$stmt->bindParam(":uid", $uid);
30+
$stmt->execute();
31+
return count($stmt->fetchAll());
32+
}
33+
34+
public function testRequestBecomePi()
35+
{
36+
global $USER, $SQL;
37+
switchUser(...getUserNotPiNotRequestedBecomePi());
38+
$this->assertFalse($USER->isPI());
39+
$this->assertNumberPiBecomeRequests(0);
40+
post(
41+
__DIR__ . "/../../webroot/panel/account.php",
42+
["form_type" => "pi_request"]
43+
);
44+
$this->assertNumberPiBecomeRequests(1);
45+
post(
46+
__DIR__ . "/../../webroot/panel/account.php",
47+
["form_type" => "pi_request"]
48+
);
49+
$this->assertNumberPiBecomeRequests(1);
50+
}
51+
}

test/phpunit-bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ function getUserHasNotRequestedAccountDeletionHasNoGroups()
8888
{
8989
return ["[email protected]", "foo", "bar", "[email protected]"];
9090
}
91+
92+
function getUserNotPiNotRequestedBecomePi()
93+
{
94+
return ["[email protected]", "foo", "bar", "[email protected]"];
95+
}

0 commit comments

Comments
 (0)