3 * @copyright Copyright (C) 2010-2021, 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\Module\Api\Twitter;
24 use Friendica\Model\Contact;
25 use Friendica\Module\Api\Twitter\ContactEndpoint;
26 use Friendica\Network\HTTPException\InternalServerErrorException;
27 use Friendica\Network\HTTPException\NotFoundException;
28 use Friendica\Object\Api\Twitter\User;
29 use Friendica\Test\FixtureTest;
31 class ContactEndpointTest extends FixtureTest
33 public function testIds()
39 'next_cursor_str' => '-1',
40 'previous_cursor' => 0,
41 'previous_cursor_str' => '0',
45 self::assertSame($expectedEmpty, ContactEndpointMock::ids(Contact::FOLLOWER, 42));
50 'next_cursor_str' => '0',
51 'previous_cursor' => 0,
52 'previous_cursor_str' => '0',
56 self::assertSame($expectedFriend, ContactEndpointMock::ids(Contact::FRIEND, 42));
57 self::assertSame($expectedFriend, ContactEndpointMock::ids([Contact::FOLLOWER, Contact::FRIEND], 42));
59 $result = ContactEndpointMock::ids(Contact::SHARING, 42);
61 self::assertArrayHasKey('ids', $result);
62 self::assertContainsOnly('int', $result['ids']);
63 self::assertSame(45, $result['ids'][0]);
65 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42);
67 self::assertArrayHasKey('ids', $result);
68 self::assertContainsOnly('int', $result['ids']);
69 self::assertSame(45, $result['ids'][0]);
76 * @throws NotFoundException
78 public function testIdsStringify()
81 $result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true);
83 self::assertArrayHasKey('ids', $result);
84 self::assertContainsOnly('string', $result['ids']);
85 self::assertSame('45', $result['ids'][0]);
89 public function testIdsPagination()
92 $expectedDefaultPageResult = [
95 'next_cursor_str' => '44',
96 'previous_cursor' => 0,
97 'previous_cursor_str' => '0',
101 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, -1, 1);
103 self::assertSame($expectedDefaultPageResult, $result);
105 $nextPageCursor = $result['next_cursor'];
107 $expectedSecondPageResult = [
110 'next_cursor_str' => '46',
111 'previous_cursor' => -46,
112 'previous_cursor_str' => '-46',
116 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $nextPageCursor, 1);
118 self::assertSame($expectedSecondPageResult, $result);
120 $firstPageCursor = $result['previous_cursor'];
121 $emptyNextPageCursor = $result['next_cursor'];
123 $expectedFirstPageResult = [
126 'next_cursor_str' => '44',
127 'previous_cursor' => -44,
128 'previous_cursor_str' => '-44',
132 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $firstPageCursor, 1);
134 self::assertSame($expectedFirstPageResult, $result);
136 $emptyPrevPageCursor = $result['previous_cursor'];
138 $expectedEmptyPrevPageResult = [
141 'next_cursor_str' => '-1',
142 'previous_cursor' => 0,
143 'previous_cursor_str' => '0',
147 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyPrevPageCursor, 1);
149 self::assertSame($expectedEmptyPrevPageResult, $result);
151 $expectedEmptyNextPageResult = [
154 'next_cursor_str' => '0',
155 'previous_cursor' => -46,
156 'previous_cursor_str' => '-46',
160 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyNextPageCursor, 1);
162 self::assertSame($expectedEmptyNextPageResult, $result);
169 * @throws NotFoundException
170 * @throws InternalServerErrorException
171 * @throws \ImagickException
173 public function testList()
179 'next_cursor_str' => '-1',
180 'previous_cursor' => 0,
181 'previous_cursor_str' => '0',
185 self::assertSame($expectedEmpty, ContactEndpointMock::list(Contact::FOLLOWER, 42));
187 $expectedFriendContactUser = [
190 'name' => 'Friend contact',
191 'screen_name' => 'friendcontact',
192 'location' => 'DFRN',
194 'url' => 'http://localhost/profile/friendcontact',
204 'protected' => false,
206 'followers_count' => 0,
207 'friends_count' => 0,
209 'favourites_count' => 0,
210 'statuses_count' => 0,
211 'created_at' => 'Fri Feb 02 00:00:00 +0000 0000',
212 'profile_banner_url' => 'http://localhost/photo/header/44?ts=-62135596800',
213 'profile_image_url_https' => 'http://localhost/photo/contact/48/44?ts=-62135596800',
214 'default_profile' => false,
215 'default_profile_image' => false,
216 'profile_image_url' => 'http://localhost/photo/contact/48/44?ts=-62135596800',
217 'profile_image_url_profile_size' => 'http://localhost/photo/contact/80/44?ts=-62135596800',
218 'profile_image_url_large' => 'http://localhost/photo/contact/1024/44?ts=-62135596800',
220 'time_zone' => 'UTC',
221 'geo_enabled' => false,
223 'contributors_enabled' => false,
224 'is_translator' => false,
225 'is_translation_enabled' => false,
226 'following' => false,
227 'follow_request_sent' => false,
228 'statusnet_blocking' => false,
229 'notifications' => false,
235 'statusnet_profile_url' => 'http://localhost/profile/friendcontact',
238 $result = ContactEndpointMock::list(Contact::SHARING, 42);
240 self::assertArrayHasKey('users', $result);
241 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
242 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());
244 $result = ContactEndpointMock::list([Contact::SHARING, Contact::FRIEND], 42);
246 self::assertArrayHasKey('users', $result);
247 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
248 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());