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