2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-05-28 16:59:38 +00:00
|
|
|
class PoolsTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Clean up any leftovers to create a fresh test env
|
|
|
|
$this->log_in_as_admin();
|
|
|
|
global $database;
|
|
|
|
foreach ($database->get_col("SELECT id FROM pools") as $pool_id) {
|
|
|
|
send_event(new PoolDeletionEvent((int)$pool_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 00:49:21 +00:00
|
|
|
public function testAnon()
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
$this->log_out();
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page('pool/list');
|
|
|
|
$this->assert_title("Pools");
|
2009-11-15 06:23:42 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page('pool/new');
|
|
|
|
$this->assert_title("Error");
|
|
|
|
}
|
2020-03-26 18:52:31 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
public function testCreate(): array
|
2020-03-26 18:52:31 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
|
|
|
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "pbx");
|
|
|
|
$this->assertNotNull($image_id_1);
|
|
|
|
$this->assertNotNull($image_id_2);
|
|
|
|
|
|
|
|
$this->get_page("pool/new");
|
|
|
|
|
2020-03-27 14:41:24 +00:00
|
|
|
$page = $this->post_page("pool/create", [
|
|
|
|
"title" => "foo",
|
|
|
|
"public" => "Y",
|
|
|
|
"description" => "My pool description",
|
|
|
|
]);
|
|
|
|
$pool_id = (int)(explode("/", $page->redirect)[4]);
|
2020-03-26 18:52:31 +00:00
|
|
|
send_event(new PoolAddPostsEvent($pool_id, [$image_id_1, $image_id_2]));
|
|
|
|
|
|
|
|
return [$pool_id, [$image_id_1, $image_id_2]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
|
|
|
public function testOnViewImage($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
global $config;
|
|
|
|
$config->set_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE, true);
|
|
|
|
$config->set_bool(PoolsConfig::INFO_ON_VIEW_IMAGE, true);
|
2020-03-27 00:15:15 +00:00
|
|
|
$config->set_bool(PoolsConfig::SHOW_NAV_LINKS, true);
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
$this->get_page("post/view/{$image_ids[0]}");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
|
|
|
public function testSearch($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
$this->get_page("post/list/pool=$pool_id/1");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
|
|
|
|
$this->get_page("post/list/pool_by_name=demo_pool/1");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
|
|
|
public function testList($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
$this->get_page("pool/list");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
|
|
|
public function testView($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
$this->get_page("pool/view/$pool_id");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
2020-03-26 19:03:34 +00:00
|
|
|
public function testHistory($args)
|
2020-03-26 18:52:31 +00:00
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-26 18:52:31 +00:00
|
|
|
|
|
|
|
$this->get_page("pool/updated/$pool_id");
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
2020-03-27 14:41:24 +00:00
|
|
|
|
|
|
|
/** @depends testCreate */
|
|
|
|
public function testImport($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-27 14:41:24 +00:00
|
|
|
|
|
|
|
$this->post_page("pool/import", [
|
|
|
|
"pool_id" => $pool_id,
|
|
|
|
"pool_tag" => "test"
|
|
|
|
]);
|
|
|
|
$this->assert_text("Pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
2021-03-14 23:43:50 +00:00
|
|
|
public function testRemovePosts($args): array
|
2020-03-27 14:41:24 +00:00
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-27 14:41:24 +00:00
|
|
|
|
|
|
|
$page = $this->post_page("pool/remove_posts", [
|
|
|
|
"pool_id" => $pool_id,
|
|
|
|
"check" => [(string)($image_ids[0]), (string)($image_ids[1])]
|
|
|
|
]);
|
2022-10-28 00:45:35 +00:00
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
2020-03-27 14:41:24 +00:00
|
|
|
|
2020-10-24 17:55:07 +00:00
|
|
|
return [$pool_id, $image_ids];
|
2020-03-27 14:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testRemovePosts */
|
|
|
|
public function testAddPosts($args)
|
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testRemovePosts(null);
|
2020-03-27 14:41:24 +00:00
|
|
|
|
|
|
|
$page = $this->post_page("pool/add_posts", [
|
|
|
|
"pool_id" => $pool_id,
|
|
|
|
"check" => [(string)($image_ids[0]), (string)($image_ids[1])]
|
|
|
|
]);
|
2022-10-28 00:45:35 +00:00
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
2020-03-27 14:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @depends testCreate */
|
2021-03-14 23:43:50 +00:00
|
|
|
public function testEditDescription($args): array
|
2020-03-27 14:41:24 +00:00
|
|
|
{
|
2020-10-24 17:55:07 +00:00
|
|
|
[$pool_id, $image_ids] = $this->testCreate();
|
2020-03-27 14:41:24 +00:00
|
|
|
|
|
|
|
$page = $this->post_page("pool/edit_description", [
|
|
|
|
"pool_id" => $pool_id,
|
|
|
|
"description" => "Updated description"
|
|
|
|
]);
|
2022-10-28 00:45:35 +00:00
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
2020-03-27 14:41:24 +00:00
|
|
|
|
2020-10-24 17:55:07 +00:00
|
|
|
return [$pool_id, $image_ids];
|
2020-03-27 14:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNuke()
|
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
|
|
|
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "pbx");
|
|
|
|
$this->assertNotNull($image_id_1);
|
|
|
|
$this->assertNotNull($image_id_2);
|
|
|
|
|
|
|
|
$this->get_page("pool/new");
|
|
|
|
|
|
|
|
$page = $this->post_page("pool/create", [
|
|
|
|
"title" => "foo2",
|
|
|
|
"public" => "Y",
|
|
|
|
"description" => "My pool description",
|
|
|
|
]);
|
|
|
|
$pool_id = (int)(explode("/", $page->redirect)[4]);
|
|
|
|
send_event(new PoolAddPostsEvent($pool_id, [$image_id_1, $image_id_2]));
|
|
|
|
|
|
|
|
$page = $this->post_page("pool/nuke", [
|
|
|
|
"pool_id" => "$pool_id",
|
|
|
|
]);
|
2022-10-28 00:45:35 +00:00
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
2020-03-27 14:41:24 +00:00
|
|
|
}
|
2009-11-15 05:34:30 +00:00
|
|
|
}
|