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