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