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

231 lines
7.8 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
class IndexTest extends ShimmiePHPUnitTestCase
{
public function testIndexPage()
{
$this->get_page('post/list');
$this->assert_title("Welcome to Shimmie");
$this->assert_no_text("Prev | Index | Next");
$this->log_in_as_user();
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
2020-01-29 20:22:50 +00:00
$this->post_image("tests/bedroom_workshop.jpg", "thing computer computing bedroom workshop");
$this->log_out();
$this->get_page('post/list');
$this->assert_title("Shimmie");
// FIXME
//$this->assert_text("Prev | Index | Next");
$this->get_page('post/list/-1');
$this->assert_title("Shimmie");
$this->get_page('post/list/0');
$this->assert_title("Shimmie");
$this->get_page('post/list/1');
$this->assert_title("Shimmie");
$this->get_page('post/list/99999');
$this->assert_response(404);
2020-01-29 20:22:50 +00:00
# No results: 404
$this->get_page('post/list/maumaumau/1');
$this->assert_response(404);
# One result: 302
$this->get_page("post/list/pbx/1");
$this->assert_response(302);
# Multiple results: 200
$this->get_page('post/list/computer/1');
$this->assert_response(200);
}
2020-01-30 10:26:28 +00:00
public function testWeirdTags()
{
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "question? colon:thing exclamation!");
2020-01-30 10:55:35 +00:00
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "question. colon_thing exclamation%");
2020-01-30 10:26:28 +00:00
$this->assert_search_results(["question?"], [$image_id_1]);
2020-01-30 10:55:35 +00:00
$this->assert_search_results(["question."], [$image_id_2]);
2020-01-30 10:26:28 +00:00
$this->assert_search_results(["colon:thing"], [$image_id_1]);
2020-01-30 10:55:35 +00:00
$this->assert_search_results(["colon_thing"], [$image_id_2]);
2020-01-30 10:26:28 +00:00
$this->assert_search_results(["exclamation!"], [$image_id_1]);
2020-01-30 10:55:35 +00:00
$this->assert_search_results(["exclamation%"], [$image_id_2]);
2020-01-30 10:26:28 +00:00
}
2020-01-29 20:22:50 +00:00
// base case
public function testUpload(): array
2020-01-29 20:22:50 +00:00
{
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "thing computer screenshot pbx phone");
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "thing computer computing bedroom workshop");
$this->log_out();
# make sure both uploads were ok
$this->assertTrue($image_id_1 > 0);
$this->assertTrue($image_id_2 > 0);
return [$image_id_1, $image_id_2];
}
/* * * * * * * * * * *
* Tag Search *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testTagSearchNoResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["maumaumau"], []);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testTagSearchOneResult($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["pbx"], [$image_ids[0]]);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testTagSearchManyResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["computer"], [$image_ids[1], $image_ids[0]]);
}
/* * * * * * * * * * *
* Multi-Tag Search *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMultiTagSearchNoResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
# multiple tags, one of which doesn't exist
# (test the "one tag doesn't exist = no hits" path)
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["computer", "asdfasdfwaffle"], []);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMultiTagSearchOneResult($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["computer", "screenshot"], [$image_ids[0]]);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMultiTagSearchManyResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["computer", "thing"], [$image_ids[1], $image_ids[0]]);
}
/* * * * * * * * * * *
* Meta Search *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMetaSearchNoResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["hash=1234567890"], []);
$this->assert_search_results(["ratio=42:12345"], []);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMetaSearchOneResult($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["hash=feb01bab5698a11dd87416724c7a89e3"], [$image_ids[0]]);
$this->assert_search_results(["md5=feb01bab5698a11dd87416724c7a89e3"], [$image_ids[0]]);
$this->assert_search_results(["id={$image_ids[1]}"], [$image_ids[1]]);
$this->assert_search_results(["filename=screenshot"], [$image_ids[0]]);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMetaSearchManyResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["size=640x480"], [$image_ids[1], $image_ids[0]]);
$this->assert_search_results(["tags=5"], [$image_ids[1], $image_ids[0]]);
$this->assert_search_results(["ext=jpg"], [$image_ids[1], $image_ids[0]]);
}
/* * * * * * * * * * *
* Wildcards *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testWildSearchNoResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["asdfasdf*"], []);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testWildSearchOneResult($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
// Only the first image matches both the wildcard and the tag.
// This checks for https://github.com/shish/shimmie2/issues/547
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["comp*", "screenshot"], [$image_ids[0]]);
}
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testWildSearchManyResults($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
// two images match comp* - one matches it once,
// one matches it twice
2020-01-29 20:22:50 +00:00
$this->assert_search_results(["comp*"], [$image_ids[1], $image_ids[0]]);
}
/* * * * * * * * * * *
* Mixed *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testMixedSearchTagMeta($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
// multiple tags, many results
$this->assert_search_results(["computer", "size=640x480"], [$image_ids[1], $image_ids[0]]);
}
// tag + negative
// wildcards + ???
/* * * * * * * * * * *
2020-01-29 20:22:50 +00:00
* Negative *
* * * * * * * * * * */
2020-01-29 20:22:50 +00:00
/** @depends testUpload */
public function testNegative($image_ids)
{
2020-10-24 17:55:07 +00:00
$image_ids = $this->testUpload();
2020-01-29 20:22:50 +00:00
// negative tag, should have one result
$this->assert_search_results(["computer", "-pbx"], [$image_ids[1]]);
2020-01-29 20:22:50 +00:00
// negative tag alone, should work
$this->assert_search_results(["-pbx"], [$image_ids[1]]);
// negative that doesn't exist
$this->assert_search_results(["-not_a_tag"], [$image_ids[1], $image_ids[0]]);
// multiple negative tags that don't exist
$this->assert_search_results(["-not_a_tag", "-also_not_a_tag"], [$image_ids[1], $image_ids[0]]);
}
2020-03-26 21:28:36 +00:00
// This isn't really an index thing, we just want to test this from
// SOMEWHERE because the default theme doesn't use them.
public function test_nav()
{
send_event(new UserLoginEvent(User::by_name(self::$user_name)));
send_event(new PageNavBuildingEvent());
2020-03-28 14:39:03 +00:00
// just a few common parents
2020-04-25 20:36:28 +00:00
foreach (["help", "posts", "system", "user"] as $parent) {
2020-03-28 14:39:03 +00:00
send_event(new PageSubNavBuildingEvent($parent));
}
2020-03-26 21:28:36 +00:00
$this->assertTrue(true);
}
}