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