Skip to content

Commit 21a143d

Browse files
committed
add tests
1 parent 5f5bd41 commit 21a143d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use UnityWebPortal\lib\exceptions\PhpUnitNoDieException;
4+
use PHPUnit\Framework\TestCase;
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
7+
class InvalidEPPNTest extends TestCase
8+
{
9+
public static function provider()
10+
{
11+
return [
12+
["", false],
13+
["a", false],
14+
["a@b", true],
15+
["a@b@c", false],
16+
];
17+
}
18+
19+
#[DataProvider("provider")]
20+
public function testInitGetSSO(string $eppn, bool $is_valid): void
21+
{
22+
global $SSO;
23+
$original_server = $_SERVER;
24+
$original_sso = $SSO;
25+
if (!$is_valid) {
26+
$this->expectException(PhpUnitNoDieException::class);
27+
$this->expectExceptionMessageMatches("/.*Invalid eppn.*/");
28+
}
29+
try {
30+
$_SERVER["REMOTE_USER"] = $eppn;
31+
$_SERVER["REMOTE_ADDR"] = "127.0.0.1";
32+
$_SERVER["eppn"] = $eppn;
33+
$_SERVER["givenName"] = "foo";
34+
$_SERVER["sn"] = "bar";
35+
// can't use http_get because it does `require_once`
36+
// won't use phpunit --process-isolation because when I try that argument all tests fail with a blank error message
37+
include __DIR__ . "/../../resources/init.php";
38+
} finally {
39+
session_destroy(); // autoload does session_start()
40+
$_SERVER = $original_server;
41+
$SSO = $original_sso;
42+
}
43+
$this->assertTrue(true); // if $is_valid, there are no other assertions
44+
}
45+
}

test/phpunit-bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once __DIR__ . "/../resources/lib/UnityRedis.php";
2020
require_once __DIR__ . "/../resources/lib/UnityGithub.php";
2121
require_once __DIR__ . "/../resources/lib/exceptions/PhpUnitNoDieException.php";
22+
require_once __DIR__ . "/../resources/lib/exceptions/SSOException.php";
2223

2324
$GLOBALS["PHPUNIT_NO_DIE_PLEASE"] = true;
2425

0 commit comments

Comments
 (0)