]> git.mxchange.org Git - friendica.git/blob - tests/src/Moderation/Factory/ReportTest.php
Fix 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                                         'rules'       => '',
43                                         'forward'     => false,
44                                         'created'     => null
45                                 ],
46                                 'postUriIds' => [],
47                                 'assertion'  => new Entity\Report(
48                                         14,
49                                         13,
50                                         new \DateTime('now', new \DateTimeZone('UTC')),
51                                         '',
52                                         null,
53                                         '',
54                                         false,
55                                         [],
56                                         12,
57                                         11,
58                                 ),
59                         ],
60                         'full' => [
61                                 'row' => [
62                                         'id'          => 11,
63                                         'uid'         => 12,
64                                         'reporter-id' => 14,
65                                         'cid'         => 13,
66                                         'comment'     => 'Report',
67                                         'category'    => 'violation',
68                                         'rules'       => 'Rules',
69                                         'forward'     => true,
70                                         'created'     => '2021-10-12 12:23:00'
71                                 ],
72                                 'postUriIds' => [89, 90],
73                                 'assertion'  => new Entity\Report(
74                                         14,
75                                         13,
76                                         new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')),
77                                         'Report',
78                                         'violation',
79                                         'Rules',
80                                         true,
81                                         [89, 90],
82                                         12,
83                                         11
84                                 ),
85                         ],
86                 ];
87         }
88
89         public function assertReport(Entity\Report $assertion, Entity\Report $report)
90         {
91                 self::assertEquals(
92                         $assertion->id,
93                         $report->id
94                 );
95                 self::assertEquals($assertion->uid, $report->uid);
96                 self::assertEquals($assertion->reporterId, $report->reporterId);
97                 self::assertEquals($assertion->cid, $report->cid);
98                 self::assertEquals($assertion->comment, $report->comment);
99                 self::assertEquals($assertion->category, $report->category);
100                 self::assertEquals($assertion->rules, $report->rules);
101                 self::assertEquals($assertion->forward, $report->forward);
102                 // No way to test "now" at the moment
103                 //self::assertEquals($assertion->created, $report->created);
104                 self::assertEquals($assertion->postUriIds, $report->postUriIds);
105         }
106
107         /**
108          * @dataProvider dataCreateFromTableRow
109          */
110         public function testCreateFromTableRow(array $row, array $postUriIds, Entity\Report $assertion)
111         {
112                 $factory = new Factory\Report(new NullLogger());
113
114                 $this->assertReport($factory->createFromTableRow($row, $postUriIds), $assertion);
115         }
116
117         public function dataCreateFromReportsRequest(): array
118         {
119                 return [
120                         'default' => [
121                                 'reporter-id' => 14,
122                                 'cid'         => 13,
123                                 'comment'     => '',
124                                 'category'    => null,
125                                 'rules'       => '',
126                                 'forward'     => false,
127                                 'postUriIds'  => [],
128                                 'uid'         => 12,
129                                 'assertion'   => new Entity\Report(
130                                         14,
131                                         13,
132                                         new \DateTime('now', new \DateTimeZone('UTC')),
133                                         '',
134                                         null,
135                                         '',
136                                         false,
137                                         [],
138                                         12,
139                                         null
140                                 ),
141                         ],
142                         'full' => [
143                                 'reporter-id' => 14,
144                                 'cid'         => 13,
145                                 'comment'     => 'Report',
146                                 'category'    => 'violation',
147                                 'rules'       => 'Rules',
148                                 'forward'     => true,
149                                 'postUriIds'  => [89, 90],
150                                 'uid'         => 12,
151                                 'assertion'   => new Entity\Report(
152                                         14,
153                                         13,
154                                         new \DateTime('now', new \DateTimeZone('UTC')),
155                                         'Report',
156                                         'violation',
157                                         'Rules',
158                                         true,
159                                         [89, 90],
160                                         12,
161                                         null
162                                 ),
163                         ],
164                 ];
165         }
166
167         /**
168          * @dataProvider dataCreateFromReportsRequest
169          */
170         public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, string $rules = '', bool $forward, array $postUriIds, int $uid, Entity\Report $assertion)
171         {
172                 $factory = new Factory\Report(new NullLogger());
173
174                 $this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $rules, $forward, $postUriIds, $uid), $assertion);
175         }
176 }