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