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