]> git.mxchange.org Git - friendica.git/blob - tests/include/ApiTest.php
Merge pull request #8186 from nupplaphil/bug/8182_another_notification_bug
[friendica.git] / tests / include / ApiTest.php
1 <?php
2 /**
3  * ApiTest class.
4  */
5
6 namespace Friendica\Test;
7
8 use Dice\Dice;
9 use Friendica\App;
10 use Friendica\Core\Config\IConfig;
11 use Friendica\Core\PConfig\IPConfig;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Session;
14 use Friendica\Core\Session\ISession;
15 use Friendica\Core\System;
16 use Friendica\Database\Database;
17 use Friendica\Database\DBA;
18 use Friendica\DI;
19 use Friendica\Model\Contact;
20 use Friendica\Network\HTTPException;
21 use Friendica\Test\Util\Database\StaticDatabase;
22 use Monolog\Handler\TestHandler;
23
24 require_once __DIR__ . '/../../include/api.php';
25
26 /**
27  * Tests for the API functions.
28  *
29  * Functions that use header() need to be tested in a separate process.
30  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31  */
32 class ApiTest extends DatabaseTest
33 {
34         /**
35          * @var TestHandler Can handle log-outputs
36          */
37         protected $logOutput;
38
39         /** @var array */
40         protected $selfUser;
41         /** @var array */
42         protected $friendUser;
43         /** @var array */
44         protected $otherUser;
45
46         protected $wrongUserId;
47
48         /** @var App */
49         protected $app;
50
51         /** @var IConfig */
52         protected $config;
53
54         /** @var Dice */
55         protected $dice;
56
57         /**
58          * Create variables used by tests.
59          */
60         protected function setUp()
61         {
62                 parent::setUp();
63
64                 $this->dice = (new Dice())
65                         ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
66                         ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
67                         ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
68                 DI::init($this->dice);
69
70                 /** @var Database $dba */
71                 $dba = $this->dice->create(Database::class);
72
73                 /** @var IConfig $config */
74                 $this->config = $this->dice->create(IConfig::class);
75
76                 $this->config->set('system', 'url', 'http://localhost');
77                 $this->config->set('system', 'hostname', 'localhost');
78                 $this->config->set('system', 'worker_dont_fork', true);
79
80                 // Default config
81                 $this->config->set('config', 'hostname', 'localhost');
82                 $this->config->set('system', 'throttle_limit_day', 100);
83                 $this->config->set('system', 'throttle_limit_week', 100);
84                 $this->config->set('system', 'throttle_limit_month', 100);
85                 $this->config->set('system', 'theme', 'system_theme');
86
87                 // Load the API dataset for the whole API
88                 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
89
90                 /** @var App app */
91                 $this->app = DI::app();
92
93                 $this->app->argc = 1;
94                 $this->app->argv = ['home'];
95
96                 // User data that the test database is populated with
97                 $this->selfUser   = [
98                         'id'   => 42,
99                         'name' => 'Self contact',
100                         'nick' => 'selfcontact',
101                         'nurl' => 'http://localhost/profile/selfcontact'
102                 ];
103                 $this->friendUser = [
104                         'id'   => 44,
105                         'name' => 'Friend contact',
106                         'nick' => 'friendcontact',
107                         'nurl' => 'http://localhost/profile/friendcontact'
108                 ];
109                 $this->otherUser  = [
110                         'id'   => 43,
111                         'name' => 'othercontact',
112                         'nick' => 'othercontact',
113                         'nurl' => 'http://localhost/profile/othercontact'
114                 ];
115
116                 // User ID that we know is not in the database
117                 $this->wrongUserId = 666;
118
119                 DI::session()->start();
120
121                 // Most API require login so we force the session
122                 $_SESSION = [
123                         'allow_api'     => true,
124                         'authenticated' => true,
125                         'uid'           => $this->selfUser['id']
126                 ];
127
128                 $_POST   = [];
129                 $_GET    = [];
130                 $_SERVER = [];
131         }
132
133         /**
134          * Assert that an user array contains expected keys.
135          *
136          * @param array $user User array
137          *
138          * @return void
139          */
140         private function assertSelfUser(array $user)
141         {
142                 $this->assertEquals($this->selfUser['id'], $user['uid']);
143                 $this->assertEquals($this->selfUser['id'], $user['cid']);
144                 $this->assertEquals(1, $user['self']);
145                 $this->assertEquals('DFRN', $user['location']);
146                 $this->assertEquals($this->selfUser['name'], $user['name']);
147                 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
148                 $this->assertEquals('dfrn', $user['network']);
149                 $this->assertTrue($user['verified']);
150         }
151
152         /**
153          * Assert that an user array contains expected keys.
154          *
155          * @param array $user User array
156          *
157          * @return void
158          */
159         private function assertOtherUser(array $user)
160         {
161                 $this->assertEquals($this->otherUser['id'], $user['id']);
162                 $this->assertEquals($this->otherUser['id'], $user['id_str']);
163                 $this->assertEquals(0, $user['self']);
164                 $this->assertEquals($this->otherUser['name'], $user['name']);
165                 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
166                 $this->assertFalse($user['verified']);
167         }
168
169         /**
170          * Assert that a status array contains expected keys.
171          *
172          * @param array $status Status array
173          *
174          * @return void
175          */
176         private function assertStatus(array $status)
177         {
178                 $this->assertInternalType('string', $status['text']);
179                 $this->assertInternalType('int', $status['id']);
180                 // We could probably do more checks here.
181         }
182
183         /**
184          * Assert that a list array contains expected keys.
185          *
186          * @param array $list List array
187          *
188          * @return void
189          */
190         private function assertList(array $list)
191         {
192                 $this->assertInternalType('string', $list['name']);
193                 $this->assertInternalType('int', $list['id']);
194                 $this->assertInternalType('string', $list['id_str']);
195                 $this->assertContains($list['mode'], ['public', 'private']);
196                 // We could probably do more checks here.
197         }
198
199         /**
200          * Assert that the string is XML and contain the root element.
201          *
202          * @param string $result       XML string
203          * @param string $root_element Root element name
204          *
205          * @return void
206          */
207         private function assertXml($result, $root_element)
208         {
209                 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
210                 $this->assertContains('<' . $root_element, $result);
211                 // We could probably do more checks here.
212         }
213
214         /**
215          * Get the path to a temporary empty PNG image.
216          *
217          * @return string Path
218          */
219         private function getTempImage()
220         {
221                 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
222                 file_put_contents(
223                         $tmpFile,
224                         base64_decode(
225                         // Empty 1x1 px PNG image
226                                 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
227                         )
228                 );
229
230                 return $tmpFile;
231         }
232
233         /**
234          * Test the api_user() function.
235          *
236          * @return void
237          */
238         public function testApiUser()
239         {
240                 $this->assertEquals($this->selfUser['id'], api_user());
241         }
242
243         /**
244          * Test the api_user() function with an unallowed user.
245          *
246          * @return void
247          */
248         public function testApiUserWithUnallowedUser()
249         {
250                 $_SESSION = ['allow_api' => false];
251                 $this->assertEquals(false, api_user());
252         }
253
254         /**
255          * Test the api_source() function.
256          *
257          * @return void
258          */
259         public function testApiSource()
260         {
261                 $this->assertEquals('api', api_source());
262         }
263
264         /**
265          * Test the api_source() function with a Twidere user agent.
266          *
267          * @return void
268          */
269         public function testApiSourceWithTwidere()
270         {
271                 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
272                 $this->assertEquals('Twidere', api_source());
273         }
274
275         /**
276          * Test the api_source() function with a GET parameter.
277          *
278          * @return void
279          */
280         public function testApiSourceWithGet()
281         {
282                 $_GET['source'] = 'source_name';
283                 $this->assertEquals('source_name', api_source());
284         }
285
286         /**
287          * Test the api_date() function.
288          *
289          * @return void
290          */
291         public function testApiDate()
292         {
293                 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
294         }
295
296         /**
297          * Test the api_register_func() function.
298          *
299          * @return void
300          */
301         public function testApiRegisterFunc()
302         {
303                 global $API;
304                 $this->assertNull(
305                         api_register_func(
306                                 'api_path',
307                                 function () {
308                                 },
309                                 true,
310                                 'method'
311                         )
312                 );
313                 $this->assertTrue($API['api_path']['auth']);
314                 $this->assertEquals('method', $API['api_path']['method']);
315                 $this->assertTrue(is_callable($API['api_path']['func']));
316         }
317
318         /**
319          * Test the api_login() function without any login.
320          *
321          * @return void
322          * @runInSeparateProcess
323          * @expectedException Friendica\Network\HTTPException\UnauthorizedException
324          */
325         public function testApiLoginWithoutLogin()
326         {
327                 api_login($this->app);
328         }
329
330         /**
331          * Test the api_login() function with a bad login.
332          *
333          * @return void
334          * @runInSeparateProcess
335          * @expectedException Friendica\Network\HTTPException\UnauthorizedException
336          */
337         public function testApiLoginWithBadLogin()
338         {
339                 $_SERVER['PHP_AUTH_USER'] = 'user@server';
340                 api_login($this->app);
341         }
342
343         /**
344          * Test the api_login() function with oAuth.
345          *
346          * @return void
347          */
348         public function testApiLoginWithOauth()
349         {
350                 $this->markTestIncomplete('Can we test this easily?');
351         }
352
353         /**
354          * Test the api_login() function with authentication provided by an addon.
355          *
356          * @return void
357          */
358         public function testApiLoginWithAddonAuth()
359         {
360                 $this->markTestIncomplete('Can we test this easily?');
361         }
362
363         /**
364          * Test the api_login() function with a correct login.
365          *
366          * @return void
367          * @runInSeparateProcess
368          */
369         public function testApiLoginWithCorrectLogin()
370         {
371                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
372                 $_SERVER['PHP_AUTH_PW']   = 'password';
373                 api_login($this->app);
374         }
375
376         /**
377          * Test the api_login() function with a remote user.
378          *
379          * @return void
380          * @runInSeparateProcess
381          * @expectedException Friendica\Network\HTTPException\UnauthorizedException
382          */
383         public function testApiLoginWithRemoteUser()
384         {
385                 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
386                 api_login($this->app);
387         }
388
389         /**
390          * Test the api_check_method() function.
391          *
392          * @return void
393          */
394         public function testApiCheckMethod()
395         {
396                 $this->assertFalse(api_check_method('method'));
397         }
398
399         /**
400          * Test the api_check_method() function with a correct method.
401          *
402          * @return void
403          */
404         public function testApiCheckMethodWithCorrectMethod()
405         {
406                 $_SERVER['REQUEST_METHOD'] = 'method';
407                 $this->assertTrue(api_check_method('method'));
408         }
409
410         /**
411          * Test the api_check_method() function with a wildcard.
412          *
413          * @return void
414          */
415         public function testApiCheckMethodWithWildcard()
416         {
417                 $this->assertTrue(api_check_method('*'));
418         }
419
420         /**
421          * Test the api_call() function.
422          *
423          * @return void
424          * @runInSeparateProcess
425          */
426         public function testApiCall()
427         {
428                 global $API;
429                 $API['api_path']           = [
430                         'method' => 'method',
431                         'func'   => function () {
432                                 return ['data' => ['some_data']];
433                         }
434                 ];
435                 $_SERVER['REQUEST_METHOD'] = 'method';
436                 $_SERVER['QUERY_STRING'] = 'q=api_path';
437                 $_GET['callback']          = 'callback_name';
438
439                 $args = DI::args()->determine($_SERVER, $_GET);
440
441                 $this->assertEquals(
442                         'callback_name(["some_data"])',
443                         api_call($this->app, $args)
444                 );
445         }
446
447         /**
448          * Test the api_call() function with the profiled enabled.
449          *
450          * @return void
451          * @runInSeparateProcess
452          */
453         public function testApiCallWithProfiler()
454         {
455                 global $API;
456                 $API['api_path']           = [
457                         'method' => 'method',
458                         'func'   => function () {
459                                 return ['data' => ['some_data']];
460                         }
461                 ];
462
463                 $_SERVER['REQUEST_METHOD'] = 'method';
464                 $_SERVER['QUERY_STRING'] = 'q=api_path';
465
466                 $args = DI::args()->determine($_SERVER, $_GET);
467
468                 $this->config->set('system', 'profiler', true);
469                 $this->config->set('rendertime', 'callstack', true);
470                 $this->app->callstack = [
471                         'database'       => ['some_function' => 200],
472                         'database_write' => ['some_function' => 200],
473                         'cache'          => ['some_function' => 200],
474                         'cache_write'    => ['some_function' => 200],
475                         'network'        => ['some_function' => 200]
476                 ];
477
478                 $this->assertEquals(
479                         '["some_data"]',
480                         api_call($this->app, $args)
481                 );
482         }
483
484         /**
485          * Test the api_call() function without any result.
486          *
487          * @return void
488          * @runInSeparateProcess
489          */
490         public function testApiCallWithNoResult()
491         {
492                 global $API;
493                 $API['api_path']           = [
494                         'method' => 'method',
495                         'func'   => function () {
496                                 return false;
497                         }
498                 ];
499                 $_SERVER['REQUEST_METHOD'] = 'method';
500                 $_SERVER['QUERY_STRING'] = 'q=api_path';
501
502                 $args = DI::args()->determine($_SERVER, $_GET);
503
504                 $this->assertEquals(
505                         '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
506                         api_call($this->app, $args)
507                 );
508         }
509
510         /**
511          * Test the api_call() function with an unimplemented API.
512          *
513          * @return void
514          * @runInSeparateProcess
515          */
516         public function testApiCallWithUninplementedApi()
517         {
518                 $this->assertEquals(
519                         '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
520                         api_call($this->app)
521                 );
522         }
523
524         /**
525          * Test the api_call() function with a JSON result.
526          *
527          * @return void
528          * @runInSeparateProcess
529          */
530         public function testApiCallWithJson()
531         {
532                 global $API;
533                 $API['api_path']           = [
534                         'method' => 'method',
535                         'func'   => function () {
536                                 return ['data' => ['some_data']];
537                         }
538                 ];
539                 $_SERVER['REQUEST_METHOD'] = 'method';
540                 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
541
542                 $args = DI::args()->determine($_SERVER, $_GET);
543
544                 $this->assertEquals(
545                         '["some_data"]',
546                         api_call($this->app, $args)
547                 );
548         }
549
550         /**
551          * Test the api_call() function with an XML result.
552          *
553          * @return void
554          * @runInSeparateProcess
555          */
556         public function testApiCallWithXml()
557         {
558                 global $API;
559                 $API['api_path']           = [
560                         'method' => 'method',
561                         'func'   => function () {
562                                 return 'some_data';
563                         }
564                 ];
565                 $_SERVER['REQUEST_METHOD'] = 'method';
566                 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
567
568                 $args = DI::args()->determine($_SERVER, $_GET);
569
570                 $this->assertEquals(
571                         'some_data',
572                         api_call($this->app, $args)
573                 );
574         }
575
576         /**
577          * Test the api_call() function with an RSS result.
578          *
579          * @return void
580          * @runInSeparateProcess
581          */
582         public function testApiCallWithRss()
583         {
584                 global $API;
585                 $API['api_path']           = [
586                         'method' => 'method',
587                         'func'   => function () {
588                                 return 'some_data';
589                         }
590                 ];
591                 $_SERVER['REQUEST_METHOD'] = 'method';
592                 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
593
594                 $args = DI::args()->determine($_SERVER, $_GET);
595
596                 $this->assertEquals(
597                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
598                         'some_data',
599                         api_call($this->app, $args)
600                 );
601         }
602
603         /**
604          * Test the api_call() function with an Atom result.
605          *
606          * @return void
607          * @runInSeparateProcess
608          */
609         public function testApiCallWithAtom()
610         {
611                 global $API;
612                 $API['api_path']           = [
613                         'method' => 'method',
614                         'func'   => function () {
615                                 return 'some_data';
616                         }
617                 ];
618                 $_SERVER['REQUEST_METHOD'] = 'method';
619                 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
620
621                 $args = DI::args()->determine($_SERVER, $_GET);
622
623                 $this->assertEquals(
624                         '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
625                         'some_data',
626                         api_call($this->app, $args)
627                 );
628         }
629
630         /**
631          * Test the api_call() function with an unallowed method.
632          *
633          * @return void
634          * @runInSeparateProcess
635          */
636         public function testApiCallWithWrongMethod()
637         {
638                 global $API;
639                 $API['api_path'] = ['method' => 'method'];
640
641                 $_SERVER['QUERY_STRING'] = 'q=api_path';
642
643                 $args = DI::args()->determine($_SERVER, $_GET);
644
645                 $this->assertEquals(
646                         '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
647                         api_call($this->app, $args)
648                 );
649         }
650
651         /**
652          * Test the api_call() function with an unauthorized user.
653          *
654          * @return void
655          * @runInSeparateProcess
656          */
657         public function testApiCallWithWrongAuth()
658         {
659                 global $API;
660                 $API['api_path']           = [
661                         'method' => 'method',
662                         'auth'   => true
663                 ];
664                 $_SESSION['authenticated'] = false;
665                 $_SERVER['REQUEST_METHOD'] = 'method';
666                 $_SERVER['QUERY_STRING'] = 'q=api_path';
667
668                 $args = DI::args()->determine($_SERVER, $_GET);
669
670                 $this->assertEquals(
671                         '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
672                         api_call($this->app, $args)
673                 );
674         }
675
676         /**
677          * Test the api_error() function with a JSON result.
678          *
679          * @return void
680          * @runInSeparateProcess
681          */
682         public function testApiErrorWithJson()
683         {
684                 $this->assertEquals(
685                         '{"status":{"error":"error_message","code":"200 OK","request":""}}',
686                         api_error('json', new HTTPException\OKException('error_message'), DI::args())
687                 );
688         }
689
690         /**
691          * Test the api_error() function with an XML result.
692          *
693          * @return void
694          * @runInSeparateProcess
695          */
696         public function testApiErrorWithXml()
697         {
698                 $this->assertEquals(
699                         '<?xml version="1.0"?>' . "\n" .
700                         '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
701                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
702                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
703                         '  <error>error_message</error>' . "\n" .
704                         '  <code>200 OK</code>' . "\n" .
705                         '  <request/>' . "\n" .
706                         '</status>' . "\n",
707                         api_error('xml', new HTTPException\OKException('error_message'), DI::args())
708                 );
709         }
710
711         /**
712          * Test the api_error() function with an RSS result.
713          *
714          * @return void
715          * @runInSeparateProcess
716          */
717         public function testApiErrorWithRss()
718         {
719                 $this->assertEquals(
720                         '<?xml version="1.0"?>' . "\n" .
721                         '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
722                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
723                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
724                         '  <error>error_message</error>' . "\n" .
725                         '  <code>200 OK</code>' . "\n" .
726                         '  <request/>' . "\n" .
727                         '</status>' . "\n",
728                         api_error('rss', new HTTPException\OKException('error_message'), DI::args())
729                 );
730         }
731
732         /**
733          * Test the api_error() function with an Atom result.
734          *
735          * @return void
736          * @runInSeparateProcess
737          */
738         public function testApiErrorWithAtom()
739         {
740                 $this->assertEquals(
741                         '<?xml version="1.0"?>' . "\n" .
742                         '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
743                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
744                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
745                         '  <error>error_message</error>' . "\n" .
746                         '  <code>200 OK</code>' . "\n" .
747                         '  <request/>' . "\n" .
748                         '</status>' . "\n",
749                         api_error('atom', new HTTPException\OKException('error_message'), DI::args())
750                 );
751         }
752
753         /**
754          * Test the api_rss_extra() function.
755          *
756          * @return void
757          */
758         public function testApiRssExtra()
759         {
760                 $user_info = ['url' => 'user_url', 'lang' => 'en'];
761                 $result    = api_rss_extra($this->app, [], $user_info);
762                 $this->assertEquals($user_info, $result['$user']);
763                 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
764                 $this->assertArrayHasKey('self', $result['$rss']);
765                 $this->assertArrayHasKey('base', $result['$rss']);
766                 $this->assertArrayHasKey('updated', $result['$rss']);
767                 $this->assertArrayHasKey('atom_updated', $result['$rss']);
768                 $this->assertArrayHasKey('language', $result['$rss']);
769                 $this->assertArrayHasKey('logo', $result['$rss']);
770         }
771
772         /**
773          * Test the api_rss_extra() function without any user info.
774          *
775          * @return void
776          */
777         public function testApiRssExtraWithoutUserInfo()
778         {
779                 $result = api_rss_extra($this->app, [], null);
780                 $this->assertInternalType('array', $result['$user']);
781                 $this->assertArrayHasKey('alternate', $result['$rss']);
782                 $this->assertArrayHasKey('self', $result['$rss']);
783                 $this->assertArrayHasKey('base', $result['$rss']);
784                 $this->assertArrayHasKey('updated', $result['$rss']);
785                 $this->assertArrayHasKey('atom_updated', $result['$rss']);
786                 $this->assertArrayHasKey('language', $result['$rss']);
787                 $this->assertArrayHasKey('logo', $result['$rss']);
788         }
789
790         /**
791          * Test the api_unique_id_to_nurl() function.
792          *
793          * @return void
794          */
795         public function testApiUniqueIdToNurl()
796         {
797                 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
798         }
799
800         /**
801          * Test the api_unique_id_to_nurl() function with a correct ID.
802          *
803          * @return void
804          */
805         public function testApiUniqueIdToNurlWithCorrectId()
806         {
807                 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
808         }
809
810         /**
811          * Test the api_get_user() function.
812          *
813          * @return void
814          */
815         public function testApiGetUser()
816         {
817                 $user = api_get_user($this->app);
818                 $this->assertSelfUser($user);
819                 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
820                 $this->assertEquals('6fdbe8', $user['profile_link_color']);
821                 $this->assertEquals('ededed', $user['profile_background_color']);
822         }
823
824         /**
825          * Test the api_get_user() function with a Frio schema.
826          *
827          * @return void
828          */
829         public function testApiGetUserWithFrioSchema()
830         {
831                 $pConfig = $this->dice->create(IPConfig::class);
832                 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
833                 $user = api_get_user($this->app);
834                 $this->assertSelfUser($user);
835                 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
836                 $this->assertEquals('6fdbe8', $user['profile_link_color']);
837                 $this->assertEquals('ededed', $user['profile_background_color']);
838         }
839
840         /**
841          * Test the api_get_user() function with a custom Frio schema.
842          *
843          * @return void
844          */
845         public function testApiGetUserWithCustomFrioSchema()
846         {
847                 $pConfig = $this->dice->create(IPConfig::class);
848                 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
849                 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
850                 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
851                 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
852                 $user = api_get_user($this->app);
853                 $this->assertSelfUser($user);
854                 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
855                 $this->assertEquals('123456', $user['profile_link_color']);
856                 $this->assertEquals('123456', $user['profile_background_color']);
857         }
858
859         /**
860          * Test the api_get_user() function with an empty Frio schema.
861          *
862          * @return void
863          */
864         public function testApiGetUserWithEmptyFrioSchema()
865         {
866                 $pConfig = $this->dice->create(IPConfig::class);
867                 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
868                 $user = api_get_user($this->app);
869                 $this->assertSelfUser($user);
870                 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
871                 $this->assertEquals('6fdbe8', $user['profile_link_color']);
872                 $this->assertEquals('ededed', $user['profile_background_color']);
873         }
874
875         /**
876          * Test the api_get_user() function with an user that is not allowed to use the API.
877          *
878          * @return void
879          * @runInSeparateProcess
880          */
881         public function testApiGetUserWithoutApiUser()
882         {
883                 $_SERVER['PHP_AUTH_USER'] = 'Test user';
884                 $_SERVER['PHP_AUTH_PW']   = 'password';
885                 $_SESSION['allow_api']    = false;
886                 $this->assertFalse(api_get_user($this->app));
887         }
888
889         /**
890          * Test the api_get_user() function with an user ID in a GET parameter.
891          *
892          * @return void
893          */
894         public function testApiGetUserWithGetId()
895         {
896                 $_GET['user_id'] = $this->otherUser['id'];
897                 $this->assertOtherUser(api_get_user($this->app));
898         }
899
900         /**
901          * Test the api_get_user() function with a wrong user ID in a GET parameter.
902          *
903          * @return void
904          * @expectedException Friendica\Network\HTTPException\BadRequestException
905          */
906         public function testApiGetUserWithWrongGetId()
907         {
908                 $_GET['user_id'] = $this->wrongUserId;
909                 $this->assertOtherUser(api_get_user($this->app));
910         }
911
912         /**
913          * Test the api_get_user() function with an user name in a GET parameter.
914          *
915          * @return void
916          */
917         public function testApiGetUserWithGetName()
918         {
919                 $_GET['screen_name'] = $this->selfUser['nick'];
920                 $this->assertSelfUser(api_get_user($this->app));
921         }
922
923         /**
924          * Test the api_get_user() function with a profile URL in a GET parameter.
925          *
926          * @return void
927          */
928         public function testApiGetUserWithGetUrl()
929         {
930                 $_GET['profileurl'] = $this->selfUser['nurl'];
931                 $this->assertSelfUser(api_get_user($this->app));
932         }
933
934         /**
935          * Test the api_get_user() function with an user ID in the API path.
936          *
937          * @return void
938          */
939         public function testApiGetUserWithNumericCalledApi()
940         {
941                 global $called_api;
942                 $called_api         = ['api_path'];
943                 $this->app->argv[1] = $this->otherUser['id'] . '.json';
944                 $this->assertOtherUser(api_get_user($this->app));
945         }
946
947         /**
948          * Test the api_get_user() function with the $called_api global variable.
949          *
950          * @return void
951          */
952         public function testApiGetUserWithCalledApi()
953         {
954                 global $called_api;
955                 $called_api = ['api', 'api_path'];
956                 $this->assertSelfUser(api_get_user($this->app));
957         }
958
959         /**
960          * Test the api_get_user() function with a valid user.
961          *
962          * @return void
963          */
964         public function testApiGetUserWithCorrectUser()
965         {
966                 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
967         }
968
969         /**
970          * Test the api_get_user() function with a wrong user ID.
971          *
972          * @return void
973          * @expectedException Friendica\Network\HTTPException\BadRequestException
974          */
975         public function testApiGetUserWithWrongUser()
976         {
977                 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
978         }
979
980         /**
981          * Test the api_get_user() function with a 0 user ID.
982          *
983          * @return void
984          */
985         public function testApiGetUserWithZeroUser()
986         {
987                 $this->assertSelfUser(api_get_user($this->app, 0));
988         }
989
990         /**
991          * Test the api_item_get_user() function.
992          *
993          * @return void
994          */
995         public function testApiItemGetUser()
996         {
997                 $users = api_item_get_user($this->app, []);
998                 $this->assertSelfUser($users[0]);
999         }
1000
1001         /**
1002          * Test the api_item_get_user() function with a different item parent.
1003          *
1004          * @return void
1005          */
1006         public function testApiItemGetUserWithDifferentParent()
1007         {
1008                 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
1009                 $this->assertSelfUser($users[0]);
1010                 $this->assertEquals($users[0], $users[1]);
1011         }
1012
1013         /**
1014          * Test the api_walk_recursive() function.
1015          *
1016          * @return void
1017          */
1018         public function testApiWalkRecursive()
1019         {
1020                 $array = ['item1'];
1021                 $this->assertEquals(
1022                         $array,
1023                         api_walk_recursive(
1024                                 $array,
1025                                 function () {
1026                                         // Should we test this with a callback that actually does something?
1027                                         return true;
1028                                 }
1029                         )
1030                 );
1031         }
1032
1033         /**
1034          * Test the api_walk_recursive() function with an array.
1035          *
1036          * @return void
1037          */
1038         public function testApiWalkRecursiveWithArray()
1039         {
1040                 $array = [['item1'], ['item2']];
1041                 $this->assertEquals(
1042                         $array,
1043                         api_walk_recursive(
1044                                 $array,
1045                                 function () {
1046                                         // Should we test this with a callback that actually does something?
1047                                         return true;
1048                                 }
1049                         )
1050                 );
1051         }
1052
1053         /**
1054          * Test the api_reformat_xml() function.
1055          *
1056          * @return void
1057          */
1058         public function testApiReformatXml()
1059         {
1060                 $item = true;
1061                 $key  = '';
1062                 $this->assertTrue(api_reformat_xml($item, $key));
1063                 $this->assertEquals('true', $item);
1064         }
1065
1066         /**
1067          * Test the api_reformat_xml() function with a statusnet_api key.
1068          *
1069          * @return void
1070          */
1071         public function testApiReformatXmlWithStatusnetKey()
1072         {
1073                 $item = '';
1074                 $key  = 'statusnet_api';
1075                 $this->assertTrue(api_reformat_xml($item, $key));
1076                 $this->assertEquals('statusnet:api', $key);
1077         }
1078
1079         /**
1080          * Test the api_reformat_xml() function with a friendica_api key.
1081          *
1082          * @return void
1083          */
1084         public function testApiReformatXmlWithFriendicaKey()
1085         {
1086                 $item = '';
1087                 $key  = 'friendica_api';
1088                 $this->assertTrue(api_reformat_xml($item, $key));
1089                 $this->assertEquals('friendica:api', $key);
1090         }
1091
1092         /**
1093          * Test the api_create_xml() function.
1094          *
1095          * @return void
1096          */
1097         public function testApiCreateXml()
1098         {
1099                 $this->assertEquals(
1100                         '<?xml version="1.0"?>' . "\n" .
1101                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1102                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1103                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1104                         '  <data>some_data</data>' . "\n" .
1105                         '</root_element>' . "\n",
1106                         api_create_xml(['data' => ['some_data']], 'root_element')
1107                 );
1108         }
1109
1110         /**
1111          * Test the api_create_xml() function without any XML namespace.
1112          *
1113          * @return void
1114          */
1115         public function testApiCreateXmlWithoutNamespaces()
1116         {
1117                 $this->assertEquals(
1118                         '<?xml version="1.0"?>' . "\n" .
1119                         '<ok>' . "\n" .
1120                         '  <data>some_data</data>' . "\n" .
1121                         '</ok>' . "\n",
1122                         api_create_xml(['data' => ['some_data']], 'ok')
1123                 );
1124         }
1125
1126         /**
1127          * Test the api_format_data() function.
1128          *
1129          * @return void
1130          */
1131         public function testApiFormatData()
1132         {
1133                 $data = ['some_data'];
1134                 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1135         }
1136
1137         /**
1138          * Test the api_format_data() function with an XML result.
1139          *
1140          * @return void
1141          */
1142         public function testApiFormatDataWithXml()
1143         {
1144                 $this->assertEquals(
1145                         '<?xml version="1.0"?>' . "\n" .
1146                         '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1147                         'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1148                         'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1149                         '  <data>some_data</data>' . "\n" .
1150                         '</root_element>' . "\n",
1151                         api_format_data('root_element', 'xml', ['data' => ['some_data']])
1152                 );
1153         }
1154
1155         /**
1156          * Test the api_account_verify_credentials() function.
1157          *
1158          * @return void
1159          */
1160         public function testApiAccountVerifyCredentials()
1161         {
1162                 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1163         }
1164
1165         /**
1166          * Test the api_account_verify_credentials() function without an authenticated user.
1167          *
1168          * @return void
1169          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1170          */
1171         public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1172         {
1173                 $_SESSION['authenticated'] = false;
1174                 api_account_verify_credentials('json');
1175         }
1176
1177         /**
1178          * Test the requestdata() function.
1179          *
1180          * @return void
1181          */
1182         public function testRequestdata()
1183         {
1184                 $this->assertNull(requestdata('variable_name'));
1185         }
1186
1187         /**
1188          * Test the requestdata() function with a POST parameter.
1189          *
1190          * @return void
1191          */
1192         public function testRequestdataWithPost()
1193         {
1194                 $_POST['variable_name'] = 'variable_value';
1195                 $this->assertEquals('variable_value', requestdata('variable_name'));
1196         }
1197
1198         /**
1199          * Test the requestdata() function with a GET parameter.
1200          *
1201          * @return void
1202          */
1203         public function testRequestdataWithGet()
1204         {
1205                 $_GET['variable_name'] = 'variable_value';
1206                 $this->assertEquals('variable_value', requestdata('variable_name'));
1207         }
1208
1209         /**
1210          * Test the api_statuses_mediap() function.
1211          *
1212          * @return void
1213          */
1214         public function testApiStatusesMediap()
1215         {
1216                 $this->app->argc = 2;
1217
1218                 $_FILES         = [
1219                         'media' => [
1220                                 'id'       => 666,
1221                                 'size'     => 666,
1222                                 'width'    => 666,
1223                                 'height'   => 666,
1224                                 'tmp_name' => $this->getTempImage(),
1225                                 'name'     => 'spacer.png',
1226                                 'type'     => 'image/png'
1227                         ]
1228                 ];
1229                 $_GET['status'] = '<b>Status content</b>';
1230
1231                 $result = api_statuses_mediap('json');
1232                 $this->assertStatus($result['status']);
1233         }
1234
1235         /**
1236          * Test the api_statuses_mediap() function without an authenticated user.
1237          *
1238          * @return void
1239          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1240          */
1241         public function testApiStatusesMediapWithoutAuthenticatedUser()
1242         {
1243                 $_SESSION['authenticated'] = false;
1244                 api_statuses_mediap('json');
1245         }
1246
1247         /**
1248          * Test the api_statuses_update() function.
1249          *
1250          * @return void
1251          */
1252         public function testApiStatusesUpdate()
1253         {
1254                 $_GET['status']                = 'Status content #friendica';
1255                 $_GET['in_reply_to_status_id'] = -1;
1256                 $_GET['lat']                   = 48;
1257                 $_GET['long']                  = 7;
1258                 $_FILES                        = [
1259                         'media' => [
1260                                 'id'       => 666,
1261                                 'size'     => 666,
1262                                 'width'    => 666,
1263                                 'height'   => 666,
1264                                 'tmp_name' => $this->getTempImage(),
1265                                 'name'     => 'spacer.png',
1266                                 'type'     => 'image/png'
1267                         ]
1268                 ];
1269
1270                 $result = api_statuses_update('json');
1271                 $this->assertStatus($result['status']);
1272         }
1273
1274         /**
1275          * Test the api_statuses_update() function with an HTML status.
1276          *
1277          * @return void
1278          */
1279         public function testApiStatusesUpdateWithHtml()
1280         {
1281                 $_GET['htmlstatus'] = '<b>Status content</b>';
1282
1283                 $result = api_statuses_update('json');
1284                 $this->assertStatus($result['status']);
1285         }
1286
1287         /**
1288          * Test the api_statuses_update() function without an authenticated user.
1289          *
1290          * @return void
1291          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1292          */
1293         public function testApiStatusesUpdateWithoutAuthenticatedUser()
1294         {
1295                 $_SESSION['authenticated'] = false;
1296                 api_statuses_update('json');
1297         }
1298
1299         /**
1300          * Test the api_statuses_update() function with a parent status.
1301          *
1302          * @return void
1303          */
1304         public function testApiStatusesUpdateWithParent()
1305         {
1306                 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1307         }
1308
1309         /**
1310          * Test the api_statuses_update() function with a media_ids parameter.
1311          *
1312          * @return void
1313          */
1314         public function testApiStatusesUpdateWithMediaIds()
1315         {
1316                 $this->markTestIncomplete();
1317         }
1318
1319         /**
1320          * Test the api_statuses_update() function with the throttle limit reached.
1321          *
1322          * @return void
1323          */
1324         public function testApiStatusesUpdateWithDayThrottleReached()
1325         {
1326                 $this->markTestIncomplete();
1327         }
1328
1329         /**
1330          * Test the api_media_upload() function.
1331          *
1332          * @return void
1333          * @expectedException Friendica\Network\HTTPException\BadRequestException
1334          */
1335         public function testApiMediaUpload()
1336         {
1337                 api_media_upload();
1338         }
1339
1340         /**
1341          * Test the api_media_upload() function without an authenticated user.
1342          *
1343          * @return void
1344          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1345          */
1346         public function testApiMediaUploadWithoutAuthenticatedUser()
1347         {
1348                 $_SESSION['authenticated'] = false;
1349                 api_media_upload();
1350         }
1351
1352         /**
1353          * Test the api_media_upload() function with an invalid uploaded media.
1354          *
1355          * @return void
1356          * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1357          */
1358         public function testApiMediaUploadWithMedia()
1359         {
1360                 $_FILES = [
1361                         'media' => [
1362                                 'id'       => 666,
1363                                 'tmp_name' => 'tmp_name'
1364                         ]
1365                 ];
1366                 api_media_upload();
1367         }
1368
1369         /**
1370          * Test the api_media_upload() function with an valid uploaded media.
1371          *
1372          * @return void
1373          */
1374         public function testApiMediaUploadWithValidMedia()
1375         {
1376                 $_FILES    = [
1377                         'media' => [
1378                                 'id'       => 666,
1379                                 'size'     => 666,
1380                                 'width'    => 666,
1381                                 'height'   => 666,
1382                                 'tmp_name' => $this->getTempImage(),
1383                                 'name'     => 'spacer.png',
1384                                 'type'     => 'image/png'
1385                         ]
1386                 ];
1387                 $app       = DI::app();
1388                 $app->argc = 2;
1389
1390                 $result = api_media_upload();
1391                 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1392                 $this->assertEquals(1, $result['media']['image']['w']);
1393                 $this->assertEquals(1, $result['media']['image']['h']);
1394                 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1395         }
1396
1397         /**
1398          * Test the api_status_show() function.
1399          */
1400         public function testApiStatusShowWithJson()
1401         {
1402                 $result = api_status_show('json', 1);
1403                 $this->assertStatus($result['status']);
1404         }
1405
1406         /**
1407          * Test the api_status_show() function with an XML result.
1408          */
1409         public function testApiStatusShowWithXml()
1410         {
1411                 $result = api_status_show('xml', 1);
1412                 $this->assertXml($result, 'statuses');
1413         }
1414
1415         /**
1416          * Test the api_get_last_status() function
1417          */
1418         public function testApiGetLastStatus()
1419         {
1420                 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1421
1422                 $this->assertNotNull($item);
1423         }
1424
1425         /**
1426          * Test the api_users_show() function.
1427          *
1428          * @return void
1429          */
1430         public function testApiUsersShow()
1431         {
1432                 $result = api_users_show('json');
1433                 // We can't use assertSelfUser() here because the user object is missing some properties.
1434                 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1435                 $this->assertEquals('DFRN', $result['user']['location']);
1436                 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1437                 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1438                 $this->assertEquals('dfrn', $result['user']['network']);
1439                 $this->assertTrue($result['user']['verified']);
1440         }
1441
1442         /**
1443          * Test the api_users_show() function with an XML result.
1444          *
1445          * @return void
1446          */
1447         public function testApiUsersShowWithXml()
1448         {
1449                 $result = api_users_show('xml');
1450                 $this->assertXml($result, 'statuses');
1451         }
1452
1453         /**
1454          * Test the api_users_search() function.
1455          *
1456          * @return void
1457          */
1458         public function testApiUsersSearch()
1459         {
1460                 $_GET['q'] = 'othercontact';
1461                 $result    = api_users_search('json');
1462                 $this->assertOtherUser($result['users'][0]);
1463         }
1464
1465         /**
1466          * Test the api_users_search() function with an XML result.
1467          *
1468          * @return void
1469          */
1470         public function testApiUsersSearchWithXml()
1471         {
1472                 $_GET['q'] = 'othercontact';
1473                 $result    = api_users_search('xml');
1474                 $this->assertXml($result, 'users');
1475         }
1476
1477         /**
1478          * Test the api_users_search() function without a GET q parameter.
1479          *
1480          * @return void
1481          * @expectedException Friendica\Network\HTTPException\BadRequestException
1482          */
1483         public function testApiUsersSearchWithoutQuery()
1484         {
1485                 api_users_search('json');
1486         }
1487
1488         /**
1489          * Test the api_users_lookup() function.
1490          *
1491          * @return void
1492          * @expectedException Friendica\Network\HTTPException\NotFoundException
1493          */
1494         public function testApiUsersLookup()
1495         {
1496                 api_users_lookup('json');
1497         }
1498
1499         /**
1500          * Test the api_users_lookup() function with an user ID.
1501          *
1502          * @return void
1503          */
1504         public function testApiUsersLookupWithUserId()
1505         {
1506                 $_REQUEST['user_id'] = $this->otherUser['id'];
1507                 $result              = api_users_lookup('json');
1508                 $this->assertOtherUser($result['users'][0]);
1509         }
1510
1511         /**
1512          * Test the api_search() function.
1513          *
1514          * @return void
1515          */
1516         public function testApiSearch()
1517         {
1518                 $_REQUEST['q']      = 'reply';
1519                 $_REQUEST['max_id'] = 10;
1520                 $result             = api_search('json');
1521                 foreach ($result['status'] as $status) {
1522                         $this->assertStatus($status);
1523                         $this->assertContains('reply', $status['text'], null, true);
1524                 }
1525         }
1526
1527         /**
1528          * Test the api_search() function a count parameter.
1529          *
1530          * @return void
1531          */
1532         public function testApiSearchWithCount()
1533         {
1534                 $_REQUEST['q']     = 'reply';
1535                 $_REQUEST['count'] = 20;
1536                 $result            = api_search('json');
1537                 foreach ($result['status'] as $status) {
1538                         $this->assertStatus($status);
1539                         $this->assertContains('reply', $status['text'], null, true);
1540                 }
1541         }
1542
1543         /**
1544          * Test the api_search() function with an rpp parameter.
1545          *
1546          * @return void
1547          */
1548         public function testApiSearchWithRpp()
1549         {
1550                 $_REQUEST['q']   = 'reply';
1551                 $_REQUEST['rpp'] = 20;
1552                 $result          = api_search('json');
1553                 foreach ($result['status'] as $status) {
1554                         $this->assertStatus($status);
1555                         $this->assertContains('reply', $status['text'], null, true);
1556                 }
1557         }
1558
1559         /**
1560          * Test the api_search() function with an q parameter contains hashtag.
1561          *
1562          * @return void
1563          */
1564         public function testApiSearchWithHashtag()
1565         {
1566                 $_REQUEST['q'] = '%23friendica';
1567                 $result        = api_search('json');
1568                 foreach ($result['status'] as $status) {
1569                         $this->assertStatus($status);
1570                         $this->assertContains('#friendica', $status['text'], null, true);
1571                 }
1572         }
1573
1574         /**
1575          * Test the api_search() function with an exclude_replies parameter.
1576          *
1577          * @return void
1578          */
1579         public function testApiSearchWithExcludeReplies()
1580         {
1581                 $_REQUEST['max_id']          = 10;
1582                 $_REQUEST['exclude_replies'] = true;
1583                 $_REQUEST['q']               = 'friendica';
1584                 $result                      = api_search('json');
1585                 foreach ($result['status'] as $status) {
1586                         $this->assertStatus($status);
1587                 }
1588         }
1589
1590         /**
1591          * Test the api_search() function without an authenticated user.
1592          *
1593          * @return void
1594          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1595          */
1596         public function testApiSearchWithUnallowedUser()
1597         {
1598                 $_SESSION['allow_api'] = false;
1599                 $_GET['screen_name']   = $this->selfUser['nick'];
1600                 api_search('json');
1601         }
1602
1603         /**
1604          * Test the api_search() function without any GET query parameter.
1605          *
1606          * @return void
1607          * @expectedException Friendica\Network\HTTPException\BadRequestException
1608          */
1609         public function testApiSearchWithoutQuery()
1610         {
1611                 api_search('json');
1612         }
1613
1614         /**
1615          * Test the api_statuses_home_timeline() function.
1616          *
1617          * @return void
1618          */
1619         public function testApiStatusesHomeTimeline()
1620         {
1621                 $_REQUEST['max_id']          = 10;
1622                 $_REQUEST['exclude_replies'] = true;
1623                 $_REQUEST['conversation_id'] = 1;
1624                 $result                      = api_statuses_home_timeline('json');
1625                 $this->assertNotEmpty($result['status']);
1626                 foreach ($result['status'] as $status) {
1627                         $this->assertStatus($status);
1628                 }
1629         }
1630
1631         /**
1632          * Test the api_statuses_home_timeline() function with a negative page parameter.
1633          *
1634          * @return void
1635          */
1636         public function testApiStatusesHomeTimelineWithNegativePage()
1637         {
1638                 $_REQUEST['page'] = -2;
1639                 $result           = api_statuses_home_timeline('json');
1640                 $this->assertNotEmpty($result['status']);
1641                 foreach ($result['status'] as $status) {
1642                         $this->assertStatus($status);
1643                 }
1644         }
1645
1646         /**
1647          * Test the api_statuses_home_timeline() with an unallowed user.
1648          *
1649          * @return void
1650          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1651          */
1652         public function testApiStatusesHomeTimelineWithUnallowedUser()
1653         {
1654                 $_SESSION['allow_api'] = false;
1655                 $_GET['screen_name']   = $this->selfUser['nick'];
1656                 api_statuses_home_timeline('json');
1657         }
1658
1659         /**
1660          * Test the api_statuses_home_timeline() function with an RSS result.
1661          *
1662          * @return void
1663          */
1664         public function testApiStatusesHomeTimelineWithRss()
1665         {
1666                 $result = api_statuses_home_timeline('rss');
1667                 $this->assertXml($result, 'statuses');
1668         }
1669
1670         /**
1671          * Test the api_statuses_public_timeline() function.
1672          *
1673          * @return void
1674          */
1675         public function testApiStatusesPublicTimeline()
1676         {
1677                 $_REQUEST['max_id']          = 10;
1678                 $_REQUEST['conversation_id'] = 1;
1679                 $result                      = api_statuses_public_timeline('json');
1680                 $this->assertNotEmpty($result['status']);
1681                 foreach ($result['status'] as $status) {
1682                         $this->assertStatus($status);
1683                 }
1684         }
1685
1686         /**
1687          * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1688          *
1689          * @return void
1690          */
1691         public function testApiStatusesPublicTimelineWithExcludeReplies()
1692         {
1693                 $_REQUEST['max_id']          = 10;
1694                 $_REQUEST['exclude_replies'] = true;
1695                 $result                      = api_statuses_public_timeline('json');
1696                 $this->assertNotEmpty($result['status']);
1697                 foreach ($result['status'] as $status) {
1698                         $this->assertStatus($status);
1699                 }
1700         }
1701
1702         /**
1703          * Test the api_statuses_public_timeline() function with a negative page parameter.
1704          *
1705          * @return void
1706          */
1707         public function testApiStatusesPublicTimelineWithNegativePage()
1708         {
1709                 $_REQUEST['page'] = -2;
1710                 $result           = api_statuses_public_timeline('json');
1711                 $this->assertNotEmpty($result['status']);
1712                 foreach ($result['status'] as $status) {
1713                         $this->assertStatus($status);
1714                 }
1715         }
1716
1717         /**
1718          * Test the api_statuses_public_timeline() function with an unallowed user.
1719          *
1720          * @return void
1721          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1722          */
1723         public function testApiStatusesPublicTimelineWithUnallowedUser()
1724         {
1725                 $_SESSION['allow_api'] = false;
1726                 $_GET['screen_name']   = $this->selfUser['nick'];
1727                 api_statuses_public_timeline('json');
1728         }
1729
1730         /**
1731          * Test the api_statuses_public_timeline() function with an RSS result.
1732          *
1733          * @return void
1734          */
1735         public function testApiStatusesPublicTimelineWithRss()
1736         {
1737                 $result = api_statuses_public_timeline('rss');
1738                 $this->assertXml($result, 'statuses');
1739         }
1740
1741         /**
1742          * Test the api_statuses_networkpublic_timeline() function.
1743          *
1744          * @return void
1745          */
1746         public function testApiStatusesNetworkpublicTimeline()
1747         {
1748                 $_REQUEST['max_id'] = 10;
1749                 $result             = api_statuses_networkpublic_timeline('json');
1750                 $this->assertNotEmpty($result['status']);
1751                 foreach ($result['status'] as $status) {
1752                         $this->assertStatus($status);
1753                 }
1754         }
1755
1756         /**
1757          * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1758          *
1759          * @return void
1760          */
1761         public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1762         {
1763                 $_REQUEST['page'] = -2;
1764                 $result           = api_statuses_networkpublic_timeline('json');
1765                 $this->assertNotEmpty($result['status']);
1766                 foreach ($result['status'] as $status) {
1767                         $this->assertStatus($status);
1768                 }
1769         }
1770
1771         /**
1772          * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1773          *
1774          * @return void
1775          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1776          */
1777         public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1778         {
1779                 $_SESSION['allow_api'] = false;
1780                 $_GET['screen_name']   = $this->selfUser['nick'];
1781                 api_statuses_networkpublic_timeline('json');
1782         }
1783
1784         /**
1785          * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1786          *
1787          * @return void
1788          */
1789         public function testApiStatusesNetworkpublicTimelineWithRss()
1790         {
1791                 $result = api_statuses_networkpublic_timeline('rss');
1792                 $this->assertXml($result, 'statuses');
1793         }
1794
1795         /**
1796          * Test the api_statuses_show() function.
1797          *
1798          * @return void
1799          * @expectedException Friendica\Network\HTTPException\BadRequestException
1800          */
1801         public function testApiStatusesShow()
1802         {
1803                 api_statuses_show('json');
1804         }
1805
1806         /**
1807          * Test the api_statuses_show() function with an ID.
1808          *
1809          * @return void
1810          */
1811         public function testApiStatusesShowWithId()
1812         {
1813                 $this->app->argv[3] = 1;
1814                 $result             = api_statuses_show('json');
1815                 $this->assertStatus($result['status']);
1816         }
1817
1818         /**
1819          * Test the api_statuses_show() function with the conversation parameter.
1820          *
1821          * @return void
1822          */
1823         public function testApiStatusesShowWithConversation()
1824         {
1825                 $this->app->argv[3]       = 1;
1826                 $_REQUEST['conversation'] = 1;
1827                 $result                   = api_statuses_show('json');
1828                 $this->assertNotEmpty($result['status']);
1829                 foreach ($result['status'] as $status) {
1830                         $this->assertStatus($status);
1831                 }
1832         }
1833
1834         /**
1835          * Test the api_statuses_show() function with an unallowed user.
1836          *
1837          * @return void
1838          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1839          */
1840         public function testApiStatusesShowWithUnallowedUser()
1841         {
1842                 $_SESSION['allow_api'] = false;
1843                 $_GET['screen_name']   = $this->selfUser['nick'];
1844                 api_statuses_show('json');
1845         }
1846
1847         /**
1848          * Test the api_conversation_show() function.
1849          *
1850          * @return void
1851          * @expectedException Friendica\Network\HTTPException\BadRequestException
1852          */
1853         public function testApiConversationShow()
1854         {
1855                 api_conversation_show('json');
1856         }
1857
1858         /**
1859          * Test the api_conversation_show() function with an ID.
1860          *
1861          * @return void
1862          */
1863         public function testApiConversationShowWithId()
1864         {
1865                 $this->app->argv[3] = 1;
1866                 $_REQUEST['max_id'] = 10;
1867                 $_REQUEST['page']   = -2;
1868                 $result             = api_conversation_show('json');
1869                 $this->assertNotEmpty($result['status']);
1870                 foreach ($result['status'] as $status) {
1871                         $this->assertStatus($status);
1872                 }
1873         }
1874
1875         /**
1876          * Test the api_conversation_show() function with an unallowed user.
1877          *
1878          * @return void
1879          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1880          */
1881         public function testApiConversationShowWithUnallowedUser()
1882         {
1883                 $_SESSION['allow_api'] = false;
1884                 $_GET['screen_name']   = $this->selfUser['nick'];
1885                 api_conversation_show('json');
1886         }
1887
1888         /**
1889          * Test the api_statuses_repeat() function.
1890          *
1891          * @return void
1892          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1893          */
1894         public function testApiStatusesRepeat()
1895         {
1896                 api_statuses_repeat('json');
1897         }
1898
1899         /**
1900          * Test the api_statuses_repeat() function without an authenticated user.
1901          *
1902          * @return void
1903          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1904          */
1905         public function testApiStatusesRepeatWithoutAuthenticatedUser()
1906         {
1907                 $_SESSION['authenticated'] = false;
1908                 api_statuses_repeat('json');
1909         }
1910
1911         /**
1912          * Test the api_statuses_repeat() function with an ID.
1913          *
1914          * @return void
1915          */
1916         public function testApiStatusesRepeatWithId()
1917         {
1918                 $this->app->argv[3] = 1;
1919                 $result             = api_statuses_repeat('json');
1920                 $this->assertStatus($result['status']);
1921
1922                 // Also test with a shared status
1923                 $this->app->argv[3] = 5;
1924                 $result             = api_statuses_repeat('json');
1925                 $this->assertStatus($result['status']);
1926         }
1927
1928         /**
1929          * Test the api_statuses_destroy() function.
1930          *
1931          * @return void
1932          * @expectedException Friendica\Network\HTTPException\BadRequestException
1933          */
1934         public function testApiStatusesDestroy()
1935         {
1936                 api_statuses_destroy('json');
1937         }
1938
1939         /**
1940          * Test the api_statuses_destroy() function without an authenticated user.
1941          *
1942          * @return void
1943          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1944          */
1945         public function testApiStatusesDestroyWithoutAuthenticatedUser()
1946         {
1947                 $_SESSION['authenticated'] = false;
1948                 api_statuses_destroy('json');
1949         }
1950
1951         /**
1952          * Test the api_statuses_destroy() function with an ID.
1953          *
1954          * @return void
1955          */
1956         public function testApiStatusesDestroyWithId()
1957         {
1958                 $this->app->argv[3] = 1;
1959                 $result             = api_statuses_destroy('json');
1960                 $this->assertStatus($result['status']);
1961         }
1962
1963         /**
1964          * Test the api_statuses_mentions() function.
1965          *
1966          * @return void
1967          */
1968         public function testApiStatusesMentions()
1969         {
1970                 $this->app->user    = ['nickname' => $this->selfUser['nick']];
1971                 $_REQUEST['max_id'] = 10;
1972                 $result             = api_statuses_mentions('json');
1973                 $this->assertEmpty($result['status']);
1974                 // We should test with mentions in the database.
1975         }
1976
1977         /**
1978          * Test the api_statuses_mentions() function with a negative page parameter.
1979          *
1980          * @return void
1981          */
1982         public function testApiStatusesMentionsWithNegativePage()
1983         {
1984                 $_REQUEST['page'] = -2;
1985                 $result           = api_statuses_mentions('json');
1986                 $this->assertEmpty($result['status']);
1987         }
1988
1989         /**
1990          * Test the api_statuses_mentions() function with an unallowed user.
1991          *
1992          * @return void
1993          * @expectedException Friendica\Network\HTTPException\ForbiddenException
1994          */
1995         public function testApiStatusesMentionsWithUnallowedUser()
1996         {
1997                 $_SESSION['allow_api'] = false;
1998                 $_GET['screen_name']   = $this->selfUser['nick'];
1999                 api_statuses_mentions('json');
2000         }
2001
2002         /**
2003          * Test the api_statuses_mentions() function with an RSS result.
2004          *
2005          * @return void
2006          */
2007         public function testApiStatusesMentionsWithRss()
2008         {
2009                 $result = api_statuses_mentions('rss');
2010                 $this->assertXml($result, 'statuses');
2011         }
2012
2013         /**
2014          * Test the api_statuses_user_timeline() function.
2015          *
2016          * @return void
2017          */
2018         public function testApiStatusesUserTimeline()
2019         {
2020                 $_REQUEST['max_id']          = 10;
2021                 $_REQUEST['exclude_replies'] = true;
2022                 $_REQUEST['conversation_id'] = 1;
2023                 $result                      = api_statuses_user_timeline('json');
2024                 $this->assertNotEmpty($result['status']);
2025                 foreach ($result['status'] as $status) {
2026                         $this->assertStatus($status);
2027                 }
2028         }
2029
2030         /**
2031          * Test the api_statuses_user_timeline() function with a negative page parameter.
2032          *
2033          * @return void
2034          */
2035         public function testApiStatusesUserTimelineWithNegativePage()
2036         {
2037                 $_REQUEST['page'] = -2;
2038                 $result           = api_statuses_user_timeline('json');
2039                 $this->assertNotEmpty($result['status']);
2040                 foreach ($result['status'] as $status) {
2041                         $this->assertStatus($status);
2042                 }
2043         }
2044
2045         /**
2046          * Test the api_statuses_user_timeline() function with an RSS result.
2047          *
2048          * @return void
2049          */
2050         public function testApiStatusesUserTimelineWithRss()
2051         {
2052                 $result = api_statuses_user_timeline('rss');
2053                 $this->assertXml($result, 'statuses');
2054         }
2055
2056         /**
2057          * Test the api_statuses_user_timeline() function with an unallowed user.
2058          *
2059          * @return void
2060          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2061          */
2062         public function testApiStatusesUserTimelineWithUnallowedUser()
2063         {
2064                 $_SESSION['allow_api'] = false;
2065                 $_GET['screen_name']   = $this->selfUser['nick'];
2066                 api_statuses_user_timeline('json');
2067         }
2068
2069         /**
2070          * Test the api_favorites_create_destroy() function.
2071          *
2072          * @return void
2073          * @expectedException Friendica\Network\HTTPException\BadRequestException
2074          */
2075         public function testApiFavoritesCreateDestroy()
2076         {
2077                 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2078                 $this->app->argc = count($this->app->argv);
2079                 api_favorites_create_destroy('json');
2080         }
2081
2082         /**
2083          * Test the api_favorites_create_destroy() function with an invalid ID.
2084          *
2085          * @return void
2086          * @expectedException Friendica\Network\HTTPException\BadRequestException
2087          */
2088         public function testApiFavoritesCreateDestroyWithInvalidId()
2089         {
2090                 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2091                 $this->app->argc = count($this->app->argv);
2092                 api_favorites_create_destroy('json');
2093         }
2094
2095         /**
2096          * Test the api_favorites_create_destroy() function with an invalid action.
2097          *
2098          * @return void
2099          * @expectedException Friendica\Network\HTTPException\BadRequestException
2100          */
2101         public function testApiFavoritesCreateDestroyWithInvalidAction()
2102         {
2103                 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2104                 $this->app->argc = count($this->app->argv);
2105                 $_REQUEST['id']  = 1;
2106                 api_favorites_create_destroy('json');
2107         }
2108
2109         /**
2110          * Test the api_favorites_create_destroy() function with the create action.
2111          *
2112          * @return void
2113          */
2114         public function testApiFavoritesCreateDestroyWithCreateAction()
2115         {
2116                 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2117                 $this->app->argc = count($this->app->argv);
2118                 $_REQUEST['id']  = 3;
2119                 $result          = api_favorites_create_destroy('json');
2120                 $this->assertStatus($result['status']);
2121         }
2122
2123         /**
2124          * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2125          *
2126          * @return void
2127          */
2128         public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2129         {
2130                 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2131                 $this->app->argc = count($this->app->argv);
2132                 $_REQUEST['id']  = 3;
2133                 $result          = api_favorites_create_destroy('rss');
2134                 $this->assertXml($result, 'status');
2135         }
2136
2137         /**
2138          * Test the api_favorites_create_destroy() function with the destroy action.
2139          *
2140          * @return void
2141          */
2142         public function testApiFavoritesCreateDestroyWithDestroyAction()
2143         {
2144                 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2145                 $this->app->argc = count($this->app->argv);
2146                 $_REQUEST['id']  = 3;
2147                 $result          = api_favorites_create_destroy('json');
2148                 $this->assertStatus($result['status']);
2149         }
2150
2151         /**
2152          * Test the api_favorites_create_destroy() function without an authenticated user.
2153          *
2154          * @return void
2155          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2156          */
2157         public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2158         {
2159                 $this->app->argv           = ['api', '1.1', 'favorites', 'create.json'];
2160                 $this->app->argc           = count($this->app->argv);
2161                 $_SESSION['authenticated'] = false;
2162                 api_favorites_create_destroy('json');
2163         }
2164
2165         /**
2166          * Test the api_favorites() function.
2167          *
2168          * @return void
2169          */
2170         public function testApiFavorites()
2171         {
2172                 $_REQUEST['page']   = -1;
2173                 $_REQUEST['max_id'] = 10;
2174                 $result             = api_favorites('json');
2175                 foreach ($result['status'] as $status) {
2176                         $this->assertStatus($status);
2177                 }
2178         }
2179
2180         /**
2181          * Test the api_favorites() function with an RSS result.
2182          *
2183          * @return void
2184          */
2185         public function testApiFavoritesWithRss()
2186         {
2187                 $result = api_favorites('rss');
2188                 $this->assertXml($result, 'statuses');
2189         }
2190
2191         /**
2192          * Test the api_favorites() function with an unallowed user.
2193          *
2194          * @return void
2195          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2196          */
2197         public function testApiFavoritesWithUnallowedUser()
2198         {
2199                 $_SESSION['allow_api'] = false;
2200                 $_GET['screen_name']   = $this->selfUser['nick'];
2201                 api_favorites('json');
2202         }
2203
2204         /**
2205          * Test the api_format_messages() function.
2206          *
2207          * @return void
2208          */
2209         public function testApiFormatMessages()
2210         {
2211                 $result = api_format_messages(
2212                         ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2213                         ['id' => 2, 'screen_name' => 'recipient_name'],
2214                         ['id' => 3, 'screen_name' => 'sender_name']
2215                 );
2216                 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2217                 $this->assertEquals(1, $result['id']);
2218                 $this->assertEquals(2, $result['recipient_id']);
2219                 $this->assertEquals(3, $result['sender_id']);
2220                 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2221                 $this->assertEquals('sender_name', $result['sender_screen_name']);
2222         }
2223
2224         /**
2225          * Test the api_format_messages() function with HTML.
2226          *
2227          * @return void
2228          */
2229         public function testApiFormatMessagesWithHtmlText()
2230         {
2231                 $_GET['getText'] = 'html';
2232                 $result          = api_format_messages(
2233                         ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2234                         ['id' => 2, 'screen_name' => 'recipient_name'],
2235                         ['id' => 3, 'screen_name' => 'sender_name']
2236                 );
2237                 $this->assertEquals('item_title', $result['title']);
2238                 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2239         }
2240
2241         /**
2242          * Test the api_format_messages() function with plain text.
2243          *
2244          * @return void
2245          */
2246         public function testApiFormatMessagesWithPlainText()
2247         {
2248                 $_GET['getText'] = 'plain';
2249                 $result          = api_format_messages(
2250                         ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2251                         ['id' => 2, 'screen_name' => 'recipient_name'],
2252                         ['id' => 3, 'screen_name' => 'sender_name']
2253                 );
2254                 $this->assertEquals('item_title', $result['title']);
2255                 $this->assertEquals('item_body', $result['text']);
2256         }
2257
2258         /**
2259          * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2260          *
2261          * @return void
2262          */
2263         public function testApiFormatMessagesWithoutUserObjects()
2264         {
2265                 $_GET['getUserObjects'] = 'false';
2266                 $result                 = api_format_messages(
2267                         ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2268                         ['id' => 2, 'screen_name' => 'recipient_name'],
2269                         ['id' => 3, 'screen_name' => 'sender_name']
2270                 );
2271                 $this->assertTrue(!isset($result['sender']));
2272                 $this->assertTrue(!isset($result['recipient']));
2273         }
2274
2275         /**
2276          * Test the api_convert_item() function.
2277          *
2278          * @return void
2279          */
2280         public function testApiConvertItem()
2281         {
2282                 $result = api_convert_item(
2283                         [
2284                                 'network' => 'feed',
2285                                 'title'   => 'item_title',
2286                                 // We need a long string to test that it is correctly cut
2287                                 'body'    => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2288                                              'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2289                                              'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2290                                              'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2291                                              'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2292                                              'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2293                                              'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2294                                              'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2295                                              'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2296                                              'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2297                                              'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2298                                              'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2299                                              'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2300                                              'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2301                                              'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2302                                              'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2303                                              'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2304                                              'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2305                                              'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2306                                              'repellat officia illum quos impedit quam iste esse unde qui ' .
2307                                              'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2308                                              'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2309                                              'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2310                                 'plink'   => 'item_plink'
2311                         ]
2312                 );
2313                 $this->assertStringStartsWith('item_title', $result['text']);
2314                 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2315         }
2316
2317         /**
2318          * Test the api_convert_item() function with an empty item body.
2319          *
2320          * @return void
2321          */
2322         public function testApiConvertItemWithoutBody()
2323         {
2324                 $result = api_convert_item(
2325                         [
2326                                 'network' => 'feed',
2327                                 'title'   => 'item_title',
2328                                 'body'    => '',
2329                                 'plink'   => 'item_plink'
2330                         ]
2331                 );
2332                 $this->assertEquals('item_title', $result['text']);
2333                 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2334         }
2335
2336         /**
2337          * Test the api_convert_item() function with the title in the body.
2338          *
2339          * @return void
2340          */
2341         public function testApiConvertItemWithTitleInBody()
2342         {
2343                 $result = api_convert_item(
2344                         [
2345                                 'title' => 'item_title',
2346                                 'body'  => 'item_title item_body'
2347                         ]
2348                 );
2349                 $this->assertEquals('item_title item_body', $result['text']);
2350                 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2351         }
2352
2353         /**
2354          * Test the api_get_attachments() function.
2355          *
2356          * @return void
2357          */
2358         public function testApiGetAttachments()
2359         {
2360                 $body = 'body';
2361                 $this->assertEmpty(api_get_attachments($body));
2362         }
2363
2364         /**
2365          * Test the api_get_attachments() function with an img tag.
2366          *
2367          * @return void
2368          */
2369         public function testApiGetAttachmentsWithImage()
2370         {
2371                 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2372                 $this->assertInternalType('array', api_get_attachments($body));
2373         }
2374
2375         /**
2376          * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2377          *
2378          * @return void
2379          */
2380         public function testApiGetAttachmentsWithImageAndAndStatus()
2381         {
2382                 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2383                 $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
2384                 $this->assertInternalType('array', api_get_attachments($body));
2385         }
2386
2387         /**
2388          * Test the api_get_entitities() function.
2389          *
2390          * @return void
2391          */
2392         public function testApiGetEntitities()
2393         {
2394                 $text = 'text';
2395                 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2396         }
2397
2398         /**
2399          * Test the api_get_entitities() function with the include_entities parameter.
2400          *
2401          * @return void
2402          */
2403         public function testApiGetEntititiesWithIncludeEntities()
2404         {
2405                 $_REQUEST['include_entities'] = 'true';
2406                 $text                         = 'text';
2407                 $result                       = api_get_entitities($text, 'bbcode');
2408                 $this->assertInternalType('array', $result['hashtags']);
2409                 $this->assertInternalType('array', $result['symbols']);
2410                 $this->assertInternalType('array', $result['urls']);
2411                 $this->assertInternalType('array', $result['user_mentions']);
2412         }
2413
2414         /**
2415          * Test the api_format_items_embeded_images() function.
2416          *
2417          * @return void
2418          */
2419         public function testApiFormatItemsEmbededImages()
2420         {
2421                 $this->assertEquals(
2422                         'text ' . DI::baseUrl() . '/display/item_guid',
2423                         api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2424                 );
2425         }
2426
2427         /**
2428          * Test the api_contactlink_to_array() function.
2429          *
2430          * @return void
2431          */
2432         public function testApiContactlinkToArray()
2433         {
2434                 $this->assertEquals(
2435                         [
2436                                 'name' => 'text',
2437                                 'url'  => '',
2438                         ],
2439                         api_contactlink_to_array('text')
2440                 );
2441         }
2442
2443         /**
2444          * Test the api_contactlink_to_array() function with an URL.
2445          *
2446          * @return void
2447          */
2448         public function testApiContactlinkToArrayWithUrl()
2449         {
2450                 $this->assertEquals(
2451                         [
2452                                 'name' => ['link_text'],
2453                                 'url'  => ['url'],
2454                         ],
2455                         api_contactlink_to_array('text <a href="url">link_text</a>')
2456                 );
2457         }
2458
2459         /**
2460          * Test the api_format_items_activities() function.
2461          *
2462          * @return void
2463          */
2464         public function testApiFormatItemsActivities()
2465         {
2466                 $item   = ['uid' => 0, 'uri' => ''];
2467                 $result = api_format_items_activities($item);
2468                 $this->assertArrayHasKey('like', $result);
2469                 $this->assertArrayHasKey('dislike', $result);
2470                 $this->assertArrayHasKey('attendyes', $result);
2471                 $this->assertArrayHasKey('attendno', $result);
2472                 $this->assertArrayHasKey('attendmaybe', $result);
2473         }
2474
2475         /**
2476          * Test the api_format_items_activities() function with an XML result.
2477          *
2478          * @return void
2479          */
2480         public function testApiFormatItemsActivitiesWithXml()
2481         {
2482                 $item   = ['uid' => 0, 'uri' => ''];
2483                 $result = api_format_items_activities($item, 'xml');
2484                 $this->assertArrayHasKey('friendica:like', $result);
2485                 $this->assertArrayHasKey('friendica:dislike', $result);
2486                 $this->assertArrayHasKey('friendica:attendyes', $result);
2487                 $this->assertArrayHasKey('friendica:attendno', $result);
2488                 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2489         }
2490
2491         /**
2492          * Test the api_format_items_profiles() function.
2493          *
2494          * @return void
2495          */
2496         public function testApiFormatItemsProfiles()
2497         {
2498                 $profile_row = [
2499                         'id'           => 'profile_id',
2500                         'profile-name' => 'profile_name',
2501                         'is-default'   => true,
2502                         'hide-friends' => true,
2503                         'photo'        => 'profile_photo',
2504                         'thumb'        => 'profile_thumb',
2505                         'publish'      => true,
2506                         'net-publish'  => true,
2507                         'pdesc'        => 'description',
2508                         'dob'          => 'date_of_birth',
2509                         'address'      => 'address',
2510                         'locality'     => 'city',
2511                         'region'       => 'region',
2512                         'postal-code'  => 'postal_code',
2513                         'country-name' => 'country',
2514                         'hometown'     => 'hometown',
2515                         'gender'       => 'gender',
2516                         'marital'      => 'marital',
2517                         'with'         => 'marital_with',
2518                         'howlong'      => 'marital_since',
2519                         'sexual'       => 'sexual',
2520                         'politic'      => 'politic',
2521                         'religion'     => 'religion',
2522                         'pub_keywords' => 'public_keywords',
2523                         'prv_keywords' => 'private_keywords',
2524
2525                         'likes'     => 'likes',
2526                         'dislikes'  => 'dislikes',
2527                         'about'     => 'about',
2528                         'music'     => 'music',
2529                         'book'      => 'book',
2530                         'tv'        => 'tv',
2531                         'film'      => 'film',
2532                         'interest'  => 'interest',
2533                         'romance'   => 'romance',
2534                         'work'      => 'work',
2535                         'education' => 'education',
2536                         'contact'   => 'social_networks',
2537                         'homepage'  => 'homepage'
2538                 ];
2539                 $result      = api_format_items_profiles($profile_row);
2540                 $this->assertEquals(
2541                         [
2542                                 'profile_id'       => 'profile_id',
2543                                 'profile_name'     => 'profile_name',
2544                                 'is_default'       => true,
2545                                 'hide_friends'     => true,
2546                                 'profile_photo'    => 'profile_photo',
2547                                 'profile_thumb'    => 'profile_thumb',
2548                                 'publish'          => true,
2549                                 'net_publish'      => true,
2550                                 'description'      => 'description',
2551                                 'date_of_birth'    => 'date_of_birth',
2552                                 'address'          => 'address',
2553                                 'city'             => 'city',
2554                                 'region'           => 'region',
2555                                 'postal_code'      => 'postal_code',
2556                                 'country'          => 'country',
2557                                 'hometown'         => 'hometown',
2558                                 'gender'           => 'gender',
2559                                 'marital'          => 'marital',
2560                                 'marital_with'     => 'marital_with',
2561                                 'marital_since'    => 'marital_since',
2562                                 'sexual'           => 'sexual',
2563                                 'politic'          => 'politic',
2564                                 'religion'         => 'religion',
2565                                 'public_keywords'  => 'public_keywords',
2566                                 'private_keywords' => 'private_keywords',
2567
2568                                 'likes'           => 'likes',
2569                                 'dislikes'        => 'dislikes',
2570                                 'about'           => 'about',
2571                                 'music'           => 'music',
2572                                 'book'            => 'book',
2573                                 'tv'              => 'tv',
2574                                 'film'            => 'film',
2575                                 'interest'        => 'interest',
2576                                 'romance'         => 'romance',
2577                                 'work'            => 'work',
2578                                 'education'       => 'education',
2579                                 'social_networks' => 'social_networks',
2580                                 'homepage'        => 'homepage',
2581                                 'users'           => null
2582                         ],
2583                         $result
2584                 );
2585         }
2586
2587         /**
2588          * Test the api_format_items() function.
2589          *
2590          * @return void
2591          */
2592         public function testApiFormatItems()
2593         {
2594                 $items  = [
2595                         [
2596                                 'item_network'   => 'item_network',
2597                                 'source'         => 'web',
2598                                 'coord'          => '5 7',
2599                                 'body'           => '',
2600                                 'verb'           => '',
2601                                 'author-id'      => 43,
2602                                 'author-network' => Protocol::DFRN,
2603                                 'author-link'    => 'http://localhost/profile/othercontact',
2604                                 'plink'          => '',
2605                         ]
2606                 ];
2607                 $result = api_format_items($items, ['id' => 0], true);
2608                 foreach ($result as $status) {
2609                         $this->assertStatus($status);
2610                 }
2611         }
2612
2613         /**
2614          * Test the api_format_items() function with an XML result.
2615          *
2616          * @return void
2617          */
2618         public function testApiFormatItemsWithXml()
2619         {
2620                 $items  = [
2621                         [
2622                                 'coord'          => '5 7',
2623                                 'body'           => '',
2624                                 'verb'           => '',
2625                                 'author-id'      => 43,
2626                                 'author-network' => Protocol::DFRN,
2627                                 'author-link'    => 'http://localhost/profile/othercontact',
2628                                 'plink'          => '',
2629                         ]
2630                 ];
2631                 $result = api_format_items($items, ['id' => 0], true, 'xml');
2632                 foreach ($result as $status) {
2633                         $this->assertStatus($status);
2634                 }
2635         }
2636
2637         /**
2638          * Test the api_format_items() function.
2639          *
2640          * @return void
2641          */
2642         public function testApiAccountRateLimitStatus()
2643         {
2644                 $result = api_account_rate_limit_status('json');
2645                 $this->assertEquals(150, $result['hash']['remaining_hits']);
2646                 $this->assertEquals(150, $result['hash']['hourly_limit']);
2647                 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2648         }
2649
2650         /**
2651          * Test the api_format_items() function with an XML result.
2652          *
2653          * @return void
2654          */
2655         public function testApiAccountRateLimitStatusWithXml()
2656         {
2657                 $result = api_account_rate_limit_status('xml');
2658                 $this->assertXml($result, 'hash');
2659         }
2660
2661         /**
2662          * Test the api_help_test() function.
2663          *
2664          * @return void
2665          */
2666         public function testApiHelpTest()
2667         {
2668                 $result = api_help_test('json');
2669                 $this->assertEquals(['ok' => 'ok'], $result);
2670         }
2671
2672         /**
2673          * Test the api_help_test() function with an XML result.
2674          *
2675          * @return void
2676          */
2677         public function testApiHelpTestWithXml()
2678         {
2679                 $result = api_help_test('xml');
2680                 $this->assertXml($result, 'ok');
2681         }
2682
2683         /**
2684          * Test the api_lists_list() function.
2685          *
2686          * @return void
2687          */
2688         public function testApiListsList()
2689         {
2690                 $result = api_lists_list('json');
2691                 $this->assertEquals(['lists_list' => []], $result);
2692         }
2693
2694         /**
2695          * Test the api_lists_ownerships() function.
2696          *
2697          * @return void
2698          */
2699         public function testApiListsOwnerships()
2700         {
2701                 $result = api_lists_ownerships('json');
2702                 foreach ($result['lists']['lists'] as $list) {
2703                         $this->assertList($list);
2704                 }
2705         }
2706
2707         /**
2708          * Test the api_lists_ownerships() function without an authenticated user.
2709          *
2710          * @return void
2711          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2712          */
2713         public function testApiListsOwnershipsWithoutAuthenticatedUser()
2714         {
2715                 $_SESSION['authenticated'] = false;
2716                 api_lists_ownerships('json');
2717         }
2718
2719         /**
2720          * Test the api_lists_statuses() function.
2721          *
2722          * @expectedException Friendica\Network\HTTPException\BadRequestException
2723          * @return void
2724          */
2725         public function testApiListsStatuses()
2726         {
2727                 api_lists_statuses('json');
2728         }
2729
2730         /**
2731          * Test the api_lists_statuses() function with a list ID.
2732          *
2733          * @return void
2734          */
2735         public function testApiListsStatusesWithListId()
2736         {
2737                 $_REQUEST['list_id'] = 1;
2738                 $_REQUEST['page']    = -1;
2739                 $_REQUEST['max_id']  = 10;
2740                 $result              = api_lists_statuses('json');
2741                 foreach ($result['status'] as $status) {
2742                         $this->assertStatus($status);
2743                 }
2744         }
2745
2746         /**
2747          * Test the api_lists_statuses() function with a list ID and a RSS result.
2748          *
2749          * @return void
2750          */
2751         public function testApiListsStatusesWithListIdAndRss()
2752         {
2753                 $_REQUEST['list_id'] = 1;
2754                 $result              = api_lists_statuses('rss');
2755                 $this->assertXml($result, 'statuses');
2756         }
2757
2758         /**
2759          * Test the api_lists_statuses() function with an unallowed user.
2760          *
2761          * @return void
2762          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2763          */
2764         public function testApiListsStatusesWithUnallowedUser()
2765         {
2766                 $_SESSION['allow_api'] = false;
2767                 $_GET['screen_name']   = $this->selfUser['nick'];
2768                 api_lists_statuses('json');
2769         }
2770
2771         /**
2772          * Test the api_statuses_f() function.
2773          *
2774          * @return void
2775          */
2776         public function testApiStatusesFWithFriends()
2777         {
2778                 $_GET['page'] = -1;
2779                 $result       = api_statuses_f('friends');
2780                 $this->assertArrayHasKey('user', $result);
2781         }
2782
2783         /**
2784          * Test the api_statuses_f() function.
2785          *
2786          * @return void
2787          */
2788         public function testApiStatusesFWithFollowers()
2789         {
2790                 $result = api_statuses_f('followers');
2791                 $this->assertArrayHasKey('user', $result);
2792         }
2793
2794         /**
2795          * Test the api_statuses_f() function.
2796          *
2797          * @return void
2798          */
2799         public function testApiStatusesFWithBlocks()
2800         {
2801                 $result = api_statuses_f('blocks');
2802                 $this->assertArrayHasKey('user', $result);
2803         }
2804
2805         /**
2806          * Test the api_statuses_f() function.
2807          *
2808          * @return void
2809          */
2810         public function testApiStatusesFWithIncoming()
2811         {
2812                 $result = api_statuses_f('incoming');
2813                 $this->assertArrayHasKey('user', $result);
2814         }
2815
2816         /**
2817          * Test the api_statuses_f() function an undefined cursor GET variable.
2818          *
2819          * @return void
2820          */
2821         public function testApiStatusesFWithUndefinedCursor()
2822         {
2823                 $_GET['cursor'] = 'undefined';
2824                 $this->assertFalse(api_statuses_f('friends'));
2825         }
2826
2827         /**
2828          * Test the api_statuses_friends() function.
2829          *
2830          * @return void
2831          */
2832         public function testApiStatusesFriends()
2833         {
2834                 $result = api_statuses_friends('json');
2835                 $this->assertArrayHasKey('user', $result);
2836         }
2837
2838         /**
2839          * Test the api_statuses_friends() function an undefined cursor GET variable.
2840          *
2841          * @return void
2842          */
2843         public function testApiStatusesFriendsWithUndefinedCursor()
2844         {
2845                 $_GET['cursor'] = 'undefined';
2846                 $this->assertFalse(api_statuses_friends('json'));
2847         }
2848
2849         /**
2850          * Test the api_statuses_followers() function.
2851          *
2852          * @return void
2853          */
2854         public function testApiStatusesFollowers()
2855         {
2856                 $result = api_statuses_followers('json');
2857                 $this->assertArrayHasKey('user', $result);
2858         }
2859
2860         /**
2861          * Test the api_statuses_followers() function an undefined cursor GET variable.
2862          *
2863          * @return void
2864          */
2865         public function testApiStatusesFollowersWithUndefinedCursor()
2866         {
2867                 $_GET['cursor'] = 'undefined';
2868                 $this->assertFalse(api_statuses_followers('json'));
2869         }
2870
2871         /**
2872          * Test the api_blocks_list() function.
2873          *
2874          * @return void
2875          */
2876         public function testApiBlocksList()
2877         {
2878                 $result = api_blocks_list('json');
2879                 $this->assertArrayHasKey('user', $result);
2880         }
2881
2882         /**
2883          * Test the api_blocks_list() function an undefined cursor GET variable.
2884          *
2885          * @return void
2886          */
2887         public function testApiBlocksListWithUndefinedCursor()
2888         {
2889                 $_GET['cursor'] = 'undefined';
2890                 $this->assertFalse(api_blocks_list('json'));
2891         }
2892
2893         /**
2894          * Test the api_friendships_incoming() function.
2895          *
2896          * @return void
2897          */
2898         public function testApiFriendshipsIncoming()
2899         {
2900                 $result = api_friendships_incoming('json');
2901                 $this->assertArrayHasKey('id', $result);
2902         }
2903
2904         /**
2905          * Test the api_friendships_incoming() function an undefined cursor GET variable.
2906          *
2907          * @return void
2908          */
2909         public function testApiFriendshipsIncomingWithUndefinedCursor()
2910         {
2911                 $_GET['cursor'] = 'undefined';
2912                 $this->assertFalse(api_friendships_incoming('json'));
2913         }
2914
2915         /**
2916          * Test the api_statusnet_config() function.
2917          *
2918          * @return void
2919          */
2920         public function testApiStatusnetConfig()
2921         {
2922                 $result = api_statusnet_config('json');
2923                 $this->assertEquals('localhost', $result['config']['site']['server']);
2924                 $this->assertEquals('default', $result['config']['site']['theme']);
2925                 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2926                 $this->assertTrue($result['config']['site']['fancy']);
2927                 $this->assertEquals('en', $result['config']['site']['language']);
2928                 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2929                 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2930                 $this->assertEquals('false', $result['config']['site']['private']);
2931                 $this->assertEquals('false', $result['config']['site']['ssl']);
2932                 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2933         }
2934
2935         /**
2936          * Test the api_statusnet_version() function.
2937          *
2938          * @return void
2939          */
2940         public function testApiStatusnetVersion()
2941         {
2942                 $result = api_statusnet_version('json');
2943                 $this->assertEquals('0.9.7', $result['version']);
2944         }
2945
2946         /**
2947          * Test the api_ff_ids() function.
2948          *
2949          * @return void
2950          */
2951         public function testApiFfIds()
2952         {
2953                 $result = api_ff_ids('json', Contact::FOLLOWER);
2954                 $this->assertEquals(['id' => []], $result);
2955         }
2956
2957         /**
2958          * Test the api_ff_ids() function with a result.
2959          *
2960          * @return void
2961          */
2962         public function testApiFfIdsWithResult()
2963         {
2964                 $this->markTestIncomplete();
2965         }
2966
2967         /**
2968          * Test the api_ff_ids() function without an authenticated user.
2969          *
2970          * @return void
2971          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2972          */
2973         public function testApiFfIdsWithoutAuthenticatedUser()
2974         {
2975                 $_SESSION['authenticated'] = false;
2976                 api_ff_ids('json', Contact::FOLLOWER);
2977         }
2978
2979         /**
2980          * Test the api_friends_ids() function.
2981          *
2982          * @return void
2983          */
2984         public function testApiFriendsIds()
2985         {
2986                 $result = api_friends_ids('json');
2987                 $this->assertEquals(['id' => []], $result);
2988         }
2989
2990         /**
2991          * Test the api_followers_ids() function.
2992          *
2993          * @return void
2994          */
2995         public function testApiFollowersIds()
2996         {
2997                 $result = api_followers_ids('json');
2998                 $this->assertEquals(['id' => []], $result);
2999         }
3000
3001         /**
3002          * Test the api_direct_messages_new() function.
3003          *
3004          * @return void
3005          */
3006         public function testApiDirectMessagesNew()
3007         {
3008                 $result = api_direct_messages_new('json');
3009                 $this->assertNull($result);
3010         }
3011
3012         /**
3013          * Test the api_direct_messages_new() function without an authenticated user.
3014          *
3015          * @return void
3016          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3017          */
3018         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
3019         {
3020                 $_SESSION['authenticated'] = false;
3021                 api_direct_messages_new('json');
3022         }
3023
3024         /**
3025          * Test the api_direct_messages_new() function with an user ID.
3026          *
3027          * @return void
3028          */
3029         public function testApiDirectMessagesNewWithUserId()
3030         {
3031                 $_POST['text']    = 'message_text';
3032                 $_POST['user_id'] = $this->otherUser['id'];
3033                 $result           = api_direct_messages_new('json');
3034                 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3035         }
3036
3037         /**
3038          * Test the api_direct_messages_new() function with a screen name.
3039          *
3040          * @return void
3041          */
3042         public function testApiDirectMessagesNewWithScreenName()
3043         {
3044                 $_POST['text']        = 'message_text';
3045                 $_POST['screen_name'] = $this->friendUser['nick'];
3046                 $result               = api_direct_messages_new('json');
3047                 $this->assertContains('message_text', $result['direct_message']['text']);
3048                 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3049                 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3050         }
3051
3052         /**
3053          * Test the api_direct_messages_new() function with a title.
3054          *
3055          * @return void
3056          */
3057         public function testApiDirectMessagesNewWithTitle()
3058         {
3059                 $_POST['text']        = 'message_text';
3060                 $_POST['screen_name'] = $this->friendUser['nick'];
3061                 $_REQUEST['title']    = 'message_title';
3062                 $result               = api_direct_messages_new('json');
3063                 $this->assertContains('message_text', $result['direct_message']['text']);
3064                 $this->assertContains('message_title', $result['direct_message']['text']);
3065                 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3066                 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3067         }
3068
3069         /**
3070          * Test the api_direct_messages_new() function with an RSS result.
3071          *
3072          * @return void
3073          */
3074         public function testApiDirectMessagesNewWithRss()
3075         {
3076                 $_POST['text']        = 'message_text';
3077                 $_POST['screen_name'] = $this->friendUser['nick'];
3078                 $result               = api_direct_messages_new('rss');
3079                 $this->assertXml($result, 'direct-messages');
3080         }
3081
3082         /**
3083          * Test the api_direct_messages_destroy() function.
3084          *
3085          * @return void
3086          * @expectedException Friendica\Network\HTTPException\BadRequestException
3087          */
3088         public function testApiDirectMessagesDestroy()
3089         {
3090                 api_direct_messages_destroy('json');
3091         }
3092
3093         /**
3094          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3095          *
3096          * @return void
3097          */
3098         public function testApiDirectMessagesDestroyWithVerbose()
3099         {
3100                 $_GET['friendica_verbose'] = 'true';
3101                 $result                    = api_direct_messages_destroy('json');
3102                 $this->assertEquals(
3103                         [
3104                                 '$result' => [
3105                                         'result'  => 'error',
3106                                         'message' => 'message id or parenturi not specified'
3107                                 ]
3108                         ],
3109                         $result
3110                 );
3111         }
3112
3113         /**
3114          * Test the api_direct_messages_destroy() function without an authenticated user.
3115          *
3116          * @return void
3117          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3118          */
3119         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3120         {
3121                 $_SESSION['authenticated'] = false;
3122                 api_direct_messages_destroy('json');
3123         }
3124
3125         /**
3126          * Test the api_direct_messages_destroy() function with a non-zero ID.
3127          *
3128          * @return void
3129          * @expectedException Friendica\Network\HTTPException\BadRequestException
3130          */
3131         public function testApiDirectMessagesDestroyWithId()
3132         {
3133                 $_REQUEST['id'] = 1;
3134                 api_direct_messages_destroy('json');
3135         }
3136
3137         /**
3138          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3139          *
3140          * @return void
3141          */
3142         public function testApiDirectMessagesDestroyWithIdAndVerbose()
3143         {
3144                 $_REQUEST['id']                  = 1;
3145                 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3146                 $_GET['friendica_verbose']       = 'true';
3147                 $result                          = api_direct_messages_destroy('json');
3148                 $this->assertEquals(
3149                         [
3150                                 '$result' => [
3151                                         'result'  => 'error',
3152                                         'message' => 'message id not in database'
3153                                 ]
3154                         ],
3155                         $result
3156                 );
3157         }
3158
3159         /**
3160          * Test the api_direct_messages_destroy() function with a non-zero ID.
3161          *
3162          * @return void
3163          */
3164         public function testApiDirectMessagesDestroyWithCorrectId()
3165         {
3166                 $this->markTestIncomplete('We need to add a dataset for this.');
3167         }
3168
3169         /**
3170          * Test the api_direct_messages_box() function.
3171          *
3172          * @return void
3173          */
3174         public function testApiDirectMessagesBoxWithSentbox()
3175         {
3176                 $_REQUEST['page']   = -1;
3177                 $_REQUEST['max_id'] = 10;
3178                 $result             = api_direct_messages_box('json', 'sentbox', 'false');
3179                 $this->assertArrayHasKey('direct_message', $result);
3180         }
3181
3182         /**
3183          * Test the api_direct_messages_box() function.
3184          *
3185          * @return void
3186          */
3187         public function testApiDirectMessagesBoxWithConversation()
3188         {
3189                 $result = api_direct_messages_box('json', 'conversation', 'false');
3190                 $this->assertArrayHasKey('direct_message', $result);
3191         }
3192
3193         /**
3194          * Test the api_direct_messages_box() function.
3195          *
3196          * @return void
3197          */
3198         public function testApiDirectMessagesBoxWithAll()
3199         {
3200                 $result = api_direct_messages_box('json', 'all', 'false');
3201                 $this->assertArrayHasKey('direct_message', $result);
3202         }
3203
3204         /**
3205          * Test the api_direct_messages_box() function.
3206          *
3207          * @return void
3208          */
3209         public function testApiDirectMessagesBoxWithInbox()
3210         {
3211                 $result = api_direct_messages_box('json', 'inbox', 'false');
3212                 $this->assertArrayHasKey('direct_message', $result);
3213         }
3214
3215         /**
3216          * Test the api_direct_messages_box() function.
3217          *
3218          * @return void
3219          */
3220         public function testApiDirectMessagesBoxWithVerbose()
3221         {
3222                 $result = api_direct_messages_box('json', 'sentbox', 'true');
3223                 $this->assertEquals(
3224                         [
3225                                 '$result' => [
3226                                         'result'  => 'error',
3227                                         'message' => 'no mails available'
3228                                 ]
3229                         ],
3230                         $result
3231                 );
3232         }
3233
3234         /**
3235          * Test the api_direct_messages_box() function with a RSS result.
3236          *
3237          * @return void
3238          */
3239         public function testApiDirectMessagesBoxWithRss()
3240         {
3241                 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3242                 $this->assertXml($result, 'direct-messages');
3243         }
3244
3245         /**
3246          * Test the api_direct_messages_box() function without an authenticated user.
3247          *
3248          * @return void
3249          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3250          */
3251         public function testApiDirectMessagesBoxWithUnallowedUser()
3252         {
3253                 $_SESSION['allow_api'] = false;
3254                 $_GET['screen_name']   = $this->selfUser['nick'];
3255                 api_direct_messages_box('json', 'sentbox', 'false');
3256         }
3257
3258         /**
3259          * Test the api_direct_messages_sentbox() function.
3260          *
3261          * @return void
3262          */
3263         public function testApiDirectMessagesSentbox()
3264         {
3265                 $result = api_direct_messages_sentbox('json');
3266                 $this->assertArrayHasKey('direct_message', $result);
3267         }
3268
3269         /**
3270          * Test the api_direct_messages_inbox() function.
3271          *
3272          * @return void
3273          */
3274         public function testApiDirectMessagesInbox()
3275         {
3276                 $result = api_direct_messages_inbox('json');
3277                 $this->assertArrayHasKey('direct_message', $result);
3278         }
3279
3280         /**
3281          * Test the api_direct_messages_all() function.
3282          *
3283          * @return void
3284          */
3285         public function testApiDirectMessagesAll()
3286         {
3287                 $result = api_direct_messages_all('json');
3288                 $this->assertArrayHasKey('direct_message', $result);
3289         }
3290
3291         /**
3292          * Test the api_direct_messages_conversation() function.
3293          *
3294          * @return void
3295          */
3296         public function testApiDirectMessagesConversation()
3297         {
3298                 $result = api_direct_messages_conversation('json');
3299                 $this->assertArrayHasKey('direct_message', $result);
3300         }
3301
3302         /**
3303          * Test the api_oauth_request_token() function.
3304          *
3305          * @return void
3306          */
3307         public function testApiOauthRequestToken()
3308         {
3309                 $this->markTestIncomplete('exit() kills phpunit as well');
3310         }
3311
3312         /**
3313          * Test the api_oauth_access_token() function.
3314          *
3315          * @return void
3316          */
3317         public function testApiOauthAccessToken()
3318         {
3319                 $this->markTestIncomplete('exit() kills phpunit as well');
3320         }
3321
3322         /**
3323          * Test the api_fr_photoalbum_delete() function.
3324          *
3325          * @return void
3326          * @expectedException Friendica\Network\HTTPException\BadRequestException
3327          */
3328         public function testApiFrPhotoalbumDelete()
3329         {
3330                 api_fr_photoalbum_delete('json');
3331         }
3332
3333         /**
3334          * Test the api_fr_photoalbum_delete() function with an album name.
3335          *
3336          * @return void
3337          * @expectedException Friendica\Network\HTTPException\BadRequestException
3338          */
3339         public function testApiFrPhotoalbumDeleteWithAlbum()
3340         {
3341                 $_REQUEST['album'] = 'album_name';
3342                 api_fr_photoalbum_delete('json');
3343         }
3344
3345         /**
3346          * Test the api_fr_photoalbum_delete() function with an album name.
3347          *
3348          * @return void
3349          */
3350         public function testApiFrPhotoalbumDeleteWithValidAlbum()
3351         {
3352                 $this->markTestIncomplete('We need to add a dataset for this.');
3353         }
3354
3355         /**
3356          * Test the api_fr_photoalbum_delete() function.
3357          *
3358          * @return void
3359          * @expectedException Friendica\Network\HTTPException\BadRequestException
3360          */
3361         public function testApiFrPhotoalbumUpdate()
3362         {
3363                 api_fr_photoalbum_update('json');
3364         }
3365
3366         /**
3367          * Test the api_fr_photoalbum_delete() function with an album name.
3368          *
3369          * @return void
3370          * @expectedException Friendica\Network\HTTPException\BadRequestException
3371          */
3372         public function testApiFrPhotoalbumUpdateWithAlbum()
3373         {
3374                 $_REQUEST['album'] = 'album_name';
3375                 api_fr_photoalbum_update('json');
3376         }
3377
3378         /**
3379          * Test the api_fr_photoalbum_delete() function with an album name.
3380          *
3381          * @return void
3382          * @expectedException Friendica\Network\HTTPException\BadRequestException
3383          */
3384         public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3385         {
3386                 $_REQUEST['album']     = 'album_name';
3387                 $_REQUEST['album_new'] = 'album_name';
3388                 api_fr_photoalbum_update('json');
3389         }
3390
3391         /**
3392          * Test the api_fr_photoalbum_update() function without an authenticated user.
3393          *
3394          * @return void
3395          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3396          */
3397         public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3398         {
3399                 $_SESSION['authenticated'] = false;
3400                 api_fr_photoalbum_update('json');
3401         }
3402
3403         /**
3404          * Test the api_fr_photoalbum_delete() function with an album name.
3405          *
3406          * @return void
3407          */
3408         public function testApiFrPhotoalbumUpdateWithValidAlbum()
3409         {
3410                 $this->markTestIncomplete('We need to add a dataset for this.');
3411         }
3412
3413         /**
3414          * Test the api_fr_photos_list() function.
3415          *
3416          * @return void
3417          */
3418         public function testApiFrPhotosList()
3419         {
3420                 $result = api_fr_photos_list('json');
3421                 $this->assertArrayHasKey('photo', $result);
3422         }
3423
3424         /**
3425          * Test the api_fr_photos_list() function without an authenticated user.
3426          *
3427          * @return void
3428          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3429          */
3430         public function testApiFrPhotosListWithoutAuthenticatedUser()
3431         {
3432                 $_SESSION['authenticated'] = false;
3433                 api_fr_photos_list('json');
3434         }
3435
3436         /**
3437          * Test the api_fr_photo_create_update() function.
3438          *
3439          * @return void
3440          * @expectedException Friendica\Network\HTTPException\BadRequestException
3441          */
3442         public function testApiFrPhotoCreateUpdate()
3443         {
3444                 api_fr_photo_create_update('json');
3445         }
3446
3447         /**
3448          * Test the api_fr_photo_create_update() function without an authenticated user.
3449          *
3450          * @return void
3451          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3452          */
3453         public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3454         {
3455                 $_SESSION['authenticated'] = false;
3456                 api_fr_photo_create_update('json');
3457         }
3458
3459         /**
3460          * Test the api_fr_photo_create_update() function with an album name.
3461          *
3462          * @return void
3463          * @expectedException Friendica\Network\HTTPException\BadRequestException
3464          */
3465         public function testApiFrPhotoCreateUpdateWithAlbum()
3466         {
3467                 $_REQUEST['album'] = 'album_name';
3468                 api_fr_photo_create_update('json');
3469         }
3470
3471         /**
3472          * Test the api_fr_photo_create_update() function with the update mode.
3473          *
3474          * @return void
3475          */
3476         public function testApiFrPhotoCreateUpdateWithUpdate()
3477         {
3478                 $this->markTestIncomplete('We need to create a dataset for this');
3479         }
3480
3481         /**
3482          * Test the api_fr_photo_create_update() function with an uploaded file.
3483          *
3484          * @return void
3485          */
3486         public function testApiFrPhotoCreateUpdateWithFile()
3487         {
3488                 $this->markTestIncomplete();
3489         }
3490
3491         /**
3492          * Test the api_fr_photo_delete() function.
3493          *
3494          * @return void
3495          * @expectedException Friendica\Network\HTTPException\BadRequestException
3496          */
3497         public function testApiFrPhotoDelete()
3498         {
3499                 api_fr_photo_delete('json');
3500         }
3501
3502         /**
3503          * Test the api_fr_photo_delete() function without an authenticated user.
3504          *
3505          * @return void
3506          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3507          */
3508         public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3509         {
3510                 $_SESSION['authenticated'] = false;
3511                 api_fr_photo_delete('json');
3512         }
3513
3514         /**
3515          * Test the api_fr_photo_delete() function with a photo ID.
3516          *
3517          * @return void
3518          * @expectedException Friendica\Network\HTTPException\BadRequestException
3519          */
3520         public function testApiFrPhotoDeleteWithPhotoId()
3521         {
3522                 $_REQUEST['photo_id'] = 1;
3523                 api_fr_photo_delete('json');
3524         }
3525
3526         /**
3527          * Test the api_fr_photo_delete() function with a correct photo ID.
3528          *
3529          * @return void
3530          */
3531         public function testApiFrPhotoDeleteWithCorrectPhotoId()
3532         {
3533                 $this->markTestIncomplete('We need to create a dataset for this.');
3534         }
3535
3536         /**
3537          * Test the api_fr_photo_detail() function.
3538          *
3539          * @return void
3540          * @expectedException Friendica\Network\HTTPException\BadRequestException
3541          */
3542         public function testApiFrPhotoDetail()
3543         {
3544                 api_fr_photo_detail('json');
3545         }
3546
3547         /**
3548          * Test the api_fr_photo_detail() function without an authenticated user.
3549          *
3550          * @return void
3551          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3552          */
3553         public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3554         {
3555                 $_SESSION['authenticated'] = false;
3556                 api_fr_photo_detail('json');
3557         }
3558
3559         /**
3560          * Test the api_fr_photo_detail() function with a photo ID.
3561          *
3562          * @return void
3563          * @expectedException Friendica\Network\HTTPException\NotFoundException
3564          */
3565         public function testApiFrPhotoDetailWithPhotoId()
3566         {
3567                 $_REQUEST['photo_id'] = 1;
3568                 api_fr_photo_detail('json');
3569         }
3570
3571         /**
3572          * Test the api_fr_photo_detail() function with a correct photo ID.
3573          *
3574          * @return void
3575          */
3576         public function testApiFrPhotoDetailCorrectPhotoId()
3577         {
3578                 $this->markTestIncomplete('We need to create a dataset for this.');
3579         }
3580
3581         /**
3582          * Test the api_account_update_profile_image() function.
3583          *
3584          * @return void
3585          * @expectedException Friendica\Network\HTTPException\BadRequestException
3586          */
3587         public function testApiAccountUpdateProfileImage()
3588         {
3589                 api_account_update_profile_image('json');
3590         }
3591
3592         /**
3593          * Test the api_account_update_profile_image() function without an authenticated user.
3594          *
3595          * @return void
3596          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3597          */
3598         public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3599         {
3600                 $_SESSION['authenticated'] = false;
3601                 api_account_update_profile_image('json');
3602         }
3603
3604         /**
3605          * Test the api_account_update_profile_image() function with an uploaded file.
3606          *
3607          * @return void
3608          * @expectedException Friendica\Network\HTTPException\BadRequestException
3609          */
3610         public function testApiAccountUpdateProfileImageWithUpload()
3611         {
3612                 $this->markTestIncomplete();
3613         }
3614
3615
3616         /**
3617          * Test the api_account_update_profile() function.
3618          *
3619          * @return void
3620          */
3621         public function testApiAccountUpdateProfile()
3622         {
3623                 $_POST['name']        = 'new_name';
3624                 $_POST['description'] = 'new_description';
3625                 $result               = api_account_update_profile('json');
3626                 // We can't use assertSelfUser() here because the user object is missing some properties.
3627                 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3628                 $this->assertEquals('DFRN', $result['user']['location']);
3629                 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3630                 $this->assertEquals('dfrn', $result['user']['network']);
3631                 $this->assertEquals('new_name', $result['user']['name']);
3632                 $this->assertEquals('new_description', $result['user']['description']);
3633         }
3634
3635         /**
3636          * Test the check_acl_input() function.
3637          *
3638          * @return void
3639          */
3640         public function testCheckAclInput()
3641         {
3642                 $result = check_acl_input('<aclstring>');
3643                 // Where does this result come from?
3644                 $this->assertEquals(1, $result);
3645         }
3646
3647         /**
3648          * Test the check_acl_input() function with an empty ACL string.
3649          *
3650          * @return void
3651          */
3652         public function testCheckAclInputWithEmptyAclString()
3653         {
3654                 $result = check_acl_input(' ');
3655                 $this->assertFalse($result);
3656         }
3657
3658         /**
3659          * Test the save_media_to_database() function.
3660          *
3661          * @return void
3662          */
3663         public function testSaveMediaToDatabase()
3664         {
3665                 $this->markTestIncomplete();
3666         }
3667
3668         /**
3669          * Test the post_photo_item() function.
3670          *
3671          * @return void
3672          */
3673         public function testPostPhotoItem()
3674         {
3675                 $this->markTestIncomplete();
3676         }
3677
3678         /**
3679          * Test the prepare_photo_data() function.
3680          *
3681          * @return void
3682          */
3683         public function testPreparePhotoData()
3684         {
3685                 $this->markTestIncomplete();
3686         }
3687
3688         /**
3689          * Test the api_friendica_remoteauth() function.
3690          *
3691          * @return void
3692          * @expectedException Friendica\Network\HTTPException\BadRequestException
3693          */
3694         public function testApiFriendicaRemoteauth()
3695         {
3696                 api_friendica_remoteauth();
3697         }
3698
3699         /**
3700          * Test the api_friendica_remoteauth() function with an URL.
3701          *
3702          * @return void
3703          * @expectedException Friendica\Network\HTTPException\BadRequestException
3704          */
3705         public function testApiFriendicaRemoteauthWithUrl()
3706         {
3707                 $_GET['url']   = 'url';
3708                 $_GET['c_url'] = 'url';
3709                 api_friendica_remoteauth();
3710         }
3711
3712         /**
3713          * Test the api_friendica_remoteauth() function with a correct URL.
3714          *
3715          * @return void
3716          */
3717         public function testApiFriendicaRemoteauthWithCorrectUrl()
3718         {
3719                 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3720                 $_GET['url']   = 'url';
3721                 $_GET['c_url'] = $this->selfUser['nurl'];
3722                 api_friendica_remoteauth();
3723         }
3724
3725         /**
3726          * Test the api_share_as_retweet() function.
3727          *
3728          * @return void
3729          */
3730         public function testApiShareAsRetweet()
3731         {
3732                 $item   = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3733                 $result = api_share_as_retweet($item);
3734                 $this->assertFalse($result);
3735         }
3736
3737         /**
3738          * Test the api_share_as_retweet() function with a valid item.
3739          *
3740          * @return void
3741          */
3742         public function testApiShareAsRetweetWithValidItem()
3743         {
3744                 $this->markTestIncomplete();
3745         }
3746
3747         /**
3748          * Test the api_in_reply_to() function.
3749          *
3750          * @return void
3751          */
3752         public function testApiInReplyTo()
3753         {
3754                 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3755                 $this->assertArrayHasKey('status_id', $result);
3756                 $this->assertArrayHasKey('user_id', $result);
3757                 $this->assertArrayHasKey('status_id_str', $result);
3758                 $this->assertArrayHasKey('user_id_str', $result);
3759                 $this->assertArrayHasKey('screen_name', $result);
3760         }
3761
3762         /**
3763          * Test the api_in_reply_to() function with a valid item.
3764          *
3765          * @return void
3766          */
3767         public function testApiInReplyToWithValidItem()
3768         {
3769                 $this->markTestIncomplete();
3770         }
3771
3772         /**
3773          * Test the api_clean_plain_items() function.
3774          *
3775          * @return void
3776          */
3777         public function testApiCleanPlainItems()
3778         {
3779                 $_REQUEST['include_entities'] = 'true';
3780                 $result                       = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3781                 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3782         }
3783
3784         /**
3785          * Test the api_best_nickname() function.
3786          *
3787          * @return void
3788          */
3789         public function testApiBestNickname()
3790         {
3791                 $contacts = [];
3792                 $result   = api_best_nickname($contacts);
3793                 $this->assertNull($result);
3794         }
3795
3796         /**
3797          * Test the api_best_nickname() function with contacts.
3798          *
3799          * @return void
3800          */
3801         public function testApiBestNicknameWithContacts()
3802         {
3803                 $this->markTestIncomplete();
3804         }
3805
3806         /**
3807          * Test the api_friendica_group_show() function.
3808          *
3809          * @return void
3810          */
3811         public function testApiFriendicaGroupShow()
3812         {
3813                 $this->markTestIncomplete();
3814         }
3815
3816         /**
3817          * Test the api_friendica_group_delete() function.
3818          *
3819          * @return void
3820          */
3821         public function testApiFriendicaGroupDelete()
3822         {
3823                 $this->markTestIncomplete();
3824         }
3825
3826         /**
3827          * Test the api_lists_destroy() function.
3828          *
3829          * @return void
3830          */
3831         public function testApiListsDestroy()
3832         {
3833                 $this->markTestIncomplete();
3834         }
3835
3836         /**
3837          * Test the group_create() function.
3838          *
3839          * @return void
3840          */
3841         public function testGroupCreate()
3842         {
3843                 $this->markTestIncomplete();
3844         }
3845
3846         /**
3847          * Test the api_friendica_group_create() function.
3848          *
3849          * @return void
3850          */
3851         public function testApiFriendicaGroupCreate()
3852         {
3853                 $this->markTestIncomplete();
3854         }
3855
3856         /**
3857          * Test the api_lists_create() function.
3858          *
3859          * @return void
3860          */
3861         public function testApiListsCreate()
3862         {
3863                 $this->markTestIncomplete();
3864         }
3865
3866         /**
3867          * Test the api_friendica_group_update() function.
3868          *
3869          * @return void
3870          */
3871         public function testApiFriendicaGroupUpdate()
3872         {
3873                 $this->markTestIncomplete();
3874         }
3875
3876         /**
3877          * Test the api_lists_update() function.
3878          *
3879          * @return void
3880          */
3881         public function testApiListsUpdate()
3882         {
3883                 $this->markTestIncomplete();
3884         }
3885
3886         /**
3887          * Test the api_friendica_activity() function.
3888          *
3889          * @return void
3890          */
3891         public function testApiFriendicaActivity()
3892         {
3893                 $this->markTestIncomplete();
3894         }
3895
3896         /**
3897          * Test the api_friendica_notification() function.
3898          *
3899          * @return void
3900          * @expectedException Friendica\Network\HTTPException\BadRequestException
3901          */
3902         public function testApiFriendicaNotification()
3903         {
3904                 api_friendica_notification('json');
3905         }
3906
3907         /**
3908          * Test the api_friendica_notification() function without an authenticated user.
3909          *
3910          * @return void
3911          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3912          */
3913         public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3914         {
3915                 $_SESSION['authenticated'] = false;
3916                 api_friendica_notification('json');
3917         }
3918
3919         /**
3920          * Test the api_friendica_notification() function with empty result
3921          *
3922          * @return void
3923          */
3924         public function testApiFriendicaNotificationWithEmptyResult()
3925         {
3926                 $this->app->argv = ['api', 'friendica', 'notification'];
3927                 $this->app->argc = count($this->app->argv);
3928                 $_SESSION['uid'] = 41;
3929                 $result          = api_friendica_notification('json');
3930                 $this->assertEquals(['note' => false], $result);
3931         }
3932
3933         /**
3934          * Test the api_friendica_notification() function with an XML result.
3935          *
3936          * @return void
3937          */
3938         public function testApiFriendicaNotificationWithXmlResult()
3939         {
3940                 $this->app->argv = ['api', 'friendica', 'notification'];
3941                 $this->app->argc = count($this->app->argv);
3942                 $result          = api_friendica_notification('xml');
3943                 $assertXml=<<<XML
3944 <?xml version="1.0"?>
3945 <notes>
3946   <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="4 weeks ago" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
3947 </notes>
3948 XML;
3949                 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3950         }
3951
3952         /**
3953          * Test the api_friendica_notification() function with an JSON result.
3954          *
3955          * @return void
3956          */
3957         public function testApiFriendicaNotificationWithJsonResult()
3958         {
3959                 $this->app->argv = ['api', 'friendica', 'notification'];
3960                 $this->app->argc = count($this->app->argv);
3961                 $result          = json_encode(api_friendica_notification('json'));
3962                 $this->assertJson($result);
3963         }
3964
3965         /**
3966          * Test the api_friendica_notification_seen() function.
3967          *
3968          * @return void
3969          */
3970         public function testApiFriendicaNotificationSeen()
3971         {
3972                 $this->markTestIncomplete();
3973         }
3974
3975         /**
3976          * Test the api_friendica_direct_messages_setseen() function.
3977          *
3978          * @return void
3979          */
3980         public function testApiFriendicaDirectMessagesSetseen()
3981         {
3982                 $this->markTestIncomplete();
3983         }
3984
3985         /**
3986          * Test the api_friendica_direct_messages_search() function.
3987          *
3988          * @return void
3989          */
3990         public function testApiFriendicaDirectMessagesSearch()
3991         {
3992                 $this->markTestIncomplete();
3993         }
3994
3995         /**
3996          * Test the api_friendica_profile_show() function.
3997          *
3998          * @return void
3999          */
4000         public function testApiFriendicaProfileShow()
4001         {
4002                 $result = api_friendica_profile_show('json');
4003                 // We can't use assertSelfUser() here because the user object is missing some properties.
4004                 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
4005                 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
4006                 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
4007                 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
4008                 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
4009                 $this->assertTrue($result['$result']['friendica_owner']['verified']);
4010                 $this->assertFalse($result['$result']['multi_profiles']);
4011         }
4012
4013         /**
4014          * Test the api_friendica_profile_show() function with a profile ID.
4015          *
4016          * @return void
4017          */
4018         public function testApiFriendicaProfileShowWithProfileId()
4019         {
4020                 $this->markTestIncomplete('We need to add a dataset for this.');
4021         }
4022
4023         /**
4024          * Test the api_friendica_profile_show() function with a wrong profile ID.
4025          *
4026          * @return void
4027          * @expectedException Friendica\Network\HTTPException\BadRequestException
4028          */
4029         public function testApiFriendicaProfileShowWithWrongProfileId()
4030         {
4031                 $_REQUEST['profile_id'] = 666;
4032                 api_friendica_profile_show('json');
4033         }
4034
4035         /**
4036          * Test the api_friendica_profile_show() function without an authenticated user.
4037          *
4038          * @return void
4039          * @expectedException Friendica\Network\HTTPException\ForbiddenException
4040          */
4041         public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4042         {
4043                 $_SESSION['authenticated'] = false;
4044                 api_friendica_profile_show('json');
4045         }
4046
4047         /**
4048          * Test the api_saved_searches_list() function.
4049          *
4050          * @return void
4051          */
4052         public function testApiSavedSearchesList()
4053         {
4054                 $result = api_saved_searches_list('json');
4055                 $this->assertEquals(1, $result['terms'][0]['id']);
4056                 $this->assertEquals(1, $result['terms'][0]['id_str']);
4057                 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4058                 $this->assertEquals('Saved search', $result['terms'][0]['query']);
4059         }
4060 }