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