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