]> git.mxchange.org Git - friendica.git/blob - tests/legacy/ApiTest.php
490fac7dd521da7f1695d756c671998ccf14bbc6
[friendica.git] / tests / legacy / ApiTest.php
1 <?php
2 /**
3  * ApiTest class.
4  */
5
6 namespace Friendica\Test\legacy;
7
8 use Friendica\App;
9 use Friendica\Core\Config\Capability\IManageConfigValues;
10 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
11 use Friendica\Core\Protocol;
12 use Friendica\DI;
13 use Friendica\Module\Api\ApiResponse;
14 use Friendica\Module\BaseApi;
15 use Friendica\Network\HTTPException;
16 use Friendica\Security\BasicAuth;
17 use Friendica\Test\FixtureTest;
18 use Friendica\Util\Arrays;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Temporal;
21 use Monolog\Handler\TestHandler;
22
23 require_once __DIR__ . '/../../include/api.php';
24
25 /**
26  * Tests for the API functions.
27  *
28  * Functions that use header() need to be tested in a separate process.
29  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
30  *
31  * @backupGlobals enabled
32  */
33 class ApiTest extends FixtureTest
34 {
35         /**
36          * @var TestHandler Can handle log-outputs
37          */
38         protected $logOutput;
39
40         /** @var array */
41         protected $selfUser;
42         /** @var array */
43         protected $friendUser;
44         /** @var array */
45         protected $otherUser;
46
47         protected $wrongUserId;
48
49         /** @var App */
50         protected $app;
51
52         /** @var IManageConfigValues */
53         protected $config;
54
55         /**
56          * Create variables used by tests.
57          */
58         protected function setUp() : void
59         {
60                 global $API, $called_api;
61                 $API = [];
62                 $called_api = [];
63
64                 parent::setUp();
65
66                 /** @var IManageConfigValues $config */
67                 $this->config = $this->dice->create(IManageConfigValues::class);
68
69                 $this->config->set('system', 'url', 'http://localhost');
70                 $this->config->set('system', 'hostname', 'localhost');
71                 $this->config->set('system', 'worker_dont_fork', true);
72
73                 // Default config
74                 $this->config->set('config', 'hostname', 'localhost');
75                 $this->config->set('system', 'throttle_limit_day', 100);
76                 $this->config->set('system', 'throttle_limit_week', 100);
77                 $this->config->set('system', 'throttle_limit_month', 100);
78                 $this->config->set('system', 'theme', 'system_theme');
79
80
81                 /** @var App app */
82                 $this->app = DI::app();
83
84                 DI::args()->setArgc(1);
85
86                 // User data that the test database is populated with
87                 $this->selfUser   = [
88                         'id'   => 42,
89                         'name' => 'Self contact',
90                         'nick' => 'selfcontact',
91                         'nurl' => 'http://localhost/profile/selfcontact'
92                 ];
93                 $this->friendUser = [
94                         'id'   => 44,
95                         'name' => 'Friend contact',
96                         'nick' => 'friendcontact',
97                         'nurl' => 'http://localhost/profile/friendcontact'
98                 ];
99                 $this->otherUser  = [
100                         'id'   => 43,
101                         'name' => 'othercontact',
102                         'nick' => 'othercontact',
103                         'nurl' => 'http://localhost/profile/othercontact'
104                 ];
105
106                 // User ID that we know is not in the database
107                 $this->wrongUserId = 666;
108
109                 DI::session()->start();
110
111                 // Most API require login so we force the session
112                 $_SESSION = [
113                         'authenticated' => true,
114                         'uid'           => $this->selfUser['id']
115                 ];
116                 BasicAuth::setCurrentUserID($this->selfUser['id']);
117         }
118
119         /**
120          * Assert that an user array contains expected keys.
121          *
122          * @param array $user User array
123          *
124          * @return void
125          */
126         private function assertSelfUser(array $user)
127         {
128                 self::assertEquals($this->selfUser['id'], $user['uid']);
129                 self::assertEquals($this->selfUser['id'], $user['cid']);
130                 self::assertEquals(1, $user['self']);
131                 self::assertEquals('DFRN', $user['location']);
132                 self::assertEquals($this->selfUser['name'], $user['name']);
133                 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
134                 self::assertEquals('dfrn', $user['network']);
135                 self::assertTrue($user['verified']);
136         }
137
138         /**
139          * Assert that an user array contains expected keys.
140          *
141          * @param array $user User array
142          *
143          * @return void
144          */
145         private function assertOtherUser(array $user = [])
146         {
147                 self::assertEquals($this->otherUser['id'], $user['id']);
148                 self::assertEquals($this->otherUser['id'], $user['id_str']);
149                 self::assertEquals(0, $user['self']);
150                 self::assertEquals($this->otherUser['name'], $user['name']);
151                 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
152                 self::assertFalse($user['verified']);
153         }
154
155         /**
156          * Assert that a status array contains expected keys.
157          *
158          * @param array $status Status array
159          *
160          * @return void
161          */
162         private function assertStatus(array $status = [])
163         {
164                 self::assertIsString($status['text'] ?? '');
165                 self::assertIsInt($status['id'] ?? '');
166                 // We could probably do more checks here.
167         }
168
169         /**
170          * Assert that a list array contains expected keys.
171          *
172          * @param array $list List array
173          *
174          * @return void
175          */
176         private function assertList(array $list = [])
177         {
178                 self::assertIsString($list['name']);
179                 self::assertIsInt($list['id']);
180                 self::assertIsString('string', $list['id_str']);
181                 self::assertContains($list['mode'], ['public', 'private']);
182                 // We could probably do more checks here.
183         }
184
185         /**
186          * Assert that the string is XML and contain the root element.
187          *
188          * @param string $result       XML string
189          * @param string $root_element Root element name
190          *
191          * @return void
192          */
193         private function assertXml($result = '', $root_element = '')
194         {
195                 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
196                 self::assertStringContainsString('<' . $root_element, $result);
197                 // We could probably do more checks here.
198         }
199
200         /**
201          * Get the path to a temporary empty PNG image.
202          *
203          * @return string Path
204          */
205         private function getTempImage()
206         {
207                 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
208                 file_put_contents(
209                         $tmpFile,
210                         base64_decode(
211                         // Empty 1x1 px PNG image
212                                 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
213                         )
214                 );
215
216                 return $tmpFile;
217         }
218
219         /**
220          * Test the api_user() function.
221          *
222          * @return void
223          */
224         public function testApiUser()
225         {
226                 self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
227         }
228
229         /**
230          * Test the api_user() function with an unallowed user.
231          *
232          * @return void
233          */
234         public function testApiUserWithUnallowedUser()
235         {
236                 // self::assertEquals(false, api_user());
237         }
238
239         /**
240          * Test the api_source() function.
241          *
242          * @return void
243          */
244         public function testApiSource()
245         {
246                 self::assertEquals('api', api_source());
247         }
248
249         /**
250          * Test the api_source() function with a Twidere user agent.
251          *
252          * @return void
253          */
254         public function testApiSourceWithTwidere()
255         {
256                 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
257                 self::assertEquals('Twidere', api_source());
258         }
259
260         /**
261          * Test the api_source() function with a GET parameter.
262          *
263          * @return void
264          */
265         public function testApiSourceWithGet()
266         {
267                 $_GET['source'] = 'source_name';
268                 self::assertEquals('source_name', api_source());
269         }
270
271         /**
272          * Test the api_date() function.
273          *
274          * @return void
275          */
276         public function testApiDate()
277         {
278                 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
279         }
280
281         /**
282          * Test the api_register_func() function.
283          *
284          * @return void
285          */
286         public function testApiRegisterFunc()
287         {
288                 global $API;
289                 self::assertNull(
290                         api_register_func(
291                                 'api_path',
292                                 function () {
293                                 },
294                                 true,
295                                 'method'
296                         )
297                 );
298                 self::assertTrue($API['api_path']['auth']);
299                 self::assertEquals('method', $API['api_path']['method']);
300                 self::assertTrue(is_callable($API['api_path']['func']));
301         }
302
303         /**
304          * Test the BasicAuth::getCurrentUserID() function without any login.
305          *
306          * @runInSeparateProcess
307          * @preserveGlobalState disabled
308          * @preserveGlobalState disabled
309          */
310         public function testApiLoginWithoutLogin()
311         {
312                 BasicAuth::setCurrentUserID();
313                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314                 BasicAuth::getCurrentUserID(true);
315         }
316
317         /**
318          * Test the BasicAuth::getCurrentUserID() function with a bad login.
319          *
320          * @runInSeparateProcess
321          * @preserveGlobalState disabled
322          * @preserveGlobalState disabled
323          */
324         public function testApiLoginWithBadLogin()
325         {
326                 BasicAuth::setCurrentUserID();
327                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
328                 $_SERVER['PHP_AUTH_USER'] = 'user@server';
329                 BasicAuth::getCurrentUserID(true);
330         }
331
332         /**
333          * Test the BasicAuth::getCurrentUserID() function with oAuth.
334          *
335          * @return void
336          */
337         public function testApiLoginWithOauth()
338         {
339                 $this->markTestIncomplete('Can we test this easily?');
340         }
341
342         /**
343          * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
344          *
345          * @return void
346          */
347         public function testApiLoginWithAddonAuth()
348         {
349                 $this->markTestIncomplete('Can we test this easily?');
350         }
351
352         /**
353          * Test the BasicAuth::getCurrentUserID() function with a correct login.
354          *
355          * @runInSeparateProcess
356          * @preserveGlobalState disabled
357          * @doesNotPerformAssertions
358          */
359         public function testApiLoginWithCorrectLogin()
360         {
361                 BasicAuth::setCurrentUserID();
362                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
363                 $_SERVER['PHP_AUTH_PW']   = 'password';
364                 BasicAuth::getCurrentUserID(true);
365         }
366
367         /**
368          * Test the BasicAuth::getCurrentUserID() function with a remote user.
369          *
370          * @runInSeparateProcess
371          * @preserveGlobalState disabled
372          */
373         public function testApiLoginWithRemoteUser()
374         {
375                 BasicAuth::setCurrentUserID();
376                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
377                 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
378                 BasicAuth::getCurrentUserID(true);
379         }
380
381         /**
382          * Test the api_call() function.
383          *
384          * @runInSeparateProcess
385          * @preserveGlobalState disabled
386          */
387         public function testApiCall()
388         {
389                 global $API;
390                 $API['api_path']           = [
391                         'method' => 'method',
392                         'func'   => function () {
393                                 return ['data' => ['some_data']];
394                         }
395                 ];
396                 $_SERVER['REQUEST_METHOD'] = 'method';
397                 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
398                 $_GET['callback']          = 'callback_name';
399
400                 $args = DI::args()->determine($_SERVER, $_GET);
401
402                 self::assertEquals(
403                         'callback_name(["some_data"])',
404                         api_call($this->app, $args)
405                 );
406         }
407
408         /**
409          * Test the api_call() function with the profiled enabled.
410          *
411          * @runInSeparateProcess
412          * @preserveGlobalState disabled
413          */
414         public function testApiCallWithProfiler()
415         {
416                 global $API;
417                 $API['api_path']           = [
418                         'method' => 'method',
419                         'func'   => function () {
420                                 return ['data' => ['some_data']];
421                         }
422                 ];
423
424                 $_SERVER['REQUEST_METHOD'] = 'method';
425                 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
426
427                 $args = DI::args()->determine($_SERVER, $_GET);
428
429                 $this->config->set('system', 'profiler', true);
430                 $this->config->set('rendertime', 'callstack', true);
431                 $this->app->callstack = [
432                         'database'       => ['some_function' => 200],
433                         'database_write' => ['some_function' => 200],
434                         'cache'          => ['some_function' => 200],
435                         'cache_write'    => ['some_function' => 200],
436                         'network'        => ['some_function' => 200]
437                 ];
438
439                 self::assertEquals(
440                         '["some_data"]',
441                         api_call($this->app, $args)
442                 );
443         }
444
445         /**
446          * Test the api_call() function with a JSON result.
447          *
448          * @runInSeparateProcess
449          * @preserveGlobalState disabled
450          */
451         public function testApiCallWithJson()
452         {
453                 global $API;
454                 $API['api_path']           = [
455                         'method' => 'method',
456                         'func'   => function () {
457                                 return ['data' => ['some_data']];
458                         }
459                 ];
460                 $_SERVER['REQUEST_METHOD'] = 'method';
461                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
462
463                 $args = DI::args()->determine($_SERVER, $_GET);
464
465                 self::assertEquals(
466                         '["some_data"]',
467                         api_call($this->app, $args)
468                 );
469         }
470
471         /**
472          * Test the api_call() function with an XML result.
473          *
474          * @runInSeparateProcess
475          * @preserveGlobalState disabled
476          */
477         public function testApiCallWithXml()
478         {
479                 global $API;
480                 $API['api_path']           = [
481                         'method' => 'method',
482                         'func'   => function () {
483                                 return 'some_data';
484                         }
485                 ];
486                 $_SERVER['REQUEST_METHOD'] = 'method';
487                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
488
489                 $args = DI::args()->determine($_SERVER, $_GET);
490
491                 self::assertEquals(
492                         'some_data',
493                         api_call($this->app, $args)
494                 );
495         }
496
497         /**
498          * Test the api_call() function with an RSS result.
499          *
500          * @runInSeparateProcess
501          * @preserveGlobalState disabled
502          */
503         public function testApiCallWithRss()
504         {
505                 global $API;
506                 $API['api_path']           = [
507                         'method' => 'method',
508                         'func'   => function () {
509                                 return 'some_data';
510                         }
511                 ];
512                 $_SERVER['REQUEST_METHOD'] = 'method';
513                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
514
515                 $args = DI::args()->determine($_SERVER, $_GET);
516
517                 self::assertEquals(
518                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
519                         'some_data',
520                         api_call($this->app, $args)
521                 );
522         }
523
524         /**
525          * Test the api_call() function with an Atom result.
526          *
527          * @runInSeparateProcess
528          * @preserveGlobalState disabled
529          */
530         public function testApiCallWithAtom()
531         {
532                 global $API;
533                 $API['api_path']           = [
534                         'method' => 'method',
535                         'func'   => function () {
536                                 return 'some_data';
537                         }
538                 ];
539                 $_SERVER['REQUEST_METHOD'] = 'method';
540                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
541
542                 $args = DI::args()->determine($_SERVER, $_GET);
543
544                 self::assertEquals(
545                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
546                         'some_data',
547                         api_call($this->app, $args)
548                 );
549         }
550
551         /**
552          * Test the api_rss_extra() function.
553          *
554          * @return void
555          */
556         public function testApiRssExtra()
557         {
558                 $user_info = ['url' => 'user_url', 'lang' => 'en'];
559                 $result    = api_rss_extra([], $user_info);
560                 self::assertEquals($user_info, $result['$user']);
561                 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
562                 self::assertArrayHasKey('self', $result['$rss']);
563                 self::assertArrayHasKey('base', $result['$rss']);
564                 self::assertArrayHasKey('updated', $result['$rss']);
565                 self::assertArrayHasKey('atom_updated', $result['$rss']);
566                 self::assertArrayHasKey('language', $result['$rss']);
567                 self::assertArrayHasKey('logo', $result['$rss']);
568         }
569
570         /**
571          * Test the api_rss_extra() function without any user info.
572          *
573          * @return void
574          */
575         public function testApiRssExtraWithoutUserInfo()
576         {
577                 $result = api_rss_extra([], null);
578                 self::assertIsArray($result['$user']);
579                 self::assertArrayHasKey('alternate', $result['$rss']);
580                 self::assertArrayHasKey('self', $result['$rss']);
581                 self::assertArrayHasKey('base', $result['$rss']);
582                 self::assertArrayHasKey('updated', $result['$rss']);
583                 self::assertArrayHasKey('atom_updated', $result['$rss']);
584                 self::assertArrayHasKey('language', $result['$rss']);
585                 self::assertArrayHasKey('logo', $result['$rss']);
586         }
587
588         /**
589          * Test the api_unique_id_to_nurl() function.
590          *
591          * @return void
592          */
593         public function testApiUniqueIdToNurl()
594         {
595                 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
596         }
597
598         /**
599          * Test the api_unique_id_to_nurl() function with a correct ID.
600          *
601          * @return void
602          */
603         public function testApiUniqueIdToNurlWithCorrectId()
604         {
605                 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
606         }
607
608         /**
609          * Test the api_get_user() function.
610          *
611          * @return void
612          */
613         public function testApiGetUser()
614         {
615                 // $user = api_get_user();
616                 // self::assertSelfUser($user);
617                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
618                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
619                 // self::assertEquals('ededed', $user['profile_background_color']);
620         }
621
622         /**
623          * Test the api_get_user() function with a Frio schema.
624          *
625          * @return void
626          */
627         public function testApiGetUserWithFrioSchema()
628         {
629                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
630                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
631                 // $user = api_get_user();
632                 // self::assertSelfUser($user);
633                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
634                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
635                 // self::assertEquals('ededed', $user['profile_background_color']);
636         }
637
638         /**
639          * Test the api_get_user() function with an empty Frio schema.
640          *
641          * @return void
642          */
643         public function testApiGetUserWithEmptyFrioSchema()
644         {
645                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
646                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
647                 // $user = api_get_user();
648                 // self::assertSelfUser($user);
649                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
650                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
651                 // self::assertEquals('ededed', $user['profile_background_color']);
652         }
653
654         /**
655          * Test the api_get_user() function with a custom Frio schema.
656          *
657          * @return void
658          */
659         public function testApiGetUserWithCustomFrioSchema()
660         {
661                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
662                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
663                 // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
664                 // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
665                 // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
666                 // $user = api_get_user();
667                 // self::assertSelfUser($user);
668                 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
669                 // self::assertEquals('123456', $user['profile_link_color']);
670                 // self::assertEquals('123456', $user['profile_background_color']);
671         }
672
673         /**
674          * Test the api_get_user() function with an user that is not allowed to use the API.
675          *
676          * @runInSeparateProcess
677          * @preserveGlobalState disabled
678          */
679         public function testApiGetUserWithoutApiUser()
680         {
681                 // api_get_user() with empty parameters is not used anymore
682                 /*
683                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
684                 $_SERVER['PHP_AUTH_PW']   = 'password';
685                 BasicAuth::setCurrentUserID();
686                 self::assertFalse(api_get_user());
687                 */
688         }
689
690         /**
691          * Test the api_get_user() function with an user ID in a GET parameter.
692          *
693          * @return void
694          */
695         public function testApiGetUserWithGetId()
696         {
697                 // self::assertOtherUser(api_get_user());
698         }
699
700         /**
701          * Test the api_get_user() function with a wrong user ID in a GET parameter.
702          *
703          * @return void
704          */
705         public function testApiGetUserWithWrongGetId()
706         {
707                 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
708                 // self::assertOtherUser(api_get_user());
709         }
710
711         /**
712          * Test the api_get_user() function with an user name in a GET parameter.
713          *
714          * @return void
715          */
716         public function testApiGetUserWithGetName()
717         {
718                 // self::assertSelfUser(api_get_user());
719         }
720
721         /**
722          * Test the api_get_user() function with a profile URL in a GET parameter.
723          *
724          * @return void
725          */
726         public function testApiGetUserWithGetUrl()
727         {
728                 // self::assertSelfUser(api_get_user());
729         }
730
731         /**
732          * Test the api_get_user() function with an user ID in the API path.
733          *
734          * @return void
735          */
736         public function testApiGetUserWithNumericCalledApi()
737         {
738                 // global $called_api;
739                 // $called_api         = ['api_path'];
740                 // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
741                 // self::assertOtherUser(api_get_user());
742         }
743
744         /**
745          * Test the api_get_user() function with the $called_api global variable.
746          *
747          * @return void
748          */
749         public function testApiGetUserWithCalledApi()
750         {
751                 // global $called_api;
752                 // $called_api = ['api', 'api_path'];
753                 // self::assertSelfUser(api_get_user());
754         }
755
756         /**
757          * Test the api_get_user() function with a 0 user ID.
758          *
759          * @return void
760          */
761         public function testApiGetUserWithZeroUser()
762         {
763                 self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
764         }
765
766         /**
767          * Test the Arrays::walkRecursive() function.
768          *
769          * @return void
770          */
771         public function testApiWalkRecursive()
772         {
773                 $array = ['item1'];
774                 self::assertEquals(
775                         $array,
776                         Arrays::walkRecursive(
777                                 $array,
778                                 function () {
779                                         // Should we test this with a callback that actually does something?
780                                         return true;
781                                 }
782                         )
783                 );
784         }
785
786         /**
787          * Test the Arrays::walkRecursive() function with an array.
788          *
789          * @return void
790          */
791         public function testApiWalkRecursiveWithArray()
792         {
793                 $array = [['item1'], ['item2']];
794                 self::assertEquals(
795                         $array,
796                         Arrays::walkRecursive(
797                                 $array,
798                                 function () {
799                                         // Should we test this with a callback that actually does something?
800                                         return true;
801                                 }
802                         )
803                 );
804         }
805
806         /**
807          * Test the BaseApi::reformatXML() function.
808          *
809          * @return void
810          */
811         public function testApiReformatXml()
812         {
813                 $item = true;
814                 $key  = '';
815                 self::assertTrue(ApiResponse::reformatXML($item, $key));
816                 self::assertEquals('true', $item);
817         }
818
819         /**
820          * Test the BaseApi::reformatXML() function with a statusnet_api key.
821          *
822          * @return void
823          */
824         public function testApiReformatXmlWithStatusnetKey()
825         {
826                 $item = '';
827                 $key  = 'statusnet_api';
828                 self::assertTrue(ApiResponse::reformatXML($item, $key));
829                 self::assertEquals('statusnet:api', $key);
830         }
831
832         /**
833          * Test the BaseApi::reformatXML() function with a friendica_api key.
834          *
835          * @return void
836          */
837         public function testApiReformatXmlWithFriendicaKey()
838         {
839                 $item = '';
840                 $key  = 'friendica_api';
841                 self::assertTrue(ApiResponse::reformatXML($item, $key));
842                 self::assertEquals('friendica:api', $key);
843         }
844
845         /**
846          * Test the BaseApi::createXML() function.
847          *
848          * @return void
849          */
850         public function testApiCreateXml()
851         {
852                 self::assertEquals(
853                         '<?xml version="1.0"?>' . "\n" .
854                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
855                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
856                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
857                         '  <data>some_data</data>' . "\n" .
858                         '</root_element>' . "\n",
859                         DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
860                 );
861         }
862
863         /**
864          * Test the BaseApi::createXML() function without any XML namespace.
865          *
866          * @return void
867          */
868         public function testApiCreateXmlWithoutNamespaces()
869         {
870                 self::assertEquals(
871                         '<?xml version="1.0"?>' . "\n" .
872                         '<ok>' . "\n" .
873                         '  <data>some_data</data>' . "\n" .
874                         '</ok>' . "\n",
875                         DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
876                 );
877         }
878
879         /**
880          * Test the BaseApi::formatData() function.
881          *
882          * @return void
883          */
884         public function testApiFormatData()
885         {
886                 $data = ['some_data'];
887                 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
888         }
889
890         /**
891          * Test the BaseApi::formatData() function with an XML result.
892          *
893          * @return void
894          */
895         public function testApiFormatDataWithXml()
896         {
897                 self::assertEquals(
898                         '<?xml version="1.0"?>' . "\n" .
899                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
900                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
901                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
902                         '  <data>some_data</data>' . "\n" .
903                         '</root_element>' . "\n",
904                         DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
905                 );
906         }
907
908         /**
909          * Test the api_account_verify_credentials() function.
910          *
911          * @return void
912          */
913         public function testApiAccountVerifyCredentials()
914         {
915                 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
916         }
917
918         /**
919          * Test the api_account_verify_credentials() function without an authenticated user.
920          *
921          * @return void
922          */
923         public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
924         {
925                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
926                 BasicAuth::setCurrentUserID();
927                 $_SESSION['authenticated'] = false;
928                 api_account_verify_credentials('json');
929         }
930
931         /**
932          * Test the requestdata() function.
933          *
934          * @return void
935          */
936         public function testRequestdata()
937         {
938                 self::assertNull(requestdata('variable_name'));
939         }
940
941         /**
942          * Test the requestdata() function with a POST parameter.
943          *
944          * @return void
945          */
946         public function testRequestdataWithPost()
947         {
948                 $_POST['variable_name'] = 'variable_value';
949                 self::assertEquals('variable_value', requestdata('variable_name'));
950         }
951
952         /**
953          * Test the requestdata() function with a GET parameter.
954          *
955          * @return void
956          */
957         public function testRequestdataWithGet()
958         {
959                 $_GET['variable_name'] = 'variable_value';
960                 self::assertEquals('variable_value', requestdata('variable_name'));
961         }
962
963         /**
964          * Test the api_statuses_mediap() function.
965          *
966          * @return void
967          */
968         public function testApiStatusesMediap()
969         {
970                 DI::args()->setArgc(2);
971
972                 $_FILES         = [
973                         'media' => [
974                                 'id'       => 666,
975                                 'size'     => 666,
976                                 'width'    => 666,
977                                 'height'   => 666,
978                                 'tmp_name' => $this->getTempImage(),
979                                 'name'     => 'spacer.png',
980                                 'type'     => 'image/png'
981                         ]
982                 ];
983                 $_GET['status'] = '<b>Status content</b>';
984
985                 $result = api_statuses_mediap('json');
986                 self::assertStatus($result['status']);
987         }
988
989         /**
990          * Test the api_statuses_mediap() function without an authenticated user.
991          *
992          * @return void
993          */
994         public function testApiStatusesMediapWithoutAuthenticatedUser()
995         {
996                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
997                 BasicAuth::setCurrentUserID();
998                 $_SESSION['authenticated'] = false;
999                 api_statuses_mediap('json');
1000         }
1001
1002         /**
1003          * Test the api_statuses_update() function.
1004          *
1005          * @return void
1006          */
1007         public function testApiStatusesUpdate()
1008         {
1009                 $_GET['status']                = 'Status content #friendica';
1010                 $_GET['in_reply_to_status_id'] = -1;
1011                 $_GET['lat']                   = 48;
1012                 $_GET['long']                  = 7;
1013                 $_FILES                        = [
1014                         'media' => [
1015                                 'id'       => 666,
1016                                 'size'     => 666,
1017                                 'width'    => 666,
1018                                 'height'   => 666,
1019                                 'tmp_name' => $this->getTempImage(),
1020                                 'name'     => 'spacer.png',
1021                                 'type'     => 'image/png'
1022                         ]
1023                 ];
1024
1025                 $result = api_statuses_update('json');
1026                 self::assertStatus($result['status']);
1027         }
1028
1029         /**
1030          * Test the api_statuses_update() function with an HTML status.
1031          *
1032          * @return void
1033          */
1034         public function testApiStatusesUpdateWithHtml()
1035         {
1036                 $_GET['htmlstatus'] = '<b>Status content</b>';
1037
1038                 $result = api_statuses_update('json');
1039                 self::assertStatus($result['status']);
1040         }
1041
1042         /**
1043          * Test the api_statuses_update() function without an authenticated user.
1044          *
1045          * @return void
1046          */
1047         public function testApiStatusesUpdateWithoutAuthenticatedUser()
1048         {
1049                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1050                 BasicAuth::setCurrentUserID();
1051                 $_SESSION['authenticated'] = false;
1052                 api_statuses_update('json');
1053         }
1054
1055         /**
1056          * Test the api_statuses_update() function with a parent status.
1057          *
1058          * @return void
1059          */
1060         public function testApiStatusesUpdateWithParent()
1061         {
1062                 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1063         }
1064
1065         /**
1066          * Test the api_statuses_update() function with a media_ids parameter.
1067          *
1068          * @return void
1069          */
1070         public function testApiStatusesUpdateWithMediaIds()
1071         {
1072                 $this->markTestIncomplete();
1073         }
1074
1075         /**
1076          * Test the api_statuses_update() function with the throttle limit reached.
1077          *
1078          * @return void
1079          */
1080         public function testApiStatusesUpdateWithDayThrottleReached()
1081         {
1082                 $this->markTestIncomplete();
1083         }
1084
1085         /**
1086          * Test the api_media_upload() function.
1087          * @runInSeparateProcess
1088          * @preserveGlobalState disabled
1089          */
1090         public function testApiMediaUpload()
1091         {
1092                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1093                 api_media_upload();
1094         }
1095
1096         /**
1097          * Test the api_media_upload() function without an authenticated user.
1098          *
1099          * @return void
1100          */
1101         public function testApiMediaUploadWithoutAuthenticatedUser()
1102         {
1103                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1104                 BasicAuth::setCurrentUserID();
1105                 $_SESSION['authenticated'] = false;
1106                 api_media_upload();
1107         }
1108
1109         /**
1110          * Test the api_media_upload() function with an invalid uploaded media.
1111          *
1112          * @return void
1113          */
1114         public function testApiMediaUploadWithMedia()
1115         {
1116                 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1117                 $_FILES = [
1118                         'media' => [
1119                                 'id'       => 666,
1120                                 'tmp_name' => 'tmp_name'
1121                         ]
1122                 ];
1123                 api_media_upload();
1124         }
1125
1126         /**
1127          * Test the api_media_upload() function with an valid uploaded media.
1128          *
1129          * @return void
1130          */
1131         public function testApiMediaUploadWithValidMedia()
1132         {
1133                 $_FILES    = [
1134                         'media' => [
1135                                 'id'       => 666,
1136                                 'size'     => 666,
1137                                 'width'    => 666,
1138                                 'height'   => 666,
1139                                 'tmp_name' => $this->getTempImage(),
1140                                 'name'     => 'spacer.png',
1141                                 'type'     => 'image/png'
1142                         ]
1143                 ];
1144                 $app       = DI::app();
1145                 DI::args()->setArgc(2);
1146
1147                 $result = api_media_upload();
1148                 self::assertEquals('image/png', $result['media']['image']['image_type']);
1149                 self::assertEquals(1, $result['media']['image']['w']);
1150                 self::assertEquals(1, $result['media']['image']['h']);
1151                 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1152         }
1153
1154         /**
1155          * Test the api_status_show() function.
1156          */
1157         public function testApiStatusShowWithJson()
1158         {
1159                 $result = api_status_show('json', 1);
1160                 self::assertStatus($result['status']);
1161         }
1162
1163         /**
1164          * Test the api_status_show() function with an XML result.
1165          */
1166         public function testApiStatusShowWithXml()
1167         {
1168                 $result = api_status_show('xml', 1);
1169                 self::assertXml($result, 'statuses');
1170         }
1171
1172         /**
1173          * Test the api_get_last_status() function
1174          */
1175         public function testApiGetLastStatus()
1176         {
1177                 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1178
1179                 self::assertNotNull($item);
1180         }
1181
1182         /**
1183          * Test the api_users_show() function.
1184          *
1185          * @return void
1186          */
1187         public function testApiUsersShow()
1188         {
1189                 $result = api_users_show('json');
1190                 // We can't use assertSelfUser() here because the user object is missing some properties.
1191                 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1192                 self::assertEquals('DFRN', $result['user']['location']);
1193                 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1194                 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1195                 self::assertEquals('dfrn', $result['user']['network']);
1196                 self::assertTrue($result['user']['verified']);
1197         }
1198
1199         /**
1200          * Test the api_users_show() function with an XML result.
1201          *
1202          * @return void
1203          */
1204         public function testApiUsersShowWithXml()
1205         {
1206                 $result = api_users_show('xml');
1207                 self::assertXml($result, 'statuses');
1208         }
1209
1210         /**
1211          * Test the api_users_search() function.
1212          *
1213          * @return void
1214          */
1215         public function testApiUsersSearch()
1216         {
1217                 $_GET['q'] = 'othercontact';
1218                 $result    = api_users_search('json');
1219                 self::assertOtherUser($result['users'][0]);
1220         }
1221
1222         /**
1223          * Test the api_users_search() function with an XML result.
1224          *
1225          * @return void
1226          */
1227         public function testApiUsersSearchWithXml()
1228         {
1229                 $_GET['q'] = 'othercontact';
1230                 $result    = api_users_search('xml');
1231                 self::assertXml($result, 'users');
1232         }
1233
1234         /**
1235          * Test the api_users_search() function without a GET q parameter.
1236          *
1237          * @return void
1238          */
1239         public function testApiUsersSearchWithoutQuery()
1240         {
1241                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1242                 api_users_search('json');
1243         }
1244
1245         /**
1246          * Test the api_users_lookup() function.
1247          *
1248          * @return void
1249          */
1250         public function testApiUsersLookup()
1251         {
1252                 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1253                 api_users_lookup('json');
1254         }
1255
1256         /**
1257          * Test the api_users_lookup() function with an user ID.
1258          *
1259          * @return void
1260          */
1261         public function testApiUsersLookupWithUserId()
1262         {
1263                 $_REQUEST['user_id'] = $this->otherUser['id'];
1264                 $result              = api_users_lookup('json');
1265                 self::assertOtherUser($result['users'][0]);
1266         }
1267
1268         /**
1269          * Test the api_search() function.
1270          *
1271          * @return void
1272          */
1273         public function testApiSearch()
1274         {
1275                 $_REQUEST['q']      = 'reply';
1276                 $_REQUEST['max_id'] = 10;
1277                 $result             = api_search('json');
1278                 foreach ($result['status'] as $status) {
1279                         self::assertStatus($status);
1280                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1281                 }
1282         }
1283
1284         /**
1285          * Test the api_search() function a count parameter.
1286          *
1287          * @return void
1288          */
1289         public function testApiSearchWithCount()
1290         {
1291                 $_REQUEST['q']     = 'reply';
1292                 $_REQUEST['count'] = 20;
1293                 $result            = api_search('json');
1294                 foreach ($result['status'] as $status) {
1295                         self::assertStatus($status);
1296                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1297                 }
1298         }
1299
1300         /**
1301          * Test the api_search() function with an rpp parameter.
1302          *
1303          * @return void
1304          */
1305         public function testApiSearchWithRpp()
1306         {
1307                 $_REQUEST['q']   = 'reply';
1308                 $_REQUEST['rpp'] = 20;
1309                 $result          = api_search('json');
1310                 foreach ($result['status'] as $status) {
1311                         self::assertStatus($status);
1312                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1313                 }
1314         }
1315
1316         /**
1317          * Test the api_search() function with an q parameter contains hashtag.
1318          * @doesNotPerformAssertions
1319          */
1320         public function testApiSearchWithHashtag()
1321         {
1322                 $_REQUEST['q'] = '%23friendica';
1323                 $result        = api_search('json');
1324                 foreach ($result['status'] as $status) {
1325                         self::assertStatus($status);
1326                         self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1327                 }
1328         }
1329
1330         /**
1331          * Test the api_search() function with an exclude_replies parameter.
1332          * @doesNotPerformAssertions
1333          */
1334         public function testApiSearchWithExcludeReplies()
1335         {
1336                 $_REQUEST['max_id']          = 10;
1337                 $_REQUEST['exclude_replies'] = true;
1338                 $_REQUEST['q']               = 'friendica';
1339                 $result                      = api_search('json');
1340                 foreach ($result['status'] as $status) {
1341                         self::assertStatus($status);
1342                 }
1343         }
1344
1345         /**
1346          * Test the api_search() function without an authenticated user.
1347          *
1348          * @return void
1349          */
1350         public function testApiSearchWithUnallowedUser()
1351         {
1352                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1353                 BasicAuth::setCurrentUserID();
1354                 api_search('json');
1355         }
1356
1357         /**
1358          * Test the api_search() function without any GET query parameter.
1359          *
1360          * @return void
1361          */
1362         public function testApiSearchWithoutQuery()
1363         {
1364                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1365                 api_search('json');
1366         }
1367
1368         /**
1369          * Test the api_statuses_home_timeline() function.
1370          *
1371          * @return void
1372          */
1373         public function testApiStatusesHomeTimeline()
1374         {
1375                 $_REQUEST['max_id']          = 10;
1376                 $_REQUEST['exclude_replies'] = true;
1377                 $_REQUEST['conversation_id'] = 1;
1378                 $result                      = api_statuses_home_timeline('json');
1379                 self::assertNotEmpty($result['status']);
1380                 foreach ($result['status'] as $status) {
1381                         self::assertStatus($status);
1382                 }
1383         }
1384
1385         /**
1386          * Test the api_statuses_home_timeline() function with a negative page parameter.
1387          *
1388          * @return void
1389          */
1390         public function testApiStatusesHomeTimelineWithNegativePage()
1391         {
1392                 $_REQUEST['page'] = -2;
1393                 $result           = api_statuses_home_timeline('json');
1394                 self::assertNotEmpty($result['status']);
1395                 foreach ($result['status'] as $status) {
1396                         self::assertStatus($status);
1397                 }
1398         }
1399
1400         /**
1401          * Test the api_statuses_home_timeline() with an unallowed user.
1402          *
1403          * @return void
1404          */
1405         public function testApiStatusesHomeTimelineWithUnallowedUser()
1406         {
1407                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1408                 BasicAuth::setCurrentUserID();
1409                 api_statuses_home_timeline('json');
1410         }
1411
1412         /**
1413          * Test the api_statuses_home_timeline() function with an RSS result.
1414          *
1415          * @return void
1416          */
1417         public function testApiStatusesHomeTimelineWithRss()
1418         {
1419                 $result = api_statuses_home_timeline('rss');
1420                 self::assertXml($result, 'statuses');
1421         }
1422
1423         /**
1424          * Test the api_statuses_public_timeline() function.
1425          *
1426          * @return void
1427          */
1428         public function testApiStatusesPublicTimeline()
1429         {
1430                 $_REQUEST['max_id']          = 10;
1431                 $_REQUEST['conversation_id'] = 1;
1432                 $result                      = api_statuses_public_timeline('json');
1433                 self::assertNotEmpty($result['status']);
1434                 foreach ($result['status'] as $status) {
1435                         self::assertStatus($status);
1436                 }
1437         }
1438
1439         /**
1440          * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1441          *
1442          * @return void
1443          */
1444         public function testApiStatusesPublicTimelineWithExcludeReplies()
1445         {
1446                 $_REQUEST['max_id']          = 10;
1447                 $_REQUEST['exclude_replies'] = true;
1448                 $result                      = api_statuses_public_timeline('json');
1449                 self::assertNotEmpty($result['status']);
1450                 foreach ($result['status'] as $status) {
1451                         self::assertStatus($status);
1452                 }
1453         }
1454
1455         /**
1456          * Test the api_statuses_public_timeline() function with a negative page parameter.
1457          *
1458          * @return void
1459          */
1460         public function testApiStatusesPublicTimelineWithNegativePage()
1461         {
1462                 $_REQUEST['page'] = -2;
1463                 $result           = api_statuses_public_timeline('json');
1464                 self::assertNotEmpty($result['status']);
1465                 foreach ($result['status'] as $status) {
1466                         self::assertStatus($status);
1467                 }
1468         }
1469
1470         /**
1471          * Test the api_statuses_public_timeline() function with an unallowed user.
1472          *
1473          * @return void
1474          */
1475         public function testApiStatusesPublicTimelineWithUnallowedUser()
1476         {
1477                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1478                 BasicAuth::setCurrentUserID();
1479                 api_statuses_public_timeline('json');
1480         }
1481
1482         /**
1483          * Test the api_statuses_public_timeline() function with an RSS result.
1484          *
1485          * @return void
1486          */
1487         public function testApiStatusesPublicTimelineWithRss()
1488         {
1489                 $result = api_statuses_public_timeline('rss');
1490                 self::assertXml($result, 'statuses');
1491         }
1492
1493         /**
1494          * Test the api_statuses_networkpublic_timeline() function.
1495          *
1496          * @return void
1497          */
1498         public function testApiStatusesNetworkpublicTimeline()
1499         {
1500                 $_REQUEST['max_id'] = 10;
1501                 $result             = api_statuses_networkpublic_timeline('json');
1502                 self::assertNotEmpty($result['status']);
1503                 foreach ($result['status'] as $status) {
1504                         self::assertStatus($status);
1505                 }
1506         }
1507
1508         /**
1509          * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1510          *
1511          * @return void
1512          */
1513         public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1514         {
1515                 $_REQUEST['page'] = -2;
1516                 $result           = api_statuses_networkpublic_timeline('json');
1517                 self::assertNotEmpty($result['status']);
1518                 foreach ($result['status'] as $status) {
1519                         self::assertStatus($status);
1520                 }
1521         }
1522
1523         /**
1524          * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1525          *
1526          * @return void
1527          */
1528         public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1529         {
1530                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1531                 BasicAuth::setCurrentUserID();
1532                 api_statuses_networkpublic_timeline('json');
1533         }
1534
1535         /**
1536          * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1537          *
1538          * @return void
1539          */
1540         public function testApiStatusesNetworkpublicTimelineWithRss()
1541         {
1542                 $result = api_statuses_networkpublic_timeline('rss');
1543                 self::assertXml($result, 'statuses');
1544         }
1545
1546         /**
1547          * Test the api_statuses_show() function.
1548          *
1549          * @return void
1550          */
1551         public function testApiStatusesShow()
1552         {
1553                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1554                 api_statuses_show('json');
1555         }
1556
1557         /**
1558          * Test the api_statuses_show() function with an ID.
1559          *
1560          * @return void
1561          */
1562         public function testApiStatusesShowWithId()
1563         {
1564                 DI::args()->setArgv(['', '', '', 1]);
1565                 $result = api_statuses_show('json');
1566                 self::assertStatus($result['status']);
1567         }
1568
1569         /**
1570          * Test the api_statuses_show() function with the conversation parameter.
1571          *
1572          * @return void
1573          */
1574         public function testApiStatusesShowWithConversation()
1575         {
1576                 DI::args()->setArgv(['', '', '', 1]);
1577                 $_REQUEST['conversation'] = 1;
1578                 $result                   = api_statuses_show('json');
1579                 self::assertNotEmpty($result['status']);
1580                 foreach ($result['status'] as $status) {
1581                         self::assertStatus($status);
1582                 }
1583         }
1584
1585         /**
1586          * Test the api_statuses_show() function with an unallowed user.
1587          *
1588          * @return void
1589          */
1590         public function testApiStatusesShowWithUnallowedUser()
1591         {
1592                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1593                 BasicAuth::setCurrentUserID();
1594                 api_statuses_show('json');
1595         }
1596
1597         /**
1598          * Test the api_conversation_show() function.
1599          *
1600          * @return void
1601          */
1602         public function testApiConversationShow()
1603         {
1604                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1605                 api_conversation_show('json');
1606         }
1607
1608         /**
1609          * Test the api_conversation_show() function with an ID.
1610          *
1611          * @return void
1612          */
1613         public function testApiConversationShowWithId()
1614         {
1615                 DI::args()->setArgv(['', '', '', 1]);
1616                 $_REQUEST['max_id'] = 10;
1617                 $_REQUEST['page']   = -2;
1618                 $result             = api_conversation_show('json');
1619                 self::assertNotEmpty($result['status']);
1620                 foreach ($result['status'] as $status) {
1621                         self::assertStatus($status);
1622                 }
1623         }
1624
1625         /**
1626          * Test the api_conversation_show() function with an unallowed user.
1627          *
1628          * @return void
1629          */
1630         public function testApiConversationShowWithUnallowedUser()
1631         {
1632                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1633                 BasicAuth::setCurrentUserID();
1634                 api_conversation_show('json');
1635         }
1636
1637         /**
1638          * Test the api_statuses_repeat() function.
1639          *
1640          * @return void
1641          */
1642         public function testApiStatusesRepeat()
1643         {
1644                 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1645                 api_statuses_repeat('json');
1646         }
1647
1648         /**
1649          * Test the api_statuses_repeat() function without an authenticated user.
1650          *
1651          * @return void
1652          */
1653         public function testApiStatusesRepeatWithoutAuthenticatedUser()
1654         {
1655                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1656                 BasicAuth::setCurrentUserID();
1657                 $_SESSION['authenticated'] = false;
1658                 api_statuses_repeat('json');
1659         }
1660
1661         /**
1662          * Test the api_statuses_repeat() function with an ID.
1663          *
1664          * @return void
1665          */
1666         public function testApiStatusesRepeatWithId()
1667         {
1668                 DI::args()->setArgv(['', '', '', 1]);
1669                 $result = api_statuses_repeat('json');
1670                 self::assertStatus($result['status']);
1671
1672                 // Also test with a shared status
1673                 DI::args()->setArgv(['', '', '', 5]);
1674                 $result = api_statuses_repeat('json');
1675                 self::assertStatus($result['status']);
1676         }
1677
1678         /**
1679          * Test the api_statuses_destroy() function.
1680          *
1681          * @return void
1682          */
1683         public function testApiStatusesDestroy()
1684         {
1685                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1686                 api_statuses_destroy('json');
1687         }
1688
1689         /**
1690          * Test the api_statuses_destroy() function without an authenticated user.
1691          *
1692          * @return void
1693          */
1694         public function testApiStatusesDestroyWithoutAuthenticatedUser()
1695         {
1696                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1697                 BasicAuth::setCurrentUserID();
1698                 $_SESSION['authenticated'] = false;
1699                 api_statuses_destroy('json');
1700         }
1701
1702         /**
1703          * Test the api_statuses_destroy() function with an ID.
1704          *
1705          * @return void
1706          */
1707         public function testApiStatusesDestroyWithId()
1708         {
1709                 DI::args()->setArgv(['', '', '', 1]);
1710                 $result = api_statuses_destroy('json');
1711                 self::assertStatus($result['status']);
1712         }
1713
1714         /**
1715          * Test the api_statuses_mentions() function.
1716          *
1717          * @return void
1718          */
1719         public function testApiStatusesMentions()
1720         {
1721                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1722                 $_REQUEST['max_id'] = 10;
1723                 $result             = api_statuses_mentions('json');
1724                 self::assertEmpty($result['status']);
1725                 // We should test with mentions in the database.
1726         }
1727
1728         /**
1729          * Test the api_statuses_mentions() function with a negative page parameter.
1730          *
1731          * @return void
1732          */
1733         public function testApiStatusesMentionsWithNegativePage()
1734         {
1735                 $_REQUEST['page'] = -2;
1736                 $result           = api_statuses_mentions('json');
1737                 self::assertEmpty($result['status']);
1738         }
1739
1740         /**
1741          * Test the api_statuses_mentions() function with an unallowed user.
1742          *
1743          * @return void
1744          */
1745         public function testApiStatusesMentionsWithUnallowedUser()
1746         {
1747                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1748                 BasicAuth::setCurrentUserID();
1749                 api_statuses_mentions('json');
1750         }
1751
1752         /**
1753          * Test the api_statuses_mentions() function with an RSS result.
1754          *
1755          * @return void
1756          */
1757         public function testApiStatusesMentionsWithRss()
1758         {
1759                 $result = api_statuses_mentions('rss');
1760                 self::assertXml($result, 'statuses');
1761         }
1762
1763         /**
1764          * Test the api_statuses_user_timeline() function.
1765          *
1766          * @return void
1767          */
1768         public function testApiStatusesUserTimeline()
1769         {
1770                 $_REQUEST['max_id']          = 10;
1771                 $_REQUEST['exclude_replies'] = true;
1772                 $_REQUEST['conversation_id'] = 1;
1773                 $result                      = api_statuses_user_timeline('json');
1774                 self::assertNotEmpty($result['status']);
1775                 foreach ($result['status'] as $status) {
1776                         self::assertStatus($status);
1777                 }
1778         }
1779
1780         /**
1781          * Test the api_statuses_user_timeline() function with a negative page parameter.
1782          *
1783          * @return void
1784          */
1785         public function testApiStatusesUserTimelineWithNegativePage()
1786         {
1787                 $_REQUEST['page'] = -2;
1788                 $result           = api_statuses_user_timeline('json');
1789                 self::assertNotEmpty($result['status']);
1790                 foreach ($result['status'] as $status) {
1791                         self::assertStatus($status);
1792                 }
1793         }
1794
1795         /**
1796          * Test the api_statuses_user_timeline() function with an RSS result.
1797          *
1798          * @return void
1799          */
1800         public function testApiStatusesUserTimelineWithRss()
1801         {
1802                 $result = api_statuses_user_timeline('rss');
1803                 self::assertXml($result, 'statuses');
1804         }
1805
1806         /**
1807          * Test the api_statuses_user_timeline() function with an unallowed user.
1808          *
1809          * @return void
1810          */
1811         public function testApiStatusesUserTimelineWithUnallowedUser()
1812         {
1813                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1814                 BasicAuth::setCurrentUserID();
1815                 api_statuses_user_timeline('json');
1816         }
1817
1818         /**
1819          * Test the api_favorites_create_destroy() function.
1820          *
1821          * @return void
1822          */
1823         public function testApiFavoritesCreateDestroy()
1824         {
1825                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1826                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1827                 api_favorites_create_destroy('json');
1828         }
1829
1830         /**
1831          * Test the api_favorites_create_destroy() function with an invalid ID.
1832          *
1833          * @return void
1834          */
1835         public function testApiFavoritesCreateDestroyWithInvalidId()
1836         {
1837                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1838                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1839                 api_favorites_create_destroy('json');
1840         }
1841
1842         /**
1843          * Test the api_favorites_create_destroy() function with an invalid action.
1844          *
1845          * @return void
1846          */
1847         public function testApiFavoritesCreateDestroyWithInvalidAction()
1848         {
1849                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1850                 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1851                 $_REQUEST['id'] = 1;
1852                 api_favorites_create_destroy('json');
1853         }
1854
1855         /**
1856          * Test the api_favorites_create_destroy() function with the create action.
1857          *
1858          * @return void
1859          */
1860         public function testApiFavoritesCreateDestroyWithCreateAction()
1861         {
1862                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1863                 $_REQUEST['id'] = 3;
1864                 $result         = api_favorites_create_destroy('json');
1865                 self::assertStatus($result['status']);
1866         }
1867
1868         /**
1869          * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1870          *
1871          * @return void
1872          */
1873         public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1874         {
1875                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1876                 $_REQUEST['id'] = 3;
1877                 $result         = api_favorites_create_destroy('rss');
1878                 self::assertXml($result, 'status');
1879         }
1880
1881         /**
1882          * Test the api_favorites_create_destroy() function with the destroy action.
1883          *
1884          * @return void
1885          */
1886         public function testApiFavoritesCreateDestroyWithDestroyAction()
1887         {
1888                 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1889                 $_REQUEST['id'] = 3;
1890                 $result         = api_favorites_create_destroy('json');
1891                 self::assertStatus($result['status']);
1892         }
1893
1894         /**
1895          * Test the api_favorites_create_destroy() function without an authenticated user.
1896          *
1897          * @return void
1898          */
1899         public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1900         {
1901                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1902                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1903                 BasicAuth::setCurrentUserID();
1904                 $_SESSION['authenticated'] = false;
1905                 api_favorites_create_destroy('json');
1906         }
1907
1908         /**
1909          * Test the api_favorites() function.
1910          *
1911          * @return void
1912          */
1913         public function testApiFavorites()
1914         {
1915                 $_REQUEST['page']   = -1;
1916                 $_REQUEST['max_id'] = 10;
1917                 $result             = api_favorites('json');
1918                 foreach ($result['status'] as $status) {
1919                         self::assertStatus($status);
1920                 }
1921         }
1922
1923         /**
1924          * Test the api_favorites() function with an RSS result.
1925          *
1926          * @return void
1927          */
1928         public function testApiFavoritesWithRss()
1929         {
1930                 $result = api_favorites('rss');
1931                 self::assertXml($result, 'statuses');
1932         }
1933
1934         /**
1935          * Test the api_favorites() function with an unallowed user.
1936          *
1937          * @return void
1938          */
1939         public function testApiFavoritesWithUnallowedUser()
1940         {
1941                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1942                 BasicAuth::setCurrentUserID();
1943                 api_favorites('json');
1944         }
1945
1946         /**
1947          * Test the api_format_messages() function.
1948          *
1949          * @return void
1950          */
1951         public function testApiFormatMessages()
1952         {
1953                 $result = api_format_messages(
1954                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1955                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1956                         ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
1957                 );
1958                 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
1959                 self::assertEquals(1, $result['id']);
1960                 self::assertEquals(2, $result['recipient_id']);
1961                 self::assertEquals(3, $result['sender_id']);
1962                 self::assertEquals('recipient_name', $result['recipient_screen_name']);
1963                 self::assertEquals('sender_name', $result['sender_screen_name']);
1964         }
1965
1966         /**
1967          * Test the api_format_messages() function with HTML.
1968          *
1969          * @return void
1970          */
1971         public function testApiFormatMessagesWithHtmlText()
1972         {
1973                 $_GET['getText'] = 'html';
1974                 $result          = api_format_messages(
1975                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1976                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1977                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1978                 );
1979                 self::assertEquals('item_title', $result['title']);
1980                 self::assertEquals('<strong>item_body</strong>', $result['text']);
1981         }
1982
1983         /**
1984          * Test the api_format_messages() function with plain text.
1985          *
1986          * @return void
1987          */
1988         public function testApiFormatMessagesWithPlainText()
1989         {
1990                 $_GET['getText'] = 'plain';
1991                 $result          = api_format_messages(
1992                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1993                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1994                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1995                 );
1996                 self::assertEquals('item_title', $result['title']);
1997                 self::assertEquals('item_body', $result['text']);
1998         }
1999
2000         /**
2001          * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2002          *
2003          * @return void
2004          */
2005         public function testApiFormatMessagesWithoutUserObjects()
2006         {
2007                 $_GET['getUserObjects'] = 'false';
2008                 $result                 = api_format_messages(
2009                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2010                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2011                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2012                 );
2013                 self::assertTrue(!isset($result['sender']));
2014                 self::assertTrue(!isset($result['recipient']));
2015         }
2016
2017         /**
2018          * Test the api_convert_item() function.
2019          *
2020          * @return void
2021          */
2022         public function testApiConvertItem()
2023         {
2024                 $result = api_convert_item(
2025                         [
2026                                 'network' => 'feed',
2027                                 'title'   => 'item_title',
2028                                 'uri-id'  => 1,
2029                                 // We need a long string to test that it is correctly cut
2030                                 'body'    => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2031                                                          'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2032                                                          'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2033                                                          'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2034                                                          'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2035                                                          'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2036                                                          'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2037                                                          'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2038                                                          'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2039                                                          'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2040                                                          'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2041                                                          'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2042                                                          'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2043                                                          'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2044                                                          'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2045                                                          'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2046                                                          'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2047                                                          'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2048                                                          'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2049                                                          'repellat officia illum quos impedit quam iste esse unde qui ' .
2050                                                          'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2051                                                          'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2052                                                          'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2053                                 'plink'   => 'item_plink'
2054                         ]
2055                 );
2056                 self::assertStringStartsWith('item_title', $result['text']);
2057                 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2058         }
2059
2060         /**
2061          * Test the api_convert_item() function with an empty item body.
2062          *
2063          * @return void
2064          */
2065         public function testApiConvertItemWithoutBody()
2066         {
2067                 $result = api_convert_item(
2068                         [
2069                                 'network' => 'feed',
2070                                 'title'   => 'item_title',
2071                                 'uri-id'  => -1,
2072                                 'body'    => '',
2073                                 'plink'   => 'item_plink'
2074                         ]
2075                 );
2076                 self::assertEquals("item_title", $result['text']);
2077                 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2078         }
2079
2080         /**
2081          * Test the api_convert_item() function with the title in the body.
2082          *
2083          * @return void
2084          */
2085         public function testApiConvertItemWithTitleInBody()
2086         {
2087                 $result = api_convert_item(
2088                         [
2089                                 'title'  => 'item_title',
2090                                 'body'   => 'item_title item_body',
2091                                 'uri-id' => 1,
2092                         ]
2093                 );
2094                 self::assertEquals('item_title item_body', $result['text']);
2095                 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2096         }
2097
2098         /**
2099          * Test the api_get_attachments() function.
2100          *
2101          * @return void
2102          */
2103         public function testApiGetAttachments()
2104         {
2105                 $body = 'body';
2106                 self::assertEmpty(api_get_attachments($body, 0));
2107         }
2108
2109         /**
2110          * Test the api_get_attachments() function with an img tag.
2111          *
2112          * @return void
2113          */
2114         public function testApiGetAttachmentsWithImage()
2115         {
2116                 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2117                 self::assertIsArray(api_get_attachments($body, 0));
2118         }
2119
2120         /**
2121          * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2122          *
2123          * @return void
2124          */
2125         public function testApiGetAttachmentsWithImageAndAndStatus()
2126         {
2127                 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2128                 $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
2129                 self::assertIsArray(api_get_attachments($body, 0));
2130         }
2131
2132         /**
2133          * Test the api_get_entitities() function.
2134          *
2135          * @return void
2136          */
2137         public function testApiGetEntitities()
2138         {
2139                 $text = 'text';
2140                 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2141         }
2142
2143         /**
2144          * Test the api_get_entitities() function with the include_entities parameter.
2145          *
2146          * @return void
2147          */
2148         public function testApiGetEntititiesWithIncludeEntities()
2149         {
2150                 $_REQUEST['include_entities'] = 'true';
2151                 $text                         = 'text';
2152                 $result                       = api_get_entitities($text, 'bbcode', 0);
2153                 self::assertIsArray($result['hashtags']);
2154                 self::assertIsArray($result['symbols']);
2155                 self::assertIsArray($result['urls']);
2156                 self::assertIsArray($result['user_mentions']);
2157         }
2158
2159         /**
2160          * Test the api_format_items_embeded_images() function.
2161          *
2162          * @return void
2163          */
2164         public function testApiFormatItemsEmbededImages()
2165         {
2166                 self::assertEquals(
2167                         'text ' . DI::baseUrl() . '/display/item_guid',
2168                         api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2169                 );
2170         }
2171
2172         /**
2173          * Test the api_contactlink_to_array() function.
2174          *
2175          * @return void
2176          */
2177         public function testApiContactlinkToArray()
2178         {
2179                 self::assertEquals(
2180                         [
2181                                 'name' => 'text',
2182                                 'url'  => '',
2183                         ],
2184                         api_contactlink_to_array('text')
2185                 );
2186         }
2187
2188         /**
2189          * Test the api_contactlink_to_array() function with an URL.
2190          *
2191          * @return void
2192          */
2193         public function testApiContactlinkToArrayWithUrl()
2194         {
2195                 self::assertEquals(
2196                         [
2197                                 'name' => ['link_text'],
2198                                 'url'  => ['url'],
2199                         ],
2200                         api_contactlink_to_array('text <a href="url">link_text</a>')
2201                 );
2202         }
2203
2204         /**
2205          * Test the api_format_items_activities() function.
2206          *
2207          * @return void
2208          */
2209         public function testApiFormatItemsActivities()
2210         {
2211                 $item   = ['uid' => 0, 'uri' => ''];
2212                 $result = api_format_items_activities($item);
2213                 self::assertArrayHasKey('like', $result);
2214                 self::assertArrayHasKey('dislike', $result);
2215                 self::assertArrayHasKey('attendyes', $result);
2216                 self::assertArrayHasKey('attendno', $result);
2217                 self::assertArrayHasKey('attendmaybe', $result);
2218         }
2219
2220         /**
2221          * Test the api_format_items_activities() function with an XML result.
2222          *
2223          * @return void
2224          */
2225         public function testApiFormatItemsActivitiesWithXml()
2226         {
2227                 $item   = ['uid' => 0, 'uri' => ''];
2228                 $result = api_format_items_activities($item, 'xml');
2229                 self::assertArrayHasKey('friendica:like', $result);
2230                 self::assertArrayHasKey('friendica:dislike', $result);
2231                 self::assertArrayHasKey('friendica:attendyes', $result);
2232                 self::assertArrayHasKey('friendica:attendno', $result);
2233                 self::assertArrayHasKey('friendica:attendmaybe', $result);
2234         }
2235
2236         /**
2237          * Test the api_format_items() function.
2238          * @doesNotPerformAssertions
2239          */
2240         public function testApiFormatItems()
2241         {
2242                 $items  = [
2243                         [
2244                                 'item_network'   => 'item_network',
2245                                 'source'         => 'web',
2246                                 'coord'          => '5 7',
2247                                 'body'           => '',
2248                                 'verb'           => '',
2249                                 'author-id'      => 43,
2250                                 'author-network' => Protocol::DFRN,
2251                                 'author-link'    => 'http://localhost/profile/othercontact',
2252                                 'plink'          => '',
2253                         ]
2254                 ];
2255                 $result = api_format_items($items, ['id' => 0], true);
2256                 foreach ($result as $status) {
2257                         self::assertStatus($status);
2258                 }
2259         }
2260
2261         /**
2262          * Test the api_format_items() function with an XML result.
2263          * @doesNotPerformAssertions
2264          */
2265         public function testApiFormatItemsWithXml()
2266         {
2267                 $items  = [
2268                         [
2269                                 'coord'          => '5 7',
2270                                 'body'           => '',
2271                                 'verb'           => '',
2272                                 'author-id'      => 43,
2273                                 'author-network' => Protocol::DFRN,
2274                                 'author-link'    => 'http://localhost/profile/othercontact',
2275                                 'plink'          => '',
2276                         ]
2277                 ];
2278                 $result = api_format_items($items, ['id' => 0], true, 'xml');
2279                 foreach ($result as $status) {
2280                         self::assertStatus($status);
2281                 }
2282         }
2283
2284         /**
2285          * Test the api_lists_list() function.
2286          *
2287          * @return void
2288          */
2289         public function testApiListsList()
2290         {
2291                 $result = api_lists_list('json');
2292                 self::assertEquals(['lists_list' => []], $result);
2293         }
2294
2295         /**
2296          * Test the api_lists_ownerships() function.
2297          *
2298          * @return void
2299          */
2300         public function testApiListsOwnerships()
2301         {
2302                 $result = api_lists_ownerships('json');
2303                 foreach ($result['lists']['lists'] as $list) {
2304                         self::assertList($list);
2305                 }
2306         }
2307
2308         /**
2309          * Test the api_lists_ownerships() function without an authenticated user.
2310          *
2311          * @return void
2312          */
2313         public function testApiListsOwnershipsWithoutAuthenticatedUser()
2314         {
2315                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2316                 BasicAuth::setCurrentUserID();
2317                 $_SESSION['authenticated'] = false;
2318                 api_lists_ownerships('json');
2319         }
2320
2321         /**
2322          * Test the api_lists_statuses() function.
2323          *
2324          * @return void
2325          */
2326         public function testApiListsStatuses()
2327         {
2328                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2329                 api_lists_statuses('json');
2330         }
2331
2332         /**
2333          * Test the api_lists_statuses() function with a list ID.
2334          * @doesNotPerformAssertions
2335          */
2336         public function testApiListsStatusesWithListId()
2337         {
2338                 $_REQUEST['list_id'] = 1;
2339                 $_REQUEST['page']    = -1;
2340                 $_REQUEST['max_id']  = 10;
2341                 $result              = api_lists_statuses('json');
2342                 foreach ($result['status'] as $status) {
2343                         self::assertStatus($status);
2344                 }
2345         }
2346
2347         /**
2348          * Test the api_lists_statuses() function with a list ID and a RSS result.
2349          *
2350          * @return void
2351          */
2352         public function testApiListsStatusesWithListIdAndRss()
2353         {
2354                 $_REQUEST['list_id'] = 1;
2355                 $result              = api_lists_statuses('rss');
2356                 self::assertXml($result, 'statuses');
2357         }
2358
2359         /**
2360          * Test the api_lists_statuses() function with an unallowed user.
2361          *
2362          * @return void
2363          */
2364         public function testApiListsStatusesWithUnallowedUser()
2365         {
2366                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2367                 BasicAuth::setCurrentUserID();
2368                 api_lists_statuses('json');
2369         }
2370
2371         /**
2372          * Test the api_statuses_f() function.
2373          *
2374          * @return void
2375          */
2376         public function testApiStatusesFWithFriends()
2377         {
2378                 $_GET['page'] = -1;
2379                 $result       = api_statuses_f('friends');
2380                 self::assertArrayHasKey('user', $result);
2381         }
2382
2383         /**
2384          * Test the api_statuses_f() function.
2385          *
2386          * @return void
2387          */
2388         public function testApiStatusesFWithFollowers()
2389         {
2390                 $result = api_statuses_f('followers');
2391                 self::assertArrayHasKey('user', $result);
2392         }
2393
2394         /**
2395          * Test the api_statuses_f() function.
2396          *
2397          * @return void
2398          */
2399         public function testApiStatusesFWithBlocks()
2400         {
2401                 $result = api_statuses_f('blocks');
2402                 self::assertArrayHasKey('user', $result);
2403         }
2404
2405         /**
2406          * Test the api_statuses_f() function.
2407          *
2408          * @return void
2409          */
2410         public function testApiStatusesFWithIncoming()
2411         {
2412                 $result = api_statuses_f('incoming');
2413                 self::assertArrayHasKey('user', $result);
2414         }
2415
2416         /**
2417          * Test the api_statuses_f() function an undefined cursor GET variable.
2418          *
2419          * @return void
2420          */
2421         public function testApiStatusesFWithUndefinedCursor()
2422         {
2423                 $_GET['cursor'] = 'undefined';
2424                 self::assertFalse(api_statuses_f('friends'));
2425         }
2426
2427         /**
2428          * Test the api_statuses_friends() function.
2429          *
2430          * @return void
2431          */
2432         public function testApiStatusesFriends()
2433         {
2434                 $result = api_statuses_friends('json');
2435                 self::assertArrayHasKey('user', $result);
2436         }
2437
2438         /**
2439          * Test the api_statuses_friends() function an undefined cursor GET variable.
2440          *
2441          * @return void
2442          */
2443         public function testApiStatusesFriendsWithUndefinedCursor()
2444         {
2445                 $_GET['cursor'] = 'undefined';
2446                 self::assertFalse(api_statuses_friends('json'));
2447         }
2448
2449         /**
2450          * Test the api_statuses_followers() function.
2451          *
2452          * @return void
2453          */
2454         public function testApiStatusesFollowers()
2455         {
2456                 $result = api_statuses_followers('json');
2457                 self::assertArrayHasKey('user', $result);
2458         }
2459
2460         /**
2461          * Test the api_statuses_followers() function an undefined cursor GET variable.
2462          *
2463          * @return void
2464          */
2465         public function testApiStatusesFollowersWithUndefinedCursor()
2466         {
2467                 $_GET['cursor'] = 'undefined';
2468                 self::assertFalse(api_statuses_followers('json'));
2469         }
2470
2471         /**
2472          * Test the api_blocks_list() function.
2473          *
2474          * @return void
2475          */
2476         public function testApiBlocksList()
2477         {
2478                 $result = api_blocks_list('json');
2479                 self::assertArrayHasKey('user', $result);
2480         }
2481
2482         /**
2483          * Test the api_blocks_list() function an undefined cursor GET variable.
2484          *
2485          * @return void
2486          */
2487         public function testApiBlocksListWithUndefinedCursor()
2488         {
2489                 $_GET['cursor'] = 'undefined';
2490                 self::assertFalse(api_blocks_list('json'));
2491         }
2492
2493         /**
2494          * Test the api_friendships_incoming() function.
2495          *
2496          * @return void
2497          */
2498         public function testApiFriendshipsIncoming()
2499         {
2500                 $result = api_friendships_incoming('json');
2501                 self::assertArrayHasKey('id', $result);
2502         }
2503
2504         /**
2505          * Test the api_friendships_incoming() function an undefined cursor GET variable.
2506          *
2507          * @return void
2508          */
2509         public function testApiFriendshipsIncomingWithUndefinedCursor()
2510         {
2511                 $_GET['cursor'] = 'undefined';
2512                 self::assertFalse(api_friendships_incoming('json'));
2513         }
2514
2515         /**
2516          * Test the api_statusnet_config() function.
2517          *
2518          * @return void
2519          */
2520         public function testApiStatusnetConfig()
2521         {
2522                 /*
2523                 $result = api_statusnet_config('json');
2524                 self::assertEquals('localhost', $result['config']['site']['server']);
2525                 self::assertEquals('default', $result['config']['site']['theme']);
2526                 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2527                 self::assertTrue($result['config']['site']['fancy']);
2528                 self::assertEquals('en', $result['config']['site']['language']);
2529                 self::assertEquals('UTC', $result['config']['site']['timezone']);
2530                 self::assertEquals(200000, $result['config']['site']['textlimit']);
2531                 self::assertEquals('false', $result['config']['site']['private']);
2532                 self::assertEquals('false', $result['config']['site']['ssl']);
2533                 self::assertEquals(30, $result['config']['site']['shorturllength']);
2534                 */
2535         }
2536
2537         /**
2538          * Test the api_direct_messages_new() function.
2539          *
2540          * @return void
2541          */
2542         public function testApiDirectMessagesNew()
2543         {
2544                 $result = api_direct_messages_new('json');
2545                 self::assertNull($result);
2546         }
2547
2548         /**
2549          * Test the api_direct_messages_new() function without an authenticated user.
2550          *
2551          * @return void
2552          */
2553         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2554         {
2555                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2556                 BasicAuth::setCurrentUserID();
2557                 $_SESSION['authenticated'] = false;
2558                 api_direct_messages_new('json');
2559         }
2560
2561         /**
2562          * Test the api_direct_messages_new() function with an user ID.
2563          *
2564          * @return void
2565          */
2566         public function testApiDirectMessagesNewWithUserId()
2567         {
2568                 $_POST['text']    = 'message_text';
2569                 $_POST['user_id'] = $this->otherUser['id'];
2570                 $result           = api_direct_messages_new('json');
2571                 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2572         }
2573
2574         /**
2575          * Test the api_direct_messages_new() function with a screen name.
2576          *
2577          * @return void
2578          */
2579         public function testApiDirectMessagesNewWithScreenName()
2580         {
2581                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2582                 $_POST['text']        = 'message_text';
2583                 $_POST['screen_name'] = $this->friendUser['nick'];
2584                 $result               = api_direct_messages_new('json');
2585                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2586                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2587                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2588         }
2589
2590         /**
2591          * Test the api_direct_messages_new() function with a title.
2592          *
2593          * @return void
2594          */
2595         public function testApiDirectMessagesNewWithTitle()
2596         {
2597                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2598                 $_POST['text']        = 'message_text';
2599                 $_POST['screen_name'] = $this->friendUser['nick'];
2600                 $_REQUEST['title']    = 'message_title';
2601                 $result               = api_direct_messages_new('json');
2602                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2603                 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2604                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2605                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2606         }
2607
2608         /**
2609          * Test the api_direct_messages_new() function with an RSS result.
2610          *
2611          * @return void
2612          */
2613         public function testApiDirectMessagesNewWithRss()
2614         {
2615                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2616                 $_POST['text']        = 'message_text';
2617                 $_POST['screen_name'] = $this->friendUser['nick'];
2618                 $result               = api_direct_messages_new('rss');
2619                 self::assertXml($result, 'direct-messages');
2620         }
2621
2622         /**
2623          * Test the api_direct_messages_destroy() function.
2624          *
2625          * @return void
2626          */
2627         public function testApiDirectMessagesDestroy()
2628         {
2629                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2630                 api_direct_messages_destroy('json');
2631         }
2632
2633         /**
2634          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2635          *
2636          * @return void
2637          */
2638         public function testApiDirectMessagesDestroyWithVerbose()
2639         {
2640                 $_GET['friendica_verbose'] = 'true';
2641                 $result                    = api_direct_messages_destroy('json');
2642                 self::assertEquals(
2643                         [
2644                                 '$result' => [
2645                                         'result'  => 'error',
2646                                         'message' => 'message id or parenturi not specified'
2647                                 ]
2648                         ],
2649                         $result
2650                 );
2651         }
2652
2653         /**
2654          * Test the api_direct_messages_destroy() function without an authenticated user.
2655          *
2656          * @return void
2657          */
2658         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2659         {
2660                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2661                 BasicAuth::setCurrentUserID();
2662                 $_SESSION['authenticated'] = false;
2663                 api_direct_messages_destroy('json');
2664         }
2665
2666         /**
2667          * Test the api_direct_messages_destroy() function with a non-zero ID.
2668          *
2669          * @return void
2670          */
2671         public function testApiDirectMessagesDestroyWithId()
2672         {
2673                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2674                 $_REQUEST['id'] = 1;
2675                 api_direct_messages_destroy('json');
2676         }
2677
2678         /**
2679          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2680          *
2681          * @return void
2682          */
2683         public function testApiDirectMessagesDestroyWithIdAndVerbose()
2684         {
2685                 $_REQUEST['id']                  = 1;
2686                 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2687                 $_GET['friendica_verbose']       = 'true';
2688                 $result                          = api_direct_messages_destroy('json');
2689                 self::assertEquals(
2690                         [
2691                                 '$result' => [
2692                                         'result'  => 'error',
2693                                         'message' => 'message id not in database'
2694                                 ]
2695                         ],
2696                         $result
2697                 );
2698         }
2699
2700         /**
2701          * Test the api_direct_messages_destroy() function with a non-zero ID.
2702          *
2703          * @return void
2704          */
2705         public function testApiDirectMessagesDestroyWithCorrectId()
2706         {
2707                 $this->markTestIncomplete('We need to add a dataset for this.');
2708         }
2709
2710         /**
2711          * Test the api_direct_messages_box() function.
2712          *
2713          * @return void
2714          */
2715         public function testApiDirectMessagesBoxWithSentbox()
2716         {
2717                 $_REQUEST['page']   = -1;
2718                 $_REQUEST['max_id'] = 10;
2719                 $result             = api_direct_messages_box('json', 'sentbox', 'false');
2720                 self::assertArrayHasKey('direct_message', $result);
2721         }
2722
2723         /**
2724          * Test the api_direct_messages_box() function.
2725          *
2726          * @return void
2727          */
2728         public function testApiDirectMessagesBoxWithConversation()
2729         {
2730                 $result = api_direct_messages_box('json', 'conversation', 'false');
2731                 self::assertArrayHasKey('direct_message', $result);
2732         }
2733
2734         /**
2735          * Test the api_direct_messages_box() function.
2736          *
2737          * @return void
2738          */
2739         public function testApiDirectMessagesBoxWithAll()
2740         {
2741                 $result = api_direct_messages_box('json', 'all', 'false');
2742                 self::assertArrayHasKey('direct_message', $result);
2743         }
2744
2745         /**
2746          * Test the api_direct_messages_box() function.
2747          *
2748          * @return void
2749          */
2750         public function testApiDirectMessagesBoxWithInbox()
2751         {
2752                 $result = api_direct_messages_box('json', 'inbox', 'false');
2753                 self::assertArrayHasKey('direct_message', $result);
2754         }
2755
2756         /**
2757          * Test the api_direct_messages_box() function.
2758          *
2759          * @return void
2760          */
2761         public function testApiDirectMessagesBoxWithVerbose()
2762         {
2763                 $result = api_direct_messages_box('json', 'sentbox', 'true');
2764                 self::assertEquals(
2765                         [
2766                                 '$result' => [
2767                                         'result'  => 'error',
2768                                         'message' => 'no mails available'
2769                                 ]
2770                         ],
2771                         $result
2772                 );
2773         }
2774
2775         /**
2776          * Test the api_direct_messages_box() function with a RSS result.
2777          *
2778          * @return void
2779          */
2780         public function testApiDirectMessagesBoxWithRss()
2781         {
2782                 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2783                 self::assertXml($result, 'direct-messages');
2784         }
2785
2786         /**
2787          * Test the api_direct_messages_box() function without an authenticated user.
2788          *
2789          * @return void
2790          */
2791         public function testApiDirectMessagesBoxWithUnallowedUser()
2792         {
2793                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2794                 BasicAuth::setCurrentUserID();
2795                 api_direct_messages_box('json', 'sentbox', 'false');
2796         }
2797
2798         /**
2799          * Test the api_direct_messages_sentbox() function.
2800          *
2801          * @return void
2802          */
2803         public function testApiDirectMessagesSentbox()
2804         {
2805                 $result = api_direct_messages_sentbox('json');
2806                 self::assertArrayHasKey('direct_message', $result);
2807         }
2808
2809         /**
2810          * Test the api_direct_messages_inbox() function.
2811          *
2812          * @return void
2813          */
2814         public function testApiDirectMessagesInbox()
2815         {
2816                 $result = api_direct_messages_inbox('json');
2817                 self::assertArrayHasKey('direct_message', $result);
2818         }
2819
2820         /**
2821          * Test the api_direct_messages_all() function.
2822          *
2823          * @return void
2824          */
2825         public function testApiDirectMessagesAll()
2826         {
2827                 $result = api_direct_messages_all('json');
2828                 self::assertArrayHasKey('direct_message', $result);
2829         }
2830
2831         /**
2832          * Test the api_direct_messages_conversation() function.
2833          *
2834          * @return void
2835          */
2836         public function testApiDirectMessagesConversation()
2837         {
2838                 $result = api_direct_messages_conversation('json');
2839                 self::assertArrayHasKey('direct_message', $result);
2840         }
2841
2842         /**
2843          * Test the api_oauth_request_token() function.
2844          *
2845          * @return void
2846          */
2847         public function testApiOauthRequestToken()
2848         {
2849                 $this->markTestIncomplete('exit() kills phpunit as well');
2850         }
2851
2852         /**
2853          * Test the api_oauth_access_token() function.
2854          *
2855          * @return void
2856          */
2857         public function testApiOauthAccessToken()
2858         {
2859                 $this->markTestIncomplete('exit() kills phpunit as well');
2860         }
2861
2862         /**
2863          * Test the api_fr_photos_list() function.
2864          *
2865          * @return void
2866          */
2867         public function testApiFrPhotosList()
2868         {
2869                 $result = api_fr_photos_list('json');
2870                 self::assertArrayHasKey('photo', $result);
2871         }
2872
2873         /**
2874          * Test the api_fr_photos_list() function without an authenticated user.
2875          *
2876          * @return void
2877          */
2878         public function testApiFrPhotosListWithoutAuthenticatedUser()
2879         {
2880                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2881                 BasicAuth::setCurrentUserID();
2882                 $_SESSION['authenticated'] = false;
2883                 api_fr_photos_list('json');
2884         }
2885
2886         /**
2887          * Test the api_fr_photo_create_update() function.
2888          */
2889         public function testApiFrPhotoCreateUpdate()
2890         {
2891                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2892                 api_fr_photo_create_update('json');
2893         }
2894
2895         /**
2896          * Test the api_fr_photo_create_update() function without an authenticated user.
2897          *
2898          * @return void
2899          */
2900         public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
2901         {
2902                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2903                 BasicAuth::setCurrentUserID();
2904                 $_SESSION['authenticated'] = false;
2905                 api_fr_photo_create_update('json');
2906         }
2907
2908         /**
2909          * Test the api_fr_photo_create_update() function with an album name.
2910          *
2911          * @return void
2912          */
2913         public function testApiFrPhotoCreateUpdateWithAlbum()
2914         {
2915                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2916                 $_REQUEST['album'] = 'album_name';
2917                 api_fr_photo_create_update('json');
2918         }
2919
2920         /**
2921          * Test the api_fr_photo_create_update() function with the update mode.
2922          *
2923          * @return void
2924          */
2925         public function testApiFrPhotoCreateUpdateWithUpdate()
2926         {
2927                 $this->markTestIncomplete('We need to create a dataset for this');
2928         }
2929
2930         /**
2931          * Test the api_fr_photo_create_update() function with an uploaded file.
2932          *
2933          * @return void
2934          */
2935         public function testApiFrPhotoCreateUpdateWithFile()
2936         {
2937                 $this->markTestIncomplete();
2938         }
2939
2940         /**
2941          * Test the api_fr_photo_detail() function.
2942          *
2943          * @return void
2944          */
2945         public function testApiFrPhotoDetail()
2946         {
2947                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2948                 api_fr_photo_detail('json');
2949         }
2950
2951         /**
2952          * Test the api_fr_photo_detail() function without an authenticated user.
2953          *
2954          * @return void
2955          */
2956         public function testApiFrPhotoDetailWithoutAuthenticatedUser()
2957         {
2958                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2959                 BasicAuth::setCurrentUserID();
2960                 $_SESSION['authenticated'] = false;
2961                 api_fr_photo_detail('json');
2962         }
2963
2964         /**
2965          * Test the api_fr_photo_detail() function with a photo ID.
2966          *
2967          * @return void
2968          */
2969         public function testApiFrPhotoDetailWithPhotoId()
2970         {
2971                 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
2972                 $_REQUEST['photo_id'] = 1;
2973                 api_fr_photo_detail('json');
2974         }
2975
2976         /**
2977          * Test the api_fr_photo_detail() function with a correct photo ID.
2978          *
2979          * @return void
2980          */
2981         public function testApiFrPhotoDetailCorrectPhotoId()
2982         {
2983                 $this->markTestIncomplete('We need to create a dataset for this.');
2984         }
2985
2986         /**
2987          * Test the api_account_update_profile_image() function.
2988          *
2989          * @return void
2990          */
2991         public function testApiAccountUpdateProfileImage()
2992         {
2993                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2994                 api_account_update_profile_image('json');
2995         }
2996
2997         /**
2998          * Test the api_account_update_profile_image() function without an authenticated user.
2999          *
3000          * @return void
3001          */
3002         public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3003         {
3004                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
3005                 BasicAuth::setCurrentUserID();
3006                 $_SESSION['authenticated'] = false;
3007                 api_account_update_profile_image('json');
3008         }
3009
3010         /**
3011          * Test the api_account_update_profile_image() function with an uploaded file.
3012          *
3013          * @return void
3014          */
3015         public function testApiAccountUpdateProfileImageWithUpload()
3016         {
3017                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3018                 $this->markTestIncomplete();
3019         }
3020
3021
3022         /**
3023          * Test the api_account_update_profile() function.
3024          *
3025          * @return void
3026          */
3027         public function testApiAccountUpdateProfile()
3028         {
3029                 $_POST['name']        = 'new_name';
3030                 $_POST['description'] = 'new_description';
3031                 $result               = api_account_update_profile('json');
3032                 // We can't use assertSelfUser() here because the user object is missing some properties.
3033                 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3034                 self::assertEquals('DFRN', $result['user']['location']);
3035                 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3036                 self::assertEquals('dfrn', $result['user']['network']);
3037                 self::assertEquals('new_name', $result['user']['name']);
3038                 self::assertEquals('new_description', $result['user']['description']);
3039         }
3040
3041         /**
3042          * Test the check_acl_input() function.
3043          *
3044          * @return void
3045          */
3046         public function testCheckAclInput()
3047         {
3048                 $result = check_acl_input('<aclstring>');
3049                 // Where does this result come from?
3050                 self::assertEquals(1, $result);
3051         }
3052
3053         /**
3054          * Test the check_acl_input() function with an empty ACL string.
3055          *
3056          * @return void
3057          */
3058         public function testCheckAclInputWithEmptyAclString()
3059         {
3060                 $result = check_acl_input(' ');
3061                 self::assertFalse($result);
3062         }
3063
3064         /**
3065          * Test the save_media_to_database() function.
3066          *
3067          * @return void
3068          */
3069         public function testSaveMediaToDatabase()
3070         {
3071                 $this->markTestIncomplete();
3072         }
3073
3074         /**
3075          * Test the post_photo_item() function.
3076          *
3077          * @return void
3078          */
3079         public function testPostPhotoItem()
3080         {
3081                 $this->markTestIncomplete();
3082         }
3083
3084         /**
3085          * Test the prepare_photo_data() function.
3086          *
3087          * @return void
3088          */
3089         public function testPreparePhotoData()
3090         {
3091                 $this->markTestIncomplete();
3092         }
3093
3094         /**
3095          * Test the api_share_as_retweet() function with a valid item.
3096          *
3097          * @return void
3098          */
3099         public function testApiShareAsRetweetWithValidItem()
3100         {
3101                 $this->markTestIncomplete();
3102         }
3103
3104         /**
3105          * Test the api_in_reply_to() function.
3106          *
3107          * @return void
3108          */
3109         public function testApiInReplyTo()
3110         {
3111                 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3112                 self::assertArrayHasKey('status_id', $result);
3113                 self::assertArrayHasKey('user_id', $result);
3114                 self::assertArrayHasKey('status_id_str', $result);
3115                 self::assertArrayHasKey('user_id_str', $result);
3116                 self::assertArrayHasKey('screen_name', $result);
3117         }
3118
3119         /**
3120          * Test the api_in_reply_to() function with a valid item.
3121          *
3122          * @return void
3123          */
3124         public function testApiInReplyToWithValidItem()
3125         {
3126                 $this->markTestIncomplete();
3127         }
3128
3129         /**
3130          * Test the api_clean_plain_items() function.
3131          *
3132          * @return void
3133          */
3134         public function testApiCleanPlainItems()
3135         {
3136                 $_REQUEST['include_entities'] = 'true';
3137                 $result                       = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3138                 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3139         }
3140
3141         /**
3142          * Test the api_best_nickname() function.
3143          *
3144          * @return void
3145          */
3146         public function testApiBestNickname()
3147         {
3148                 $contacts = [];
3149                 $result   = api_best_nickname($contacts);
3150                 self::assertNull($result);
3151         }
3152
3153         /**
3154          * Test the api_best_nickname() function with contacts.
3155          *
3156          * @return void
3157          */
3158         public function testApiBestNicknameWithContacts()
3159         {
3160                 $this->markTestIncomplete();
3161         }
3162
3163         /**
3164          * Test the api_friendica_group_show() function.
3165          *
3166          * @return void
3167          */
3168         public function testApiFriendicaGroupShow()
3169         {
3170                 $this->markTestIncomplete();
3171         }
3172
3173         /**
3174          * Test the api_friendica_group_delete() function.
3175          *
3176          * @return void
3177          */
3178         public function testApiFriendicaGroupDelete()
3179         {
3180                 $this->markTestIncomplete();
3181         }
3182
3183         /**
3184          * Test the api_lists_destroy() function.
3185          *
3186          * @return void
3187          */
3188         public function testApiListsDestroy()
3189         {
3190                 $this->markTestIncomplete();
3191         }
3192
3193         /**
3194          * Test the group_create() function.
3195          *
3196          * @return void
3197          */
3198         public function testGroupCreate()
3199         {
3200                 $this->markTestIncomplete();
3201         }
3202
3203         /**
3204          * Test the api_friendica_group_create() function.
3205          *
3206          * @return void
3207          */
3208         public function testApiFriendicaGroupCreate()
3209         {
3210                 $this->markTestIncomplete();
3211         }
3212
3213         /**
3214          * Test the api_lists_create() function.
3215          *
3216          * @return void
3217          */
3218         public function testApiListsCreate()
3219         {
3220                 $this->markTestIncomplete();
3221         }
3222
3223         /**
3224          * Test the api_friendica_group_update() function.
3225          *
3226          * @return void
3227          */
3228         public function testApiFriendicaGroupUpdate()
3229         {
3230                 $this->markTestIncomplete();
3231         }
3232
3233         /**
3234          * Test the api_lists_update() function.
3235          *
3236          * @return void
3237          */
3238         public function testApiListsUpdate()
3239         {
3240                 $this->markTestIncomplete();
3241         }
3242
3243         /**
3244          * Test the api_friendica_activity() function.
3245          *
3246          * @return void
3247          */
3248         public function testApiFriendicaActivity()
3249         {
3250                 $this->markTestIncomplete();
3251         }
3252
3253         /**
3254          * Test the api_friendica_notification_seen() function.
3255          *
3256          * @return void
3257          */
3258         public function testApiFriendicaNotificationSeen()
3259         {
3260                 $this->markTestIncomplete();
3261         }
3262
3263         /**
3264          * Test the api_friendica_direct_messages_setseen() function.
3265          *
3266          * @return void
3267          */
3268         public function testApiFriendicaDirectMessagesSetseen()
3269         {
3270                 $this->markTestIncomplete();
3271         }
3272
3273         /**
3274          * Test the api_friendica_direct_messages_search() function.
3275          *
3276          * @return void
3277          */
3278         public function testApiFriendicaDirectMessagesSearch()
3279         {
3280                 $this->markTestIncomplete();
3281         }
3282 }