nits
This commit is contained in:
parent
9b878d98d6
commit
8ff70134ae
10 changed files with 62 additions and 69 deletions
|
@ -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'];
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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'] = "<cli command>";
|
||||
$_SERVER['HTTP_HOST'] = "cli-command";
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ class PolyfillsTest extends TestCase
|
|||
public function test_html_escape()
|
||||
{
|
||||
$this->assertEquals(
|
||||
html_escape("Foo & <waffles>"),
|
||||
"Foo & <waffles>"
|
||||
"Foo & <main>",
|
||||
html_escape("Foo & <main>")
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
html_unescape("Foo & <waffles>"),
|
||||
"Foo & <waffles>"
|
||||
"Foo & <main>",
|
||||
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()
|
||||
|
|
|
@ -43,13 +43,13 @@ class UrlsTest extends TestCase
|
|||
{
|
||||
// relative to shimmie install
|
||||
$this->assertEquals(
|
||||
"http://<cli command>/test/foo",
|
||||
"http://cli-command/test/foo",
|
||||
make_http("foo")
|
||||
);
|
||||
|
||||
// relative to web server
|
||||
$this->assertEquals(
|
||||
"http://<cli command>/foo",
|
||||
"http://cli-command/foo",
|
||||
make_http("/foo")
|
||||
);
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,60 +4,60 @@ class BBCodeTest extends ShimmiePHPUnitTestCase
|
|||
public function testBasics()
|
||||
{
|
||||
$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()
|
||||
{
|
||||
$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->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()
|
||||
{
|
||||
$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]"),
|
||||
"<pre>[b]bold[/b]</pre>"
|
||||
"<pre>[b]bold[/b]</pre>",
|
||||
$this->filter("[code][b]bold[/b][/code]")
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedList()
|
||||
{
|
||||
$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->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()
|
||||
{
|
||||
$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->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]"),
|
||||
"<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->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->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]"),
|
||||
"<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()
|
||||
{
|
||||
$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]")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue