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/random_image/test.php
Shish 399a56ac79 [dev] bump phpstan strictness
no more null surprises
2024-08-31 21:25:20 +01:00

52 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
class RandomImageTest extends ShimmiePHPUnitTestCase
{
public function testRandom(): void
{
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
$this->log_out();
$page = $this->get_page("random_image/view");
$this->assertEquals("Post $image_id: test", $page->title);
$page = $this->get_page("random_image/view/test");
$this->assertEquals("Post $image_id: test", $page->title);
$page = $this->get_page("random_image/download");
$this->assertNotNull($page->data);
# FIXME: assert($raw == file(blah.jpg))
}
public function testPostListBlock(): void
{
global $config;
$this->log_in_as_admin();
# enabled, no image = no text
$config->set_bool("show_random_block", true);
$page = $this->get_page("post/list");
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
# enabled, image = text
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
$page = $this->get_page("post/list");
$this->assertNotNull($page->find_block("Random Post"));
# disabled, image = no text
$config->set_bool("show_random_block", false);
$page = $this->get_page("post/list");
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
# disabled, no image = no image
$this->delete_image($image_id);
$page = $this->get_page("post/list");
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
}
}