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 protected function setUp()
31 // Reusable App object
32 $this->app = BaseObject::getApp();
34 // User data that the test database is populated with
37 'name' => 'Self contact',
38 'nick' => 'selfcontact',
39 'nurl' => 'http://localhost/profile/selfcontact'
43 'name' => 'Friend contact',
44 'nick' => 'friendcontact',
45 'nurl' => 'http://localhost/profile/friendcontact'
49 'name' => 'othercontact',
50 'nick' => 'othercontact',
51 'nurl' => 'http://localhost/profile/othercontact'
54 // User ID that we know is not in the database
55 $this->wrongUserId = 666;
57 // Most API require login so we force the session
60 'authenticated' => true,
61 'uid' => $this->selfUser['id']
65 Config::set('config', 'hostname', 'localhost');
66 Config::set('system', 'throttle_limit_day', 100);
67 Config::set('system', 'throttle_limit_week', 100);
68 Config::set('system', 'throttle_limit_month', 100);
69 Config::set('system', 'theme', 'system_theme');
73 * Cleanup variables used by tests.
75 protected function tearDown()
81 $app->argv = ['home'];
85 * Assert that an user array contains expected keys.
86 * @param array $user User array
89 private function assertSelfUser(array $user)
91 $this->assertEquals($this->selfUser['id'], $user['uid']);
92 $this->assertEquals($this->selfUser['id'], $user['cid']);
93 $this->assertEquals(1, $user['self']);
94 $this->assertEquals('Friendica', $user['location']);
95 $this->assertEquals($this->selfUser['name'], $user['name']);
96 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
97 $this->assertEquals('dfrn', $user['network']);
98 $this->assertTrue($user['verified']);
102 * Assert that an user array contains expected keys.
103 * @param array $user User array
106 private function assertOtherUser(array $user)
108 $this->assertEquals($this->otherUser['id'], $user['id']);
109 $this->assertEquals($this->otherUser['id'], $user['id_str']);
110 $this->assertEquals(0, $user['self']);
111 $this->assertEquals($this->otherUser['name'], $user['name']);
112 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
113 $this->assertFalse($user['verified']);
117 * Assert that a status array contains expected keys.
118 * @param array $status Status array
121 private function assertStatus(array $status)
123 $this->assertInternalType('string', $status['text']);
124 $this->assertInternalType('int', $status['id']);
125 // We could probably do more checks here.
129 * Assert that a list array contains expected keys.
130 * @param array $list List array
133 private function assertList(array $list)
135 $this->assertInternalType('string', $list['name']);
136 $this->assertInternalType('int', $list['id']);
137 $this->assertInternalType('string', $list['id_str']);
138 $this->assertContains($list['mode'], ['public', 'private']);
139 // We could probably do more checks here.
143 * Assert that the string is XML and contain the root element.
144 * @param string $result XML string
145 * @param string $root_element Root element name
148 private function assertXml($result, $root_element)
150 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
151 $this->assertContains('<'.$root_element, $result);
152 // We could probably do more checks here.
156 * Get the path to a temporary empty PNG image.
157 * @return string Path
159 private function getTempImage()
161 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
165 // Empty 1x1 px PNG image
166 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
174 * Test the api_user() function.
177 public function testApiUser()
179 $this->assertEquals($this->selfUser['id'], api_user());
183 * Test the api_user() function with an unallowed user.
186 public function testApiUserWithUnallowedUser()
188 $_SESSION = ['allow_api' => false];
189 $this->assertEquals(false, api_user());
193 * Test the api_source() function.
196 public function testApiSource()
198 $this->assertEquals('api', api_source());
202 * Test the api_source() function with a Twidere user agent.
205 public function testApiSourceWithTwidere()
207 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
208 $this->assertEquals('Twidere', api_source());
212 * Test the api_source() function with a GET parameter.
215 public function testApiSourceWithGet()
217 $_GET['source'] = 'source_name';
218 $this->assertEquals('source_name', api_source());
222 * Test the api_date() function.
225 public function testApiDate()
227 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
231 * Test the api_register_func() function.
234 public function testApiRegisterFunc()
246 $this->assertTrue($API['api_path']['auth']);
247 $this->assertEquals('method', $API['api_path']['method']);
248 $this->assertTrue(is_callable($API['api_path']['func']));
252 * Test the api_login() function without any login.
254 * @runInSeparateProcess
255 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
257 public function testApiLoginWithoutLogin()
259 api_login($this->app);
263 * Test the api_login() function with a bad login.
265 * @runInSeparateProcess
266 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
268 public function testApiLoginWithBadLogin()
270 $_SERVER['PHP_AUTH_USER'] = 'user@server';
271 api_login($this->app);
275 * Test the api_login() function with oAuth.
278 public function testApiLoginWithOauth()
280 $this->markTestIncomplete('Can we test this easily?');
284 * Test the api_login() function with authentication provided by an addon.
287 public function testApiLoginWithAddonAuth()
289 $this->markTestIncomplete('Can we test this easily?');
293 * Test the api_login() function with a correct login.
295 * @runInSeparateProcess
297 public function testApiLoginWithCorrectLogin()
299 $_SERVER['PHP_AUTH_USER'] = 'Test user';
300 $_SERVER['PHP_AUTH_PW'] = 'password';
301 api_login($this->app);
305 * Test the api_login() function with a remote user.
307 * @runInSeparateProcess
308 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
310 public function testApiLoginWithRemoteUser()
312 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
313 api_login($this->app);
317 * Test the api_check_method() function.
320 public function testApiCheckMethod()
322 $this->assertFalse(api_check_method('method'));
326 * Test the api_check_method() function with a correct method.
329 public function testApiCheckMethodWithCorrectMethod()
331 $_SERVER['REQUEST_METHOD'] = 'method';
332 $this->assertTrue(api_check_method('method'));
336 * Test the api_check_method() function with a wildcard.
339 public function testApiCheckMethodWithWildcard()
341 $this->assertTrue(api_check_method('*'));
345 * Test the api_call() function.
347 * @runInSeparateProcess
349 public function testApiCall()
353 'method' => 'method',
354 'func' => function () {
355 return ['data' => ['some_data']];
358 $_SERVER['REQUEST_METHOD'] = 'method';
359 $_GET['callback'] = 'callback_name';
361 $this->app->query_string = 'api_path';
363 'callback_name(["some_data"])',
369 * Test the api_call() function with the profiled enabled.
371 * @runInSeparateProcess
373 public function testApiCallWithProfiler()
377 'method' => 'method',
378 'func' => function () {
379 return ['data' => ['some_data']];
382 $_SERVER['REQUEST_METHOD'] = 'method';
383 Config::set('system', 'profiler', true);
384 Config::set('rendertime', 'callstack', true);
385 $this->app->callstack = [
386 'database' => ['some_function' => 200],
387 'database_write' => ['some_function' => 200],
388 'cache' => ['some_function' => 200],
389 'cache_write' => ['some_function' => 200],
390 'network' => ['some_function' => 200]
393 $this->app->query_string = 'api_path';
401 * Test the api_call() function without any result.
403 * @runInSeparateProcess
405 public function testApiCallWithNoResult()
409 'method' => 'method',
410 'func' => function () {
414 $_SERVER['REQUEST_METHOD'] = 'method';
416 $this->app->query_string = 'api_path';
418 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
424 * Test the api_call() function with an unimplemented API.
426 * @runInSeparateProcess
428 public function testApiCallWithUninplementedApi()
431 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
437 * Test the api_call() function with a JSON result.
439 * @runInSeparateProcess
441 public function testApiCallWithJson()
445 'method' => 'method',
446 'func' => function () {
447 return ['data' => ['some_data']];
450 $_SERVER['REQUEST_METHOD'] = 'method';
452 $this->app->query_string = 'api_path.json';
460 * Test the api_call() function with an XML result.
462 * @runInSeparateProcess
464 public function testApiCallWithXml()
468 'method' => 'method',
469 'func' => function () {
473 $_SERVER['REQUEST_METHOD'] = 'method';
475 $this->app->query_string = 'api_path.xml';
483 * Test the api_call() function with an RSS result.
485 * @runInSeparateProcess
487 public function testApiCallWithRss()
491 'method' => 'method',
492 'func' => function () {
496 $_SERVER['REQUEST_METHOD'] = 'method';
498 $this->app->query_string = 'api_path.rss';
500 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
507 * Test the api_call() function with an Atom result.
509 * @runInSeparateProcess
511 public function testApiCallWithAtom()
515 'method' => 'method',
516 'func' => function () {
520 $_SERVER['REQUEST_METHOD'] = 'method';
522 $this->app->query_string = 'api_path.atom';
524 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
531 * Test the api_call() function with an unallowed method.
533 * @runInSeparateProcess
535 public function testApiCallWithWrongMethod()
538 $API['api_path'] = ['method' => 'method'];
540 $this->app->query_string = 'api_path';
542 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
548 * Test the api_call() function with an unauthorized user.
550 * @runInSeparateProcess
552 public function testApiCallWithWrongAuth()
556 'method' => 'method',
559 $_SERVER['REQUEST_METHOD'] = 'method';
560 $_SESSION['authenticated'] = false;
562 $this->app->query_string = 'api_path';
564 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
570 * Test the api_error() function with a JSON result.
572 * @runInSeparateProcess
574 public function testApiErrorWithJson()
577 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
578 api_error('json', new HTTPException('error_message'))
583 * Test the api_error() function with an XML result.
585 * @runInSeparateProcess
587 public function testApiErrorWithXml()
590 '<?xml version="1.0"?>'."\n".
591 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
592 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
593 'xmlns:georss="http://www.georss.org/georss">'."\n".
594 ' <error>error_message</error>'."\n".
595 ' <code>200 Friendica\Network\HTTP</code>'."\n".
598 api_error('xml', new HTTPException('error_message'))
603 * Test the api_error() function with an RSS result.
605 * @runInSeparateProcess
607 public function testApiErrorWithRss()
610 '<?xml version="1.0"?>'."\n".
611 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
612 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
613 'xmlns:georss="http://www.georss.org/georss">'."\n".
614 ' <error>error_message</error>'."\n".
615 ' <code>200 Friendica\Network\HTTP</code>'."\n".
618 api_error('rss', new HTTPException('error_message'))
623 * Test the api_error() function with an Atom result.
625 * @runInSeparateProcess
627 public function testApiErrorWithAtom()
630 '<?xml version="1.0"?>'."\n".
631 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
632 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
633 'xmlns:georss="http://www.georss.org/georss">'."\n".
634 ' <error>error_message</error>'."\n".
635 ' <code>200 Friendica\Network\HTTP</code>'."\n".
638 api_error('atom', new HTTPException('error_message'))
643 * Test the api_rss_extra() function.
646 public function testApiRssExtra()
648 $user_info = ['url' => 'user_url', 'lang' => 'en'];
649 $result = api_rss_extra($this->app, [], $user_info);
650 $this->assertEquals($user_info, $result['$user']);
651 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
652 $this->assertArrayHasKey('self', $result['$rss']);
653 $this->assertArrayHasKey('base', $result['$rss']);
654 $this->assertArrayHasKey('updated', $result['$rss']);
655 $this->assertArrayHasKey('atom_updated', $result['$rss']);
656 $this->assertArrayHasKey('language', $result['$rss']);
657 $this->assertArrayHasKey('logo', $result['$rss']);
661 * Test the api_rss_extra() function without any user info.
663 * @runInSeparateProcess
665 public function testApiRssExtraWithoutUserInfo()
667 $result = api_rss_extra($this->app, [], null);
668 $this->assertInternalType('array', $result['$user']);
669 $this->assertArrayHasKey('alternate', $result['$rss']);
670 $this->assertArrayHasKey('self', $result['$rss']);
671 $this->assertArrayHasKey('base', $result['$rss']);
672 $this->assertArrayHasKey('updated', $result['$rss']);
673 $this->assertArrayHasKey('atom_updated', $result['$rss']);
674 $this->assertArrayHasKey('language', $result['$rss']);
675 $this->assertArrayHasKey('logo', $result['$rss']);
679 * Test the api_unique_id_to_nurl() function.
682 public function testApiUniqueIdToNurl()
684 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
688 * Test the api_unique_id_to_nurl() function with a correct ID.
691 public function testApiUniqueIdToNurlWithCorrectId()
693 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
697 * Test the api_get_user() function.
699 * @runInSeparateProcess
701 public function testApiGetUser()
703 $user = api_get_user($this->app);
704 $this->assertSelfUser($user);
705 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
706 $this->assertEquals('6fdbe8', $user['profile_link_color']);
707 $this->assertEquals('ededed', $user['profile_background_color']);
711 * Test the api_get_user() function with a Frio schema.
713 * @runInSeparateProcess
715 public function testApiGetUserWithFrioSchema()
717 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
718 $user = api_get_user($this->app);
719 $this->assertSelfUser($user);
720 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
721 $this->assertEquals('6fdbe8', $user['profile_link_color']);
722 $this->assertEquals('ededed', $user['profile_background_color']);
726 * Test the api_get_user() function with a custom Frio schema.
728 * @runInSeparateProcess
730 public function testApiGetUserWithCustomFrioSchema()
732 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
733 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
734 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
735 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
736 $user = api_get_user($this->app);
737 $this->assertSelfUser($user);
738 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
739 $this->assertEquals('123456', $user['profile_link_color']);
740 $this->assertEquals('123456', $user['profile_background_color']);
744 * Test the api_get_user() function with an empty Frio schema.
746 * @runInSeparateProcess
748 public function testApiGetUserWithEmptyFrioSchema()
750 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
751 $user = api_get_user($this->app);
752 $this->assertSelfUser($user);
753 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
754 $this->assertEquals('6fdbe8', $user['profile_link_color']);
755 $this->assertEquals('ededed', $user['profile_background_color']);
759 * Test the api_get_user() function with an user that is not allowed to use the API.
761 * @runInSeparateProcess
763 public function testApiGetUserWithoutApiUser()
765 $_SERVER['PHP_AUTH_USER'] = 'Test user';
766 $_SERVER['PHP_AUTH_PW'] = 'password';
767 $_SESSION['allow_api'] = false;
768 $this->assertFalse(api_get_user($this->app));
772 * Test the api_get_user() function with an user ID in a GET parameter.
774 * @runInSeparateProcess
776 public function testApiGetUserWithGetId()
778 $_GET['user_id'] = $this->otherUser['id'];
779 $this->assertOtherUser(api_get_user($this->app));
783 * Test the api_get_user() function with a wrong user ID in a GET parameter.
785 * @runInSeparateProcess
786 * @expectedException Friendica\Network\HTTPException\BadRequestException
788 public function testApiGetUserWithWrongGetId()
790 $_GET['user_id'] = $this->wrongUserId;
791 $this->assertOtherUser(api_get_user($this->app));
795 * Test the api_get_user() function with an user name in a GET parameter.
797 * @runInSeparateProcess
799 public function testApiGetUserWithGetName()
801 $_GET['screen_name'] = $this->selfUser['nick'];
802 $this->assertSelfUser(api_get_user($this->app));
806 * Test the api_get_user() function with a profile URL in a GET parameter.
808 * @runInSeparateProcess
810 public function testApiGetUserWithGetUrl()
812 $_GET['profileurl'] = $this->selfUser['nurl'];
813 $this->assertSelfUser(api_get_user($this->app));
817 * Test the api_get_user() function with an user ID in the API path.
819 * @runInSeparateProcess
821 public function testApiGetUserWithNumericCalledApi()
824 $called_api = ['api_path'];
825 $this->app->argv[1] = $this->otherUser['id'].'.json';
826 $this->assertOtherUser(api_get_user($this->app));
830 * Test the api_get_user() function with the $called_api global variable.
832 * @runInSeparateProcess
834 public function testApiGetUserWithCalledApi()
837 $called_api = ['api', 'api_path'];
838 $this->assertSelfUser(api_get_user($this->app));
842 * Test the api_get_user() function with a valid user.
844 * @runInSeparateProcess
846 public function testApiGetUserWithCorrectUser()
848 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
852 * Test the api_get_user() function with a wrong user ID.
854 * @runInSeparateProcess
855 * @expectedException Friendica\Network\HTTPException\BadRequestException
857 public function testApiGetUserWithWrongUser()
859 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
863 * Test the api_get_user() function with a 0 user ID.
865 * @runInSeparateProcess
867 public function testApiGetUserWithZeroUser()
869 $this->assertSelfUser(api_get_user($this->app, 0));
873 * Test the api_item_get_user() function.
875 * @runInSeparateProcess
877 public function testApiItemGetUser()
879 $users = api_item_get_user($this->app, []);
880 $this->assertSelfUser($users[0]);
884 * Test the api_item_get_user() function with a different item parent.
887 public function testApiItemGetUserWithDifferentParent()
889 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
890 $this->assertSelfUser($users[0]);
891 $this->assertEquals($users[0], $users[1]);
895 * Test the api_walk_recursive() function.
898 public function testApiWalkRecursive()
906 // Should we test this with a callback that actually does something?
914 * Test the api_walk_recursive() function with an array.
917 public function testApiWalkRecursiveWithArray()
919 $array = [['item1'], ['item2']];
925 // Should we test this with a callback that actually does something?
933 * Test the api_reformat_xml() function.
936 public function testApiReformatXml()
940 $this->assertTrue(api_reformat_xml($item, $key));
941 $this->assertEquals('true', $item);
945 * Test the api_reformat_xml() function with a statusnet_api key.
948 public function testApiReformatXmlWithStatusnetKey()
951 $key = 'statusnet_api';
952 $this->assertTrue(api_reformat_xml($item, $key));
953 $this->assertEquals('statusnet:api', $key);
957 * Test the api_reformat_xml() function with a friendica_api key.
960 public function testApiReformatXmlWithFriendicaKey()
963 $key = 'friendica_api';
964 $this->assertTrue(api_reformat_xml($item, $key));
965 $this->assertEquals('friendica:api', $key);
969 * Test the api_create_xml() function.
972 public function testApiCreateXml()
975 '<?xml version="1.0"?>'."\n".
976 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
977 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
978 'xmlns:georss="http://www.georss.org/georss">'."\n".
979 ' <data>some_data</data>'."\n".
980 '</root_element>'."\n",
981 api_create_xml(['data' => ['some_data']], 'root_element')
986 * Test the api_create_xml() function without any XML namespace.
989 public function testApiCreateXmlWithoutNamespaces()
992 '<?xml version="1.0"?>'."\n".
994 ' <data>some_data</data>'."\n".
996 api_create_xml(['data' => ['some_data']], 'ok')
1001 * Test the api_format_data() function.
1004 public function testApiFormatData()
1006 $data = ['some_data'];
1007 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1011 * Test the api_format_data() function with an XML result.
1014 public function testApiFormatDataWithXml()
1016 $this->assertEquals(
1017 '<?xml version="1.0"?>'."\n".
1018 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1019 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1020 'xmlns:georss="http://www.georss.org/georss">'."\n".
1021 ' <data>some_data</data>'."\n".
1022 '</root_element>'."\n",
1023 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1028 * Test the api_account_verify_credentials() function.
1031 public function testApiAccountVerifyCredentials()
1033 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1037 * Test the api_account_verify_credentials() function without an authenticated user.
1039 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1041 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1043 $_SESSION['authenticated'] = false;
1044 api_account_verify_credentials('json');
1048 * Test the requestdata() function.
1051 public function testRequestdata()
1053 $this->assertNull(requestdata('variable_name'));
1057 * Test the requestdata() function with a POST parameter.
1060 public function testRequestdataWithPost()
1062 $_POST['variable_name'] = 'variable_value';
1063 $this->assertEquals('variable_value', requestdata('variable_name'));
1067 * Test the requestdata() function with a GET parameter.
1070 public function testRequestdataWithGet()
1072 $_GET['variable_name'] = 'variable_value';
1073 $this->assertEquals('variable_value', requestdata('variable_name'));
1077 * Test the api_statuses_mediap() function.
1080 public function testApiStatusesMediap()
1082 $this->app->argc = 2;
1090 'tmp_name' => $this->getTempImage(),
1091 'name' => 'spacer.png',
1092 'type' => 'image/png'
1095 $_GET['status'] = '<b>Status content</b>';
1097 $result = api_statuses_mediap('json');
1098 $this->assertStatus($result['status']);
1102 * Test the api_statuses_mediap() function without an authenticated user.
1104 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1106 public function testApiStatusesMediapWithoutAuthenticatedUser()
1108 $_SESSION['authenticated'] = false;
1109 api_statuses_mediap('json');
1113 * Test the api_statuses_update() function.
1116 public function testApiStatusesUpdate()
1118 $_GET['status'] = 'Status content';
1119 $_GET['in_reply_to_status_id'] = -1;
1128 'tmp_name' => $this->getTempImage(),
1129 'name' => 'spacer.png',
1130 'type' => 'image/png'
1134 $result = api_statuses_update('json');
1135 $this->assertStatus($result['status']);
1139 * Test the api_statuses_update() function with an HTML status.
1142 public function testApiStatusesUpdateWithHtml()
1144 $_GET['htmlstatus'] = '<b>Status content</b>';
1146 $result = api_statuses_update('json');
1147 $this->assertStatus($result['status']);
1151 * Test the api_statuses_update() function without an authenticated user.
1153 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1155 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1157 $_SESSION['authenticated'] = false;
1158 api_statuses_update('json');
1162 * Test the api_statuses_update() function with a parent status.
1165 public function testApiStatusesUpdateWithParent()
1167 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1171 * Test the api_statuses_update() function with a media_ids parameter.
1174 public function testApiStatusesUpdateWithMediaIds()
1176 $this->markTestIncomplete();
1180 * Test the api_statuses_update() function with the throttle limit reached.
1183 public function testApiStatusesUpdateWithDayThrottleReached()
1185 $this->markTestIncomplete();
1189 * Test the api_media_upload() function.
1191 * @expectedException Friendica\Network\HTTPException\BadRequestException
1193 public function testApiMediaUpload()
1199 * Test the api_media_upload() function without an authenticated user.
1201 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1203 public function testApiMediaUploadWithoutAuthenticatedUser()
1205 $_SESSION['authenticated'] = false;
1210 * Test the api_media_upload() function with an invalid uploaded media.
1212 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1214 public function testApiMediaUploadWithMedia()
1219 'tmp_name' => 'tmp_name'
1226 * Test the api_media_upload() function with an valid uploaded media.
1229 public function testApiMediaUploadWithValidMedia()
1237 'tmp_name' => $this->getTempImage(),
1238 'name' => 'spacer.png',
1239 'type' => 'image/png'
1245 $result = api_media_upload();
1246 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1247 $this->assertEquals(1, $result['media']['image']['w']);
1248 $this->assertEquals(1, $result['media']['image']['h']);
1252 * Test the api_status_show() function.
1255 public function testApiStatusShow()
1257 $result = api_status_show('json');
1258 $this->assertStatus($result['status']);
1262 * Test the api_status_show() function with an XML result.
1265 public function testApiStatusShowWithXml()
1267 $result = api_status_show('xml');
1268 $this->assertXml($result, 'statuses');
1272 * Test the api_status_show() function with a raw result.
1275 public function testApiStatusShowWithRaw()
1277 $this->assertStatus(api_status_show('raw'));
1281 * Test the api_users_show() function.
1284 public function testApiUsersShow()
1286 $result = api_users_show('json');
1287 // We can't use assertSelfUser() here because the user object is missing some properties.
1288 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1289 $this->assertEquals('Friendica', $result['user']['location']);
1290 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1291 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1292 $this->assertEquals('dfrn', $result['user']['network']);
1293 $this->assertTrue($result['user']['verified']);
1297 * Test the api_users_show() function with an XML result.
1300 public function testApiUsersShowWithXml()
1302 $result = api_users_show('xml');
1303 $this->assertXml($result, 'statuses');
1307 * Test the api_users_search() function.
1310 public function testApiUsersSearch()
1312 $_GET['q'] = 'othercontact';
1313 $result = api_users_search('json');
1314 $this->assertOtherUser($result['users'][0]);
1318 * Test the api_users_search() function with an XML result.
1321 public function testApiUsersSearchWithXml()
1323 $_GET['q'] = 'othercontact';
1324 $result = api_users_search('xml');
1325 $this->assertXml($result, 'users');
1329 * Test the api_users_search() function without a GET q parameter.
1331 * @expectedException Friendica\Network\HTTPException\BadRequestException
1333 public function testApiUsersSearchWithoutQuery()
1335 api_users_search('json');
1339 * Test the api_users_lookup() function.
1341 * @expectedException Friendica\Network\HTTPException\NotFoundException
1343 public function testApiUsersLookup()
1345 api_users_lookup('json');
1349 * Test the api_users_lookup() function with an user ID.
1352 public function testApiUsersLookupWithUserId()
1354 $_REQUEST['user_id'] = $this->otherUser['id'];
1355 $result = api_users_lookup('json');
1356 $this->assertOtherUser($result['users'][0]);
1360 * Test the api_search() function.
1363 public function testApiSearch()
1365 $_REQUEST['q'] = 'reply';
1366 $_REQUEST['max_id'] = 10;
1367 $result = api_search('json');
1368 foreach ($result['status'] as $status) {
1369 $this->assertStatus($status);
1370 $this->assertContains('reply', $status['text'], null, true);
1375 * Test the api_search() function a count parameter.
1378 public function testApiSearchWithCount()
1380 $_REQUEST['q'] = 'reply';
1381 $_REQUEST['count'] = 20;
1382 $result = api_search('json');
1383 foreach ($result['status'] as $status) {
1384 $this->assertStatus($status);
1385 $this->assertContains('reply', $status['text'], null, true);
1390 * Test the api_search() function with an rpp parameter.
1393 public function testApiSearchWithRpp()
1395 $_REQUEST['q'] = 'reply';
1396 $_REQUEST['rpp'] = 20;
1397 $result = api_search('json');
1398 foreach ($result['status'] as $status) {
1399 $this->assertStatus($status);
1400 $this->assertContains('reply', $status['text'], null, true);
1406 * Test the api_search() function without an authenticated user.
1408 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1410 public function testApiSearchWithUnallowedUser()
1412 $_SESSION['allow_api'] = false;
1413 $_GET['screen_name'] = $this->selfUser['nick'];
1418 * Test the api_search() function without any GET query parameter.
1420 * @expectedException Friendica\Network\HTTPException\BadRequestException
1422 public function testApiSearchWithoutQuery()
1428 * Test the api_statuses_home_timeline() function.
1431 public function testApiStatusesHomeTimeline()
1433 $_REQUEST['max_id'] = 10;
1434 $_REQUEST['exclude_replies'] = true;
1435 $_REQUEST['conversation_id'] = 1;
1436 $result = api_statuses_home_timeline('json');
1437 $this->assertNotEmpty($result['status']);
1438 foreach ($result['status'] as $status) {
1439 $this->assertStatus($status);
1444 * Test the api_statuses_home_timeline() function with a negative page parameter.
1447 public function testApiStatusesHomeTimelineWithNegativePage()
1449 $_REQUEST['page'] = -2;
1450 $result = api_statuses_home_timeline('json');
1451 $this->assertNotEmpty($result['status']);
1452 foreach ($result['status'] as $status) {
1453 $this->assertStatus($status);
1458 * Test the api_statuses_home_timeline() with an unallowed user.
1460 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1462 public function testApiStatusesHomeTimelineWithUnallowedUser()
1464 $_SESSION['allow_api'] = false;
1465 $_GET['screen_name'] = $this->selfUser['nick'];
1466 api_statuses_home_timeline('json');
1470 * Test the api_statuses_home_timeline() function with an RSS result.
1473 public function testApiStatusesHomeTimelineWithRss()
1475 $result = api_statuses_home_timeline('rss');
1476 $this->assertXml($result, 'statuses');
1480 * Test the api_statuses_public_timeline() function.
1483 public function testApiStatusesPublicTimeline()
1485 $_REQUEST['max_id'] = 10;
1486 $_REQUEST['conversation_id'] = 1;
1487 $result = api_statuses_public_timeline('json');
1488 $this->assertNotEmpty($result['status']);
1489 foreach ($result['status'] as $status) {
1490 $this->assertStatus($status);
1495 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1498 public function testApiStatusesPublicTimelineWithExcludeReplies()
1500 $_REQUEST['max_id'] = 10;
1501 $_REQUEST['exclude_replies'] = true;
1502 $result = api_statuses_public_timeline('json');
1503 $this->assertNotEmpty($result['status']);
1504 foreach ($result['status'] as $status) {
1505 $this->assertStatus($status);
1510 * Test the api_statuses_public_timeline() function with a negative page parameter.
1513 public function testApiStatusesPublicTimelineWithNegativePage()
1515 $_REQUEST['page'] = -2;
1516 $result = api_statuses_public_timeline('json');
1517 $this->assertNotEmpty($result['status']);
1518 foreach ($result['status'] as $status) {
1519 $this->assertStatus($status);
1524 * Test the api_statuses_public_timeline() function with an unallowed user.
1526 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1528 public function testApiStatusesPublicTimelineWithUnallowedUser()
1530 $_SESSION['allow_api'] = false;
1531 $_GET['screen_name'] = $this->selfUser['nick'];
1532 api_statuses_public_timeline('json');
1536 * Test the api_statuses_public_timeline() function with an RSS result.
1539 public function testApiStatusesPublicTimelineWithRss()
1541 $result = api_statuses_public_timeline('rss');
1542 $this->assertXml($result, 'statuses');
1546 * Test the api_statuses_networkpublic_timeline() function.
1549 public function testApiStatusesNetworkpublicTimeline()
1551 $_REQUEST['max_id'] = 10;
1552 $result = api_statuses_networkpublic_timeline('json');
1553 $this->assertNotEmpty($result['status']);
1554 foreach ($result['status'] as $status) {
1555 $this->assertStatus($status);
1560 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1563 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1565 $_REQUEST['page'] = -2;
1566 $result = api_statuses_networkpublic_timeline('json');
1567 $this->assertNotEmpty($result['status']);
1568 foreach ($result['status'] as $status) {
1569 $this->assertStatus($status);
1574 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1576 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1578 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1580 $_SESSION['allow_api'] = false;
1581 $_GET['screen_name'] = $this->selfUser['nick'];
1582 api_statuses_networkpublic_timeline('json');
1586 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1589 public function testApiStatusesNetworkpublicTimelineWithRss()
1591 $result = api_statuses_networkpublic_timeline('rss');
1592 $this->assertXml($result, 'statuses');
1596 * Test the api_statuses_show() function.
1598 * @expectedException Friendica\Network\HTTPException\BadRequestException
1600 public function testApiStatusesShow()
1602 api_statuses_show('json');
1606 * Test the api_statuses_show() function with an ID.
1609 public function testApiStatusesShowWithId()
1611 $this->app->argv[3] = 1;
1612 $result = api_statuses_show('json');
1613 $this->assertStatus($result['status']);
1617 * Test the api_statuses_show() function with the conversation parameter.
1620 public function testApiStatusesShowWithConversation()
1622 $this->app->argv[3] = 1;
1623 $_REQUEST['conversation'] = 1;
1624 $result = api_statuses_show('json');
1625 $this->assertNotEmpty($result['status']);
1626 foreach ($result['status'] as $status) {
1627 $this->assertStatus($status);
1632 * Test the api_statuses_show() function with an unallowed user.
1634 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1636 public function testApiStatusesShowWithUnallowedUser()
1638 $_SESSION['allow_api'] = false;
1639 $_GET['screen_name'] = $this->selfUser['nick'];
1640 api_statuses_show('json');
1644 * Test the api_conversation_show() function.
1646 * @expectedException Friendica\Network\HTTPException\BadRequestException
1648 public function testApiConversationShow()
1650 api_conversation_show('json');
1654 * Test the api_conversation_show() function with an ID.
1657 public function testApiConversationShowWithId()
1659 $this->app->argv[3] = 1;
1660 $_REQUEST['max_id'] = 10;
1661 $_REQUEST['page'] = -2;
1662 $result = api_conversation_show('json');
1663 $this->assertNotEmpty($result['status']);
1664 foreach ($result['status'] as $status) {
1665 $this->assertStatus($status);
1670 * Test the api_conversation_show() function with an unallowed user.
1672 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1674 public function testApiConversationShowWithUnallowedUser()
1676 $_SESSION['allow_api'] = false;
1677 $_GET['screen_name'] = $this->selfUser['nick'];
1678 api_conversation_show('json');
1682 * Test the api_statuses_repeat() function.
1684 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1686 public function testApiStatusesRepeat()
1688 api_statuses_repeat('json');
1692 * Test the api_statuses_repeat() function without an authenticated user.
1694 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1696 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1698 $_SESSION['authenticated'] = false;
1699 api_statuses_repeat('json');
1703 * Test the api_statuses_repeat() function with an ID.
1706 public function testApiStatusesRepeatWithId()
1708 $this->app->argv[3] = 1;
1709 $result = api_statuses_repeat('json');
1710 $this->assertStatus($result['status']);
1712 // Also test with a shared status
1713 $this->app->argv[3] = 5;
1714 $result = api_statuses_repeat('json');
1715 $this->assertStatus($result['status']);
1719 * Test the api_statuses_destroy() function.
1721 * @expectedException Friendica\Network\HTTPException\BadRequestException
1723 public function testApiStatusesDestroy()
1725 api_statuses_destroy('json');
1729 * Test the api_statuses_destroy() function without an authenticated user.
1731 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1733 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1735 $_SESSION['authenticated'] = false;
1736 api_statuses_destroy('json');
1740 * Test the api_statuses_destroy() function with an ID.
1743 public function testApiStatusesDestroyWithId()
1745 $this->app->argv[3] = 1;
1746 $result = api_statuses_destroy('json');
1747 $this->assertStatus($result['status']);
1751 * Test the api_statuses_mentions() function.
1754 public function testApiStatusesMentions()
1756 $this->app->user = ['nickname' => $this->selfUser['nick']];
1757 $_REQUEST['max_id'] = 10;
1758 $result = api_statuses_mentions('json');
1759 $this->assertEmpty($result['status']);
1760 // We should test with mentions in the database.
1764 * Test the api_statuses_mentions() function with a negative page parameter.
1767 public function testApiStatusesMentionsWithNegativePage()
1769 $_REQUEST['page'] = -2;
1770 $result = api_statuses_mentions('json');
1771 $this->assertEmpty($result['status']);
1775 * Test the api_statuses_mentions() function with an unallowed user.
1777 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1779 public function testApiStatusesMentionsWithUnallowedUser()
1781 $_SESSION['allow_api'] = false;
1782 $_GET['screen_name'] = $this->selfUser['nick'];
1783 api_statuses_mentions('json');
1787 * Test the api_statuses_mentions() function with an RSS result.
1790 public function testApiStatusesMentionsWithRss()
1792 $result = api_statuses_mentions('rss');
1793 $this->assertXml($result, 'statuses');
1797 * Test the api_statuses_user_timeline() function.
1800 public function testApiStatusesUserTimeline()
1802 $_REQUEST['max_id'] = 10;
1803 $_REQUEST['exclude_replies'] = true;
1804 $_REQUEST['conversation_id'] = 1;
1805 $result = api_statuses_user_timeline('json');
1806 $this->assertNotEmpty($result['status']);
1807 foreach ($result['status'] as $status) {
1808 $this->assertStatus($status);
1813 * Test the api_statuses_user_timeline() function with a negative page parameter.
1816 public function testApiStatusesUserTimelineWithNegativePage()
1818 $_REQUEST['page'] = -2;
1819 $result = api_statuses_user_timeline('json');
1820 $this->assertNotEmpty($result['status']);
1821 foreach ($result['status'] as $status) {
1822 $this->assertStatus($status);
1827 * Test the api_statuses_user_timeline() function with an RSS result.
1830 public function testApiStatusesUserTimelineWithRss()
1832 $result = api_statuses_user_timeline('rss');
1833 $this->assertXml($result, 'statuses');
1837 * Test the api_statuses_user_timeline() function with an unallowed user.
1839 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1841 public function testApiStatusesUserTimelineWithUnallowedUser()
1843 $_SESSION['allow_api'] = false;
1844 $_GET['screen_name'] = $this->selfUser['nick'];
1845 api_statuses_user_timeline('json');
1849 * Test the api_favorites_create_destroy() function.
1851 * @expectedException Friendica\Network\HTTPException\BadRequestException
1853 public function testApiFavoritesCreateDestroy()
1855 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1856 $this->app->argc = count($this->app->argv);
1857 api_favorites_create_destroy('json');
1861 * Test the api_favorites_create_destroy() function with an invalid ID.
1863 * @expectedException Friendica\Network\HTTPException\BadRequestException
1865 public function testApiFavoritesCreateDestroyWithInvalidId()
1867 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1868 $this->app->argc = count($this->app->argv);
1869 api_favorites_create_destroy('json');
1873 * Test the api_favorites_create_destroy() function with an invalid action.
1875 * @expectedException Friendica\Network\HTTPException\BadRequestException
1877 public function testApiFavoritesCreateDestroyWithInvalidAction()
1879 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1880 $this->app->argc = count($this->app->argv);
1881 $_REQUEST['id'] = 1;
1882 api_favorites_create_destroy('json');
1886 * Test the api_favorites_create_destroy() function with the create action.
1889 public function testApiFavoritesCreateDestroyWithCreateAction()
1891 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1892 $this->app->argc = count($this->app->argv);
1893 $_REQUEST['id'] = 3;
1894 $result = api_favorites_create_destroy('json');
1895 $this->assertStatus($result['status']);
1899 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1902 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1904 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1905 $this->app->argc = count($this->app->argv);
1906 $_REQUEST['id'] = 3;
1907 $result = api_favorites_create_destroy('rss');
1908 $this->assertXml($result, 'status');
1912 * Test the api_favorites_create_destroy() function with the destroy action.
1915 public function testApiFavoritesCreateDestroyWithDestroyAction()
1917 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1918 $this->app->argc = count($this->app->argv);
1919 $_REQUEST['id'] = 3;
1920 $result = api_favorites_create_destroy('json');
1921 $this->assertStatus($result['status']);
1925 * Test the api_favorites_create_destroy() function without an authenticated user.
1927 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1929 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1931 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1932 $this->app->argc = count($this->app->argv);
1933 $_SESSION['authenticated'] = false;
1934 api_favorites_create_destroy('json');
1938 * Test the api_favorites() function.
1941 public function testApiFavorites()
1943 $_REQUEST['page'] = -1;
1944 $_REQUEST['max_id'] = 10;
1945 $result = api_favorites('json');
1946 foreach ($result['status'] as $status) {
1947 $this->assertStatus($status);
1952 * Test the api_favorites() function with an RSS result.
1955 public function testApiFavoritesWithRss()
1957 $result = api_favorites('rss');
1958 $this->assertXml($result, 'statuses');
1962 * Test the api_favorites() function with an unallowed user.
1964 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1966 public function testApiFavoritesWithUnallowedUser()
1968 $_SESSION['allow_api'] = false;
1969 $_GET['screen_name'] = $this->selfUser['nick'];
1970 api_favorites('json');
1974 * Test the api_format_messages() function.
1977 public function testApiFormatMessages()
1979 $result = api_format_messages(
1980 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1981 ['id' => 2, 'screen_name' => 'recipient_name'],
1982 ['id' => 3, 'screen_name' => 'sender_name']
1984 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1985 $this->assertEquals(1, $result['id']);
1986 $this->assertEquals(2, $result['recipient_id']);
1987 $this->assertEquals(3, $result['sender_id']);
1988 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1989 $this->assertEquals('sender_name', $result['sender_screen_name']);
1993 * Test the api_format_messages() function with HTML.
1996 public function testApiFormatMessagesWithHtmlText()
1998 $_GET['getText'] = 'html';
1999 $result = api_format_messages(
2000 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2001 ['id' => 2, 'screen_name' => 'recipient_name'],
2002 ['id' => 3, 'screen_name' => 'sender_name']
2004 $this->assertEquals('item_title', $result['title']);
2005 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2009 * Test the api_format_messages() function with plain text.
2012 public function testApiFormatMessagesWithPlainText()
2014 $_GET['getText'] = 'plain';
2015 $result = api_format_messages(
2016 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2017 ['id' => 2, 'screen_name' => 'recipient_name'],
2018 ['id' => 3, 'screen_name' => 'sender_name']
2020 $this->assertEquals('item_title', $result['title']);
2021 $this->assertEquals('item_body', $result['text']);
2025 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2028 public function testApiFormatMessagesWithoutUserObjects()
2030 $_GET['getUserObjects'] = 'false';
2031 $result = api_format_messages(
2032 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2033 ['id' => 2, 'screen_name' => 'recipient_name'],
2034 ['id' => 3, 'screen_name' => 'sender_name']
2036 $this->assertTrue(!isset($result['sender']));
2037 $this->assertTrue(!isset($result['recipient']));
2041 * Test the api_convert_item() function.
2044 public function testApiConvertItem()
2046 $result = api_convert_item(
2048 'network' => 'feed',
2049 'title' => 'item_title',
2050 // We need a long string to test that it is correctly cut
2051 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2052 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2053 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2054 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2055 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2056 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2057 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2058 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2059 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2060 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2061 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2062 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2063 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2064 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2065 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2066 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2067 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2068 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2069 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2070 'repellat officia illum quos impedit quam iste esse unde qui '.
2071 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2072 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2073 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2074 'plink' => 'item_plink'
2077 $this->assertStringStartsWith('item_title', $result['text']);
2078 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2082 * Test the api_convert_item() function with an empty item body.
2085 public function testApiConvertItemWithoutBody()
2087 $result = api_convert_item(
2089 'network' => 'feed',
2090 'title' => 'item_title',
2092 'plink' => 'item_plink'
2095 $this->assertEquals('item_title', $result['text']);
2096 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2100 * Test the api_convert_item() function with the title in the body.
2103 public function testApiConvertItemWithTitleInBody()
2105 $result = api_convert_item(
2107 'title' => 'item_title',
2108 'body' => 'item_title item_body'
2111 $this->assertEquals('item_title item_body', $result['text']);
2112 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2116 * Test the api_get_attachments() function.
2119 public function testApiGetAttachments()
2122 $this->assertEmpty(api_get_attachments($body));
2126 * Test the api_get_attachments() function with an img tag.
2129 public function testApiGetAttachmentsWithImage()
2131 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2132 $this->assertInternalType('array', api_get_attachments($body));
2136 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2139 public function testApiGetAttachmentsWithImageAndAndStatus()
2141 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2142 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2143 $this->assertInternalType('array', api_get_attachments($body));
2147 * Test the api_get_entitities() function.
2150 public function testApiGetEntitities()
2153 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2157 * Test the api_get_entitities() function with the include_entities parameter.
2160 public function testApiGetEntititiesWithIncludeEntities()
2162 $_REQUEST['include_entities'] = 'true';
2164 $result = api_get_entitities($text, 'bbcode');
2165 $this->assertInternalType('array', $result['hashtags']);
2166 $this->assertInternalType('array', $result['symbols']);
2167 $this->assertInternalType('array', $result['urls']);
2168 $this->assertInternalType('array', $result['user_mentions']);
2172 * Test the api_format_items_embeded_images() function.
2175 public function testApiFormatItemsEmbededImages()
2177 $this->assertEquals(
2178 'text ' . System::baseUrl() . '/display/item_guid',
2179 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2184 * Test the api_contactlink_to_array() function.
2187 public function testApiContactlinkToArray()
2189 $this->assertEquals(
2194 api_contactlink_to_array('text')
2199 * Test the api_contactlink_to_array() function with an URL.
2202 public function testApiContactlinkToArrayWithUrl()
2204 $this->assertEquals(
2206 'name' => ['link_text'],
2209 api_contactlink_to_array('text <a href="url">link_text</a>')
2214 * Test the api_format_items_activities() function.
2217 public function testApiFormatItemsActivities()
2219 $item = ['uid' => 0, 'uri' => ''];
2220 $result = api_format_items_activities($item);
2221 $this->assertArrayHasKey('like', $result);
2222 $this->assertArrayHasKey('dislike', $result);
2223 $this->assertArrayHasKey('attendyes', $result);
2224 $this->assertArrayHasKey('attendno', $result);
2225 $this->assertArrayHasKey('attendmaybe', $result);
2229 * Test the api_format_items_activities() function with an XML result.
2232 public function testApiFormatItemsActivitiesWithXml()
2234 $item = ['uid' => 0, 'uri' => ''];
2235 $result = api_format_items_activities($item, 'xml');
2236 $this->assertArrayHasKey('friendica:like', $result);
2237 $this->assertArrayHasKey('friendica:dislike', $result);
2238 $this->assertArrayHasKey('friendica:attendyes', $result);
2239 $this->assertArrayHasKey('friendica:attendno', $result);
2240 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2244 * Test the api_format_items_profiles() function.
2247 public function testApiFormatItemsProfiles()
2250 'id' => 'profile_id',
2251 'profile-name' => 'profile_name',
2252 'is-default' => true,
2253 'hide-friends' => true,
2254 'photo' => 'profile_photo',
2255 'thumb' => 'profile_thumb',
2257 'net-publish' => true,
2258 'pdesc' => 'description',
2259 'dob' => 'date_of_birth',
2260 'address' => 'address',
2261 'locality' => 'city',
2262 'region' => 'region',
2263 'postal-code' => 'postal_code',
2264 'country-name' => 'country',
2265 'hometown' => 'hometown',
2266 'gender' => 'gender',
2267 'marital' => 'marital',
2268 'with' => 'marital_with',
2269 'howlong' => 'marital_since',
2270 'sexual' => 'sexual',
2271 'politic' => 'politic',
2272 'religion' => 'religion',
2273 'pub_keywords' => 'public_keywords',
2274 'prv_keywords' => 'private_keywords',
2277 'dislikes' => 'dislikes',
2283 'interest' => 'interest',
2284 'romance' => 'romance',
2286 'education' => 'education',
2287 'contact' => 'social_networks',
2288 'homepage' => 'homepage'
2290 $result = api_format_items_profiles($profile_row);
2291 $this->assertEquals(
2293 'profile_id' => 'profile_id',
2294 'profile_name' => 'profile_name',
2295 'is_default' => true,
2296 'hide_friends' => true,
2297 'profile_photo' => 'profile_photo',
2298 'profile_thumb' => 'profile_thumb',
2300 'net_publish' => true,
2301 'description' => 'description',
2302 'date_of_birth' => 'date_of_birth',
2303 'address' => 'address',
2305 'region' => 'region',
2306 'postal_code' => 'postal_code',
2307 'country' => 'country',
2308 'hometown' => 'hometown',
2309 'gender' => 'gender',
2310 'marital' => 'marital',
2311 'marital_with' => 'marital_with',
2312 'marital_since' => 'marital_since',
2313 'sexual' => 'sexual',
2314 'politic' => 'politic',
2315 'religion' => 'religion',
2316 'public_keywords' => 'public_keywords',
2317 'private_keywords' => 'private_keywords',
2320 'dislikes' => 'dislikes',
2326 'interest' => 'interest',
2327 'romance' => 'romance',
2329 'education' => 'education',
2330 'social_networks' => 'social_networks',
2331 'homepage' => 'homepage',
2339 * Test the api_format_items() function.
2342 public function testApiFormatItems()
2346 'item_network' => 'item_network',
2352 'author-network' => Protocol::DFRN,
2353 'author-link' => 'http://localhost/profile/othercontact',
2357 $result = api_format_items($items, ['id' => 0], true);
2358 foreach ($result as $status) {
2359 $this->assertStatus($status);
2364 * Test the api_format_items() function with an XML result.
2367 public function testApiFormatItemsWithXml()
2375 'author-network' => Protocol::DFRN,
2376 'author-link' => 'http://localhost/profile/othercontact',
2380 $result = api_format_items($items, ['id' => 0], true, 'xml');
2381 foreach ($result as $status) {
2382 $this->assertStatus($status);
2387 * Test the api_format_items() function.
2390 public function testApiAccountRateLimitStatus()
2392 $result = api_account_rate_limit_status('json');
2393 $this->assertEquals(150, $result['hash']['remaining_hits']);
2394 $this->assertEquals(150, $result['hash']['hourly_limit']);
2395 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2399 * Test the api_format_items() function with an XML result.
2402 public function testApiAccountRateLimitStatusWithXml()
2404 $result = api_account_rate_limit_status('xml');
2405 $this->assertXml($result, 'hash');
2409 * Test the api_help_test() function.
2412 public function testApiHelpTest()
2414 $result = api_help_test('json');
2415 $this->assertEquals(['ok' => 'ok'], $result);
2419 * Test the api_help_test() function with an XML result.
2422 public function testApiHelpTestWithXml()
2424 $result = api_help_test('xml');
2425 $this->assertXml($result, 'ok');
2429 * Test the api_lists_list() function.
2432 public function testApiListsList()
2434 $result = api_lists_list('json');
2435 $this->assertEquals(['lists_list' => []], $result);
2439 * Test the api_lists_ownerships() function.
2442 public function testApiListsOwnerships()
2444 $result = api_lists_ownerships('json');
2445 foreach ($result['lists']['lists'] as $list) {
2446 $this->assertList($list);
2451 * Test the api_lists_ownerships() function without an authenticated user.
2453 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2455 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2457 $_SESSION['authenticated'] = false;
2458 api_lists_ownerships('json');
2462 * Test the api_lists_statuses() function.
2463 * @expectedException Friendica\Network\HTTPException\BadRequestException
2466 public function testApiListsStatuses()
2468 api_lists_statuses('json');
2472 * Test the api_lists_statuses() function with a list ID.
2475 public function testApiListsStatusesWithListId()
2477 $_REQUEST['list_id'] = 1;
2478 $_REQUEST['page'] = -1;
2479 $_REQUEST['max_id'] = 10;
2480 $result = api_lists_statuses('json');
2481 foreach ($result['status'] as $status) {
2482 $this->assertStatus($status);
2487 * Test the api_lists_statuses() function with a list ID and a RSS result.
2490 public function testApiListsStatusesWithListIdAndRss()
2492 $_REQUEST['list_id'] = 1;
2493 $result = api_lists_statuses('rss');
2494 $this->assertXml($result, 'statuses');
2498 * Test the api_lists_statuses() function with an unallowed user.
2500 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2502 public function testApiListsStatusesWithUnallowedUser()
2504 $_SESSION['allow_api'] = false;
2505 $_GET['screen_name'] = $this->selfUser['nick'];
2506 api_lists_statuses('json');
2510 * Test the api_statuses_f() function.
2513 public function testApiStatusesFWithFriends()
2516 $result = api_statuses_f('friends');
2517 $this->assertArrayHasKey('user', $result);
2521 * Test the api_statuses_f() function.
2524 public function testApiStatusesFWithFollowers()
2526 $result = api_statuses_f('followers');
2527 $this->assertArrayHasKey('user', $result);
2531 * Test the api_statuses_f() function.
2534 public function testApiStatusesFWithBlocks()
2536 $result = api_statuses_f('blocks');
2537 $this->assertArrayHasKey('user', $result);
2541 * Test the api_statuses_f() function.
2544 public function testApiStatusesFWithIncoming()
2546 $result = api_statuses_f('incoming');
2547 $this->assertArrayHasKey('user', $result);
2551 * Test the api_statuses_f() function an undefined cursor GET variable.
2554 public function testApiStatusesFWithUndefinedCursor()
2556 $_GET['cursor'] = 'undefined';
2557 $this->assertFalse(api_statuses_f('friends'));
2561 * Test the api_statuses_friends() function.
2564 public function testApiStatusesFriends()
2566 $result = api_statuses_friends('json');
2567 $this->assertArrayHasKey('user', $result);
2571 * Test the api_statuses_friends() function an undefined cursor GET variable.
2574 public function testApiStatusesFriendsWithUndefinedCursor()
2576 $_GET['cursor'] = 'undefined';
2577 $this->assertFalse(api_statuses_friends('json'));
2581 * Test the api_statuses_followers() function.
2584 public function testApiStatusesFollowers()
2586 $result = api_statuses_followers('json');
2587 $this->assertArrayHasKey('user', $result);
2591 * Test the api_statuses_followers() function an undefined cursor GET variable.
2594 public function testApiStatusesFollowersWithUndefinedCursor()
2596 $_GET['cursor'] = 'undefined';
2597 $this->assertFalse(api_statuses_followers('json'));
2601 * Test the api_blocks_list() function.
2604 public function testApiBlocksList()
2606 $result = api_blocks_list('json');
2607 $this->assertArrayHasKey('user', $result);
2611 * Test the api_blocks_list() function an undefined cursor GET variable.
2614 public function testApiBlocksListWithUndefinedCursor()
2616 $_GET['cursor'] = 'undefined';
2617 $this->assertFalse(api_blocks_list('json'));
2621 * Test the api_friendships_incoming() function.
2624 public function testApiFriendshipsIncoming()
2626 $result = api_friendships_incoming('json');
2627 $this->assertArrayHasKey('id', $result);
2631 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2634 public function testApiFriendshipsIncomingWithUndefinedCursor()
2636 $_GET['cursor'] = 'undefined';
2637 $this->assertFalse(api_friendships_incoming('json'));
2641 * Test the api_statusnet_config() function.
2644 public function testApiStatusnetConfig()
2646 $result = api_statusnet_config('json');
2647 $this->assertEquals('localhost', $result['config']['site']['server']);
2648 $this->assertEquals('default', $result['config']['site']['theme']);
2649 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2650 $this->assertTrue($result['config']['site']['fancy']);
2651 $this->assertEquals('en', $result['config']['site']['language']);
2652 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2653 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2654 $this->assertEquals('false', $result['config']['site']['private']);
2655 $this->assertEquals('false', $result['config']['site']['ssl']);
2656 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2660 * Test the api_statusnet_version() function.
2663 public function testApiStatusnetVersion()
2665 $result = api_statusnet_version('json');
2666 $this->assertEquals('0.9.7', $result['version']);
2670 * Test the api_ff_ids() function.
2673 public function testApiFfIds()
2675 $result = api_ff_ids('json');
2676 $this->assertNull($result);
2680 * Test the api_ff_ids() function with a result.
2683 public function testApiFfIdsWithResult()
2685 $this->markTestIncomplete();
2689 * Test the api_ff_ids() function without an authenticated user.
2691 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2693 public function testApiFfIdsWithoutAuthenticatedUser()
2695 $_SESSION['authenticated'] = false;
2700 * Test the api_friends_ids() function.
2703 public function testApiFriendsIds()
2705 $result = api_friends_ids('json');
2706 $this->assertNull($result);
2710 * Test the api_followers_ids() function.
2713 public function testApiFollowersIds()
2715 $result = api_followers_ids('json');
2716 $this->assertNull($result);
2720 * Test the api_direct_messages_new() function.
2723 public function testApiDirectMessagesNew()
2725 $result = api_direct_messages_new('json');
2726 $this->assertNull($result);
2730 * Test the api_direct_messages_new() function without an authenticated user.
2732 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2734 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2736 $_SESSION['authenticated'] = false;
2737 api_direct_messages_new('json');
2741 * Test the api_direct_messages_new() function with an user ID.
2744 public function testApiDirectMessagesNewWithUserId()
2746 $_POST['text'] = 'message_text';
2747 $_POST['user_id'] = $this->otherUser['id'];
2748 $result = api_direct_messages_new('json');
2749 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2753 * Test the api_direct_messages_new() function with a screen name.
2756 public function testApiDirectMessagesNewWithScreenName()
2758 $_POST['text'] = 'message_text';
2759 $_POST['screen_name'] = $this->friendUser['nick'];
2760 $result = api_direct_messages_new('json');
2761 $this->assertEquals(1, $result['direct_message']['id']);
2762 $this->assertContains('message_text', $result['direct_message']['text']);
2763 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2764 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2768 * Test the api_direct_messages_new() function with a title.
2771 public function testApiDirectMessagesNewWithTitle()
2773 $_POST['text'] = 'message_text';
2774 $_POST['screen_name'] = $this->friendUser['nick'];
2775 $_REQUEST['title'] = 'message_title';
2776 $result = api_direct_messages_new('json');
2777 $this->assertEquals(1, $result['direct_message']['id']);
2778 $this->assertContains('message_text', $result['direct_message']['text']);
2779 $this->assertContains('message_title', $result['direct_message']['text']);
2780 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2781 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2785 * Test the api_direct_messages_new() function with an RSS result.
2788 public function testApiDirectMessagesNewWithRss()
2790 $_POST['text'] = 'message_text';
2791 $_POST['screen_name'] = $this->friendUser['nick'];
2792 $result = api_direct_messages_new('rss');
2793 $this->assertXml($result, 'direct-messages');
2797 * Test the api_direct_messages_destroy() function.
2799 * @expectedException Friendica\Network\HTTPException\BadRequestException
2801 public function testApiDirectMessagesDestroy()
2803 api_direct_messages_destroy('json');
2807 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2810 public function testApiDirectMessagesDestroyWithVerbose()
2812 $_GET['friendica_verbose'] = 'true';
2813 $result = api_direct_messages_destroy('json');
2814 $this->assertEquals(
2817 'result' => 'error',
2818 'message' => 'message id or parenturi not specified'
2826 * Test the api_direct_messages_destroy() function without an authenticated user.
2828 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2830 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2832 $_SESSION['authenticated'] = false;
2833 api_direct_messages_destroy('json');
2837 * Test the api_direct_messages_destroy() function with a non-zero ID.
2839 * @expectedException Friendica\Network\HTTPException\BadRequestException
2841 public function testApiDirectMessagesDestroyWithId()
2843 $_REQUEST['id'] = 1;
2844 api_direct_messages_destroy('json');
2848 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2851 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2853 $_REQUEST['id'] = 1;
2854 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2855 $_GET['friendica_verbose'] = 'true';
2856 $result = api_direct_messages_destroy('json');
2857 $this->assertEquals(
2860 'result' => 'error',
2861 'message' => 'message id not in database'
2869 * Test the api_direct_messages_destroy() function with a non-zero ID.
2872 public function testApiDirectMessagesDestroyWithCorrectId()
2874 $this->markTestIncomplete('We need to add a dataset for this.');
2878 * Test the api_direct_messages_box() function.
2881 public function testApiDirectMessagesBoxWithSentbox()
2883 $_REQUEST['page'] = -1;
2884 $_REQUEST['max_id'] = 10;
2885 $result = api_direct_messages_box('json', 'sentbox', 'false');
2886 $this->assertArrayHasKey('direct_message', $result);
2890 * Test the api_direct_messages_box() function.
2893 public function testApiDirectMessagesBoxWithConversation()
2895 $result = api_direct_messages_box('json', 'conversation', 'false');
2896 $this->assertArrayHasKey('direct_message', $result);
2900 * Test the api_direct_messages_box() function.
2903 public function testApiDirectMessagesBoxWithAll()
2905 $result = api_direct_messages_box('json', 'all', 'false');
2906 $this->assertArrayHasKey('direct_message', $result);
2910 * Test the api_direct_messages_box() function.
2913 public function testApiDirectMessagesBoxWithInbox()
2915 $result = api_direct_messages_box('json', 'inbox', 'false');
2916 $this->assertArrayHasKey('direct_message', $result);
2920 * Test the api_direct_messages_box() function.
2923 public function testApiDirectMessagesBoxWithVerbose()
2925 $result = api_direct_messages_box('json', 'sentbox', 'true');
2926 $this->assertEquals(
2929 'result' => 'error',
2930 'message' => 'no mails available'
2938 * Test the api_direct_messages_box() function with a RSS result.
2941 public function testApiDirectMessagesBoxWithRss()
2943 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2944 $this->assertXml($result, 'direct-messages');
2948 * Test the api_direct_messages_box() function without an authenticated user.
2950 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2952 public function testApiDirectMessagesBoxWithUnallowedUser()
2954 $_SESSION['allow_api'] = false;
2955 $_GET['screen_name'] = $this->selfUser['nick'];
2956 api_direct_messages_box('json', 'sentbox', 'false');
2960 * Test the api_direct_messages_sentbox() function.
2963 public function testApiDirectMessagesSentbox()
2965 $result = api_direct_messages_sentbox('json');
2966 $this->assertArrayHasKey('direct_message', $result);
2970 * Test the api_direct_messages_inbox() function.
2973 public function testApiDirectMessagesInbox()
2975 $result = api_direct_messages_inbox('json');
2976 $this->assertArrayHasKey('direct_message', $result);
2980 * Test the api_direct_messages_all() function.
2983 public function testApiDirectMessagesAll()
2985 $result = api_direct_messages_all('json');
2986 $this->assertArrayHasKey('direct_message', $result);
2990 * Test the api_direct_messages_conversation() function.
2993 public function testApiDirectMessagesConversation()
2995 $result = api_direct_messages_conversation('json');
2996 $this->assertArrayHasKey('direct_message', $result);
3000 * Test the api_oauth_request_token() function.
3003 public function testApiOauthRequestToken()
3005 $this->markTestIncomplete('killme() kills phpunit as well');
3009 * Test the api_oauth_access_token() function.
3012 public function testApiOauthAccessToken()
3014 $this->markTestIncomplete('killme() kills phpunit as well');
3018 * Test the api_fr_photoalbum_delete() function.
3020 * @expectedException Friendica\Network\HTTPException\BadRequestException
3022 public function testApiFrPhotoalbumDelete()
3024 api_fr_photoalbum_delete('json');
3028 * Test the api_fr_photoalbum_delete() function with an album name.
3030 * @expectedException Friendica\Network\HTTPException\BadRequestException
3032 public function testApiFrPhotoalbumDeleteWithAlbum()
3034 $_REQUEST['album'] = 'album_name';
3035 api_fr_photoalbum_delete('json');
3039 * Test the api_fr_photoalbum_delete() function with an album name.
3042 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3044 $this->markTestIncomplete('We need to add a dataset for this.');
3048 * Test the api_fr_photoalbum_delete() function.
3050 * @expectedException Friendica\Network\HTTPException\BadRequestException
3052 public function testApiFrPhotoalbumUpdate()
3054 api_fr_photoalbum_update('json');
3058 * Test the api_fr_photoalbum_delete() function with an album name.
3060 * @expectedException Friendica\Network\HTTPException\BadRequestException
3062 public function testApiFrPhotoalbumUpdateWithAlbum()
3064 $_REQUEST['album'] = 'album_name';
3065 api_fr_photoalbum_update('json');
3069 * Test the api_fr_photoalbum_delete() function with an album name.
3071 * @expectedException Friendica\Network\HTTPException\BadRequestException
3073 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3075 $_REQUEST['album'] = 'album_name';
3076 $_REQUEST['album_new'] = 'album_name';
3077 api_fr_photoalbum_update('json');
3081 * Test the api_fr_photoalbum_update() function without an authenticated user.
3083 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3085 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3087 $_SESSION['authenticated'] = false;
3088 api_fr_photoalbum_update('json');
3092 * Test the api_fr_photoalbum_delete() function with an album name.
3095 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3097 $this->markTestIncomplete('We need to add a dataset for this.');
3101 * Test the api_fr_photos_list() function.
3104 public function testApiFrPhotosList()
3106 $result = api_fr_photos_list('json');
3107 $this->assertArrayHasKey('photo', $result);
3111 * Test the api_fr_photos_list() function without an authenticated user.
3113 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3115 public function testApiFrPhotosListWithoutAuthenticatedUser()
3117 $_SESSION['authenticated'] = false;
3118 api_fr_photos_list('json');
3122 * Test the api_fr_photo_create_update() function.
3124 * @expectedException Friendica\Network\HTTPException\BadRequestException
3126 public function testApiFrPhotoCreateUpdate()
3128 api_fr_photo_create_update('json');
3132 * Test the api_fr_photo_create_update() function without an authenticated user.
3134 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3136 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3138 $_SESSION['authenticated'] = false;
3139 api_fr_photo_create_update('json');
3143 * Test the api_fr_photo_create_update() function with an album name.
3145 * @expectedException Friendica\Network\HTTPException\BadRequestException
3147 public function testApiFrPhotoCreateUpdateWithAlbum()
3149 $_REQUEST['album'] = 'album_name';
3150 api_fr_photo_create_update('json');
3154 * Test the api_fr_photo_create_update() function with the update mode.
3157 public function testApiFrPhotoCreateUpdateWithUpdate()
3159 $this->markTestIncomplete('We need to create a dataset for this');
3163 * Test the api_fr_photo_create_update() function with an uploaded file.
3166 public function testApiFrPhotoCreateUpdateWithFile()
3168 $this->markTestIncomplete();
3172 * Test the api_fr_photo_delete() function.
3174 * @expectedException Friendica\Network\HTTPException\BadRequestException
3176 public function testApiFrPhotoDelete()
3178 api_fr_photo_delete('json');
3182 * Test the api_fr_photo_delete() function without an authenticated user.
3184 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3186 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3188 $_SESSION['authenticated'] = false;
3189 api_fr_photo_delete('json');
3193 * Test the api_fr_photo_delete() function with a photo ID.
3195 * @expectedException Friendica\Network\HTTPException\BadRequestException
3197 public function testApiFrPhotoDeleteWithPhotoId()
3199 $_REQUEST['photo_id'] = 1;
3200 api_fr_photo_delete('json');
3204 * Test the api_fr_photo_delete() function with a correct photo ID.
3207 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3209 $this->markTestIncomplete('We need to create a dataset for this.');
3213 * Test the api_fr_photo_detail() function.
3215 * @expectedException Friendica\Network\HTTPException\BadRequestException
3217 public function testApiFrPhotoDetail()
3219 api_fr_photo_detail('json');
3223 * Test the api_fr_photo_detail() function without an authenticated user.
3225 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3227 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3229 $_SESSION['authenticated'] = false;
3230 api_fr_photo_detail('json');
3234 * Test the api_fr_photo_detail() function with a photo ID.
3236 * @expectedException Friendica\Network\HTTPException\NotFoundException
3238 public function testApiFrPhotoDetailWithPhotoId()
3240 $_REQUEST['photo_id'] = 1;
3241 api_fr_photo_detail('json');
3245 * Test the api_fr_photo_detail() function with a correct photo ID.
3248 public function testApiFrPhotoDetailCorrectPhotoId()
3250 $this->markTestIncomplete('We need to create a dataset for this.');
3254 * Test the api_account_update_profile_image() function.
3256 * @expectedException Friendica\Network\HTTPException\BadRequestException
3258 public function testApiAccountUpdateProfileImage()
3260 api_account_update_profile_image('json');
3264 * Test the api_account_update_profile_image() function without an authenticated user.
3266 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3268 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3270 $_SESSION['authenticated'] = false;
3271 api_account_update_profile_image('json');
3275 * Test the api_account_update_profile_image() function with an uploaded file.
3277 * @expectedException Friendica\Network\HTTPException\BadRequestException
3279 public function testApiAccountUpdateProfileImageWithUpload()
3281 $this->markTestIncomplete();
3286 * Test the api_account_update_profile() function.
3289 public function testApiAccountUpdateProfile()
3291 $_POST['name'] = 'new_name';
3292 $_POST['description'] = 'new_description';
3293 $result = api_account_update_profile('json');
3294 // We can't use assertSelfUser() here because the user object is missing some properties.
3295 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3296 $this->assertEquals('Friendica', $result['user']['location']);
3297 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3298 $this->assertEquals('dfrn', $result['user']['network']);
3299 $this->assertEquals('new_name', $result['user']['name']);
3300 $this->assertEquals('new_description', $result['user']['description']);
3304 * Test the check_acl_input() function.
3307 public function testCheckAclInput()
3309 $result = check_acl_input('<aclstring>');
3310 // Where does this result come from?
3311 $this->assertEquals(1, $result);
3315 * Test the check_acl_input() function with an empty ACL string.
3318 public function testCheckAclInputWithEmptyAclString()
3320 $result = check_acl_input(' ');
3321 $this->assertFalse($result);
3325 * Test the save_media_to_database() function.
3328 public function testSaveMediaToDatabase()
3330 $this->markTestIncomplete();
3334 * Test the post_photo_item() function.
3337 public function testPostPhotoItem()
3339 $this->markTestIncomplete();
3343 * Test the prepare_photo_data() function.
3346 public function testPreparePhotoData()
3348 $this->markTestIncomplete();
3352 * Test the api_friendica_remoteauth() function.
3354 * @expectedException Friendica\Network\HTTPException\BadRequestException
3356 public function testApiFriendicaRemoteauth()
3358 api_friendica_remoteauth();
3362 * Test the api_friendica_remoteauth() function with an URL.
3364 * @expectedException Friendica\Network\HTTPException\BadRequestException
3366 public function testApiFriendicaRemoteauthWithUrl()
3368 $_GET['url'] = 'url';
3369 $_GET['c_url'] = 'url';
3370 api_friendica_remoteauth();
3374 * Test the api_friendica_remoteauth() function with a correct URL.
3377 public function testApiFriendicaRemoteauthWithCorrectUrl()
3379 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3380 $_GET['url'] = 'url';
3381 $_GET['c_url'] = $this->selfUser['nurl'];
3382 api_friendica_remoteauth();
3386 * Test the api_share_as_retweet() function.
3389 public function testApiShareAsRetweet()
3391 $item = ['body' => ''];
3392 $result = api_share_as_retweet($item);
3393 $this->assertFalse($result);
3397 * Test the api_share_as_retweet() function with a valid item.
3400 public function testApiShareAsRetweetWithValidItem()
3402 $this->markTestIncomplete();
3406 * Test the api_get_nick() function.
3409 public function testApiGetNick()
3411 $result = api_get_nick($this->otherUser['nurl']);
3412 $this->assertEquals('othercontact', $result);
3416 * Test the api_get_nick() function with a wrong URL.
3419 public function testApiGetNickWithWrongUrl()
3421 $result = api_get_nick('wrong_url');
3422 $this->assertFalse($result);
3426 * Test the api_in_reply_to() function.
3429 public function testApiInReplyTo()
3431 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3432 $this->assertArrayHasKey('status_id', $result);
3433 $this->assertArrayHasKey('user_id', $result);
3434 $this->assertArrayHasKey('status_id_str', $result);
3435 $this->assertArrayHasKey('user_id_str', $result);
3436 $this->assertArrayHasKey('screen_name', $result);
3440 * Test the api_in_reply_to() function with a valid item.
3443 public function testApiInReplyToWithValidItem()
3445 $this->markTestIncomplete();
3449 * Test the api_clean_plain_items() function.
3452 public function testApiCleanPlainItems()
3454 $_REQUEST['include_entities'] = 'true';
3455 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3456 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3460 * Test the api_clean_attachments() function.
3463 public function testApiCleanAttachments()
3465 $this->markTestIncomplete();
3469 * Test the api_best_nickname() function.
3472 public function testApiBestNickname()
3475 $result = api_best_nickname($contacts);
3476 $this->assertNull($result);
3480 * Test the api_best_nickname() function with contacts.
3483 public function testApiBestNicknameWithContacts()
3485 $this->markTestIncomplete();
3489 * Test the api_friendica_group_show() function.
3492 public function testApiFriendicaGroupShow()
3494 $this->markTestIncomplete();
3498 * Test the api_friendica_group_delete() function.
3501 public function testApiFriendicaGroupDelete()
3503 $this->markTestIncomplete();
3507 * Test the api_lists_destroy() function.
3510 public function testApiListsDestroy()
3512 $this->markTestIncomplete();
3516 * Test the group_create() function.
3519 public function testGroupCreate()
3521 $this->markTestIncomplete();
3525 * Test the api_friendica_group_create() function.
3528 public function testApiFriendicaGroupCreate()
3530 $this->markTestIncomplete();
3534 * Test the api_lists_create() function.
3537 public function testApiListsCreate()
3539 $this->markTestIncomplete();
3543 * Test the api_friendica_group_update() function.
3546 public function testApiFriendicaGroupUpdate()
3548 $this->markTestIncomplete();
3552 * Test the api_lists_update() function.
3555 public function testApiListsUpdate()
3557 $this->markTestIncomplete();
3561 * Test the api_friendica_activity() function.
3564 public function testApiFriendicaActivity()
3566 $this->markTestIncomplete();
3570 * Test the api_friendica_notification() function.
3572 * @expectedException Friendica\Network\HTTPException\BadRequestException
3574 public function testApiFriendicaNotification()
3576 api_friendica_notification('json');
3580 * Test the api_friendica_notification() function without an authenticated user.
3582 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3584 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3586 $_SESSION['authenticated'] = false;
3587 api_friendica_notification('json');
3591 * Test the api_friendica_notification() function with an argument count.
3594 public function testApiFriendicaNotificationWithArgumentCount()
3596 $this->app->argv = ['api', 'friendica', 'notification'];
3597 $this->app->argc = count($this->app->argv);
3598 $result = api_friendica_notification('json');
3599 $this->assertEquals(['note' => false], $result);
3603 * Test the api_friendica_notification() function with an XML result.
3606 public function testApiFriendicaNotificationWithXmlResult()
3608 $this->app->argv = ['api', 'friendica', 'notification'];
3609 $this->app->argc = count($this->app->argv);
3610 $result = api_friendica_notification('xml');
3611 $this->assertXml($result, 'notes');
3615 * Test the api_friendica_notification_seen() function.
3618 public function testApiFriendicaNotificationSeen()
3620 $this->markTestIncomplete();
3624 * Test the api_friendica_direct_messages_setseen() function.
3627 public function testApiFriendicaDirectMessagesSetseen()
3629 $this->markTestIncomplete();
3633 * Test the api_friendica_direct_messages_search() function.
3636 public function testApiFriendicaDirectMessagesSearch()
3638 $this->markTestIncomplete();
3642 * Test the api_friendica_profile_show() function.
3645 public function testApiFriendicaProfileShow()
3647 $result = api_friendica_profile_show('json');
3648 // We can't use assertSelfUser() here because the user object is missing some properties.
3649 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3650 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3651 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3652 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3653 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3654 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3655 $this->assertFalse($result['$result']['multi_profiles']);
3659 * Test the api_friendica_profile_show() function with a profile ID.
3662 public function testApiFriendicaProfileShowWithProfileId()
3664 $this->markTestIncomplete('We need to add a dataset for this.');
3668 * Test the api_friendica_profile_show() function with a wrong profile ID.
3670 * @expectedException Friendica\Network\HTTPException\BadRequestException
3672 public function testApiFriendicaProfileShowWithWrongProfileId()
3674 $_REQUEST['profile_id'] = 666;
3675 api_friendica_profile_show('json');
3679 * Test the api_friendica_profile_show() function without an authenticated user.
3681 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3683 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3685 $_SESSION['authenticated'] = false;
3686 api_friendica_profile_show('json');
3690 * Test the api_saved_searches_list() function.
3693 public function testApiSavedSearchesList()
3695 $result = api_saved_searches_list('json');
3696 $this->assertEquals(1, $result['terms'][0]['id']);
3697 $this->assertEquals(1, $result['terms'][0]['id_str']);
3698 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3699 $this->assertEquals('Saved search', $result['terms'][0]['query']);