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