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

40 lines
1.2 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
class BanWordsTest extends ShimmiePHPUnitTestCase
{
public function check_blocked(int $image_id, string $words): void
{
global $user;
try {
send_event(new CommentPostingEvent($image_id, $user, $words));
$this->fail("Exception not thrown");
} catch (CommentPostingException $e) {
2020-10-24 12:46:49 +00:00
$this->assertEquals("Comment contains banned terms", $e->getMessage());
}
}
2015-08-09 11:14:28 +00:00
2024-01-15 14:31:51 +00:00
public function testWordBan(): void
{
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();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
2009-07-16 19:21:49 +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');
$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
}