This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/comment/test.php

111 lines
2.9 KiB
PHP
Raw Normal View History

<?php
class CommentListTest extends ShimmiePHPUnitTestCase {
2015-09-26 10:17:13 +00:00
public function setUp() {
global $config;
parent::setUp();
$config->set_int("comment_limit", 100);
2009-10-26 10:50:48 +00:00
$this->log_out();
}
2015-09-26 10:17:13 +00:00
public function tearDown() {
global $config;
$config->set_int("comment_limit", 10);
parent::tearDown();
2009-10-26 10:50:48 +00:00
}
2015-09-26 10:17:13 +00:00
public function testCommentsPage() {
global $user;
2009-07-15 16:09:50 +00:00
$this->log_in_as_user();
2015-08-09 11:14:28 +00:00
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
2009-07-15 16:09:50 +00:00
# a good comment
send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
2009-07-15 16:09:50 +00:00
$this->get_page("post/view/$image_id");
2009-08-19 00:28:48 +00:00
$this->assert_text("ASDFASDF");
2009-07-15 16:09:50 +00:00
# dupe
try {
send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
}
catch(CommentPostingException $e) {
$this->assertContains("try and be more original", $e->getMessage());
}
2009-07-15 16:09:50 +00:00
# empty comment
try {
send_event(new CommentPostingEvent($image_id, $user, ""));
}
catch(CommentPostingException $e) {
$this->assertContains("Comments need text", $e->getMessage());
}
2009-07-15 16:09:50 +00:00
# whitespace is still empty...
try {
send_event(new CommentPostingEvent($image_id, $user, " \t\r\n"));
}
catch(CommentPostingException $e) {
$this->assertContains("Comments need text", $e->getMessage());
}
2009-07-15 16:09:50 +00:00
2009-08-03 09:18:40 +00:00
# repetitive (aka. gzip gives >= 10x improvement)
try {
send_event(new CommentPostingEvent($image_id, $user, str_repeat("U", 5000)));
}
catch(CommentPostingException $e) {
$this->assertContains("Comment too repetitive", $e->getMessage());
}
2009-07-15 16:09:50 +00:00
2010-03-14 20:51:15 +00:00
# test UTF8
send_event(new CommentPostingEvent($image_id, $user, "Test Comment むちむち"));
2010-03-14 20:51:15 +00:00
$this->get_page("post/view/$image_id");
$this->assert_text("むちむち");
2009-08-03 09:18:40 +00:00
# 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");
2009-08-03 09:18:40 +00:00
2009-07-15 16:09:50 +00:00
$this->log_out();
$this->get_page('comment/list');
2009-08-19 00:28:48 +00:00
$this->assert_title('Comments');
$this->assert_text('ASDFASDF');
2009-07-15 16:09:50 +00:00
$this->get_page('comment/list/2');
2009-08-19 00:28:48 +00:00
$this->assert_title('Comments');
2009-07-15 16:09:50 +00:00
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
2009-10-23 13:26:40 +00:00
$this->get_page('comment/list');
$this->assert_title('Comments');
$this->assert_no_text('ASDFASDF');
2009-08-12 14:45:13 +00:00
}
2015-09-26 10:17:13 +00:00
public function testSingleDel() {
$this->markTestIncomplete();
2009-08-12 14:45:13 +00:00
$this->log_in_as_admin();
2015-08-09 11:14:28 +00:00
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
2009-08-12 14:45:13 +00:00
# make a comment
$this->get_page("post/view/$image_id");
2009-08-19 00:28:48 +00:00
$this->set_field('comment', "Test Comment ASDFASDF");
2009-08-12 14:45:13 +00:00
$this->click("Post Comment");
2009-08-19 00:28:48 +00:00
$this->assert_title("Image $image_id: pbx");
$this->assert_text("ASDFASDF");
2009-07-20 05:51:36 +00:00
2009-08-12 14:45:13 +00:00
# delete it
$this->click("Del");
2009-08-19 00:28:48 +00:00
$this->assert_title("Image $image_id: pbx");
$this->assert_no_text("ASDFASDF");
2009-08-12 14:45:13 +00:00
# tidy up
$this->delete_image($image_id);
$this->log_out();
}
}