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