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

46 lines
1.4 KiB
PHP
Raw Normal View History

2020-01-26 13:19:35 +00:00
<?php declare(strict_types=1);
class ImageBanTest extends ShimmiePHPUnitTestCase
{
2020-01-30 09:01:19 +00:00
private $hash = "feb01bab5698a11dd87416724c7a89e3";
public function testBan()
{
$this->log_in_as_admin();
// Post image
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$page = $this->get_page("post/view/$image_id");
$this->assertEquals(200, $page->code);
2015-09-20 21:40:04 +00:00
// Ban & delete
2020-01-30 09:01:19 +00:00
send_event(new AddImageHashBanEvent($this->hash, "test hash ban"));
send_event(new ImageDeletionEvent(Image::by_id($image_id), true));
2015-09-20 21:40:04 +00:00
// Check deleted
$page = $this->get_page("post/view/$image_id");
$this->assertEquals(404, $page->code);
2012-03-10 17:40:11 +00:00
// Can't repost
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->assertTrue(false);
2020-01-29 00:49:21 +00:00
} catch (UploadException $e) {
$this->assertTrue(true);
}
2012-03-10 17:51:56 +00:00
// Remove ban
2020-01-30 09:01:19 +00:00
send_event(new RemoveImageHashBanEvent($this->hash));
2012-03-10 17:51:56 +00:00
// Can repost
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$page = $this->get_page("post/view/$image_id");
$this->assertEquals(200, $page->code);
}
2020-01-30 09:01:19 +00:00
2020-03-13 09:23:54 +00:00
public function onNotSuccessfulTest(Throwable $t): void
2020-01-30 14:50:38 +00:00
{
2020-01-30 09:01:19 +00:00
send_event(new RemoveImageHashBanEvent($this->hash));
parent::onNotSuccessfulTest($t); // TODO: Change the autogenerated stub
}
2012-03-10 17:40:11 +00:00
}