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