2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
class RandomImageTest extends ShimmiePHPUnitTestCase
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testRandom(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
|
|
|
$this->log_out();
|
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
$page = $this->get_page("random_image/view");
|
2020-10-26 15:17:15 +00:00
|
|
|
$this->assertEquals("Post $image_id: test", $page->title);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
$page = $this->get_page("random_image/view/test");
|
2020-10-26 15:17:15 +00:00
|
|
|
$this->assertEquals("Post $image_id: test", $page->title);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
$page = $this->get_page("random_image/download");
|
|
|
|
$this->assertNotNull($page->data);
|
2019-05-28 16:59:38 +00:00
|
|
|
# FIXME: assert($raw == file(blah.jpg))
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testPostListBlock(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
global $config;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->log_in_as_admin();
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# enabled, no image = no text
|
2020-01-28 21:19:59 +00:00
|
|
|
$config->set_bool("show_random_block", true);
|
|
|
|
$page = $this->get_page("post/list");
|
2024-08-31 20:22:54 +00:00
|
|
|
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# enabled, image = text
|
2020-01-28 21:19:59 +00:00
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
|
|
|
$page = $this->get_page("post/list");
|
2020-10-26 15:17:15 +00:00
|
|
|
$this->assertNotNull($page->find_block("Random Post"));
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# disabled, image = no text
|
2020-01-28 21:19:59 +00:00
|
|
|
$config->set_bool("show_random_block", false);
|
|
|
|
$page = $this->get_page("post/list");
|
2024-08-31 20:22:54 +00:00
|
|
|
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# disabled, no image = no image
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->delete_image($image_id);
|
|
|
|
$page = $this->get_page("post/list");
|
2024-08-31 20:22:54 +00:00
|
|
|
$this->assertException(\Exception::class, function () use ($page) {$page->find_block("Random Post");});
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-07-20 05:51:36 +00:00
|
|
|
}
|