]> git.mxchange.org Git - friendica.git/blob - tests/src/Contact/Introduction/Factory/IntroductionTest.php
Reenable Twitter/Mentions tests
[friendica.git] / tests / src / Contact / Introduction / Factory / IntroductionTest.php
1 <?php
2
3 namespace Friendica\Test\src\Contact\Introduction\Factory;
4
5 use Friendica\Contact\Introduction\Factory\Introduction;
6 use PHPUnit\Framework\TestCase;
7 use Psr\Log\NullLogger;
8
9 class IntroductionTest extends TestCase
10 {
11         public function dataRow()
12         {
13                 return [
14                         'default' => [
15                                 'input' => [
16                                         'uid'         => 42,
17                                         'suggest-cid' => 13,
18                                         'contact-id'  => 24,
19                                         'knowyou'     => 1,
20                                         'note'        => 'a note',
21                                         'hash'        => '12345',
22                                         'datetime'    => '1970-01-01 00:00:00',
23                                         'ignore'      => 0,
24                                         'id'          => 56,
25                                 ],
26                                 'assertion' => [
27                                         'uid'         => 42,
28                                         'suggest-cid' => 13,
29                                         'contact-id'  => 24,
30                                         'knowyou'     => true,
31                                         'note'        => 'a note',
32                                         'hash'        => '12345',
33                                         'datetime'    => new \DateTime('1970-01-01 00:00:00', new \DateTimeZone('UTC')),
34                                         'ignore'      => false,
35                                         'id'          => 56,
36                                 ]
37                         ],
38                         'empty' => [
39                                 'input' => [
40                                 ],
41                                 'assertion' => [
42                                         'uid'         => 0,
43                                         'contact-id'  => 0,
44                                         'suggest-cid' => null,
45                                         'knowyou'     => false,
46                                         'note'        => '',
47                                         'ignore'      => false,
48                                         'id'          => null,
49                                 ]
50                         ],
51                 ];
52         }
53
54         public function assertIntro(\Friendica\Contact\Introduction\Entity\Introduction $intro, array $assertion)
55         {
56                 self::assertEquals($intro->id, $assertion['id'] ?? null);
57                 self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
58                 self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
59                 self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
60                 self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
61                 self::assertEquals($intro->note, $assertion['note'] ?? '');
62                 if (isset($assertion['hash'])) {
63                         self::assertEquals($intro->hash, $assertion['hash']);
64                 } else {
65                         self::assertIsString($intro->hash);
66                 }
67                 if (isset($assertion['datetime'])) {
68                         self::assertEquals($intro->datetime, $assertion['datetime']);
69                 } else {
70                         self::assertInstanceOf(\DateTime::class, $intro->datetime);
71                 }
72                 self::assertEquals($intro->ignore, $assertion['ignore'] ?? false);
73         }
74
75         /**
76          * @dataProvider dataRow
77          */
78         public function testCreateFromTableRow(array $input, array $assertion)
79         {
80                 $factory = new Introduction(new NullLogger());
81
82                 $intro = $factory->createFromTableRow($input);
83                 $this->assertIntro($intro, $assertion);
84         }
85
86         /**
87          * @dataProvider dataRow
88          */
89         public function testCreateNew(array $input, array $assertion)
90         {
91                 $factory = new Introduction(new NullLogger());
92
93                 $intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
94
95                 $this->assertIntro($intro, [
96                         'uid'        => $input['uid'] ?? 0,
97                         'contact-id' => $input['cid'] ?? 0,
98                         'note'       => $input['note'] ?? '',
99                 ]);
100         }
101
102         /**
103          * @dataProvider dataRow
104          */
105         public function testCreateDummy(array $input, array $assertion)
106         {
107                 $factory = new Introduction(new NullLogger());
108
109                 $intro = $factory->createDummy($input['id'] ?? null);
110
111                 $this->assertIntro($intro, ['id' => $input['id'] ?? null]);
112         }
113 }