6 namespace Friendica\Test;
9 use Friendica\Core\Config\IConfig;
10 use Friendica\Core\PConfig\IPConfig;
11 use Friendica\Core\Protocol;
13 use Friendica\Network\HTTPException;
14 use Friendica\Util\Temporal;
15 use Monolog\Handler\TestHandler;
17 require_once __DIR__ . '/../../include/api.php';
20 * Tests for the API functions.
22 * Functions that use header() need to be tested in a separate process.
23 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
25 class ApiTest extends FixtureTest
28 * @var TestHandler Can handle log-outputs
35 protected $friendUser;
39 protected $wrongUserId;
48 * Create variables used by tests.
50 protected function setUp()
54 /** @var IConfig $config */
55 $this->config = $this->dice->create(IConfig::class);
57 $this->config->set('system', 'url', 'http://localhost');
58 $this->config->set('system', 'hostname', 'localhost');
59 $this->config->set('system', 'worker_dont_fork', true);
62 $this->config->set('config', 'hostname', 'localhost');
63 $this->config->set('system', 'throttle_limit_day', 100);
64 $this->config->set('system', 'throttle_limit_week', 100);
65 $this->config->set('system', 'throttle_limit_month', 100);
66 $this->config->set('system', 'theme', 'system_theme');
70 $this->app = DI::app();
73 $this->app->argv = ['home'];
75 // User data that the test database is populated with
78 'name' => 'Self contact',
79 'nick' => 'selfcontact',
80 'nurl' => 'http://localhost/profile/selfcontact'
84 'name' => 'Friend contact',
85 'nick' => 'friendcontact',
86 'nurl' => 'http://localhost/profile/friendcontact'
90 'name' => 'othercontact',
91 'nick' => 'othercontact',
92 'nurl' => 'http://localhost/profile/othercontact'
95 // User ID that we know is not in the database
96 $this->wrongUserId = 666;
98 DI::session()->start();
100 // Most API require login so we force the session
103 'authenticated' => true,
104 'uid' => $this->selfUser['id']
113 * Assert that an user array contains expected keys.
115 * @param array $user User array
119 private function assertSelfUser(array $user)
121 $this->assertEquals($this->selfUser['id'], $user['uid']);
122 $this->assertEquals($this->selfUser['id'], $user['cid']);
123 $this->assertEquals(1, $user['self']);
124 $this->assertEquals('DFRN', $user['location']);
125 $this->assertEquals($this->selfUser['name'], $user['name']);
126 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
127 $this->assertEquals('dfrn', $user['network']);
128 $this->assertTrue($user['verified']);
132 * Assert that an user array contains expected keys.
134 * @param array $user User array
138 private function assertOtherUser(array $user)
140 $this->assertEquals($this->otherUser['id'], $user['id']);
141 $this->assertEquals($this->otherUser['id'], $user['id_str']);
142 $this->assertEquals(0, $user['self']);
143 $this->assertEquals($this->otherUser['name'], $user['name']);
144 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
145 $this->assertFalse($user['verified']);
149 * Assert that a status array contains expected keys.
151 * @param array $status Status array
155 private function assertStatus(array $status)
157 $this->assertInternalType('string', $status['text']);
158 $this->assertInternalType('int', $status['id']);
159 // We could probably do more checks here.
163 * Assert that a list array contains expected keys.
165 * @param array $list List array
169 private function assertList(array $list)
171 $this->assertInternalType('string', $list['name']);
172 $this->assertInternalType('int', $list['id']);
173 $this->assertInternalType('string', $list['id_str']);
174 $this->assertContains($list['mode'], ['public', 'private']);
175 // We could probably do more checks here.
179 * Assert that the string is XML and contain the root element.
181 * @param string $result XML string
182 * @param string $root_element Root element name
186 private function assertXml($result, $root_element)
188 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
189 $this->assertContains('<' . $root_element, $result);
190 // We could probably do more checks here.
194 * Get the path to a temporary empty PNG image.
196 * @return string Path
198 private function getTempImage()
200 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
204 // Empty 1x1 px PNG image
205 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
213 * Test the api_user() function.
217 public function testApiUser()
219 $this->assertEquals($this->selfUser['id'], api_user());
223 * Test the api_user() function with an unallowed user.
227 public function testApiUserWithUnallowedUser()
229 $_SESSION = ['allow_api' => false];
230 $this->assertEquals(false, api_user());
234 * Test the api_source() function.
238 public function testApiSource()
240 $this->assertEquals('api', api_source());
244 * Test the api_source() function with a Twidere user agent.
248 public function testApiSourceWithTwidere()
250 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
251 $this->assertEquals('Twidere', api_source());
255 * Test the api_source() function with a GET parameter.
259 public function testApiSourceWithGet()
261 $_GET['source'] = 'source_name';
262 $this->assertEquals('source_name', api_source());
266 * Test the api_date() function.
270 public function testApiDate()
272 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
276 * Test the api_register_func() function.
280 public function testApiRegisterFunc()
292 $this->assertTrue($API['api_path']['auth']);
293 $this->assertEquals('method', $API['api_path']['method']);
294 $this->assertTrue(is_callable($API['api_path']['func']));
298 * Test the api_login() function without any login.
301 * @runInSeparateProcess
302 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
304 public function testApiLoginWithoutLogin()
306 api_login($this->app);
310 * Test the api_login() function with a bad login.
313 * @runInSeparateProcess
314 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
316 public function testApiLoginWithBadLogin()
318 $_SERVER['PHP_AUTH_USER'] = 'user@server';
319 api_login($this->app);
323 * Test the api_login() function with oAuth.
327 public function testApiLoginWithOauth()
329 $this->markTestIncomplete('Can we test this easily?');
333 * Test the api_login() function with authentication provided by an addon.
337 public function testApiLoginWithAddonAuth()
339 $this->markTestIncomplete('Can we test this easily?');
343 * Test the api_login() function with a correct login.
346 * @runInSeparateProcess
348 public function testApiLoginWithCorrectLogin()
350 $_SERVER['PHP_AUTH_USER'] = 'Test user';
351 $_SERVER['PHP_AUTH_PW'] = 'password';
352 api_login($this->app);
356 * Test the api_login() function with a remote user.
359 * @runInSeparateProcess
360 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
362 public function testApiLoginWithRemoteUser()
364 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
365 api_login($this->app);
369 * Test the api_check_method() function.
373 public function testApiCheckMethod()
375 $this->assertFalse(api_check_method('method'));
379 * Test the api_check_method() function with a correct method.
383 public function testApiCheckMethodWithCorrectMethod()
385 $_SERVER['REQUEST_METHOD'] = 'method';
386 $this->assertTrue(api_check_method('method'));
390 * Test the api_check_method() function with a wildcard.
394 public function testApiCheckMethodWithWildcard()
396 $this->assertTrue(api_check_method('*'));
400 * Test the api_call() function.
403 * @runInSeparateProcess
405 public function testApiCall()
409 'method' => 'method',
410 'func' => function () {
411 return ['data' => ['some_data']];
414 $_SERVER['REQUEST_METHOD'] = 'method';
415 $_SERVER['QUERY_STRING'] = 'q=api_path';
416 $_GET['callback'] = 'callback_name';
418 $args = DI::args()->determine($_SERVER, $_GET);
421 'callback_name(["some_data"])',
422 api_call($this->app, $args)
427 * Test the api_call() function with the profiled enabled.
430 * @runInSeparateProcess
432 public function testApiCallWithProfiler()
436 'method' => 'method',
437 'func' => function () {
438 return ['data' => ['some_data']];
442 $_SERVER['REQUEST_METHOD'] = 'method';
443 $_SERVER['QUERY_STRING'] = 'q=api_path';
445 $args = DI::args()->determine($_SERVER, $_GET);
447 $this->config->set('system', 'profiler', true);
448 $this->config->set('rendertime', 'callstack', true);
449 $this->app->callstack = [
450 'database' => ['some_function' => 200],
451 'database_write' => ['some_function' => 200],
452 'cache' => ['some_function' => 200],
453 'cache_write' => ['some_function' => 200],
454 'network' => ['some_function' => 200]
459 api_call($this->app, $args)
464 * Test the api_call() function without any result.
467 * @runInSeparateProcess
469 public function testApiCallWithNoResult()
473 'method' => 'method',
474 'func' => function () {
478 $_SERVER['REQUEST_METHOD'] = 'method';
479 $_SERVER['QUERY_STRING'] = 'q=api_path';
481 $args = DI::args()->determine($_SERVER, $_GET);
484 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
485 api_call($this->app, $args)
490 * Test the api_call() function with an unimplemented API.
493 * @runInSeparateProcess
495 public function testApiCallWithUninplementedApi()
498 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
504 * Test the api_call() function with a JSON result.
507 * @runInSeparateProcess
509 public function testApiCallWithJson()
513 'method' => 'method',
514 'func' => function () {
515 return ['data' => ['some_data']];
518 $_SERVER['REQUEST_METHOD'] = 'method';
519 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
521 $args = DI::args()->determine($_SERVER, $_GET);
525 api_call($this->app, $args)
530 * Test the api_call() function with an XML result.
533 * @runInSeparateProcess
535 public function testApiCallWithXml()
539 'method' => 'method',
540 'func' => function () {
544 $_SERVER['REQUEST_METHOD'] = 'method';
545 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
547 $args = DI::args()->determine($_SERVER, $_GET);
551 api_call($this->app, $args)
556 * Test the api_call() function with an RSS result.
559 * @runInSeparateProcess
561 public function testApiCallWithRss()
565 'method' => 'method',
566 'func' => function () {
570 $_SERVER['REQUEST_METHOD'] = 'method';
571 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
573 $args = DI::args()->determine($_SERVER, $_GET);
576 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
578 api_call($this->app, $args)
583 * Test the api_call() function with an Atom result.
586 * @runInSeparateProcess
588 public function testApiCallWithAtom()
592 'method' => 'method',
593 'func' => function () {
597 $_SERVER['REQUEST_METHOD'] = 'method';
598 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
600 $args = DI::args()->determine($_SERVER, $_GET);
603 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
605 api_call($this->app, $args)
610 * Test the api_call() function with an unallowed method.
613 * @runInSeparateProcess
615 public function testApiCallWithWrongMethod()
618 $API['api_path'] = ['method' => 'method'];
620 $_SERVER['QUERY_STRING'] = 'q=api_path';
622 $args = DI::args()->determine($_SERVER, $_GET);
625 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
626 api_call($this->app, $args)
631 * Test the api_call() function with an unauthorized user.
634 * @runInSeparateProcess
636 public function testApiCallWithWrongAuth()
640 'method' => 'method',
643 $_SESSION['authenticated'] = false;
644 $_SERVER['REQUEST_METHOD'] = 'method';
645 $_SERVER['QUERY_STRING'] = 'q=api_path';
647 $args = DI::args()->determine($_SERVER, $_GET);
650 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
651 api_call($this->app, $args)
656 * Test the api_error() function with a JSON result.
659 * @runInSeparateProcess
661 public function testApiErrorWithJson()
664 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
665 api_error('json', new HTTPException\OKException('error_message'), DI::args())
670 * Test the api_error() function with an XML result.
673 * @runInSeparateProcess
675 public function testApiErrorWithXml()
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" .
686 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
691 * Test the api_error() function with an RSS result.
694 * @runInSeparateProcess
696 public function testApiErrorWithRss()
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" .
707 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
712 * Test the api_error() function with an Atom result.
715 * @runInSeparateProcess
717 public function testApiErrorWithAtom()
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" .
728 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
733 * Test the api_rss_extra() function.
737 public function testApiRssExtra()
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']);
752 * Test the api_rss_extra() function without any user info.
756 public function testApiRssExtraWithoutUserInfo()
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']);
770 * Test the api_unique_id_to_nurl() function.
774 public function testApiUniqueIdToNurl()
776 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
780 * Test the api_unique_id_to_nurl() function with a correct ID.
784 public function testApiUniqueIdToNurlWithCorrectId()
786 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
790 * Test the api_get_user() function.
794 public function testApiGetUser()
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']);
804 * Test the api_get_user() function with a Frio schema.
808 public function testApiGetUserWithFrioSchema()
810 $pConfig = $this->dice->create(IPConfig::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']);
820 * Test the api_get_user() function with an empty Frio schema.
824 public function testApiGetUserWithEmptyFrioSchema()
826 $pConfig = $this->dice->create(IPConfig::class);
827 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
828 $user = api_get_user($this->app);
829 $this->assertSelfUser($user);
830 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
831 $this->assertEquals('6fdbe8', $user['profile_link_color']);
832 $this->assertEquals('ededed', $user['profile_background_color']);
836 * Test the api_get_user() function with a custom Frio schema.
840 public function testApiGetUserWithCustomFrioSchema()
842 $pConfig = $this->dice->create(IPConfig::class);
843 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
844 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
845 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
846 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
847 $user = api_get_user($this->app);
848 $this->assertSelfUser($user);
849 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
850 $this->assertEquals('123456', $user['profile_link_color']);
851 $this->assertEquals('123456', $user['profile_background_color']);
855 * Test the api_get_user() function with an user that is not allowed to use the API.
858 * @runInSeparateProcess
860 public function testApiGetUserWithoutApiUser()
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));
869 * Test the api_get_user() function with an user ID in a GET parameter.
873 public function testApiGetUserWithGetId()
875 $_GET['user_id'] = $this->otherUser['id'];
876 $this->assertOtherUser(api_get_user($this->app));
880 * Test the api_get_user() function with a wrong user ID in a GET parameter.
883 * @expectedException Friendica\Network\HTTPException\BadRequestException
885 public function testApiGetUserWithWrongGetId()
887 $_GET['user_id'] = $this->wrongUserId;
888 $this->assertOtherUser(api_get_user($this->app));
892 * Test the api_get_user() function with an user name in a GET parameter.
896 public function testApiGetUserWithGetName()
898 $_GET['screen_name'] = $this->selfUser['nick'];
899 $this->assertSelfUser(api_get_user($this->app));
903 * Test the api_get_user() function with a profile URL in a GET parameter.
907 public function testApiGetUserWithGetUrl()
909 $_GET['profileurl'] = $this->selfUser['nurl'];
910 $this->assertSelfUser(api_get_user($this->app));
914 * Test the api_get_user() function with an user ID in the API path.
918 public function testApiGetUserWithNumericCalledApi()
921 $called_api = ['api_path'];
922 $this->app->argv[1] = $this->otherUser['id'] . '.json';
923 $this->assertOtherUser(api_get_user($this->app));
927 * Test the api_get_user() function with the $called_api global variable.
931 public function testApiGetUserWithCalledApi()
934 $called_api = ['api', 'api_path'];
935 $this->assertSelfUser(api_get_user($this->app));
939 * Test the api_get_user() function with a valid user.
943 public function testApiGetUserWithCorrectUser()
945 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
949 * Test the api_get_user() function with a wrong user ID.
952 * @expectedException Friendica\Network\HTTPException\BadRequestException
954 public function testApiGetUserWithWrongUser()
956 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
960 * Test the api_get_user() function with a 0 user ID.
964 public function testApiGetUserWithZeroUser()
966 $this->assertSelfUser(api_get_user($this->app, 0));
970 * Test the api_item_get_user() function.
974 public function testApiItemGetUser()
976 $users = api_item_get_user($this->app, []);
977 $this->assertSelfUser($users[0]);
981 * Test the api_item_get_user() function with a different item parent.
985 public function testApiItemGetUserWithDifferentParent()
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]);
993 * Test the api_walk_recursive() function.
997 public function testApiWalkRecursive()
1000 $this->assertEquals(
1005 // Should we test this with a callback that actually does something?
1013 * Test the api_walk_recursive() function with an array.
1017 public function testApiWalkRecursiveWithArray()
1019 $array = [['item1'], ['item2']];
1020 $this->assertEquals(
1025 // Should we test this with a callback that actually does something?
1033 * Test the api_reformat_xml() function.
1037 public function testApiReformatXml()
1041 $this->assertTrue(api_reformat_xml($item, $key));
1042 $this->assertEquals('true', $item);
1046 * Test the api_reformat_xml() function with a statusnet_api key.
1050 public function testApiReformatXmlWithStatusnetKey()
1053 $key = 'statusnet_api';
1054 $this->assertTrue(api_reformat_xml($item, $key));
1055 $this->assertEquals('statusnet:api', $key);
1059 * Test the api_reformat_xml() function with a friendica_api key.
1063 public function testApiReformatXmlWithFriendicaKey()
1066 $key = 'friendica_api';
1067 $this->assertTrue(api_reformat_xml($item, $key));
1068 $this->assertEquals('friendica:api', $key);
1072 * Test the api_create_xml() function.
1076 public function testApiCreateXml()
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')
1090 * Test the api_create_xml() function without any XML namespace.
1094 public function testApiCreateXmlWithoutNamespaces()
1096 $this->assertEquals(
1097 '<?xml version="1.0"?>' . "\n" .
1099 ' <data>some_data</data>' . "\n" .
1101 api_create_xml(['data' => ['some_data']], 'ok')
1106 * Test the api_format_data() function.
1110 public function testApiFormatData()
1112 $data = ['some_data'];
1113 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1117 * Test the api_format_data() function with an XML result.
1121 public function testApiFormatDataWithXml()
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']])
1135 * Test the api_account_verify_credentials() function.
1139 public function testApiAccountVerifyCredentials()
1141 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1145 * Test the api_account_verify_credentials() function without an authenticated user.
1148 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1150 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1152 $_SESSION['authenticated'] = false;
1153 api_account_verify_credentials('json');
1157 * Test the requestdata() function.
1161 public function testRequestdata()
1163 $this->assertNull(requestdata('variable_name'));
1167 * Test the requestdata() function with a POST parameter.
1171 public function testRequestdataWithPost()
1173 $_POST['variable_name'] = 'variable_value';
1174 $this->assertEquals('variable_value', requestdata('variable_name'));
1178 * Test the requestdata() function with a GET parameter.
1182 public function testRequestdataWithGet()
1184 $_GET['variable_name'] = 'variable_value';
1185 $this->assertEquals('variable_value', requestdata('variable_name'));
1189 * Test the api_statuses_mediap() function.
1193 public function testApiStatusesMediap()
1195 $this->app->argc = 2;
1203 'tmp_name' => $this->getTempImage(),
1204 'name' => 'spacer.png',
1205 'type' => 'image/png'
1208 $_GET['status'] = '<b>Status content</b>';
1210 $result = api_statuses_mediap('json');
1211 $this->assertStatus($result['status']);
1215 * Test the api_statuses_mediap() function without an authenticated user.
1218 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1220 public function testApiStatusesMediapWithoutAuthenticatedUser()
1222 $_SESSION['authenticated'] = false;
1223 api_statuses_mediap('json');
1227 * Test the api_statuses_update() function.
1231 public function testApiStatusesUpdate()
1233 $_GET['status'] = 'Status content #friendica';
1234 $_GET['in_reply_to_status_id'] = -1;
1243 'tmp_name' => $this->getTempImage(),
1244 'name' => 'spacer.png',
1245 'type' => 'image/png'
1249 $result = api_statuses_update('json');
1250 $this->assertStatus($result['status']);
1254 * Test the api_statuses_update() function with an HTML status.
1258 public function testApiStatusesUpdateWithHtml()
1260 $_GET['htmlstatus'] = '<b>Status content</b>';
1262 $result = api_statuses_update('json');
1263 $this->assertStatus($result['status']);
1267 * Test the api_statuses_update() function without an authenticated user.
1270 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1272 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1274 $_SESSION['authenticated'] = false;
1275 api_statuses_update('json');
1279 * Test the api_statuses_update() function with a parent status.
1283 public function testApiStatusesUpdateWithParent()
1285 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1289 * Test the api_statuses_update() function with a media_ids parameter.
1293 public function testApiStatusesUpdateWithMediaIds()
1295 $this->markTestIncomplete();
1299 * Test the api_statuses_update() function with the throttle limit reached.
1303 public function testApiStatusesUpdateWithDayThrottleReached()
1305 $this->markTestIncomplete();
1309 * Test the api_media_upload() function.
1312 * @expectedException Friendica\Network\HTTPException\BadRequestException
1314 public function testApiMediaUpload()
1320 * Test the api_media_upload() function without an authenticated user.
1323 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1325 public function testApiMediaUploadWithoutAuthenticatedUser()
1327 $_SESSION['authenticated'] = false;
1332 * Test the api_media_upload() function with an invalid uploaded media.
1335 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1337 public function testApiMediaUploadWithMedia()
1342 'tmp_name' => 'tmp_name'
1349 * Test the api_media_upload() function with an valid uploaded media.
1353 public function testApiMediaUploadWithValidMedia()
1361 'tmp_name' => $this->getTempImage(),
1362 'name' => 'spacer.png',
1363 'type' => 'image/png'
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']);
1377 * Test the api_status_show() function.
1379 public function testApiStatusShowWithJson()
1381 $result = api_status_show('json', 1);
1382 $this->assertStatus($result['status']);
1386 * Test the api_status_show() function with an XML result.
1388 public function testApiStatusShowWithXml()
1390 $result = api_status_show('xml', 1);
1391 $this->assertXml($result, 'statuses');
1395 * Test the api_get_last_status() function
1397 public function testApiGetLastStatus()
1399 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1401 $this->assertNotNull($item);
1405 * Test the api_users_show() function.
1409 public function testApiUsersShow()
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']);
1422 * Test the api_users_show() function with an XML result.
1426 public function testApiUsersShowWithXml()
1428 $result = api_users_show('xml');
1429 $this->assertXml($result, 'statuses');
1433 * Test the api_users_search() function.
1437 public function testApiUsersSearch()
1439 $_GET['q'] = 'othercontact';
1440 $result = api_users_search('json');
1441 $this->assertOtherUser($result['users'][0]);
1445 * Test the api_users_search() function with an XML result.
1449 public function testApiUsersSearchWithXml()
1451 $_GET['q'] = 'othercontact';
1452 $result = api_users_search('xml');
1453 $this->assertXml($result, 'users');
1457 * Test the api_users_search() function without a GET q parameter.
1460 * @expectedException Friendica\Network\HTTPException\BadRequestException
1462 public function testApiUsersSearchWithoutQuery()
1464 api_users_search('json');
1468 * Test the api_users_lookup() function.
1471 * @expectedException Friendica\Network\HTTPException\NotFoundException
1473 public function testApiUsersLookup()
1475 api_users_lookup('json');
1479 * Test the api_users_lookup() function with an user ID.
1483 public function testApiUsersLookupWithUserId()
1485 $_REQUEST['user_id'] = $this->otherUser['id'];
1486 $result = api_users_lookup('json');
1487 $this->assertOtherUser($result['users'][0]);
1491 * Test the api_search() function.
1495 public function testApiSearch()
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);
1507 * Test the api_search() function a count parameter.
1511 public function testApiSearchWithCount()
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);
1523 * Test the api_search() function with an rpp parameter.
1527 public function testApiSearchWithRpp()
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);
1539 * Test the api_search() function with an q parameter contains hashtag.
1543 public function testApiSearchWithHashtag()
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);
1554 * Test the api_search() function with an exclude_replies parameter.
1558 public function testApiSearchWithExcludeReplies()
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);
1570 * Test the api_search() function without an authenticated user.
1573 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1575 public function testApiSearchWithUnallowedUser()
1577 $_SESSION['allow_api'] = false;
1578 $_GET['screen_name'] = $this->selfUser['nick'];
1583 * Test the api_search() function without any GET query parameter.
1586 * @expectedException Friendica\Network\HTTPException\BadRequestException
1588 public function testApiSearchWithoutQuery()
1594 * Test the api_statuses_home_timeline() function.
1598 public function testApiStatusesHomeTimeline()
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);
1611 * Test the api_statuses_home_timeline() function with a negative page parameter.
1615 public function testApiStatusesHomeTimelineWithNegativePage()
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);
1626 * Test the api_statuses_home_timeline() with an unallowed user.
1629 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1631 public function testApiStatusesHomeTimelineWithUnallowedUser()
1633 $_SESSION['allow_api'] = false;
1634 $_GET['screen_name'] = $this->selfUser['nick'];
1635 api_statuses_home_timeline('json');
1639 * Test the api_statuses_home_timeline() function with an RSS result.
1643 public function testApiStatusesHomeTimelineWithRss()
1645 $result = api_statuses_home_timeline('rss');
1646 $this->assertXml($result, 'statuses');
1650 * Test the api_statuses_public_timeline() function.
1654 public function testApiStatusesPublicTimeline()
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);
1666 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1670 public function testApiStatusesPublicTimelineWithExcludeReplies()
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);
1682 * Test the api_statuses_public_timeline() function with a negative page parameter.
1686 public function testApiStatusesPublicTimelineWithNegativePage()
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);
1697 * Test the api_statuses_public_timeline() function with an unallowed user.
1700 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1702 public function testApiStatusesPublicTimelineWithUnallowedUser()
1704 $_SESSION['allow_api'] = false;
1705 $_GET['screen_name'] = $this->selfUser['nick'];
1706 api_statuses_public_timeline('json');
1710 * Test the api_statuses_public_timeline() function with an RSS result.
1714 public function testApiStatusesPublicTimelineWithRss()
1716 $result = api_statuses_public_timeline('rss');
1717 $this->assertXml($result, 'statuses');
1721 * Test the api_statuses_networkpublic_timeline() function.
1725 public function testApiStatusesNetworkpublicTimeline()
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);
1736 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1740 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
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);
1751 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1754 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1756 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1758 $_SESSION['allow_api'] = false;
1759 $_GET['screen_name'] = $this->selfUser['nick'];
1760 api_statuses_networkpublic_timeline('json');
1764 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1768 public function testApiStatusesNetworkpublicTimelineWithRss()
1770 $result = api_statuses_networkpublic_timeline('rss');
1771 $this->assertXml($result, 'statuses');
1775 * Test the api_statuses_show() function.
1778 * @expectedException Friendica\Network\HTTPException\BadRequestException
1780 public function testApiStatusesShow()
1782 api_statuses_show('json');
1786 * Test the api_statuses_show() function with an ID.
1790 public function testApiStatusesShowWithId()
1792 $this->app->argv[3] = 1;
1793 $result = api_statuses_show('json');
1794 $this->assertStatus($result['status']);
1798 * Test the api_statuses_show() function with the conversation parameter.
1802 public function testApiStatusesShowWithConversation()
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);
1814 * Test the api_statuses_show() function with an unallowed user.
1817 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1819 public function testApiStatusesShowWithUnallowedUser()
1821 $_SESSION['allow_api'] = false;
1822 $_GET['screen_name'] = $this->selfUser['nick'];
1823 api_statuses_show('json');
1827 * Test the api_conversation_show() function.
1830 * @expectedException Friendica\Network\HTTPException\BadRequestException
1832 public function testApiConversationShow()
1834 api_conversation_show('json');
1838 * Test the api_conversation_show() function with an ID.
1842 public function testApiConversationShowWithId()
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);
1855 * Test the api_conversation_show() function with an unallowed user.
1858 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1860 public function testApiConversationShowWithUnallowedUser()
1862 $_SESSION['allow_api'] = false;
1863 $_GET['screen_name'] = $this->selfUser['nick'];
1864 api_conversation_show('json');
1868 * Test the api_statuses_repeat() function.
1871 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1873 public function testApiStatusesRepeat()
1875 api_statuses_repeat('json');
1879 * Test the api_statuses_repeat() function without an authenticated user.
1882 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1884 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1886 $_SESSION['authenticated'] = false;
1887 api_statuses_repeat('json');
1891 * Test the api_statuses_repeat() function with an ID.
1895 public function testApiStatusesRepeatWithId()
1897 $this->app->argv[3] = 1;
1898 $result = api_statuses_repeat('json');
1899 $this->assertStatus($result['status']);
1901 // Also test with a shared status
1902 $this->app->argv[3] = 5;
1903 $result = api_statuses_repeat('json');
1904 $this->assertStatus($result['status']);
1908 * Test the api_statuses_destroy() function.
1911 * @expectedException Friendica\Network\HTTPException\BadRequestException
1913 public function testApiStatusesDestroy()
1915 api_statuses_destroy('json');
1919 * Test the api_statuses_destroy() function without an authenticated user.
1922 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1924 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1926 $_SESSION['authenticated'] = false;
1927 api_statuses_destroy('json');
1931 * Test the api_statuses_destroy() function with an ID.
1935 public function testApiStatusesDestroyWithId()
1937 $this->app->argv[3] = 1;
1938 $result = api_statuses_destroy('json');
1939 $this->assertStatus($result['status']);
1943 * Test the api_statuses_mentions() function.
1947 public function testApiStatusesMentions()
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.
1957 * Test the api_statuses_mentions() function with a negative page parameter.
1961 public function testApiStatusesMentionsWithNegativePage()
1963 $_REQUEST['page'] = -2;
1964 $result = api_statuses_mentions('json');
1965 $this->assertEmpty($result['status']);
1969 * Test the api_statuses_mentions() function with an unallowed user.
1972 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1974 public function testApiStatusesMentionsWithUnallowedUser()
1976 $_SESSION['allow_api'] = false;
1977 $_GET['screen_name'] = $this->selfUser['nick'];
1978 api_statuses_mentions('json');
1982 * Test the api_statuses_mentions() function with an RSS result.
1986 public function testApiStatusesMentionsWithRss()
1988 $result = api_statuses_mentions('rss');
1989 $this->assertXml($result, 'statuses');
1993 * Test the api_statuses_user_timeline() function.
1997 public function testApiStatusesUserTimeline()
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);
2010 * Test the api_statuses_user_timeline() function with a negative page parameter.
2014 public function testApiStatusesUserTimelineWithNegativePage()
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);
2025 * Test the api_statuses_user_timeline() function with an RSS result.
2029 public function testApiStatusesUserTimelineWithRss()
2031 $result = api_statuses_user_timeline('rss');
2032 $this->assertXml($result, 'statuses');
2036 * Test the api_statuses_user_timeline() function with an unallowed user.
2039 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2041 public function testApiStatusesUserTimelineWithUnallowedUser()
2043 $_SESSION['allow_api'] = false;
2044 $_GET['screen_name'] = $this->selfUser['nick'];
2045 api_statuses_user_timeline('json');
2049 * Test the api_favorites_create_destroy() function.
2052 * @expectedException Friendica\Network\HTTPException\BadRequestException
2054 public function testApiFavoritesCreateDestroy()
2056 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2057 $this->app->argc = count($this->app->argv);
2058 api_favorites_create_destroy('json');
2062 * Test the api_favorites_create_destroy() function with an invalid ID.
2065 * @expectedException Friendica\Network\HTTPException\BadRequestException
2067 public function testApiFavoritesCreateDestroyWithInvalidId()
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');
2075 * Test the api_favorites_create_destroy() function with an invalid action.
2078 * @expectedException Friendica\Network\HTTPException\BadRequestException
2080 public function testApiFavoritesCreateDestroyWithInvalidAction()
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');
2089 * Test the api_favorites_create_destroy() function with the create action.
2093 public function testApiFavoritesCreateDestroyWithCreateAction()
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']);
2103 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2107 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
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');
2117 * Test the api_favorites_create_destroy() function with the destroy action.
2121 public function testApiFavoritesCreateDestroyWithDestroyAction()
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']);
2131 * Test the api_favorites_create_destroy() function without an authenticated user.
2134 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2136 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
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');
2145 * Test the api_favorites() function.
2149 public function testApiFavorites()
2151 $_REQUEST['page'] = -1;
2152 $_REQUEST['max_id'] = 10;
2153 $result = api_favorites('json');
2154 foreach ($result['status'] as $status) {
2155 $this->assertStatus($status);
2160 * Test the api_favorites() function with an RSS result.
2164 public function testApiFavoritesWithRss()
2166 $result = api_favorites('rss');
2167 $this->assertXml($result, 'statuses');
2171 * Test the api_favorites() function with an unallowed user.
2174 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2176 public function testApiFavoritesWithUnallowedUser()
2178 $_SESSION['allow_api'] = false;
2179 $_GET['screen_name'] = $this->selfUser['nick'];
2180 api_favorites('json');
2184 * Test the api_format_messages() function.
2188 public function testApiFormatMessages()
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']
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']);
2204 * Test the api_format_messages() function with HTML.
2208 public function testApiFormatMessagesWithHtmlText()
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']
2216 $this->assertEquals('item_title', $result['title']);
2217 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2221 * Test the api_format_messages() function with plain text.
2225 public function testApiFormatMessagesWithPlainText()
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']
2233 $this->assertEquals('item_title', $result['title']);
2234 $this->assertEquals('item_body', $result['text']);
2238 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2242 public function testApiFormatMessagesWithoutUserObjects()
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']
2250 $this->assertTrue(!isset($result['sender']));
2251 $this->assertTrue(!isset($result['recipient']));
2255 * Test the api_convert_item() function.
2259 public function testApiConvertItem()
2261 $result = api_convert_item(
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'
2292 $this->assertStringStartsWith('item_title', $result['text']);
2293 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2297 * Test the api_convert_item() function with an empty item body.
2301 public function testApiConvertItemWithoutBody()
2303 $result = api_convert_item(
2305 'network' => 'feed',
2306 'title' => 'item_title',
2308 'plink' => 'item_plink'
2311 $this->assertEquals('item_title', $result['text']);
2312 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2316 * Test the api_convert_item() function with the title in the body.
2320 public function testApiConvertItemWithTitleInBody()
2322 $result = api_convert_item(
2324 'title' => 'item_title',
2325 'body' => 'item_title item_body'
2328 $this->assertEquals('item_title item_body', $result['text']);
2329 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2333 * Test the api_get_attachments() function.
2337 public function testApiGetAttachments()
2340 $this->assertEmpty(api_get_attachments($body));
2344 * Test the api_get_attachments() function with an img tag.
2348 public function testApiGetAttachmentsWithImage()
2350 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2351 $this->assertInternalType('array', api_get_attachments($body));
2355 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2359 public function testApiGetAttachmentsWithImageAndAndStatus()
2361 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2362 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2363 $this->assertInternalType('array', api_get_attachments($body));
2367 * Test the api_get_entitities() function.
2371 public function testApiGetEntitities()
2374 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2378 * Test the api_get_entitities() function with the include_entities parameter.
2382 public function testApiGetEntititiesWithIncludeEntities()
2384 $_REQUEST['include_entities'] = 'true';
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']);
2394 * Test the api_format_items_embeded_images() function.
2398 public function testApiFormatItemsEmbededImages()
2400 $this->assertEquals(
2401 'text ' . DI::baseUrl() . '/display/item_guid',
2402 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2407 * Test the api_contactlink_to_array() function.
2411 public function testApiContactlinkToArray()
2413 $this->assertEquals(
2418 api_contactlink_to_array('text')
2423 * Test the api_contactlink_to_array() function with an URL.
2427 public function testApiContactlinkToArrayWithUrl()
2429 $this->assertEquals(
2431 'name' => ['link_text'],
2434 api_contactlink_to_array('text <a href="url">link_text</a>')
2439 * Test the api_format_items_activities() function.
2443 public function testApiFormatItemsActivities()
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);
2455 * Test the api_format_items_activities() function with an XML result.
2459 public function testApiFormatItemsActivitiesWithXml()
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);
2471 * Test the api_format_items() function.
2475 public function testApiFormatItems()
2479 'item_network' => 'item_network',
2485 'author-network' => Protocol::DFRN,
2486 'author-link' => 'http://localhost/profile/othercontact',
2490 $result = api_format_items($items, ['id' => 0], true);
2491 foreach ($result as $status) {
2492 $this->assertStatus($status);
2497 * Test the api_format_items() function with an XML result.
2501 public function testApiFormatItemsWithXml()
2509 'author-network' => Protocol::DFRN,
2510 'author-link' => 'http://localhost/profile/othercontact',
2514 $result = api_format_items($items, ['id' => 0], true, 'xml');
2515 foreach ($result as $status) {
2516 $this->assertStatus($status);
2521 * Test the api_format_items() function.
2525 public function testApiAccountRateLimitStatus()
2527 $result = api_account_rate_limit_status('json');
2528 $this->assertEquals(150, $result['hash']['remaining_hits']);
2529 $this->assertEquals(150, $result['hash']['hourly_limit']);
2530 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2534 * Test the api_format_items() function with an XML result.
2538 public function testApiAccountRateLimitStatusWithXml()
2540 $result = api_account_rate_limit_status('xml');
2541 $this->assertXml($result, 'hash');
2545 * Test the api_help_test() function.
2549 public function testApiHelpTest()
2551 $result = api_help_test('json');
2552 $this->assertEquals(['ok' => 'ok'], $result);
2556 * Test the api_help_test() function with an XML result.
2560 public function testApiHelpTestWithXml()
2562 $result = api_help_test('xml');
2563 $this->assertXml($result, 'ok');
2567 * Test the api_lists_list() function.
2571 public function testApiListsList()
2573 $result = api_lists_list('json');
2574 $this->assertEquals(['lists_list' => []], $result);
2578 * Test the api_lists_ownerships() function.
2582 public function testApiListsOwnerships()
2584 $result = api_lists_ownerships('json');
2585 foreach ($result['lists']['lists'] as $list) {
2586 $this->assertList($list);
2591 * Test the api_lists_ownerships() function without an authenticated user.
2594 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2596 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2598 $_SESSION['authenticated'] = false;
2599 api_lists_ownerships('json');
2603 * Test the api_lists_statuses() function.
2605 * @expectedException Friendica\Network\HTTPException\BadRequestException
2608 public function testApiListsStatuses()
2610 api_lists_statuses('json');
2614 * Test the api_lists_statuses() function with a list ID.
2618 public function testApiListsStatusesWithListId()
2620 $_REQUEST['list_id'] = 1;
2621 $_REQUEST['page'] = -1;
2622 $_REQUEST['max_id'] = 10;
2623 $result = api_lists_statuses('json');
2624 foreach ($result['status'] as $status) {
2625 $this->assertStatus($status);
2630 * Test the api_lists_statuses() function with a list ID and a RSS result.
2634 public function testApiListsStatusesWithListIdAndRss()
2636 $_REQUEST['list_id'] = 1;
2637 $result = api_lists_statuses('rss');
2638 $this->assertXml($result, 'statuses');
2642 * Test the api_lists_statuses() function with an unallowed user.
2645 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2647 public function testApiListsStatusesWithUnallowedUser()
2649 $_SESSION['allow_api'] = false;
2650 $_GET['screen_name'] = $this->selfUser['nick'];
2651 api_lists_statuses('json');
2655 * Test the api_statuses_f() function.
2659 public function testApiStatusesFWithFriends()
2662 $result = api_statuses_f('friends');
2663 $this->assertArrayHasKey('user', $result);
2667 * Test the api_statuses_f() function.
2671 public function testApiStatusesFWithFollowers()
2673 $result = api_statuses_f('followers');
2674 $this->assertArrayHasKey('user', $result);
2678 * Test the api_statuses_f() function.
2682 public function testApiStatusesFWithBlocks()
2684 $result = api_statuses_f('blocks');
2685 $this->assertArrayHasKey('user', $result);
2689 * Test the api_statuses_f() function.
2693 public function testApiStatusesFWithIncoming()
2695 $result = api_statuses_f('incoming');
2696 $this->assertArrayHasKey('user', $result);
2700 * Test the api_statuses_f() function an undefined cursor GET variable.
2704 public function testApiStatusesFWithUndefinedCursor()
2706 $_GET['cursor'] = 'undefined';
2707 $this->assertFalse(api_statuses_f('friends'));
2711 * Test the api_statuses_friends() function.
2715 public function testApiStatusesFriends()
2717 $result = api_statuses_friends('json');
2718 $this->assertArrayHasKey('user', $result);
2722 * Test the api_statuses_friends() function an undefined cursor GET variable.
2726 public function testApiStatusesFriendsWithUndefinedCursor()
2728 $_GET['cursor'] = 'undefined';
2729 $this->assertFalse(api_statuses_friends('json'));
2733 * Test the api_statuses_followers() function.
2737 public function testApiStatusesFollowers()
2739 $result = api_statuses_followers('json');
2740 $this->assertArrayHasKey('user', $result);
2744 * Test the api_statuses_followers() function an undefined cursor GET variable.
2748 public function testApiStatusesFollowersWithUndefinedCursor()
2750 $_GET['cursor'] = 'undefined';
2751 $this->assertFalse(api_statuses_followers('json'));
2755 * Test the api_blocks_list() function.
2759 public function testApiBlocksList()
2761 $result = api_blocks_list('json');
2762 $this->assertArrayHasKey('user', $result);
2766 * Test the api_blocks_list() function an undefined cursor GET variable.
2770 public function testApiBlocksListWithUndefinedCursor()
2772 $_GET['cursor'] = 'undefined';
2773 $this->assertFalse(api_blocks_list('json'));
2777 * Test the api_friendships_incoming() function.
2781 public function testApiFriendshipsIncoming()
2783 $result = api_friendships_incoming('json');
2784 $this->assertArrayHasKey('id', $result);
2788 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2792 public function testApiFriendshipsIncomingWithUndefinedCursor()
2794 $_GET['cursor'] = 'undefined';
2795 $this->assertFalse(api_friendships_incoming('json'));
2799 * Test the api_statusnet_config() function.
2803 public function testApiStatusnetConfig()
2805 $result = api_statusnet_config('json');
2806 $this->assertEquals('localhost', $result['config']['site']['server']);
2807 $this->assertEquals('default', $result['config']['site']['theme']);
2808 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2809 $this->assertTrue($result['config']['site']['fancy']);
2810 $this->assertEquals('en', $result['config']['site']['language']);
2811 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2812 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2813 $this->assertEquals('false', $result['config']['site']['private']);
2814 $this->assertEquals('false', $result['config']['site']['ssl']);
2815 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2819 * Test the api_statusnet_version() function.
2823 public function testApiStatusnetVersion()
2825 $result = api_statusnet_version('json');
2826 $this->assertEquals('0.9.7', $result['version']);
2830 * Test the api_direct_messages_new() function.
2834 public function testApiDirectMessagesNew()
2836 $result = api_direct_messages_new('json');
2837 $this->assertNull($result);
2841 * Test the api_direct_messages_new() function without an authenticated user.
2844 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2846 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2848 $_SESSION['authenticated'] = false;
2849 api_direct_messages_new('json');
2853 * Test the api_direct_messages_new() function with an user ID.
2857 public function testApiDirectMessagesNewWithUserId()
2859 $_POST['text'] = 'message_text';
2860 $_POST['user_id'] = $this->otherUser['id'];
2861 $result = api_direct_messages_new('json');
2862 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2866 * Test the api_direct_messages_new() function with a screen name.
2870 public function testApiDirectMessagesNewWithScreenName()
2872 $this->app->user = ['nickname' => $this->selfUser['nick']];
2873 $_POST['text'] = 'message_text';
2874 $_POST['screen_name'] = $this->friendUser['nick'];
2875 $result = api_direct_messages_new('json');
2876 $this->assertContains('message_text', $result['direct_message']['text']);
2877 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2878 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2882 * Test the api_direct_messages_new() function with a title.
2886 public function testApiDirectMessagesNewWithTitle()
2888 $this->app->user = ['nickname' => $this->selfUser['nick']];
2889 $_POST['text'] = 'message_text';
2890 $_POST['screen_name'] = $this->friendUser['nick'];
2891 $_REQUEST['title'] = 'message_title';
2892 $result = api_direct_messages_new('json');
2893 $this->assertContains('message_text', $result['direct_message']['text']);
2894 $this->assertContains('message_title', $result['direct_message']['text']);
2895 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2896 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2900 * Test the api_direct_messages_new() function with an RSS result.
2904 public function testApiDirectMessagesNewWithRss()
2906 $this->app->user = ['nickname' => $this->selfUser['nick']];
2907 $_POST['text'] = 'message_text';
2908 $_POST['screen_name'] = $this->friendUser['nick'];
2909 $result = api_direct_messages_new('rss');
2910 $this->assertXml($result, 'direct-messages');
2914 * Test the api_direct_messages_destroy() function.
2917 * @expectedException Friendica\Network\HTTPException\BadRequestException
2919 public function testApiDirectMessagesDestroy()
2921 api_direct_messages_destroy('json');
2925 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2929 public function testApiDirectMessagesDestroyWithVerbose()
2931 $_GET['friendica_verbose'] = 'true';
2932 $result = api_direct_messages_destroy('json');
2933 $this->assertEquals(
2936 'result' => 'error',
2937 'message' => 'message id or parenturi not specified'
2945 * Test the api_direct_messages_destroy() function without an authenticated user.
2948 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2950 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2952 $_SESSION['authenticated'] = false;
2953 api_direct_messages_destroy('json');
2957 * Test the api_direct_messages_destroy() function with a non-zero ID.
2960 * @expectedException Friendica\Network\HTTPException\BadRequestException
2962 public function testApiDirectMessagesDestroyWithId()
2964 $_REQUEST['id'] = 1;
2965 api_direct_messages_destroy('json');
2969 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2973 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2975 $_REQUEST['id'] = 1;
2976 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2977 $_GET['friendica_verbose'] = 'true';
2978 $result = api_direct_messages_destroy('json');
2979 $this->assertEquals(
2982 'result' => 'error',
2983 'message' => 'message id not in database'
2991 * Test the api_direct_messages_destroy() function with a non-zero ID.
2995 public function testApiDirectMessagesDestroyWithCorrectId()
2997 $this->markTestIncomplete('We need to add a dataset for this.');
3001 * Test the api_direct_messages_box() function.
3005 public function testApiDirectMessagesBoxWithSentbox()
3007 $_REQUEST['page'] = -1;
3008 $_REQUEST['max_id'] = 10;
3009 $result = api_direct_messages_box('json', 'sentbox', 'false');
3010 $this->assertArrayHasKey('direct_message', $result);
3014 * Test the api_direct_messages_box() function.
3018 public function testApiDirectMessagesBoxWithConversation()
3020 $result = api_direct_messages_box('json', 'conversation', 'false');
3021 $this->assertArrayHasKey('direct_message', $result);
3025 * Test the api_direct_messages_box() function.
3029 public function testApiDirectMessagesBoxWithAll()
3031 $result = api_direct_messages_box('json', 'all', 'false');
3032 $this->assertArrayHasKey('direct_message', $result);
3036 * Test the api_direct_messages_box() function.
3040 public function testApiDirectMessagesBoxWithInbox()
3042 $result = api_direct_messages_box('json', 'inbox', 'false');
3043 $this->assertArrayHasKey('direct_message', $result);
3047 * Test the api_direct_messages_box() function.
3051 public function testApiDirectMessagesBoxWithVerbose()
3053 $result = api_direct_messages_box('json', 'sentbox', 'true');
3054 $this->assertEquals(
3057 'result' => 'error',
3058 'message' => 'no mails available'
3066 * Test the api_direct_messages_box() function with a RSS result.
3070 public function testApiDirectMessagesBoxWithRss()
3072 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3073 $this->assertXml($result, 'direct-messages');
3077 * Test the api_direct_messages_box() function without an authenticated user.
3080 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3082 public function testApiDirectMessagesBoxWithUnallowedUser()
3084 $_SESSION['allow_api'] = false;
3085 $_GET['screen_name'] = $this->selfUser['nick'];
3086 api_direct_messages_box('json', 'sentbox', 'false');
3090 * Test the api_direct_messages_sentbox() function.
3094 public function testApiDirectMessagesSentbox()
3096 $result = api_direct_messages_sentbox('json');
3097 $this->assertArrayHasKey('direct_message', $result);
3101 * Test the api_direct_messages_inbox() function.
3105 public function testApiDirectMessagesInbox()
3107 $result = api_direct_messages_inbox('json');
3108 $this->assertArrayHasKey('direct_message', $result);
3112 * Test the api_direct_messages_all() function.
3116 public function testApiDirectMessagesAll()
3118 $result = api_direct_messages_all('json');
3119 $this->assertArrayHasKey('direct_message', $result);
3123 * Test the api_direct_messages_conversation() function.
3127 public function testApiDirectMessagesConversation()
3129 $result = api_direct_messages_conversation('json');
3130 $this->assertArrayHasKey('direct_message', $result);
3134 * Test the api_oauth_request_token() function.
3138 public function testApiOauthRequestToken()
3140 $this->markTestIncomplete('exit() kills phpunit as well');
3144 * Test the api_oauth_access_token() function.
3148 public function testApiOauthAccessToken()
3150 $this->markTestIncomplete('exit() kills phpunit as well');
3154 * Test the api_fr_photoalbum_delete() function.
3157 * @expectedException Friendica\Network\HTTPException\BadRequestException
3159 public function testApiFrPhotoalbumDelete()
3161 api_fr_photoalbum_delete('json');
3165 * Test the api_fr_photoalbum_delete() function with an album name.
3168 * @expectedException Friendica\Network\HTTPException\BadRequestException
3170 public function testApiFrPhotoalbumDeleteWithAlbum()
3172 $_REQUEST['album'] = 'album_name';
3173 api_fr_photoalbum_delete('json');
3177 * Test the api_fr_photoalbum_delete() function with an album name.
3181 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3183 $this->markTestIncomplete('We need to add a dataset for this.');
3187 * Test the api_fr_photoalbum_delete() function.
3190 * @expectedException Friendica\Network\HTTPException\BadRequestException
3192 public function testApiFrPhotoalbumUpdate()
3194 api_fr_photoalbum_update('json');
3198 * Test the api_fr_photoalbum_delete() function with an album name.
3201 * @expectedException Friendica\Network\HTTPException\BadRequestException
3203 public function testApiFrPhotoalbumUpdateWithAlbum()
3205 $_REQUEST['album'] = 'album_name';
3206 api_fr_photoalbum_update('json');
3210 * Test the api_fr_photoalbum_delete() function with an album name.
3213 * @expectedException Friendica\Network\HTTPException\BadRequestException
3215 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3217 $_REQUEST['album'] = 'album_name';
3218 $_REQUEST['album_new'] = 'album_name';
3219 api_fr_photoalbum_update('json');
3223 * Test the api_fr_photoalbum_update() function without an authenticated user.
3226 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3228 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3230 $_SESSION['authenticated'] = false;
3231 api_fr_photoalbum_update('json');
3235 * Test the api_fr_photoalbum_delete() function with an album name.
3239 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3241 $this->markTestIncomplete('We need to add a dataset for this.');
3245 * Test the api_fr_photos_list() function.
3249 public function testApiFrPhotosList()
3251 $result = api_fr_photos_list('json');
3252 $this->assertArrayHasKey('photo', $result);
3256 * Test the api_fr_photos_list() function without an authenticated user.
3259 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3261 public function testApiFrPhotosListWithoutAuthenticatedUser()
3263 $_SESSION['authenticated'] = false;
3264 api_fr_photos_list('json');
3268 * Test the api_fr_photo_create_update() function.
3271 * @expectedException Friendica\Network\HTTPException\BadRequestException
3273 public function testApiFrPhotoCreateUpdate()
3275 api_fr_photo_create_update('json');
3279 * Test the api_fr_photo_create_update() function without an authenticated user.
3282 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3284 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3286 $_SESSION['authenticated'] = false;
3287 api_fr_photo_create_update('json');
3291 * Test the api_fr_photo_create_update() function with an album name.
3294 * @expectedException Friendica\Network\HTTPException\BadRequestException
3296 public function testApiFrPhotoCreateUpdateWithAlbum()
3298 $_REQUEST['album'] = 'album_name';
3299 api_fr_photo_create_update('json');
3303 * Test the api_fr_photo_create_update() function with the update mode.
3307 public function testApiFrPhotoCreateUpdateWithUpdate()
3309 $this->markTestIncomplete('We need to create a dataset for this');
3313 * Test the api_fr_photo_create_update() function with an uploaded file.
3317 public function testApiFrPhotoCreateUpdateWithFile()
3319 $this->markTestIncomplete();
3323 * Test the api_fr_photo_delete() function.
3326 * @expectedException Friendica\Network\HTTPException\BadRequestException
3328 public function testApiFrPhotoDelete()
3330 api_fr_photo_delete('json');
3334 * Test the api_fr_photo_delete() function without an authenticated user.
3337 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3339 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3341 $_SESSION['authenticated'] = false;
3342 api_fr_photo_delete('json');
3346 * Test the api_fr_photo_delete() function with a photo ID.
3349 * @expectedException Friendica\Network\HTTPException\BadRequestException
3351 public function testApiFrPhotoDeleteWithPhotoId()
3353 $_REQUEST['photo_id'] = 1;
3354 api_fr_photo_delete('json');
3358 * Test the api_fr_photo_delete() function with a correct photo ID.
3362 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3364 $this->markTestIncomplete('We need to create a dataset for this.');
3368 * Test the api_fr_photo_detail() function.
3371 * @expectedException Friendica\Network\HTTPException\BadRequestException
3373 public function testApiFrPhotoDetail()
3375 api_fr_photo_detail('json');
3379 * Test the api_fr_photo_detail() function without an authenticated user.
3382 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3384 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3386 $_SESSION['authenticated'] = false;
3387 api_fr_photo_detail('json');
3391 * Test the api_fr_photo_detail() function with a photo ID.
3394 * @expectedException Friendica\Network\HTTPException\NotFoundException
3396 public function testApiFrPhotoDetailWithPhotoId()
3398 $_REQUEST['photo_id'] = 1;
3399 api_fr_photo_detail('json');
3403 * Test the api_fr_photo_detail() function with a correct photo ID.
3407 public function testApiFrPhotoDetailCorrectPhotoId()
3409 $this->markTestIncomplete('We need to create a dataset for this.');
3413 * Test the api_account_update_profile_image() function.
3416 * @expectedException Friendica\Network\HTTPException\BadRequestException
3418 public function testApiAccountUpdateProfileImage()
3420 api_account_update_profile_image('json');
3424 * Test the api_account_update_profile_image() function without an authenticated user.
3427 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3429 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3431 $_SESSION['authenticated'] = false;
3432 api_account_update_profile_image('json');
3436 * Test the api_account_update_profile_image() function with an uploaded file.
3439 * @expectedException Friendica\Network\HTTPException\BadRequestException
3441 public function testApiAccountUpdateProfileImageWithUpload()
3443 $this->markTestIncomplete();
3448 * Test the api_account_update_profile() function.
3452 public function testApiAccountUpdateProfile()
3454 $_POST['name'] = 'new_name';
3455 $_POST['description'] = 'new_description';
3456 $result = api_account_update_profile('json');
3457 // We can't use assertSelfUser() here because the user object is missing some properties.
3458 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3459 $this->assertEquals('DFRN', $result['user']['location']);
3460 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3461 $this->assertEquals('dfrn', $result['user']['network']);
3462 $this->assertEquals('new_name', $result['user']['name']);
3463 $this->assertEquals('new_description', $result['user']['description']);
3467 * Test the check_acl_input() function.
3471 public function testCheckAclInput()
3473 $result = check_acl_input('<aclstring>');
3474 // Where does this result come from?
3475 $this->assertEquals(1, $result);
3479 * Test the check_acl_input() function with an empty ACL string.
3483 public function testCheckAclInputWithEmptyAclString()
3485 $result = check_acl_input(' ');
3486 $this->assertFalse($result);
3490 * Test the save_media_to_database() function.
3494 public function testSaveMediaToDatabase()
3496 $this->markTestIncomplete();
3500 * Test the post_photo_item() function.
3504 public function testPostPhotoItem()
3506 $this->markTestIncomplete();
3510 * Test the prepare_photo_data() function.
3514 public function testPreparePhotoData()
3516 $this->markTestIncomplete();
3520 * Test the api_friendica_remoteauth() function.
3523 * @expectedException Friendica\Network\HTTPException\BadRequestException
3525 public function testApiFriendicaRemoteauth()
3527 api_friendica_remoteauth();
3531 * Test the api_friendica_remoteauth() function with an URL.
3534 * @expectedException Friendica\Network\HTTPException\BadRequestException
3536 public function testApiFriendicaRemoteauthWithUrl()
3538 $_GET['url'] = 'url';
3539 $_GET['c_url'] = 'url';
3540 api_friendica_remoteauth();
3544 * Test the api_friendica_remoteauth() function with a correct URL.
3548 public function testApiFriendicaRemoteauthWithCorrectUrl()
3550 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3551 $_GET['url'] = 'url';
3552 $_GET['c_url'] = $this->selfUser['nurl'];
3553 api_friendica_remoteauth();
3557 * Test the api_share_as_retweet() function.
3561 public function testApiShareAsRetweet()
3563 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3564 $result = api_share_as_retweet($item);
3565 $this->assertFalse($result);
3569 * Test the api_share_as_retweet() function with a valid item.
3573 public function testApiShareAsRetweetWithValidItem()
3575 $this->markTestIncomplete();
3579 * Test the api_in_reply_to() function.
3583 public function testApiInReplyTo()
3585 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3586 $this->assertArrayHasKey('status_id', $result);
3587 $this->assertArrayHasKey('user_id', $result);
3588 $this->assertArrayHasKey('status_id_str', $result);
3589 $this->assertArrayHasKey('user_id_str', $result);
3590 $this->assertArrayHasKey('screen_name', $result);
3594 * Test the api_in_reply_to() function with a valid item.
3598 public function testApiInReplyToWithValidItem()
3600 $this->markTestIncomplete();
3604 * Test the api_clean_plain_items() function.
3608 public function testApiCleanPlainItems()
3610 $_REQUEST['include_entities'] = 'true';
3611 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3612 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3616 * Test the api_best_nickname() function.
3620 public function testApiBestNickname()
3623 $result = api_best_nickname($contacts);
3624 $this->assertNull($result);
3628 * Test the api_best_nickname() function with contacts.
3632 public function testApiBestNicknameWithContacts()
3634 $this->markTestIncomplete();
3638 * Test the api_friendica_group_show() function.
3642 public function testApiFriendicaGroupShow()
3644 $this->markTestIncomplete();
3648 * Test the api_friendica_group_delete() function.
3652 public function testApiFriendicaGroupDelete()
3654 $this->markTestIncomplete();
3658 * Test the api_lists_destroy() function.
3662 public function testApiListsDestroy()
3664 $this->markTestIncomplete();
3668 * Test the group_create() function.
3672 public function testGroupCreate()
3674 $this->markTestIncomplete();
3678 * Test the api_friendica_group_create() function.
3682 public function testApiFriendicaGroupCreate()
3684 $this->markTestIncomplete();
3688 * Test the api_lists_create() function.
3692 public function testApiListsCreate()
3694 $this->markTestIncomplete();
3698 * Test the api_friendica_group_update() function.
3702 public function testApiFriendicaGroupUpdate()
3704 $this->markTestIncomplete();
3708 * Test the api_lists_update() function.
3712 public function testApiListsUpdate()
3714 $this->markTestIncomplete();
3718 * Test the api_friendica_activity() function.
3722 public function testApiFriendicaActivity()
3724 $this->markTestIncomplete();
3728 * Test the api_friendica_notification() function.
3731 * @expectedException Friendica\Network\HTTPException\BadRequestException
3733 public function testApiFriendicaNotification()
3735 api_friendica_notification('json');
3739 * Test the api_friendica_notification() function without an authenticated user.
3742 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3744 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3746 $_SESSION['authenticated'] = false;
3747 api_friendica_notification('json');
3751 * Test the api_friendica_notification() function with empty result
3755 public function testApiFriendicaNotificationWithEmptyResult()
3757 $this->app->argv = ['api', 'friendica', 'notification'];
3758 $this->app->argc = count($this->app->argv);
3759 $_SESSION['uid'] = 41;
3760 $result = api_friendica_notification('json');
3761 $this->assertEquals(['note' => false], $result);
3765 * Test the api_friendica_notification() function with an XML result.
3769 public function testApiFriendicaNotificationWithXmlResult()
3771 $this->app->argv = ['api', 'friendica', 'notification'];
3772 $this->app->argc = count($this->app->argv);
3773 $result = api_friendica_notification('xml');
3774 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3776 <?xml version="1.0"?>
3778 <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" uri-id="" link="http://localhost/notification/1" iid="4" parent="0" parent-uri-id="" seen="0" verb="" otype="item" name_cache="Reply to" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
3781 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3785 * Test the api_friendica_notification() function with an JSON result.
3789 public function testApiFriendicaNotificationWithJsonResult()
3791 $this->app->argv = ['api', 'friendica', 'notification'];
3792 $this->app->argc = count($this->app->argv);
3793 $result = json_encode(api_friendica_notification('json'));
3794 $this->assertJson($result);
3798 * Test the api_friendica_notification_seen() function.
3802 public function testApiFriendicaNotificationSeen()
3804 $this->markTestIncomplete();
3808 * Test the api_friendica_direct_messages_setseen() function.
3812 public function testApiFriendicaDirectMessagesSetseen()
3814 $this->markTestIncomplete();
3818 * Test the api_friendica_direct_messages_search() function.
3822 public function testApiFriendicaDirectMessagesSearch()
3824 $this->markTestIncomplete();
3828 * Test the api_saved_searches_list() function.
3832 public function testApiSavedSearchesList()
3834 $result = api_saved_searches_list('json');
3835 $this->assertEquals(1, $result['terms'][0]['id']);
3836 $this->assertEquals(1, $result['terms'][0]['id_str']);
3837 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3838 $this->assertEquals('Saved search', $result['terms'][0]['query']);