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 $_POST['text'] = 'message_text';
2873 $_POST['screen_name'] = $this->friendUser['nick'];
2874 $result = api_direct_messages_new('json');
2875 $this->assertContains('message_text', $result['direct_message']['text']);
2876 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2877 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2881 * Test the api_direct_messages_new() function with a title.
2885 public function testApiDirectMessagesNewWithTitle()
2887 $_POST['text'] = 'message_text';
2888 $_POST['screen_name'] = $this->friendUser['nick'];
2889 $_REQUEST['title'] = 'message_title';
2890 $result = api_direct_messages_new('json');
2891 $this->assertContains('message_text', $result['direct_message']['text']);
2892 $this->assertContains('message_title', $result['direct_message']['text']);
2893 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2894 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2898 * Test the api_direct_messages_new() function with an RSS result.
2902 public function testApiDirectMessagesNewWithRss()
2904 $_POST['text'] = 'message_text';
2905 $_POST['screen_name'] = $this->friendUser['nick'];
2906 $result = api_direct_messages_new('rss');
2907 $this->assertXml($result, 'direct-messages');
2911 * Test the api_direct_messages_destroy() function.
2914 * @expectedException Friendica\Network\HTTPException\BadRequestException
2916 public function testApiDirectMessagesDestroy()
2918 api_direct_messages_destroy('json');
2922 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2926 public function testApiDirectMessagesDestroyWithVerbose()
2928 $_GET['friendica_verbose'] = 'true';
2929 $result = api_direct_messages_destroy('json');
2930 $this->assertEquals(
2933 'result' => 'error',
2934 'message' => 'message id or parenturi not specified'
2942 * Test the api_direct_messages_destroy() function without an authenticated user.
2945 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2947 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2949 $_SESSION['authenticated'] = false;
2950 api_direct_messages_destroy('json');
2954 * Test the api_direct_messages_destroy() function with a non-zero ID.
2957 * @expectedException Friendica\Network\HTTPException\BadRequestException
2959 public function testApiDirectMessagesDestroyWithId()
2961 $_REQUEST['id'] = 1;
2962 api_direct_messages_destroy('json');
2966 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2970 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2972 $_REQUEST['id'] = 1;
2973 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2974 $_GET['friendica_verbose'] = 'true';
2975 $result = api_direct_messages_destroy('json');
2976 $this->assertEquals(
2979 'result' => 'error',
2980 'message' => 'message id not in database'
2988 * Test the api_direct_messages_destroy() function with a non-zero ID.
2992 public function testApiDirectMessagesDestroyWithCorrectId()
2994 $this->markTestIncomplete('We need to add a dataset for this.');
2998 * Test the api_direct_messages_box() function.
3002 public function testApiDirectMessagesBoxWithSentbox()
3004 $_REQUEST['page'] = -1;
3005 $_REQUEST['max_id'] = 10;
3006 $result = api_direct_messages_box('json', 'sentbox', 'false');
3007 $this->assertArrayHasKey('direct_message', $result);
3011 * Test the api_direct_messages_box() function.
3015 public function testApiDirectMessagesBoxWithConversation()
3017 $result = api_direct_messages_box('json', 'conversation', 'false');
3018 $this->assertArrayHasKey('direct_message', $result);
3022 * Test the api_direct_messages_box() function.
3026 public function testApiDirectMessagesBoxWithAll()
3028 $result = api_direct_messages_box('json', 'all', 'false');
3029 $this->assertArrayHasKey('direct_message', $result);
3033 * Test the api_direct_messages_box() function.
3037 public function testApiDirectMessagesBoxWithInbox()
3039 $result = api_direct_messages_box('json', 'inbox', 'false');
3040 $this->assertArrayHasKey('direct_message', $result);
3044 * Test the api_direct_messages_box() function.
3048 public function testApiDirectMessagesBoxWithVerbose()
3050 $result = api_direct_messages_box('json', 'sentbox', 'true');
3051 $this->assertEquals(
3054 'result' => 'error',
3055 'message' => 'no mails available'
3063 * Test the api_direct_messages_box() function with a RSS result.
3067 public function testApiDirectMessagesBoxWithRss()
3069 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3070 $this->assertXml($result, 'direct-messages');
3074 * Test the api_direct_messages_box() function without an authenticated user.
3077 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3079 public function testApiDirectMessagesBoxWithUnallowedUser()
3081 $_SESSION['allow_api'] = false;
3082 $_GET['screen_name'] = $this->selfUser['nick'];
3083 api_direct_messages_box('json', 'sentbox', 'false');
3087 * Test the api_direct_messages_sentbox() function.
3091 public function testApiDirectMessagesSentbox()
3093 $result = api_direct_messages_sentbox('json');
3094 $this->assertArrayHasKey('direct_message', $result);
3098 * Test the api_direct_messages_inbox() function.
3102 public function testApiDirectMessagesInbox()
3104 $result = api_direct_messages_inbox('json');
3105 $this->assertArrayHasKey('direct_message', $result);
3109 * Test the api_direct_messages_all() function.
3113 public function testApiDirectMessagesAll()
3115 $result = api_direct_messages_all('json');
3116 $this->assertArrayHasKey('direct_message', $result);
3120 * Test the api_direct_messages_conversation() function.
3124 public function testApiDirectMessagesConversation()
3126 $result = api_direct_messages_conversation('json');
3127 $this->assertArrayHasKey('direct_message', $result);
3131 * Test the api_oauth_request_token() function.
3135 public function testApiOauthRequestToken()
3137 $this->markTestIncomplete('exit() kills phpunit as well');
3141 * Test the api_oauth_access_token() function.
3145 public function testApiOauthAccessToken()
3147 $this->markTestIncomplete('exit() kills phpunit as well');
3151 * Test the api_fr_photoalbum_delete() function.
3154 * @expectedException Friendica\Network\HTTPException\BadRequestException
3156 public function testApiFrPhotoalbumDelete()
3158 api_fr_photoalbum_delete('json');
3162 * Test the api_fr_photoalbum_delete() function with an album name.
3165 * @expectedException Friendica\Network\HTTPException\BadRequestException
3167 public function testApiFrPhotoalbumDeleteWithAlbum()
3169 $_REQUEST['album'] = 'album_name';
3170 api_fr_photoalbum_delete('json');
3174 * Test the api_fr_photoalbum_delete() function with an album name.
3178 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3180 $this->markTestIncomplete('We need to add a dataset for this.');
3184 * Test the api_fr_photoalbum_delete() function.
3187 * @expectedException Friendica\Network\HTTPException\BadRequestException
3189 public function testApiFrPhotoalbumUpdate()
3191 api_fr_photoalbum_update('json');
3195 * Test the api_fr_photoalbum_delete() function with an album name.
3198 * @expectedException Friendica\Network\HTTPException\BadRequestException
3200 public function testApiFrPhotoalbumUpdateWithAlbum()
3202 $_REQUEST['album'] = 'album_name';
3203 api_fr_photoalbum_update('json');
3207 * Test the api_fr_photoalbum_delete() function with an album name.
3210 * @expectedException Friendica\Network\HTTPException\BadRequestException
3212 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3214 $_REQUEST['album'] = 'album_name';
3215 $_REQUEST['album_new'] = 'album_name';
3216 api_fr_photoalbum_update('json');
3220 * Test the api_fr_photoalbum_update() function without an authenticated user.
3223 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3225 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3227 $_SESSION['authenticated'] = false;
3228 api_fr_photoalbum_update('json');
3232 * Test the api_fr_photoalbum_delete() function with an album name.
3236 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3238 $this->markTestIncomplete('We need to add a dataset for this.');
3242 * Test the api_fr_photos_list() function.
3246 public function testApiFrPhotosList()
3248 $result = api_fr_photos_list('json');
3249 $this->assertArrayHasKey('photo', $result);
3253 * Test the api_fr_photos_list() function without an authenticated user.
3256 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3258 public function testApiFrPhotosListWithoutAuthenticatedUser()
3260 $_SESSION['authenticated'] = false;
3261 api_fr_photos_list('json');
3265 * Test the api_fr_photo_create_update() function.
3268 * @expectedException Friendica\Network\HTTPException\BadRequestException
3270 public function testApiFrPhotoCreateUpdate()
3272 api_fr_photo_create_update('json');
3276 * Test the api_fr_photo_create_update() function without an authenticated user.
3279 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3281 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3283 $_SESSION['authenticated'] = false;
3284 api_fr_photo_create_update('json');
3288 * Test the api_fr_photo_create_update() function with an album name.
3291 * @expectedException Friendica\Network\HTTPException\BadRequestException
3293 public function testApiFrPhotoCreateUpdateWithAlbum()
3295 $_REQUEST['album'] = 'album_name';
3296 api_fr_photo_create_update('json');
3300 * Test the api_fr_photo_create_update() function with the update mode.
3304 public function testApiFrPhotoCreateUpdateWithUpdate()
3306 $this->markTestIncomplete('We need to create a dataset for this');
3310 * Test the api_fr_photo_create_update() function with an uploaded file.
3314 public function testApiFrPhotoCreateUpdateWithFile()
3316 $this->markTestIncomplete();
3320 * Test the api_fr_photo_delete() function.
3323 * @expectedException Friendica\Network\HTTPException\BadRequestException
3325 public function testApiFrPhotoDelete()
3327 api_fr_photo_delete('json');
3331 * Test the api_fr_photo_delete() function without an authenticated user.
3334 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3336 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3338 $_SESSION['authenticated'] = false;
3339 api_fr_photo_delete('json');
3343 * Test the api_fr_photo_delete() function with a photo ID.
3346 * @expectedException Friendica\Network\HTTPException\BadRequestException
3348 public function testApiFrPhotoDeleteWithPhotoId()
3350 $_REQUEST['photo_id'] = 1;
3351 api_fr_photo_delete('json');
3355 * Test the api_fr_photo_delete() function with a correct photo ID.
3359 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3361 $this->markTestIncomplete('We need to create a dataset for this.');
3365 * Test the api_fr_photo_detail() function.
3368 * @expectedException Friendica\Network\HTTPException\BadRequestException
3370 public function testApiFrPhotoDetail()
3372 api_fr_photo_detail('json');
3376 * Test the api_fr_photo_detail() function without an authenticated user.
3379 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3381 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3383 $_SESSION['authenticated'] = false;
3384 api_fr_photo_detail('json');
3388 * Test the api_fr_photo_detail() function with a photo ID.
3391 * @expectedException Friendica\Network\HTTPException\NotFoundException
3393 public function testApiFrPhotoDetailWithPhotoId()
3395 $_REQUEST['photo_id'] = 1;
3396 api_fr_photo_detail('json');
3400 * Test the api_fr_photo_detail() function with a correct photo ID.
3404 public function testApiFrPhotoDetailCorrectPhotoId()
3406 $this->markTestIncomplete('We need to create a dataset for this.');
3410 * Test the api_account_update_profile_image() function.
3413 * @expectedException Friendica\Network\HTTPException\BadRequestException
3415 public function testApiAccountUpdateProfileImage()
3417 api_account_update_profile_image('json');
3421 * Test the api_account_update_profile_image() function without an authenticated user.
3424 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3426 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3428 $_SESSION['authenticated'] = false;
3429 api_account_update_profile_image('json');
3433 * Test the api_account_update_profile_image() function with an uploaded file.
3436 * @expectedException Friendica\Network\HTTPException\BadRequestException
3438 public function testApiAccountUpdateProfileImageWithUpload()
3440 $this->markTestIncomplete();
3445 * Test the api_account_update_profile() function.
3449 public function testApiAccountUpdateProfile()
3451 $_POST['name'] = 'new_name';
3452 $_POST['description'] = 'new_description';
3453 $result = api_account_update_profile('json');
3454 // We can't use assertSelfUser() here because the user object is missing some properties.
3455 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3456 $this->assertEquals('DFRN', $result['user']['location']);
3457 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3458 $this->assertEquals('dfrn', $result['user']['network']);
3459 $this->assertEquals('new_name', $result['user']['name']);
3460 $this->assertEquals('new_description', $result['user']['description']);
3464 * Test the check_acl_input() function.
3468 public function testCheckAclInput()
3470 $result = check_acl_input('<aclstring>');
3471 // Where does this result come from?
3472 $this->assertEquals(1, $result);
3476 * Test the check_acl_input() function with an empty ACL string.
3480 public function testCheckAclInputWithEmptyAclString()
3482 $result = check_acl_input(' ');
3483 $this->assertFalse($result);
3487 * Test the save_media_to_database() function.
3491 public function testSaveMediaToDatabase()
3493 $this->markTestIncomplete();
3497 * Test the post_photo_item() function.
3501 public function testPostPhotoItem()
3503 $this->markTestIncomplete();
3507 * Test the prepare_photo_data() function.
3511 public function testPreparePhotoData()
3513 $this->markTestIncomplete();
3517 * Test the api_friendica_remoteauth() function.
3520 * @expectedException Friendica\Network\HTTPException\BadRequestException
3522 public function testApiFriendicaRemoteauth()
3524 api_friendica_remoteauth();
3528 * Test the api_friendica_remoteauth() function with an URL.
3531 * @expectedException Friendica\Network\HTTPException\BadRequestException
3533 public function testApiFriendicaRemoteauthWithUrl()
3535 $_GET['url'] = 'url';
3536 $_GET['c_url'] = 'url';
3537 api_friendica_remoteauth();
3541 * Test the api_friendica_remoteauth() function with a correct URL.
3545 public function testApiFriendicaRemoteauthWithCorrectUrl()
3547 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3548 $_GET['url'] = 'url';
3549 $_GET['c_url'] = $this->selfUser['nurl'];
3550 api_friendica_remoteauth();
3554 * Test the api_share_as_retweet() function.
3558 public function testApiShareAsRetweet()
3560 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3561 $result = api_share_as_retweet($item);
3562 $this->assertFalse($result);
3566 * Test the api_share_as_retweet() function with a valid item.
3570 public function testApiShareAsRetweetWithValidItem()
3572 $this->markTestIncomplete();
3576 * Test the api_in_reply_to() function.
3580 public function testApiInReplyTo()
3582 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3583 $this->assertArrayHasKey('status_id', $result);
3584 $this->assertArrayHasKey('user_id', $result);
3585 $this->assertArrayHasKey('status_id_str', $result);
3586 $this->assertArrayHasKey('user_id_str', $result);
3587 $this->assertArrayHasKey('screen_name', $result);
3591 * Test the api_in_reply_to() function with a valid item.
3595 public function testApiInReplyToWithValidItem()
3597 $this->markTestIncomplete();
3601 * Test the api_clean_plain_items() function.
3605 public function testApiCleanPlainItems()
3607 $_REQUEST['include_entities'] = 'true';
3608 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3609 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3613 * Test the api_best_nickname() function.
3617 public function testApiBestNickname()
3620 $result = api_best_nickname($contacts);
3621 $this->assertNull($result);
3625 * Test the api_best_nickname() function with contacts.
3629 public function testApiBestNicknameWithContacts()
3631 $this->markTestIncomplete();
3635 * Test the api_friendica_group_show() function.
3639 public function testApiFriendicaGroupShow()
3641 $this->markTestIncomplete();
3645 * Test the api_friendica_group_delete() function.
3649 public function testApiFriendicaGroupDelete()
3651 $this->markTestIncomplete();
3655 * Test the api_lists_destroy() function.
3659 public function testApiListsDestroy()
3661 $this->markTestIncomplete();
3665 * Test the group_create() function.
3669 public function testGroupCreate()
3671 $this->markTestIncomplete();
3675 * Test the api_friendica_group_create() function.
3679 public function testApiFriendicaGroupCreate()
3681 $this->markTestIncomplete();
3685 * Test the api_lists_create() function.
3689 public function testApiListsCreate()
3691 $this->markTestIncomplete();
3695 * Test the api_friendica_group_update() function.
3699 public function testApiFriendicaGroupUpdate()
3701 $this->markTestIncomplete();
3705 * Test the api_lists_update() function.
3709 public function testApiListsUpdate()
3711 $this->markTestIncomplete();
3715 * Test the api_friendica_activity() function.
3719 public function testApiFriendicaActivity()
3721 $this->markTestIncomplete();
3725 * Test the api_friendica_notification() function.
3728 * @expectedException Friendica\Network\HTTPException\BadRequestException
3730 public function testApiFriendicaNotification()
3732 api_friendica_notification('json');
3736 * Test the api_friendica_notification() function without an authenticated user.
3739 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3741 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3743 $_SESSION['authenticated'] = false;
3744 api_friendica_notification('json');
3748 * Test the api_friendica_notification() function with empty result
3752 public function testApiFriendicaNotificationWithEmptyResult()
3754 $this->app->argv = ['api', 'friendica', 'notification'];
3755 $this->app->argc = count($this->app->argv);
3756 $_SESSION['uid'] = 41;
3757 $result = api_friendica_notification('json');
3758 $this->assertEquals(['note' => false], $result);
3762 * Test the api_friendica_notification() function with an XML result.
3766 public function testApiFriendicaNotificationWithXmlResult()
3768 $this->app->argv = ['api', 'friendica', 'notification'];
3769 $this->app->argc = count($this->app->argv);
3770 $result = api_friendica_notification('xml');
3771 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3773 <?xml version="1.0"?>
3775 <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"/>
3778 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3782 * Test the api_friendica_notification() function with an JSON result.
3786 public function testApiFriendicaNotificationWithJsonResult()
3788 $this->app->argv = ['api', 'friendica', 'notification'];
3789 $this->app->argc = count($this->app->argv);
3790 $result = json_encode(api_friendica_notification('json'));
3791 $this->assertJson($result);
3795 * Test the api_friendica_notification_seen() function.
3799 public function testApiFriendicaNotificationSeen()
3801 $this->markTestIncomplete();
3805 * Test the api_friendica_direct_messages_setseen() function.
3809 public function testApiFriendicaDirectMessagesSetseen()
3811 $this->markTestIncomplete();
3815 * Test the api_friendica_direct_messages_search() function.
3819 public function testApiFriendicaDirectMessagesSearch()
3821 $this->markTestIncomplete();
3825 * Test the api_saved_searches_list() function.
3829 public function testApiSavedSearchesList()
3831 $result = api_saved_searches_list('json');
3832 $this->assertEquals(1, $result['terms'][0]['id']);
3833 $this->assertEquals(1, $result['terms'][0]['id_str']);
3834 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3835 $this->assertEquals('Saved search', $result['terms'][0]['query']);