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