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