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