3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Moderation\Factory;
24 use Friendica\Moderation\Collection;
25 use Friendica\Moderation\Factory;
26 use Friendica\Moderation\Entity;
27 use Friendica\Test\MockedTest;
28 use Friendica\Util\Clock\FrozenClock;
29 use Friendica\Util\DateTimeFormat;
30 use Psr\Clock\ClockInterface;
31 use Psr\Log\NullLogger;
33 class ReportTest extends MockedTest
35 public function dataCreateFromTableRow(): array
37 $clock = new FrozenClock();
39 // We need to strip the microseconds part to match database stored timestamps
40 $nowSeconds = $clock->now()->setTime(
41 $clock->now()->format('H'),
42 $clock->now()->format('i'),
43 $clock->now()->format('s')
57 'category-id' => Entity\Report::CATEGORY_SPAM,
58 'public-remarks' => '',
59 'private-remarks' => '',
60 'last-editor-uid' => null,
61 'assigned-uid' => null,
62 'status' => Entity\Report::STATUS_OPEN,
64 'created' => $nowSeconds->format(DateTimeFormat::MYSQL),
67 'posts' => new Collection\Report\Posts(),
68 'rules' => new Collection\Report\Rules(),
69 'assertion' => new Entity\Report(
74 Entity\Report::CATEGORY_SPAM,
78 new Collection\Report\Posts(),
79 new Collection\Report\Rules(),
83 Entity\Report::STATUS_OPEN,
98 'comment' => 'Report',
100 'category-id' => Entity\Report::CATEGORY_VIOLATION,
101 'public-remarks' => 'Public remarks',
102 'private-remarks' => 'Private remarks',
103 'last-editor-uid' => 15,
104 'assigned-uid' => 16,
105 'status' => Entity\Report::STATUS_CLOSED,
106 'resolution' => Entity\Report::RESOLUTION_ACCEPTED,
107 'created' => '2021-10-12 12:23:00',
108 'edited' => '2021-12-10 21:08:00',
110 'posts' => new Collection\Report\Posts([
111 new Entity\Report\Post(89),
112 new Entity\Report\Post(90),
114 'rules' => new Collection\Report\Rules([
115 new Entity\Report\Rule(1, 'No hate speech'),
116 new Entity\Report\Rule(3, 'No commercial promotion'),
118 'assertion' => new Entity\Report(
122 new \DateTimeImmutable('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
123 Entity\Report::CATEGORY_VIOLATION,
127 new Collection\Report\Posts([
128 new Entity\Report\Post(89),
129 new Entity\Report\Post(90),
131 new Collection\Report\Rules([
132 new Entity\Report\Rule(1, 'No hate speech'),
133 new Entity\Report\Rule(3, 'No commercial promotion'),
137 new \DateTimeImmutable('2021-12-10 21:08:00', new \DateTimeZone('UTC')),
138 Entity\Report::STATUS_CLOSED,
139 Entity\Report::RESOLUTION_ACCEPTED,
149 * @dataProvider dataCreateFromTableRow
151 public function testCreateFromTableRow(ClockInterface $clock, array $row, Collection\Report\Posts $posts, Collection\Report\Rules $rules, Entity\Report $assertion)
153 $factory = new Factory\Report(new NullLogger(), $clock);
155 $this->assertEquals($factory->createFromTableRow($row, $posts, $rules), $assertion);
158 public function dataCreateFromReportsRequest(): array
160 $clock = new FrozenClock();
170 'category' => 'spam',
175 'assertion' => new Entity\Report(
180 Entity\Report::CATEGORY_SPAM,
185 'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
189 'comment' => 'Report',
190 'category' => 'violation',
192 'postUriIds' => [89, 90],
195 'assertion' => new Entity\Report(
200 Entity\Report::CATEGORY_VIOLATION,
204 new Collection\Report\Posts([
205 new Entity\Report\Post(89),
206 new Entity\Report\Post(90)
208 new Collection\Report\Rules([
209 new Entity\Report\Rule(1, 'Rule 1'),
210 new Entity\Report\Rule(3, 'Rule 3'),
214 'forced-violation' => [
216 'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
220 'comment' => 'Report',
221 'category' => 'other',
226 'assertion' => new Entity\Report(
231 Entity\Report::CATEGORY_VIOLATION,
235 new Collection\Report\Posts(),
236 new Collection\Report\Rules([
237 new Entity\Report\Rule(2, 'Rule 2'),
238 new Entity\Report\Rule(3, 'Rule 3'),
242 'unknown-category' => [
244 'rules' => ['', 'Rule 1', 'Rule 2', 'Rule 3'],
249 'category' => 'unknown',
254 'assertion' => new Entity\Report(
259 Entity\Report::CATEGORY_OTHER,
266 * @dataProvider dataCreateFromReportsRequest
268 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)
270 $factory = new Factory\Report(new NullLogger(), $clock);
272 $this->assertEquals($factory->createFromReportsRequest($rules, $reporterId, $cid, $gsid, $comment, $category, $forward, $postUriIds, $ruleIds, $uid), $assertion);