This commit is contained in:
Shish 2020-10-24 13:46:49 +01:00
parent 9b878d98d6
commit 8ff70134ae
10 changed files with 62 additions and 69 deletions

View File

@ -409,8 +409,6 @@ abstract class DataHandlerExtension extends Extension
protected function create_image_from_data(string $filename, array $metadata): Image protected function create_image_from_data(string $filename, array $metadata): Image
{ {
global $config;
$image = new Image(); $image = new Image();
$image->filesize = $metadata['size']; $image->filesize = $metadata['size'];

View File

@ -33,11 +33,6 @@ function add_dir(string $base): array
/** /**
* Sends a DataUploadEvent for a file. * 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 function add_image(string $tmpname, string $filename, string $tags): int
{ {

View File

@ -49,7 +49,6 @@ function get_dsn()
{ {
if (getenv("INSTALL_DSN")) { if (getenv("INSTALL_DSN")) {
$dsn = getenv("INSTALL_DSN"); $dsn = getenv("INSTALL_DSN");
;
} elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) { } elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) {
/** @noinspection PhpUnhandledExceptionInspection */ /** @noinspection PhpUnhandledExceptionInspection */
$id = bin2hex(random_bytes(5)); $id = bin2hex(random_bytes(5));

View File

@ -56,5 +56,5 @@ if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
die("CLI with remote addr? Confused, not taking the risk."); die("CLI with remote addr? Confused, not taking the risk.");
} }
$_SERVER['REMOTE_ADDR'] = "0.0.0.0"; $_SERVER['REMOTE_ADDR'] = "0.0.0.0";
$_SERVER['HTTP_HOST'] = "<cli command>"; $_SERVER['HTTP_HOST'] = "cli-command";
} }

View File

