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