]> git.mxchange.org Git - friendica.git/blob - tests/src/Contact/Introduction/Factory/IntroductionTest.php
Just commit config transactions if something changed
[friendica.git] / tests / src / Contact / Introduction / Factory / IntroductionTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Contact\Introduction\Factory;
23
24 use Friendica\Contact\Introduction\Factory\Introduction;
25 use PHPUnit\Framework\TestCase;
26 use Psr\Log\NullLogger;
27
28 class IntroductionTest extends TestCase
29 {
30         public function dataRow()
31         {
32                 return [
33                         'default' => [
34                                 'input' => [
35                                         'uid'         => 42,
36                                         'suggest-cid' => 13,
37                                         'contact-id'  => 24,
38                                         'knowyou'     => 1,
39                                         'note'        => 'a note',
40                                         'hash'        => '12345',
41                                         'datetime'    => '1970-01-01 00:00:00',
42                                         'ignore'      => 0,
43                                         'id'          => 56,
44                                 ],
45                                 'assertion' => [
46                                         'uid'         => 42,
47                                         'suggest-cid' => 13,
48                                         'contact-id'  => 24,
49                                         'knowyou'     => true,
50                                         'note'        => 'a note',
51                                         'hash'        => '12345',
52                                         'datetime'    => new \DateTime('1970-01-01 00:00:00', new \DateTimeZone('UTC')),
53                                         'ignore'      => false,
54                                         'id'          => 56,
55                                 ]
56                         ],
57                         'empty' => [
58                                 'input' => [
59                                 ],
60                                 'assertion' => [
61                                         'uid'         => 0,
62                                         'contact-id'  => 0,
63                                         'suggest-cid' => null,
64                                         'knowyou'     => false,
65                                         'note'        => '',
66                                         'ignore'      => false,
67                                         'id'          => null,
68                                 ]
69                         ],
70                 ];
71         }
72
73         public function assertIntro(\Friendica\Contact\Introduction\Entity\Introduction $intro, array $assertion)
74         {
75                 self::assertEquals($intro->id, $assertion['id'] ?? null);
76                 self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
77                 self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
78                 self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
79                 self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
80                 self::assertEquals($intro->note, $assertion['note'] ?? '');
81                 if (isset($assertion['hash'])) {
82                         self::assertEquals($intro->hash, $assertion['hash']);
83                 } else {
84                         self::assertIsString($intro->hash);
85                 }
86                 if (isset($assertion['datetime'])) {
87                         self::assertEquals($intro->datetime, $assertion['datetime']);
88                 } else {
89                         self::assertInstanceOf(\DateTime::class, $intro->datetime);
90                 }
91                 self::assertEquals($intro->ignore, $assertion['ignore'] ?? false);
92         }
93
94         /**
95          * @dataProvider dataRow
96          */
97         public function testCreateFromTableRow(array $input, array $assertion)
98         {
99                 $factory = new Introduction(new NullLogger());
100
101                 $intro = $factory->createFromTableRow($input);
102                 $this->assertIntro($intro, $assertion);
103         }
104
105         /**
106          * @dataProvider dataRow
107          */
108         public function testCreateNew(array $input, array $assertion)
109         {
110                 $factory = new Introduction(new NullLogger());
111
112                 $intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
113
114                 $this->assertIntro($intro, [
115                         'uid'        => $input['uid'] ?? 0,
116                         'contact-id' => $input['cid'] ?? 0,
117                         'note'       => $input['note'] ?? '',
118                 ]);
119         }
120
121         /**
122          * @dataProvider dataRow
123          */
124         public function testCreateDummy(array $input, array $assertion)
125         {
126                 $factory = new Introduction(new NullLogger());
127
128                 $intro = $factory->createDummy($input['id'] ?? null);
129
130                 $this->assertIntro($intro, ['id' => $input['id'] ?? null]);
131         }
132 }