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

@@ -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');
}
}