diff --git a/tests/src/Contact/FriendSuggest/Factory/FriendSuggestTest.php b/tests/src/Contact/FriendSuggest/Factory/FriendSuggestTest.php new file mode 100644 index 0000000000..86c956a838 --- /dev/null +++ b/tests/src/Contact/FriendSuggest/Factory/FriendSuggestTest.php @@ -0,0 +1,113 @@ + [ + 'input' => [ + 'uid' => 12, + 'cid' => 13, + 'name' => 'test', + 'url' => 'https://friendica.local/profile/test', + 'request' => 'https://friendica.local/dfrn_request/test', + 'photo' => 'https://friendica.local/photo/profile/test', + 'note' => 'a common note', + 'created' => '2021-10-12 12:23:00' + ], + 'assertion' => [ + 'uid' => 12, + 'cid' => 13, + 'name' => 'test', + 'url' => 'https://friendica.local/profile/test', + 'request' => 'https://friendica.local/dfrn_request/test', + 'photo' => 'https://friendica.local/photo/profile/test', + 'note' => 'a common note', + 'created' => new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')), + 'id' => null, + ], + ], + 'minimum' => [ + 'input' => [ + 'id' => 20, + ], + 'assertion' => [ + 'id' => 20, + ] + ], + 'full' => [ + 'input' => [ + 'uid' => 12, + 'cid' => 13, + 'name' => 'test', + 'url' => 'https://friendica.local/profile/test', + 'request' => 'https://friendica.local/dfrn_request/test', + 'photo' => 'https://friendica.local/photo/profile/test', + 'note' => 'a common note', + 'created' => '2021-10-12 12:23:00', + 'id' => 666, + ], + 'assertion' => [ + 'uid' => 12, + 'cid' => 13, + 'name' => 'test', + 'url' => 'https://friendica.local/profile/test', + 'request' => 'https://friendica.local/dfrn_request/test', + 'photo' => 'https://friendica.local/photo/profile/test', + 'note' => 'a common note', + 'created' => new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')), + 'id' => 666, + ], + ], + ]; + } + + public function assertFriendSuggest(Entity\FriendSuggest $friendSuggest, array $assertion) + { + self::assertEquals($assertion['id'] ?? null, $friendSuggest->id); + self::assertEquals($assertion['uid'] ?? 0, $friendSuggest->uid); + self::assertEquals($assertion['cid'] ?? 0, $friendSuggest->cid); + self::assertEquals($assertion['name'] ?? '', $friendSuggest->name); + self::assertEquals($assertion['url'] ?? '', $friendSuggest->url); + self::assertEquals($assertion['request'] ?? '', $friendSuggest->request); + self::assertEquals($assertion['photo'] ?? '', $friendSuggest->photo); + self::assertEquals($assertion['note'] ?? '', $friendSuggest->note); + if (empty($assertion['created'])) { + self::assertInstanceOf(\DateTime::class, $friendSuggest->created); + } else { + self::assertEquals($assertion['created'], $friendSuggest->created); + } + } + + public function testCreateNew() + { + $factory = new FriendSuggest(new VoidLogger()); + + $this->assertFriendSuggest($factory->createNew(12, 13), ['uid' => 12, 'cid' => 13]); + } + + /** + * @dataProvider dataCreate + */ + public function testCreateFromTableRow(array $input, array $assertion) + { + $factory = new FriendSuggest(new VoidLogger()); + + $this->assertFriendSuggest($factory->createFromTableRow($input), $assertion); + } + + public function testCreateEmpty() + { + $factory = new FriendSuggest(new VoidLogger()); + + $this->assertFriendSuggest($factory->createEmpty(66), ['id' => 66]); + } +}