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\NotFoundException;
8 use Friendica\Object\Api\Twitter\User;
9 use Friendica\Test\FixtureTest;
11 class ContactEndpointTest extends FixtureTest
13 public function testGetUid()
15 $this->assertSame(42, ContactEndpointMock::getUid(42));
16 $this->assertSame(42, ContactEndpointMock::getUid(null, 'selfcontact'));
17 $this->assertSame(42, ContactEndpointMock::getUid(84, 'selfcontact'));
20 public function testGetUidContactIdNotFound()
22 $this->expectException(NotFoundException::class);
23 $this->expectExceptionMessage('Contact not found');
25 ContactEndpointMock::getUid(84);
28 public function testGetUidScreenNameNotFound()
30 $this->expectException(NotFoundException::class);
31 $this->expectExceptionMessage('User not found');
33 ContactEndpointMock::getUid(null, 'othercontact');
36 public function testGetUidContactIdScreenNameNotFound()
38 $this->expectException(NotFoundException::class);
39 $this->expectExceptionMessage('User not found');
41 ContactEndpointMock::getUid(42, 'othercontact');
44 public function testIds()
49 'next_cursor_str' => '-1',
50 'previous_cursor' => 0,
51 'previous_cursor_str' => '0',
55 $this->assertSame($expectedEmpty, ContactEndpointMock::ids(Contact::FOLLOWER, 42));
60 'next_cursor_str' => '0',
61 'previous_cursor' => 0,
62 'previous_cursor_str' => '0',
66 $this->assertSame($expectedFriend, ContactEndpointMock::ids(Contact::FRIEND, 42));
67 $this->assertSame($expectedFriend, ContactEndpointMock::ids([Contact::FOLLOWER, Contact::FRIEND], 42));
69 $result = ContactEndpointMock::ids(Contact::SHARING, 42);
71 $this->assertArrayHasKey('ids', $result);
72 $this->assertContainsOnly('int', $result['ids']);
73 $this->assertSame(45, $result['ids'][0]);
75 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42);
77 $this->assertArrayHasKey('ids', $result);
78 $this->assertContainsOnly('int', $result['ids']);
79 $this->assertSame(45, $result['ids'][0]);
85 * @throws NotFoundException
87 public function testIdsStringify()
89 $result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true);
91 $this->assertArrayHasKey('ids', $result);
92 $this->assertContainsOnly('string', $result['ids']);
93 $this->assertSame('45', $result['ids'][0]);
96 public function testIdsPagination()
98 $expectedDefaultPageResult = [
101 'next_cursor_str' => '44',
102 'previous_cursor' => 0,
103 'previous_cursor_str' => '0',
107 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, -1, 1);
109 $this->assertSame($expectedDefaultPageResult, $result);
111 $nextPageCursor = $result['next_cursor'];
113 $expectedSecondPageResult = [
116 'next_cursor_str' => '46',
117 'previous_cursor' => -46,
118 'previous_cursor_str' => '-46',
122 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $nextPageCursor, 1);
124 $this->assertSame($expectedSecondPageResult, $result);
126 $firstPageCursor = $result['previous_cursor'];
127 $emptyNextPageCursor = $result['next_cursor'];
129 $expectedFirstPageResult = [
132 'next_cursor_str' => '44',
133 'previous_cursor' => -44,
134 'previous_cursor_str' => '-44',
138 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $firstPageCursor, 1);
140 $this->assertSame($expectedFirstPageResult, $result);
142 $emptyPrevPageCursor = $result['previous_cursor'];
144 $expectedEmptyPrevPageResult = [
147 'next_cursor_str' => '-1',
148 'previous_cursor' => 0,
149 'previous_cursor_str' => '0',
153 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyPrevPageCursor, 1);
155 $this->assertSame($expectedEmptyPrevPageResult, $result);
157 $expectedEmptyNextPageResult = [
160 'next_cursor_str' => '0',
161 'previous_cursor' => -46,
162 'previous_cursor_str' => '-46',
166 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyNextPageCursor, 1);
168 $this->assertSame($expectedEmptyNextPageResult, $result);
174 * @throws NotFoundException
175 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
176 * @throws \ImagickException
178 public function testList()
183 'next_cursor_str' => '-1',
184 'previous_cursor' => 0,
185 'previous_cursor_str' => '0',
189 $this->assertSame($expectedEmpty, ContactEndpointMock::list(Contact::FOLLOWER, 42));
191 $expectedFriendContactUser = [
194 'name' => 'Friend contact',
195 'screen_name' => 'friendcontact',
196 'location' => 'DFRN',
198 'url' => 'http://localhost/profile/friendcontact',
208 'protected' => false,
210 'followers_count' => 0,
211 'friends_count' => 0,
213 'favourites_count' => 0,
214 'statuses_count' => 0,
215 'created_at' => 'Fri Feb 02 00:00:00 +0000 0000',
216 'profile_banner_url' => '',
217 'profile_image_url_https' => '',
218 'default_profile' => false,
219 'default_profile_image' => false,
220 'profile_image_url' => '',
221 'profile_image_url_profile_size' => '',
222 'profile_image_url_large' => '',
224 'time_zone' => 'UTC',
225 'geo_enabled' => false,
227 'contributors_enabled' => false,
228 'is_translator' => false,
229 'is_translation_enabled' => false,
230 'following' => false,
231 'follow_request_sent' => false,
232 'statusnet_blocking' => false,
233 'notifications' => false,
239 'statusnet_profile_url' => 'http://localhost/profile/friendcontact',
242 $result = ContactEndpointMock::list(Contact::SHARING, 42);
244 $this->assertArrayHasKey('users', $result);
245 $this->assertContainsOnlyInstancesOf(User::class, $result['users']);
246 $this->assertSame($expectedFriendContactUser, $result['users'][0]->toArray());
248 $result = ContactEndpointMock::list([Contact::SHARING, Contact::FRIEND], 42);
250 $this->assertArrayHasKey('users', $result);
251 $this->assertContainsOnlyInstancesOf(User::class, $result['users']);
252 $this->assertSame($expectedFriendContactUser, $result['users'][0]->toArray());