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