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