2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-01-28 21:19:59 +00:00
|
|
|
class RatingsTest extends ShimmiePHPUnitTestCase
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-29 01:47:43 +00:00
|
|
|
public function testRatingSafe()
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
2020-01-29 01:47:43 +00:00
|
|
|
$image = Image::by_id($image_id);
|
|
|
|
send_event(new RatingSetEvent($image, "s"));
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# search for it in various ways
|
2020-01-29 20:22:50 +00:00
|
|
|
$this->assert_search_results(["rating=Safe"], [$image_id]);
|
|
|
|
$this->assert_search_results(["rating=s"], [$image_id]);
|
|
|
|
$this->assert_search_results(["rating=sqe"], [$image_id]);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# test that search by tag still works
|
2020-01-29 20:22:50 +00:00
|
|
|
$this->assert_search_results(["pbx"], [$image_id]);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# searching for a different rating should return nothing
|
2020-01-29 20:22:50 +00:00
|
|
|
$this->assert_search_results(["rating=q"], []);
|
2020-01-29 01:47:43 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-29 01:47:43 +00:00
|
|
|
public function testRatingExplicit()
|
|
|
|
{
|
2020-01-29 11:30:52 +00:00
|
|
|
global $config;
|
|
|
|
$config->set_array("ext_rating_anonymous_privs", ["s", "q"]);
|
2020-01-29 01:47:43 +00:00
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
|
|
|
$image = Image::by_id($image_id);
|
|
|
|
send_event(new RatingSetEvent($image, "e"));
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
# the explicit image shouldn't show up in anon's searches
|
2020-01-29 01:47:43 +00:00
|
|
|
$this->log_out();
|
2020-01-29 20:22:50 +00:00
|
|
|
$this->assert_search_results(["pbx"], []);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-08-13 20:42:48 +00:00
|
|
|
}
|