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