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