3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Contact\Introduction\Factory;
24 use Friendica\Contact\Introduction\Factory\Introduction;
25 use PHPUnit\Framework\TestCase;
26 use Psr\Log\NullLogger;
28 class IntroductionTest extends TestCase
30 public function dataRow()
41 'datetime' => '1970-01-01 00:00:00',
52 'datetime' => new \DateTime('1970-01-01 00:00:00', new \DateTimeZone('UTC')),
63 'suggest-cid' => null,
73 public function assertIntro(\Friendica\Contact\Introduction\Entity\Introduction $intro, array $assertion)
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']);
84 self::assertIsString($intro->hash);
86 if (isset($assertion['datetime'])) {
87 self::assertEquals($intro->datetime, $assertion['datetime']);
89 self::assertInstanceOf(\DateTime::class, $intro->datetime);
91 self::assertEquals($intro->ignore, $assertion['ignore'] ?? false);
95 * @dataProvider dataRow
97 public function testCreateFromTableRow(array $input, array $assertion)
99 $factory = new Introduction(new NullLogger());
101 $intro = $factory->createFromTableRow($input);
102 $this->assertIntro($intro, $assertion);
106 * @dataProvider dataRow
108 public function testCreateNew(array $input, array $assertion)
110 $factory = new Introduction(new NullLogger());
112 $intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
114 $this->assertIntro($intro, [
115 'uid' => $input['uid'] ?? 0,
116 'contact-id' => $input['cid'] ?? 0,
117 'note' => $input['note'] ?? '',
122 * @dataProvider dataRow
124 public function testCreateDummy(array $input, array $assertion)
126 $factory = new Introduction(new NullLogger());
128 $intro = $factory->createDummy($input['id'] ?? null);
130 $this->assertIntro($intro, ['id' => $input['id'] ?? null]);