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

66 lines
2.2 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
class NumericScoreTest extends ShimmiePHPUnitTestCase
{
2024-01-15 14:31:51 +00:00
public function testNumericScore(): void
{
global $user;
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->get_page("post/view/$image_id");
$this->assert_text("Current Score: 0");
send_event(new NumericScoreSetEvent($image_id, $user, -1));
$this->get_page("post/view/$image_id");
$this->assert_text("Current Score: -1");
send_event(new NumericScoreSetEvent($image_id, $user, 1));
$this->get_page("post/view/$image_id");
$this->assert_text("Current Score: 1");
# FIXME: test that up and down are hidden if already voted up or down
# test search by score
$page = $this->get_page("post/list/score=1/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$page = $this->get_page("post/list/score>0/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$page = $this->get_page("post/list/score>-5/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$page = $this->get_page("post/list/-score>5/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
$page = $this->get_page("post/list/-score<-5/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
# test search by vote
$page = $this->get_page("post/list/upvoted_by=test/1");
$this->assertEquals(PageMode::REDIRECT, $page->mode);
# and downvote
$page = $this->get_page("post/list/downvoted_by=test/1");
$this->assertEquals(404, $page->code);
# test errors
$this->assertException(UserNotFound::class, function () {
2024-02-11 15:47:40 +00:00
$this->get_page("post/list/upvoted_by=asdfasdf/1");
});
$this->assertException(UserNotFound::class, function () {
2024-02-11 15:47:40 +00:00
$this->get_page("post/list/downvoted_by=asdfasdf/1");
});
$page = $this->get_page("post/list/upvoted_by_id=0/1");
$this->assertEquals(404, $page->code);
$page = $this->get_page("post/list/downvoted_by_id=0/1");
$this->assertEquals(404, $page->code);
}
2009-07-20 05:51:36 +00:00
}