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