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