mirror of
https://github.com/friendica/friendica
synced 2025-04-26 17:10:10 +00:00
Add fields to Report entity
- Add clock dependency to Moderation\Factory\Report - Change DateTime field to DateTimeImmutable to satisfy Clock return type - Add category, status and resolution constants
This commit is contained in:
parent
d29a84ae46
commit
76de49a25c
13 changed files with 543 additions and 222 deletions
|
@ -21,144 +21,242 @@
|
|||
|
||||
namespace Friendica\Test\src\Moderation\Factory;
|
||||
|
||||
use Friendica\Moderation\Collection;
|
||||
use Friendica\Moderation\Factory;
|
||||
use Friendica\Moderation\Entity;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Util\Clock\FrozenClock;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Clock\ClockInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class ReportTest extends MockedTest
|
||||
{
|
||||
public function dataCreateFromTableRow(): array
|
||||
{
|
||||
$clock = new FrozenClock();
|
||||
|
||||
// We need to strip the microseconds part to match database stored timestamps
|
||||
$nowSeconds = $clock->now()->setTime(
|
||||
$clock->now()->format('H'),
|
||||
$clock->now()->format('i'),
|
||||
$clock->now()->format('s')
|
||||
);
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'clock' => $clock,
|
||||
'row' => [
|
||||
'id' => 11,
|
||||
'uid' => 12,
|
||||
'reporter-id' => 14,
|
||||
'cid' => 13,
|
||||
'comment' => '',
|
||||
'category' => null,
|
||||
'rules' => '',
|
||||
'forward' => false,
|
||||
'created' => null
|
||||
'id' => 11,
|
||||
'reporter-id' => 12,
|
||||
'uid' => null,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => '',
|
||||
'forward' => false,
|
||||
'category-id' => Entity\Report::CATEGORY_SPAM,
|
||||
'public-remarks' => '',
|
||||
'private-remarks' => '',
|
||||
'last-editor-uid' => null,
|
||||
'assigned-uid' => null,
|
||||
'status' => Entity\Report::STATUS_OPEN,
|
||||
'resolution' => null,
|
||||
'created' => $nowSeconds->format(DateTimeFormat::MYSQL),
|
||||
'edited' => null,
|
||||
],
|
||||
'postUriIds' => [],
|
||||
'posts' => new Collection\Report\Posts(),
|
||||
'rules' => new Collection\Report\Rules(),
|
||||
'assertion' => new Entity\Report(
|
||||
14,
|
||||
12,
|
||||
13,
|
||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||
'',
|
||||
14,
|
||||
$nowSeconds,
|
||||
Entity\Report::CATEGORY_SPAM,
|
||||
null,
|
||||
'',
|
||||
false,
|
||||
[],
|
||||
12,
|
||||
11,
|
||||
new Collection\Report\Posts(),
|
||||
new Collection\Report\Rules(),
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
Entity\Report::STATUS_OPEN,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
11
|
||||
),
|
||||
],
|
||||
'full' => [
|
||||
'clock' => $clock,
|
||||
'row' => [
|
||||
'id' => 11,
|
||||
'uid' => 12,
|
||||
'reporter-id' => 14,
|
||||
'cid' => 13,
|
||||
'comment' => 'Report',
|
||||
'category' => 'violation',
|
||||
'rules' => 'Rules',
|
||||
'forward' => true,
|
||||
'created' => '2021-10-12 12:23:00'
|
||||
'id' => 11,
|
||||
'reporter-id' => 42,
|
||||
'uid' => 12,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => 'Report',
|
||||
'forward' => true,
|
||||
'category-id' => Entity\Report::CATEGORY_VIOLATION,
|
||||
'public-remarks' => 'Public remarks',
|
||||
'private-remarks' => 'Private remarks',
|
||||
'last-editor-uid' => 15,
|
||||
'assigned-uid' => 16,
|
||||
'status' => Entity\Report::STATUS_CLOSED,
|
||||
'resolution' => Entity\Report::RESOLUTION_ACCEPTED,
|
||||
'created' => '2021-10-12 12:23:00',
|
||||
'edited' => '2021-12-10 21:08:00',
|
||||
],
|
||||
'postUriIds' => [89, 90],
|
||||
'posts' => new Collection\Report\Posts([
|
||||
new Entity\Report\Post(89),
|
||||
new Entity\Report\Post(90),
|
||||
]),
|
||||
'rules' => new Collection\Report\Rules([
|
||||
new Entity\Report\Rule(1, 'No hate speech'),
|
||||
new Entity\Report\Rule(3, 'No commercial promotion'),
|
||||
]),
|
||||
'assertion' => new Entity\Report(
|
||||
14,
|
||||
42,
|
||||
13,
|
||||
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
|
||||
'Report',
|
||||
'violation',
|
||||
'Rules',
|
||||
true,
|
||||
[89, 90],
|
||||
14,
|
||||
new \DateTimeImmutable('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
|
||||
Entity\Report::CATEGORY_VIOLATION,
|
||||
12,
|
||||
'Report',
|
||||
true,
|
||||
new Collection\Report\Posts([
|
||||
new Entity\Report\Post(89),
|
||||
new Entity\Report\Post(90),
|
||||
]),
|
||||
new Collection\Report\Rules([
|
||||
new Entity\Report\Rule(1, 'No hate speech'),
|
||||
new Entity\Report\Rule(3, 'No commercial promotion'),
|
||||
]),
|
||||
'Public remarks',
|
||||
'Private remarks',
|
||||
new \DateTimeImmutable('2021-12-10 21:08:00', new \DateTimeZone('UTC')),
|
||||
Entity\Report::STATUS_CLOSED,
|
||||
Entity\Report::RESOLUTION_ACCEPTED,
|
||||
16,
|
||||
15,
|
||||
11
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function assertReport(Entity\Report $assertion, Entity\Report $report)
|
||||
{
|
||||
self::assertEquals(
|
||||
$assertion->id,
|
||||
$report->id
|
||||
);
|
||||
self::assertEquals($assertion->uid, $report->uid);
|
||||
self::assertEquals($assertion->reporterId, $report->reporterId);
|
||||
self::assertEquals($assertion->cid, $report->cid);
|
||||
self::assertEquals($assertion->comment, $report->comment);
|
||||
self::assertEquals($assertion->category, $report->category);
|
||||
self::assertEquals($assertion->rules, $report->rules);
|
||||
self::assertEquals($assertion->forward, $report->forward);
|
||||
// No way to test "now" at the moment
|
||||
//self::assertEquals($assertion->created, $report->created);
|
||||
self::assertEquals($assertion->postUriIds, $report->postUriIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataCreateFromTableRow
|
||||
*/
|
||||
public function testCreateFromTableRow(array $row, array $postUriIds, Entity\Report $assertion)
|
||||
public function testCreateFromTableRow(ClockInterface $clock, array $row, Collection\Report\Posts $posts, Collection\Report\Rules $rules, Entity\Report $assertion)
|
||||
{
|
||||
$factory = new Factory\Report(new NullLogger());
|
||||
$factory = new Factory\Report(new NullLogger(), $clock);
|
||||
|
||||
$this->assertReport($factory->createFromTableRow($row, $postUriIds), $assertion);
|
||||
$this->assertEquals($factory->createFromTableRow($row, $posts, $rules), $assertion);
|
||||
}
|
||||
|
||||
public function dataCreateFromReportsRequest(): array
|
||||
{
|
||||
$clock = new FrozenClock();
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'reporter-id' => 14,
|
||||
'cid' => 13,
|
||||
'comment' => '',
|
||||
'category' => null,
|
||||
'rules' => '',
|
||||
'forward' => false,
|
||||
'postUriIds' => [],
|
||||
'uid' => 12,
|
||||
'assertion' => new Entity\Report(
|
||||
14,
|
||||
13,
|
||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||
'',
|
||||
null,
|
||||
'',
|
||||
false,
|
||||
[],
|
||||
'clock' => $clock,
|
||||
'rules' => [],
|
||||
'reporterId' => 12,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => '',
|
||||
'category' => 'spam',
|
||||
'forward' => false,
|
||||
'postUriIds' => [],
|
||||
'ruleIds' => [],
|
||||
'uid' => null,
|
||||
'assertion' => new Entity\Report(
|
||||
12,
|
||||
null
|
||||
13,
|
||||
14,
|
||||
$clock->now(),
|
||||
Entity\Report::CATEGORY_SPAM,
|
||||
),
|
||||
],
|
||||
'full' => [
|
||||
'reporter-id' => 14,
|
||||
'cid' => 13,
|
||||
'comment' => 'Report',
|
||||
'category' => 'violation',
|
||||
'rules' => 'Rules',
|
||||
'forward' => true,
|
||||
'postUriIds' => [89, 90],
|
||||
'uid' => 12,
|
||||
'assertion' => new Entity\Report(
|
||||
14,
|
||||
13,
|
||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||
'Report',
|
||||
'violation',
|
||||
'Rules',
|
||||
true,
|
||||
[89, 90],
|
||||
'clock' => $clock,
|
||||
'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
|
||||
'reporterId' => 12,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => 'Report',
|
||||
'category' => 'violation',
|
||||
'forward' => true,
|
||||
'postUriIds' => [89, 90],
|
||||
'ruleIds' => [1, 3],
|
||||
'uid' => 42,
|
||||
'assertion' => new Entity\Report(
|
||||
12,
|
||||
null
|
||||
13,
|
||||
14,
|
||||
$clock->now(),
|
||||
Entity\Report::CATEGORY_VIOLATION,
|
||||
42,
|
||||
'Report',
|
||||
true,
|
||||
new Collection\Report\Posts([
|
||||
new Entity\Report\Post(89),
|
||||
new Entity\Report\Post(90)
|
||||
]),
|
||||
new Collection\Report\Rules([
|
||||
new Entity\Report\Rule(1, 'Rule 1'),
|
||||
new Entity\Report\Rule(3, 'Rule 3'),
|
||||
]),
|
||||
),
|
||||
],
|
||||
'forced-violation' => [
|
||||
'clock' => $clock,
|
||||
'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
|
||||
'reporterId' => 12,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => 'Report',
|
||||
'category' => 'other',
|
||||
'forward' => false,
|
||||
'postUriIds' => [],
|
||||
'ruleIds' => [2, 3],
|
||||
'uid' => null,
|
||||
'assertion' => new Entity\Report(
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
$clock->now(),
|
||||
Entity\Report::CATEGORY_VIOLATION,
|
||||
null,
|
||||
'Report',
|
||||
false,
|
||||
new Collection\Report\Posts(),
|
||||
new Collection\Report\Rules([
|
||||
new Entity\Report\Rule(2, 'Rule 2'),
|
||||
new Entity\Report\Rule(3, 'Rule 3'),
|
||||
]),
|
||||
),
|
||||
],
|
||||
'unknown-category' => [
|
||||
'clock' => $clock,
|
||||
'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
|
||||
'reporterId' => 12,
|
||||
'cid' => 13,
|
||||
'gsid' => 14,
|
||||
'comment' => '',
|
||||
'category' => 'unknown',
|
||||
'forward' => false,
|
||||
'postUriIds' => [],
|
||||
'ruleIds' => [],
|
||||
'uid' => null,
|
||||
'assertion' => new Entity\Report(
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
$clock->now(),
|
||||
Entity\Report::CATEGORY_OTHER,
|
||||
),
|
||||
],
|
||||
];
|
||||
|
@ -167,10 +265,10 @@ class ReportTest extends MockedTest
|
|||
/**
|
||||
* @dataProvider dataCreateFromReportsRequest
|
||||
*/
|
||||
public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, string $rules = '', bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
|
||||
public function testCreateFromReportsRequest(ClockInterface $clock, array $rules, int $reporterId, int $cid, int $gsid, string $comment, string $category, bool $forward, array $postUriIds, array $ruleIds, int $uid = null, Entity\Report $assertion)
|
||||
{
|
||||
$factory = new Factory\Report(new NullLogger());
|
||||
$factory = new Factory\Report(new NullLogger(), $clock);
|
||||
|
||||
$this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $rules, $forward, $postUriIds, $uid), $assertion);
|
||||
$this->assertEquals($factory->createFromReportsRequest($rules, $reporterId, $cid, $gsid, $comment, $category, $forward, $postUriIds, $ruleIds, $uid), $assertion);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue