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