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