[core] Utils tests
This commit is contained in:
parent
dd6c47484d
commit
ae92e42300
2 changed files with 34 additions and 3 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Reference in a new issue