diff --git a/core/tests/UtilTest.php b/core/tests/UtilTest.php index d622cc2d..d99b1fa5 100644 --- a/core/tests/UtilTest.php +++ b/core/tests/UtilTest.php @@ -162,4 +162,35 @@ class UtilTest extends TestCase path_to_tags("/category:/tag/baz.jpg") ); } + + public function test_contact_link(): void + { + $this->assertEquals( + "mailto:asdf@example.com", + contact_link("asdf@example.com") + ); + $this->assertEquals( + "http://example.com", + contact_link("http://example.com") + ); + $this->assertEquals( + "https://foo.com/bar", + contact_link("foo.com/bar") + ); + $this->assertEquals( + "john", + contact_link("john") + ); + } + + public function test_get_user(): void + { + // TODO: HTTP_AUTHORIZATION + // TODO: cookie user + session + // fallback to anonymous + $this->assertEquals( + "Anonymous", + _get_user()->name + ); + } } diff --git a/core/util.php b/core/util.php index b237e4a4..45d26d5e 100644 --- a/core/util.php +++ b/core/util.php @@ -21,10 +21,10 @@ function get_theme(): string return $theme; } -function contact_link(): ?string +function contact_link(?string $contact = null): ?string { global $config; - $text = $config->get_string('contact_link'); + $text = $contact ?? $config->get_string('contact_link'); if (is_null($text)) { return null; } @@ -42,7 +42,7 @@ function contact_link(): ?string } if (str_contains($text, "/")) { - return "http://$text"; + return "https://$text"; } return $text;