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