3 namespace Friendica\Test\src\Module\Api\Twitter;
5 use Friendica\Model\Contact;
6 use Friendica\Module\Api\Twitter\ContactEndpoint;
7 use Friendica\Network\HTTPException\InternalServerErrorException;
8 use Friendica\Network\HTTPException\NotFoundException;
9 use Friendica\Object\Api\Twitter\User;
10 use Friendica\Test\FixtureTest;
12 class ContactEndpointTest extends FixtureTest
14 public function testGetUid()
16 self::assertSame(42, ContactEndpointMock::getUid(42));
17 self::assertSame(42, ContactEndpointMock::getUid(null, 'selfcontact'));
18 self::assertSame(42, ContactEndpointMock::getUid(84, 'selfcontact'));
21 public function testGetUidContactIdNotFound()
23 $this->expectException(NotFoundException::class);
24 $this->expectExceptionMessage('Contact not found');
26 ContactEndpointMock::getUid(84);
29 public function testGetUidScreenNameNotFound()
31 $this->expectException(NotFoundException::class);
32 $this->expectExceptionMessage('User not found');
34 ContactEndpointMock::getUid(null, 'othercontact');
37 public function testGetUidContactIdScreenNameNotFound()
39 $this->expectException(NotFoundException::class);
40 $this->expectExceptionMessage('User not found');
42 ContactEndpointMock::getUid(42, 'othercontact');
45 public function testIds()
50 'next_cursor_str' => '-1',
51 'previous_cursor' => 0,
52 'previous_cursor_str' => '0',
56 self::assertSame($expectedEmpty, ContactEndpointMock::ids(Contact::FOLLOWER, 42));
61 'next_cursor_str' => '0',
62 'previous_cursor' => 0,
63 'previous_cursor_str' => '0',
67 self::assertSame($expectedFriend, ContactEndpointMock::ids(Contact::FRIEND, 42));
68 self::assertSame($expectedFriend, ContactEndpointMock::ids([Contact::FOLLOWER, Contact::FRIEND], 42));
70 $result = ContactEndpointMock::ids(Contact::SHARING, 42);
72 self::assertArrayHasKey('ids', $result);
73 self::assertContainsOnly('int', $result['ids']);
74 self::assertSame(45, $result['ids'][0]);
76 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42);
78 self::assertArrayHasKey('ids', $result);
79 self::assertContainsOnly('int', $result['ids']);
80 self::assertSame(45, $result['ids'][0]);
86 * @throws NotFoundException
88 public function testIdsStringify()
90 $result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true);
92 self::assertArrayHasKey('ids', $result);
93 self::assertContainsOnly('string', $result['ids']);
94 self::assertSame('45', $result['ids'][0]);
97 public function testIdsPagination()
99 $expectedDefaultPageResult = [
102 'next_cursor_str' => '44',
103 'previous_cursor' => 0,
104 'previous_cursor_str' => '0',
108 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, -1, 1);
110 self::assertSame($expectedDefaultPageResult, $result);
112 $nextPageCursor = $result['next_cursor'];
114 $expectedSecondPageResult = [
117 'next_cursor_str' => '46',
118 'previous_cursor' => -46,
119 'previous_cursor_str' => '-46',
123 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $nextPageCursor, 1);
125 self::assertSame($expectedSecondPageResult, $result);
127 $firstPageCursor = $result['previous_cursor'];
128 $emptyNextPageCursor = $result['next_cursor'];
130 $expectedFirstPageResult = [
133 'next_cursor_str' => '44',
134 'previous_cursor' => -44,
135 'previous_cursor_str' => '-44',
139 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $firstPageCursor, 1);
141 self::assertSame($expectedFirstPageResult, $result);
143 $emptyPrevPageCursor = $result['previous_cursor'];
145 $expectedEmptyPrevPageResult = [
148 'next_cursor_str' => '-1',
149 'previous_cursor' => 0,
150 'previous_cursor_str' => '0',
154 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyPrevPageCursor, 1);
156 self::assertSame($expectedEmptyPrevPageResult, $result);
158 $expectedEmptyNextPageResult = [
161 'next_cursor_str' => '0',
162 'previous_cursor' => -46,
163 'previous_cursor_str' => '-46',
167 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyNextPageCursor, 1);
169 self::assertSame($expectedEmptyNextPageResult, $result);
175 * @throws NotFoundException
176 * @throws InternalServerErrorException
177 * @throws \ImagickException
179 public function testList()
184 'next_cursor_str' => '-1',
185 'previous_cursor' => 0,
186 'previous_cursor_str' => '0',
190 self::assertSame($expectedEmpty, ContactEndpointMock::list(Contact::FOLLOWER, 42));
192 $expectedFriendContactUser = [
195 'name' => 'Friend contact',
196 'screen_name' => 'friendcontact',
197 'location' => 'DFRN',
199 'url' => 'http://localhost/profile/friendcontact',
209 'protected' => false,
211 'followers_count' => 0,
212 'friends_count' => 0,
214 'favourites_count' => 0,
215 'statuses_count' => 0,
216 'created_at' => 'Fri Feb 02 00:00:00 +0000 0000',
217 'profile_banner_url' => '',
218 'profile_image_url_https' => '',
219 'default_profile' => false,
220 'default_profile_image' => false,
221 'profile_image_url' => '',
222 'profile_image_url_profile_size' => '',
223 'profile_image_url_large' => '',
225 'time_zone' => 'UTC',
226 'geo_enabled' => false,
228 'contributors_enabled' => false,
229 'is_translator' => false,
230 'is_translation_enabled' => false,
231 'following' => false,
232 'follow_request_sent' => false,
233 'statusnet_blocking' => false,
234 'notifications' => false,
240 'statusnet_profile_url' => 'http://localhost/profile/friendcontact',
243 $result = ContactEndpointMock::list(Contact::SHARING, 42);
245 self::assertArrayHasKey('users', $result);
246 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
247 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());
249 $result = ContactEndpointMock::list([Contact::SHARING, Contact::FRIEND], 42);
251 self::assertArrayHasKey('users', $result);
252 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
253 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());