2022-11-13 00:58:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\Moderation\Factory;
|
|
|
|
|
|
|
|
use Friendica\Moderation\Factory;
|
|
|
|
use Friendica\Moderation\Entity;
|
|
|
|
use Friendica\Test\MockedTest;
|
|
|
|
use Psr\Log\NullLogger;
|
|
|
|
|
|
|
|
class ReportTest extends MockedTest
|
|
|
|
{
|
|
|
|
public function dataCreateFromTableRow(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'default' => [
|
|
|
|
'row' => [
|
2022-12-24 08:03:37 +00:00
|
|
|
'id' => 11,
|
|
|
|
'uid' => 12,
|
|
|
|
'reporter-id' => 14,
|
|
|
|
'cid' => 13,
|
|
|
|
'comment' => '',
|
2022-12-24 23:26:54 +00:00
|
|
|
'category' => null,
|
2022-12-25 10:52:47 +00:00
|
|
|
'rules' => '',
|
2022-12-24 08:03:37 +00:00
|
|
|
'forward' => false,
|
|
|
|
'created' => null
|
2022-11-13 00:58:56 +00:00
|
|
|
],
|
|
|
|
'postUriIds' => [],
|
|
|
|
'assertion' => new Entity\Report(
|
2022-12-24 08:03:37 +00:00
|
|
|
14,
|
2022-11-13 00:58:56 +00:00
|
|
|
13,
|
|
|
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
|
|
|
'',
|
2022-12-24 13:57:43 +00:00
|
|
|
null,
|
2022-12-25 10:44:06 +00:00
|
|
|
'',
|
2022-11-13 00:58:56 +00:00
|
|
|
false,
|
|
|
|
[],
|
2022-12-25 07:30:39 +00:00
|
|
|
12,
|
2022-11-13 00:58:56 +00:00
|
|
|
11,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
'full' => [
|
|
|
|
'row' => [
|
2022-12-24 08:03:37 +00:00
|
|
|
'id' => 11,
|
|
|
|
'uid' => 12,
|
|
|
|
'reporter-id' => 14,
|
|
|
|
'cid' => 13,
|
|
|
|
'comment' => 'Report',
|
2022-12-24 23:26:54 +00:00
|
|
|
'category' => 'violation',
|
2022-12-25 10:44:06 +00:00
|
|
|
'rules' => 'Rules',
|
2022-12-24 08:03:37 +00:00
|
|
|
'forward' => true,
|
|
|
|
'created' => '2021-10-12 12:23:00'
|
2022-11-13 00:58:56 +00:00
|
|
|
],
|
|
|
|
'postUriIds' => [89, 90],
|
|
|
|
'assertion' => new Entity\Report(
|
2022-12-24 08:03:37 +00:00
|
|
|
14,
|
2022-11-13 00:58:56 +00:00
|
|
|
13,
|
|
|
|
new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
|
|
|
|
'Report',
|
2022-12-24 13:57:43 +00:00
|
|
|
'violation',
|
2022-12-25 10:44:06 +00:00
|
|
|
'Rules',
|
2022-11-13 00:58:56 +00:00
|
|
|
true,
|
|
|
|
[89, 90],
|
2022-12-25 07:30:39 +00:00
|
|
|
12,
|
2022-11-13 00:58:56 +00:00
|
|
|
11
|
|
|
|
),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assertReport(Entity\Report $assertion, Entity\Report $report)
|
|
|
|
{
|
|
|
|
self::assertEquals(
|
|
|
|
$assertion->id,
|
|
|
|
$report->id
|
|
|
|
);
|
|
|
|
self::assertEquals($assertion->uid, $report->uid);
|
2022-12-24 08:03:37 +00:00
|
|
|
self::assertEquals($assertion->reporterId, $report->reporterId);
|
2022-11-13 00:58:56 +00:00
|
|
|
self::assertEquals($assertion->cid, $report->cid);
|
|
|
|
self::assertEquals($assertion->comment, $report->comment);
|
2022-12-24 13:57:43 +00:00
|
|
|
self::assertEquals($assertion->category, $report->category);
|
2022-12-25 10:52:47 +00:00
|
|
|
self::assertEquals($assertion->rules, $report->rules);
|
2022-11-13 00:58:56 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
$factory = new Factory\Report(new NullLogger());
|
|
|
|
|
|
|
|
$this->assertReport($factory->createFromTableRow($row, $postUriIds), $assertion);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataCreateFromReportsRequest(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'default' => [
|
2022-12-24 08:03:37 +00:00
|
|
|
'reporter-id' => 14,
|
|
|
|
'cid' => 13,
|
|
|
|
'comment' => '',
|
2022-12-24 23:26:54 +00:00
|
|
|
'category' => null,
|
2022-12-25 10:44:06 +00:00
|
|
|
'rules' => null,
|
2022-12-24 08:03:37 +00:00
|
|
|
'forward' => false,
|
|
|
|
'postUriIds' => [],
|
2022-12-25 07:40:19 +00:00
|
|
|
'uid' => 12,
|
2022-12-24 08:03:37 +00:00
|
|
|
'assertion' => new Entity\Report(
|
|
|
|
14,
|
2022-11-13 00:58:56 +00:00
|
|
|
13,
|
|
|
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
|
|
|
'',
|
2022-12-24 13:57:43 +00:00
|
|
|
null,
|
2022-12-25 10:44:06 +00:00
|
|
|
'',
|
2022-11-13 00:58:56 +00:00
|
|
|
false,
|
|
|
|
[],
|
2022-12-25 07:30:39 +00:00
|
|
|
12,
|
2022-11-13 00:58:56 +00:00
|
|
|
null
|
|
|
|
),
|
|
|
|
],
|
|
|
|
'full' => [
|
2022-12-24 08:03:37 +00:00
|
|
|
'reporter-id' => 14,
|
|
|
|
'cid' => 13,
|
|
|
|
'comment' => 'Report',
|
2022-12-24 23:26:54 +00:00
|
|
|
'category' => 'violation',
|
2022-12-25 10:52:47 +00:00
|
|
|
'rules' => 'Rules',
|
2022-12-24 08:03:37 +00:00
|
|
|
'forward' => true,
|
|
|
|
'postUriIds' => [89, 90],
|
2022-12-25 07:40:19 +00:00
|
|
|
'uid' => 12,
|
2022-12-24 08:03:37 +00:00
|
|
|
'assertion' => new Entity\Report(
|
|
|
|
14,
|
2022-11-13 00:58:56 +00:00
|
|
|
13,
|
|
|
|
new \DateTime('now', new \DateTimeZone('UTC')),
|
|
|
|
'Report',
|
2022-12-24 13:57:43 +00:00
|
|
|
'violation',
|
2022-12-25 10:44:06 +00:00
|
|
|
'Rules',
|
2022-11-13 00:58:56 +00:00
|
|
|
true,
|
|
|
|
[89, 90],
|
2022-12-25 07:30:39 +00:00
|
|
|
12,
|
2022-11-13 00:58:56 +00:00
|
|
|
null
|
|
|
|
),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataCreateFromReportsRequest
|
|
|
|
*/
|
2022-12-25 10:52:47 +00:00
|
|
|
public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, string $rules = '', bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
|
2022-11-13 00:58:56 +00:00
|
|
|
{
|
|
|
|
$factory = new Factory\Report(new NullLogger());
|
|
|
|
|
2022-12-25 10:44:06 +00:00
|
|
|
$this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $rules, $forward, $postUriIds, $uid), $assertion);
|
2022-11-13 00:58:56 +00:00
|
|
|
}
|
|
|
|
}
|