[core] Utils tests

This commit is contained in:
Shish 2024-02-21 23:40:10 +00:00 committed by Shish
parent dd6c47484d
commit ae92e42300
2 changed files with 34 additions and 3 deletions

View file

@ -162,4 +162,35 @@ class UtilTest extends TestCase
path_to_tags("/category:/tag/baz.jpg") 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
);
}
} }

View file

@ -21,10 +21,10 @@ function get_theme(): string
return $theme; return $theme;
} }
function contact_link(): ?string function contact_link(?string $contact = null): ?string
{ {
global $config; global $config;
$text = $config->get_string('contact_link'); $text = $contact ?? $config->get_string('contact_link');
if (is_null($text)) { if (is_null($text)) {
return null; return null;
} }
@ -42,7 +42,7 @@ function contact_link(): ?string
} }
if (str_contains($text, "/")) { if (str_contains($text, "/")) {
return "http://$text"; return "https://$text";
} }
return $text; return $text;