]> git.mxchange.org Git - friendica.git/blob - tests/legacy/ApiTest.php
13509bf3434aac3f7d111c12ad1dbbdababb6aa2
[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 api_item_get_user() function.
768          *
769          * @return void
770          */
771         public function testApiItemGetUser()
772         {
773                 $users = api_item_get_user($this->app, []);
774                 self::assertSelfUser($users[0]);
775         }
776
777         /**
778          * Test the api_item_get_user() function with a different item parent.
779          *
780          * @return void
781          */
782         public function testApiItemGetUserWithDifferentParent()
783         {
784                 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
785                 self::assertSelfUser($users[0]);
786                 self::assertEquals($users[0], $users[1]);
787         }
788
789         /**
790          * Test the Arrays::walkRecursive() function.
791          *
792          * @return void
793          */
794         public function testApiWalkRecursive()
795         {
796                 $array = ['item1'];
797                 self::assertEquals(
798                         $array,
799                         Arrays::walkRecursive(
800                                 $array,
801                                 function () {
802                                         // Should we test this with a callback that actually does something?
803                                         return true;
804                                 }
805                         )
806                 );
807         }
808
809         /**
810          * Test the Arrays::walkRecursive() function with an array.
811          *
812          * @return void
813          */
814         public function testApiWalkRecursiveWithArray()
815         {
816                 $array = [['item1'], ['item2']];
817                 self::assertEquals(
818                         $array,
819                         Arrays::walkRecursive(
820                                 $array,
821                                 function () {
822                                         // Should we test this with a callback that actually does something?
823                                         return true;
824                                 }
825                         )
826                 );
827         }
828
829         /**
830          * Test the BaseApi::reformatXML() function.
831          *
832          * @return void
833          */
834         public function testApiReformatXml()
835         {
836                 $item = true;
837                 $key  = '';
838                 self::assertTrue(ApiResponse::reformatXML($item, $key));
839                 self::assertEquals('true', $item);
840         }
841
842         /**
843          * Test the BaseApi::reformatXML() function with a statusnet_api key.
844          *
845          * @return void
846          */
847         public function testApiReformatXmlWithStatusnetKey()
848         {
849                 $item = '';
850                 $key  = 'statusnet_api';
851                 self::assertTrue(ApiResponse::reformatXML($item, $key));
852                 self::assertEquals('statusnet:api', $key);
853         }
854
855         /**
856          * Test the BaseApi::reformatXML() function with a friendica_api key.
857          *
858          * @return void
859          */
860         public function testApiReformatXmlWithFriendicaKey()
861         {
862                 $item = '';
863                 $key  = 'friendica_api';
864                 self::assertTrue(ApiResponse::reformatXML($item, $key));
865                 self::assertEquals('friendica:api', $key);
866         }
867
868         /**
869          * Test the BaseApi::createXML() function.
870          *
871          * @return void
872          */
873         public function testApiCreateXml()
874         {
875                 self::assertEquals(
876                         '<?xml version="1.0"?>' . "\n" .
877                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
878                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
879                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
880                         '  <data>some_data</data>' . "\n" .
881                         '</root_element>' . "\n",
882                         DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
883                 );
884         }
885
886         /**
887          * Test the BaseApi::createXML() function without any XML namespace.
888          *
889          * @return void
890          */
891         public function testApiCreateXmlWithoutNamespaces()
892         {
893                 self::assertEquals(
894                         '<?xml version="1.0"?>' . "\n" .
895                         '<ok>' . "\n" .
896                         '  <data>some_data</data>' . "\n" .
897                         '</ok>' . "\n",
898                         DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
899                 );
900         }
901
902         /**
903          * Test the BaseApi::formatData() function.
904          *
905          * @return void
906          */
907         public function testApiFormatData()
908         {
909                 $data = ['some_data'];
910                 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
911         }
912
913         /**
914          * Test the BaseApi::formatData() function with an XML result.
915          *
916          * @return void
917          */
918         public function testApiFormatDataWithXml()
919         {
920                 self::assertEquals(
921                         '<?xml version="1.0"?>' . "\n" .
922                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
923                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
924                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
925                         '  <data>some_data</data>' . "\n" .
926                         '</root_element>' . "\n",
927                         DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
928                 );
929         }
930
931         /**
932          * Test the api_account_verify_credentials() function.
933          *
934          * @return void
935          */
936         public function testApiAccountVerifyCredentials()
937         {
938                 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
939         }
940
941         /**
942          * Test the api_account_verify_credentials() function without an authenticated user.
943          *
944          * @return void
945          */
946         public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
947         {
948                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
949                 BasicAuth::setCurrentUserID();
950                 $_SESSION['authenticated'] = false;
951                 api_account_verify_credentials('json');
952         }
953
954         /**
955          * Test the requestdata() function.
956          *
957          * @return void
958          */
959         public function testRequestdata()
960         {
961                 self::assertNull(requestdata('variable_name'));
962         }
963
964         /**
965          * Test the requestdata() function with a POST parameter.
966          *
967          * @return void
968          */
969         public function testRequestdataWithPost()
970         {
971                 $_POST['variable_name'] = 'variable_value';
972                 self::assertEquals('variable_value', requestdata('variable_name'));
973         }
974
975         /**
976          * Test the requestdata() function with a GET parameter.
977          *
978          * @return void
979          */
980         public function testRequestdataWithGet()
981         {
982                 $_GET['variable_name'] = 'variable_value';
983                 self::assertEquals('variable_value', requestdata('variable_name'));
984         }
985
986         /**
987          * Test the api_statuses_mediap() function.
988          *
989          * @return void
990          */
991         public function testApiStatusesMediap()
992         {
993                 DI::args()->setArgc(2);
994
995                 $_FILES         = [
996                         'media' => [
997                                 'id'       => 666,
998                                 'size'     => 666,
999                                 'width'    => 666,
1000                                 'height'   => 666,
1001                                 'tmp_name' => $this->getTempImage(),
1002                                 'name'     => 'spacer.png',
1003                                 'type'     => 'image/png'
1004                         ]
1005                 ];
1006                 $_GET['status'] = '<b>Status content</b>';
1007
1008                 $result = api_statuses_mediap('json');
1009                 self::assertStatus($result['status']);
1010         }
1011
1012         /**
1013          * Test the api_statuses_mediap() function without an authenticated user.
1014          *
1015          * @return void
1016          */
1017         public function testApiStatusesMediapWithoutAuthenticatedUser()
1018         {
1019                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1020                 BasicAuth::setCurrentUserID();
1021                 $_SESSION['authenticated'] = false;
1022                 api_statuses_mediap('json');
1023         }
1024
1025         /**
1026          * Test the api_statuses_update() function.
1027          *
1028          * @return void
1029          */
1030         public function testApiStatusesUpdate()
1031         {
1032                 $_GET['status']                = 'Status content #friendica';
1033                 $_GET['in_reply_to_status_id'] = -1;
1034                 $_GET['lat']                   = 48;
1035                 $_GET['long']                  = 7;
1036                 $_FILES                        = [
1037                         'media' => [
1038                                 'id'       => 666,
1039                                 'size'     => 666,
1040                                 'width'    => 666,
1041                                 'height'   => 666,
1042                                 'tmp_name' => $this->getTempImage(),
1043                                 'name'     => 'spacer.png',
1044                                 'type'     => 'image/png'
1045                         ]
1046                 ];
1047
1048                 $result = api_statuses_update('json');
1049                 self::assertStatus($result['status']);
1050         }
1051
1052         /**
1053          * Test the api_statuses_update() function with an HTML status.
1054          *
1055          * @return void
1056          */
1057         public function testApiStatusesUpdateWithHtml()
1058         {
1059                 $_GET['htmlstatus'] = '<b>Status content</b>';
1060
1061                 $result = api_statuses_update('json');
1062                 self::assertStatus($result['status']);
1063         }
1064
1065         /**
1066          * Test the api_statuses_update() function without an authenticated user.
1067          *
1068          * @return void
1069          */
1070         public function testApiStatusesUpdateWithoutAuthenticatedUser()
1071         {
1072                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1073                 BasicAuth::setCurrentUserID();
1074                 $_SESSION['authenticated'] = false;
1075                 api_statuses_update('json');
1076         }
1077
1078         /**
1079          * Test the api_statuses_update() function with a parent status.
1080          *
1081          * @return void
1082          */
1083         public function testApiStatusesUpdateWithParent()
1084         {
1085                 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1086         }
1087
1088         /**
1089          * Test the api_statuses_update() function with a media_ids parameter.
1090          *
1091          * @return void
1092          */
1093         public function testApiStatusesUpdateWithMediaIds()
1094         {
1095                 $this->markTestIncomplete();
1096         }
1097
1098         /**
1099          * Test the api_statuses_update() function with the throttle limit reached.
1100          *
1101          * @return void
1102          */
1103         public function testApiStatusesUpdateWithDayThrottleReached()
1104         {
1105                 $this->markTestIncomplete();
1106         }
1107
1108         /**
1109          * Test the api_media_upload() function.
1110          * @runInSeparateProcess
1111          * @preserveGlobalState disabled
1112          */
1113         public function testApiMediaUpload()
1114         {
1115                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1116                 api_media_upload();
1117         }
1118
1119         /**
1120          * Test the api_media_upload() function without an authenticated user.
1121          *
1122          * @return void
1123          */
1124         public function testApiMediaUploadWithoutAuthenticatedUser()
1125         {
1126                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1127                 BasicAuth::setCurrentUserID();
1128                 $_SESSION['authenticated'] = false;
1129                 api_media_upload();
1130         }
1131
1132         /**
1133          * Test the api_media_upload() function with an invalid uploaded media.
1134          *
1135          * @return void
1136          */
1137         public function testApiMediaUploadWithMedia()
1138         {
1139                 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1140                 $_FILES = [
1141                         'media' => [
1142                                 'id'       => 666,
1143                                 'tmp_name' => 'tmp_name'
1144                         ]
1145                 ];
1146                 api_media_upload();
1147         }
1148
1149         /**
1150          * Test the api_media_upload() function with an valid uploaded media.
1151          *
1152          * @return void
1153          */
1154         public function testApiMediaUploadWithValidMedia()
1155         {
1156                 $_FILES    = [
1157                         'media' => [
1158                                 'id'       => 666,
1159                                 'size'     => 666,
1160                                 'width'    => 666,
1161                                 'height'   => 666,
1162                                 'tmp_name' => $this->getTempImage(),
1163                                 'name'     => 'spacer.png',
1164                                 'type'     => 'image/png'
1165                         ]
1166                 ];
1167                 $app       = DI::app();
1168                 DI::args()->setArgc(2);
1169
1170                 $result = api_media_upload();
1171                 self::assertEquals('image/png', $result['media']['image']['image_type']);
1172                 self::assertEquals(1, $result['media']['image']['w']);
1173                 self::assertEquals(1, $result['media']['image']['h']);
1174                 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1175         }
1176
1177         /**
1178          * Test the api_status_show() function.
1179          */
1180         public function testApiStatusShowWithJson()
1181         {
1182                 $result = api_status_show('json', 1);
1183                 self::assertStatus($result['status']);
1184         }
1185
1186         /**
1187          * Test the api_status_show() function with an XML result.
1188          */
1189         public function testApiStatusShowWithXml()
1190         {
1191                 $result = api_status_show('xml', 1);
1192                 self::assertXml($result, 'statuses');
1193         }
1194
1195         /**
1196          * Test the api_get_last_status() function
1197          */
1198         public function testApiGetLastStatus()
1199         {
1200                 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1201
1202                 self::assertNotNull($item);
1203         }
1204
1205         /**
1206          * Test the api_users_show() function.
1207          *
1208          * @return void
1209          */
1210         public function testApiUsersShow()
1211         {
1212                 $result = api_users_show('json');
1213                 // We can't use assertSelfUser() here because the user object is missing some properties.
1214                 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1215                 self::assertEquals('DFRN', $result['user']['location']);
1216                 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1217                 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1218                 self::assertEquals('dfrn', $result['user']['network']);
1219                 self::assertTrue($result['user']['verified']);
1220         }
1221
1222         /**
1223          * Test the api_users_show() function with an XML result.
1224          *
1225          * @return void
1226          */
1227         public function testApiUsersShowWithXml()
1228         {
1229                 $result = api_users_show('xml');
1230                 self::assertXml($result, 'statuses');
1231         }
1232
1233         /**
1234          * Test the api_users_search() function.
1235          *
1236          * @return void
1237          */
1238         public function testApiUsersSearch()
1239         {
1240                 $_GET['q'] = 'othercontact';
1241                 $result    = api_users_search('json');
1242                 self::assertOtherUser($result['users'][0]);
1243         }
1244
1245         /**
1246          * Test the api_users_search() function with an XML result.
1247          *
1248          * @return void
1249          */
1250         public function testApiUsersSearchWithXml()
1251         {
1252                 $_GET['q'] = 'othercontact';
1253                 $result    = api_users_search('xml');
1254                 self::assertXml($result, 'users');
1255         }
1256
1257         /**
1258          * Test the api_users_search() function without a GET q parameter.
1259          *
1260          * @return void
1261          */
1262         public function testApiUsersSearchWithoutQuery()
1263         {
1264                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1265                 api_users_search('json');
1266         }
1267
1268         /**
1269          * Test the api_users_lookup() function.
1270          *
1271          * @return void
1272          */
1273         public function testApiUsersLookup()
1274         {
1275                 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1276                 api_users_lookup('json');
1277         }
1278
1279         /**
1280          * Test the api_users_lookup() function with an user ID.
1281          *
1282          * @return void
1283          */
1284         public function testApiUsersLookupWithUserId()
1285         {
1286                 $_REQUEST['user_id'] = $this->otherUser['id'];
1287                 $result              = api_users_lookup('json');
1288                 self::assertOtherUser($result['users'][0]);
1289         }
1290
1291         /**
1292          * Test the api_search() function.
1293          *
1294          * @return void
1295          */
1296         public function testApiSearch()
1297         {
1298                 $_REQUEST['q']      = 'reply';
1299                 $_REQUEST['max_id'] = 10;
1300                 $result             = api_search('json');
1301                 foreach ($result['status'] as $status) {
1302                         self::assertStatus($status);
1303                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1304                 }
1305         }
1306
1307         /**
1308          * Test the api_search() function a count parameter.
1309          *
1310          * @return void
1311          */
1312         public function testApiSearchWithCount()
1313         {
1314                 $_REQUEST['q']     = 'reply';
1315                 $_REQUEST['count'] = 20;
1316                 $result            = api_search('json');
1317                 foreach ($result['status'] as $status) {
1318                         self::assertStatus($status);
1319                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1320                 }
1321         }
1322
1323         /**
1324          * Test the api_search() function with an rpp parameter.
1325          *
1326          * @return void
1327          */
1328         public function testApiSearchWithRpp()
1329         {
1330                 $_REQUEST['q']   = 'reply';
1331                 $_REQUEST['rpp'] = 20;
1332                 $result          = api_search('json');
1333                 foreach ($result['status'] as $status) {
1334                         self::assertStatus($status);
1335                         self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1336                 }
1337         }
1338
1339         /**
1340          * Test the api_search() function with an q parameter contains hashtag.
1341          * @doesNotPerformAssertions
1342          */
1343         public function testApiSearchWithHashtag()
1344         {
1345                 $_REQUEST['q'] = '%23friendica';
1346                 $result        = api_search('json');
1347                 foreach ($result['status'] as $status) {
1348                         self::assertStatus($status);
1349                         self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1350                 }
1351         }
1352
1353         /**
1354          * Test the api_search() function with an exclude_replies parameter.
1355          * @doesNotPerformAssertions
1356          */
1357         public function testApiSearchWithExcludeReplies()
1358         {
1359                 $_REQUEST['max_id']          = 10;
1360                 $_REQUEST['exclude_replies'] = true;
1361                 $_REQUEST['q']               = 'friendica';
1362                 $result                      = api_search('json');
1363                 foreach ($result['status'] as $status) {
1364                         self::assertStatus($status);
1365                 }
1366         }
1367
1368         /**
1369          * Test the api_search() function without an authenticated user.
1370          *
1371          * @return void
1372          */
1373         public function testApiSearchWithUnallowedUser()
1374         {
1375                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1376                 BasicAuth::setCurrentUserID();
1377                 api_search('json');
1378         }
1379
1380         /**
1381          * Test the api_search() function without any GET query parameter.
1382          *
1383          * @return void
1384          */
1385         public function testApiSearchWithoutQuery()
1386         {
1387                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1388                 api_search('json');
1389         }
1390
1391         /**
1392          * Test the api_statuses_home_timeline() function.
1393          *
1394          * @return void
1395          */
1396         public function testApiStatusesHomeTimeline()
1397         {
1398                 $_REQUEST['max_id']          = 10;
1399                 $_REQUEST['exclude_replies'] = true;
1400                 $_REQUEST['conversation_id'] = 1;
1401                 $result                      = api_statuses_home_timeline('json');
1402                 self::assertNotEmpty($result['status']);
1403                 foreach ($result['status'] as $status) {
1404                         self::assertStatus($status);
1405                 }
1406         }
1407
1408         /**
1409          * Test the api_statuses_home_timeline() function with a negative page parameter.
1410          *
1411          * @return void
1412          */
1413         public function testApiStatusesHomeTimelineWithNegativePage()
1414         {
1415                 $_REQUEST['page'] = -2;
1416                 $result           = api_statuses_home_timeline('json');
1417                 self::assertNotEmpty($result['status']);
1418                 foreach ($result['status'] as $status) {
1419                         self::assertStatus($status);
1420                 }
1421         }
1422
1423         /**
1424          * Test the api_statuses_home_timeline() with an unallowed user.
1425          *
1426          * @return void
1427          */
1428         public function testApiStatusesHomeTimelineWithUnallowedUser()
1429         {
1430                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1431                 BasicAuth::setCurrentUserID();
1432                 api_statuses_home_timeline('json');
1433         }
1434
1435         /**
1436          * Test the api_statuses_home_timeline() function with an RSS result.
1437          *
1438          * @return void
1439          */
1440         public function testApiStatusesHomeTimelineWithRss()
1441         {
1442                 $result = api_statuses_home_timeline('rss');
1443                 self::assertXml($result, 'statuses');
1444         }
1445
1446         /**
1447          * Test the api_statuses_public_timeline() function.
1448          *
1449          * @return void
1450          */
1451         public function testApiStatusesPublicTimeline()
1452         {
1453                 $_REQUEST['max_id']          = 10;
1454                 $_REQUEST['conversation_id'] = 1;
1455                 $result                      = api_statuses_public_timeline('json');
1456                 self::assertNotEmpty($result['status']);
1457                 foreach ($result['status'] as $status) {
1458                         self::assertStatus($status);
1459                 }
1460         }
1461
1462         /**
1463          * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1464          *
1465          * @return void
1466          */
1467         public function testApiStatusesPublicTimelineWithExcludeReplies()
1468         {
1469                 $_REQUEST['max_id']          = 10;
1470                 $_REQUEST['exclude_replies'] = true;
1471                 $result                      = api_statuses_public_timeline('json');
1472                 self::assertNotEmpty($result['status']);
1473                 foreach ($result['status'] as $status) {
1474                         self::assertStatus($status);
1475                 }
1476         }
1477
1478         /**
1479          * Test the api_statuses_public_timeline() function with a negative page parameter.
1480          *
1481          * @return void
1482          */
1483         public function testApiStatusesPublicTimelineWithNegativePage()
1484         {
1485                 $_REQUEST['page'] = -2;
1486                 $result           = api_statuses_public_timeline('json');
1487                 self::assertNotEmpty($result['status']);
1488                 foreach ($result['status'] as $status) {
1489                         self::assertStatus($status);
1490                 }
1491         }
1492
1493         /**
1494          * Test the api_statuses_public_timeline() function with an unallowed user.
1495          *
1496          * @return void
1497          */
1498         public function testApiStatusesPublicTimelineWithUnallowedUser()
1499         {
1500                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1501                 BasicAuth::setCurrentUserID();
1502                 api_statuses_public_timeline('json');
1503         }
1504
1505         /**
1506          * Test the api_statuses_public_timeline() function with an RSS result.
1507          *
1508          * @return void
1509          */
1510         public function testApiStatusesPublicTimelineWithRss()
1511         {
1512                 $result = api_statuses_public_timeline('rss');
1513                 self::assertXml($result, 'statuses');
1514         }
1515
1516         /**
1517          * Test the api_statuses_networkpublic_timeline() function.
1518          *
1519          * @return void
1520          */
1521         public function testApiStatusesNetworkpublicTimeline()
1522         {
1523                 $_REQUEST['max_id'] = 10;
1524                 $result             = api_statuses_networkpublic_timeline('json');
1525                 self::assertNotEmpty($result['status']);
1526                 foreach ($result['status'] as $status) {
1527                         self::assertStatus($status);
1528                 }
1529         }
1530
1531         /**
1532          * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1533          *
1534          * @return void
1535          */
1536         public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1537         {
1538                 $_REQUEST['page'] = -2;
1539                 $result           = api_statuses_networkpublic_timeline('json');
1540                 self::assertNotEmpty($result['status']);
1541                 foreach ($result['status'] as $status) {
1542                         self::assertStatus($status);
1543                 }
1544         }
1545
1546         /**
1547          * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1548          *
1549          * @return void
1550          */
1551         public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1552         {
1553                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1554                 BasicAuth::setCurrentUserID();
1555                 api_statuses_networkpublic_timeline('json');
1556         }
1557
1558         /**
1559          * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1560          *
1561          * @return void
1562          */
1563         public function testApiStatusesNetworkpublicTimelineWithRss()
1564         {
1565                 $result = api_statuses_networkpublic_timeline('rss');
1566                 self::assertXml($result, 'statuses');
1567         }
1568
1569         /**
1570          * Test the api_statuses_show() function.
1571          *
1572          * @return void
1573          */
1574         public function testApiStatusesShow()
1575         {
1576                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1577                 api_statuses_show('json');
1578         }
1579
1580         /**
1581          * Test the api_statuses_show() function with an ID.
1582          *
1583          * @return void
1584          */
1585         public function testApiStatusesShowWithId()
1586         {
1587                 DI::args()->setArgv(['', '', '', 1]);
1588                 $result = api_statuses_show('json');
1589                 self::assertStatus($result['status']);
1590         }
1591
1592         /**
1593          * Test the api_statuses_show() function with the conversation parameter.
1594          *
1595          * @return void
1596          */
1597         public function testApiStatusesShowWithConversation()
1598         {
1599                 DI::args()->setArgv(['', '', '', 1]);
1600                 $_REQUEST['conversation'] = 1;
1601                 $result                   = api_statuses_show('json');
1602                 self::assertNotEmpty($result['status']);
1603                 foreach ($result['status'] as $status) {
1604                         self::assertStatus($status);
1605                 }
1606         }
1607
1608         /**
1609          * Test the api_statuses_show() function with an unallowed user.
1610          *
1611          * @return void
1612          */
1613         public function testApiStatusesShowWithUnallowedUser()
1614         {
1615                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1616                 BasicAuth::setCurrentUserID();
1617                 api_statuses_show('json');
1618         }
1619
1620         /**
1621          * Test the api_conversation_show() function.
1622          *
1623          * @return void
1624          */
1625         public function testApiConversationShow()
1626         {
1627                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1628                 api_conversation_show('json');
1629         }
1630
1631         /**
1632          * Test the api_conversation_show() function with an ID.
1633          *
1634          * @return void
1635          */
1636         public function testApiConversationShowWithId()
1637         {
1638                 DI::args()->setArgv(['', '', '', 1]);
1639                 $_REQUEST['max_id'] = 10;
1640                 $_REQUEST['page']   = -2;
1641                 $result             = api_conversation_show('json');
1642                 self::assertNotEmpty($result['status']);
1643                 foreach ($result['status'] as $status) {
1644                         self::assertStatus($status);
1645                 }
1646         }
1647
1648         /**
1649          * Test the api_conversation_show() function with an unallowed user.
1650          *
1651          * @return void
1652          */
1653         public function testApiConversationShowWithUnallowedUser()
1654         {
1655                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1656                 BasicAuth::setCurrentUserID();
1657                 api_conversation_show('json');
1658         }
1659
1660         /**
1661          * Test the api_statuses_repeat() function.
1662          *
1663          * @return void
1664          */
1665         public function testApiStatusesRepeat()
1666         {
1667                 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1668                 api_statuses_repeat('json');
1669         }
1670
1671         /**
1672          * Test the api_statuses_repeat() function without an authenticated user.
1673          *
1674          * @return void
1675          */
1676         public function testApiStatusesRepeatWithoutAuthenticatedUser()
1677         {
1678                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1679                 BasicAuth::setCurrentUserID();
1680                 $_SESSION['authenticated'] = false;
1681                 api_statuses_repeat('json');
1682         }
1683
1684         /**
1685          * Test the api_statuses_repeat() function with an ID.
1686          *
1687          * @return void
1688          */
1689         public function testApiStatusesRepeatWithId()
1690         {
1691                 DI::args()->setArgv(['', '', '', 1]);
1692                 $result = api_statuses_repeat('json');
1693                 self::assertStatus($result['status']);
1694
1695                 // Also test with a shared status
1696                 DI::args()->setArgv(['', '', '', 5]);
1697                 $result = api_statuses_repeat('json');
1698                 self::assertStatus($result['status']);
1699         }
1700
1701         /**
1702          * Test the api_statuses_destroy() function.
1703          *
1704          * @return void
1705          */
1706         public function testApiStatusesDestroy()
1707         {
1708                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1709                 api_statuses_destroy('json');
1710         }
1711
1712         /**
1713          * Test the api_statuses_destroy() function without an authenticated user.
1714          *
1715          * @return void
1716          */
1717         public function testApiStatusesDestroyWithoutAuthenticatedUser()
1718         {
1719                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1720                 BasicAuth::setCurrentUserID();
1721                 $_SESSION['authenticated'] = false;
1722                 api_statuses_destroy('json');
1723         }
1724
1725         /**
1726          * Test the api_statuses_destroy() function with an ID.
1727          *
1728          * @return void
1729          */
1730         public function testApiStatusesDestroyWithId()
1731         {
1732                 DI::args()->setArgv(['', '', '', 1]);
1733                 $result = api_statuses_destroy('json');
1734                 self::assertStatus($result['status']);
1735         }
1736
1737         /**
1738          * Test the api_statuses_mentions() function.
1739          *
1740          * @return void
1741          */
1742         public function testApiStatusesMentions()
1743         {
1744                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1745                 $_REQUEST['max_id'] = 10;
1746                 $result             = api_statuses_mentions('json');
1747                 self::assertEmpty($result['status']);
1748                 // We should test with mentions in the database.
1749         }
1750
1751         /**
1752          * Test the api_statuses_mentions() function with a negative page parameter.
1753          *
1754          * @return void
1755          */
1756         public function testApiStatusesMentionsWithNegativePage()
1757         {
1758                 $_REQUEST['page'] = -2;
1759                 $result           = api_statuses_mentions('json');
1760                 self::assertEmpty($result['status']);
1761         }
1762
1763         /**
1764          * Test the api_statuses_mentions() function with an unallowed user.
1765          *
1766          * @return void
1767          */
1768         public function testApiStatusesMentionsWithUnallowedUser()
1769         {
1770                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1771                 BasicAuth::setCurrentUserID();
1772                 api_statuses_mentions('json');
1773         }
1774
1775         /**
1776          * Test the api_statuses_mentions() function with an RSS result.
1777          *
1778          * @return void
1779          */
1780         public function testApiStatusesMentionsWithRss()
1781         {
1782                 $result = api_statuses_mentions('rss');
1783                 self::assertXml($result, 'statuses');
1784         }
1785
1786         /**
1787          * Test the api_statuses_user_timeline() function.
1788          *
1789          * @return void
1790          */
1791         public function testApiStatusesUserTimeline()
1792         {
1793                 $_REQUEST['max_id']          = 10;
1794                 $_REQUEST['exclude_replies'] = true;
1795                 $_REQUEST['conversation_id'] = 1;
1796                 $result                      = api_statuses_user_timeline('json');
1797                 self::assertNotEmpty($result['status']);
1798                 foreach ($result['status'] as $status) {
1799                         self::assertStatus($status);
1800                 }
1801         }
1802
1803         /**
1804          * Test the api_statuses_user_timeline() function with a negative page parameter.
1805          *
1806          * @return void
1807          */
1808         public function testApiStatusesUserTimelineWithNegativePage()
1809         {
1810                 $_REQUEST['page'] = -2;
1811                 $result           = api_statuses_user_timeline('json');
1812                 self::assertNotEmpty($result['status']);
1813                 foreach ($result['status'] as $status) {
1814                         self::assertStatus($status);
1815                 }
1816         }
1817
1818         /**
1819          * Test the api_statuses_user_timeline() function with an RSS result.
1820          *
1821          * @return void
1822          */
1823         public function testApiStatusesUserTimelineWithRss()
1824         {
1825                 $result = api_statuses_user_timeline('rss');
1826                 self::assertXml($result, 'statuses');
1827         }
1828
1829         /**
1830          * Test the api_statuses_user_timeline() function with an unallowed user.
1831          *
1832          * @return void
1833          */
1834         public function testApiStatusesUserTimelineWithUnallowedUser()
1835         {
1836                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1837                 BasicAuth::setCurrentUserID();
1838                 api_statuses_user_timeline('json');
1839         }
1840
1841         /**
1842          * Test the api_favorites_create_destroy() function.
1843          *
1844          * @return void
1845          */
1846         public function testApiFavoritesCreateDestroy()
1847         {
1848                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1849                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1850                 api_favorites_create_destroy('json');
1851         }
1852
1853         /**
1854          * Test the api_favorites_create_destroy() function with an invalid ID.
1855          *
1856          * @return void
1857          */
1858         public function testApiFavoritesCreateDestroyWithInvalidId()
1859         {
1860                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1861                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1862                 api_favorites_create_destroy('json');
1863         }
1864
1865         /**
1866          * Test the api_favorites_create_destroy() function with an invalid action.
1867          *
1868          * @return void
1869          */
1870         public function testApiFavoritesCreateDestroyWithInvalidAction()
1871         {
1872                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1873                 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1874                 $_REQUEST['id'] = 1;
1875                 api_favorites_create_destroy('json');
1876         }
1877
1878         /**
1879          * Test the api_favorites_create_destroy() function with the create action.
1880          *
1881          * @return void
1882          */
1883         public function testApiFavoritesCreateDestroyWithCreateAction()
1884         {
1885                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1886                 $_REQUEST['id'] = 3;
1887                 $result         = api_favorites_create_destroy('json');
1888                 self::assertStatus($result['status']);
1889         }
1890
1891         /**
1892          * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1893          *
1894          * @return void
1895          */
1896         public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1897         {
1898                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1899                 $_REQUEST['id'] = 3;
1900                 $result         = api_favorites_create_destroy('rss');
1901                 self::assertXml($result, 'status');
1902         }
1903
1904         /**
1905          * Test the api_favorites_create_destroy() function with the destroy action.
1906          *
1907          * @return void
1908          */
1909         public function testApiFavoritesCreateDestroyWithDestroyAction()
1910         {
1911                 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1912                 $_REQUEST['id'] = 3;
1913                 $result         = api_favorites_create_destroy('json');
1914                 self::assertStatus($result['status']);
1915         }
1916
1917         /**
1918          * Test the api_favorites_create_destroy() function without an authenticated user.
1919          *
1920          * @return void
1921          */
1922         public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1923         {
1924                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1925                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1926                 BasicAuth::setCurrentUserID();
1927                 $_SESSION['authenticated'] = false;
1928                 api_favorites_create_destroy('json');
1929         }
1930
1931         /**
1932          * Test the api_favorites() function.
1933          *
1934          * @return void
1935          */
1936         public function testApiFavorites()
1937         {
1938                 $_REQUEST['page']   = -1;
1939                 $_REQUEST['max_id'] = 10;
1940                 $result             = api_favorites('json');
1941                 foreach ($result['status'] as $status) {
1942                         self::assertStatus($status);
1943                 }
1944         }
1945
1946         /**
1947          * Test the api_favorites() function with an RSS result.
1948          *
1949          * @return void
1950          */
1951         public function testApiFavoritesWithRss()
1952         {
1953                 $result = api_favorites('rss');
1954                 self::assertXml($result, 'statuses');
1955         }
1956
1957         /**
1958          * Test the api_favorites() function with an unallowed user.
1959          *
1960          * @return void
1961          */
1962         public function testApiFavoritesWithUnallowedUser()
1963         {
1964                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1965                 BasicAuth::setCurrentUserID();
1966                 api_favorites('json');
1967         }
1968
1969         /**
1970          * Test the api_format_messages() function.
1971          *
1972          * @return void
1973          */
1974         public function testApiFormatMessages()
1975         {
1976                 $result = api_format_messages(
1977                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1978                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1979                         ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
1980                 );
1981                 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
1982                 self::assertEquals(1, $result['id']);
1983                 self::assertEquals(2, $result['recipient_id']);
1984                 self::assertEquals(3, $result['sender_id']);
1985                 self::assertEquals('recipient_name', $result['recipient_screen_name']);
1986                 self::assertEquals('sender_name', $result['sender_screen_name']);
1987         }
1988
1989         /**
1990          * Test the api_format_messages() function with HTML.
1991          *
1992          * @return void
1993          */
1994         public function testApiFormatMessagesWithHtmlText()
1995         {
1996                 $_GET['getText'] = 'html';
1997                 $result          = api_format_messages(
1998                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1999                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2000                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2001                 );
2002                 self::assertEquals('item_title', $result['title']);
2003                 self::assertEquals('<strong>item_body</strong>', $result['text']);
2004         }
2005
2006         /**
2007          * Test the api_format_messages() function with plain text.
2008          *
2009          * @return void
2010          */
2011         public function testApiFormatMessagesWithPlainText()
2012         {
2013                 $_GET['getText'] = 'plain';
2014                 $result          = api_format_messages(
2015                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2016                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2017                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2018                 );
2019                 self::assertEquals('item_title', $result['title']);
2020                 self::assertEquals('item_body', $result['text']);
2021         }
2022
2023         /**
2024          * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2025          *
2026          * @return void
2027          */
2028         public function testApiFormatMessagesWithoutUserObjects()
2029         {
2030                 $_GET['getUserObjects'] = 'false';
2031                 $result                 = api_format_messages(
2032                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2033                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2034                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2035                 );
2036                 self::assertTrue(!isset($result['sender']));
2037                 self::assertTrue(!isset($result['recipient']));
2038         }
2039
2040         /**
2041          * Test the api_convert_item() function.
2042          *
2043          * @return void
2044          */
2045         public function testApiConvertItem()
2046         {
2047                 $result = api_convert_item(
2048                         [
2049                                 'network' => 'feed',
2050                                 'title'   => 'item_title',
2051                                 'uri-id'  => 1,
2052                                 // We need a long string to test that it is correctly cut
2053                                 'body'    => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2054                                                          'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2055                                                          'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2056                                                          'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2057                                                          'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2058                                                          'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2059                                                          'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2060                                                          'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2061                                                          'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2062                                                          'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2063                                                          'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2064                                                          'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2065                                                          'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2066                                                          'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2067                                                          'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2068                                                          'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2069                                                          'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2070                                                          'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2071                                                          'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2072                                                          'repellat officia illum quos impedit quam iste esse unde qui ' .
2073                                                          'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2074                                                          'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2075                                                          'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2076                                 'plink'   => 'item_plink'
2077                         ]
2078                 );
2079                 self::assertStringStartsWith('item_title', $result['text']);
2080                 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2081         }
2082
2083         /**
2084          * Test the api_convert_item() function with an empty item body.
2085          *
2086          * @return void
2087          */
2088         public function testApiConvertItemWithoutBody()
2089         {
2090                 $result = api_convert_item(
2091                         [
2092                                 'network' => 'feed',
2093                                 'title'   => 'item_title',
2094                                 'uri-id'  => -1,
2095                                 'body'    => '',
2096                                 'plink'   => 'item_plink'
2097                         ]
2098                 );
2099                 self::assertEquals("item_title", $result['text']);
2100                 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2101         }
2102
2103         /**
2104          * Test the api_convert_item() function with the title in the body.
2105          *
2106          * @return void
2107          */
2108         public function testApiConvertItemWithTitleInBody()
2109         {
2110                 $result = api_convert_item(
2111                         [
2112                                 'title'  => 'item_title',
2113                                 'body'   => 'item_title item_body',
2114                                 'uri-id' => 1,
2115                         ]
2116                 );
2117                 self::assertEquals('item_title item_body', $result['text']);
2118                 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2119         }
2120
2121         /**
2122          * Test the api_get_attachments() function.
2123          *
2124          * @return void
2125          */
2126         public function testApiGetAttachments()
2127         {
2128                 $body = 'body';
2129                 self::assertEmpty(api_get_attachments($body, 0));
2130         }
2131
2132         /**
2133          * Test the api_get_attachments() function with an img tag.
2134          *
2135          * @return void
2136          */
2137         public function testApiGetAttachmentsWithImage()
2138         {
2139                 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2140                 self::assertIsArray(api_get_attachments($body, 0));
2141         }
2142
2143         /**
2144          * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2145          *
2146          * @return void
2147          */
2148         public function testApiGetAttachmentsWithImageAndAndStatus()
2149         {
2150                 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2151                 $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
2152                 self::assertIsArray(api_get_attachments($body, 0));
2153         }
2154
2155         /**
2156          * Test the api_get_entitities() function.
2157          *
2158          * @return void
2159          */
2160         public function testApiGetEntitities()
2161         {
2162                 $text = 'text';
2163                 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2164         }
2165
2166         /**
2167          * Test the api_get_entitities() function with the include_entities parameter.
2168          *
2169          * @return void
2170          */
2171         public function testApiGetEntititiesWithIncludeEntities()
2172         {
2173                 $_REQUEST['include_entities'] = 'true';
2174                 $text                         = 'text';
2175                 $result                       = api_get_entitities($text, 'bbcode', 0);
2176                 self::assertIsArray($result['hashtags']);
2177                 self::assertIsArray($result['symbols']);
2178                 self::assertIsArray($result['urls']);
2179                 self::assertIsArray($result['user_mentions']);
2180         }
2181
2182         /**
2183          * Test the api_format_items_embeded_images() function.
2184          *
2185          * @return void
2186          */
2187         public function testApiFormatItemsEmbededImages()
2188         {
2189                 self::assertEquals(
2190                         'text ' . DI::baseUrl() . '/display/item_guid',
2191                         api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2192                 );
2193         }
2194
2195         /**
2196          * Test the api_contactlink_to_array() function.
2197          *
2198          * @return void
2199          */
2200         public function testApiContactlinkToArray()
2201         {
2202                 self::assertEquals(
2203                         [
2204                                 'name' => 'text',
2205                                 'url'  => '',
2206                         ],
2207                         api_contactlink_to_array('text')
2208                 );
2209         }
2210
2211         /**
2212          * Test the api_contactlink_to_array() function with an URL.
2213          *
2214          * @return void
2215          */
2216         public function testApiContactlinkToArrayWithUrl()
2217         {
2218                 self::assertEquals(
2219                         [
2220                                 'name' => ['link_text'],
2221                                 'url'  => ['url'],
2222                         ],
2223                         api_contactlink_to_array('text <a href="url">link_text</a>')
2224                 );
2225         }
2226
2227         /**
2228          * Test the api_format_items_activities() function.
2229          *
2230          * @return void
2231          */
2232         public function testApiFormatItemsActivities()
2233         {
2234                 $item   = ['uid' => 0, 'uri' => ''];
2235                 $result = api_format_items_activities($item);
2236                 self::assertArrayHasKey('like', $result);
2237                 self::assertArrayHasKey('dislike', $result);
2238                 self::assertArrayHasKey('attendyes', $result);
2239                 self::assertArrayHasKey('attendno', $result);
2240                 self::assertArrayHasKey('attendmaybe', $result);
2241         }
2242
2243         /**
2244          * Test the api_format_items_activities() function with an XML result.
2245          *
2246          * @return void
2247          */
2248         public function testApiFormatItemsActivitiesWithXml()
2249         {
2250                 $item   = ['uid' => 0, 'uri' => ''];
2251                 $result = api_format_items_activities($item, 'xml');
2252                 self::assertArrayHasKey('friendica:like', $result);
2253                 self::assertArrayHasKey('friendica:dislike', $result);
2254                 self::assertArrayHasKey('friendica:attendyes', $result);
2255                 self::assertArrayHasKey('friendica:attendno', $result);
2256                 self::assertArrayHasKey('friendica:attendmaybe', $result);
2257         }
2258
2259         /**
2260          * Test the api_format_items() function.
2261          * @doesNotPerformAssertions
2262          */
2263         public function testApiFormatItems()
2264         {
2265                 $items  = [
2266                         [
2267                                 'item_network'   => 'item_network',
2268                                 'source'         => 'web',
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);
2279                 foreach ($result as $status) {
2280                         self::assertStatus($status);
2281                 }
2282         }
2283
2284         /**
2285          * Test the api_format_items() function with an XML result.
2286          * @doesNotPerformAssertions
2287          */
2288         public function testApiFormatItemsWithXml()
2289         {
2290                 $items  = [
2291                         [
2292                                 'coord'          => '5 7',
2293                                 'body'           => '',
2294                                 'verb'           => '',
2295                                 'author-id'      => 43,
2296                                 'author-network' => Protocol::DFRN,
2297                                 'author-link'    => 'http://localhost/profile/othercontact',
2298                                 'plink'          => '',
2299                         ]
2300                 ];
2301                 $result = api_format_items($items, ['id' => 0], true, 'xml');
2302                 foreach ($result as $status) {
2303                         self::assertStatus($status);
2304                 }
2305         }
2306
2307         /**
2308          * Test the api_lists_list() function.
2309          *
2310          * @return void
2311          */
2312         public function testApiListsList()
2313         {
2314                 $result = api_lists_list('json');
2315                 self::assertEquals(['lists_list' => []], $result);
2316         }
2317
2318         /**
2319          * Test the api_lists_ownerships() function.
2320          *
2321          * @return void
2322          */
2323         public function testApiListsOwnerships()
2324         {
2325                 $result = api_lists_ownerships('json');
2326                 foreach ($result['lists']['lists'] as $list) {
2327                         self::assertList($list);
2328                 }
2329         }
2330
2331         /**
2332          * Test the api_lists_ownerships() function without an authenticated user.
2333          *
2334          * @return void
2335          */
2336         public function testApiListsOwnershipsWithoutAuthenticatedUser()
2337         {
2338                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2339                 BasicAuth::setCurrentUserID();
2340                 $_SESSION['authenticated'] = false;
2341                 api_lists_ownerships('json');
2342         }
2343
2344         /**
2345          * Test the api_lists_statuses() function.
2346          *
2347          * @return void
2348          */
2349         public function testApiListsStatuses()
2350         {
2351                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2352                 api_lists_statuses('json');
2353         }
2354
2355         /**
2356          * Test the api_lists_statuses() function with a list ID.
2357          * @doesNotPerformAssertions
2358          */
2359         public function testApiListsStatusesWithListId()
2360         {
2361                 $_REQUEST['list_id'] = 1;
2362                 $_REQUEST['page']    = -1;
2363                 $_REQUEST['max_id']  = 10;
2364                 $result              = api_lists_statuses('json');
2365                 foreach ($result['status'] as $status) {
2366                         self::assertStatus($status);
2367                 }
2368         }
2369
2370         /**
2371          * Test the api_lists_statuses() function with a list ID and a RSS result.
2372          *
2373          * @return void
2374          */
2375         public function testApiListsStatusesWithListIdAndRss()
2376         {
2377                 $_REQUEST['list_id'] = 1;
2378                 $result              = api_lists_statuses('rss');
2379                 self::assertXml($result, 'statuses');
2380         }
2381
2382         /**
2383          * Test the api_lists_statuses() function with an unallowed user.
2384          *
2385          * @return void
2386          */
2387         public function testApiListsStatusesWithUnallowedUser()
2388         {
2389                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2390                 BasicAuth::setCurrentUserID();
2391                 api_lists_statuses('json');
2392         }
2393
2394         /**
2395          * Test the api_statuses_f() function.
2396          *
2397          * @return void
2398          */
2399         public function testApiStatusesFWithFriends()
2400         {
2401                 $_GET['page'] = -1;
2402                 $result       = api_statuses_f('friends');
2403                 self::assertArrayHasKey('user', $result);
2404         }
2405
2406         /**
2407          * Test the api_statuses_f() function.
2408          *
2409          * @return void
2410          */
2411         public function testApiStatusesFWithFollowers()
2412         {
2413                 $result = api_statuses_f('followers');
2414                 self::assertArrayHasKey('user', $result);
2415         }
2416
2417         /**
2418          * Test the api_statuses_f() function.
2419          *
2420          * @return void
2421          */
2422         public function testApiStatusesFWithBlocks()
2423         {
2424                 $result = api_statuses_f('blocks');
2425                 self::assertArrayHasKey('user', $result);
2426         }
2427
2428         /**
2429          * Test the api_statuses_f() function.
2430          *
2431          * @return void
2432          */
2433         public function testApiStatusesFWithIncoming()
2434         {
2435                 $result = api_statuses_f('incoming');
2436                 self::assertArrayHasKey('user', $result);
2437         }
2438
2439         /**
2440          * Test the api_statuses_f() function an undefined cursor GET variable.
2441          *
2442          * @return void
2443          */
2444         public function testApiStatusesFWithUndefinedCursor()
2445         {
2446                 $_GET['cursor'] = 'undefined';
2447                 self::assertFalse(api_statuses_f('friends'));
2448         }
2449
2450         /**
2451          * Test the api_statuses_friends() function.
2452          *
2453          * @return void
2454          */
2455         public function testApiStatusesFriends()
2456         {
2457                 $result = api_statuses_friends('json');
2458                 self::assertArrayHasKey('user', $result);
2459         }
2460
2461         /**
2462          * Test the api_statuses_friends() function an undefined cursor GET variable.
2463          *
2464          * @return void
2465          */
2466         public function testApiStatusesFriendsWithUndefinedCursor()
2467         {
2468                 $_GET['cursor'] = 'undefined';
2469                 self::assertFalse(api_statuses_friends('json'));
2470         }
2471
2472         /**
2473          * Test the api_statuses_followers() function.
2474          *
2475          * @return void
2476          */
2477         public function testApiStatusesFollowers()
2478         {
2479                 $result = api_statuses_followers('json');
2480                 self::assertArrayHasKey('user', $result);
2481         }
2482
2483         /**
2484          * Test the api_statuses_followers() function an undefined cursor GET variable.
2485          *
2486          * @return void
2487          */
2488         public function testApiStatusesFollowersWithUndefinedCursor()
2489         {
2490                 $_GET['cursor'] = 'undefined';
2491                 self::assertFalse(api_statuses_followers('json'));
2492         }
2493
2494         /**
2495          * Test the api_blocks_list() function.
2496          *
2497          * @return void
2498          */
2499         public function testApiBlocksList()
2500         {
2501                 $result = api_blocks_list('json');
2502                 self::assertArrayHasKey('user', $result);
2503         }
2504
2505         /**
2506          * Test the api_blocks_list() function an undefined cursor GET variable.
2507          *
2508          * @return void
2509          */
2510         public function testApiBlocksListWithUndefinedCursor()
2511         {
2512                 $_GET['cursor'] = 'undefined';
2513                 self::assertFalse(api_blocks_list('json'));
2514         }
2515
2516         /**
2517          * Test the api_friendships_incoming() function.
2518          *
2519          * @return void
2520          */
2521         public function testApiFriendshipsIncoming()
2522         {
2523                 $result = api_friendships_incoming('json');
2524                 self::assertArrayHasKey('id', $result);
2525         }
2526
2527         /**
2528          * Test the api_friendships_incoming() function an undefined cursor GET variable.
2529          *
2530          * @return void
2531          */
2532         public function testApiFriendshipsIncomingWithUndefinedCursor()
2533         {
2534                 $_GET['cursor'] = 'undefined';
2535                 self::assertFalse(api_friendships_incoming('json'));
2536         }
2537
2538         /**
2539          * Test the api_statusnet_config() function.
2540          *
2541          * @return void
2542          */
2543         public function testApiStatusnetConfig()
2544         {
2545                 /*
2546                 $result = api_statusnet_config('json');
2547                 self::assertEquals('localhost', $result['config']['site']['server']);
2548                 self::assertEquals('default', $result['config']['site']['theme']);
2549                 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2550                 self::assertTrue($result['config']['site']['fancy']);
2551                 self::assertEquals('en', $result['config']['site']['language']);
2552                 self::assertEquals('UTC', $result['config']['site']['timezone']);
2553                 self::assertEquals(200000, $result['config']['site']['textlimit']);
2554                 self::assertEquals('false', $result['config']['site']['private']);
2555                 self::assertEquals('false', $result['config']['site']['ssl']);
2556                 self::assertEquals(30, $result['config']['site']['shorturllength']);
2557                 */
2558         }
2559
2560         /**
2561          * Test the api_direct_messages_new() function.
2562          *
2563          * @return void
2564          */
2565         public function testApiDirectMessagesNew()
2566         {
2567                 $result = api_direct_messages_new('json');
2568                 self::assertNull($result);
2569         }
2570
2571         /**
2572          * Test the api_direct_messages_new() function without an authenticated user.
2573          *
2574          * @return void
2575          */
2576         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2577         {
2578                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2579                 BasicAuth::setCurrentUserID();
2580                 $_SESSION['authenticated'] = false;
2581                 api_direct_messages_new('json');
2582         }
2583
2584         /**
2585          * Test the api_direct_messages_new() function with an user ID.
2586          *
2587          * @return void
2588          */
2589         public function testApiDirectMessagesNewWithUserId()
2590         {
2591                 $_POST['text']    = 'message_text';
2592                 $_POST['user_id'] = $this->otherUser['id'];
2593                 $result           = api_direct_messages_new('json');
2594                 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2595         }
2596
2597         /**
2598          * Test the api_direct_messages_new() function with a screen name.
2599          *
2600          * @return void
2601          */
2602         public function testApiDirectMessagesNewWithScreenName()
2603         {
2604                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2605                 $_POST['text']        = 'message_text';
2606                 $_POST['screen_name'] = $this->friendUser['nick'];
2607                 $result               = api_direct_messages_new('json');
2608                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2609                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2610                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2611         }
2612
2613         /**
2614          * Test the api_direct_messages_new() function with a title.
2615          *
2616          * @return void
2617          */
2618         public function testApiDirectMessagesNewWithTitle()
2619         {
2620                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2621                 $_POST['text']        = 'message_text';
2622                 $_POST['screen_name'] = $this->friendUser['nick'];
2623                 $_REQUEST['title']    = 'message_title';
2624                 $result               = api_direct_messages_new('json');
2625                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2626                 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2627                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2628                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2629         }
2630
2631         /**
2632          * Test the api_direct_messages_new() function with an RSS result.
2633          *
2634          * @return void
2635          */
2636         public function testApiDirectMessagesNewWithRss()
2637         {
2638                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2639                 $_POST['text']        = 'message_text';
2640                 $_POST['screen_name'] = $this->friendUser['nick'];
2641                 $result               = api_direct_messages_new('rss');
2642                 self::assertXml($result, 'direct-messages');
2643         }
2644
2645         /**
2646          * Test the api_direct_messages_destroy() function.
2647          *
2648          * @return void
2649          */
2650         public function testApiDirectMessagesDestroy()
2651         {
2652                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2653                 api_direct_messages_destroy('json');
2654         }
2655
2656         /**
2657          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2658          *
2659          * @return void
2660          */
2661         public function testApiDirectMessagesDestroyWithVerbose()
2662         {
2663                 $_GET['friendica_verbose'] = 'true';
2664                 $result                    = api_direct_messages_destroy('json');
2665                 self::assertEquals(
2666                         [
2667                                 '$result' => [
2668                                         'result'  => 'error',
2669                                         'message' => 'message id or parenturi not specified'
2670                                 ]
2671                         ],
2672                         $result
2673                 );
2674         }
2675
2676         /**
2677          * Test the api_direct_messages_destroy() function without an authenticated user.
2678          *
2679          * @return void
2680          */
2681         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2682         {
2683                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2684                 BasicAuth::setCurrentUserID();
2685                 $_SESSION['authenticated'] = false;
2686                 api_direct_messages_destroy('json');
2687         }
2688
2689         /**
2690          * Test the api_direct_messages_destroy() function with a non-zero ID.
2691          *
2692          * @return void
2693          */
2694         public function testApiDirectMessagesDestroyWithId()
2695         {
2696                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2697                 $_REQUEST['id'] = 1;
2698                 api_direct_messages_destroy('json');
2699         }
2700
2701         /**
2702          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2703          *
2704          * @return void
2705          */
2706         public function testApiDirectMessagesDestroyWithIdAndVerbose()
2707         {
2708                 $_REQUEST['id']                  = 1;
2709                 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2710                 $_GET['friendica_verbose']       = 'true';
2711                 $result                          = api_direct_messages_destroy('json');
2712                 self::assertEquals(
2713                         [
2714                                 '$result' => [
2715                                         'result'  => 'error',
2716                                         'message' => 'message id not in database'
2717                                 ]
2718                         ],
2719                         $result
2720                 );
2721         }
2722
2723         /**
2724          * Test the api_direct_messages_destroy() function with a non-zero ID.
2725          *
2726          * @return void
2727          */
2728         public function testApiDirectMessagesDestroyWithCorrectId()
2729         {
2730                 $this->markTestIncomplete('We need to add a dataset for this.');
2731         }
2732
2733         /**
2734          * Test the api_direct_messages_box() function.
2735          *
2736          * @return void
2737          */
2738         public function testApiDirectMessagesBoxWithSentbox()
2739         {
2740                 $_REQUEST['page']   = -1;
2741                 $_REQUEST['max_id'] = 10;
2742                 $result             = api_direct_messages_box('json', 'sentbox', 'false');
2743                 self::assertArrayHasKey('direct_message', $result);
2744         }
2745
2746         /**
2747          * Test the api_direct_messages_box() function.
2748          *
2749          * @return void
2750          */
2751         public function testApiDirectMessagesBoxWithConversation()
2752         {
2753                 $result = api_direct_messages_box('json', 'conversation', 'false');
2754                 self::assertArrayHasKey('direct_message', $result);
2755         }
2756
2757         /**
2758          * Test the api_direct_messages_box() function.
2759          *
2760          * @return void
2761          */
2762         public function testApiDirectMessagesBoxWithAll()
2763         {
2764                 $result = api_direct_messages_box('json', 'all', 'false');
2765                 self::assertArrayHasKey('direct_message', $result);
2766         }
2767
2768         /**
2769          * Test the api_direct_messages_box() function.
2770          *
2771          * @return void
2772          */
2773         public function testApiDirectMessagesBoxWithInbox()
2774         {
2775                 $result = api_direct_messages_box('json', 'inbox', 'false');
2776                 self::assertArrayHasKey('direct_message', $result);
2777         }
2778
2779         /**
2780          * Test the api_direct_messages_box() function.
2781          *
2782          * @return void
2783          */
2784         public function testApiDirectMessagesBoxWithVerbose()
2785         {
2786                 $result = api_direct_messages_box('json', 'sentbox', 'true');
2787                 self::assertEquals(
2788                         [
2789                                 '$result' => [
2790                                         'result'  => 'error',
2791                                         'message' => 'no mails available'
2792                                 ]
2793                         ],
2794                         $result
2795                 );
2796         }
2797
2798         /**
2799          * Test the api_direct_messages_box() function with a RSS result.
2800          *
2801          * @return void
2802          */
2803         public function testApiDirectMessagesBoxWithRss()
2804         {
2805                 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2806                 self::assertXml($result, 'direct-messages');
2807         }
2808
2809         /**
2810          * Test the api_direct_messages_box() function without an authenticated user.
2811          *
2812          * @return void
2813          */
2814         public function testApiDirectMessagesBoxWithUnallowedUser()
2815         {
2816                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2817                 BasicAuth::setCurrentUserID();
2818                 api_direct_messages_box('json', 'sentbox', 'false');
2819         }
2820
2821         /**
2822          * Test the api_direct_messages_sentbox() function.
2823          *
2824          * @return void
2825          */
2826         public function testApiDirectMessagesSentbox()
2827         {
2828                 $result = api_direct_messages_sentbox('json');
2829                 self::assertArrayHasKey('direct_message', $result);
2830         }
2831
2832         /**
2833          * Test the api_direct_messages_inbox() function.
2834          *
2835          * @return void
2836          */
2837         public function testApiDirectMessagesInbox()
2838         {
2839                 $result = api_direct_messages_inbox('json');
2840                 self::assertArrayHasKey('direct_message', $result);
2841         }
2842
2843         /**
2844          * Test the api_direct_messages_all() function.
2845          *
2846          * @return void
2847          */
2848         public function testApiDirectMessagesAll()
2849         {
2850                 $result = api_direct_messages_all('json');
2851                 self::assertArrayHasKey('direct_message', $result);
2852         }
2853
2854         /**
2855          * Test the api_direct_messages_conversation() function.
2856          *
2857          * @return void
2858          */
2859         public function testApiDirectMessagesConversation()
2860         {
2861                 $result = api_direct_messages_conversation('json');
2862                 self::assertArrayHasKey('direct_message', $result);
2863         }
2864
2865         /**
2866          * Test the api_oauth_request_token() function.
2867          *
2868          * @return void
2869          */
2870         public function testApiOauthRequestToken()
2871         {
2872                 $this->markTestIncomplete('exit() kills phpunit as well');
2873         }
2874
2875         /**
2876          * Test the api_oauth_access_token() function.
2877          *
2878          * @return void
2879          */
2880         public function testApiOauthAccessToken()
2881         {
2882                 $this->markTestIncomplete('exit() kills phpunit as well');
2883         }
2884
2885         /**
2886          * Test the api_fr_photos_list() function.
2887          *
2888          * @return void
2889          */
2890         public function testApiFrPhotosList()
2891         {
2892                 $result = api_fr_photos_list('json');
2893                 self::assertArrayHasKey('photo', $result);
2894         }
2895
2896         /**
2897          * Test the api_fr_photos_list() function without an authenticated user.
2898          *
2899          * @return void
2900          */
2901         public function testApiFrPhotosListWithoutAuthenticatedUser()
2902         {
2903                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2904                 BasicAuth::setCurrentUserID();
2905                 $_SESSION['authenticated'] = false;
2906                 api_fr_photos_list('json');
2907         }
2908
2909         /**
2910          * Test the api_fr_photo_create_update() function.
2911          */
2912         public function testApiFrPhotoCreateUpdate()
2913         {
2914                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2915                 api_fr_photo_create_update('json');
2916         }
2917
2918         /**
2919          * Test the api_fr_photo_create_update() function without an authenticated user.
2920          *
2921          * @return void
2922          */
2923         public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
2924         {
2925                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2926                 BasicAuth::setCurrentUserID();
2927                 $_SESSION['authenticated'] = false;
2928                 api_fr_photo_create_update('json');
2929         }
2930
2931         /**
2932          * Test the api_fr_photo_create_update() function with an album name.
2933          *
2934          * @return void
2935          */
2936         public function testApiFrPhotoCreateUpdateWithAlbum()
2937         {
2938                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2939                 $_REQUEST['album'] = 'album_name';
2940                 api_fr_photo_create_update('json');
2941         }
2942
2943         /**
2944          * Test the api_fr_photo_create_update() function with the update mode.
2945          *
2946          * @return void
2947          */
2948         public function testApiFrPhotoCreateUpdateWithUpdate()
2949         {
2950                 $this->markTestIncomplete('We need to create a dataset for this');
2951         }
2952
2953         /**
2954          * Test the api_fr_photo_create_update() function with an uploaded file.
2955          *
2956          * @return void
2957          */
2958         public function testApiFrPhotoCreateUpdateWithFile()
2959         {
2960                 $this->markTestIncomplete();
2961         }
2962
2963         /**
2964          * Test the api_fr_photo_detail() function.
2965          *
2966          * @return void
2967          */
2968         public function testApiFrPhotoDetail()
2969         {
2970                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2971                 api_fr_photo_detail('json');
2972         }
2973
2974         /**
2975          * Test the api_fr_photo_detail() function without an authenticated user.
2976          *
2977          * @return void
2978          */
2979         public function testApiFrPhotoDetailWithoutAuthenticatedUser()
2980         {
2981                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2982                 BasicAuth::setCurrentUserID();
2983                 $_SESSION['authenticated'] = false;
2984                 api_fr_photo_detail('json');
2985         }
2986
2987         /**
2988          * Test the api_fr_photo_detail() function with a photo ID.
2989          *
2990          * @return void
2991          */
2992         public function testApiFrPhotoDetailWithPhotoId()
2993         {
2994                 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
2995                 $_REQUEST['photo_id'] = 1;
2996                 api_fr_photo_detail('json');
2997         }
2998
2999         /**
3000          * Test the api_fr_photo_detail() function with a correct photo ID.
3001          *
3002          * @return void
3003          */
3004         public function testApiFrPhotoDetailCorrectPhotoId()
3005         {
3006                 $this->markTestIncomplete('We need to create a dataset for this.');
3007         }
3008
3009         /**
3010          * Test the api_account_update_profile_image() function.
3011          *
3012          * @return void
3013          */
3014         public function testApiAccountUpdateProfileImage()
3015         {
3016                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3017                 api_account_update_profile_image('json');
3018         }
3019
3020         /**
3021          * Test the api_account_update_profile_image() function without an authenticated user.
3022          *
3023          * @return void
3024          */
3025         public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3026         {
3027                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
3028                 BasicAuth::setCurrentUserID();
3029                 $_SESSION['authenticated'] = false;
3030                 api_account_update_profile_image('json');
3031         }
3032
3033         /**
3034          * Test the api_account_update_profile_image() function with an uploaded file.
3035          *
3036          * @return void
3037          */
3038         public function testApiAccountUpdateProfileImageWithUpload()
3039         {
3040                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3041                 $this->markTestIncomplete();
3042         }
3043
3044
3045         /**
3046          * Test the api_account_update_profile() function.
3047          *
3048          * @return void
3049          */
3050         public function testApiAccountUpdateProfile()
3051         {
3052                 $_POST['name']        = 'new_name';
3053                 $_POST['description'] = 'new_description';
3054                 $result               = api_account_update_profile('json');
3055                 // We can't use assertSelfUser() here because the user object is missing some properties.
3056                 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3057                 self::assertEquals('DFRN', $result['user']['location']);
3058                 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3059                 self::assertEquals('dfrn', $result['user']['network']);
3060                 self::assertEquals('new_name', $result['user']['name']);
3061                 self::assertEquals('new_description', $result['user']['description']);
3062         }
3063
3064         /**
3065          * Test the check_acl_input() function.
3066          *
3067          * @return void
3068          */
3069         public function testCheckAclInput()
3070         {
3071                 $result = check_acl_input('<aclstring>');
3072                 // Where does this result come from?
3073                 self::assertEquals(1, $result);
3074         }
3075
3076         /**
3077          * Test the check_acl_input() function with an empty ACL string.
3078          *
3079          * @return void
3080          */
3081         public function testCheckAclInputWithEmptyAclString()
3082         {
3083                 $result = check_acl_input(' ');
3084                 self::assertFalse($result);
3085         }
3086
3087         /**
3088          * Test the save_media_to_database() function.
3089          *
3090          * @return void
3091          */
3092         public function testSaveMediaToDatabase()
3093         {
3094                 $this->markTestIncomplete();
3095         }
3096
3097         /**
3098          * Test the post_photo_item() function.
3099          *
3100          * @return void
3101          */
3102         public function testPostPhotoItem()
3103         {
3104                 $this->markTestIncomplete();
3105         }
3106
3107         /**
3108          * Test the prepare_photo_data() function.
3109          *
3110          * @return void
3111          */
3112         public function testPreparePhotoData()
3113         {
3114                 $this->markTestIncomplete();
3115         }
3116
3117         /**
3118          * Test the api_share_as_retweet() function with a valid item.
3119          *
3120          * @return void
3121          */
3122         public function testApiShareAsRetweetWithValidItem()
3123         {
3124                 $this->markTestIncomplete();
3125         }
3126
3127         /**
3128          * Test the api_in_reply_to() function.
3129          *
3130          * @return void
3131          */
3132         public function testApiInReplyTo()
3133         {
3134                 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3135                 self::assertArrayHasKey('status_id', $result);
3136                 self::assertArrayHasKey('user_id', $result);
3137                 self::assertArrayHasKey('status_id_str', $result);
3138                 self::assertArrayHasKey('user_id_str', $result);
3139                 self::assertArrayHasKey('screen_name', $result);
3140         }
3141
3142         /**
3143          * Test the api_in_reply_to() function with a valid item.
3144          *
3145          * @return void
3146          */
3147         public function testApiInReplyToWithValidItem()
3148         {
3149                 $this->markTestIncomplete();
3150         }
3151
3152         /**
3153          * Test the api_clean_plain_items() function.
3154          *
3155          * @return void
3156          */
3157         public function testApiCleanPlainItems()
3158         {
3159                 $_REQUEST['include_entities'] = 'true';
3160                 $result                       = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3161                 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3162         }
3163
3164         /**
3165          * Test the api_best_nickname() function.
3166          *
3167          * @return void
3168          */
3169         public function testApiBestNickname()
3170         {
3171                 $contacts = [];
3172                 $result   = api_best_nickname($contacts);
3173                 self::assertNull($result);
3174         }
3175
3176         /**
3177          * Test the api_best_nickname() function with contacts.
3178          *
3179          * @return void
3180          */
3181         public function testApiBestNicknameWithContacts()
3182         {
3183                 $this->markTestIncomplete();
3184         }
3185
3186         /**
3187          * Test the api_friendica_group_show() function.
3188          *
3189          * @return void
3190          */
3191         public function testApiFriendicaGroupShow()
3192         {
3193                 $this->markTestIncomplete();
3194         }
3195
3196         /**
3197          * Test the api_friendica_group_delete() function.
3198          *
3199          * @return void
3200          */
3201         public function testApiFriendicaGroupDelete()
3202         {
3203                 $this->markTestIncomplete();
3204         }
3205
3206         /**
3207          * Test the api_lists_destroy() function.
3208          *
3209          * @return void
3210          */
3211         public function testApiListsDestroy()
3212         {
3213                 $this->markTestIncomplete();
3214         }
3215
3216         /**
3217          * Test the group_create() function.
3218          *
3219          * @return void
3220          */
3221         public function testGroupCreate()
3222         {
3223                 $this->markTestIncomplete();
3224         }
3225
3226         /**
3227          * Test the api_friendica_group_create() function.
3228          *
3229          * @return void
3230          */
3231         public function testApiFriendicaGroupCreate()
3232         {
3233                 $this->markTestIncomplete();
3234         }
3235
3236         /**
3237          * Test the api_lists_create() function.
3238          *
3239          * @return void
3240          */
3241         public function testApiListsCreate()
3242         {
3243                 $this->markTestIncomplete();
3244         }
3245
3246         /**
3247          * Test the api_friendica_group_update() function.
3248          *
3249          * @return void
3250          */
3251         public function testApiFriendicaGroupUpdate()
3252         {
3253                 $this->markTestIncomplete();
3254         }
3255
3256         /**
3257          * Test the api_lists_update() function.
3258          *
3259          * @return void
3260          */
3261         public function testApiListsUpdate()
3262         {
3263                 $this->markTestIncomplete();
3264         }
3265
3266         /**
3267          * Test the api_friendica_activity() function.
3268          *
3269          * @return void
3270          */
3271         public function testApiFriendicaActivity()
3272         {
3273                 $this->markTestIncomplete();
3274         }
3275
3276         /**
3277          * Test the api_friendica_notification_seen() function.
3278          *
3279          * @return void
3280          */
3281         public function testApiFriendicaNotificationSeen()
3282         {
3283                 $this->markTestIncomplete();
3284         }
3285
3286         /**
3287          * Test the api_friendica_direct_messages_setseen() function.
3288          *
3289          * @return void
3290          */
3291         public function testApiFriendicaDirectMessagesSetseen()
3292         {
3293                 $this->markTestIncomplete();
3294         }
3295
3296         /**
3297          * Test the api_friendica_direct_messages_search() function.
3298          *
3299          * @return void
3300          */
3301         public function testApiFriendicaDirectMessagesSearch()
3302         {
3303                 $this->markTestIncomplete();
3304         }
3305 }