@ -9,13 +9,13 @@ class PolyfillsTest extends TestCase
public function test_html_escape() public function test_html_escape()
{ {
$this->assertEquals( $this->assertEquals(
html_escape("Foo & <waffles>"), "Foo &amp; &lt;main&gt;",
"Foo &amp; &lt;waffles&gt;" html_escape("Foo & <main>")
); );
$this->assertEquals( $this->assertEquals(
html_unescape("Foo &amp; &lt;waffles&gt;"), "Foo & <main>",
"Foo & <waffles>" html_unescape("Foo &amp; &lt;main&gt;")
); );
$x = "Foo &amp; &lt;waffles&gt;"; $x = "Foo &amp; &lt;waffles&gt;";
@ -24,17 +24,17 @@ class PolyfillsTest extends TestCase
public function test_int_escape() public function test_int_escape()
{ {
$this->assertEquals(int_escape(""), 0); $this->assertEquals(0, int_escape(""));
$this->assertEquals(int_escape("1"), 1); $this->assertEquals(1, int_escape("1"));
$this->assertEquals(int_escape("-1"), -1); $this->assertEquals(-1, int_escape("-1"));
$this->assertEquals(int_escape("-1.5"), -1); $this->assertEquals(-1, int_escape("-1.5"));
$this->assertEquals(int_escape(null), 0); $this->assertEquals(0, int_escape(null));
} }
public function test_url_escape() public function test_url_escape()
{ {
$this->assertEquals(url_escape("^\o/^"), "%5E%5Co%2F%5E"); $this->assertEquals("%5E%5Co%2F%5E", url_escape("^\o/^"));
$this->assertEquals(url_escape(null), ""); $this->assertEquals("", url_escape(null));
} }
public function test_bool_escape() public function test_bool_escape()
@ -69,33 +69,33 @@ class PolyfillsTest extends TestCase
public function test_clamp() public function test_clamp()
{ {
$this->assertEquals(clamp(0, 5, 10), 5); $this->assertEquals(5, clamp(0, 5, 10));
$this->assertEquals(clamp(5, 5, 10), 5); $this->assertEquals(5, clamp(5, 5, 10));
$this->assertEquals(clamp(7, 5, 10), 7); $this->assertEquals(7, clamp(7, 5, 10));
$this->assertEquals(clamp(10, 5, 10), 10); $this->assertEquals(10, clamp(10, 5, 10));
$this->assertEquals(clamp(15, 5, 10), 10); $this->assertEquals(10, clamp(15, 5, 10));
} }
public function test_truncate() public function test_truncate()
{ {
$this->assertEquals(truncate("test words", 10), "test words"); $this->assertEquals("test words", truncate("test words", 10));
$this->assertEquals(truncate("test...", 9), "test..."); $this->assertEquals("test...", truncate("test...", 9));
$this->assertEquals(truncate("test...", 6), "test..."); $this->assertEquals("test...", truncate("test...", 6));
$this->assertEquals(truncate("te...", 2), "te..."); $this->assertEquals("te...", truncate("te...", 2));
} }
public function test_to_shorthand_int() public function test_to_shorthand_int()
{ {
$this->assertEquals(to_shorthand_int(1231231231), "1.1GB"); $this->assertEquals("1.1GB", to_shorthand_int(1231231231));
$this->assertEquals(to_shorthand_int(2), "2"); $this->assertEquals("2", to_shorthand_int(2));
} }
public function test_parse_shorthand_int() public function test_parse_shorthand_int()
{ {
$this->assertEquals(parse_shorthand_int("foo"), -1); $this->assertEquals(-1, parse_shorthand_int("foo"));
$this->assertEquals(parse_shorthand_int("32M"), 33554432); $this->assertEquals(33554432, parse_shorthand_int("32M"));
$this->assertEquals(parse_shorthand_int("43.4KB"), 44441); $this->assertEquals(44441, parse_shorthand_int("43.4KB"));
$this->assertEquals(parse_shorthand_int("1231231231"), 1231231231); $this->assertEquals(1231231231, parse_shorthand_int("1231231231"));
} }
public function test_format_milliseconds() public function test_format_milliseconds()

View File

@ -43,13 +43,13 @@ class UrlsTest extends TestCase
{ {
// relative to shimmie install // relative to shimmie install
$this->assertEquals( $this->assertEquals(
"http://<cli command>/test/foo", "http://cli-command/test/foo",
make_http("foo") make_http("foo")
); );
// relative to web server // relative to web server
$this->assertEquals( $this->assertEquals(
"http://<cli command>/foo", "http://cli-command/foo",
make_http("/foo") make_http("/foo")
); );

View File

@ -8,7 +8,7 @@ class BanWordsTest extends ShimmiePHPUnitTestCase
send_event(new CommentPostingEvent($image_id, $user, $words)); send_event(new CommentPostingEvent($image_id, $user, $words));
$this->fail("Exception not thrown"); $this->fail("Exception not thrown");
} catch (CommentPostingException $e) { } catch (CommentPostingException $e) {
$this->assertEquals($e->getMessage(), "Comment contains banned terms"); $this->assertEquals("Comment contains banned terms", $e->getMessage());
} }
} }

View File

