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

101 lines
3.4 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
2023-12-31 01:20:36 +00:00
class ViewPostTest extends ShimmiePHPUnitTestCase
{
2019-11-14 18:24:09 +00:00
public function setUp(): void
{
parent::setUp();
// FIXME: upload images
}
2024-01-15 14:31:51 +00:00
public function testViewPage(): void
{
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
$this->get_page("post/view/$image_id_1");
2020-10-26 15:13:47 +00:00
$this->assert_title("Post $image_id_1: test");
}
2024-01-15 14:31:51 +00:00
public function testViewInfo(): void
2020-07-31 14:50:57 +00:00
{
global $config;
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
$config->set_string(ImageConfig::INFO, '$size // $filesize // $ext');
$this->get_page("post/view/$image_id_1");
$this->assert_text("640x480 // 19KB // jpg");
2020-07-31 14:50:57 +00:00
}
2024-01-15 14:31:51 +00:00
public function testPrevNext(): void
{
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2");
$image_id_3 = $this->post_image("tests/favicon.png", "test");
2009-09-19 19:19:09 +00:00
// Front image: no next, has prev
$page = $this->get_page("post/next/$image_id_1");
$this->assertEquals(404, $page->code);
$page = $this->get_page("post/prev/$image_id_1");
2020-02-01 22:26:08 +00:00
$this->assertEquals("/test/post/view/$image_id_2", $page->redirect);
2009-09-19 19:19:09 +00:00
// When searching, we skip the middle
2023-11-11 21:49:12 +00:00
$page = $this->get_page("post/prev/$image_id_1", ["search" => "test"]);
2020-10-27 22:19:26 +00:00
$this->assertEquals("/test/post/view/$image_id_3?#search=test", $page->redirect);
2020-10-27 21:19:19 +00:00
2023-11-11 21:49:12 +00:00
$page = $this->get_page("post/next/$image_id_3", ["search" => "test"]);
2020-10-27 22:19:26 +00:00
$this->assertEquals("/test/post/view/$image_id_1?#search=test", $page->redirect);
// Middle image: has next and prev
$page = $this->get_page("post/next/$image_id_2");
2020-02-01 22:26:08 +00:00
$this->assertEquals("/test/post/view/$image_id_1", $page->redirect);
$page = $this->get_page("post/prev/$image_id_2");
2020-02-01 22:26:08 +00:00
$this->assertEquals("/test/post/view/$image_id_3", $page->redirect);
2009-09-19 19:19:09 +00:00
// Last image has next, no prev
$page = $this->get_page("post/next/$image_id_3");
2020-02-01 22:26:08 +00:00
$this->assertEquals("/test/post/view/$image_id_2", $page->redirect);
$page = $this->get_page("post/prev/$image_id_3");
$this->assertEquals(404, $page->code);
}
2024-01-15 14:31:51 +00:00
public function testPrevNextDisabledWhenOrdered(): void
{
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
$this->get_page("post/view/$image_id");
$this->assert_text("Prev");
$this->get_page("post/view/$image_id", ["search" => "test"]);
$this->assert_text("Prev");
$this->get_page("post/view/$image_id", ["search" => "cake_order:_the_cakening"]);
$this->assert_text("Prev");
$this->get_page("post/view/$image_id", ["search" => "order:score"]);
$this->assert_no_text("Prev");
}
2024-01-15 14:31:51 +00:00
public function testView404(): void
{
$this->log_in_as_user();
2020-03-13 09:23:54 +00:00
$image_id_1 = $this->post_image("tests/favicon.png", "test");
$idp1 = $image_id_1 + 1;
$this->assertException(ImageNotFound::class, function () use ($idp1) {
$this->get_page("post/view/$idp1");
});
$this->assertException(ImageNotFound::class, function () {
$this->get_page('post/view/-1');
});
}
}