]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/Twitter/ContactEndpointTest.php
Reenable Twitter/Search test
[friendica.git] / tests / src / Module / Api / Twitter / ContactEndpointTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Module\Api\Twitter;
23
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;
30
31 class ContactEndpointTest extends FixtureTest
32 {
33         public function testIds()
34         {
35                 /*
36                 $expectedEmpty = [
37                         'ids' => [],
38                         'next_cursor' => -1,
39                         'next_cursor_str' => '-1',
40                         'previous_cursor' => 0,
41                         'previous_cursor_str' => '0',
42                         'total_count' => 0,
43                 ];
44
45                 self::assertSame($expectedEmpty, ContactEndpointMock::ids(Contact::FOLLOWER, 42));
46
47                 $expectedFriend = [
48                         'ids' => [47],
49                         'next_cursor' => 0,
50                         'next_cursor_str' => '0',
51                         'previous_cursor' => 0,
52                         'previous_cursor_str' => '0',
53                         'total_count' => 1,
54                 ];
55
56                 self::assertSame($expectedFriend, ContactEndpointMock::ids(Contact::FRIEND, 42));
57                 self::assertSame($expectedFriend, ContactEndpointMock::ids([Contact::FOLLOWER, Contact::FRIEND], 42));
58
59                 $result = ContactEndpointMock::ids(Contact::SHARING, 42);
60
61                 self::assertArrayHasKey('ids', $result);
62                 self::assertContainsOnly('int', $result['ids']);
63                 self::assertSame(45, $result['ids'][0]);
64
65                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42);
66
67                 self::assertArrayHasKey('ids', $result);
68                 self::assertContainsOnly('int', $result['ids']);
69                 self::assertSame(45, $result['ids'][0]);
70                 */
71         }
72
73         /**
74          * @depends testIds
75          *
76          * @throws NotFoundException
77          */
78         public function testIdsStringify()
79         {
80                 /*
81                 $result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true);
82
83                 self::assertArrayHasKey('ids', $result);
84                 self::assertContainsOnly('string', $result['ids']);
85                 self::assertSame('45', $result['ids'][0]);
86                 */
87         }
88
89         public function testIdsPagination()
90         {
91                 /*
92                 $expectedDefaultPageResult = [
93                         'ids' => [45],
94                         'next_cursor' => 44,
95                         'next_cursor_str' => '44',
96                         'previous_cursor' => 0,
97                         'previous_cursor_str' => '0',
98                         'total_count' => 2,
99                 ];
100
101                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, -1, 1);
102
103                 self::assertSame($expectedDefaultPageResult, $result);
104
105                 $nextPageCursor = $result['next_cursor'];
106
107                 $expectedSecondPageResult = [
108                         'ids' => [47],
109                         'next_cursor' => 46,
110                         'next_cursor_str' => '46',
111                         'previous_cursor' => -46,
112                         'previous_cursor_str' => '-46',
113                         'total_count' => 2,
114                 ];
115
116                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $nextPageCursor, 1);
117
118                 self::assertSame($expectedSecondPageResult, $result);
119
120                 $firstPageCursor = $result['previous_cursor'];
121                 $emptyNextPageCursor = $result['next_cursor'];
122
123                 $expectedFirstPageResult = [
124                         'ids' => [45],
125                         'next_cursor' => 44,
126                         'next_cursor_str' => '44',
127                         'previous_cursor' => -44,
128                         'previous_cursor_str' => '-44',
129                         'total_count' => 2,
130                 ];
131
132                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $firstPageCursor, 1);
133
134                 self::assertSame($expectedFirstPageResult, $result);
135
136                 $emptyPrevPageCursor = $result['previous_cursor'];
137
138                 $expectedEmptyPrevPageResult = [
139                         'ids' => [],
140                         'next_cursor' => -1,
141                         'next_cursor_str' => '-1',
142                         'previous_cursor' => 0,
143                         'previous_cursor_str' => '0',
144                         'total_count' => 2,
145                 ];
146
147                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyPrevPageCursor, 1);
148
149                 self::assertSame($expectedEmptyPrevPageResult, $result);
150
151                 $expectedEmptyNextPageResult = [
152                         'ids' => [],
153                         'next_cursor' => 0,
154                         'next_cursor_str' => '0',
155                         'previous_cursor' => -46,
156                         'previous_cursor_str' => '-46',
157                         'total_count' => 2,
158                 ];
159
160                 $result = ContactEndpointMock::ids([Contact::SHARING, Contact::FRIEND], 42, $emptyNextPageCursor, 1);
161
162                 self::assertSame($expectedEmptyNextPageResult, $result);
163                 */
164         }
165
166         /**
167          * @depends testIds
168          *
169          * @throws NotFoundException
170          * @throws InternalServerErrorException
171          * @throws \ImagickException
172          */
173         public function testList()
174         {
175                 /*
176                 $expectedEmpty = [
177                         'users' => [],
178                         'next_cursor' => -1,
179                         'next_cursor_str' => '-1',
180                         'previous_cursor' => 0,
181                         'previous_cursor_str' => '0',
182                         'total_count' => 0,
183                 ];
184
185                 self::assertSame($expectedEmpty, ContactEndpointMock::list(Contact::FOLLOWER, 42));
186
187                 $expectedFriendContactUser = [
188                         'id' => 45,
189                         'id_str' => '45',
190                         'name' => 'Friend contact',
191                         'screen_name' => 'friendcontact',
192                         'location' => 'DFRN',
193                         'derived' => [],
194                         'url' => 'http://localhost/profile/friendcontact',
195                         'entities' => [
196                                 'url' => [
197                                         'urls' => [],
198                                 ],
199                                 'description' => [
200                                         'urls' => [],
201                                 ],
202                         ],
203                         'description' => '',
204                         'protected' => false,
205                         'verified' => true,
206                         'followers_count' => 0,
207                         'friends_count' => 0,
208                         'listed_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',
219                         'utc_offset' => 0,
220                         'time_zone' => 'UTC',
221                         'geo_enabled' => false,
222                         'lang' => NULL,
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,
230                         'uid' => 42,
231                         'cid' => 44,
232                         'pid' => 45,
233                         'self' => false,
234                         'network' => 'dfrn',
235                         'statusnet_profile_url' => 'http://localhost/profile/friendcontact',
236                 ];
237
238                 $result = ContactEndpointMock::list(Contact::SHARING, 42);
239
240                 self::assertArrayHasKey('users', $result);
241                 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
242                 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());
243
244                 $result = ContactEndpointMock::list([Contact::SHARING, Contact::FRIEND], 42);
245
246                 self::assertArrayHasKey('users', $result);
247                 self::assertContainsOnlyInstancesOf(User::class, $result['users']);
248                 self::assertSame($expectedFriendContactUser, $result['users'][0]->toArray());
249                 */
250         }
251 }