2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-05-28 16:59:38 +00:00
|
|
|
class CommentListTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2019-11-14 18:24:09 +00:00
|
|
|
public function setUp(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
parent::setUp();
|
|
|
|
$config->set_int("comment_limit", 100);
|
|
|
|
$this->log_out();
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:24:09 +00:00
|
|
|
public function tearDown(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$config->set_int("comment_limit", 10);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCommentsPage()
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
|
|
|
|
|
|
|
# a good comment
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
|
|
|
|
$this->get_page("post/view/$image_id");
|
|
|
|
$this->assert_text("ASDFASDF");
|
|
|
|
|
|
|
|
# dupe
|
|
|
|
try {
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
|
|
|
|
} catch (CommentPostingException $e) {
|
2019-11-21 17:16:11 +00:00
|
|
|
$this->assertStringContainsString("try and be more original", $e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# empty comment
|
|
|
|
try {
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, ""));
|
|
|
|
} catch (CommentPostingException $e) {
|
2019-11-21 17:16:11 +00:00
|
|
|
$this->assertStringContainsString("Comments need text", $e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# whitespace is still empty...
|
|
|
|
try {
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, " \t\r\n"));
|
|
|
|
} catch (CommentPostingException $e) {
|
2019-11-21 17:16:11 +00:00
|
|
|
$this->assertStringContainsString("Comments need text", $e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# repetitive (aka. gzip gives >= 10x improvement)
|
|
|
|
try {
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, str_repeat("U", 5000)));
|
|
|
|
} catch (CommentPostingException $e) {
|
2019-11-21 17:16:11 +00:00
|
|
|
$this->assertStringContainsString("Comment too repetitive", $e->getMessage());
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# test UTF8
|
|
|
|
send_event(new CommentPostingEvent($image_id, $user, "Test Comment むちむち"));
|
|
|
|
$this->get_page("post/view/$image_id");
|
|
|
|
$this->assert_text("むちむち");
|
|
|
|
|
|
|
|
# test that search by comment metadata works
|
|
|
|
// $this->get_page("post/list/commented_by=test/1");
|
|
|
|
// $this->assert_title("Image $image_id: pbx");
|
|
|
|
// $this->get_page("post/list/comments=2/1");
|
|
|
|
// $this->assert_title("Image $image_id: pbx");
|
|
|
|
|
|
|
|
$this->log_out();
|
|
|
|
|
|
|
|
$this->get_page('comment/list');
|
|
|
|
$this->assert_title('Comments');
|
|
|
|
$this->assert_text('ASDFASDF');
|
|
|
|
|
|
|
|
$this->get_page('comment/list/2');
|
|
|
|
$this->assert_title('Comments');
|
|
|
|
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
$this->delete_image($image_id);
|
|
|
|
$this->log_out();
|
|
|
|
|
|
|
|
$this->get_page('comment/list');
|
|
|
|
$this->assert_title('Comments');
|
|
|
|
$this->assert_no_text('ASDFASDF');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSingleDel()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
|
|
|
|
|
|
|
# make a comment
|
|
|
|
$this->get_page("post/view/$image_id");
|
|
|
|
$this->set_field('comment', "Test Comment ASDFASDF");
|
|
|
|
$this->click("Post Comment");
|
|
|
|
$this->assert_title("Image $image_id: pbx");
|
|
|
|
$this->assert_text("ASDFASDF");
|
|
|
|
|
|
|
|
# delete it
|
|
|
|
$this->click("Del");
|
|
|
|
$this->assert_title("Image $image_id: pbx");
|
|
|
|
$this->assert_no_text("ASDFASDF");
|
|
|
|
|
|
|
|
# tidy up
|
|
|
|
$this->delete_image($image_id);
|
|
|
|
$this->log_out();
|
|
|
|
}
|
2008-10-11 07:09:42 +00:00
|
|
|
}
|