[autocomplete] more tests
This commit is contained in:
@ -56,7 +56,6 @@ class AutoComplete extends Extension
|
|||||||
if ($limit !== 0) {
|
if ($limit !== 0) {
|
||||||
$limitSQL = "LIMIT :limit";
|
$limitSQL = "LIMIT :limit";
|
||||||
$SQLarr['limit'] = $limit;
|
$SQLarr['limit'] = $limit;
|
||||||
$cache_key .= "-" . $limit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache_get_or_set($cache_key, fn () => $database->get_pairs(
|
return cache_get_or_set($cache_key, fn () => $database->get_pairs(
|
||||||
|
@ -8,10 +8,39 @@ class AutoCompleteTest extends ShimmiePHPUnitTestCase
|
|||||||
{
|
{
|
||||||
public function testAuth(): void
|
public function testAuth(): void
|
||||||
{
|
{
|
||||||
|
$this->log_in_as_user();
|
||||||
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "some_tag");
|
||||||
|
|
||||||
send_event(new UserLoginEvent(User::by_name(self::$anon_name)));
|
send_event(new UserLoginEvent(User::by_name(self::$anon_name)));
|
||||||
$page = $this->get_page('api/internal/autocomplete', ["s" => "not-a-tag"]);
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "not-a-tag"]);
|
||||||
$this->assertEquals(200, $page->code);
|
$this->assertEquals(200, $page->code);
|
||||||
$this->assertEquals(PageMode::DATA, $page->mode);
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
||||||
$this->assertEquals("[]", $page->data);
|
$this->assertEquals("[]", $page->data);
|
||||||
|
|
||||||
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "so"]);
|
||||||
|
$this->assertEquals(200, $page->code);
|
||||||
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
||||||
|
$this->assertEquals('{"some_tag":1}', $page->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCategories(): void
|
||||||
|
{
|
||||||
|
$this->log_in_as_user();
|
||||||
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "artist:bob");
|
||||||
|
|
||||||
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "bob"]);
|
||||||
|
$this->assertEquals(200, $page->code);
|
||||||
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
||||||
|
$this->assertEquals('{"artist:bob":1}', $page->data);
|
||||||
|
|
||||||
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "art"]);
|
||||||
|
$this->assertEquals(200, $page->code);
|
||||||
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
||||||
|
$this->assertEquals('{"artist:bob":1}', $page->data);
|
||||||
|
|
||||||
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "artist:"]);
|
||||||
|
$this->assertEquals(200, $page->code);
|
||||||
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
||||||
|
$this->assertEquals('{"artist:bob":1}', $page->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user