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