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