From c81911893f8afc752cf598f9419edaeaba79fa27 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 11 Jan 2023 14:04:35 +0000 Subject: [PATCH] tests --- core/database.php | 3 ++- core/tests/util.test.php | 35 +++++++++++++++++++++++++++++++++++ core/util.php | 17 +++-------------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/core/database.php b/core/database.php index d0b726fe..978396af 100644 --- a/core/database.php +++ b/core/database.php @@ -102,7 +102,8 @@ class Database } } - private function get_engine(): DBEngine { + private function get_engine(): DBEngine + { if (is_null($this->engine)) { $this->connect_engine(); } diff --git a/core/tests/util.test.php b/core/tests/util.test.php index a0f45ca5..30fffbf7 100644 --- a/core/tests/util.test.php +++ b/core/tests/util.test.php @@ -10,6 +10,41 @@ require_once "core/util.php"; class UtilTest extends TestCase { + public function test_get_theme() + { + $this->assertEquals("default", get_theme()); + } + + public function test_get_memory_limit() + { + get_memory_limit(); + $this->assertTrue(true); + } + + public function test_check_gd_version() + { + check_gd_version(); + $this->assertTrue(true); + } + + public function test_check_im_version() + { + check_im_version(); + $this->assertTrue(true); + } + + public function test_human_filesize() + { + $this->assertEquals("123.00B", human_filesize(123)); + $this->assertEquals("123B", human_filesize(123, 0)); + $this->assertEquals("120.56KB", human_filesize(123456)); + } + + public function test_generate_key() + { + $this->assertEquals(20, strlen(generate_key())); + } + public function test_warehouse_path() { $hash = "7ac19c10d6859415"; diff --git a/core/util.php b/core/util.php index 88bd7e23..01f5373d 100644 --- a/core/util.php +++ b/core/util.php @@ -207,8 +207,9 @@ function get_session_ip(Config $config): string */ function format_text(string $string): string { - $tfe = send_event(new TextFormattingEvent($string)); - return $tfe->formatted; + $event = new TextFormattingEvent($string); + send_event($event); + return $event->formatted; } /** @@ -397,18 +398,6 @@ function path_to_tags(string $path): string return implode(" ", $tags); } - -function join_url(string $base, string ...$paths): string -{ - $output = $base; - foreach ($paths as $path) { - $output = rtrim($output, "/"); - $path = ltrim($path, "/"); - $output .= "/".$path; - } - return $output; -} - function get_dir_contents(string $dir): array { assert(!empty($dir));