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/ban_words/test.php

34 lines
1 KiB
PHP
Raw Normal View History

2009-07-16 19:21:49 +00:00
<?php
2015-08-09 11:14:28 +00:00
class BanWordsTest extends ShimmiePHPUnitTestCase {
2015-09-26 10:17:13 +00:00
public function check_blocked($image_id, $words) {
2015-08-09 11:14:28 +00:00
global $user;
try {
send_event(new CommentPostingEvent($image_id, $user, $words));
$this->fail("Exception not thrown");
}
catch(CommentPostingException $e) {
$this->assertEquals($e->getMessage(), "Comment contains banned terms");
}
}
2015-09-26 10:17:13 +00:00
public function testWordBan() {
2015-08-09 11:14:28 +00:00
global $config;
$config->set_string("banned_words", "viagra\nporn\n\n/http:.*\.cn\//");
2009-07-16 19:21:49 +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 computer screenshot");
2009-07-16 19:21:49 +00:00
2015-08-09 11:14:28 +00:00
$this->check_blocked($image_id, "kittens and viagra");
$this->check_blocked($image_id, "kittens and ViagrA");
$this->check_blocked($image_id, "kittens and viagra!");
$this->check_blocked($image_id, "some link to http://something.cn/");
2009-07-16 19:21:49 +00:00
$this->get_page('comment/list');
2009-08-19 00:28:48 +00:00
$this->assert_title('Comments');
$this->assert_no_text('viagra');
$this->assert_no_text('ViagrA');
$this->assert_no_text('http://something.cn/');
2009-07-16 19:21:49 +00:00
}
}