]> git.mxchange.org Git - friendica.git/blob - tests/src/Moderation/Factory/ReportTest.php
Tests
[friendica.git] / tests / src / Moderation / Factory / ReportTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Moderation\Factory;
23
24 use Friendica\Moderation\Factory;
25 use Friendica\Moderation\Entity;
26 use Friendica\Test\MockedTest;
27 use Psr\Log\NullLogger;
28
29 class ReportTest extends MockedTest
30 {
31         public function dataCreateFromTableRow(): array
32         {
33                 return [
34                         'default' => [
35                                 'row' => [
36                                         'id'          => 11,
37                                         'uid'         => 12,
38                                         'reporter-id' => 14,
39                                         'cid'         => 13,
40                                         'comment'     => '',
41                                         'category'    => null,
42                                         'forward'     => false,
43                                         'created'     => null
44                                 ],
45                                 'postUriIds' => [],
46                                 'assertion'  => new Entity\Report(
47                                         14,
48                                         13,
49                                         new \DateTime('now', new \DateTimeZone('UTC')),
50                                         '',
51                                         null,
52                                         false,
53                                         [],
54                                         12,
55                                         11,
56                                 ),
57                         ],
58                         'full' => [
59                                 'row' => [
60                                         'id'          => 11,
61                                         'uid'         => 12,
62                                         'reporter-id' => 14,
63                                         'cid'         => 13,
64                                         'comment'     => 'Report',
65                                         'category'    => 'violation',
66                                         'forward'     => true,
67                                         'created'     => '2021-10-12 12:23:00'
68                                 ],
69                                 'postUriIds' => [89, 90],
70                                 'assertion'  => new Entity\Report(
71                                         14,
72                                         13,
73                                         new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
74                                         'Report',
75                                         'violation',
76                                         true,
77                                         [89, 90],
78                                         12,
79                                         11
80                                 ),
81                         ],
82                 ];
83         }
84
85         public function assertReport(Entity\Report $assertion, Entity\Report $report)
86         {
87                 self::assertEquals(
88                         $assertion->id,
89                         $report->id
90                 );
91                 self::assertEquals($assertion->uid, $report->uid);
92                 self::assertEquals($assertion->reporterId, $report->reporterId);
93                 self::assertEquals($assertion->cid, $report->cid);
94                 self::assertEquals($assertion->comment, $report->comment);
95                 self::assertEquals($assertion->category, $report->category);
96                 self::assertEquals($assertion->forward, $report->forward);
97                 // No way to test "now" at the moment
98                 //self::assertEquals($assertion->created, $report->created);
99                 self::assertEquals($assertion->postUriIds, $report->postUriIds);
100         }
101
102         /**
103          * @dataProvider dataCreateFromTableRow
104          */
105         public function testCreateFromTableRow(array $row, array $postUriIds, Entity\Report $assertion)
106         {
107                 $factory = new Factory\Report(new NullLogger());
108
109                 $this->assertReport($factory->createFromTableRow($row, $postUriIds), $assertion);
110         }
111
112         public function dataCreateFromReportsRequest(): array
113         {
114                 return [
115                         'default' => [
116                                 'reporter-id' => 14,
117                                 'cid'         => 13,
118                                 'comment'     => '',
119                                 'category'    => null,
120                                 'forward'     => false,
121                                 'postUriIds'  => [],
122                                 'uid'         => 12,
123                                 'assertion'   => new Entity\Report(
124                                         14,
125                                         13,
126                                         new \DateTime('now', new \DateTimeZone('UTC')),
127                                         '',
128                                         null,
129                                         false,
130                                         [],
131                                         12,
132                                         null
133                                 ),
134                         ],
135                         'full' => [
136                                 'reporter-id' => 14,
137                                 'cid'         => 13,
138                                 'comment'     => 'Report',
139                                 'category'    => 'violation',
140                                 'forward'     => true,
141                                 'postUriIds'  => [89, 90],
142                                 'uid'         => 12,
143                                 'assertion'   => new Entity\Report(
144                                         14,
145                                         13,
146                                         new \DateTime('now', new \DateTimeZone('UTC')),
147                                         'Report',
148                                         'violation',
149                                         true,
150                                         [89, 90],
151                                         12,
152                                         null
153                                 ),
154                         ],
155                 ];
156         }
157
158         /**
159          * @dataProvider dataCreateFromReportsRequest
160          */
161         public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
162         {
163                 $factory = new Factory\Report(new NullLogger());
164
165                 $this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $forward, $postUriIds, $uid), $assertion);
166         }
167 }