2020-01-28 21:19:59 +00:00
|
|
|
<?php
|
2021-12-14 18:32:47 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-01-29 00:49:21 +00:00
|
|
|
class AutoCompleteTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testAuth(): void
|
2020-01-29 00:49:21 +00:00
|
|
|
{
|
2024-01-21 10:41:25 +00:00
|
|
|
$this->log_in_as_user();
|
2024-02-12 13:40:23 +00:00
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "link");
|
|
|
|
send_event(new AddAliasEvent("prince_zelda", "link"));
|
2024-01-21 10:41:25 +00:00
|
|
|
|
2020-01-29 20:22:50 +00:00
|
|
|
send_event(new UserLoginEvent(User::by_name(self::$anon_name)));
|
2023-11-11 21:49:12 +00:00
|
|
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "not-a-tag"]);
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->assertEquals(200, $page->code);
|
|
|
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
|
|
|
$this->assertEquals("[]", $page->data);
|
2024-01-21 10:41:25 +00:00
|
|
|
|
2024-02-12 13:40:23 +00:00
|
|
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "li"]);
|
2024-01-21 10:41:25 +00:00
|
|
|
$this->assertEquals(200, $page->code);
|
|
|
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
2024-02-12 13:40:23 +00:00
|
|
|
$this->assertEquals('{"link":{"newtag":null,"count":1}}', $page->data);
|
|
|
|
|
|
|
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "pr"]);
|
|
|
|
$this->assertEquals(200, $page->code);
|
|
|
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
|
|
|
$this->assertEquals('{"prince_zelda":{"newtag":"link","count":1}}', $page->data);
|
2024-01-21 10:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2024-02-12 13:40:23 +00:00
|
|
|
$this->assertEquals('{"artist:bob":{"newtag":null,"count":1}}', $page->data);
|
2024-01-21 10:41:25 +00:00
|
|
|
|
|
|
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "art"]);
|
|
|
|
$this->assertEquals(200, $page->code);
|
|
|
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
2024-02-12 13:40:23 +00:00
|
|
|
$this->assertEquals('{"artist:bob":{"newtag":null,"count":1}}', $page->data);
|
2024-01-21 10:41:25 +00:00
|
|
|
|
|
|
|
$page = $this->get_page('api/internal/autocomplete', ["s" => "artist:"]);
|
|
|
|
$this->assertEquals(200, $page->code);
|
|
|
|
$this->assertEquals(PageMode::DATA, $page->mode);
|
2024-02-12 13:40:23 +00:00
|
|
|
$this->assertEquals('{"artist:bob":{"newtag":null,"count":1}}', $page->data);
|
2020-01-28 21:19:59 +00:00
|
|
|
}
|
|
|
|
}
|