@ -4,60 +4,60 @@ class BBCodeTest extends ShimmiePHPUnitTestCase
public function testBasics() public function testBasics()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[b]bold[/b][i]italic[/i]"), "<b>bold</b><i>italic</i>",
"<b>bold</b><i>italic</i>" $this->filter("[b]bold[/b][i]italic[/i]")
); );
} }
public function testStacking() public function testStacking()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[b]B[/b][i]I[/i][b]B[/b]"), "<b>B</b><i>I</i><b>B</b>",
"<b>B</b><i>I</i><b>B</b>" $this->filter("[b]B[/b][i]I[/i][b]B[/b]")
); );
$this->assertEquals( $this->assertEquals(
$this->filter("[b]bold[i]bolditalic[/i]bold[/b]"), "<b>bold<i>bolditalic</i>bold</b>",
"<b>bold<i>bolditalic</i>bold</b>" $this->filter("[b]bold[i]bolditalic[/i]bold[/b]")
); );
} }
public function testFailure() public function testFailure()
{ {
$this->assertEquals( $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() public function testCode()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[code][b]bold[/b][/code]"), "<pre>[b]bold[/b]</pre>",
"<pre>[b]bold[/b]</pre>" $this->filter("[code][b]bold[/b][/code]")
); );
} }
public function testNestedList() public function testNestedList()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"), "<ul><li>a<ul><li>a<li>b</ul><li>b</ul>",
"<ul><li>a<ul><li>a<li>b</ul><li>b</ul>" $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]")
); );
$this->assertEquals( $this->assertEquals(
$this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]"), "<ul><li>a<ol><li>a<li>b</ol><li>b</ul>",
"<ul><li>a<ol><li>a<li>b</ol><li>b</ul>" $this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]")
); );
} }
public function testSpoiler() public function testSpoiler()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[spoiler]ShishNet[/spoiler]"), "<span style=\"background-color:#000; color:#000;\">ShishNet</span>",
"<span style=\"background-color:#000; color:#000;\">ShishNet</span>" $this->filter("[spoiler]ShishNet[/spoiler]")
); );
$this->assertEquals( $this->assertEquals(
$this->strip("[spoiler]ShishNet[/spoiler]"), "FuvfuArg",
"FuvfuArg" $this->strip("[spoiler]ShishNet[/spoiler]")
); );
#$this->assertEquals( #$this->assertEquals(
# $this->filter("[spoiler]ShishNet"), # $this->filter("[spoiler]ShishNet"),
@ -67,32 +67,32 @@ class BBCodeTest extends ShimmiePHPUnitTestCase
public function testURL() public function testURL()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[url]https://shishnet.org[/url]"), "<a href=\"https://shishnet.org\">https://shishnet.org</a>",
"<a href=\"https://shishnet.org\">https://shishnet.org</a>" $this->filter("[url]https://shishnet.org[/url]")
); );
$this->assertEquals( $this->assertEquals(
$this->filter("[url=https://shishnet.org]ShishNet[/url]"), "<a href=\"https://shishnet.org\">ShishNet</a>",
"<a href=\"https://shishnet.org\">ShishNet</a>" $this->filter("[url=https://shishnet.org]ShishNet[/url]")
); );
$this->assertEquals( $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() public function testEmailURL()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[email]spam@shishnet.org[/email]"), "<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>",
"<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>" $this->filter("[email]spam@shishnet.org[/email]")
); );
} }
public function testAnchor() public function testAnchor()
{ {
$this->assertEquals( $this->assertEquals(
$this->filter("[anchor=rules]Rules[/anchor]"), '<span class="anchor">Rules <a class="alink" href="#bb-rules" name="bb-rules" title="link to this anchor"> ¶ </a></span>',
'<span class="anchor">Rules <a class="alink" href="#bb-rules" name="bb-rules" title="link to this anchor"> ¶ </a></span>' $this->filter("[anchor=rules]Rules[/anchor]")
); );
} }

View File

@ -169,8 +169,9 @@ class MessageColumn extends Column
protected function scan_entities(string $line) protected function scan_entities(string $line)
{ {
return preg_replace_callback("/Image #(\d+)/s", [$this, "link_image"], $line); $line = preg_replace_callback("/Image #(\d+)/s", [$this, "link_image"], $line);
return preg_replace_callback("/>>(\d+)/s", [$this, "link_image"], $line); $line = preg_replace_callback("/>>(\d+)/s", [$this, "link_image"], $line);
return $line;
} }
protected function link_image($id) protected function link_image($id)

View File

@ -4,6 +4,6 @@ class MimeSystemTest extends ShimmiePHPUnitTestCase
public function testJPEG() public function testJPEG()
{ {
$result = MimeType::get_for_file("tests/bedroom_workshop.jpg"); $result = MimeType::get_for_file("tests/bedroom_workshop.jpg");
$this->assertEquals($result, MimeType::JPEG); $this->assertEquals(MimeType::JPEG, $result);
} }
} }