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