refactor report decoration

This commit is contained in:
Spine
2023-07-17 05:10:12 +00:00
parent 3833bce2ab
commit 6be39becc1
16 changed files with 343 additions and 253 deletions

View File

@@ -5,12 +5,9 @@ namespace Gazelle\Manager;
class Report extends \Gazelle\BaseManager {
protected const ID_KEY = 'zz_r_%d';
protected User $userMan;
public function setUserManager(User $userMan): \Gazelle\Manager\Report {
$this->userMan = $userMan;
return $this;
}
public function __construct(
protected \Gazelle\Manager\User $userMan,
) {}
public function create(\Gazelle\User $user, int $id, string $type, string $reason): \Gazelle\Report {
self::$db->prepared_query("
@@ -42,11 +39,77 @@ class Report extends \Gazelle\BaseManager {
if (!$id) {
return null;
}
$report = new \Gazelle\Report($id);
if (isset($this->userMan)) {
$report->setUserManager($this->userMan);
return (new \Gazelle\Report($id))->setUserManager($this->userMan);
}
public function decorate(
array $idList,
\Gazelle\Manager\Collage $collageMan,
\Gazelle\Manager\Comment $commentMan,
\Gazelle\Manager\Forum $forumMan,
\Gazelle\Manager\ForumThread $threadMan,
\Gazelle\Manager\ForumPost $postMan,
\Gazelle\Manager\Request $requestMan,
): array {
$list = [];
foreach ($idList as $id) {
$report = $this->findById($id);
switch ($report-> subjectType()) {
case 'collage':
$context = [
'label' => 'collage',
'subject' => $collageMan->findById($report->subjectId()),
];
break;
case 'comment':
$context = [
'label' => 'comment',
'subject' => $commentMan->findById($report->subjectId()),
];
break;
case 'request':
case 'request_update':
$context = [
'label' => 'request',
'subject' => $requestMan->findById($report->subjectId()),
];
break;
case 'thread':
$thread = $threadMan->findById($report->subjectId());
$context = [
'label' => 'forum thread',
'subject' => $thread,
'link' => $thread
? ($thread->forum()->link() . ' › ' . $thread->link()
. ' created by ' . ($thread->author()->link()))
: null,
];
break;
case 'post':
$post = $postMan->findById($report->subjectId());
$link = null;
if ($post) {
$thread = $post->thread();
$link = $thread->forum()->link() . ' › ' . $thread->link() . ' › ' . $post->link()
. ' posted by ' . ($this->userMan->findById($post->userId())?->link() ?? 'System');
}
$context = [
'label' => 'forum post',
'subject' => $post,
'link' => $link,
];
break;
case 'user':
$context = [
'label' => 'user',
'subject' => $this->userMan->findById($report->subjectId()),
];
break;
}
$context['report'] = $report;
$list[] = $context;
}
return $report;
return $list;
}
public function remainingTotal(): int {

View File

@@ -128,4 +128,17 @@ class Report extends BaseObject {
return $affected;
}
/**
* You should never call this in production - it is only for unit tests
*/
public function remove(): int {
self::$db->prepared_query("
DELETE FROM reports WHERE ID = ?
", $this->id
);
$this->flush();
self::$cache->delete_value('num_other_reports');
return $this->id();
}
}

11
boris
View File

@@ -26,7 +26,8 @@ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$b = new Boris\Boris(SITE_NAME . '> ');
$b->setInspector(new Boris\ExportInspector);
$torMan = new Gazelle\Manager\Torrent;
$torMan = new Gazelle\Manager\Torrent;
$userMan = new Gazelle\Manager\User;
$preload = [
'cache' => $Cache,
'db' => Gazelle\DB::DB(),
@@ -39,15 +40,15 @@ $preload = [
'pg' => new Gazelle\DB\Pg(GZPG_DSN),
'postMan' => new Gazelle\Manager\ForumPost,
'privMan' => new Gazelle\Manager\Privilege,
'repMan' => new Gazelle\Manager\Report,
'repMan' => new Gazelle\Manager\Report($userMan),
'reqMan' => new Gazelle\Manager\Request,
'tagMan' => new Gazelle\Manager\Tag,
'tgMan' => new Gazelle\Manager\TGroup,
'threadMan' => new Gazelle\Manager\ForumThread,
'torMan' => $torMan,
'trepMan' => new Gazelle\Manager\Torrent\Report($torMan),
'trepTypeMan' => new Gazelle\Manager\Torrent\ReportType,
'userMan' => new Gazelle\Manager\User,
'trepMan' => new Gazelle\Manager\Torrent\Report($torMan),
'trepTypeMan' => new Gazelle\Manager\Torrent\ReportType,
'userMan' => $userMan,
];
printf("** preloaded objects:\n** %s\n", implode(', ', array_keys($preload)));

View File

@@ -2445,36 +2445,6 @@ parameters:
count: 1
path: ../sections/referral/index.php
-
message: "#^Variable \\$Types might not be defined\\.$#"
count: 1
path: ../sections/reports/report.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../sections/reports/reports.php
-
message: "#^Using nullsafe method call on non\\-nullable type Gazelle\\\\ForumThread\\. Use \\-\\> instead\\.$#"
count: 1
path: ../sections/reports/reports.php
-
message: "#^Variable \\$Types might not be defined\\.$#"
count: 1
path: ../sections/reports/reports.php
-
message: "#^Variable \\$ToID might not be defined\\.$#"
count: 2
path: ../sections/reports/takecompose.php
-
message: "#^Strict comparison using === between mixed and '0' will always evaluate to false\\.$#"
count: 1
path: ../sections/reports/takereport.php
-
message: "#^Variable \\$ToID in isset\\(\\) always exists and is not nullable\\.$#"
count: 1

View File

@@ -98,3 +98,7 @@ parameters:
message: '/^Variable \$Router might not be defined\.$/'
paths:
- ../sections/forums/index.php
-
message: '/^Variable \$Types might not be defined\.$/'
paths:
- ../sections/reports/*

View File

@@ -3,7 +3,7 @@
if (!$Viewer->permitted('site_moderate_forums')) {
json_error('forbidden');
}
$report = (new Gazelle\Manager\Report)->findById((int)($_POST['id'] ?? 0));
$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User))->findById((int)($_POST['id'] ?? 0));
if (is_null($report)) {
json_error('bad post id');
}

View File

@@ -4,7 +4,7 @@ if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) {
json_error('bad parameters');
}
$report = (new Gazelle\Manager\Report)->findById((int)($_POST['id'] ?? 0));
$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User))->findById((int)($_POST['id'] ?? 0));
if (is_null($report)) {
json_error('no report id');
}

View File

@@ -5,13 +5,14 @@ if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) {
}
authorize();
$report = (new Gazelle\Manager\Report)->findById((int)($_POST['reportid'] ?? 0));
$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User);
$report = $manager->findById((int)($_POST['reportid'] ?? 0));
if (is_null($report)) {
json_error('no report id');
}
if (!$Viewer->permitted('admin_reports') && !in_array($report->subjectType(), ['comment', 'post', 'thread'])) {
json_error('forbidden ' . $report->subjectType());
}
$report->resolve($Viewer, new Gazelle\Manager\Report);
$report->resolve($Viewer, $manager);
echo json_encode(['status' => 'success']);

View File

@@ -4,7 +4,7 @@ if (!$Viewer->permitted('site_moderate_forums') || empty($_POST['remove'])) {
json_error('bad parameters');
}
$report = (new Gazelle\Manager\Report)->findById((int)($_POST['id'] ?? 0));
$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User))->findById((int)($_POST['id'] ?? 0));
if (is_null($report)) {
json_error('no report id');
}

View File

@@ -24,78 +24,17 @@ if (isset($_GET['id'])) {
$paginator = new Gazelle\Util\Paginator(REPORTS_PER_PAGE, (int)($_GET['page'] ?? 1));
$paginator->setTotal($search->total());
$idList = $search->page($paginator->limit(), $paginator->offset());
$collageMan = new Gazelle\Manager\Collage;
$commentMan = new Gazelle\Manager\Comment;
$forumMan = new Gazelle\Manager\Forum;
$threadMan = new Gazelle\Manager\ForumThread;
$postMan = new Gazelle\Manager\ForumPost;
$requestMan = new Gazelle\Manager\Request;
$userMan = new Gazelle\Manager\User;
$reportMan = (new Gazelle\Manager\Report)->setUserManager($userMan);
$list = [];
foreach ($idList as $id) {
$report = $reportMan->findById($id);
switch ($report-> subjectType()) {
case 'collage':
$context = [
'label' => 'collage',
'subject' => $collageMan->findById($report->subjectId()),
];
break;
case 'comment':
$context = [
'label' => 'comment',
'subject' => $commentMan->findById($report->subjectId()),
];
break;
case 'request':
case 'request_update':
$context = [
'label' => 'request',
'subject' => $requestMan->findById($report->subjectId()),
];
break;
case 'thread':
$thread = $threadMan->findById($report->subjectId());
$context = [
'label' => 'forum thread',
'subject' => $thread,
'link' => $thread
? ($thread->forum()->link() . ' › ' . $thread->link()
. ' created by ' . ($thread?->author()->link() ?? 'System'))
: null,
];
break;
case 'post':
$post = $postMan->findById($report->subjectId());
$link = null;
if ($post) {
$thread = $post->thread();
$link = $thread->forum()->link() . ' › ' . $thread->link() . ' › ' . $post->link()
. ' posted by ' . ($userMan->findById($post->userId())?->link() ?? 'System');
}
$context = [
'label' => 'forum post',
'subject' => $post,
'link' => $link,
];
break;
case 'user':
$context = [
'label' => 'user',
'subject' => $userMan->findById($report->subjectId()),
];
break;
}
$context['report'] = $report;
$list[] = $context;
}
echo $Twig->render('report/index.twig', [
'list' => $list,
'list' => (new Gazelle\Manager\Report(new Gazelle\Manager\User))->decorate(
$search->page($paginator->limit(), $paginator->offset()),
new Gazelle\Manager\Collage,
new Gazelle\Manager\Comment,
new Gazelle\Manager\Forum,
new Gazelle\Manager\ForumThread,
new Gazelle\Manager\ForumPost,
new Gazelle\Manager\Request,
),
'paginator' => $paginator,
'type' => $Types,
'viewer' => $Viewer,

View File

@@ -14,12 +14,7 @@ $ConvID = false;
if (isset($_POST['convid']) && is_number($_POST['convid'])) {
$ConvID = $_POST['convid'];
$Subject = '';
$ToID = explode(',', $_POST['toid']);
foreach ($ToID as $TID) {
if (!is_number($TID)) {
$Err = 'A recipient does not exist.';
}
}
$ToID = (int)$_POST['toid'];
$db = Gazelle\DB::DB();
$db->prepared_query("
SELECT UserID
@@ -32,16 +27,15 @@ if (isset($_POST['convid']) && is_number($_POST['convid'])) {
error(403);
}
} else {
if (!is_number($_POST['toid'])) {
$Err = 'This recipient does not exist.';
} else {
$ToID = $_POST['toid'];
}
$ToID = (int)$_POST['toid'];
$Subject = trim($_POST['subject']);
if (empty($Subject)) {
$Err = "You can't send a message without a subject.";
}
}
if (!$ToID) {
$Err = 'This recipient does not exist.';
}
$Body = trim($_POST['body'] ?? '');
if ($Body === '') {
$Err = "You can't send a message without a body!";

View File

@@ -25,7 +25,7 @@ if ($reportType !== 'request_update') {
}
$reason = "[b]Year[/b]: {$year}.\n\n";
// If the release type is somehow invalid, return "Not given"; otherwise, return the release type.
$reason .= '[b]Release type[/b]: '.((empty($_POST['releasetype']) || !is_number($_POST['releasetype']) || $_POST['releasetype'] === '0')
$reason .= '[b]Release type[/b]: '.((empty($_POST['releasetype']) || !is_number($_POST['releasetype']) || $_POST['releasetype'] == '0')
? 'Not given' : (new Gazelle\ReleaseType)->findNameById($_POST['releasetype']))." . \n\n";
$reason .= '[b]Additional comments[/b]: '.$_POST['comment'];
}
@@ -44,7 +44,7 @@ if (is_null($location)) {
error("Cannot generate a link to the reported item");
}
$report = (new Gazelle\Manager\Report)->create($Viewer, $subjectId, $reportType, $reason);
$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User))->create($Viewer, $subjectId, $reportType, $reason);
$channelList = [];
if ($reportType === 'request_update') {

View File

@@ -5,13 +5,14 @@ if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) {
}
authorize();
$report = (new Gazelle\Manager\Report)->findById((int)($_POST['id'] ?? 0));
$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User);
$report = $manager->findById((int)($_POST['id'] ?? 0));
if (is_null($report)) {
json_error('no report id');
}
if (!$Viewer->permitted('admin_reports') && !in_array($report->subjectType(), ['comment', 'post', 'thread'])) {
error('forbidden ' . $report->subjectType());
}
$report->resolve($Viewer, new Gazelle\Manager\Report);
$report->resolve($Viewer, $manager);
header('Location: reports.php');

View File

@@ -594,23 +594,4 @@ class CollageTest extends TestCase {
$collage->remove();
$this->assertInstanceOf(Gazelle\Collage::class, $manager->recoverById($collage->id()), 'collage-recover-by-id');
}
public function testCollageReport(): void {
$name = 'phpunit collage report ' . randomString(20);
$this->collageList[] = (new Gazelle\Manager\Collage)->create(
user: $this->userList['u1'],
categoryId: 2, /* Theme */
name: $name,
description: 'phpunit collage report description',
tagList: implode(' ', $this->tagList(3)),
logger: new Gazelle\Log,
);
$collage = $this->collageList[0];
$manager = new Gazelle\Manager\Report;
$report = $manager->create($this->userList['u2'], $collage->id(), 'collage', 'phpunit collage report');
$this->assertEquals("phpunit collage report", $report->reason(), 'collage-report-reason');
$this->assertEquals($collage->id(), $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals(1, $report->resolve($this->userList['u1'], $manager));
}
}

View File

@@ -265,103 +265,4 @@ class RequestTest extends TestCase {
$this->assertEquals('', $payload['fillerName'], 'req-json-can-vote');
$this->assertEquals('UA-7890', $payload['catalogueNumber'], 'req-json-catno');
}
public function testReport(): void {
$this->request = (new Gazelle\Manager\Request)->create(
userId: $this->userList['user']->id(),
categoryId: (new Gazelle\Manager\Category)->findIdByName('Comics'),
year: (int)date('Y'),
title: 'phpunit request report',
image: '',
description: 'This is a unit test description',
recordLabel: 'Unitest Artists',
catalogueNumber: 'UA-7890',
releaseType: 1,
encodingList: 'Lossless',
formatList: 'FLAC',
mediaList: 'WEB',
checksum: false,
logCue: '',
oclc: '',
);
$manager = new Gazelle\Manager\Report;
$initial = $manager->remainingTotal();
$report = $manager->create($this->userList['user'], $this->request->id(), 'request', 'phpunit report');
$report->setUserManager(new Gazelle\Manager\User);
$this->assertEquals($initial + 1, $manager->remainingTotal(), 'request-report-one-more');
$this->assertEquals('New', $report->status(), 'request-report-status-new');
$this->assertEquals('phpunit report', $report->reason(), 'request-report-reason');
$this->assertEquals($this->userList['user']->id(), $report->reporter()?->id(), 'request-report-reporter-id');
$this->assertEquals('request', $report->subjectType(), 'request-report-subject-type');
$this->assertEquals($this->request->id(), $report->subjectId(), 'request-report-subject-id');
$this->assertEquals(
"<a href=\"reports.php?id={$report->id()}#report{$report->id()}\">Report #{$report->id()}</a>",
$report->link(),
'request-report-link'
);
$this->assertNull($report->notes(), 'request-no-notes-yet');
$this->assertNull($report->claimer(), 'request-report-no-claimer');
$this->assertNull($report->resolver(), 'request-report-no-resolver');
$this->assertNull($report->resolved(), 'request-report-not-resolved-date');
$this->assertFalse($report->isClaimed(), 'request-report-not-yet-claimed');
// report specifics
$reqReport = new Gazelle\Report\Request($report->id(), $this->request);
$this->assertTrue($reqReport->needReason(), 'request-report-not-an-update');
$this->assertEquals(
'Request Report: ' . display_str($this->request->title()),
$reqReport->title(),
'request-report-not-an-update'
);
// note
$note = "abc<br />def<br />ghi";
$report->addNote($note);
$this->assertEquals("abc\ndef\nghi", $report->notes(), 'request-report-notes');
// claim
$this->assertEquals(1, $report->claim($this->userList['admin']), 'request-report-claim');
$this->assertTrue($report->isClaimed(), 'request-report-is-claimed');
$this->assertEquals('InProgress', $report->flush()->status(), 'request-report-in-progress');
$claimer = $report->claimer();
$this->assertNotNull($claimer, 'request-report-has-claimer');
$this->assertEquals($this->userList['admin']->id(), $claimer->id(), 'request-report-claimer-id');
$this->assertEquals(1, $report->claim(null), 'request-report-unclaim');
$this->assertFalse($report->isClaimed(), 'request-report-is-unclaimed');
// search
$this->assertCount(
1,
(new Gazelle\Search\Report)->setId($report->id())->page(2, 0),
'request-report-search-id'
);
$this->assertEquals(
1,
(new Gazelle\Search\Report)->setStatus(['InProgress'])->total(),
'request-report-search-in-progress-total'
);
$this->assertEquals(
0,
(new Gazelle\Search\Report)->setStatus(['InProgress'])->restrictForumMod()->total(),
'request-report-search-fmod-in-progress-total'
);
$search = new Gazelle\Search\Report;
$total = $search->setStatus(['InProgress'])->total();
$page = $search->page($total, 0);
$this->assertEquals($total, count($page), 'request-report-page-list');
$this->assertEquals($report->id(), $page[0], 'request-report-page-id');
// resolve
$this->assertEquals(1, $report->resolve($this->userList['admin'], $manager), 'request-report-claim');
$this->assertNotNull($report->resolved(), 'request-report-resolved-date');
$this->assertEquals('Resolved', $report->status(), 'request-report-resolved-status');
$resolver = $report->resolver();
$this->assertNotNull($resolver, 'request-report-has-resolver');
$this->assertEquals($this->userList['admin']->id(), $resolver->id(), 'request-report-resolver-id');
$this->assertEquals($initial, $manager->remainingTotal(), 'request-report-initial-total');
}
}

View File

@@ -0,0 +1,222 @@
<?php
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../../lib/bootstrap.php');
require_once(__DIR__ . '/../../helper.php');
class ReportManagerTest extends TestCase {
protected array $reportList = [];
protected array $userList = [];
protected \Gazelle\Collage $collage;
protected \Gazelle\Request $request;
public function setUp(): void {
$this->userList = [
Helper::makeUser('report.' . randomString(10), 'report'),
Helper::makeUser('report.' . randomString(10), 'report'),
];
foreach ($this->userList as $user) {
$user->setField('Enabled', '1')->modify();
$pmMan = new Gazelle\Manager\PM($user);
foreach ((new Gazelle\User\Inbox($user))->messageList($pmMan, 1, 0) as $pm) {
$pm->remove();
}
}
}
public function tearDown(): void {
if (isset($this->collage)) {
$this->collage->hardRemove();
}
if (isset($this->request)) {
$this->request->remove();
}
foreach ($this->reportList as $report) {
$report->remove();
}
foreach ($this->userList as $user) {
$user->remove();
}
}
public function testReportCollage(): void {
$this->collage = (new Gazelle\Manager\Collage)->create(
user: $this->userList[0],
categoryId: 2,
name: 'phpunit collage report ' . randomString(20),
description: 'phpunit collage report description',
tagList: 'disco funk metal',
logger: new Gazelle\Log,
);
$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User);
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$this->assertEquals("phpunit collage report", $report->reason(), 'collage-report-reason');
$this->assertEquals($this->collage->id(), $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals(1, $report->resolve($this->userList[0], $manager));
}
public function testReportRequest(): void {
$this->request = (new Gazelle\Manager\Request)->create(
userId: $this->userList[1]->id(),
categoryId: (new Gazelle\Manager\Category)->findIdByName('Comics'),
year: (int)date('Y'),
title: 'phpunit request report',
image: '',
description: 'This is a unit test description',
recordLabel: 'Unitest Artists',
catalogueNumber: 'UA-7890',
releaseType: 1,
encodingList: 'Lossless',
formatList: 'FLAC',
mediaList: 'WEB',
checksum: false,
logCue: '',
oclc: '',
);
$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User);
$initial = $manager->remainingTotal();
$report = $manager->create($this->userList[1], $this->request->id(), 'request', 'phpunit report');
$this->reportList[] = $report;
$this->assertEquals($initial + 1, $manager->remainingTotal(), 'request-report-one-more');
$this->assertEquals('New', $report->status(), 'request-report-status-new');
$this->assertEquals('phpunit report', $report->reason(), 'request-report-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporter()?->id(), 'request-report-reporter-id');
$this->assertEquals('request', $report->subjectType(), 'request-report-subject-type');
$this->assertEquals($this->request->id(), $report->subjectId(), 'request-report-subject-id');
$this->assertEquals(
"<a href=\"reports.php?id={$report->id()}#report{$report->id()}\">Report #{$report->id()}</a>",
$report->link(),
'request-report-link'
);
$this->assertNull($report->notes(), 'request-no-notes-yet');
$this->assertNull($report->claimer(), 'request-report-no-claimer');
$this->assertNull($report->resolver(), 'request-report-no-resolver');
$this->assertNull($report->resolved(), 'request-report-not-resolved-date');
$this->assertFalse($report->isClaimed(), 'request-report-not-yet-claimed');
// report specifics
$reqReport = new Gazelle\Report\Request($report->id(), $this->request);
$this->assertTrue($reqReport->needReason(), 'request-report-not-an-update');
$this->assertEquals(
'Request Report: ' . display_str($this->request->title()),
$reqReport->title(),
'request-report-not-an-update'
);
// note
$note = "abc<br />def<br />ghi";
$report->addNote($note);
$this->assertEquals("abc\ndef\nghi", $report->notes(), 'request-report-notes');
// claim
$this->assertEquals(1, $report->claim($this->userList[0]), 'request-report-claim');
$this->assertTrue($report->isClaimed(), 'request-report-is-claimed');
$this->assertEquals('InProgress', $report->flush()->status(), 'request-report-in-progress');
$claimer = $report->claimer();
$this->assertNotNull($claimer, 'request-report-has-claimer');
$this->assertEquals($this->userList[0]->id(), $claimer->id(), 'request-report-claimer-id');
$this->assertEquals(1, $report->claim(null), 'request-report-unclaim');
$this->assertFalse($report->isClaimed(), 'request-report-is-unclaimed');
// search
$this->assertCount(
1,
(new Gazelle\Search\Report)->setId($report->id())->page(2, 0),
'request-report-search-id'
);
$this->assertEquals(
1,
(new Gazelle\Search\Report)->setStatus(['InProgress'])->total(),
'request-report-search-in-progress-total'
);
$this->assertEquals(
0,
(new Gazelle\Search\Report)->setStatus(['InProgress'])->restrictForumMod()->total(),
'request-report-search-fmod-in-progress-total'
);
$search = new Gazelle\Search\Report;
$total = $search->setStatus(['InProgress'])->total();
$page = $search->page($total, 0);
$this->assertEquals($total, count($page), 'request-report-page-list');
$this->assertEquals($report->id(), $page[0], 'request-report-page-id');
// resolve
$this->assertEquals(1, $report->resolve($this->userList[0], $manager), 'request-report-claim');
$this->assertNotNull($report->resolved(), 'request-report-resolved-date');
$this->assertEquals('Resolved', $report->status(), 'request-report-resolved-status');
$resolver = $report->resolver();
$this->assertNotNull($resolver, 'request-report-has-resolver');
$this->assertEquals($this->userList[0]->id(), $resolver->id(), 'request-report-resolver-id');
$this->assertEquals($initial, $manager->remainingTotal(), 'request-report-initial-total');
}
public function testReportUser(): void {
$manager = new \Gazelle\Manager\Report(new Gazelle\Manager\User);
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$this->reportList[] = $report;
$this->assertInstanceOf(\Gazelle\Report::class, $report, 'report-user-create');
$this->assertEquals('reports', $report->tableName(), 'report-table-name');
$this->assertEquals(
"<a href=\"{$report->url()}\">Report #{$report->id()}</a>",
$report->link(),
'report-link'
);
$this->assertEquals(
"reports.php?id={$report->id()}#report{$report->id()}",
$report->location(),
'report-location'
);
$this->assertEquals('phpunit user report', $report->reason(), 'report-reason');
$this->assertEquals('New', $report->status(), 'report-new-status');
$this->assertEquals($this->userList[1]->id(), $report->subjectId(), 'report-subject-id');
$this->assertEquals('user', $report->subjectType(), 'report-subject-type');
$this->assertEquals($this->userList[0]->id(), $report->reporter()->id(), 'report-reporter');
$this->assertFalse($report->isClaimed(), 'report-is-not-claimed');
$this->assertNull($report->resolved(), 'report-not-resolved');
$this->assertMatchesRegularExpression('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $report->created(), 'report-created');
$this->assertNull($report->notes(), 'report-no-notes');
$report->addNote('phpunit add note');
$this->assertEquals('phpunit add note', $report->notes(), 'report-add-notes');
$this->assertEquals($report->id(), $manager->findById($report->id())->id(), 'report-user-find');
}
public function testDecorate(): void {
$manager = new \Gazelle\Manager\Report(new Gazelle\Manager\User);
$this->collage = (new Gazelle\Manager\Collage)->create(
user: $this->userList[0],
categoryId: 2,
name: 'phpunit collage report ' . randomString(20),
description: 'phpunit collage report description',
tagList: 'disco funk metal',
logger: new Gazelle\Log,
);
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$this->reportList[] = $report;
$list = $manager->decorate(
array_map(fn($r) => $r->id(), $this->reportList),
new Gazelle\Manager\Collage,
new Gazelle\Manager\Comment,
new Gazelle\Manager\Forum,
new Gazelle\Manager\ForumThread,
new Gazelle\Manager\ForumPost,
new Gazelle\Manager\Request,
);
$this->assertCount(2, $list, 'report-decorate-list');
$this->assertEquals('collage', $list[0]['label'], 'report-list-label');
$this->assertEquals($this->collage->id(), $list[0]['subject']->id(), 'report-list-subject-id');
$this->assertNull($list[0]['context'], 'report-list-collage-context-null');
}
}