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