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