]> git.mxchange.org Git - friendica.git/blob - tests/include/ApiTest.php
Move api/profile/show to src/Module
[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() function.
2493          *
2494          * @return void
2495          */
2496         public function testApiFormatItems()
2497         {
2498                 $items  = [
2499                         [
2500                                 'item_network'   => 'item_network',
2501                                 'source'         => 'web',
2502                                 'coord'          => '5 7',
2503                                 'body'           => '',
2504                                 'verb'           => '',
2505                                 'author-id'      => 43,
2506                                 'author-network' => Protocol::DFRN,
2507                                 'author-link'    => 'http://localhost/profile/othercontact',
2508                                 'plink'          => '',
2509                         ]
2510                 ];
2511                 $result = api_format_items($items, ['id' => 0], true);
2512                 foreach ($result as $status) {
2513                         $this->assertStatus($status);
2514                 }
2515         }
2516
2517         /**
2518          * Test the api_format_items() function with an XML result.
2519          *
2520          * @return void
2521          */
2522         public function testApiFormatItemsWithXml()
2523         {
2524                 $items  = [
2525                         [
2526                                 'coord'          => '5 7',
2527                                 'body'           => '',
2528                                 'verb'           => '',
2529                                 'author-id'      => 43,
2530                                 'author-network' => Protocol::DFRN,
2531                                 'author-link'    => 'http://localhost/profile/othercontact',
2532                                 'plink'          => '',
2533                         ]
2534                 ];
2535                 $result = api_format_items($items, ['id' => 0], true, 'xml');
2536                 foreach ($result as $status) {
2537                         $this->assertStatus($status);
2538                 }
2539         }
2540
2541         /**
2542          * Test the api_format_items() function.
2543          *
2544          * @return void
2545          */
2546         public function testApiAccountRateLimitStatus()
2547         {
2548                 $result = api_account_rate_limit_status('json');
2549                 $this->assertEquals(150, $result['hash']['remaining_hits']);
2550                 $this->assertEquals(150, $result['hash']['hourly_limit']);
2551                 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2552         }
2553
2554         /**
2555          * Test the api_format_items() function with an XML result.
2556          *
2557          * @return void
2558          */
2559         public function testApiAccountRateLimitStatusWithXml()
2560         {
2561                 $result = api_account_rate_limit_status('xml');
2562                 $this->assertXml($result, 'hash');
2563         }
2564
2565         /**
2566          * Test the api_help_test() function.
2567          *
2568          * @return void
2569          */
2570         public function testApiHelpTest()
2571         {
2572                 $result = api_help_test('json');
2573                 $this->assertEquals(['ok' => 'ok'], $result);
2574         }
2575
2576         /**
2577          * Test the api_help_test() function with an XML result.
2578          *
2579          * @return void
2580          */
2581         public function testApiHelpTestWithXml()
2582         {
2583                 $result = api_help_test('xml');
2584                 $this->assertXml($result, 'ok');
2585         }
2586
2587         /**
2588          * Test the api_lists_list() function.
2589          *
2590          * @return void
2591          */
2592         public function testApiListsList()
2593         {
2594                 $result = api_lists_list('json');
2595                 $this->assertEquals(['lists_list' => []], $result);
2596         }
2597
2598         /**
2599          * Test the api_lists_ownerships() function.
2600          *
2601          * @return void
2602          */
2603         public function testApiListsOwnerships()
2604         {
2605                 $result = api_lists_ownerships('json');
2606                 foreach ($result['lists']['lists'] as $list) {
2607                         $this->assertList($list);
2608                 }
2609         }
2610
2611         /**
2612          * Test the api_lists_ownerships() function without an authenticated user.
2613          *
2614          * @return void
2615          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2616          */
2617         public function testApiListsOwnershipsWithoutAuthenticatedUser()
2618         {
2619                 $_SESSION['authenticated'] = false;
2620                 api_lists_ownerships('json');
2621         }
2622
2623         /**
2624          * Test the api_lists_statuses() function.
2625          *
2626          * @expectedException Friendica\Network\HTTPException\BadRequestException
2627          * @return void
2628          */
2629         public function testApiListsStatuses()
2630         {
2631                 api_lists_statuses('json');
2632         }
2633
2634         /**
2635          * Test the api_lists_statuses() function with a list ID.
2636          *
2637          * @return void
2638          */
2639         public function testApiListsStatusesWithListId()
2640         {
2641                 $_REQUEST['list_id'] = 1;
2642                 $_REQUEST['page']    = -1;
2643                 $_REQUEST['max_id']  = 10;
2644                 $result              = api_lists_statuses('json');
2645                 foreach ($result['status'] as $status) {
2646                         $this->assertStatus($status);
2647                 }
2648         }
2649
2650         /**
2651          * Test the api_lists_statuses() function with a list ID and a RSS result.
2652          *
2653          * @return void
2654          */
2655         public function testApiListsStatusesWithListIdAndRss()
2656         {
2657                 $_REQUEST['list_id'] = 1;
2658                 $result              = api_lists_statuses('rss');
2659                 $this->assertXml($result, 'statuses');
2660         }
2661
2662         /**
2663          * Test the api_lists_statuses() function with an unallowed user.
2664          *
2665          * @return void
2666          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2667          */
2668         public function testApiListsStatusesWithUnallowedUser()
2669         {
2670                 $_SESSION['allow_api'] = false;
2671                 $_GET['screen_name']   = $this->selfUser['nick'];
2672                 api_lists_statuses('json');
2673         }
2674
2675         /**
2676          * Test the api_statuses_f() function.
2677          *
2678          * @return void
2679          */
2680         public function testApiStatusesFWithFriends()
2681         {
2682                 $_GET['page'] = -1;
2683                 $result       = api_statuses_f('friends');
2684                 $this->assertArrayHasKey('user', $result);
2685         }
2686
2687         /**
2688          * Test the api_statuses_f() function.
2689          *
2690          * @return void
2691          */
2692         public function testApiStatusesFWithFollowers()
2693         {
2694                 $result = api_statuses_f('followers');
2695                 $this->assertArrayHasKey('user', $result);
2696         }
2697
2698         /**
2699          * Test the api_statuses_f() function.
2700          *
2701          * @return void
2702          */
2703         public function testApiStatusesFWithBlocks()
2704         {
2705                 $result = api_statuses_f('blocks');
2706                 $this->assertArrayHasKey('user', $result);
2707         }
2708
2709         /**
2710          * Test the api_statuses_f() function.
2711          *
2712          * @return void
2713          */
2714         public function testApiStatusesFWithIncoming()
2715         {
2716                 $result = api_statuses_f('incoming');
2717                 $this->assertArrayHasKey('user', $result);
2718         }
2719
2720         /**
2721          * Test the api_statuses_f() function an undefined cursor GET variable.
2722          *
2723          * @return void
2724          */
2725         public function testApiStatusesFWithUndefinedCursor()
2726         {
2727                 $_GET['cursor'] = 'undefined';
2728                 $this->assertFalse(api_statuses_f('friends'));
2729         }
2730
2731         /**
2732          * Test the api_statuses_friends() function.
2733          *
2734          * @return void
2735          */
2736         public function testApiStatusesFriends()
2737         {
2738                 $result = api_statuses_friends('json');
2739                 $this->assertArrayHasKey('user', $result);
2740         }
2741
2742         /**
2743          * Test the api_statuses_friends() function an undefined cursor GET variable.
2744          *
2745          * @return void
2746          */
2747         public function testApiStatusesFriendsWithUndefinedCursor()
2748         {
2749                 $_GET['cursor'] = 'undefined';
2750                 $this->assertFalse(api_statuses_friends('json'));
2751         }
2752
2753         /**
2754          * Test the api_statuses_followers() function.
2755          *
2756          * @return void
2757          */
2758         public function testApiStatusesFollowers()
2759         {
2760                 $result = api_statuses_followers('json');
2761                 $this->assertArrayHasKey('user', $result);
2762         }
2763
2764         /**
2765          * Test the api_statuses_followers() function an undefined cursor GET variable.
2766          *
2767          * @return void
2768          */
2769         public function testApiStatusesFollowersWithUndefinedCursor()
2770         {
2771                 $_GET['cursor'] = 'undefined';
2772                 $this->assertFalse(api_statuses_followers('json'));
2773         }
2774
2775         /**
2776          * Test the api_blocks_list() function.
2777          *
2778          * @return void
2779          */
2780         public function testApiBlocksList()
2781         {
2782                 $result = api_blocks_list('json');
2783                 $this->assertArrayHasKey('user', $result);
2784         }
2785
2786         /**
2787          * Test the api_blocks_list() function an undefined cursor GET variable.
2788          *
2789          * @return void
2790          */
2791         public function testApiBlocksListWithUndefinedCursor()
2792         {
2793                 $_GET['cursor'] = 'undefined';
2794                 $this->assertFalse(api_blocks_list('json'));
2795         }
2796
2797         /**
2798          * Test the api_friendships_incoming() function.
2799          *
2800          * @return void
2801          */
2802         public function testApiFriendshipsIncoming()
2803         {
2804                 $result = api_friendships_incoming('json');
2805                 $this->assertArrayHasKey('id', $result);
2806         }
2807
2808         /**
2809          * Test the api_friendships_incoming() function an undefined cursor GET variable.
2810          *
2811          * @return void
2812          */
2813         public function testApiFriendshipsIncomingWithUndefinedCursor()
2814         {
2815                 $_GET['cursor'] = 'undefined';
2816                 $this->assertFalse(api_friendships_incoming('json'));
2817         }
2818
2819         /**
2820          * Test the api_statusnet_config() function.
2821          *
2822          * @return void
2823          */
2824         public function testApiStatusnetConfig()
2825         {
2826                 $result = api_statusnet_config('json');
2827                 $this->assertEquals('localhost', $result['config']['site']['server']);
2828                 $this->assertEquals('default', $result['config']['site']['theme']);
2829                 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2830                 $this->assertTrue($result['config']['site']['fancy']);
2831                 $this->assertEquals('en', $result['config']['site']['language']);
2832                 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2833                 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2834                 $this->assertEquals('false', $result['config']['site']['private']);
2835                 $this->assertEquals('false', $result['config']['site']['ssl']);
2836                 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2837         }
2838
2839         /**
2840          * Test the api_statusnet_version() function.
2841          *
2842          * @return void
2843          */
2844         public function testApiStatusnetVersion()
2845         {
2846                 $result = api_statusnet_version('json');
2847                 $this->assertEquals('0.9.7', $result['version']);
2848         }
2849
2850         /**
2851          * Test the api_ff_ids() function.
2852          *
2853          * @return void
2854          */
2855         public function testApiFfIds()
2856         {
2857                 $result = api_ff_ids('json', Contact::FOLLOWER);
2858                 $this->assertEquals(['id' => []], $result);
2859         }
2860
2861         /**
2862          * Test the api_ff_ids() function with a result.
2863          *
2864          * @return void
2865          */
2866         public function testApiFfIdsWithResult()
2867         {
2868                 $this->markTestIncomplete();
2869         }
2870
2871         /**
2872          * Test the api_ff_ids() function without an authenticated user.
2873          *
2874          * @return void
2875          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2876          */
2877         public function testApiFfIdsWithoutAuthenticatedUser()
2878         {
2879                 $_SESSION['authenticated'] = false;
2880                 api_ff_ids('json', Contact::FOLLOWER);
2881         }
2882
2883         /**
2884          * Test the api_friends_ids() function.
2885          *
2886          * @return void
2887          */
2888         public function testApiFriendsIds()
2889         {
2890                 $result = api_friends_ids('json');
2891                 $this->assertEquals(['id' => []], $result);
2892         }
2893
2894         /**
2895          * Test the api_followers_ids() function.
2896          *
2897          * @return void
2898          */
2899         public function testApiFollowersIds()
2900         {
2901                 $result = api_followers_ids('json');
2902                 $this->assertEquals(['id' => []], $result);
2903         }
2904
2905         /**
2906          * Test the api_direct_messages_new() function.
2907          *
2908          * @return void
2909          */
2910         public function testApiDirectMessagesNew()
2911         {
2912                 $result = api_direct_messages_new('json');
2913                 $this->assertNull($result);
2914         }
2915
2916         /**
2917          * Test the api_direct_messages_new() function without an authenticated user.
2918          *
2919          * @return void
2920          * @expectedException Friendica\Network\HTTPException\ForbiddenException
2921          */
2922         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2923         {
2924                 $_SESSION['authenticated'] = false;
2925                 api_direct_messages_new('json');
2926         }
2927
2928         /**
2929          * Test the api_direct_messages_new() function with an user ID.
2930          *
2931          * @return void
2932          */
2933         public function testApiDirectMessagesNewWithUserId()
2934         {
2935                 $_POST['text']    = 'message_text';
2936                 $_POST['user_id'] = $this->otherUser['id'];
2937                 $result           = api_direct_messages_new('json');
2938                 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2939         }
2940
2941         /**
2942          * Test the api_direct_messages_new() function with a screen name.
2943          *
2944          * @return void
2945          */
2946         public function testApiDirectMessagesNewWithScreenName()
2947         {
2948                 $_POST['text']        = 'message_text';
2949                 $_POST['screen_name'] = $this->friendUser['nick'];
2950                 $result               = api_direct_messages_new('json');
2951                 $this->assertContains('message_text', $result['direct_message']['text']);
2952                 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2953                 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2954         }
2955
2956         /**
2957          * Test the api_direct_messages_new() function with a title.
2958          *
2959          * @return void
2960          */
2961         public function testApiDirectMessagesNewWithTitle()
2962         {
2963                 $_POST['text']        = 'message_text';
2964                 $_POST['screen_name'] = $this->friendUser['nick'];
2965                 $_REQUEST['title']    = 'message_title';
2966                 $result               = api_direct_messages_new('json');
2967                 $this->assertContains('message_text', $result['direct_message']['text']);
2968                 $this->assertContains('message_title', $result['direct_message']['text']);
2969                 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2970                 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2971         }
2972
2973         /**
2974          * Test the api_direct_messages_new() function with an RSS result.
2975          *
2976          * @return void
2977          */
2978         public function testApiDirectMessagesNewWithRss()
2979         {
2980                 $_POST['text']        = 'message_text';
2981                 $_POST['screen_name'] = $this->friendUser['nick'];
2982                 $result               = api_direct_messages_new('rss');
2983                 $this->assertXml($result, 'direct-messages');
2984         }
2985
2986         /**
2987          * Test the api_direct_messages_destroy() function.
2988          *
2989          * @return void
2990          * @expectedException Friendica\Network\HTTPException\BadRequestException
2991          */
2992         public function testApiDirectMessagesDestroy()
2993         {
2994                 api_direct_messages_destroy('json');
2995         }
2996
2997         /**
2998          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2999          *
3000          * @return void
3001          */
3002         public function testApiDirectMessagesDestroyWithVerbose()
3003         {
3004                 $_GET['friendica_verbose'] = 'true';
3005                 $result                    = api_direct_messages_destroy('json');
3006                 $this->assertEquals(
3007                         [
3008                                 '$result' => [
3009                                         'result'  => 'error',
3010                                         'message' => 'message id or parenturi not specified'
3011                                 ]
3012                         ],
3013                         $result
3014                 );
3015         }
3016
3017         /**
3018          * Test the api_direct_messages_destroy() function without an authenticated user.
3019          *
3020          * @return void
3021          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3022          */
3023         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3024         {
3025                 $_SESSION['authenticated'] = false;
3026                 api_direct_messages_destroy('json');
3027         }
3028
3029         /**
3030          * Test the api_direct_messages_destroy() function with a non-zero ID.
3031          *
3032          * @return void
3033          * @expectedException Friendica\Network\HTTPException\BadRequestException
3034          */
3035         public function testApiDirectMessagesDestroyWithId()
3036         {
3037                 $_REQUEST['id'] = 1;
3038                 api_direct_messages_destroy('json');
3039         }
3040
3041         /**
3042          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3043          *
3044          * @return void
3045          */
3046         public function testApiDirectMessagesDestroyWithIdAndVerbose()
3047         {
3048                 $_REQUEST['id']                  = 1;
3049                 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3050                 $_GET['friendica_verbose']       = 'true';
3051                 $result                          = api_direct_messages_destroy('json');
3052                 $this->assertEquals(
3053                         [
3054                                 '$result' => [
3055                                         'result'  => 'error',
3056                                         'message' => 'message id not in database'
3057                                 ]
3058                         ],
3059                         $result
3060                 );
3061         }
3062
3063         /**
3064          * Test the api_direct_messages_destroy() function with a non-zero ID.
3065          *
3066          * @return void
3067          */
3068         public function testApiDirectMessagesDestroyWithCorrectId()
3069         {
3070                 $this->markTestIncomplete('We need to add a dataset for this.');
3071         }
3072
3073         /**
3074          * Test the api_direct_messages_box() function.
3075          *
3076          * @return void
3077          */
3078         public function testApiDirectMessagesBoxWithSentbox()
3079         {
3080                 $_REQUEST['page']   = -1;
3081                 $_REQUEST['max_id'] = 10;
3082                 $result             = api_direct_messages_box('json', 'sentbox', 'false');
3083                 $this->assertArrayHasKey('direct_message', $result);
3084         }
3085
3086         /**
3087          * Test the api_direct_messages_box() function.
3088          *
3089          * @return void
3090          */
3091         public function testApiDirectMessagesBoxWithConversation()
3092         {
3093                 $result = api_direct_messages_box('json', 'conversation', 'false');
3094                 $this->assertArrayHasKey('direct_message', $result);
3095         }
3096
3097         /**
3098          * Test the api_direct_messages_box() function.
3099          *
3100          * @return void
3101          */
3102         public function testApiDirectMessagesBoxWithAll()
3103         {
3104                 $result = api_direct_messages_box('json', 'all', 'false');
3105                 $this->assertArrayHasKey('direct_message', $result);
3106         }
3107
3108         /**
3109          * Test the api_direct_messages_box() function.
3110          *
3111          * @return void
3112          */
3113         public function testApiDirectMessagesBoxWithInbox()
3114         {
3115                 $result = api_direct_messages_box('json', 'inbox', 'false');
3116                 $this->assertArrayHasKey('direct_message', $result);
3117         }
3118
3119         /**
3120          * Test the api_direct_messages_box() function.
3121          *
3122          * @return void
3123          */
3124         public function testApiDirectMessagesBoxWithVerbose()
3125         {
3126                 $result = api_direct_messages_box('json', 'sentbox', 'true');
3127                 $this->assertEquals(
3128                         [
3129                                 '$result' => [
3130                                         'result'  => 'error',
3131                                         'message' => 'no mails available'
3132                                 ]
3133                         ],
3134                         $result
3135                 );
3136         }
3137
3138         /**
3139          * Test the api_direct_messages_box() function with a RSS result.
3140          *
3141          * @return void
3142          */
3143         public function testApiDirectMessagesBoxWithRss()
3144         {
3145                 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3146                 $this->assertXml($result, 'direct-messages');
3147         }
3148
3149         /**
3150          * Test the api_direct_messages_box() function without an authenticated user.
3151          *
3152          * @return void
3153          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3154          */
3155         public function testApiDirectMessagesBoxWithUnallowedUser()
3156         {
3157                 $_SESSION['allow_api'] = false;
3158                 $_GET['screen_name']   = $this->selfUser['nick'];
3159                 api_direct_messages_box('json', 'sentbox', 'false');
3160         }
3161
3162         /**
3163          * Test the api_direct_messages_sentbox() function.
3164          *
3165          * @return void
3166          */
3167         public function testApiDirectMessagesSentbox()
3168         {
3169                 $result = api_direct_messages_sentbox('json');
3170                 $this->assertArrayHasKey('direct_message', $result);
3171         }
3172
3173         /**
3174          * Test the api_direct_messages_inbox() function.
3175          *
3176          * @return void
3177          */
3178         public function testApiDirectMessagesInbox()
3179         {
3180                 $result = api_direct_messages_inbox('json');
3181                 $this->assertArrayHasKey('direct_message', $result);
3182         }
3183
3184         /**
3185          * Test the api_direct_messages_all() function.
3186          *
3187          * @return void
3188          */
3189         public function testApiDirectMessagesAll()
3190         {
3191                 $result = api_direct_messages_all('json');
3192                 $this->assertArrayHasKey('direct_message', $result);
3193         }
3194
3195         /**
3196          * Test the api_direct_messages_conversation() function.
3197          *
3198          * @return void
3199          */
3200         public function testApiDirectMessagesConversation()
3201         {
3202                 $result = api_direct_messages_conversation('json');
3203                 $this->assertArrayHasKey('direct_message', $result);
3204         }
3205
3206         /**
3207          * Test the api_oauth_request_token() function.
3208          *
3209          * @return void
3210          */
3211         public function testApiOauthRequestToken()
3212         {
3213                 $this->markTestIncomplete('exit() kills phpunit as well');
3214         }
3215
3216         /**
3217          * Test the api_oauth_access_token() function.
3218          *
3219          * @return void
3220          */
3221         public function testApiOauthAccessToken()
3222         {
3223                 $this->markTestIncomplete('exit() kills phpunit as well');
3224         }
3225
3226         /**
3227          * Test the api_fr_photoalbum_delete() function.
3228          *
3229          * @return void
3230          * @expectedException Friendica\Network\HTTPException\BadRequestException
3231          */
3232         public function testApiFrPhotoalbumDelete()
3233         {
3234                 api_fr_photoalbum_delete('json');
3235         }
3236
3237         /**
3238          * Test the api_fr_photoalbum_delete() function with an album name.
3239          *
3240          * @return void
3241          * @expectedException Friendica\Network\HTTPException\BadRequestException
3242          */
3243         public function testApiFrPhotoalbumDeleteWithAlbum()
3244         {
3245                 $_REQUEST['album'] = 'album_name';
3246                 api_fr_photoalbum_delete('json');
3247         }
3248
3249         /**
3250          * Test the api_fr_photoalbum_delete() function with an album name.
3251          *
3252          * @return void
3253          */
3254         public function testApiFrPhotoalbumDeleteWithValidAlbum()
3255         {
3256                 $this->markTestIncomplete('We need to add a dataset for this.');
3257         }
3258
3259         /**
3260          * Test the api_fr_photoalbum_delete() function.
3261          *
3262          * @return void
3263          * @expectedException Friendica\Network\HTTPException\BadRequestException
3264          */
3265         public function testApiFrPhotoalbumUpdate()
3266         {
3267                 api_fr_photoalbum_update('json');
3268         }
3269
3270         /**
3271          * Test the api_fr_photoalbum_delete() function with an album name.
3272          *
3273          * @return void
3274          * @expectedException Friendica\Network\HTTPException\BadRequestException
3275          */
3276         public function testApiFrPhotoalbumUpdateWithAlbum()
3277         {
3278                 $_REQUEST['album'] = 'album_name';
3279                 api_fr_photoalbum_update('json');
3280         }
3281
3282         /**
3283          * Test the api_fr_photoalbum_delete() function with an album name.
3284          *
3285          * @return void
3286          * @expectedException Friendica\Network\HTTPException\BadRequestException
3287          */
3288         public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3289         {
3290                 $_REQUEST['album']     = 'album_name';
3291                 $_REQUEST['album_new'] = 'album_name';
3292                 api_fr_photoalbum_update('json');
3293         }
3294
3295         /**
3296          * Test the api_fr_photoalbum_update() function without an authenticated user.
3297          *
3298          * @return void
3299          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3300          */
3301         public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3302         {
3303                 $_SESSION['authenticated'] = false;
3304                 api_fr_photoalbum_update('json');
3305         }
3306
3307         /**
3308          * Test the api_fr_photoalbum_delete() function with an album name.
3309          *
3310          * @return void
3311          */
3312         public function testApiFrPhotoalbumUpdateWithValidAlbum()
3313         {
3314                 $this->markTestIncomplete('We need to add a dataset for this.');
3315         }
3316
3317         /**
3318          * Test the api_fr_photos_list() function.
3319          *
3320          * @return void
3321          */
3322         public function testApiFrPhotosList()
3323         {
3324                 $result = api_fr_photos_list('json');
3325                 $this->assertArrayHasKey('photo', $result);
3326         }
3327
3328         /**
3329          * Test the api_fr_photos_list() function without an authenticated user.
3330          *
3331          * @return void
3332          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3333          */
3334         public function testApiFrPhotosListWithoutAuthenticatedUser()
3335         {
3336                 $_SESSION['authenticated'] = false;
3337                 api_fr_photos_list('json');
3338         }
3339
3340         /**
3341          * Test the api_fr_photo_create_update() function.
3342          *
3343          * @return void
3344          * @expectedException Friendica\Network\HTTPException\BadRequestException
3345          */
3346         public function testApiFrPhotoCreateUpdate()
3347         {
3348                 api_fr_photo_create_update('json');
3349         }
3350
3351         /**
3352          * Test the api_fr_photo_create_update() function without an authenticated user.
3353          *
3354          * @return void
3355          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3356          */
3357         public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3358         {
3359                 $_SESSION['authenticated'] = false;
3360                 api_fr_photo_create_update('json');
3361         }
3362
3363         /**
3364          * Test the api_fr_photo_create_update() function with an album name.
3365          *
3366          * @return void
3367          * @expectedException Friendica\Network\HTTPException\BadRequestException
3368          */
3369         public function testApiFrPhotoCreateUpdateWithAlbum()
3370         {
3371                 $_REQUEST['album'] = 'album_name';
3372                 api_fr_photo_create_update('json');
3373         }
3374
3375         /**
3376          * Test the api_fr_photo_create_update() function with the update mode.
3377          *
3378          * @return void
3379          */
3380         public function testApiFrPhotoCreateUpdateWithUpdate()
3381         {
3382                 $this->markTestIncomplete('We need to create a dataset for this');
3383         }
3384
3385         /**
3386          * Test the api_fr_photo_create_update() function with an uploaded file.
3387          *
3388          * @return void
3389          */
3390         public function testApiFrPhotoCreateUpdateWithFile()
3391         {
3392                 $this->markTestIncomplete();
3393         }
3394
3395         /**
3396          * Test the api_fr_photo_delete() function.
3397          *
3398          * @return void
3399          * @expectedException Friendica\Network\HTTPException\BadRequestException
3400          */
3401         public function testApiFrPhotoDelete()
3402         {
3403                 api_fr_photo_delete('json');
3404         }
3405
3406         /**
3407          * Test the api_fr_photo_delete() function without an authenticated user.
3408          *
3409          * @return void
3410          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3411          */
3412         public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3413         {
3414                 $_SESSION['authenticated'] = false;
3415                 api_fr_photo_delete('json');
3416         }
3417
3418         /**
3419          * Test the api_fr_photo_delete() function with a photo ID.
3420          *
3421          * @return void
3422          * @expectedException Friendica\Network\HTTPException\BadRequestException
3423          */
3424         public function testApiFrPhotoDeleteWithPhotoId()
3425         {
3426                 $_REQUEST['photo_id'] = 1;
3427                 api_fr_photo_delete('json');
3428         }
3429
3430         /**
3431          * Test the api_fr_photo_delete() function with a correct photo ID.
3432          *
3433          * @return void
3434          */
3435         public function testApiFrPhotoDeleteWithCorrectPhotoId()
3436         {
3437                 $this->markTestIncomplete('We need to create a dataset for this.');
3438         }
3439
3440         /**
3441          * Test the api_fr_photo_detail() function.
3442          *
3443          * @return void
3444          * @expectedException Friendica\Network\HTTPException\BadRequestException
3445          */
3446         public function testApiFrPhotoDetail()
3447         {
3448                 api_fr_photo_detail('json');
3449         }
3450
3451         /**
3452          * Test the api_fr_photo_detail() function without an authenticated user.
3453          *
3454          * @return void
3455          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3456          */
3457         public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3458         {
3459                 $_SESSION['authenticated'] = false;
3460                 api_fr_photo_detail('json');
3461         }
3462
3463         /**
3464          * Test the api_fr_photo_detail() function with a photo ID.
3465          *
3466          * @return void
3467          * @expectedException Friendica\Network\HTTPException\NotFoundException
3468          */
3469         public function testApiFrPhotoDetailWithPhotoId()
3470         {
3471                 $_REQUEST['photo_id'] = 1;
3472                 api_fr_photo_detail('json');
3473         }
3474
3475         /**
3476          * Test the api_fr_photo_detail() function with a correct photo ID.
3477          *
3478          * @return void
3479          */
3480         public function testApiFrPhotoDetailCorrectPhotoId()
3481         {
3482                 $this->markTestIncomplete('We need to create a dataset for this.');
3483         }
3484
3485         /**
3486          * Test the api_account_update_profile_image() function.
3487          *
3488          * @return void
3489          * @expectedException Friendica\Network\HTTPException\BadRequestException
3490          */
3491         public function testApiAccountUpdateProfileImage()
3492         {
3493                 api_account_update_profile_image('json');
3494         }
3495
3496         /**
3497          * Test the api_account_update_profile_image() function without an authenticated user.
3498          *
3499          * @return void
3500          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3501          */
3502         public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3503         {
3504                 $_SESSION['authenticated'] = false;
3505                 api_account_update_profile_image('json');
3506         }
3507
3508         /**
3509          * Test the api_account_update_profile_image() function with an uploaded file.
3510          *
3511          * @return void
3512          * @expectedException Friendica\Network\HTTPException\BadRequestException
3513          */
3514         public function testApiAccountUpdateProfileImageWithUpload()
3515         {
3516                 $this->markTestIncomplete();
3517         }
3518
3519
3520         /**
3521          * Test the api_account_update_profile() function.
3522          *
3523          * @return void
3524          */
3525         public function testApiAccountUpdateProfile()
3526         {
3527                 $_POST['name']        = 'new_name';
3528                 $_POST['description'] = 'new_description';
3529                 $result               = api_account_update_profile('json');
3530                 // We can't use assertSelfUser() here because the user object is missing some properties.
3531                 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3532                 $this->assertEquals('DFRN', $result['user']['location']);
3533                 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3534                 $this->assertEquals('dfrn', $result['user']['network']);
3535                 $this->assertEquals('new_name', $result['user']['name']);
3536                 $this->assertEquals('new_description', $result['user']['description']);
3537         }
3538
3539         /**
3540          * Test the check_acl_input() function.
3541          *
3542          * @return void
3543          */
3544         public function testCheckAclInput()
3545         {
3546                 $result = check_acl_input('<aclstring>');
3547                 // Where does this result come from?
3548                 $this->assertEquals(1, $result);
3549         }
3550
3551         /**
3552          * Test the check_acl_input() function with an empty ACL string.
3553          *
3554          * @return void
3555          */
3556         public function testCheckAclInputWithEmptyAclString()
3557         {
3558                 $result = check_acl_input(' ');
3559                 $this->assertFalse($result);
3560         }
3561
3562         /**
3563          * Test the save_media_to_database() function.
3564          *
3565          * @return void
3566          */
3567         public function testSaveMediaToDatabase()
3568         {
3569                 $this->markTestIncomplete();
3570         }
3571
3572         /**
3573          * Test the post_photo_item() function.
3574          *
3575          * @return void
3576          */
3577         public function testPostPhotoItem()
3578         {
3579                 $this->markTestIncomplete();
3580         }
3581
3582         /**
3583          * Test the prepare_photo_data() function.
3584          *
3585          * @return void
3586          */
3587         public function testPreparePhotoData()
3588         {
3589                 $this->markTestIncomplete();
3590         }
3591
3592         /**
3593          * Test the api_friendica_remoteauth() function.
3594          *
3595          * @return void
3596          * @expectedException Friendica\Network\HTTPException\BadRequestException
3597          */
3598         public function testApiFriendicaRemoteauth()
3599         {
3600                 api_friendica_remoteauth();
3601         }
3602
3603         /**
3604          * Test the api_friendica_remoteauth() function with an URL.
3605          *
3606          * @return void
3607          * @expectedException Friendica\Network\HTTPException\BadRequestException
3608          */
3609         public function testApiFriendicaRemoteauthWithUrl()
3610         {
3611                 $_GET['url']   = 'url';
3612                 $_GET['c_url'] = 'url';
3613                 api_friendica_remoteauth();
3614         }
3615
3616         /**
3617          * Test the api_friendica_remoteauth() function with a correct URL.
3618          *
3619          * @return void
3620          */
3621         public function testApiFriendicaRemoteauthWithCorrectUrl()
3622         {
3623                 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3624                 $_GET['url']   = 'url';
3625                 $_GET['c_url'] = $this->selfUser['nurl'];
3626                 api_friendica_remoteauth();
3627         }
3628
3629         /**
3630          * Test the api_share_as_retweet() function.
3631          *
3632          * @return void
3633          */
3634         public function testApiShareAsRetweet()
3635         {
3636                 $item   = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3637                 $result = api_share_as_retweet($item);
3638                 $this->assertFalse($result);
3639         }
3640
3641         /**
3642          * Test the api_share_as_retweet() function with a valid item.
3643          *
3644          * @return void
3645          */
3646         public function testApiShareAsRetweetWithValidItem()
3647         {
3648                 $this->markTestIncomplete();
3649         }
3650
3651         /**
3652          * Test the api_in_reply_to() function.
3653          *
3654          * @return void
3655          */
3656         public function testApiInReplyTo()
3657         {
3658                 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3659                 $this->assertArrayHasKey('status_id', $result);
3660                 $this->assertArrayHasKey('user_id', $result);
3661                 $this->assertArrayHasKey('status_id_str', $result);
3662                 $this->assertArrayHasKey('user_id_str', $result);
3663                 $this->assertArrayHasKey('screen_name', $result);
3664         }
3665
3666         /**
3667          * Test the api_in_reply_to() function with a valid item.
3668          *
3669          * @return void
3670          */
3671         public function testApiInReplyToWithValidItem()
3672         {
3673                 $this->markTestIncomplete();
3674         }
3675
3676         /**
3677          * Test the api_clean_plain_items() function.
3678          *
3679          * @return void
3680          */
3681         public function testApiCleanPlainItems()
3682         {
3683                 $_REQUEST['include_entities'] = 'true';
3684                 $result                       = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3685                 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3686         }
3687
3688         /**
3689          * Test the api_best_nickname() function.
3690          *
3691          * @return void
3692          */
3693         public function testApiBestNickname()
3694         {
3695                 $contacts = [];
3696                 $result   = api_best_nickname($contacts);
3697                 $this->assertNull($result);
3698         }
3699
3700         /**
3701          * Test the api_best_nickname() function with contacts.
3702          *
3703          * @return void
3704          */
3705         public function testApiBestNicknameWithContacts()
3706         {
3707                 $this->markTestIncomplete();
3708         }
3709
3710         /**
3711          * Test the api_friendica_group_show() function.
3712          *
3713          * @return void
3714          */
3715         public function testApiFriendicaGroupShow()
3716         {
3717                 $this->markTestIncomplete();
3718         }
3719
3720         /**
3721          * Test the api_friendica_group_delete() function.
3722          *
3723          * @return void
3724          */
3725         public function testApiFriendicaGroupDelete()
3726         {
3727                 $this->markTestIncomplete();
3728         }
3729
3730         /**
3731          * Test the api_lists_destroy() function.
3732          *
3733          * @return void
3734          */
3735         public function testApiListsDestroy()
3736         {
3737                 $this->markTestIncomplete();
3738         }
3739
3740         /**
3741          * Test the group_create() function.
3742          *
3743          * @return void
3744          */
3745         public function testGroupCreate()
3746         {
3747                 $this->markTestIncomplete();
3748         }
3749
3750         /**
3751          * Test the api_friendica_group_create() function.
3752          *
3753          * @return void
3754          */
3755         public function testApiFriendicaGroupCreate()
3756         {
3757                 $this->markTestIncomplete();
3758         }
3759
3760         /**
3761          * Test the api_lists_create() function.
3762          *
3763          * @return void
3764          */
3765         public function testApiListsCreate()
3766         {
3767                 $this->markTestIncomplete();
3768         }
3769
3770         /**
3771          * Test the api_friendica_group_update() function.
3772          *
3773          * @return void
3774          */
3775         public function testApiFriendicaGroupUpdate()
3776         {
3777                 $this->markTestIncomplete();
3778         }
3779
3780         /**
3781          * Test the api_lists_update() function.
3782          *
3783          * @return void
3784          */
3785         public function testApiListsUpdate()
3786         {
3787                 $this->markTestIncomplete();
3788         }
3789
3790         /**
3791          * Test the api_friendica_activity() function.
3792          *
3793          * @return void
3794          */
3795         public function testApiFriendicaActivity()
3796         {
3797                 $this->markTestIncomplete();
3798         }
3799
3800         /**
3801          * Test the api_friendica_notification() function.
3802          *
3803          * @return void
3804          * @expectedException Friendica\Network\HTTPException\BadRequestException
3805          */
3806         public function testApiFriendicaNotification()
3807         {
3808                 api_friendica_notification('json');
3809         }
3810
3811         /**
3812          * Test the api_friendica_notification() function without an authenticated user.
3813          *
3814          * @return void
3815          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3816          */
3817         public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3818         {
3819                 $_SESSION['authenticated'] = false;
3820                 api_friendica_notification('json');
3821         }
3822
3823         /**
3824          * Test the api_friendica_notification() function with empty result
3825          *
3826          * @return void
3827          */
3828         public function testApiFriendicaNotificationWithEmptyResult()
3829         {
3830                 $this->app->argv = ['api', 'friendica', 'notification'];
3831                 $this->app->argc = count($this->app->argv);
3832                 $_SESSION['uid'] = 41;
3833                 $result          = api_friendica_notification('json');
3834                 $this->assertEquals(['note' => false], $result);
3835         }
3836
3837         /**
3838          * Test the api_friendica_notification() function with an XML result.
3839          *
3840          * @return void
3841          */
3842         public function testApiFriendicaNotificationWithXmlResult()
3843         {
3844                 $this->app->argv = ['api', 'friendica', 'notification'];
3845                 $this->app->argc = count($this->app->argv);
3846                 $result          = api_friendica_notification('xml');
3847                 $assertXml=<<<XML
3848 <?xml version="1.0"?>
3849 <notes>
3850   <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"/>
3851 </notes>
3852 XML;
3853                 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3854         }
3855
3856         /**
3857          * Test the api_friendica_notification() function with an JSON result.
3858          *
3859          * @return void
3860          */
3861         public function testApiFriendicaNotificationWithJsonResult()
3862         {
3863                 $this->app->argv = ['api', 'friendica', 'notification'];
3864                 $this->app->argc = count($this->app->argv);
3865                 $result          = json_encode(api_friendica_notification('json'));
3866                 $this->assertJson($result);
3867         }
3868
3869         /**
3870          * Test the api_friendica_notification_seen() function.
3871          *
3872          * @return void
3873          */
3874         public function testApiFriendicaNotificationSeen()
3875         {
3876                 $this->markTestIncomplete();
3877         }
3878
3879         /**
3880          * Test the api_friendica_direct_messages_setseen() function.
3881          *
3882          * @return void
3883          */
3884         public function testApiFriendicaDirectMessagesSetseen()
3885         {
3886                 $this->markTestIncomplete();
3887         }
3888
3889         /**
3890          * Test the api_friendica_direct_messages_search() function.
3891          *
3892          * @return void
3893          */
3894         public function testApiFriendicaDirectMessagesSearch()
3895         {
3896                 $this->markTestIncomplete();
3897         }
3898
3899         /**
3900          * Test the api_friendica_profile_show() function.
3901          *
3902          * @return void
3903          */
3904         public function testApiFriendicaProfileShow()
3905         {
3906                 $result = api_friendica_profile_show('json');
3907                 // We can't use assertSelfUser() here because the user object is missing some properties.
3908                 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3909                 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3910                 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3911                 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3912                 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3913                 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3914                 $this->assertFalse($result['$result']['multi_profiles']);
3915         }
3916
3917         /**
3918          * Test the api_friendica_profile_show() function with a profile ID.
3919          *
3920          * @return void
3921          */
3922         public function testApiFriendicaProfileShowWithProfileId()
3923         {
3924                 $this->markTestIncomplete('We need to add a dataset for this.');
3925         }
3926
3927         /**
3928          * Test the api_friendica_profile_show() function with a wrong profile ID.
3929          *
3930          * @return void
3931          * @expectedException Friendica\Network\HTTPException\BadRequestException
3932          */
3933         public function testApiFriendicaProfileShowWithWrongProfileId()
3934         {
3935                 $_REQUEST['profile_id'] = 666;
3936                 api_friendica_profile_show('json');
3937         }
3938
3939         /**
3940          * Test the api_friendica_profile_show() function without an authenticated user.
3941          *
3942          * @return void
3943          * @expectedException Friendica\Network\HTTPException\ForbiddenException
3944          */
3945         public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3946         {
3947                 $_SESSION['authenticated'] = false;
3948                 api_friendica_profile_show('json');
3949         }
3950
3951         /**
3952          * Test the api_saved_searches_list() function.
3953          *
3954          * @return void
3955          */
3956         public function testApiSavedSearchesList()
3957         {
3958                 $result = api_saved_searches_list('json');
3959                 $this->assertEquals(1, $result['terms'][0]['id']);
3960                 $this->assertEquals(1, $result['terms'][0]['id_str']);
3961                 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3962                 $this->assertEquals('Saved search', $result['terms'][0]['query']);
3963         }
3964 }