]> git.mxchange.org Git - friendica.git/blob - tests/legacy/ApiTest.php
Fix dataset
[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\DI;
11 use Friendica\Module\Api\ApiResponse;
12 use Friendica\Module\BaseApi;
13 use Friendica\Security\BasicAuth;
14 use Friendica\Test\FixtureTest;
15 use Friendica\Util\Arrays;
16 use Friendica\Util\DateTimeFormat;
17 use Monolog\Handler\TestHandler;
18
19 require_once __DIR__ . '/../../include/api.php';
20
21 /**
22  * Tests for the API functions.
23  *
24  * Functions that use header() need to be tested in a separate process.
25  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
26  *
27  * @backupGlobals enabled
28  */
29 class ApiTest extends FixtureTest
30 {
31         /**
32          * @var TestHandler Can handle log-outputs
33          */
34         protected $logOutput;
35
36         /** @var array */
37         protected $selfUser;
38         /** @var array */
39         protected $friendUser;
40         /** @var array */
41         protected $otherUser;
42
43         protected $wrongUserId;
44
45         /** @var App */
46         protected $app;
47
48         /** @var IManageConfigValues */
49         protected $config;
50
51         /**
52          * Create variables used by tests.
53          */
54         protected function setUp() : void
55         {
56                 global $API, $called_api;
57                 $API = [];
58                 $called_api = [];
59
60                 parent::setUp();
61
62                 /** @var IManageConfigValues $config */
63                 $this->config = $this->dice->create(IManageConfigValues::class);
64
65                 $this->config->set('system', 'url', 'http://localhost');
66                 $this->config->set('system', 'hostname', 'localhost');
67                 $this->config->set('system', 'worker_dont_fork', true);
68
69                 // Default config
70                 $this->config->set('config', 'hostname', 'localhost');
71                 $this->config->set('system', 'throttle_limit_day', 100);
72                 $this->config->set('system', 'throttle_limit_week', 100);
73                 $this->config->set('system', 'throttle_limit_month', 100);
74                 $this->config->set('system', 'theme', 'system_theme');
75
76
77                 /** @var App app */
78                 $this->app = DI::app();
79
80                 DI::args()->setArgc(1);
81
82                 // User data that the test database is populated with
83                 $this->selfUser   = [
84                         'id'   => 42,
85                         'name' => 'Self contact',
86                         'nick' => 'selfcontact',
87                         'nurl' => 'http://localhost/profile/selfcontact'
88                 ];
89                 $this->friendUser = [
90                         'id'   => 44,
91                         'name' => 'Friend contact',
92                         'nick' => 'friendcontact',
93                         'nurl' => 'http://localhost/profile/friendcontact'
94                 ];
95                 $this->otherUser  = [
96                         'id'   => 43,
97                         'name' => 'othercontact',
98                         'nick' => 'othercontact',
99                         'nurl' => 'http://localhost/profile/othercontact'
100                 ];
101
102                 // User ID that we know is not in the database
103                 $this->wrongUserId = 666;
104
105                 DI::session()->start();
106
107                 // Most API require login so we force the session
108                 $_SESSION = [
109                         'authenticated' => true,
110                         'uid'           => $this->selfUser['id']
111                 ];
112                 BasicAuth::setCurrentUserID($this->selfUser['id']);
113         }
114
115         /**
116          * Assert that an user array contains expected keys.
117          *
118          * @param array $user User array
119          *
120          * @return void
121          */
122         private function assertSelfUser(array $user)
123         {
124                 self::assertEquals($this->selfUser['id'], $user['uid']);
125                 self::assertEquals($this->selfUser['id'], $user['cid']);
126                 self::assertEquals(1, $user['self']);
127                 self::assertEquals('DFRN', $user['location']);
128                 self::assertEquals($this->selfUser['name'], $user['name']);
129                 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
130                 self::assertEquals('dfrn', $user['network']);
131                 self::assertTrue($user['verified']);
132         }
133
134         /**
135          * Assert that an user array contains expected keys.
136          *
137          * @param array $user User array
138          *
139          * @return void
140          */
141         private function assertOtherUser(array $user = [])
142         {
143                 self::assertEquals($this->otherUser['id'], $user['id']);
144                 self::assertEquals($this->otherUser['id'], $user['id_str']);
145                 self::assertEquals($this->otherUser['name'], $user['name']);
146                 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
147                 self::assertFalse($user['verified']);
148         }
149
150         /**
151          * Assert that a status array contains expected keys.
152          *
153          * @param array $status Status array
154          *
155          * @return void
156          */
157         private function assertStatus(array $status = [])
158         {
159                 self::assertIsString($status['text'] ?? '');
160                 self::assertIsInt($status['id'] ?? '');
161                 // We could probably do more checks here.
162         }
163
164         /**
165          * Assert that a list array contains expected keys.
166          *
167          * @param array $list List array
168          *
169          * @return void
170          */
171         private function assertList(array $list = [])
172         {
173                 self::assertIsString($list['name']);
174                 self::assertIsInt($list['id']);
175                 self::assertIsString('string', $list['id_str']);
176                 self::assertContains($list['mode'], ['public', 'private']);
177                 // We could probably do more checks here.
178         }
179
180         /**
181          * Assert that the string is XML and contain the root element.
182          *
183          * @param string $result       XML string
184          * @param string $root_element Root element name
185          *
186          * @return void
187          */
188         private function assertXml($result = '', $root_element = '')
189         {
190                 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
191                 self::assertStringContainsString('<' . $root_element, $result);
192                 // We could probably do more checks here.
193         }
194
195         /**
196          * Test the api_user() function.
197          *
198          * @return void
199          */
200         public function testApiUser()
201         {
202                 self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
203         }
204
205         /**
206          * Test the api_user() function with an unallowed user.
207          *
208          * @return void
209          */
210         public function testApiUserWithUnallowedUser()
211         {
212                 // self::assertEquals(false, api_user());
213         }
214
215         /**
216          * Test the api_source() function.
217          *
218          * @return void
219          */
220         public function testApiSource()
221         {
222                 self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
223         }
224
225         /**
226          * Test the api_source() function with a Twidere user agent.
227          *
228          * @return void
229          */
230         public function testApiSourceWithTwidere()
231         {
232                 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
233                 self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
234         }
235
236         /**
237          * Test the api_source() function with a GET parameter.
238          *
239          * @return void
240          */
241         public function testApiSourceWithGet()
242         {
243                 $_REQUEST['source'] = 'source_name';
244                 self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
245         }
246
247         /**
248          * Test the api_date() function.
249          *
250          * @return void
251          */
252         public function testApiDate()
253         {
254                 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
255         }
256
257         /**
258          * Test the api_register_func() function.
259          *
260          * @return void
261          */
262         public function testApiRegisterFunc()
263         {
264                 global $API;
265                 self::assertNull(
266                         api_register_func(
267                                 'api_path',
268                                 function () {
269                                 },
270                                 true,
271                                 'method'
272                         )
273                 );
274                 self::assertTrue(is_callable($API['api_path']['func']));
275         }
276
277         /**
278          * Test the BasicAuth::getCurrentUserID() function without any login.
279          *
280          * @runInSeparateProcess
281          * @preserveGlobalState disabled
282          * @preserveGlobalState disabled
283          */
284         public function testApiLoginWithoutLogin()
285         {
286                 BasicAuth::setCurrentUserID();
287                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
288                 BasicAuth::getCurrentUserID(true);
289         }
290
291         /**
292          * Test the BasicAuth::getCurrentUserID() function with a bad login.
293          *
294          * @runInSeparateProcess
295          * @preserveGlobalState disabled
296          * @preserveGlobalState disabled
297          */
298         public function testApiLoginWithBadLogin()
299         {
300                 BasicAuth::setCurrentUserID();
301                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
302                 $_SERVER['PHP_AUTH_USER'] = 'user@server';
303                 BasicAuth::getCurrentUserID(true);
304         }
305
306         /**
307          * Test the BasicAuth::getCurrentUserID() function with oAuth.
308          *
309          * @return void
310          */
311         public function testApiLoginWithOauth()
312         {
313                 $this->markTestIncomplete('Can we test this easily?');
314         }
315
316         /**
317          * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
318          *
319          * @return void
320          */
321         public function testApiLoginWithAddonAuth()
322         {
323                 $this->markTestIncomplete('Can we test this easily?');
324         }
325
326         /**
327          * Test the BasicAuth::getCurrentUserID() function with a correct login.
328          *
329          * @runInSeparateProcess
330          * @preserveGlobalState disabled
331          * @doesNotPerformAssertions
332          */
333         public function testApiLoginWithCorrectLogin()
334         {
335                 BasicAuth::setCurrentUserID();
336                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
337                 $_SERVER['PHP_AUTH_PW']   = 'password';
338                 BasicAuth::getCurrentUserID(true);
339         }
340
341         /**
342          * Test the BasicAuth::getCurrentUserID() function with a remote user.
343          *
344          * @runInSeparateProcess
345          * @preserveGlobalState disabled
346          */
347         public function testApiLoginWithRemoteUser()
348         {
349                 BasicAuth::setCurrentUserID();
350                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
351                 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
352                 BasicAuth::getCurrentUserID(true);
353         }
354
355         /**
356          * Test the api_call() function.
357          *
358          * @runInSeparateProcess
359          * @preserveGlobalState disabled
360          */
361         public function testApiCall()
362         {
363                 global $API;
364                 $API['api_path']           = [
365                         'method' => 'method',
366                         'func'   => function () {
367                                 return ['data' => ['some_data']];
368                         }
369                 ];
370                 $_SERVER['REQUEST_METHOD'] = 'method';
371                 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
372                 $_GET['callback']          = 'callback_name';
373
374                 self::assertEquals(
375                         'callback_name(["some_data"])',
376                         api_call('api_path', 'json')
377                 );
378         }
379
380         /**
381          * Test the api_call() function with the profiled enabled.
382          *
383          * @runInSeparateProcess
384          * @preserveGlobalState disabled
385          */
386         public function testApiCallWithProfiler()
387         {
388                 global $API;
389                 $API['api_path']           = [
390                         'method' => 'method',
391                         'func'   => function () {
392                                 return ['data' => ['some_data']];
393                         }
394                 ];
395
396                 $_SERVER['REQUEST_METHOD'] = 'method';
397                 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
398
399                 $this->config->set('system', 'profiler', true);
400                 $this->config->set('rendertime', 'callstack', true);
401                 $this->app->callstack = [
402                         'database'       => ['some_function' => 200],
403                         'database_write' => ['some_function' => 200],
404                         'cache'          => ['some_function' => 200],
405                         'cache_write'    => ['some_function' => 200],
406                         'network'        => ['some_function' => 200]
407                 ];
408
409                 self::assertEquals(
410                         '["some_data"]',
411                         api_call('api_path', 'json')
412                 );
413         }
414
415         /**
416          * Test the api_call() function with a JSON result.
417          *
418          * @runInSeparateProcess
419          * @preserveGlobalState disabled
420          */
421         public function testApiCallWithJson()
422         {
423                 global $API;
424                 $API['api_path']           = [
425                         'method' => 'method',
426                         'func'   => function () {
427                                 return ['data' => ['some_data']];
428                         }
429                 ];
430                 $_SERVER['REQUEST_METHOD'] = 'method';
431                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
432
433                 self::assertEquals(
434                         '["some_data"]',
435                         api_call('api_path.json', 'json')
436                 );
437         }
438
439         /**
440          * Test the api_call() function with an XML result.
441          *
442          * @runInSeparateProcess
443          * @preserveGlobalState disabled
444          */
445         public function testApiCallWithXml()
446         {
447                 global $API;
448                 $API['api_path']           = [
449                         'method' => 'method',
450                         'func'   => function () {
451                                 return 'some_data';
452                         }
453                 ];
454                 $_SERVER['REQUEST_METHOD'] = 'method';
455                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
456
457                 $args = DI::args()->determine($_SERVER, $_GET);
458
459                 self::assertEquals(
460                         'some_data',
461                         api_call('api_path.xml', 'xml')
462                 );
463         }
464
465         /**
466          * Test the api_call() function with an RSS result.
467          *
468          * @runInSeparateProcess
469          * @preserveGlobalState disabled
470          */
471         public function testApiCallWithRss()
472         {
473                 global $API;
474                 $API['api_path']           = [
475                         'method' => 'method',
476                         'func'   => function () {
477                                 return 'some_data';
478                         }
479                 ];
480                 $_SERVER['REQUEST_METHOD'] = 'method';
481                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
482
483                 self::assertEquals(
484                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
485                         'some_data',
486                         api_call('api_path.rss', 'rss')
487                 );
488         }
489
490         /**
491          * Test the api_call() function with an Atom result.
492          *
493          * @runInSeparateProcess
494          * @preserveGlobalState disabled
495          */
496         public function testApiCallWithAtom()
497         {
498                 global $API;
499                 $API['api_path']           = [
500                         'method' => 'method',
501                         'func'   => function () {
502                                 return 'some_data';
503                         }
504                 ];
505                 $_SERVER['REQUEST_METHOD'] = 'method';
506                 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
507
508                 self::assertEquals(
509                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
510                         'some_data',
511                         api_call('api_path.atom', 'atom')
512                 );
513         }
514
515         /**
516          * Test the api_rss_extra() function.
517          *
518          * @return void
519          */
520         public function testApiRssExtra()
521         {
522                 /*
523                 $user_info = ['url' => 'user_url', 'lang' => 'en'];
524                 $result    = api_rss_extra([], $user_info);
525                 self::assertEquals($user_info, $result['$user']);
526                 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
527                 self::assertArrayHasKey('self', $result['$rss']);
528                 self::assertArrayHasKey('base', $result['$rss']);
529                 self::assertArrayHasKey('updated', $result['$rss']);
530                 self::assertArrayHasKey('atom_updated', $result['$rss']);
531                 self::assertArrayHasKey('language', $result['$rss']);
532                 self::assertArrayHasKey('logo', $result['$rss']);
533                 */
534         }
535
536         /**
537          * Test the api_rss_extra() function without any user info.
538          *
539          * @return void
540          */
541         public function testApiRssExtraWithoutUserInfo()
542         {
543                 /*
544                 $result = api_rss_extra([], null);
545                 self::assertIsArray($result['$user']);
546                 self::assertArrayHasKey('alternate', $result['$rss']);
547                 self::assertArrayHasKey('self', $result['$rss']);
548                 self::assertArrayHasKey('base', $result['$rss']);
549                 self::assertArrayHasKey('updated', $result['$rss']);
550                 self::assertArrayHasKey('atom_updated', $result['$rss']);
551                 self::assertArrayHasKey('language', $result['$rss']);
552                 self::assertArrayHasKey('logo', $result['$rss']);
553                 */
554         }
555
556         /**
557          * Test the api_get_user() function.
558          *
559          * @return void
560          */
561         public function testApiGetUser()
562         {
563                 // $user = api_get_user();
564                 // self::assertSelfUser($user);
565                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
566                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
567                 // self::assertEquals('ededed', $user['profile_background_color']);
568         }
569
570         /**
571          * Test the api_get_user() function with a Frio schema.
572          *
573          * @return void
574          */
575         public function testApiGetUserWithFrioSchema()
576         {
577                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
578                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
579                 // $user = api_get_user();
580                 // self::assertSelfUser($user);
581                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
582                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
583                 // self::assertEquals('ededed', $user['profile_background_color']);
584         }
585
586         /**
587          * Test the api_get_user() function with an empty Frio schema.
588          *
589          * @return void
590          */
591         public function testApiGetUserWithEmptyFrioSchema()
592         {
593                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
594                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
595                 // $user = api_get_user();
596                 // self::assertSelfUser($user);
597                 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
598                 // self::assertEquals('6fdbe8', $user['profile_link_color']);
599                 // self::assertEquals('ededed', $user['profile_background_color']);
600         }
601
602         /**
603          * Test the api_get_user() function with a custom Frio schema.
604          *
605          * @return void
606          */
607         public function testApiGetUserWithCustomFrioSchema()
608         {
609                 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
610                 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
611                 // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
612                 // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
613                 // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
614                 // $user = api_get_user();
615                 // self::assertSelfUser($user);
616                 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
617                 // self::assertEquals('123456', $user['profile_link_color']);
618                 // self::assertEquals('123456', $user['profile_background_color']);
619         }
620
621         /**
622          * Test the api_get_user() function with an user that is not allowed to use the API.
623          *
624          * @runInSeparateProcess
625          * @preserveGlobalState disabled
626          */
627         public function testApiGetUserWithoutApiUser()
628         {
629                 // api_get_user() with empty parameters is not used anymore
630                 /*
631                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
632                 $_SERVER['PHP_AUTH_PW']   = 'password';
633                 BasicAuth::setCurrentUserID();
634                 self::assertFalse(api_get_user());
635                 */
636         }
637
638         /**
639          * Test the api_get_user() function with an user ID in a GET parameter.
640          *
641          * @return void
642          */
643         public function testApiGetUserWithGetId()
644         {
645                 // self::assertOtherUser(api_get_user());
646         }
647
648         /**
649          * Test the api_get_user() function with a wrong user ID in a GET parameter.
650          *
651          * @return void
652          */
653         public function testApiGetUserWithWrongGetId()
654         {
655                 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
656                 // self::assertOtherUser(api_get_user());
657         }
658
659         /**
660          * Test the api_get_user() function with an user name in a GET parameter.
661          *
662          * @return void
663          */
664         public function testApiGetUserWithGetName()
665         {
666                 // self::assertSelfUser(api_get_user());
667         }
668
669         /**
670          * Test the api_get_user() function with a profile URL in a GET parameter.
671          *
672          * @return void
673          */
674         public function testApiGetUserWithGetUrl()
675         {
676                 // self::assertSelfUser(api_get_user());
677         }
678
679         /**
680          * Test the api_get_user() function with an user ID in the API path.
681          *
682          * @return void
683          */
684         public function testApiGetUserWithNumericCalledApi()
685         {
686                 // global $called_api;
687                 // $called_api         = ['api_path'];
688                 // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
689                 // self::assertOtherUser(api_get_user());
690         }
691
692         /**
693          * Test the api_get_user() function with the $called_api global variable.
694          *
695          * @return void
696          */
697         public function testApiGetUserWithCalledApi()
698         {
699                 // global $called_api;
700                 // $called_api = ['api', 'api_path'];
701                 // self::assertSelfUser(api_get_user());
702         }
703
704         /**
705          * Test the Arrays::walkRecursive() function.
706          *
707          * @return void
708          */
709         public function testApiWalkRecursive()
710         {
711                 $array = ['item1'];
712                 self::assertEquals(
713                         $array,
714                         Arrays::walkRecursive(
715                                 $array,
716                                 function () {
717                                         // Should we test this with a callback that actually does something?
718                                         return true;
719                                 }
720                         )
721                 );
722         }
723
724         /**
725          * Test the Arrays::walkRecursive() function with an array.
726          *
727          * @return void
728          */
729         public function testApiWalkRecursiveWithArray()
730         {
731                 $array = [['item1'], ['item2']];
732                 self::assertEquals(
733                         $array,
734                         Arrays::walkRecursive(
735                                 $array,
736                                 function () {
737                                         // Should we test this with a callback that actually does something?
738                                         return true;
739                                 }
740                         )
741                 );
742         }
743
744         /**
745          * Test the BaseApi::reformatXML() function.
746          *
747          * @return void
748          */
749         public function testApiReformatXml()
750         {
751                 $item = true;
752                 $key  = '';
753                 self::assertTrue(ApiResponse::reformatXML($item, $key));
754                 self::assertEquals('true', $item);
755         }
756
757         /**
758          * Test the BaseApi::reformatXML() function with a statusnet_api key.
759          *
760          * @return void
761          */
762         public function testApiReformatXmlWithStatusnetKey()
763         {
764                 $item = '';
765                 $key  = 'statusnet_api';
766                 self::assertTrue(ApiResponse::reformatXML($item, $key));
767                 self::assertEquals('statusnet:api', $key);
768         }
769
770         /**
771          * Test the BaseApi::reformatXML() function with a friendica_api key.
772          *
773          * @return void
774          */
775         public function testApiReformatXmlWithFriendicaKey()
776         {
777                 $item = '';
778                 $key  = 'friendica_api';
779                 self::assertTrue(ApiResponse::reformatXML($item, $key));
780                 self::assertEquals('friendica:api', $key);
781         }
782
783         /**
784          * Test the BaseApi::createXML() function.
785          *
786          * @return void
787          */
788         public function testApiCreateXml()
789         {
790                 self::assertEquals(
791                         '<?xml version="1.0"?>' . "\n" .
792                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
793                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
794                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
795                         '  <data>some_data</data>' . "\n" .
796                         '</root_element>' . "\n",
797                         DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
798                 );
799         }
800
801         /**
802          * Test the BaseApi::createXML() function without any XML namespace.
803          *
804          * @return void
805          */
806         public function testApiCreateXmlWithoutNamespaces()
807         {
808                 self::assertEquals(
809                         '<?xml version="1.0"?>' . "\n" .
810                         '<ok>' . "\n" .
811                         '  <data>some_data</data>' . "\n" .
812                         '</ok>' . "\n",
813                         DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
814                 );
815         }
816
817         /**
818          * Test the BaseApi::formatData() function.
819          *
820          * @return void
821          */
822         public function testApiFormatData()
823         {
824                 $data = ['some_data'];
825                 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
826         }
827
828         /**
829          * Test the BaseApi::formatData() function with an XML result.
830          *
831          * @return void
832          */
833         public function testApiFormatDataWithXml()
834         {
835                 self::assertEquals(
836                         '<?xml version="1.0"?>' . "\n" .
837                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
838                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
839                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
840                         '  <data>some_data</data>' . "\n" .
841                         '</root_element>' . "\n",
842                         DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
843                 );
844         }
845
846         /**
847          * Test the api_statuses_mediap() function.
848          *
849          * @return void
850          */
851         public function testApiStatusesMediap()
852         {
853                 /*
854                 DI::args()->setArgc(2);
855
856                 $_FILES         = [
857                         'media' => [
858                                 'id'       => 666,
859                                 'size'     => 666,
860                                 'width'    => 666,
861                                 'height'   => 666,
862                                 'tmp_name' => $this->getTempImage(),
863                                 'name'     => 'spacer.png',
864                                 'type'     => 'image/png'
865                         ]
866                 ];
867                 $_GET['status'] = '<b>Status content</b>';
868
869                 $result = api_statuses_mediap('json');
870                 self::assertStatus($result['status']);
871                 */
872         }
873
874         /**
875          * Test the api_statuses_mediap() function without an authenticated user.
876          *
877          * @return void
878          */
879         public function testApiStatusesMediapWithoutAuthenticatedUser()
880         {
881                 // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
882                 // BasicAuth::setCurrentUserID();
883                 // $_SESSION['authenticated'] = false;
884                 // api_statuses_mediap('json');
885         }
886
887         /**
888          * Test the api_statuses_update() function.
889          *
890          * @return void
891          */
892         public function testApiStatusesUpdate()
893         {
894                 /*
895                 $_REQUEST['status']                = 'Status content #friendica';
896                 $_REQUEST['in_reply_to_status_id'] = -1;
897                 $_REQUEST['lat']                   = 48;
898                 $_REQUEST['long']                  = 7;
899                 $_FILES                            = [
900                         'media' => [
901                                 'id'       => 666,
902                                 'size'     => 666,
903                                 'width'    => 666,
904                                 'height'   => 666,
905                                 'tmp_name' => $this->getTempImage(),
906                                 'name'     => 'spacer.png',
907                                 'type'     => 'image/png'
908                         ]
909                 ];
910
911                 $result = api_statuses_update('json');
912                 self::assertStatus($result['status']);
913                 */
914         }
915
916         /**
917          * Test the api_statuses_update() function with an HTML status.
918          *
919          * @return void
920          */
921         public function testApiStatusesUpdateWithHtml()
922         {
923                 /*
924                 $_REQUEST['htmlstatus'] = '<b>Status content</b>';
925
926                 $result = api_statuses_update('json');
927                 self::assertStatus($result['status']);
928                 */
929         }
930
931         /**
932          * Test the api_statuses_update() function without an authenticated user.
933          *
934          * @return void
935          */
936         public function testApiStatusesUpdateWithoutAuthenticatedUser()
937         {
938                 /*
939                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
940                 BasicAuth::setCurrentUserID();
941                 $_SESSION['authenticated'] = false;
942                 api_statuses_update('json');
943                 */
944         }
945
946         /**
947          * Test the api_statuses_update() function with a parent status.
948          *
949          * @return void
950          */
951         public function testApiStatusesUpdateWithParent()
952         {
953                 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
954         }
955
956         /**
957          * Test the api_statuses_update() function with a media_ids parameter.
958          *
959          * @return void
960          */
961         public function testApiStatusesUpdateWithMediaIds()
962         {
963                 $this->markTestIncomplete();
964         }
965
966         /**
967          * Test the api_statuses_update() function with the throttle limit reached.
968          *
969          * @return void
970          */
971         public function testApiStatusesUpdateWithDayThrottleReached()
972         {
973                 $this->markTestIncomplete();
974         }
975
976
977
978         /**
979          * Test the api_statuses_repeat() function.
980          *
981          * @return void
982          */
983         public function testApiStatusesRepeat()
984         {
985                 // $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
986                 // api_statuses_repeat('json');
987         }
988
989         /**
990          * Test the api_statuses_repeat() function without an authenticated user.
991          *
992          * @return void
993          */
994         public function testApiStatusesRepeatWithoutAuthenticatedUser()
995         {
996                 // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
997                 // BasicAuth::setCurrentUserID();
998                 // $_SESSION['authenticated'] = false;
999                 // api_statuses_repeat('json');
1000         }
1001
1002         /**
1003          * Test the api_statuses_repeat() function with an ID.
1004          *
1005          * @return void
1006          */
1007         public function testApiStatusesRepeatWithId()
1008         {
1009                 // DI::args()->setArgv(['', '', '', 1]);
1010                 // $result = api_statuses_repeat('json');
1011                 // self::assertStatus($result['status']);
1012
1013                 // Also test with a shared status
1014                 // DI::args()->setArgv(['', '', '', 5]);
1015                 // $result = api_statuses_repeat('json');
1016                 // self::assertStatus($result['status']);
1017         }
1018
1019         /**
1020          * Test the api_favorites_create_destroy() function.
1021          *
1022          * @return void
1023          */
1024         public function testApiFavoritesCreateDestroy()
1025         {
1026                 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1027                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1028                 // api_favorites_create_destroy('json');
1029         }
1030
1031         /**
1032          * Test the api_favorites_create_destroy() function with an invalid ID.
1033          *
1034          * @return void
1035          */
1036         public function testApiFavoritesCreateDestroyWithInvalidId()
1037         {
1038                 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1039                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1040                 // api_favorites_create_destroy('json');
1041         }
1042
1043         /**
1044          * Test the api_favorites_create_destroy() function with an invalid action.
1045          *
1046          * @return void
1047          */
1048         public function testApiFavoritesCreateDestroyWithInvalidAction()
1049         {
1050                 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1051                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1052                 // $_REQUEST['id'] = 1;
1053                 // api_favorites_create_destroy('json');
1054         }
1055
1056         /**
1057          * Test the api_favorites_create_destroy() function with the create action.
1058          *
1059          * @return void
1060          */
1061         public function testApiFavoritesCreateDestroyWithCreateAction()
1062         {
1063                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1064                 // $_REQUEST['id'] = 3;
1065                 // $result         = api_favorites_create_destroy('json');
1066                 // self::assertStatus($result['status']);
1067         }
1068
1069         /**
1070          * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1071          *
1072          * @return void
1073          */
1074         public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1075         {
1076                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1077                 // $_REQUEST['id'] = 3;
1078                 // $result         = api_favorites_create_destroy('rss');
1079                 // self::assertXml($result, 'status');
1080         }
1081
1082         /**
1083          * Test the api_favorites_create_destroy() function with the destroy action.
1084          *
1085          * @return void
1086          */
1087         public function testApiFavoritesCreateDestroyWithDestroyAction()
1088         {
1089                 // DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1090                 // $_REQUEST['id'] = 3;
1091                 // $result         = api_favorites_create_destroy('json');
1092                 // self::assertStatus($result['status']);
1093         }
1094
1095         /**
1096          * Test the api_favorites_create_destroy() function without an authenticated user.
1097          *
1098          * @return void
1099          */
1100         public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1101         {
1102                 /*
1103                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1104                 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1105                 BasicAuth::setCurrentUserID();
1106                 $_SESSION['authenticated'] = false;
1107                 api_favorites_create_destroy('json');
1108                 */
1109         }
1110
1111
1112
1113         /**
1114          * Test the api_format_messages() function.
1115          *
1116          * @return void
1117          */
1118         public function testApiFormatMessages()
1119         {
1120                 $result = api_format_messages(
1121                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1122                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1123                         ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
1124                 );
1125                 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
1126                 self::assertEquals(1, $result['id']);
1127                 self::assertEquals(2, $result['recipient_id']);
1128                 self::assertEquals(3, $result['sender_id']);
1129                 self::assertEquals('recipient_name', $result['recipient_screen_name']);
1130                 self::assertEquals('sender_name', $result['sender_screen_name']);
1131         }
1132
1133         /**
1134          * Test the api_format_messages() function with HTML.
1135          *
1136          * @return void
1137          */
1138         public function testApiFormatMessagesWithHtmlText()
1139         {
1140                 $_GET['getText'] = 'html';
1141                 $result          = api_format_messages(
1142                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1143                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1144                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1145                 );
1146                 self::assertEquals('item_title', $result['title']);
1147                 self::assertEquals('<strong>item_body</strong>', $result['text']);
1148         }
1149
1150         /**
1151          * Test the api_format_messages() function with plain text.
1152          *
1153          * @return void
1154          */
1155         public function testApiFormatMessagesWithPlainText()
1156         {
1157                 $_GET['getText'] = 'plain';
1158                 $result          = api_format_messages(
1159                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1160                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1161                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1162                 );
1163                 self::assertEquals('item_title', $result['title']);
1164                 self::assertEquals('item_body', $result['text']);
1165         }
1166
1167         /**
1168          * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
1169          *
1170          * @return void
1171          */
1172         public function testApiFormatMessagesWithoutUserObjects()
1173         {
1174                 $_GET['getUserObjects'] = 'false';
1175                 $result                 = api_format_messages(
1176                         ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1177                         ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1178                         ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1179                 );
1180                 self::assertTrue(!isset($result['sender']));
1181                 self::assertTrue(!isset($result['recipient']));
1182         }
1183
1184         /**
1185          * Test the api_convert_item() function.
1186          *
1187          * @return void
1188          */
1189         public function testApiConvertItem()
1190         {
1191                 /*
1192                 $result = api_convert_item(
1193                         [
1194                                 'network' => 'feed',
1195                                 'title'   => 'item_title',
1196                                 'uri-id'  => 1,
1197                                 // We need a long string to test that it is correctly cut
1198                                 'body'    => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
1199                                                          'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
1200                                                          'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
1201                                                          'laudantium atque commodi alias voluptatem non possimus aperiam ' .
1202                                                          'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
1203                                                          'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
1204                                                          'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
1205                                                          'veritatis nihil distinctio qui eum repellat officia illum quos ' .
1206                                                          'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
1207                                                          'omnis exercitationem quo magnam consequatur maxime aut illum ' .
1208                                                          'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
1209                                                          'temporibus corporis ratione blanditiis perspiciatis impedit ' .
1210                                                          'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
1211                                                          'sunt consequatur inventore dolor officiis pariatur doloremque ' .
1212                                                          'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
1213                                                          'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
1214                                                          'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
1215                                                          'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
1216                                                          'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
1217                                                          'repellat officia illum quos impedit quam iste esse unde qui ' .
1218                                                          'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
1219                                                          'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
1220                                                          'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
1221                                 'plink'   => 'item_plink'
1222                         ]
1223                 );
1224                 self::assertStringStartsWith('item_title', $result['text']);
1225                 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
1226                 */
1227         }
1228
1229         /**
1230          * Test the api_convert_item() function with an empty item body.
1231          *
1232          * @return void
1233          */
1234         public function testApiConvertItemWithoutBody()
1235         {
1236                 /*
1237                 $result = api_convert_item(
1238                         [
1239                                 'network' => 'feed',
1240                                 'title'   => 'item_title',
1241                                 'uri-id'  => -1,
1242                                 'body'    => '',
1243                                 'plink'   => 'item_plink'
1244                         ]
1245                 );
1246                 self::assertEquals("item_title", $result['text']);
1247                 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
1248                 */
1249         }
1250
1251         /**
1252          * Test the api_convert_item() function with the title in the body.
1253          *
1254          * @return void
1255          */
1256         public function testApiConvertItemWithTitleInBody()
1257         {
1258                 /*
1259                 $result = api_convert_item(
1260                         [
1261                                 'title'  => 'item_title',
1262                                 'body'   => 'item_title item_body',
1263                                 'uri-id' => 1,
1264                         ]
1265                 );
1266                 self::assertEquals('item_title item_body', $result['text']);
1267                 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
1268                 */
1269         }
1270
1271         /**
1272          * Test the api_get_attachments() function.
1273          *
1274          * @return void
1275          */
1276         public function testApiGetAttachments()
1277         {
1278                 // $body = 'body';
1279                 // self::assertEmpty(api_get_attachments($body, 0));
1280         }
1281
1282         /**
1283          * Test the api_get_attachments() function with an img tag.
1284          *
1285          * @return void
1286          */
1287         public function testApiGetAttachmentsWithImage()
1288         {
1289                 // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
1290                 // self::assertIsArray(api_get_attachments($body, 0));
1291         }
1292
1293         /**
1294          * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
1295          *
1296          * @return void
1297          */
1298         public function testApiGetAttachmentsWithImageAndAndStatus()
1299         {
1300                 // $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
1301                 // $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
1302                 // self::assertIsArray(api_get_attachments($body, 0));
1303         }
1304
1305         /**
1306          * Test the api_get_entitities() function.
1307          *
1308          * @return void
1309          */
1310         public function testApiGetEntitities()
1311         {
1312                 // $text = 'text';
1313                 // self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
1314         }
1315
1316         /**
1317          * Test the api_get_entitities() function with the include_entities parameter.
1318          *
1319          * @return void
1320          */
1321         public function testApiGetEntititiesWithIncludeEntities()
1322         {
1323                 /*
1324                 $_REQUEST['include_entities'] = 'true';
1325                 $text                         = 'text';
1326                 $result                       = api_get_entitities($text, 'bbcode', 0);
1327                 self::assertIsArray($result['hashtags']);
1328                 self::assertIsArray($result['symbols']);
1329                 self::assertIsArray($result['urls']);
1330                 self::assertIsArray($result['user_mentions']);
1331                 */
1332         }
1333
1334         /**
1335          * Test the api_format_items_embeded_images() function.
1336          *
1337          * @return void
1338          */
1339         public function testApiFormatItemsEmbededImages()
1340         {
1341                 /*
1342                 self::assertEquals(
1343                         'text ' . DI::baseUrl() . '/display/item_guid',
1344                         api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
1345                 );
1346                 */
1347         }
1348
1349         /**
1350          * Test the api_format_items_activities() function.
1351          *
1352          * @return void
1353          */
1354         public function testApiFormatItemsActivities()
1355         {
1356                 $item   = ['uid' => 0, 'uri-id' => 1];
1357                 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
1358                 self::assertArrayHasKey('like', $result);
1359                 self::assertArrayHasKey('dislike', $result);
1360                 self::assertArrayHasKey('attendyes', $result);
1361                 self::assertArrayHasKey('attendno', $result);
1362                 self::assertArrayHasKey('attendmaybe', $result);
1363         }
1364
1365         /**
1366          * Test the api_format_items_activities() function with an XML result.
1367          *
1368          * @return void
1369          */
1370         public function testApiFormatItemsActivitiesWithXml()
1371         {
1372                 $item   = ['uid' => 0, 'uri-id' => 1];
1373                 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
1374                 self::assertArrayHasKey('friendica:like', $result);
1375                 self::assertArrayHasKey('friendica:dislike', $result);
1376                 self::assertArrayHasKey('friendica:attendyes', $result);
1377                 self::assertArrayHasKey('friendica:attendno', $result);
1378                 self::assertArrayHasKey('friendica:attendmaybe', $result);
1379         }
1380
1381         /**
1382          * Test the api_format_items() function.
1383          * @doesNotPerformAssertions
1384          */
1385         public function testApiFormatItems()
1386         {
1387                 /*
1388                 $items = Post::selectToArray([], ['uid' => 42]);
1389                 foreach ($items as $item) {
1390                         $status = api_format_item($item);
1391                         self::assertStatus($status);
1392                 }
1393                 */
1394         }
1395
1396         /**
1397          * Test the api_format_items() function with an XML result.
1398          * @doesNotPerformAssertions
1399          */
1400         public function testApiFormatItemsWithXml()
1401         {
1402                 /*
1403                 $items = Post::selectToArray([], ['uid' => 42]);
1404                 foreach ($items as $item) {
1405                         $status = api_format_item($item, 'xml');
1406                         self::assertStatus($status);
1407                 }
1408                 */
1409         }
1410
1411         /**
1412          * Test the api_lists_list() function.
1413          *
1414          * @return void
1415          */
1416         public function testApiListsList()
1417         {
1418                 $result = api_lists_list('json');
1419                 self::assertEquals(['lists_list' => []], $result);
1420         }
1421
1422         /**
1423          * Test the api_lists_ownerships() function.
1424          *
1425          * @return void
1426          */
1427         public function testApiListsOwnerships()
1428         {
1429                 $result = api_lists_ownerships('json');
1430                 foreach ($result['lists']['lists'] as $list) {
1431                         self::assertList($list);
1432                 }
1433         }
1434
1435         /**
1436          * Test the api_lists_ownerships() function without an authenticated user.
1437          *
1438          * @return void
1439          */
1440         public function testApiListsOwnershipsWithoutAuthenticatedUser()
1441         {
1442                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1443                 BasicAuth::setCurrentUserID();
1444                 $_SESSION['authenticated'] = false;
1445                 api_lists_ownerships('json');
1446         }
1447
1448         /**
1449          * Test the api_statuses_f() function.
1450          *
1451          * @return void
1452          */
1453         public function testApiStatusesFWithIncoming()
1454         {
1455                 // $result = api_statuses_f('incoming');
1456                 // self::assertArrayHasKey('user', $result);
1457         }
1458
1459
1460         /**
1461          * Test the api_direct_messages_new() function.
1462          *
1463          * @return void
1464          */
1465         public function testApiDirectMessagesNew()
1466         {
1467                 $result = api_direct_messages_new('json');
1468                 self::assertNull($result);
1469         }
1470
1471         /**
1472          * Test the api_direct_messages_new() function without an authenticated user.
1473          *
1474          * @return void
1475          */
1476         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
1477         {
1478                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1479                 BasicAuth::setCurrentUserID();
1480                 $_SESSION['authenticated'] = false;
1481                 api_direct_messages_new('json');
1482         }
1483
1484         /**
1485          * Test the api_direct_messages_new() function with an user ID.
1486          *
1487          * @return void
1488          */
1489         public function testApiDirectMessagesNewWithUserId()
1490         {
1491                 $_POST['text']       = 'message_text';
1492                 $_REQUEST['user_id'] = $this->otherUser['id'];
1493                 $result           = api_direct_messages_new('json');
1494                 self::assertEquals(['direct_message' => ['error' => -1]], $result);
1495         }
1496
1497         /**
1498          * Test the api_direct_messages_new() function with a screen name.
1499          *
1500          * @return void
1501          */
1502         public function testApiDirectMessagesNewWithScreenName()
1503         {
1504                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1505                 $_POST['text']       = 'message_text';
1506                 $_REQUEST['user_id'] = $this->friendUser['id'];
1507                 $result              = api_direct_messages_new('json');
1508                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1509                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1510                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1511         }
1512
1513         /**
1514          * Test the api_direct_messages_new() function with a title.
1515          *
1516          * @return void
1517          */
1518         public function testApiDirectMessagesNewWithTitle()
1519         {
1520                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1521                 $_POST['text']        = 'message_text';
1522                 $_REQUEST['user_id']  = $this->friendUser['id'];
1523                 $_REQUEST['title']    = 'message_title';
1524                 $result            = api_direct_messages_new('json');
1525                 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1526                 self::assertStringContainsString('message_title', $result['direct_message']['text']);
1527                 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1528                 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1529         }
1530
1531         /**
1532          * Test the api_direct_messages_new() function with an RSS result.
1533          *
1534          * @return void
1535          */
1536         public function testApiDirectMessagesNewWithRss()
1537         {
1538                 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1539                 $_POST['text']       = 'message_text';
1540                 $_REQUEST['user_id'] = $this->friendUser['id'];
1541                 $result              = api_direct_messages_new('rss');
1542                 self::assertXml($result, 'direct-messages');
1543         }
1544
1545         /**
1546          * Test the api_direct_messages_destroy() function.
1547          *
1548          * @return void
1549          */
1550         public function testApiDirectMessagesDestroy()
1551         {
1552                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1553                 api_direct_messages_destroy('json');
1554         }
1555
1556         /**
1557          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
1558          *
1559          * @return void
1560          */
1561         public function testApiDirectMessagesDestroyWithVerbose()
1562         {
1563                 $_GET['friendica_verbose'] = 'true';
1564                 $result                    = api_direct_messages_destroy('json');
1565                 self::assertEquals(
1566                         [
1567                                 '$result' => [
1568                                         'result'  => 'error',
1569                                         'message' => 'message id or parenturi not specified'
1570                                 ]
1571                         ],
1572                         $result
1573                 );
1574         }
1575
1576         /**
1577          * Test the api_direct_messages_destroy() function without an authenticated user.
1578          *
1579          * @return void
1580          */
1581         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
1582         {
1583                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1584                 BasicAuth::setCurrentUserID();
1585                 $_SESSION['authenticated'] = false;
1586                 api_direct_messages_destroy('json');
1587         }
1588
1589         /**
1590          * Test the api_direct_messages_destroy() function with a non-zero ID.
1591          *
1592          * @return void
1593          */
1594         public function testApiDirectMessagesDestroyWithId()
1595         {
1596                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1597                 $_REQUEST['id'] = 1;
1598                 api_direct_messages_destroy('json');
1599         }
1600
1601         /**
1602          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
1603          *
1604          * @return void
1605          */
1606         public function testApiDirectMessagesDestroyWithIdAndVerbose()
1607         {
1608                 $_REQUEST['id']                  = 1;
1609                 $_REQUEST['friendica_parenturi'] = 'parent_uri';
1610                 $_GET['friendica_verbose']       = 'true';
1611                 $result                          = api_direct_messages_destroy('json');
1612                 self::assertEquals(
1613                         [
1614                                 '$result' => [
1615                                         'result'  => 'error',
1616                                         'message' => 'message id not in database'
1617                                 ]
1618                         ],
1619                         $result
1620                 );
1621         }
1622
1623         /**
1624          * Test the api_direct_messages_destroy() function with a non-zero ID.
1625          *
1626          * @return void
1627          */
1628         public function testApiDirectMessagesDestroyWithCorrectId()
1629         {
1630                 $this->markTestIncomplete('We need to add a dataset for this.');
1631         }
1632
1633         /**
1634          * Test the api_direct_messages_box() function.
1635          *
1636          * @return void
1637          */
1638         public function testApiDirectMessagesBoxWithSentbox()
1639         {
1640                 $_REQUEST['page']   = -1;
1641                 $_REQUEST['max_id'] = 10;
1642                 $result             = api_direct_messages_box('json', 'sentbox', 'false');
1643                 self::assertArrayHasKey('direct_message', $result);
1644         }
1645
1646         /**
1647          * Test the api_direct_messages_box() function.
1648          *
1649          * @return void
1650          */
1651         public function testApiDirectMessagesBoxWithConversation()
1652         {
1653                 $result = api_direct_messages_box('json', 'conversation', 'false');
1654                 self::assertArrayHasKey('direct_message', $result);
1655         }
1656
1657         /**
1658          * Test the api_direct_messages_box() function.
1659          *
1660          * @return void
1661          */
1662         public function testApiDirectMessagesBoxWithAll()
1663         {
1664                 $result = api_direct_messages_box('json', 'all', 'false');
1665                 self::assertArrayHasKey('direct_message', $result);
1666         }
1667
1668         /**
1669          * Test the api_direct_messages_box() function.
1670          *
1671          * @return void
1672          */
1673         public function testApiDirectMessagesBoxWithInbox()
1674         {
1675                 $result = api_direct_messages_box('json', 'inbox', 'false');
1676                 self::assertArrayHasKey('direct_message', $result);
1677         }
1678
1679         /**
1680          * Test the api_direct_messages_box() function.
1681          *
1682          * @return void
1683          */
1684         public function testApiDirectMessagesBoxWithVerbose()
1685         {
1686                 $result = api_direct_messages_box('json', 'sentbox', 'true');
1687                 self::assertEquals(
1688                         [
1689                                 '$result' => [
1690                                         'result'  => 'error',
1691                                         'message' => 'no mails available'
1692                                 ]
1693                         ],
1694                         $result
1695                 );
1696         }
1697
1698         /**
1699          * Test the api_direct_messages_box() function with a RSS result.
1700          *
1701          * @return void
1702          */
1703         public function testApiDirectMessagesBoxWithRss()
1704         {
1705                 $result = api_direct_messages_box('rss', 'sentbox', 'false');
1706                 self::assertXml($result, 'direct-messages');
1707         }
1708
1709         /**
1710          * Test the api_direct_messages_box() function without an authenticated user.
1711          *
1712          * @return void
1713          */
1714         public function testApiDirectMessagesBoxWithUnallowedUser()
1715         {
1716                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1717                 BasicAuth::setCurrentUserID();
1718                 api_direct_messages_box('json', 'sentbox', 'false');
1719         }
1720
1721         /**
1722          * Test the api_direct_messages_sentbox() function.
1723          *
1724          * @return void
1725          */
1726         public function testApiDirectMessagesSentbox()
1727         {
1728                 $result = api_direct_messages_sentbox('json');
1729                 self::assertArrayHasKey('direct_message', $result);
1730         }
1731
1732         /**
1733          * Test the api_direct_messages_inbox() function.
1734          *
1735          * @return void
1736          */
1737         public function testApiDirectMessagesInbox()
1738         {
1739                 $result = api_direct_messages_inbox('json');
1740                 self::assertArrayHasKey('direct_message', $result);
1741         }
1742
1743         /**
1744          * Test the api_direct_messages_all() function.
1745          *
1746          * @return void
1747          */
1748         public function testApiDirectMessagesAll()
1749         {
1750                 $result = api_direct_messages_all('json');
1751                 self::assertArrayHasKey('direct_message', $result);
1752         }
1753
1754         /**
1755          * Test the api_direct_messages_conversation() function.
1756          *
1757          * @return void
1758          */
1759         public function testApiDirectMessagesConversation()
1760         {
1761                 $result = api_direct_messages_conversation('json');
1762                 self::assertArrayHasKey('direct_message', $result);
1763         }
1764
1765         /**
1766          * Test the api_oauth_request_token() function.
1767          *
1768          * @return void
1769          */
1770         public function testApiOauthRequestToken()
1771         {
1772                 $this->markTestIncomplete('exit() kills phpunit as well');
1773         }
1774
1775         /**
1776          * Test the api_oauth_access_token() function.
1777          *
1778          * @return void
1779          */
1780         public function testApiOauthAccessToken()
1781         {
1782                 $this->markTestIncomplete('exit() kills phpunit as well');
1783         }
1784
1785         /**
1786          * Test the api_fr_photos_list() function.
1787          *
1788          * @return void
1789          */
1790         public function testApiFrPhotosList()
1791         {
1792                 $result = api_fr_photos_list('json');
1793                 self::assertArrayHasKey('photo', $result);
1794         }
1795
1796         /**
1797          * Test the api_fr_photos_list() function without an authenticated user.
1798          *
1799          * @return void
1800          */
1801         public function testApiFrPhotosListWithoutAuthenticatedUser()
1802         {
1803                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1804                 BasicAuth::setCurrentUserID();
1805                 $_SESSION['authenticated'] = false;
1806                 api_fr_photos_list('json');
1807         }
1808
1809         /**
1810          * Test the api_fr_photo_create_update() function.
1811          */
1812         public function testApiFrPhotoCreateUpdate()
1813         {
1814                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1815                 api_fr_photo_create_update('json');
1816         }
1817
1818         /**
1819          * Test the api_fr_photo_create_update() function without an authenticated user.
1820          *
1821          * @return void
1822          */
1823         public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
1824         {
1825                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1826                 BasicAuth::setCurrentUserID();
1827                 $_SESSION['authenticated'] = false;
1828                 api_fr_photo_create_update('json');
1829         }
1830
1831         /**
1832          * Test the api_fr_photo_create_update() function with an album name.
1833          *
1834          * @return void
1835          */
1836         public function testApiFrPhotoCreateUpdateWithAlbum()
1837         {
1838                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1839                 $_REQUEST['album'] = 'album_name';
1840                 api_fr_photo_create_update('json');
1841         }
1842
1843         /**
1844          * Test the api_fr_photo_create_update() function with the update mode.
1845          *
1846          * @return void
1847          */
1848         public function testApiFrPhotoCreateUpdateWithUpdate()
1849         {
1850                 $this->markTestIncomplete('We need to create a dataset for this');
1851         }
1852
1853         /**
1854          * Test the api_fr_photo_create_update() function with an uploaded file.
1855          *
1856          * @return void
1857          */
1858         public function testApiFrPhotoCreateUpdateWithFile()
1859         {
1860                 $this->markTestIncomplete();
1861         }
1862
1863         /**
1864          * Test the api_fr_photo_detail() function.
1865          *
1866          * @return void
1867          */
1868         public function testApiFrPhotoDetail()
1869         {
1870                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1871                 api_fr_photo_detail('json');
1872         }
1873
1874         /**
1875          * Test the api_fr_photo_detail() function without an authenticated user.
1876          *
1877          * @return void
1878          */
1879         public function testApiFrPhotoDetailWithoutAuthenticatedUser()
1880         {
1881                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1882                 BasicAuth::setCurrentUserID();
1883                 $_SESSION['authenticated'] = false;
1884                 api_fr_photo_detail('json');
1885         }
1886
1887         /**
1888          * Test the api_fr_photo_detail() function with a photo ID.
1889          *
1890          * @return void
1891          */
1892         public function testApiFrPhotoDetailWithPhotoId()
1893         {
1894                 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1895                 $_REQUEST['photo_id'] = 1;
1896                 api_fr_photo_detail('json');
1897         }
1898
1899         /**
1900          * Test the api_fr_photo_detail() function with a correct photo ID.
1901          *
1902          * @return void
1903          */
1904         public function testApiFrPhotoDetailCorrectPhotoId()
1905         {
1906                 $this->markTestIncomplete('We need to create a dataset for this.');
1907         }
1908
1909         /**
1910          * Test the api_account_update_profile_image() function.
1911          *
1912          * @return void
1913          */
1914         public function testApiAccountUpdateProfileImage()
1915         {
1916                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1917                 api_account_update_profile_image('json');
1918         }
1919
1920         /**
1921          * Test the api_account_update_profile_image() function without an authenticated user.
1922          *
1923          * @return void
1924          */
1925         public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
1926         {
1927                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1928                 BasicAuth::setCurrentUserID();
1929                 $_SESSION['authenticated'] = false;
1930                 api_account_update_profile_image('json');
1931         }
1932
1933         /**
1934          * Test the api_account_update_profile_image() function with an uploaded file.
1935          *
1936          * @return void
1937          */
1938         public function testApiAccountUpdateProfileImageWithUpload()
1939         {
1940                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1941                 $this->markTestIncomplete();
1942         }
1943
1944         /**
1945          * Test the check_acl_input() function.
1946          *
1947          * @return void
1948          */
1949         public function testCheckAclInput()
1950         {
1951                 $result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
1952                 // Where does this result come from?
1953                 self::assertEquals(1, $result);
1954         }
1955
1956         /**
1957          * Test the check_acl_input() function with an empty ACL string.
1958          *
1959          * @return void
1960          */
1961         public function testCheckAclInputWithEmptyAclString()
1962         {
1963                 $result = check_acl_input(' ', BaseApi::getCurrentUserID());
1964                 self::assertFalse($result);
1965         }
1966
1967         /**
1968          * Test the save_media_to_database() function.
1969          *
1970          * @return void
1971          */
1972         public function testSaveMediaToDatabase()
1973         {
1974                 $this->markTestIncomplete();
1975         }
1976
1977         /**
1978          * Test the post_photo_item() function.
1979          *
1980          * @return void
1981          */
1982         public function testPostPhotoItem()
1983         {
1984                 $this->markTestIncomplete();
1985         }
1986
1987         /**
1988          * Test the prepare_photo_data() function.
1989          *
1990          * @return void
1991          */
1992         public function testPreparePhotoData()
1993         {
1994                 $this->markTestIncomplete();
1995         }
1996
1997         /**
1998          * Test the api_share_as_retweet() function with a valid item.
1999          *
2000          * @return void
2001          */
2002         public function testApiShareAsRetweetWithValidItem()
2003         {
2004                 $this->markTestIncomplete();
2005         }
2006
2007         /**
2008          * Test the api_in_reply_to() function with a valid item.
2009          *
2010          * @return void
2011          */
2012         public function testApiInReplyToWithValidItem()
2013         {
2014                 $this->markTestIncomplete();
2015         }
2016
2017         /**
2018          * Test the api_clean_plain_items() function.
2019          *
2020          * @return void
2021          */
2022         public function testApiCleanPlainItems()
2023         {
2024                 $_REQUEST['include_entities'] = 'true';
2025                 $result                       = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
2026                 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
2027         }
2028
2029         /**
2030          * Test the api_best_nickname() function with contacts.
2031          *
2032          * @return void
2033          */
2034         public function testApiBestNicknameWithContacts()
2035         {
2036                 $this->markTestIncomplete();
2037         }
2038
2039         /**
2040          * Test the api_friendica_group_show() function.
2041          *
2042          * @return void
2043          */
2044         public function testApiFriendicaGroupShow()
2045         {
2046                 $this->markTestIncomplete();
2047         }
2048
2049         /**
2050          * Test the api_friendica_group_delete() function.
2051          *
2052          * @return void
2053          */
2054         public function testApiFriendicaGroupDelete()
2055         {
2056                 $this->markTestIncomplete();
2057         }
2058
2059         /**
2060          * Test the api_lists_destroy() function.
2061          *
2062          * @return void
2063          */
2064         public function testApiListsDestroy()
2065         {
2066                 $this->markTestIncomplete();
2067         }
2068
2069         /**
2070          * Test the group_create() function.
2071          *
2072          * @return void
2073          */
2074         public function testGroupCreate()
2075         {
2076                 $this->markTestIncomplete();
2077         }
2078
2079         /**
2080          * Test the api_friendica_group_create() function.
2081          *
2082          * @return void
2083          */
2084         public function testApiFriendicaGroupCreate()
2085         {
2086                 $this->markTestIncomplete();
2087         }
2088
2089         /**
2090          * Test the api_lists_create() function.
2091          *
2092          * @return void
2093          */
2094         public function testApiListsCreate()
2095         {
2096                 $this->markTestIncomplete();
2097         }
2098
2099         /**
2100          * Test the api_friendica_group_update() function.
2101          *
2102          * @return void
2103          */
2104         public function testApiFriendicaGroupUpdate()
2105         {
2106                 $this->markTestIncomplete();
2107         }
2108
2109         /**
2110          * Test the api_lists_update() function.
2111          *
2112          * @return void
2113          */
2114         public function testApiListsUpdate()
2115         {
2116                 $this->markTestIncomplete();
2117         }
2118
2119         /**
2120          * Test the api_friendica_activity() function.
2121          *
2122          * @return void
2123          */
2124         public function testApiFriendicaActivity()
2125         {
2126                 $this->markTestIncomplete();
2127         }
2128
2129         /**
2130          * Test the api_friendica_notification_seen() function.
2131          *
2132          * @return void
2133          */
2134         public function testApiFriendicaNotificationSeen()
2135         {
2136                 $this->markTestIncomplete();
2137         }
2138
2139         /**
2140          * Test the api_friendica_direct_messages_setseen() function.
2141          *
2142          * @return void
2143          */
2144         public function testApiFriendicaDirectMessagesSetseen()
2145         {
2146                 $this->markTestIncomplete();
2147         }
2148
2149         /**
2150          * Test the api_friendica_direct_messages_search() function.
2151          *
2152          * @return void
2153          */
2154         public function testApiFriendicaDirectMessagesSearch()
2155         {
2156                 $this->markTestIncomplete();
2157         }
2158 }