6 namespace Friendica\Test;
8 use Friendica\BaseObject;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Network\HTTPException;
16 * Tests for the API functions.
18 * Functions that use header() need to be tested in a separate process.
19 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
21 class ApiTest extends DatabaseTest
25 * Create variables used by tests.
27 public function setUp()
31 require_once __DIR__.'/../include/api.php';
33 // User data that the test database is populated with
36 'name' => 'Self contact',
37 'nick' => 'selfcontact',
38 'nurl' => 'http://localhost/profile/selfcontact'
42 'name' => 'Friend contact',
43 'nick' => 'friendcontact',
44 'nurl' => 'http://localhost/profile/friendcontact'
48 'name' => 'othercontact',
49 'nick' => 'othercontact',
50 'nurl' => 'http://localhost/profile/othercontact'
53 // User ID that we know is not in the database
54 $this->wrongUserId = 666;
56 // Most API require login so we force the session
59 'authenticated' => true,
60 'uid' => $this->selfUser['id']
64 Config::set('config', 'hostname', 'localhost');
65 Config::set('system', 'throttle_limit_day', 100);
66 Config::set('system', 'throttle_limit_week', 100);
67 Config::set('system', 'throttle_limit_month', 100);
68 Config::set('system', 'theme', 'system_theme');
72 * Cleanup variables used by tests.
74 protected function tearDown()
79 $this->app->argv = ['home'];
83 * Assert that an user array contains expected keys.
84 * @param array $user User array
87 private function assertSelfUser(array $user)
89 $this->assertEquals($this->selfUser['id'], $user['uid']);
90 $this->assertEquals($this->selfUser['id'], $user['cid']);
91 $this->assertEquals(1, $user['self']);
92 $this->assertEquals('Friendica', $user['location']);
93 $this->assertEquals($this->selfUser['name'], $user['name']);
94 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
95 $this->assertEquals('dfrn', $user['network']);
96 $this->assertTrue($user['verified']);
100 * Assert that an user array contains expected keys.
101 * @param array $user User array
104 private function assertOtherUser(array $user)
106 $this->assertEquals($this->otherUser['id'], $user['id']);
107 $this->assertEquals($this->otherUser['id'], $user['id_str']);
108 $this->assertEquals(0, $user['self']);
109 $this->assertEquals($this->otherUser['name'], $user['name']);
110 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
111 $this->assertFalse($user['verified']);
115 * Assert that a status array contains expected keys.
116 * @param array $status Status array
119 private function assertStatus(array $status)
121 $this->assertInternalType('string', $status['text']);
122 $this->assertInternalType('int', $status['id']);
123 // We could probably do more checks here.
127 * Assert that a list array contains expected keys.
128 * @param array $list List array
131 private function assertList(array $list)
133 $this->assertInternalType('string', $list['name']);
134 $this->assertInternalType('int', $list['id']);
135 $this->assertInternalType('string', $list['id_str']);
136 $this->assertContains($list['mode'], ['public', 'private']);
137 // We could probably do more checks here.
141 * Assert that the string is XML and contain the root element.
142 * @param string $result XML string
143 * @param string $root_element Root element name
146 private function assertXml($result, $root_element)
148 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
149 $this->assertContains('<'.$root_element, $result);
150 // We could probably do more checks here.
154 * Get the path to a temporary empty PNG image.
155 * @return string Path
157 private function getTempImage()
159 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
163 // Empty 1x1 px PNG image
164 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
172 * Test the api_user() function.
175 public function testApiUser()
177 $this->assertEquals($this->selfUser['id'], api_user());
181 * Test the api_user() function with an unallowed user.
184 public function testApiUserWithUnallowedUser()
186 $_SESSION = ['allow_api' => false];
187 $this->assertEquals(false, api_user());
191 * Test the api_source() function.
194 public function testApiSource()
196 $this->assertEquals('api', api_source());
200 * Test the api_source() function with a Twidere user agent.
203 public function testApiSourceWithTwidere()
205 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
206 $this->assertEquals('Twidere', api_source());
210 * Test the api_source() function with a GET parameter.
213 public function testApiSourceWithGet()
215 $_GET['source'] = 'source_name';
216 $this->assertEquals('source_name', api_source());
220 * Test the api_date() function.
223 public function testApiDate()
225 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
229 * Test the api_register_func() function.
232 public function testApiRegisterFunc()
244 $this->assertTrue($API['api_path']['auth']);
245 $this->assertEquals('method', $API['api_path']['method']);
246 $this->assertTrue(is_callable($API['api_path']['func']));
250 * Test the api_login() function without any login.
252 * @runInSeparateProcess
253 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
255 public function testApiLoginWithoutLogin()
257 api_login($this->app);
261 * Test the api_login() function with a bad login.
263 * @runInSeparateProcess
264 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
266 public function testApiLoginWithBadLogin()
268 $_SERVER['PHP_AUTH_USER'] = 'user@server';
269 api_login($this->app);
273 * Test the api_login() function with oAuth.
276 public function testApiLoginWithOauth()
278 $this->markTestIncomplete('Can we test this easily?');
282 * Test the api_login() function with authentication provided by an addon.
285 public function testApiLoginWithAddonAuth()
287 $this->markTestIncomplete('Can we test this easily?');
291 * Test the api_login() function with a correct login.
293 * @runInSeparateProcess
295 public function testApiLoginWithCorrectLogin()
297 $_SERVER['PHP_AUTH_USER'] = 'Test user';
298 $_SERVER['PHP_AUTH_PW'] = 'password';
299 api_login($this->app);
303 * Test the api_login() function with a remote user.
305 * @runInSeparateProcess
306 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
308 public function testApiLoginWithRemoteUser()
310 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
311 api_login($this->app);
315 * Test the api_check_method() function.
318 public function testApiCheckMethod()
320 $this->assertFalse(api_check_method('method'));
324 * Test the api_check_method() function with a correct method.
327 public function testApiCheckMethodWithCorrectMethod()
329 $_SERVER['REQUEST_METHOD'] = 'method';
330 $this->assertTrue(api_check_method('method'));
334 * Test the api_check_method() function with a wildcard.
337 public function testApiCheckMethodWithWildcard()
339 $this->assertTrue(api_check_method('*'));
343 * Test the api_call() function.
345 * @runInSeparateProcess
347 public function testApiCall()
351 'method' => 'method',
352 'func' => function () {
353 return ['data' => ['some_data']];
356 $_SERVER['REQUEST_METHOD'] = 'method';
357 $_GET['callback'] = 'callback_name';
359 $this->app->query_string = 'api_path';
361 'callback_name(["some_data"])',
367 * Test the api_call() function with the profiled enabled.
369 * @runInSeparateProcess
371 public function testApiCallWithProfiler()
375 'method' => 'method',
376 'func' => function () {
377 return ['data' => ['some_data']];
380 $_SERVER['REQUEST_METHOD'] = 'method';
381 Config::set('system', 'profiler', true);
382 Config::set('rendertime', 'callstack', true);
383 $this->app->callstack = [
384 'database' => ['some_function' => 200],
385 'database_write' => ['some_function' => 200],
386 'cache' => ['some_function' => 200],
387 'cache_write' => ['some_function' => 200],
388 'network' => ['some_function' => 200]
391 $this->app->query_string = 'api_path';
399 * Test the api_call() function without any result.
401 * @runInSeparateProcess
403 public function testApiCallWithNoResult()
407 'method' => 'method',
408 'func' => function () {
412 $_SERVER['REQUEST_METHOD'] = 'method';
414 $this->app->query_string = 'api_path';
416 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
422 * Test the api_call() function with an unimplemented API.
424 * @runInSeparateProcess
426 public function testApiCallWithUninplementedApi()
429 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
435 * Test the api_call() function with a JSON result.
437 * @runInSeparateProcess
439 public function testApiCallWithJson()
443 'method' => 'method',
444 'func' => function () {
445 return ['data' => ['some_data']];
448 $_SERVER['REQUEST_METHOD'] = 'method';
450 $this->app->query_string = 'api_path.json';
458 * Test the api_call() function with an XML result.
460 * @runInSeparateProcess
462 public function testApiCallWithXml()
466 'method' => 'method',
467 'func' => function () {
471 $_SERVER['REQUEST_METHOD'] = 'method';
473 $this->app->query_string = 'api_path.xml';
481 * Test the api_call() function with an RSS result.
483 * @runInSeparateProcess
485 public function testApiCallWithRss()
489 'method' => 'method',
490 'func' => function () {
494 $_SERVER['REQUEST_METHOD'] = 'method';
496 $this->app->query_string = 'api_path.rss';
498 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
505 * Test the api_call() function with an Atom result.
507 * @runInSeparateProcess
509 public function testApiCallWithAtom()
513 'method' => 'method',
514 'func' => function () {
518 $_SERVER['REQUEST_METHOD'] = 'method';
520 $this->app->query_string = 'api_path.atom';
522 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
529 * Test the api_call() function with an unallowed method.
531 * @runInSeparateProcess
533 public function testApiCallWithWrongMethod()
536 $API['api_path'] = ['method' => 'method'];
538 $this->app->query_string = 'api_path';
540 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
546 * Test the api_call() function with an unauthorized user.
548 * @runInSeparateProcess
550 public function testApiCallWithWrongAuth()
554 'method' => 'method',
557 $_SERVER['REQUEST_METHOD'] = 'method';
558 $_SESSION['authenticated'] = false;
560 $this->app->query_string = 'api_path';
562 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
568 * Test the api_error() function with a JSON result.
570 * @runInSeparateProcess
572 public function testApiErrorWithJson()
575 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
576 api_error('json', new HTTPException('error_message'))
581 * Test the api_error() function with an XML result.
583 * @runInSeparateProcess
585 public function testApiErrorWithXml()
588 '<?xml version="1.0"?>'."\n".
589 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
590 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
591 'xmlns:georss="http://www.georss.org/georss">'."\n".
592 ' <error>error_message</error>'."\n".
593 ' <code>200 Friendica\Network\HTTP</code>'."\n".
596 api_error('xml', new HTTPException('error_message'))
601 * Test the api_error() function with an RSS result.
603 * @runInSeparateProcess
605 public function testApiErrorWithRss()
608 '<?xml version="1.0"?>'."\n".
609 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
610 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
611 'xmlns:georss="http://www.georss.org/georss">'."\n".
612 ' <error>error_message</error>'."\n".
613 ' <code>200 Friendica\Network\HTTP</code>'."\n".
616 api_error('rss', new HTTPException('error_message'))
621 * Test the api_error() function with an Atom result.
623 * @runInSeparateProcess
625 public function testApiErrorWithAtom()
628 '<?xml version="1.0"?>'."\n".
629 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
630 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
631 'xmlns:georss="http://www.georss.org/georss">'."\n".
632 ' <error>error_message</error>'."\n".
633 ' <code>200 Friendica\Network\HTTP</code>'."\n".
636 api_error('atom', new HTTPException('error_message'))
641 * Test the api_rss_extra() function.
644 public function testApiRssExtra()
646 $user_info = ['url' => 'user_url', 'lang' => 'en'];
647 $result = api_rss_extra($this->app, [], $user_info);
648 $this->assertEquals($user_info, $result['$user']);
649 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
650 $this->assertArrayHasKey('self', $result['$rss']);
651 $this->assertArrayHasKey('base', $result['$rss']);
652 $this->assertArrayHasKey('updated', $result['$rss']);
653 $this->assertArrayHasKey('atom_updated', $result['$rss']);
654 $this->assertArrayHasKey('language', $result['$rss']);
655 $this->assertArrayHasKey('logo', $result['$rss']);
659 * Test the api_rss_extra() function without any user info.
661 * @runInSeparateProcess
663 public function testApiRssExtraWithoutUserInfo()
665 $result = api_rss_extra($this->app, [], null);
666 $this->assertInternalType('array', $result['$user']);
667 $this->assertArrayHasKey('alternate', $result['$rss']);
668 $this->assertArrayHasKey('self', $result['$rss']);
669 $this->assertArrayHasKey('base', $result['$rss']);
670 $this->assertArrayHasKey('updated', $result['$rss']);
671 $this->assertArrayHasKey('atom_updated', $result['$rss']);
672 $this->assertArrayHasKey('language', $result['$rss']);
673 $this->assertArrayHasKey('logo', $result['$rss']);
677 * Test the api_unique_id_to_nurl() function.
680 public function testApiUniqueIdToNurl()
682 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
686 * Test the api_unique_id_to_nurl() function with a correct ID.
689 public function testApiUniqueIdToNurlWithCorrectId()
691 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
695 * Test the api_get_user() function.
697 * @runInSeparateProcess
699 public function testApiGetUser()
701 $user = api_get_user($this->app);
702 $this->assertSelfUser($user);
703 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
704 $this->assertEquals('6fdbe8', $user['profile_link_color']);
705 $this->assertEquals('ededed', $user['profile_background_color']);
709 * Test the api_get_user() function with a Frio schema.
711 * @runInSeparateProcess
713 public function testApiGetUserWithFrioSchema()
715 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
716 $user = api_get_user($this->app);
717 $this->assertSelfUser($user);
718 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
719 $this->assertEquals('6fdbe8', $user['profile_link_color']);
720 $this->assertEquals('ededed', $user['profile_background_color']);
724 * Test the api_get_user() function with a custom Frio schema.
726 * @runInSeparateProcess
728 public function testApiGetUserWithCustomFrioSchema()
730 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
731 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
732 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
733 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
734 $user = api_get_user($this->app);
735 $this->assertSelfUser($user);
736 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
737 $this->assertEquals('123456', $user['profile_link_color']);
738 $this->assertEquals('123456', $user['profile_background_color']);
742 * Test the api_get_user() function with an empty Frio schema.
744 * @runInSeparateProcess
746 public function testApiGetUserWithEmptyFrioSchema()
748 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
749 $user = api_get_user($this->app);
750 $this->assertSelfUser($user);
751 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
752 $this->assertEquals('6fdbe8', $user['profile_link_color']);
753 $this->assertEquals('ededed', $user['profile_background_color']);
757 * Test the api_get_user() function with an user that is not allowed to use the API.
759 * @runInSeparateProcess
761 public function testApiGetUserWithoutApiUser()
763 $_SERVER['PHP_AUTH_USER'] = 'Test user';
764 $_SERVER['PHP_AUTH_PW'] = 'password';
765 $_SESSION['allow_api'] = false;
766 $this->assertFalse(api_get_user($this->app));
770 * Test the api_get_user() function with an user ID in a GET parameter.
772 * @runInSeparateProcess
774 public function testApiGetUserWithGetId()
776 $_GET['user_id'] = $this->otherUser['id'];
777 $this->assertOtherUser(api_get_user($this->app));
781 * Test the api_get_user() function with a wrong user ID in a GET parameter.
783 * @runInSeparateProcess
784 * @expectedException Friendica\Network\HTTPException\BadRequestException
786 public function testApiGetUserWithWrongGetId()
788 $_GET['user_id'] = $this->wrongUserId;
789 $this->assertOtherUser(api_get_user($this->app));
793 * Test the api_get_user() function with an user name in a GET parameter.
795 * @runInSeparateProcess
797 public function testApiGetUserWithGetName()
799 $_GET['screen_name'] = $this->selfUser['nick'];
800 $this->assertSelfUser(api_get_user($this->app));
804 * Test the api_get_user() function with a profile URL in a GET parameter.
806 * @runInSeparateProcess
808 public function testApiGetUserWithGetUrl()
810 $_GET['profileurl'] = $this->selfUser['nurl'];
811 $this->assertSelfUser(api_get_user($this->app));
815 * Test the api_get_user() function with an user ID in the API path.
817 * @runInSeparateProcess
819 public function testApiGetUserWithNumericCalledApi()
822 $called_api = ['api_path'];
823 $this->app->argv[1] = $this->otherUser['id'].'.json';
824 $this->assertOtherUser(api_get_user($this->app));
828 * Test the api_get_user() function with the $called_api global variable.
830 * @runInSeparateProcess
832 public function testApiGetUserWithCalledApi()
835 $called_api = ['api', 'api_path'];
836 $this->assertSelfUser(api_get_user($this->app));
840 * Test the api_get_user() function with a valid user.
842 * @runInSeparateProcess
844 public function testApiGetUserWithCorrectUser()
846 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
850 * Test the api_get_user() function with a wrong user ID.
852 * @runInSeparateProcess
853 * @expectedException Friendica\Network\HTTPException\BadRequestException
855 public function testApiGetUserWithWrongUser()
857 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
861 * Test the api_get_user() function with a 0 user ID.
863 * @runInSeparateProcess
865 public function testApiGetUserWithZeroUser()
867 $this->assertSelfUser(api_get_user($this->app, 0));
871 * Test the api_item_get_user() function.
873 * @runInSeparateProcess
875 public function testApiItemGetUser()
877 $users = api_item_get_user($this->app, []);
878 $this->assertSelfUser($users[0]);
882 * Test the api_item_get_user() function with a different item parent.
885 public function testApiItemGetUserWithDifferentParent()
887 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
888 $this->assertSelfUser($users[0]);
889 $this->assertEquals($users[0], $users[1]);
893 * Test the api_walk_recursive() function.
896 public function testApiWalkRecursive()
904 // Should we test this with a callback that actually does something?
912 * Test the api_walk_recursive() function with an array.
915 public function testApiWalkRecursiveWithArray()
917 $array = [['item1'], ['item2']];
923 // Should we test this with a callback that actually does something?
931 * Test the api_reformat_xml() function.
934 public function testApiReformatXml()
938 $this->assertTrue(api_reformat_xml($item, $key));
939 $this->assertEquals('true', $item);
943 * Test the api_reformat_xml() function with a statusnet_api key.
946 public function testApiReformatXmlWithStatusnetKey()
949 $key = 'statusnet_api';
950 $this->assertTrue(api_reformat_xml($item, $key));
951 $this->assertEquals('statusnet:api', $key);
955 * Test the api_reformat_xml() function with a friendica_api key.
958 public function testApiReformatXmlWithFriendicaKey()
961 $key = 'friendica_api';
962 $this->assertTrue(api_reformat_xml($item, $key));
963 $this->assertEquals('friendica:api', $key);
967 * Test the api_create_xml() function.
970 public function testApiCreateXml()
973 '<?xml version="1.0"?>'."\n".
974 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
975 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
976 'xmlns:georss="http://www.georss.org/georss">'."\n".
977 ' <data>some_data</data>'."\n".
978 '</root_element>'."\n",
979 api_create_xml(['data' => ['some_data']], 'root_element')
984 * Test the api_create_xml() function without any XML namespace.
987 public function testApiCreateXmlWithoutNamespaces()
990 '<?xml version="1.0"?>'."\n".
992 ' <data>some_data</data>'."\n".
994 api_create_xml(['data' => ['some_data']], 'ok')
999 * Test the api_format_data() function.
1002 public function testApiFormatData()
1004 $data = ['some_data'];
1005 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1009 * Test the api_format_data() function with an XML result.
1012 public function testApiFormatDataWithXml()
1014 $this->assertEquals(
1015 '<?xml version="1.0"?>'."\n".
1016 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1017 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1018 'xmlns:georss="http://www.georss.org/georss">'."\n".
1019 ' <data>some_data</data>'."\n".
1020 '</root_element>'."\n",
1021 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1026 * Test the api_account_verify_credentials() function.
1029 public function testApiAccountVerifyCredentials()
1031 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1035 * Test the api_account_verify_credentials() function without an authenticated user.
1037 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1039 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1041 $_SESSION['authenticated'] = false;
1042 api_account_verify_credentials('json');
1046 * Test the requestdata() function.
1049 public function testRequestdata()
1051 $this->assertNull(requestdata('variable_name'));
1055 * Test the requestdata() function with a POST parameter.
1058 public function testRequestdataWithPost()
1060 $_POST['variable_name'] = 'variable_value';
1061 $this->assertEquals('variable_value', requestdata('variable_name'));
1065 * Test the requestdata() function with a GET parameter.
1068 public function testRequestdataWithGet()
1070 $_GET['variable_name'] = 'variable_value';
1071 $this->assertEquals('variable_value', requestdata('variable_name'));
1075 * Test the api_statuses_mediap() function.
1078 public function testApiStatusesMediap()
1080 $this->app->argc = 2;
1088 'tmp_name' => $this->getTempImage(),
1089 'name' => 'spacer.png',
1090 'type' => 'image/png'
1093 $_GET['status'] = '<b>Status content</b>';
1095 $result = api_statuses_mediap('json');
1096 $this->assertStatus($result['status']);
1100 * Test the api_statuses_mediap() function without an authenticated user.
1102 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1104 public function testApiStatusesMediapWithoutAuthenticatedUser()
1106 $_SESSION['authenticated'] = false;
1107 api_statuses_mediap('json');
1111 * Test the api_statuses_update() function.
1114 public function testApiStatusesUpdate()
1116 $_GET['status'] = 'Status content';
1117 $_GET['in_reply_to_status_id'] = -1;
1126 'tmp_name' => $this->getTempImage(),
1127 'name' => 'spacer.png',
1128 'type' => 'image/png'
1132 $result = api_statuses_update('json');
1133 $this->assertStatus($result['status']);
1137 * Test the api_statuses_update() function with an HTML status.
1140 public function testApiStatusesUpdateWithHtml()
1142 $_GET['htmlstatus'] = '<b>Status content</b>';
1144 $result = api_statuses_update('json');
1145 $this->assertStatus($result['status']);
1149 * Test the api_statuses_update() function without an authenticated user.
1151 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1153 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1155 $_SESSION['authenticated'] = false;
1156 api_statuses_update('json');
1160 * Test the api_statuses_update() function with a parent status.
1163 public function testApiStatusesUpdateWithParent()
1165 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1169 * Test the api_statuses_update() function with a media_ids parameter.
1172 public function testApiStatusesUpdateWithMediaIds()
1174 $this->markTestIncomplete();
1178 * Test the api_statuses_update() function with the throttle limit reached.
1181 public function testApiStatusesUpdateWithDayThrottleReached()
1183 $this->markTestIncomplete();
1187 * Test the api_media_upload() function.
1189 * @expectedException Friendica\Network\HTTPException\BadRequestException
1191 public function testApiMediaUpload()
1197 * Test the api_media_upload() function without an authenticated user.
1199 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1201 public function testApiMediaUploadWithoutAuthenticatedUser()
1203 $_SESSION['authenticated'] = false;
1208 * Test the api_media_upload() function with an invalid uploaded media.
1210 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1212 public function testApiMediaUploadWithMedia()
1217 'tmp_name' => 'tmp_name'
1224 * Test the api_media_upload() function with an valid uploaded media.
1227 public function testApiMediaUploadWithValidMedia()
1235 'tmp_name' => $this->getTempImage(),
1236 'name' => 'spacer.png',
1237 'type' => 'image/png'
1243 $result = api_media_upload();
1244 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1245 $this->assertEquals(1, $result['media']['image']['w']);
1246 $this->assertEquals(1, $result['media']['image']['h']);
1250 * Test the api_status_show() function.
1253 public function testApiStatusShow()
1255 $result = api_status_show('json');
1256 $this->assertStatus($result['status']);
1260 * Test the api_status_show() function with an XML result.
1263 public function testApiStatusShowWithXml()
1265 $result = api_status_show('xml');
1266 $this->assertXml($result, 'statuses');
1270 * Test the api_status_show() function with a raw result.
1273 public function testApiStatusShowWithRaw()
1275 $this->assertStatus(api_status_show('raw'));
1279 * Test the api_users_show() function.
1282 public function testApiUsersShow()
1284 $result = api_users_show('json');
1285 // We can't use assertSelfUser() here because the user object is missing some properties.
1286 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1287 $this->assertEquals('Friendica', $result['user']['location']);
1288 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1289 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1290 $this->assertEquals('dfrn', $result['user']['network']);
1291 $this->assertTrue($result['user']['verified']);
1295 * Test the api_users_show() function with an XML result.
1298 public function testApiUsersShowWithXml()
1300 $result = api_users_show('xml');
1301 $this->assertXml($result, 'statuses');
1305 * Test the api_users_search() function.
1308 public function testApiUsersSearch()
1310 $_GET['q'] = 'othercontact';
1311 $result = api_users_search('json');
1312 $this->assertOtherUser($result['users'][0]);
1316 * Test the api_users_search() function with an XML result.
1319 public function testApiUsersSearchWithXml()
1321 $_GET['q'] = 'othercontact';
1322 $result = api_users_search('xml');
1323 $this->assertXml($result, 'users');
1327 * Test the api_users_search() function without a GET q parameter.
1329 * @expectedException Friendica\Network\HTTPException\BadRequestException
1331 public function testApiUsersSearchWithoutQuery()
1333 api_users_search('json');
1337 * Test the api_users_lookup() function.
1339 * @expectedException Friendica\Network\HTTPException\NotFoundException
1341 public function testApiUsersLookup()
1343 api_users_lookup('json');
1347 * Test the api_users_lookup() function with an user ID.
1350 public function testApiUsersLookupWithUserId()
1352 $_REQUEST['user_id'] = $this->otherUser['id'];
1353 $result = api_users_lookup('json');
1354 $this->assertOtherUser($result['users'][0]);
1358 * Test the api_search() function.
1361 public function testApiSearch()
1363 $_REQUEST['q'] = 'reply';
1364 $_REQUEST['max_id'] = 10;
1365 $result = api_search('json');
1366 foreach ($result['status'] as $status) {
1367 $this->assertStatus($status);
1368 $this->assertContains('reply', $status['text'], null, true);
1373 * Test the api_search() function a count parameter.
1376 public function testApiSearchWithCount()
1378 $_REQUEST['q'] = 'reply';
1379 $_REQUEST['count'] = 20;
1380 $result = api_search('json');
1381 foreach ($result['status'] as $status) {
1382 $this->assertStatus($status);
1383 $this->assertContains('reply', $status['text'], null, true);
1388 * Test the api_search() function with an rpp parameter.
1391 public function testApiSearchWithRpp()
1393 $_REQUEST['q'] = 'reply';
1394 $_REQUEST['rpp'] = 20;
1395 $result = api_search('json');
1396 foreach ($result['status'] as $status) {
1397 $this->assertStatus($status);
1398 $this->assertContains('reply', $status['text'], null, true);
1404 * Test the api_search() function without an authenticated user.
1406 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1408 public function testApiSearchWithUnallowedUser()
1410 $_SESSION['allow_api'] = false;
1411 $_GET['screen_name'] = $this->selfUser['nick'];
1416 * Test the api_search() function without any GET query parameter.
1418 * @expectedException Friendica\Network\HTTPException\BadRequestException
1420 public function testApiSearchWithoutQuery()
1426 * Test the api_statuses_home_timeline() function.
1429 public function testApiStatusesHomeTimeline()
1431 $_REQUEST['max_id'] = 10;
1432 $_REQUEST['exclude_replies'] = true;
1433 $_REQUEST['conversation_id'] = 1;
1434 $result = api_statuses_home_timeline('json');
1435 $this->assertNotEmpty($result['status']);
1436 foreach ($result['status'] as $status) {
1437 $this->assertStatus($status);
1442 * Test the api_statuses_home_timeline() function with a negative page parameter.
1445 public function testApiStatusesHomeTimelineWithNegativePage()
1447 $_REQUEST['page'] = -2;
1448 $result = api_statuses_home_timeline('json');
1449 $this->assertNotEmpty($result['status']);
1450 foreach ($result['status'] as $status) {
1451 $this->assertStatus($status);
1456 * Test the api_statuses_home_timeline() with an unallowed user.
1458 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1460 public function testApiStatusesHomeTimelineWithUnallowedUser()
1462 $_SESSION['allow_api'] = false;
1463 $_GET['screen_name'] = $this->selfUser['nick'];
1464 api_statuses_home_timeline('json');
1468 * Test the api_statuses_home_timeline() function with an RSS result.
1471 public function testApiStatusesHomeTimelineWithRss()
1473 $result = api_statuses_home_timeline('rss');
1474 $this->assertXml($result, 'statuses');
1478 * Test the api_statuses_public_timeline() function.
1481 public function testApiStatusesPublicTimeline()
1483 $_REQUEST['max_id'] = 10;
1484 $_REQUEST['conversation_id'] = 1;
1485 $result = api_statuses_public_timeline('json');
1486 $this->assertNotEmpty($result['status']);
1487 foreach ($result['status'] as $status) {
1488 $this->assertStatus($status);
1493 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1496 public function testApiStatusesPublicTimelineWithExcludeReplies()
1498 $_REQUEST['max_id'] = 10;
1499 $_REQUEST['exclude_replies'] = true;
1500 $result = api_statuses_public_timeline('json');
1501 $this->assertNotEmpty($result['status']);
1502 foreach ($result['status'] as $status) {
1503 $this->assertStatus($status);
1508 * Test the api_statuses_public_timeline() function with a negative page parameter.
1511 public function testApiStatusesPublicTimelineWithNegativePage()
1513 $_REQUEST['page'] = -2;
1514 $result = api_statuses_public_timeline('json');
1515 $this->assertNotEmpty($result['status']);
1516 foreach ($result['status'] as $status) {
1517 $this->assertStatus($status);
1522 * Test the api_statuses_public_timeline() function with an unallowed user.
1524 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1526 public function testApiStatusesPublicTimelineWithUnallowedUser()
1528 $_SESSION['allow_api'] = false;
1529 $_GET['screen_name'] = $this->selfUser['nick'];
1530 api_statuses_public_timeline('json');
1534 * Test the api_statuses_public_timeline() function with an RSS result.
1537 public function testApiStatusesPublicTimelineWithRss()
1539 $result = api_statuses_public_timeline('rss');
1540 $this->assertXml($result, 'statuses');
1544 * Test the api_statuses_networkpublic_timeline() function.
1547 public function testApiStatusesNetworkpublicTimeline()
1549 $_REQUEST['max_id'] = 10;
1550 $result = api_statuses_networkpublic_timeline('json');
1551 $this->assertNotEmpty($result['status']);
1552 foreach ($result['status'] as $status) {
1553 $this->assertStatus($status);
1558 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1561 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1563 $_REQUEST['page'] = -2;
1564 $result = api_statuses_networkpublic_timeline('json');
1565 $this->assertNotEmpty($result['status']);
1566 foreach ($result['status'] as $status) {
1567 $this->assertStatus($status);
1572 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1574 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1576 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1578 $_SESSION['allow_api'] = false;
1579 $_GET['screen_name'] = $this->selfUser['nick'];
1580 api_statuses_networkpublic_timeline('json');
1584 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1587 public function testApiStatusesNetworkpublicTimelineWithRss()
1589 $result = api_statuses_networkpublic_timeline('rss');
1590 $this->assertXml($result, 'statuses');
1594 * Test the api_statuses_show() function.
1596 * @expectedException Friendica\Network\HTTPException\BadRequestException
1598 public function testApiStatusesShow()
1600 api_statuses_show('json');
1604 * Test the api_statuses_show() function with an ID.
1607 public function testApiStatusesShowWithId()
1609 $this->app->argv[3] = 1;
1610 $result = api_statuses_show('json');
1611 $this->assertStatus($result['status']);
1615 * Test the api_statuses_show() function with the conversation parameter.
1618 public function testApiStatusesShowWithConversation()
1620 $this->app->argv[3] = 1;
1621 $_REQUEST['conversation'] = 1;
1622 $result = api_statuses_show('json');
1623 $this->assertNotEmpty($result['status']);
1624 foreach ($result['status'] as $status) {
1625 $this->assertStatus($status);
1630 * Test the api_statuses_show() function with an unallowed user.
1632 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1634 public function testApiStatusesShowWithUnallowedUser()
1636 $_SESSION['allow_api'] = false;
1637 $_GET['screen_name'] = $this->selfUser['nick'];
1638 api_statuses_show('json');
1642 * Test the api_conversation_show() function.
1644 * @expectedException Friendica\Network\HTTPException\BadRequestException
1646 public function testApiConversationShow()
1648 api_conversation_show('json');
1652 * Test the api_conversation_show() function with an ID.
1655 public function testApiConversationShowWithId()
1657 $this->app->argv[3] = 1;
1658 $_REQUEST['max_id'] = 10;
1659 $_REQUEST['page'] = -2;
1660 $result = api_conversation_show('json');
1661 $this->assertNotEmpty($result['status']);
1662 foreach ($result['status'] as $status) {
1663 $this->assertStatus($status);
1668 * Test the api_conversation_show() function with an unallowed user.
1670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1672 public function testApiConversationShowWithUnallowedUser()
1674 $_SESSION['allow_api'] = false;
1675 $_GET['screen_name'] = $this->selfUser['nick'];
1676 api_conversation_show('json');
1680 * Test the api_statuses_repeat() function.
1682 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1684 public function testApiStatusesRepeat()
1686 api_statuses_repeat('json');
1690 * Test the api_statuses_repeat() function without an authenticated user.
1692 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1694 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1696 $_SESSION['authenticated'] = false;
1697 api_statuses_repeat('json');
1701 * Test the api_statuses_repeat() function with an ID.
1704 public function testApiStatusesRepeatWithId()
1706 $this->app->argv[3] = 1;
1707 $result = api_statuses_repeat('json');
1708 $this->assertStatus($result['status']);
1710 // Also test with a shared status
1711 $this->app->argv[3] = 5;
1712 $result = api_statuses_repeat('json');
1713 $this->assertStatus($result['status']);
1717 * Test the api_statuses_destroy() function.
1719 * @expectedException Friendica\Network\HTTPException\BadRequestException
1721 public function testApiStatusesDestroy()
1723 api_statuses_destroy('json');
1727 * Test the api_statuses_destroy() function without an authenticated user.
1729 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1731 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1733 $_SESSION['authenticated'] = false;
1734 api_statuses_destroy('json');
1738 * Test the api_statuses_destroy() function with an ID.
1741 public function testApiStatusesDestroyWithId()
1743 $this->app->argv[3] = 1;
1744 $result = api_statuses_destroy('json');
1745 $this->assertStatus($result['status']);
1749 * Test the api_statuses_mentions() function.
1752 public function testApiStatusesMentions()
1754 $this->app->user = ['nickname' => $this->selfUser['nick']];
1755 $_REQUEST['max_id'] = 10;
1756 $result = api_statuses_mentions('json');
1757 $this->assertEmpty($result['status']);
1758 // We should test with mentions in the database.
1762 * Test the api_statuses_mentions() function with a negative page parameter.
1765 public function testApiStatusesMentionsWithNegativePage()
1767 $_REQUEST['page'] = -2;
1768 $result = api_statuses_mentions('json');
1769 $this->assertEmpty($result['status']);
1773 * Test the api_statuses_mentions() function with an unallowed user.
1775 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1777 public function testApiStatusesMentionsWithUnallowedUser()
1779 $_SESSION['allow_api'] = false;
1780 $_GET['screen_name'] = $this->selfUser['nick'];
1781 api_statuses_mentions('json');
1785 * Test the api_statuses_mentions() function with an RSS result.
1788 public function testApiStatusesMentionsWithRss()
1790 $result = api_statuses_mentions('rss');
1791 $this->assertXml($result, 'statuses');
1795 * Test the api_statuses_user_timeline() function.
1798 public function testApiStatusesUserTimeline()
1800 $_REQUEST['max_id'] = 10;
1801 $_REQUEST['exclude_replies'] = true;
1802 $_REQUEST['conversation_id'] = 1;
1803 $result = api_statuses_user_timeline('json');
1804 $this->assertNotEmpty($result['status']);
1805 foreach ($result['status'] as $status) {
1806 $this->assertStatus($status);
1811 * Test the api_statuses_user_timeline() function with a negative page parameter.
1814 public function testApiStatusesUserTimelineWithNegativePage()
1816 $_REQUEST['page'] = -2;
1817 $result = api_statuses_user_timeline('json');
1818 $this->assertNotEmpty($result['status']);
1819 foreach ($result['status'] as $status) {
1820 $this->assertStatus($status);
1825 * Test the api_statuses_user_timeline() function with an RSS result.
1828 public function testApiStatusesUserTimelineWithRss()
1830 $result = api_statuses_user_timeline('rss');
1831 $this->assertXml($result, 'statuses');
1835 * Test the api_statuses_user_timeline() function with an unallowed user.
1837 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1839 public function testApiStatusesUserTimelineWithUnallowedUser()
1841 $_SESSION['allow_api'] = false;
1842 $_GET['screen_name'] = $this->selfUser['nick'];
1843 api_statuses_user_timeline('json');
1847 * Test the api_favorites_create_destroy() function.
1849 * @expectedException Friendica\Network\HTTPException\BadRequestException
1851 public function testApiFavoritesCreateDestroy()
1853 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1854 $this->app->argc = count($this->app->argv);
1855 api_favorites_create_destroy('json');
1859 * Test the api_favorites_create_destroy() function with an invalid ID.
1861 * @expectedException Friendica\Network\HTTPException\BadRequestException
1863 public function testApiFavoritesCreateDestroyWithInvalidId()
1865 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1866 $this->app->argc = count($this->app->argv);
1867 api_favorites_create_destroy('json');
1871 * Test the api_favorites_create_destroy() function with an invalid action.
1873 * @expectedException Friendica\Network\HTTPException\BadRequestException
1875 public function testApiFavoritesCreateDestroyWithInvalidAction()
1877 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1878 $this->app->argc = count($this->app->argv);
1879 $_REQUEST['id'] = 1;
1880 api_favorites_create_destroy('json');
1884 * Test the api_favorites_create_destroy() function with the create action.
1887 public function testApiFavoritesCreateDestroyWithCreateAction()
1889 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1890 $this->app->argc = count($this->app->argv);
1891 $_REQUEST['id'] = 3;
1892 $result = api_favorites_create_destroy('json');
1893 $this->assertStatus($result['status']);
1897 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1900 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1902 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1903 $this->app->argc = count($this->app->argv);
1904 $_REQUEST['id'] = 3;
1905 $result = api_favorites_create_destroy('rss');
1906 $this->assertXml($result, 'status');
1910 * Test the api_favorites_create_destroy() function with the destroy action.
1913 public function testApiFavoritesCreateDestroyWithDestroyAction()
1915 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1916 $this->app->argc = count($this->app->argv);
1917 $_REQUEST['id'] = 3;
1918 $result = api_favorites_create_destroy('json');
1919 $this->assertStatus($result['status']);
1923 * Test the api_favorites_create_destroy() function without an authenticated user.
1925 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1927 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1929 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1930 $this->app->argc = count($this->app->argv);
1931 $_SESSION['authenticated'] = false;
1932 api_favorites_create_destroy('json');
1936 * Test the api_favorites() function.
1939 public function testApiFavorites()
1941 $_REQUEST['page'] = -1;
1942 $_REQUEST['max_id'] = 10;
1943 $result = api_favorites('json');
1944 foreach ($result['status'] as $status) {
1945 $this->assertStatus($status);
1950 * Test the api_favorites() function with an RSS result.
1953 public function testApiFavoritesWithRss()
1955 $result = api_favorites('rss');
1956 $this->assertXml($result, 'statuses');
1960 * Test the api_favorites() function with an unallowed user.
1962 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1964 public function testApiFavoritesWithUnallowedUser()
1966 $_SESSION['allow_api'] = false;
1967 $_GET['screen_name'] = $this->selfUser['nick'];
1968 api_favorites('json');
1972 * Test the api_format_messages() function.
1975 public function testApiFormatMessages()
1977 $result = api_format_messages(
1978 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1979 ['id' => 2, 'screen_name' => 'recipient_name'],
1980 ['id' => 3, 'screen_name' => 'sender_name']
1982 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1983 $this->assertEquals(1, $result['id']);
1984 $this->assertEquals(2, $result['recipient_id']);
1985 $this->assertEquals(3, $result['sender_id']);
1986 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1987 $this->assertEquals('sender_name', $result['sender_screen_name']);
1991 * Test the api_format_messages() function with HTML.
1994 public function testApiFormatMessagesWithHtmlText()
1996 $_GET['getText'] = 'html';
1997 $result = api_format_messages(
1998 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1999 ['id' => 2, 'screen_name' => 'recipient_name'],
2000 ['id' => 3, 'screen_name' => 'sender_name']
2002 $this->assertEquals('item_title', $result['title']);
2003 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2007 * Test the api_format_messages() function with plain text.
2010 public function testApiFormatMessagesWithPlainText()
2012 $_GET['getText'] = 'plain';
2013 $result = api_format_messages(
2014 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2015 ['id' => 2, 'screen_name' => 'recipient_name'],
2016 ['id' => 3, 'screen_name' => 'sender_name']
2018 $this->assertEquals('item_title', $result['title']);
2019 $this->assertEquals('item_body', $result['text']);
2023 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2026 public function testApiFormatMessagesWithoutUserObjects()
2028 $_GET['getUserObjects'] = 'false';
2029 $result = api_format_messages(
2030 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2031 ['id' => 2, 'screen_name' => 'recipient_name'],
2032 ['id' => 3, 'screen_name' => 'sender_name']
2034 $this->assertTrue(!isset($result['sender']));
2035 $this->assertTrue(!isset($result['recipient']));
2039 * Test the api_convert_item() function.
2042 public function testApiConvertItem()
2044 $result = api_convert_item(
2046 'network' => 'feed',
2047 'title' => 'item_title',
2048 // We need a long string to test that it is correctly cut
2049 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2050 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2051 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2052 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2053 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2054 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2055 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2056 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2057 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2058 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2059 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2060 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2061 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2062 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2063 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2064 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2065 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2066 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2067 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2068 'repellat officia illum quos impedit quam iste esse unde qui '.
2069 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2070 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2071 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2072 'plink' => 'item_plink'
2075 $this->assertStringStartsWith('item_title', $result['text']);
2076 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2080 * Test the api_convert_item() function with an empty item body.
2083 public function testApiConvertItemWithoutBody()
2085 $result = api_convert_item(
2087 'network' => 'feed',
2088 'title' => 'item_title',
2090 'plink' => 'item_plink'
2093 $this->assertEquals('item_title', $result['text']);
2094 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2098 * Test the api_convert_item() function with the title in the body.
2101 public function testApiConvertItemWithTitleInBody()
2103 $result = api_convert_item(
2105 'title' => 'item_title',
2106 'body' => 'item_title item_body'
2109 $this->assertEquals('item_title item_body', $result['text']);
2110 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2114 * Test the api_get_attachments() function.
2117 public function testApiGetAttachments()
2120 $this->assertEmpty(api_get_attachments($body));
2124 * Test the api_get_attachments() function with an img tag.
2127 public function testApiGetAttachmentsWithImage()
2129 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2130 $this->assertInternalType('array', api_get_attachments($body));
2134 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2137 public function testApiGetAttachmentsWithImageAndAndStatus()
2139 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2140 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2141 $this->assertInternalType('array', api_get_attachments($body));
2145 * Test the api_get_entitities() function.
2148 public function testApiGetEntitities()
2151 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2155 * Test the api_get_entitities() function with the include_entities parameter.
2158 public function testApiGetEntititiesWithIncludeEntities()
2160 $_REQUEST['include_entities'] = 'true';
2162 $result = api_get_entitities($text, 'bbcode');
2163 $this->assertInternalType('array', $result['hashtags']);
2164 $this->assertInternalType('array', $result['symbols']);
2165 $this->assertInternalType('array', $result['urls']);
2166 $this->assertInternalType('array', $result['user_mentions']);
2170 * Test the api_format_items_embeded_images() function.
2173 public function testApiFormatItemsEmbededImages()
2175 $this->assertEquals(
2176 'text ' . System::baseUrl() . '/display/item_guid',
2177 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2182 * Test the api_contactlink_to_array() function.
2185 public function testApiContactlinkToArray()
2187 $this->assertEquals(
2192 api_contactlink_to_array('text')
2197 * Test the api_contactlink_to_array() function with an URL.
2200 public function testApiContactlinkToArrayWithUrl()
2202 $this->assertEquals(
2204 'name' => ['link_text'],
2207 api_contactlink_to_array('text <a href="url">link_text</a>')
2212 * Test the api_format_items_activities() function.
2215 public function testApiFormatItemsActivities()
2217 $item = ['uid' => 0, 'uri' => ''];
2218 $result = api_format_items_activities($item);
2219 $this->assertArrayHasKey('like', $result);
2220 $this->assertArrayHasKey('dislike', $result);
2221 $this->assertArrayHasKey('attendyes', $result);
2222 $this->assertArrayHasKey('attendno', $result);
2223 $this->assertArrayHasKey('attendmaybe', $result);
2227 * Test the api_format_items_activities() function with an XML result.
2230 public function testApiFormatItemsActivitiesWithXml()
2232 $item = ['uid' => 0, 'uri' => ''];
2233 $result = api_format_items_activities($item, 'xml');
2234 $this->assertArrayHasKey('friendica:like', $result);
2235 $this->assertArrayHasKey('friendica:dislike', $result);
2236 $this->assertArrayHasKey('friendica:attendyes', $result);
2237 $this->assertArrayHasKey('friendica:attendno', $result);
2238 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2242 * Test the api_format_items_profiles() function.
2245 public function testApiFormatItemsProfiles()
2248 'id' => 'profile_id',
2249 'profile-name' => 'profile_name',
2250 'is-default' => true,
2251 'hide-friends' => true,
2252 'photo' => 'profile_photo',
2253 'thumb' => 'profile_thumb',
2255 'net-publish' => true,
2256 'pdesc' => 'description',
2257 'dob' => 'date_of_birth',
2258 'address' => 'address',
2259 'locality' => 'city',
2260 'region' => 'region',
2261 'postal-code' => 'postal_code',
2262 'country-name' => 'country',
2263 'hometown' => 'hometown',
2264 'gender' => 'gender',
2265 'marital' => 'marital',
2266 'with' => 'marital_with',
2267 'howlong' => 'marital_since',
2268 'sexual' => 'sexual',
2269 'politic' => 'politic',
2270 'religion' => 'religion',
2271 'pub_keywords' => 'public_keywords',
2272 'prv_keywords' => 'private_keywords',
2275 'dislikes' => 'dislikes',
2281 'interest' => 'interest',
2282 'romance' => 'romance',
2284 'education' => 'education',
2285 'contact' => 'social_networks',
2286 'homepage' => 'homepage'
2288 $result = api_format_items_profiles($profile_row);
2289 $this->assertEquals(
2291 'profile_id' => 'profile_id',
2292 'profile_name' => 'profile_name',
2293 'is_default' => true,
2294 'hide_friends' => true,
2295 'profile_photo' => 'profile_photo',
2296 'profile_thumb' => 'profile_thumb',
2298 'net_publish' => true,
2299 'description' => 'description',
2300 'date_of_birth' => 'date_of_birth',
2301 'address' => 'address',
2303 'region' => 'region',
2304 'postal_code' => 'postal_code',
2305 'country' => 'country',
2306 'hometown' => 'hometown',
2307 'gender' => 'gender',
2308 'marital' => 'marital',
2309 'marital_with' => 'marital_with',
2310 'marital_since' => 'marital_since',
2311 'sexual' => 'sexual',
2312 'politic' => 'politic',
2313 'religion' => 'religion',
2314 'public_keywords' => 'public_keywords',
2315 'private_keywords' => 'private_keywords',
2318 'dislikes' => 'dislikes',
2324 'interest' => 'interest',
2325 'romance' => 'romance',
2327 'education' => 'education',
2328 'social_networks' => 'social_networks',
2329 'homepage' => 'homepage',
2337 * Test the api_format_items() function.
2340 public function testApiFormatItems()
2344 'item_network' => 'item_network',
2350 'author-network' => Protocol::DFRN,
2351 'author-link' => 'http://localhost/profile/othercontact',
2355 $result = api_format_items($items, ['id' => 0], true);
2356 foreach ($result as $status) {
2357 $this->assertStatus($status);
2362 * Test the api_format_items() function with an XML result.
2365 public function testApiFormatItemsWithXml()
2373 'author-network' => Protocol::DFRN,
2374 'author-link' => 'http://localhost/profile/othercontact',
2378 $result = api_format_items($items, ['id' => 0], true, 'xml');
2379 foreach ($result as $status) {
2380 $this->assertStatus($status);
2385 * Test the api_format_items() function.
2388 public function testApiAccountRateLimitStatus()
2390 $result = api_account_rate_limit_status('json');
2391 $this->assertEquals(150, $result['hash']['remaining_hits']);
2392 $this->assertEquals(150, $result['hash']['hourly_limit']);
2393 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2397 * Test the api_format_items() function with an XML result.
2400 public function testApiAccountRateLimitStatusWithXml()
2402 $result = api_account_rate_limit_status('xml');
2403 $this->assertXml($result, 'hash');
2407 * Test the api_help_test() function.
2410 public function testApiHelpTest()
2412 $result = api_help_test('json');
2413 $this->assertEquals(['ok' => 'ok'], $result);
2417 * Test the api_help_test() function with an XML result.
2420 public function testApiHelpTestWithXml()
2422 $result = api_help_test('xml');
2423 $this->assertXml($result, 'ok');
2427 * Test the api_lists_list() function.
2430 public function testApiListsList()
2432 $result = api_lists_list('json');
2433 $this->assertEquals(['lists_list' => []], $result);
2437 * Test the api_lists_ownerships() function.
2440 public function testApiListsOwnerships()
2442 $result = api_lists_ownerships('json');
2443 foreach ($result['lists']['lists'] as $list) {
2444 $this->assertList($list);
2449 * Test the api_lists_ownerships() function without an authenticated user.
2451 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2453 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2455 $_SESSION['authenticated'] = false;
2456 api_lists_ownerships('json');
2460 * Test the api_lists_statuses() function.
2461 * @expectedException Friendica\Network\HTTPException\BadRequestException
2464 public function testApiListsStatuses()
2466 api_lists_statuses('json');
2470 * Test the api_lists_statuses() function with a list ID.
2473 public function testApiListsStatusesWithListId()
2475 $_REQUEST['list_id'] = 1;
2476 $_REQUEST['page'] = -1;
2477 $_REQUEST['max_id'] = 10;
2478 $result = api_lists_statuses('json');
2479 foreach ($result['status'] as $status) {
2480 $this->assertStatus($status);
2485 * Test the api_lists_statuses() function with a list ID and a RSS result.
2488 public function testApiListsStatusesWithListIdAndRss()
2490 $_REQUEST['list_id'] = 1;
2491 $result = api_lists_statuses('rss');
2492 $this->assertXml($result, 'statuses');
2496 * Test the api_lists_statuses() function with an unallowed user.
2498 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2500 public function testApiListsStatusesWithUnallowedUser()
2502 $_SESSION['allow_api'] = false;
2503 $_GET['screen_name'] = $this->selfUser['nick'];
2504 api_lists_statuses('json');
2508 * Test the api_statuses_f() function.
2511 public function testApiStatusesFWithFriends()
2514 $result = api_statuses_f('friends');
2515 $this->assertArrayHasKey('user', $result);
2519 * Test the api_statuses_f() function.
2522 public function testApiStatusesFWithFollowers()
2524 $result = api_statuses_f('followers');
2525 $this->assertArrayHasKey('user', $result);
2529 * Test the api_statuses_f() function.
2532 public function testApiStatusesFWithBlocks()
2534 $result = api_statuses_f('blocks');
2535 $this->assertArrayHasKey('user', $result);
2539 * Test the api_statuses_f() function.
2542 public function testApiStatusesFWithIncoming()
2544 $result = api_statuses_f('incoming');
2545 $this->assertArrayHasKey('user', $result);
2549 * Test the api_statuses_f() function an undefined cursor GET variable.
2552 public function testApiStatusesFWithUndefinedCursor()
2554 $_GET['cursor'] = 'undefined';
2555 $this->assertFalse(api_statuses_f('friends'));
2559 * Test the api_statuses_friends() function.
2562 public function testApiStatusesFriends()
2564 $result = api_statuses_friends('json');
2565 $this->assertArrayHasKey('user', $result);
2569 * Test the api_statuses_friends() function an undefined cursor GET variable.
2572 public function testApiStatusesFriendsWithUndefinedCursor()
2574 $_GET['cursor'] = 'undefined';
2575 $this->assertFalse(api_statuses_friends('json'));
2579 * Test the api_statuses_followers() function.
2582 public function testApiStatusesFollowers()
2584 $result = api_statuses_followers('json');
2585 $this->assertArrayHasKey('user', $result);
2589 * Test the api_statuses_followers() function an undefined cursor GET variable.
2592 public function testApiStatusesFollowersWithUndefinedCursor()
2594 $_GET['cursor'] = 'undefined';
2595 $this->assertFalse(api_statuses_followers('json'));
2599 * Test the api_blocks_list() function.
2602 public function testApiBlocksList()
2604 $result = api_blocks_list('json');
2605 $this->assertArrayHasKey('user', $result);
2609 * Test the api_blocks_list() function an undefined cursor GET variable.
2612 public function testApiBlocksListWithUndefinedCursor()
2614 $_GET['cursor'] = 'undefined';
2615 $this->assertFalse(api_blocks_list('json'));
2619 * Test the api_friendships_incoming() function.
2622 public function testApiFriendshipsIncoming()
2624 $result = api_friendships_incoming('json');
2625 $this->assertArrayHasKey('id', $result);
2629 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2632 public function testApiFriendshipsIncomingWithUndefinedCursor()
2634 $_GET['cursor'] = 'undefined';
2635 $this->assertFalse(api_friendships_incoming('json'));
2639 * Test the api_statusnet_config() function.
2642 public function testApiStatusnetConfig()
2644 $result = api_statusnet_config('json');
2645 $this->assertEquals('localhost', $result['config']['site']['server']);
2646 $this->assertEquals('default', $result['config']['site']['theme']);
2647 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2648 $this->assertTrue($result['config']['site']['fancy']);
2649 $this->assertEquals('en', $result['config']['site']['language']);
2650 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2651 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2652 $this->assertEquals('false', $result['config']['site']['private']);
2653 $this->assertEquals('false', $result['config']['site']['ssl']);
2654 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2658 * Test the api_statusnet_version() function.
2661 public function testApiStatusnetVersion()
2663 $result = api_statusnet_version('json');
2664 $this->assertEquals('0.9.7', $result['version']);
2668 * Test the api_ff_ids() function.
2671 public function testApiFfIds()
2673 $result = api_ff_ids('json');
2674 $this->assertNull($result);
2678 * Test the api_ff_ids() function with a result.
2681 public function testApiFfIdsWithResult()
2683 $this->markTestIncomplete();
2687 * Test the api_ff_ids() function without an authenticated user.
2689 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2691 public function testApiFfIdsWithoutAuthenticatedUser()
2693 $_SESSION['authenticated'] = false;
2698 * Test the api_friends_ids() function.
2701 public function testApiFriendsIds()
2703 $result = api_friends_ids('json');
2704 $this->assertNull($result);
2708 * Test the api_followers_ids() function.
2711 public function testApiFollowersIds()
2713 $result = api_followers_ids('json');
2714 $this->assertNull($result);
2718 * Test the api_direct_messages_new() function.
2721 public function testApiDirectMessagesNew()
2723 $result = api_direct_messages_new('json');
2724 $this->assertNull($result);
2728 * Test the api_direct_messages_new() function without an authenticated user.
2730 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2732 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2734 $_SESSION['authenticated'] = false;
2735 api_direct_messages_new('json');
2739 * Test the api_direct_messages_new() function with an user ID.
2742 public function testApiDirectMessagesNewWithUserId()
2744 $_POST['text'] = 'message_text';
2745 $_POST['user_id'] = $this->otherUser['id'];
2746 $result = api_direct_messages_new('json');
2747 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2751 * Test the api_direct_messages_new() function with a screen name.
2754 public function testApiDirectMessagesNewWithScreenName()
2756 $_POST['text'] = 'message_text';
2757 $_POST['screen_name'] = $this->friendUser['nick'];
2758 $result = api_direct_messages_new('json');
2759 $this->assertEquals(1, $result['direct_message']['id']);
2760 $this->assertContains('message_text', $result['direct_message']['text']);
2761 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2762 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2766 * Test the api_direct_messages_new() function with a title.
2769 public function testApiDirectMessagesNewWithTitle()
2771 $_POST['text'] = 'message_text';
2772 $_POST['screen_name'] = $this->friendUser['nick'];
2773 $_REQUEST['title'] = 'message_title';
2774 $result = api_direct_messages_new('json');
2775 $this->assertEquals(1, $result['direct_message']['id']);
2776 $this->assertContains('message_text', $result['direct_message']['text']);
2777 $this->assertContains('message_title', $result['direct_message']['text']);
2778 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2779 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2783 * Test the api_direct_messages_new() function with an RSS result.
2786 public function testApiDirectMessagesNewWithRss()
2788 $_POST['text'] = 'message_text';
2789 $_POST['screen_name'] = $this->friendUser['nick'];
2790 $result = api_direct_messages_new('rss');
2791 $this->assertXml($result, 'direct-messages');
2795 * Test the api_direct_messages_destroy() function.
2797 * @expectedException Friendica\Network\HTTPException\BadRequestException
2799 public function testApiDirectMessagesDestroy()
2801 api_direct_messages_destroy('json');
2805 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2808 public function testApiDirectMessagesDestroyWithVerbose()
2810 $_GET['friendica_verbose'] = 'true';
2811 $result = api_direct_messages_destroy('json');
2812 $this->assertEquals(
2815 'result' => 'error',
2816 'message' => 'message id or parenturi not specified'
2824 * Test the api_direct_messages_destroy() function without an authenticated user.
2826 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2828 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2830 $_SESSION['authenticated'] = false;
2831 api_direct_messages_destroy('json');
2835 * Test the api_direct_messages_destroy() function with a non-zero ID.
2837 * @expectedException Friendica\Network\HTTPException\BadRequestException
2839 public function testApiDirectMessagesDestroyWithId()
2841 $_REQUEST['id'] = 1;
2842 api_direct_messages_destroy('json');
2846 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2849 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2851 $_REQUEST['id'] = 1;
2852 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2853 $_GET['friendica_verbose'] = 'true';
2854 $result = api_direct_messages_destroy('json');
2855 $this->assertEquals(
2858 'result' => 'error',
2859 'message' => 'message id not in database'
2867 * Test the api_direct_messages_destroy() function with a non-zero ID.
2870 public function testApiDirectMessagesDestroyWithCorrectId()
2872 $this->markTestIncomplete('We need to add a dataset for this.');
2876 * Test the api_direct_messages_box() function.
2879 public function testApiDirectMessagesBoxWithSentbox()
2881 $_REQUEST['page'] = -1;
2882 $_REQUEST['max_id'] = 10;
2883 $result = api_direct_messages_box('json', 'sentbox', 'false');
2884 $this->assertArrayHasKey('direct_message', $result);
2888 * Test the api_direct_messages_box() function.
2891 public function testApiDirectMessagesBoxWithConversation()
2893 $result = api_direct_messages_box('json', 'conversation', 'false');
2894 $this->assertArrayHasKey('direct_message', $result);
2898 * Test the api_direct_messages_box() function.
2901 public function testApiDirectMessagesBoxWithAll()
2903 $result = api_direct_messages_box('json', 'all', 'false');
2904 $this->assertArrayHasKey('direct_message', $result);
2908 * Test the api_direct_messages_box() function.
2911 public function testApiDirectMessagesBoxWithInbox()
2913 $result = api_direct_messages_box('json', 'inbox', 'false');
2914 $this->assertArrayHasKey('direct_message', $result);
2918 * Test the api_direct_messages_box() function.
2921 public function testApiDirectMessagesBoxWithVerbose()
2923 $result = api_direct_messages_box('json', 'sentbox', 'true');
2924 $this->assertEquals(
2927 'result' => 'error',
2928 'message' => 'no mails available'
2936 * Test the api_direct_messages_box() function with a RSS result.
2939 public function testApiDirectMessagesBoxWithRss()
2941 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2942 $this->assertXml($result, 'direct-messages');
2946 * Test the api_direct_messages_box() function without an authenticated user.
2948 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2950 public function testApiDirectMessagesBoxWithUnallowedUser()
2952 $_SESSION['allow_api'] = false;
2953 $_GET['screen_name'] = $this->selfUser['nick'];
2954 api_direct_messages_box('json', 'sentbox', 'false');
2958 * Test the api_direct_messages_sentbox() function.
2961 public function testApiDirectMessagesSentbox()
2963 $result = api_direct_messages_sentbox('json');
2964 $this->assertArrayHasKey('direct_message', $result);
2968 * Test the api_direct_messages_inbox() function.
2971 public function testApiDirectMessagesInbox()
2973 $result = api_direct_messages_inbox('json');
2974 $this->assertArrayHasKey('direct_message', $result);
2978 * Test the api_direct_messages_all() function.
2981 public function testApiDirectMessagesAll()
2983 $result = api_direct_messages_all('json');
2984 $this->assertArrayHasKey('direct_message', $result);
2988 * Test the api_direct_messages_conversation() function.
2991 public function testApiDirectMessagesConversation()
2993 $result = api_direct_messages_conversation('json');
2994 $this->assertArrayHasKey('direct_message', $result);
2998 * Test the api_oauth_request_token() function.
3001 public function testApiOauthRequestToken()
3003 $this->markTestIncomplete('killme() kills phpunit as well');
3007 * Test the api_oauth_access_token() function.
3010 public function testApiOauthAccessToken()
3012 $this->markTestIncomplete('killme() kills phpunit as well');
3016 * Test the api_fr_photoalbum_delete() function.
3018 * @expectedException Friendica\Network\HTTPException\BadRequestException
3020 public function testApiFrPhotoalbumDelete()
3022 api_fr_photoalbum_delete('json');
3026 * Test the api_fr_photoalbum_delete() function with an album name.
3028 * @expectedException Friendica\Network\HTTPException\BadRequestException
3030 public function testApiFrPhotoalbumDeleteWithAlbum()
3032 $_REQUEST['album'] = 'album_name';
3033 api_fr_photoalbum_delete('json');
3037 * Test the api_fr_photoalbum_delete() function with an album name.
3040 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3042 $this->markTestIncomplete('We need to add a dataset for this.');
3046 * Test the api_fr_photoalbum_delete() function.
3048 * @expectedException Friendica\Network\HTTPException\BadRequestException
3050 public function testApiFrPhotoalbumUpdate()
3052 api_fr_photoalbum_update('json');
3056 * Test the api_fr_photoalbum_delete() function with an album name.
3058 * @expectedException Friendica\Network\HTTPException\BadRequestException
3060 public function testApiFrPhotoalbumUpdateWithAlbum()
3062 $_REQUEST['album'] = 'album_name';
3063 api_fr_photoalbum_update('json');
3067 * Test the api_fr_photoalbum_delete() function with an album name.
3069 * @expectedException Friendica\Network\HTTPException\BadRequestException
3071 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3073 $_REQUEST['album'] = 'album_name';
3074 $_REQUEST['album_new'] = 'album_name';
3075 api_fr_photoalbum_update('json');
3079 * Test the api_fr_photoalbum_update() function without an authenticated user.
3081 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3083 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3085 $_SESSION['authenticated'] = false;
3086 api_fr_photoalbum_update('json');
3090 * Test the api_fr_photoalbum_delete() function with an album name.
3093 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3095 $this->markTestIncomplete('We need to add a dataset for this.');
3099 * Test the api_fr_photos_list() function.
3102 public function testApiFrPhotosList()
3104 $result = api_fr_photos_list('json');
3105 $this->assertArrayHasKey('photo', $result);
3109 * Test the api_fr_photos_list() function without an authenticated user.
3111 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3113 public function testApiFrPhotosListWithoutAuthenticatedUser()
3115 $_SESSION['authenticated'] = false;
3116 api_fr_photos_list('json');
3120 * Test the api_fr_photo_create_update() function.
3122 * @expectedException Friendica\Network\HTTPException\BadRequestException
3124 public function testApiFrPhotoCreateUpdate()
3126 api_fr_photo_create_update('json');
3130 * Test the api_fr_photo_create_update() function without an authenticated user.
3132 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3134 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3136 $_SESSION['authenticated'] = false;
3137 api_fr_photo_create_update('json');
3141 * Test the api_fr_photo_create_update() function with an album name.
3143 * @expectedException Friendica\Network\HTTPException\BadRequestException
3145 public function testApiFrPhotoCreateUpdateWithAlbum()
3147 $_REQUEST['album'] = 'album_name';
3148 api_fr_photo_create_update('json');
3152 * Test the api_fr_photo_create_update() function with the update mode.
3155 public function testApiFrPhotoCreateUpdateWithUpdate()
3157 $this->markTestIncomplete('We need to create a dataset for this');
3161 * Test the api_fr_photo_create_update() function with an uploaded file.
3164 public function testApiFrPhotoCreateUpdateWithFile()
3166 $this->markTestIncomplete();
3170 * Test the api_fr_photo_delete() function.
3172 * @expectedException Friendica\Network\HTTPException\BadRequestException
3174 public function testApiFrPhotoDelete()
3176 api_fr_photo_delete('json');
3180 * Test the api_fr_photo_delete() function without an authenticated user.
3182 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3184 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3186 $_SESSION['authenticated'] = false;
3187 api_fr_photo_delete('json');
3191 * Test the api_fr_photo_delete() function with a photo ID.
3193 * @expectedException Friendica\Network\HTTPException\BadRequestException
3195 public function testApiFrPhotoDeleteWithPhotoId()
3197 $_REQUEST['photo_id'] = 1;
3198 api_fr_photo_delete('json');
3202 * Test the api_fr_photo_delete() function with a correct photo ID.
3205 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3207 $this->markTestIncomplete('We need to create a dataset for this.');
3211 * Test the api_fr_photo_detail() function.
3213 * @expectedException Friendica\Network\HTTPException\BadRequestException
3215 public function testApiFrPhotoDetail()
3217 api_fr_photo_detail('json');
3221 * Test the api_fr_photo_detail() function without an authenticated user.
3223 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3225 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3227 $_SESSION['authenticated'] = false;
3228 api_fr_photo_detail('json');
3232 * Test the api_fr_photo_detail() function with a photo ID.
3234 * @expectedException Friendica\Network\HTTPException\NotFoundException
3236 public function testApiFrPhotoDetailWithPhotoId()
3238 $_REQUEST['photo_id'] = 1;
3239 api_fr_photo_detail('json');
3243 * Test the api_fr_photo_detail() function with a correct photo ID.
3246 public function testApiFrPhotoDetailCorrectPhotoId()
3248 $this->markTestIncomplete('We need to create a dataset for this.');
3252 * Test the api_account_update_profile_image() function.
3254 * @expectedException Friendica\Network\HTTPException\BadRequestException
3256 public function testApiAccountUpdateProfileImage()
3258 api_account_update_profile_image('json');
3262 * Test the api_account_update_profile_image() function without an authenticated user.
3264 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3266 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3268 $_SESSION['authenticated'] = false;
3269 api_account_update_profile_image('json');
3273 * Test the api_account_update_profile_image() function with an uploaded file.
3275 * @expectedException Friendica\Network\HTTPException\BadRequestException
3277 public function testApiAccountUpdateProfileImageWithUpload()
3279 $this->markTestIncomplete();
3284 * Test the api_account_update_profile() function.
3287 public function testApiAccountUpdateProfile()
3289 $_POST['name'] = 'new_name';
3290 $_POST['description'] = 'new_description';
3291 $result = api_account_update_profile('json');
3292 // We can't use assertSelfUser() here because the user object is missing some properties.
3293 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3294 $this->assertEquals('Friendica', $result['user']['location']);
3295 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3296 $this->assertEquals('dfrn', $result['user']['network']);
3297 $this->assertEquals('new_name', $result['user']['name']);
3298 $this->assertEquals('new_description', $result['user']['description']);
3302 * Test the check_acl_input() function.
3305 public function testCheckAclInput()
3307 $result = check_acl_input('<aclstring>');
3308 // Where does this result come from?
3309 $this->assertEquals(1, $result);
3313 * Test the check_acl_input() function with an empty ACL string.
3316 public function testCheckAclInputWithEmptyAclString()
3318 $result = check_acl_input(' ');
3319 $this->assertFalse($result);
3323 * Test the save_media_to_database() function.
3326 public function testSaveMediaToDatabase()
3328 $this->markTestIncomplete();
3332 * Test the post_photo_item() function.
3335 public function testPostPhotoItem()
3337 $this->markTestIncomplete();
3341 * Test the prepare_photo_data() function.
3344 public function testPreparePhotoData()
3346 $this->markTestIncomplete();
3350 * Test the api_friendica_remoteauth() function.
3352 * @expectedException Friendica\Network\HTTPException\BadRequestException
3354 public function testApiFriendicaRemoteauth()
3356 api_friendica_remoteauth();
3360 * Test the api_friendica_remoteauth() function with an URL.
3362 * @expectedException Friendica\Network\HTTPException\BadRequestException
3364 public function testApiFriendicaRemoteauthWithUrl()
3366 $_GET['url'] = 'url';
3367 $_GET['c_url'] = 'url';
3368 api_friendica_remoteauth();
3372 * Test the api_friendica_remoteauth() function with a correct URL.
3375 public function testApiFriendicaRemoteauthWithCorrectUrl()
3377 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3378 $_GET['url'] = 'url';
3379 $_GET['c_url'] = $this->selfUser['nurl'];
3380 api_friendica_remoteauth();
3384 * Test the api_share_as_retweet() function.
3387 public function testApiShareAsRetweet()
3389 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3390 $result = api_share_as_retweet($item);
3391 $this->assertFalse($result);
3395 * Test the api_share_as_retweet() function with a valid item.
3398 public function testApiShareAsRetweetWithValidItem()
3400 $this->markTestIncomplete();
3404 * Test the api_get_nick() function.
3407 public function testApiGetNick()
3409 $result = api_get_nick($this->otherUser['nurl']);
3410 $this->assertEquals('othercontact', $result);
3414 * Test the api_get_nick() function with a wrong URL.
3417 public function testApiGetNickWithWrongUrl()
3419 $result = api_get_nick('wrong_url');
3420 $this->assertFalse($result);
3424 * Test the api_in_reply_to() function.
3427 public function testApiInReplyTo()
3429 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3430 $this->assertArrayHasKey('status_id', $result);
3431 $this->assertArrayHasKey('user_id', $result);
3432 $this->assertArrayHasKey('status_id_str', $result);
3433 $this->assertArrayHasKey('user_id_str', $result);
3434 $this->assertArrayHasKey('screen_name', $result);
3438 * Test the api_in_reply_to() function with a valid item.
3441 public function testApiInReplyToWithValidItem()
3443 $this->markTestIncomplete();
3447 * Test the api_clean_plain_items() function.
3450 public function testApiCleanPlainItems()
3452 $_REQUEST['include_entities'] = 'true';
3453 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3454 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3458 * Test the api_clean_attachments() function.
3461 public function testApiCleanAttachments()
3463 $this->markTestIncomplete();
3467 * Test the api_best_nickname() function.
3470 public function testApiBestNickname()
3473 $result = api_best_nickname($contacts);
3474 $this->assertNull($result);
3478 * Test the api_best_nickname() function with contacts.
3481 public function testApiBestNicknameWithContacts()
3483 $this->markTestIncomplete();
3487 * Test the api_friendica_group_show() function.
3490 public function testApiFriendicaGroupShow()
3492 $this->markTestIncomplete();
3496 * Test the api_friendica_group_delete() function.
3499 public function testApiFriendicaGroupDelete()
3501 $this->markTestIncomplete();
3505 * Test the api_lists_destroy() function.
3508 public function testApiListsDestroy()
3510 $this->markTestIncomplete();
3514 * Test the group_create() function.
3517 public function testGroupCreate()
3519 $this->markTestIncomplete();
3523 * Test the api_friendica_group_create() function.
3526 public function testApiFriendicaGroupCreate()
3528 $this->markTestIncomplete();
3532 * Test the api_lists_create() function.
3535 public function testApiListsCreate()
3537 $this->markTestIncomplete();
3541 * Test the api_friendica_group_update() function.
3544 public function testApiFriendicaGroupUpdate()
3546 $this->markTestIncomplete();
3550 * Test the api_lists_update() function.
3553 public function testApiListsUpdate()
3555 $this->markTestIncomplete();
3559 * Test the api_friendica_activity() function.
3562 public function testApiFriendicaActivity()
3564 $this->markTestIncomplete();
3568 * Test the api_friendica_notification() function.
3570 * @expectedException Friendica\Network\HTTPException\BadRequestException
3572 public function testApiFriendicaNotification()
3574 api_friendica_notification('json');
3578 * Test the api_friendica_notification() function without an authenticated user.
3580 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3582 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3584 $_SESSION['authenticated'] = false;
3585 api_friendica_notification('json');
3589 * Test the api_friendica_notification() function with an argument count.
3592 public function testApiFriendicaNotificationWithArgumentCount()
3594 $this->app->argv = ['api', 'friendica', 'notification'];
3595 $this->app->argc = count($this->app->argv);
3596 $result = api_friendica_notification('json');
3597 $this->assertEquals(['note' => false], $result);
3601 * Test the api_friendica_notification() function with an XML result.
3604 public function testApiFriendicaNotificationWithXmlResult()
3606 $this->app->argv = ['api', 'friendica', 'notification'];
3607 $this->app->argc = count($this->app->argv);
3608 $result = api_friendica_notification('xml');
3609 $this->assertXml($result, 'notes');
3613 * Test the api_friendica_notification_seen() function.
3616 public function testApiFriendicaNotificationSeen()
3618 $this->markTestIncomplete();
3622 * Test the api_friendica_direct_messages_setseen() function.
3625 public function testApiFriendicaDirectMessagesSetseen()
3627 $this->markTestIncomplete();
3631 * Test the api_friendica_direct_messages_search() function.
3634 public function testApiFriendicaDirectMessagesSearch()
3636 $this->markTestIncomplete();
3640 * Test the api_friendica_profile_show() function.
3643 public function testApiFriendicaProfileShow()
3645 $result = api_friendica_profile_show('json');
3646 // We can't use assertSelfUser() here because the user object is missing some properties.
3647 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3648 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3649 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3650 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3651 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3652 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3653 $this->assertFalse($result['$result']['multi_profiles']);
3657 * Test the api_friendica_profile_show() function with a profile ID.
3660 public function testApiFriendicaProfileShowWithProfileId()
3662 $this->markTestIncomplete('We need to add a dataset for this.');
3666 * Test the api_friendica_profile_show() function with a wrong profile ID.
3668 * @expectedException Friendica\Network\HTTPException\BadRequestException
3670 public function testApiFriendicaProfileShowWithWrongProfileId()
3672 $_REQUEST['profile_id'] = 666;
3673 api_friendica_profile_show('json');
3677 * Test the api_friendica_profile_show() function without an authenticated user.
3679 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3681 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3683 $_SESSION['authenticated'] = false;
3684 api_friendica_profile_show('json');
3688 * Test the api_saved_searches_list() function.
3691 public function testApiSavedSearchesList()
3693 $result = api_saved_searches_list('json');
3694 $this->assertEquals(1, $result['terms'][0]['id']);
3695 $this->assertEquals(1, $result['terms'][0]['id_str']);
3696 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3697 $this->assertEquals('Saved search', $result['terms'][0]['query']);