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