Skip to content

Commit 752203c

Browse files
committed
add unit tests
1 parent cbb56e0 commit 752203c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/unit/UtilsTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,29 @@ public function testTestValidSSHKey(bool $expected, string $key)
8080
{
8181
$this->assertEquals($expected, testValidSSHKey($key));
8282
}
83+
84+
public static function URLComponentProvider()
85+
{
86+
if (CONFIG["site"]["prefix"] != "http://127.0.0.1:8000") {
87+
throw new RuntimeException("site prefix has changed!");
88+
}
89+
return [
90+
[["", ""], "http://127.0.0.1:8000"],
91+
[["", "/"], "http://127.0.0.1:8000/"],
92+
[["/", "a"], "http://127.0.0.1:8000/a"],
93+
[["/", "/a"], "http://127.0.0.1:8000/a"],
94+
[["abc", "def"], "http://127.0.0.1:8000/abc/def"],
95+
[["abc", "/def"], "http://127.0.0.1:8000/abc/def"],
96+
[["/abc", "def"], "http://127.0.0.1:8000/abc/def"],
97+
[["/abc", "def///"], "http://127.0.0.1:8000/abc/def/"],
98+
[["", "foo.jpg"], "http://127.0.0.1:8000/foo.jpg"],
99+
[["dir", "0", "a.jpg"], "http://127.0.0.1:8000/dir/0/a.jpg"],
100+
];
101+
}
102+
103+
#[DataProvider("URLComponentProvider")]
104+
public function testGetURL(array $relative_url_components, string $expected)
105+
{
106+
$this->assertEquals($expected, getURL(...$relative_url_components));
107+
}
83108
}

0 commit comments

Comments
 (0)