diff --git a/core/extension.php b/core/extension.php index b544acf0..54074b13 100644 --- a/core/extension.php +++ b/core/extension.php @@ -409,8 +409,6 @@ abstract class DataHandlerExtension extends Extension protected function create_image_from_data(string $filename, array $metadata): Image { - global $config; - $image = new Image(); $image->filesize = $metadata['size']; diff --git a/core/imageboard/misc.php b/core/imageboard/misc.php index 8bef7bec..ba0856ea 100644 --- a/core/imageboard/misc.php +++ b/core/imageboard/misc.php @@ -33,11 +33,6 @@ function add_dir(string $base): array /** * Sends a DataUploadEvent for a file. - * - * @param string $tmpname - * @param string $filename - * @param string $tags - * @throws UploadException */ function add_image(string $tmpname, string $filename, string $tags): int { diff --git a/core/install.php b/core/install.php index d739646e..74bb3e72 100644 --- a/core/install.php +++ b/core/install.php @@ -49,7 +49,6 @@ function get_dsn() { if (getenv("INSTALL_DSN")) { $dsn = getenv("INSTALL_DSN"); - ; } elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) { /** @noinspection PhpUnhandledExceptionInspection */ $id = bin2hex(random_bytes(5)); diff --git a/core/sanitize_php.php b/core/sanitize_php.php index 8a5b2e3d..5f36cddb 100644 --- a/core/sanitize_php.php +++ b/core/sanitize_php.php @@ -56,5 +56,5 @@ if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { die("CLI with remote addr? Confused, not taking the risk."); } $_SERVER['REMOTE_ADDR'] = "0.0.0.0"; - $_SERVER['HTTP_HOST'] = ""; + $_SERVER['HTTP_HOST'] = "cli-command"; } diff --git a/core/tests/polyfills.test.php b/core/tests/polyfills.test.php index ba5b6fcd..9ca56d33 100644 --- a/core/tests/polyfills.test.php +++ b/core/tests/polyfills.test.php @@ -9,13 +9,13 @@ class PolyfillsTest extends TestCase public function test_html_escape() { $this->assertEquals( - html_escape("Foo & "), - "Foo & <waffles>" + "Foo & <main>", + html_escape("Foo &
") ); $this->assertEquals( - html_unescape("Foo & <waffles>"), - "Foo & " + "Foo &
", + html_unescape("Foo & <main>") ); $x = "Foo & <waffles>"; @@ -24,17 +24,17 @@ class PolyfillsTest extends TestCase public function test_int_escape() { - $this->assertEquals(int_escape(""), 0); - $this->assertEquals(int_escape("1"), 1); - $this->assertEquals(int_escape("-1"), -1); - $this->assertEquals(int_escape("-1.5"), -1); - $this->assertEquals(int_escape(null), 0); + $this->assertEquals(0, int_escape("")); + $this->assertEquals(1, int_escape("1")); + $this->assertEquals(-1, int_escape("-1")); + $this->assertEquals(-1, int_escape("-1.5")); + $this->assertEquals(0, int_escape(null)); } public function test_url_escape() { - $this->assertEquals(url_escape("^\o/^"), "%5E%5Co%2F%5E"); - $this->assertEquals(url_escape(null), ""); + $this->assertEquals("%5E%5Co%2F%5E", url_escape("^\o/^")); + $this->assertEquals("", url_escape(null)); } public function test_bool_escape() @@ -69,33 +69,33 @@ class PolyfillsTest extends TestCase public function test_clamp() { - $this->assertEquals(clamp(0, 5, 10), 5); - $this->assertEquals(clamp(5, 5, 10), 5); - $this->assertEquals(clamp(7, 5, 10), 7); - $this->assertEquals(clamp(10, 5, 10), 10); - $this->assertEquals(clamp(15, 5, 10), 10); + $this->assertEquals(5, clamp(0, 5, 10)); + $this->assertEquals(5, clamp(5, 5, 10)); + $this->assertEquals(7, clamp(7, 5, 10)); + $this->assertEquals(10, clamp(10, 5, 10)); + $this->assertEquals(10, clamp(15, 5, 10)); } public function test_truncate() { - $this->assertEquals(truncate("test words", 10), "test words"); - $this->assertEquals(truncate("test...", 9), "test..."); - $this->assertEquals(truncate("test...", 6), "test..."); - $this->assertEquals(truncate("te...", 2), "te..."); + $this->assertEquals("test words", truncate("test words", 10)); + $this->assertEquals("test...", truncate("test...", 9)); + $this->assertEquals("test...", truncate("test...", 6)); + $this->assertEquals("te...", truncate("te...", 2)); } public function test_to_shorthand_int() { - $this->assertEquals(to_shorthand_int(1231231231), "1.1GB"); - $this->assertEquals(to_shorthand_int(2), "2"); + $this->assertEquals("1.1GB", to_shorthand_int(1231231231)); + $this->assertEquals("2", to_shorthand_int(2)); } public function test_parse_shorthand_int() { - $this->assertEquals(parse_shorthand_int("foo"), -1); - $this->assertEquals(parse_shorthand_int("32M"), 33554432); - $this->assertEquals(parse_shorthand_int("43.4KB"), 44441); - $this->assertEquals(parse_shorthand_int("1231231231"), 1231231231); + $this->assertEquals(-1, parse_shorthand_int("foo")); + $this->assertEquals(33554432, parse_shorthand_int("32M")); + $this->assertEquals(44441, parse_shorthand_int("43.4KB")); + $this->assertEquals(1231231231, parse_shorthand_int("1231231231")); } public function test_format_milliseconds() diff --git a/core/tests/urls.test.php b/core/tests/urls.test.php index 74b952cc..c35c6655 100644 --- a/core/tests/urls.test.php +++ b/core/tests/urls.test.php @@ -43,13 +43,13 @@ class UrlsTest extends TestCase { // relative to shimmie install $this->assertEquals( - "http:///test/foo", + "http://cli-command/test/foo", make_http("foo") ); // relative to web server $this->assertEquals( - "http:///foo", + "http://cli-command/foo", make_http("/foo") ); diff --git a/ext/ban_words/test.php b/ext/ban_words/test.php index 448694dc..a79ccefb 100644 --- a/ext/ban_words/test.php +++ b/ext/ban_words/test.php @@ -8,7 +8,7 @@ class BanWordsTest extends ShimmiePHPUnitTestCase send_event(new CommentPostingEvent($image_id, $user, $words)); $this->fail("Exception not thrown"); } catch (CommentPostingException $e) { - $this->assertEquals($e->getMessage(), "Comment contains banned terms"); + $this->assertEquals("Comment contains banned terms", $e->getMessage()); } } diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index c585c37e..8284ae92 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -4,60 +4,60 @@ class BBCodeTest extends ShimmiePHPUnitTestCase public function testBasics() { $this->assertEquals( - $this->filter("[b]bold[/b][i]italic[/i]"), - "bolditalic" + "bolditalic", + $this->filter("[b]bold[/b][i]italic[/i]") ); } public function testStacking() { $this->assertEquals( - $this->filter("[b]B[/b][i]I[/i][b]B[/b]"), - "BIB" + "BIB", + $this->filter("[b]B[/b][i]I[/i][b]B[/b]") ); $this->assertEquals( - $this->filter("[b]bold[i]bolditalic[/i]bold[/b]"), - "boldbolditalicbold" + "boldbolditalicbold", + $this->filter("[b]bold[i]bolditalic[/i]bold[/b]") ); } public function testFailure() { $this->assertEquals( - $this->filter("[b]bold[i]italic"), - "[b]bold[i]italic" + "[b]bold[i]italic", + $this->filter("[b]bold[i]italic") ); } public function testCode() { $this->assertEquals( - $this->filter("[code][b]bold[/b][/code]"), - "
[b]bold[/b]
" + "
[b]bold[/b]
", + $this->filter("[code][b]bold[/b][/code]") ); } public function testNestedList() { $this->assertEquals( - $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"), - "
  • a
    • a
    • b
  • b
" + "
  • a
    • a
    • b
  • b
", + $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]") ); $this->assertEquals( - $this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]"), - "
  • a
    1. a
    2. b
  • b
" + "
  • a
    1. a
    2. b
  • b
", + $this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]") ); } public function testSpoiler() { $this->assertEquals( - $this->filter("[spoiler]ShishNet[/spoiler]"), - "ShishNet" + "ShishNet", + $this->filter("[spoiler]ShishNet[/spoiler]") ); $this->assertEquals( - $this->strip("[spoiler]ShishNet[/spoiler]"), - "FuvfuArg" + "FuvfuArg", + $this->strip("[spoiler]ShishNet[/spoiler]") ); #$this->assertEquals( # $this->filter("[spoiler]ShishNet"), @@ -67,32 +67,32 @@ class BBCodeTest extends ShimmiePHPUnitTestCase public function testURL() { $this->assertEquals( - $this->filter("[url]https://shishnet.org[/url]"), - "https://shishnet.org" + "https://shishnet.org", + $this->filter("[url]https://shishnet.org[/url]") ); $this->assertEquals( - $this->filter("[url=https://shishnet.org]ShishNet[/url]"), - "ShishNet" + "ShishNet", + $this->filter("[url=https://shishnet.org]ShishNet[/url]") ); $this->assertEquals( - $this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"), - "[url=javascript:alert(\"owned\")]click to fail[/url]" + "[url=javascript:alert(\"owned\")]click to fail[/url]", + $this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]") ); } public function testEmailURL() { $this->assertEquals( - $this->filter("[email]spam@shishnet.org[/email]"), - "spam@shishnet.org" + "spam@shishnet.org", + $this->filter("[email]spam@shishnet.org[/email]") ); } public function testAnchor() { $this->assertEquals( - $this->filter("[anchor=rules]Rules[/anchor]"), - 'Rules ' + 'Rules ', + $this->filter("[anchor=rules]Rules[/anchor]") ); } diff --git a/ext/log_db/main.php b/ext/log_db/main.php index d09a82cd..a6ffd357 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -169,8 +169,9 @@ class MessageColumn extends Column protected function scan_entities(string $line) { - return preg_replace_callback("/Image #(\d+)/s", [$this, "link_image"], $line); - return preg_replace_callback("/>>(\d+)/s", [$this, "link_image"], $line); + $line = preg_replace_callback("/Image #(\d+)/s", [$this, "link_image"], $line); + $line = preg_replace_callback("/>>(\d+)/s", [$this, "link_image"], $line); + return $line; } protected function link_image($id) diff --git a/ext/mime/test.php b/ext/mime/test.php index 91b37a40..03efd73c 100644 --- a/ext/mime/test.php +++ b/ext/mime/test.php @@ -4,6 +4,6 @@ class MimeSystemTest extends ShimmiePHPUnitTestCase public function testJPEG() { $result = MimeType::get_for_file("tests/bedroom_workshop.jpg"); - $this->assertEquals($result, MimeType::JPEG); + $this->assertEquals(MimeType::JPEG, $result); } }