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;
15 require_once __DIR__ . '/../../include/api.php';
18 * Tests for the API functions.
20 * Functions that use header() need to be tested in a separate process.
21 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
23 class ApiTest extends DatabaseTest
26 * Create variables used by tests.
28 public function setUp()
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']
64 Config::set('system', 'url', 'http://localhost');
65 Config::set('system', 'hostname', 'localhost');
66 Config::set('system', 'worker_dont_fork', true);
69 Config::set('config', 'hostname', 'localhost');
70 Config::set('system', 'throttle_limit_day', 100);
71 Config::set('system', 'throttle_limit_week', 100);
72 Config::set('system', 'throttle_limit_month', 100);
73 Config::set('system', 'theme', 'system_theme');
77 * Cleanup variables used by tests.
79 protected function tearDown()
84 $this->app->argv = ['home'];
88 * Assert that an user array contains expected keys.
89 * @param array $user User array
92 private function assertSelfUser(array $user)
94 $this->assertEquals($this->selfUser['id'], $user['uid']);
95 $this->assertEquals($this->selfUser['id'], $user['cid']);
96 $this->assertEquals(1, $user['self']);
97 $this->assertEquals('DFRN', $user['location']);
98 $this->assertEquals($this->selfUser['name'], $user['name']);
99 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
100 $this->assertEquals('dfrn', $user['network']);
101 $this->assertTrue($user['verified']);
105 * Assert that an user array contains expected keys.
106 * @param array $user User array
109 private function assertOtherUser(array $user)
111 $this->assertEquals($this->otherUser['id'], $user['id']);
112 $this->assertEquals($this->otherUser['id'], $user['id_str']);
113 $this->assertEquals(0, $user['self']);
114 $this->assertEquals($this->otherUser['name'], $user['name']);
115 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
116 $this->assertFalse($user['verified']);
120 * Assert that a status array contains expected keys.
121 * @param array $status Status array
124 private function assertStatus(array $status)
126 $this->assertInternalType('string', $status['text']);
127 $this->assertInternalType('int', $status['id']);
128 // We could probably do more checks here.
132 * Assert that a list array contains expected keys.
133 * @param array $list List array
136 private function assertList(array $list)
138 $this->assertInternalType('string', $list['name']);
139 $this->assertInternalType('int', $list['id']);
140 $this->assertInternalType('string', $list['id_str']);
141 $this->assertContains($list['mode'], ['public', 'private']);
142 // We could probably do more checks here.
146 * Assert that the string is XML and contain the root element.
147 * @param string $result XML string
148 * @param string $root_element Root element name
151 private function assertXml($result, $root_element)
153 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
154 $this->assertContains('<'.$root_element, $result);
155 // We could probably do more checks here.
159 * Get the path to a temporary empty PNG image.
160 * @return string Path
162 private function getTempImage()
164 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
168 // Empty 1x1 px PNG image
169 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
177 * Test the api_user() function.
180 public function testApiUser()
182 $this->assertEquals($this->selfUser['id'], api_user());
186 * Test the api_user() function with an unallowed user.
189 public function testApiUserWithUnallowedUser()
191 $_SESSION = ['allow_api' => false];
192 $this->assertEquals(false, api_user());
196 * Test the api_source() function.
199 public function testApiSource()
201 $this->assertEquals('api', api_source());
205 * Test the api_source() function with a Twidere user agent.
208 public function testApiSourceWithTwidere()
210 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
211 $this->assertEquals('Twidere', api_source());
215 * Test the api_source() function with a GET parameter.
218 public function testApiSourceWithGet()
220 $_GET['source'] = 'source_name';
221 $this->assertEquals('source_name', api_source());
225 * Test the api_date() function.
228 public function testApiDate()
230 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
234 * Test the api_register_func() function.
237 public function testApiRegisterFunc()
249 $this->assertTrue($API['api_path']['auth']);
250 $this->assertEquals('method', $API['api_path']['method']);
251 $this->assertTrue(is_callable($API['api_path']['func']));
255 * Test the api_login() function without any login.
257 * @runInSeparateProcess
258 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
260 public function testApiLoginWithoutLogin()
262 api_login($this->app);
266 * Test the api_login() function with a bad login.
268 * @runInSeparateProcess
269 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
271 public function testApiLoginWithBadLogin()
273 $_SERVER['PHP_AUTH_USER'] = 'user@server';
274 api_login($this->app);
278 * Test the api_login() function with oAuth.
281 public function testApiLoginWithOauth()
283 $this->markTestIncomplete('Can we test this easily?');
287 * Test the api_login() function with authentication provided by an addon.
290 public function testApiLoginWithAddonAuth()
292 $this->markTestIncomplete('Can we test this easily?');
296 * Test the api_login() function with a correct login.
298 * @runInSeparateProcess
300 public function testApiLoginWithCorrectLogin()
302 $_SERVER['PHP_AUTH_USER'] = 'Test user';
303 $_SERVER['PHP_AUTH_PW'] = 'password';
304 api_login($this->app);
308 * Test the api_login() function with a remote user.
310 * @runInSeparateProcess
311 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
313 public function testApiLoginWithRemoteUser()
315 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
316 api_login($this->app);
320 * Test the api_check_method() function.
323 public function testApiCheckMethod()
325 $this->assertFalse(api_check_method('method'));
329 * Test the api_check_method() function with a correct method.
332 public function testApiCheckMethodWithCorrectMethod()
334 $_SERVER['REQUEST_METHOD'] = 'method';
335 $this->assertTrue(api_check_method('method'));
339 * Test the api_check_method() function with a wildcard.
342 public function testApiCheckMethodWithWildcard()
344 $this->assertTrue(api_check_method('*'));
348 * Test the api_call() function.
350 * @runInSeparateProcess
352 public function testApiCall()
356 'method' => 'method',
357 'func' => function () {
358 return ['data' => ['some_data']];
361 $_SERVER['REQUEST_METHOD'] = 'method';
362 $_GET['callback'] = 'callback_name';
364 $this->app->query_string = 'api_path';
366 'callback_name(["some_data"])',
372 * Test the api_call() function with the profiled enabled.
374 * @runInSeparateProcess
376 public function testApiCallWithProfiler()
380 'method' => 'method',
381 'func' => function () {
382 return ['data' => ['some_data']];
385 $_SERVER['REQUEST_METHOD'] = 'method';
386 Config::set('system', 'profiler', true);
387 Config::set('rendertime', 'callstack', true);
388 $this->app->callstack = [
389 'database' => ['some_function' => 200],
390 'database_write' => ['some_function' => 200],
391 'cache' => ['some_function' => 200],
392 'cache_write' => ['some_function' => 200],
393 'network' => ['some_function' => 200]
396 $this->app->query_string = 'api_path';
404 * Test the api_call() function without any result.
406 * @runInSeparateProcess
408 public function testApiCallWithNoResult()
412 'method' => 'method',
413 'func' => function () {
417 $_SERVER['REQUEST_METHOD'] = 'method';
419 $this->app->query_string = 'api_path';
421 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
427 * Test the api_call() function with an unimplemented API.
429 * @runInSeparateProcess
431 public function testApiCallWithUninplementedApi()
434 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
440 * Test the api_call() function with a JSON result.
442 * @runInSeparateProcess
444 public function testApiCallWithJson()
448 'method' => 'method',
449 'func' => function () {
450 return ['data' => ['some_data']];
453 $_SERVER['REQUEST_METHOD'] = 'method';
455 $this->app->query_string = 'api_path.json';
463 * Test the api_call() function with an XML result.
465 * @runInSeparateProcess
467 public function testApiCallWithXml()
471 'method' => 'method',
472 'func' => function () {
476 $_SERVER['REQUEST_METHOD'] = 'method';
478 $this->app->query_string = 'api_path.xml';
486 * Test the api_call() function with an RSS result.
488 * @runInSeparateProcess
490 public function testApiCallWithRss()
494 'method' => 'method',
495 'func' => function () {
499 $_SERVER['REQUEST_METHOD'] = 'method';
501 $this->app->query_string = 'api_path.rss';
503 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
510 * Test the api_call() function with an Atom result.
512 * @runInSeparateProcess
514 public function testApiCallWithAtom()
518 'method' => 'method',
519 'func' => function () {
523 $_SERVER['REQUEST_METHOD'] = 'method';
525 $this->app->query_string = 'api_path.atom';
527 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
534 * Test the api_call() function with an unallowed method.
536 * @runInSeparateProcess
538 public function testApiCallWithWrongMethod()
541 $API['api_path'] = ['method' => 'method'];
543 $this->app->query_string = 'api_path';
545 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
551 * Test the api_call() function with an unauthorized user.
553 * @runInSeparateProcess
555 public function testApiCallWithWrongAuth()
559 'method' => 'method',
562 $_SERVER['REQUEST_METHOD'] = 'method';
563 $_SESSION['authenticated'] = false;
565 $this->app->query_string = 'api_path';
567 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
573 * Test the api_error() function with a JSON result.
575 * @runInSeparateProcess
577 public function testApiErrorWithJson()
580 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
581 api_error('json', new HTTPException('error_message'))
586 * Test the api_error() function with an XML result.
588 * @runInSeparateProcess
590 public function testApiErrorWithXml()
593 '<?xml version="1.0"?>'."\n".
594 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
595 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
596 'xmlns:georss="http://www.georss.org/georss">'."\n".
597 ' <error>error_message</error>'."\n".
598 ' <code>200 Friendica\Network\HTTP</code>'."\n".
601 api_error('xml', new HTTPException('error_message'))
606 * Test the api_error() function with an RSS result.
608 * @runInSeparateProcess
610 public function testApiErrorWithRss()
613 '<?xml version="1.0"?>'."\n".
614 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
615 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
616 'xmlns:georss="http://www.georss.org/georss">'."\n".
617 ' <error>error_message</error>'."\n".
618 ' <code>200 Friendica\Network\HTTP</code>'."\n".
621 api_error('rss', new HTTPException('error_message'))
626 * Test the api_error() function with an Atom result.
628 * @runInSeparateProcess
630 public function testApiErrorWithAtom()
633 '<?xml version="1.0"?>'."\n".
634 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
635 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
636 'xmlns:georss="http://www.georss.org/georss">'."\n".
637 ' <error>error_message</error>'."\n".
638 ' <code>200 Friendica\Network\HTTP</code>'."\n".
641 api_error('atom', new HTTPException('error_message'))
646 * Test the api_rss_extra() function.
649 public function testApiRssExtra()
651 $user_info = ['url' => 'user_url', 'lang' => 'en'];
652 $result = api_rss_extra($this->app, [], $user_info);
653 $this->assertEquals($user_info, $result['$user']);
654 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
655 $this->assertArrayHasKey('self', $result['$rss']);
656 $this->assertArrayHasKey('base', $result['$rss']);
657 $this->assertArrayHasKey('updated', $result['$rss']);
658 $this->assertArrayHasKey('atom_updated', $result['$rss']);
659 $this->assertArrayHasKey('language', $result['$rss']);
660 $this->assertArrayHasKey('logo', $result['$rss']);
664 * Test the api_rss_extra() function without any user info.
666 * @runInSeparateProcess
668 public function testApiRssExtraWithoutUserInfo()
670 $result = api_rss_extra($this->app, [], null);
671 $this->assertInternalType('array', $result['$user']);
672 $this->assertArrayHasKey('alternate', $result['$rss']);
673 $this->assertArrayHasKey('self', $result['$rss']);
674 $this->assertArrayHasKey('base', $result['$rss']);
675 $this->assertArrayHasKey('updated', $result['$rss']);
676 $this->assertArrayHasKey('atom_updated', $result['$rss']);
677 $this->assertArrayHasKey('language', $result['$rss']);
678 $this->assertArrayHasKey('logo', $result['$rss']);
682 * Test the api_unique_id_to_nurl() function.
685 public function testApiUniqueIdToNurl()
687 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
691 * Test the api_unique_id_to_nurl() function with a correct ID.
694 public function testApiUniqueIdToNurlWithCorrectId()
696 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
700 * Test the api_get_user() function.
702 * @runInSeparateProcess
704 public function testApiGetUser()
706 $user = api_get_user($this->app);
707 $this->assertSelfUser($user);
708 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
709 $this->assertEquals('6fdbe8', $user['profile_link_color']);
710 $this->assertEquals('ededed', $user['profile_background_color']);
714 * Test the api_get_user() function with a Frio schema.
716 * @runInSeparateProcess
718 public function testApiGetUserWithFrioSchema()
720 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
721 $user = api_get_user($this->app);
722 $this->assertSelfUser($user);
723 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
724 $this->assertEquals('6fdbe8', $user['profile_link_color']);
725 $this->assertEquals('ededed', $user['profile_background_color']);
729 * Test the api_get_user() function with a custom Frio schema.
731 * @runInSeparateProcess
733 public function testApiGetUserWithCustomFrioSchema()
735 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
736 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
737 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
738 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
739 $user = api_get_user($this->app);
740 $this->assertSelfUser($user);
741 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
742 $this->assertEquals('123456', $user['profile_link_color']);
743 $this->assertEquals('123456', $user['profile_background_color']);
747 * Test the api_get_user() function with an empty Frio schema.
749 * @runInSeparateProcess
751 public function testApiGetUserWithEmptyFrioSchema()
753 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
754 $user = api_get_user($this->app);
755 $this->assertSelfUser($user);
756 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
757 $this->assertEquals('6fdbe8', $user['profile_link_color']);
758 $this->assertEquals('ededed', $user['profile_background_color']);
762 * Test the api_get_user() function with an user that is not allowed to use the API.
764 * @runInSeparateProcess
766 public function testApiGetUserWithoutApiUser()
768 $_SERVER['PHP_AUTH_USER'] = 'Test user';
769 $_SERVER['PHP_AUTH_PW'] = 'password';
770 $_SESSION['allow_api'] = false;
771 $this->assertFalse(api_get_user($this->app));
775 * Test the api_get_user() function with an user ID in a GET parameter.
777 * @runInSeparateProcess
779 public function testApiGetUserWithGetId()
781 $_GET['user_id'] = $this->otherUser['id'];
782 $this->assertOtherUser(api_get_user($this->app));
786 * Test the api_get_user() function with a wrong user ID in a GET parameter.
788 * @runInSeparateProcess
789 * @expectedException Friendica\Network\HTTPException\BadRequestException
791 public function testApiGetUserWithWrongGetId()
793 $_GET['user_id'] = $this->wrongUserId;
794 $this->assertOtherUser(api_get_user($this->app));
798 * Test the api_get_user() function with an user name in a GET parameter.
800 * @runInSeparateProcess
802 public function testApiGetUserWithGetName()
804 $_GET['screen_name'] = $this->selfUser['nick'];
805 $this->assertSelfUser(api_get_user($this->app));
809 * Test the api_get_user() function with a profile URL in a GET parameter.
811 * @runInSeparateProcess
813 public function testApiGetUserWithGetUrl()
815 $_GET['profileurl'] = $this->selfUser['nurl'];
816 $this->assertSelfUser(api_get_user($this->app));
820 * Test the api_get_user() function with an user ID in the API path.
822 * @runInSeparateProcess
824 public function testApiGetUserWithNumericCalledApi()
827 $called_api = ['api_path'];
828 $this->app->argv[1] = $this->otherUser['id'].'.json';
829 $this->assertOtherUser(api_get_user($this->app));
833 * Test the api_get_user() function with the $called_api global variable.
835 * @runInSeparateProcess
837 public function testApiGetUserWithCalledApi()
840 $called_api = ['api', 'api_path'];
841 $this->assertSelfUser(api_get_user($this->app));
845 * Test the api_get_user() function with a valid user.
847 * @runInSeparateProcess
849 public function testApiGetUserWithCorrectUser()
851 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
855 * Test the api_get_user() function with a wrong user ID.
857 * @runInSeparateProcess
858 * @expectedException Friendica\Network\HTTPException\BadRequestException
860 public function testApiGetUserWithWrongUser()
862 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
866 * Test the api_get_user() function with a 0 user ID.
868 * @runInSeparateProcess
870 public function testApiGetUserWithZeroUser()
872 $this->assertSelfUser(api_get_user($this->app, 0));
876 * Test the api_item_get_user() function.
878 * @runInSeparateProcess
880 public function testApiItemGetUser()
882 $users = api_item_get_user($this->app, []);
883 $this->assertSelfUser($users[0]);
887 * Test the api_item_get_user() function with a different item parent.
890 public function testApiItemGetUserWithDifferentParent()
892 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
893 $this->assertSelfUser($users[0]);
894 $this->assertEquals($users[0], $users[1]);
898 * Test the api_walk_recursive() function.
901 public function testApiWalkRecursive()
909 // Should we test this with a callback that actually does something?
917 * Test the api_walk_recursive() function with an array.
920 public function testApiWalkRecursiveWithArray()
922 $array = [['item1'], ['item2']];
928 // Should we test this with a callback that actually does something?
936 * Test the api_reformat_xml() function.
939 public function testApiReformatXml()
943 $this->assertTrue(api_reformat_xml($item, $key));
944 $this->assertEquals('true', $item);
948 * Test the api_reformat_xml() function with a statusnet_api key.
951 public function testApiReformatXmlWithStatusnetKey()
954 $key = 'statusnet_api';
955 $this->assertTrue(api_reformat_xml($item, $key));
956 $this->assertEquals('statusnet:api', $key);
960 * Test the api_reformat_xml() function with a friendica_api key.
963 public function testApiReformatXmlWithFriendicaKey()
966 $key = 'friendica_api';
967 $this->assertTrue(api_reformat_xml($item, $key));
968 $this->assertEquals('friendica:api', $key);
972 * Test the api_create_xml() function.
975 public function testApiCreateXml()
978 '<?xml version="1.0"?>'."\n".
979 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
980 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
981 'xmlns:georss="http://www.georss.org/georss">'."\n".
982 ' <data>some_data</data>'."\n".
983 '</root_element>'."\n",
984 api_create_xml(['data' => ['some_data']], 'root_element')
989 * Test the api_create_xml() function without any XML namespace.
992 public function testApiCreateXmlWithoutNamespaces()
995 '<?xml version="1.0"?>'."\n".
997 ' <data>some_data</data>'."\n".
999 api_create_xml(['data' => ['some_data']], 'ok')
1004 * Test the api_format_data() function.
1007 public function testApiFormatData()
1009 $data = ['some_data'];
1010 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1014 * Test the api_format_data() function with an XML result.
1017 public function testApiFormatDataWithXml()
1019 $this->assertEquals(
1020 '<?xml version="1.0"?>'."\n".
1021 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1022 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1023 'xmlns:georss="http://www.georss.org/georss">'."\n".
1024 ' <data>some_data</data>'."\n".
1025 '</root_element>'."\n",
1026 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1031 * Test the api_account_verify_credentials() function.
1034 public function testApiAccountVerifyCredentials()
1036 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1040 * Test the api_account_verify_credentials() function without an authenticated user.
1042 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1044 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1046 $_SESSION['authenticated'] = false;
1047 api_account_verify_credentials('json');
1051 * Test the requestdata() function.
1054 public function testRequestdata()
1056 $this->assertNull(requestdata('variable_name'));
1060 * Test the requestdata() function with a POST parameter.
1063 public function testRequestdataWithPost()
1065 $_POST['variable_name'] = 'variable_value';
1066 $this->assertEquals('variable_value', requestdata('variable_name'));
1070 * Test the requestdata() function with a GET parameter.
1073 public function testRequestdataWithGet()
1075 $_GET['variable_name'] = 'variable_value';
1076 $this->assertEquals('variable_value', requestdata('variable_name'));
1080 * Test the api_statuses_mediap() function.
1083 public function testApiStatusesMediap()
1085 $this->app->argc = 2;
1093 'tmp_name' => $this->getTempImage(),
1094 'name' => 'spacer.png',
1095 'type' => 'image/png'
1098 $_GET['status'] = '<b>Status content</b>';
1100 $result = api_statuses_mediap('json');
1101 $this->assertStatus($result['status']);
1105 * Test the api_statuses_mediap() function without an authenticated user.
1107 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1109 public function testApiStatusesMediapWithoutAuthenticatedUser()
1111 $_SESSION['authenticated'] = false;
1112 api_statuses_mediap('json');
1116 * Test the api_statuses_update() function.
1119 public function testApiStatusesUpdate()
1121 $_GET['status'] = 'Status content #friendica';
1122 $_GET['in_reply_to_status_id'] = -1;
1131 'tmp_name' => $this->getTempImage(),
1132 'name' => 'spacer.png',
1133 'type' => 'image/png'
1137 $result = api_statuses_update('json');
1138 $this->assertStatus($result['status']);
1142 * Test the api_statuses_update() function with an HTML status.
1145 public function testApiStatusesUpdateWithHtml()
1147 $_GET['htmlstatus'] = '<b>Status content</b>';
1149 $result = api_statuses_update('json');
1150 $this->assertStatus($result['status']);
1154 * Test the api_statuses_update() function without an authenticated user.
1156 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1158 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1160 $_SESSION['authenticated'] = false;
1161 api_statuses_update('json');
1165 * Test the api_statuses_update() function with a parent status.
1168 public function testApiStatusesUpdateWithParent()
1170 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1174 * Test the api_statuses_update() function with a media_ids parameter.
1177 public function testApiStatusesUpdateWithMediaIds()
1179 $this->markTestIncomplete();
1183 * Test the api_statuses_update() function with the throttle limit reached.
1186 public function testApiStatusesUpdateWithDayThrottleReached()
1188 $this->markTestIncomplete();
1192 * Test the api_media_upload() function.
1194 * @expectedException Friendica\Network\HTTPException\BadRequestException
1196 public function testApiMediaUpload()
1202 * Test the api_media_upload() function without an authenticated user.
1204 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1206 public function testApiMediaUploadWithoutAuthenticatedUser()
1208 $_SESSION['authenticated'] = false;
1213 * Test the api_media_upload() function with an invalid uploaded media.
1215 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1217 public function testApiMediaUploadWithMedia()
1222 'tmp_name' => 'tmp_name'
1229 * Test the api_media_upload() function with an valid uploaded media.
1232 public function testApiMediaUploadWithValidMedia()
1240 'tmp_name' => $this->getTempImage(),
1241 'name' => 'spacer.png',
1242 'type' => 'image/png'
1248 $result = api_media_upload();
1249 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1250 $this->assertEquals(1, $result['media']['image']['w']);
1251 $this->assertEquals(1, $result['media']['image']['h']);
1252 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1256 * Test the api_status_show() function.
1259 public function testApiStatusShow()
1261 $result = api_status_show('json');
1262 $this->assertStatus($result['status']);
1266 * Test the api_status_show() function with an XML result.
1269 public function testApiStatusShowWithXml()
1271 $result = api_status_show('xml');
1272 $this->assertXml($result, 'statuses');
1276 * Test the api_status_show() function with a raw result.
1279 public function testApiStatusShowWithRaw()
1281 $this->assertStatus(api_status_show('raw'));
1285 * Test the api_users_show() function.
1288 public function testApiUsersShow()
1290 $result = api_users_show('json');
1291 // We can't use assertSelfUser() here because the user object is missing some properties.
1292 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1293 $this->assertEquals('DFRN', $result['user']['location']);
1294 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1295 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1296 $this->assertEquals('dfrn', $result['user']['network']);
1297 $this->assertTrue($result['user']['verified']);
1301 * Test the api_users_show() function with an XML result.
1304 public function testApiUsersShowWithXml()
1306 $result = api_users_show('xml');
1307 $this->assertXml($result, 'statuses');
1311 * Test the api_users_search() function.
1314 public function testApiUsersSearch()
1316 $_GET['q'] = 'othercontact';
1317 $result = api_users_search('json');
1318 $this->assertOtherUser($result['users'][0]);
1322 * Test the api_users_search() function with an XML result.
1325 public function testApiUsersSearchWithXml()
1327 $_GET['q'] = 'othercontact';
1328 $result = api_users_search('xml');
1329 $this->assertXml($result, 'users');
1333 * Test the api_users_search() function without a GET q parameter.
1335 * @expectedException Friendica\Network\HTTPException\BadRequestException
1337 public function testApiUsersSearchWithoutQuery()
1339 api_users_search('json');
1343 * Test the api_users_lookup() function.
1345 * @expectedException Friendica\Network\HTTPException\NotFoundException
1347 public function testApiUsersLookup()
1349 api_users_lookup('json');
1353 * Test the api_users_lookup() function with an user ID.
1356 public function testApiUsersLookupWithUserId()
1358 $_REQUEST['user_id'] = $this->otherUser['id'];
1359 $result = api_users_lookup('json');
1360 $this->assertOtherUser($result['users'][0]);
1364 * Test the api_search() function.
1367 public function testApiSearch()
1369 $_REQUEST['q'] = 'reply';
1370 $_REQUEST['max_id'] = 10;
1371 $result = api_search('json');
1372 foreach ($result['status'] as $status) {
1373 $this->assertStatus($status);
1374 $this->assertContains('reply', $status['text'], null, true);
1379 * Test the api_search() function a count parameter.
1382 public function testApiSearchWithCount()
1384 $_REQUEST['q'] = 'reply';
1385 $_REQUEST['count'] = 20;
1386 $result = api_search('json');
1387 foreach ($result['status'] as $status) {
1388 $this->assertStatus($status);
1389 $this->assertContains('reply', $status['text'], null, true);
1394 * Test the api_search() function with friendica_tag
1397 public function testApiSearchWithFriendicaTag()
1399 $_REQUEST['friendica_tag'] = 'friendica';
1400 $result = api_search('json');
1401 foreach ($result['status'] as $status) {
1402 $this->assertStatus($status);
1403 $this->assertContains('#friendica', $status['text'], null, true);
1408 * Test the api_search() function with an rpp parameter.
1411 public function testApiSearchWithRpp()
1413 $_REQUEST['q'] = 'reply';
1414 $_REQUEST['rpp'] = 20;
1415 $result = api_search('json');
1416 foreach ($result['status'] as $status) {
1417 $this->assertStatus($status);
1418 $this->assertContains('reply', $status['text'], null, true);
1424 * Test the api_search() function without an authenticated user.
1426 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1428 public function testApiSearchWithUnallowedUser()
1430 $_SESSION['allow_api'] = false;
1431 $_GET['screen_name'] = $this->selfUser['nick'];
1436 * Test the api_search() function without any GET query parameter.
1438 * @expectedException Friendica\Network\HTTPException\BadRequestException
1440 public function testApiSearchWithoutQuery()
1446 * Test the api_statuses_home_timeline() function.
1449 public function testApiStatusesHomeTimeline()
1451 $_REQUEST['max_id'] = 10;
1452 $_REQUEST['exclude_replies'] = true;
1453 $_REQUEST['conversation_id'] = 1;
1454 $result = api_statuses_home_timeline('json');
1455 $this->assertNotEmpty($result['status']);
1456 foreach ($result['status'] as $status) {
1457 $this->assertStatus($status);
1462 * Test the api_statuses_home_timeline() function with a negative page parameter.
1465 public function testApiStatusesHomeTimelineWithNegativePage()
1467 $_REQUEST['page'] = -2;
1468 $result = api_statuses_home_timeline('json');
1469 $this->assertNotEmpty($result['status']);
1470 foreach ($result['status'] as $status) {
1471 $this->assertStatus($status);
1476 * Test the api_statuses_home_timeline() with an unallowed user.
1478 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1480 public function testApiStatusesHomeTimelineWithUnallowedUser()
1482 $_SESSION['allow_api'] = false;
1483 $_GET['screen_name'] = $this->selfUser['nick'];
1484 api_statuses_home_timeline('json');
1488 * Test the api_statuses_home_timeline() function with an RSS result.
1491 public function testApiStatusesHomeTimelineWithRss()
1493 $result = api_statuses_home_timeline('rss');
1494 $this->assertXml($result, 'statuses');
1498 * Test the api_statuses_public_timeline() function.
1501 public function testApiStatusesPublicTimeline()
1503 $_REQUEST['max_id'] = 10;
1504 $_REQUEST['conversation_id'] = 1;
1505 $result = api_statuses_public_timeline('json');
1506 $this->assertNotEmpty($result['status']);
1507 foreach ($result['status'] as $status) {
1508 $this->assertStatus($status);
1513 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1516 public function testApiStatusesPublicTimelineWithExcludeReplies()
1518 $_REQUEST['max_id'] = 10;
1519 $_REQUEST['exclude_replies'] = true;
1520 $result = api_statuses_public_timeline('json');
1521 $this->assertNotEmpty($result['status']);
1522 foreach ($result['status'] as $status) {
1523 $this->assertStatus($status);
1528 * Test the api_statuses_public_timeline() function with a negative page parameter.
1531 public function testApiStatusesPublicTimelineWithNegativePage()
1533 $_REQUEST['page'] = -2;
1534 $result = api_statuses_public_timeline('json');
1535 $this->assertNotEmpty($result['status']);
1536 foreach ($result['status'] as $status) {
1537 $this->assertStatus($status);
1542 * Test the api_statuses_public_timeline() function with an unallowed user.
1544 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1546 public function testApiStatusesPublicTimelineWithUnallowedUser()
1548 $_SESSION['allow_api'] = false;
1549 $_GET['screen_name'] = $this->selfUser['nick'];
1550 api_statuses_public_timeline('json');
1554 * Test the api_statuses_public_timeline() function with an RSS result.
1557 public function testApiStatusesPublicTimelineWithRss()
1559 $result = api_statuses_public_timeline('rss');
1560 $this->assertXml($result, 'statuses');
1564 * Test the api_statuses_networkpublic_timeline() function.
1567 public function testApiStatusesNetworkpublicTimeline()
1569 $_REQUEST['max_id'] = 10;
1570 $result = api_statuses_networkpublic_timeline('json');
1571 $this->assertNotEmpty($result['status']);
1572 foreach ($result['status'] as $status) {
1573 $this->assertStatus($status);
1578 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1581 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1583 $_REQUEST['page'] = -2;
1584 $result = api_statuses_networkpublic_timeline('json');
1585 $this->assertNotEmpty($result['status']);
1586 foreach ($result['status'] as $status) {
1587 $this->assertStatus($status);
1592 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1594 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1596 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1598 $_SESSION['allow_api'] = false;
1599 $_GET['screen_name'] = $this->selfUser['nick'];
1600 api_statuses_networkpublic_timeline('json');
1604 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1607 public function testApiStatusesNetworkpublicTimelineWithRss()
1609 $result = api_statuses_networkpublic_timeline('rss');
1610 $this->assertXml($result, 'statuses');
1614 * Test the api_statuses_show() function.
1616 * @expectedException Friendica\Network\HTTPException\BadRequestException
1618 public function testApiStatusesShow()
1620 api_statuses_show('json');
1624 * Test the api_statuses_show() function with an ID.
1627 public function testApiStatusesShowWithId()
1629 $this->app->argv[3] = 1;
1630 $result = api_statuses_show('json');
1631 $this->assertStatus($result['status']);
1635 * Test the api_statuses_show() function with the conversation parameter.
1638 public function testApiStatusesShowWithConversation()
1640 $this->app->argv[3] = 1;
1641 $_REQUEST['conversation'] = 1;
1642 $result = api_statuses_show('json');
1643 $this->assertNotEmpty($result['status']);
1644 foreach ($result['status'] as $status) {
1645 $this->assertStatus($status);
1650 * Test the api_statuses_show() function with an unallowed user.
1652 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1654 public function testApiStatusesShowWithUnallowedUser()
1656 $_SESSION['allow_api'] = false;
1657 $_GET['screen_name'] = $this->selfUser['nick'];
1658 api_statuses_show('json');
1662 * Test the api_conversation_show() function.
1664 * @expectedException Friendica\Network\HTTPException\BadRequestException
1666 public function testApiConversationShow()
1668 api_conversation_show('json');
1672 * Test the api_conversation_show() function with an ID.
1675 public function testApiConversationShowWithId()
1677 $this->app->argv[3] = 1;
1678 $_REQUEST['max_id'] = 10;
1679 $_REQUEST['page'] = -2;
1680 $result = api_conversation_show('json');
1681 $this->assertNotEmpty($result['status']);
1682 foreach ($result['status'] as $status) {
1683 $this->assertStatus($status);
1688 * Test the api_conversation_show() function with an unallowed user.
1690 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1692 public function testApiConversationShowWithUnallowedUser()
1694 $_SESSION['allow_api'] = false;
1695 $_GET['screen_name'] = $this->selfUser['nick'];
1696 api_conversation_show('json');
1700 * Test the api_statuses_repeat() function.
1702 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1704 public function testApiStatusesRepeat()
1706 api_statuses_repeat('json');
1710 * Test the api_statuses_repeat() function without an authenticated user.
1712 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1714 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1716 $_SESSION['authenticated'] = false;
1717 api_statuses_repeat('json');
1721 * Test the api_statuses_repeat() function with an ID.
1724 public function testApiStatusesRepeatWithId()
1726 $this->app->argv[3] = 1;
1727 $result = api_statuses_repeat('json');
1728 $this->assertStatus($result['status']);
1730 // Also test with a shared status
1731 $this->app->argv[3] = 5;
1732 $result = api_statuses_repeat('json');
1733 $this->assertStatus($result['status']);
1737 * Test the api_statuses_destroy() function.
1739 * @expectedException Friendica\Network\HTTPException\BadRequestException
1741 public function testApiStatusesDestroy()
1743 api_statuses_destroy('json');
1747 * Test the api_statuses_destroy() function without an authenticated user.
1749 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1751 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1753 $_SESSION['authenticated'] = false;
1754 api_statuses_destroy('json');
1758 * Test the api_statuses_destroy() function with an ID.
1761 public function testApiStatusesDestroyWithId()
1763 $this->app->argv[3] = 1;
1764 $result = api_statuses_destroy('json');
1765 $this->assertStatus($result['status']);
1769 * Test the api_statuses_mentions() function.
1772 public function testApiStatusesMentions()
1774 $this->app->user = ['nickname' => $this->selfUser['nick']];
1775 $_REQUEST['max_id'] = 10;
1776 $result = api_statuses_mentions('json');
1777 $this->assertEmpty($result['status']);
1778 // We should test with mentions in the database.
1782 * Test the api_statuses_mentions() function with a negative page parameter.
1785 public function testApiStatusesMentionsWithNegativePage()
1787 $_REQUEST['page'] = -2;
1788 $result = api_statuses_mentions('json');
1789 $this->assertEmpty($result['status']);
1793 * Test the api_statuses_mentions() function with an unallowed user.
1795 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1797 public function testApiStatusesMentionsWithUnallowedUser()
1799 $_SESSION['allow_api'] = false;
1800 $_GET['screen_name'] = $this->selfUser['nick'];
1801 api_statuses_mentions('json');
1805 * Test the api_statuses_mentions() function with an RSS result.
1808 public function testApiStatusesMentionsWithRss()
1810 $result = api_statuses_mentions('rss');
1811 $this->assertXml($result, 'statuses');
1815 * Test the api_statuses_user_timeline() function.
1818 public function testApiStatusesUserTimeline()
1820 $_REQUEST['max_id'] = 10;
1821 $_REQUEST['exclude_replies'] = true;
1822 $_REQUEST['conversation_id'] = 1;
1823 $result = api_statuses_user_timeline('json');
1824 $this->assertNotEmpty($result['status']);
1825 foreach ($result['status'] as $status) {
1826 $this->assertStatus($status);
1831 * Test the api_statuses_user_timeline() function with a negative page parameter.
1834 public function testApiStatusesUserTimelineWithNegativePage()
1836 $_REQUEST['page'] = -2;
1837 $result = api_statuses_user_timeline('json');
1838 $this->assertNotEmpty($result['status']);
1839 foreach ($result['status'] as $status) {
1840 $this->assertStatus($status);
1845 * Test the api_statuses_user_timeline() function with an RSS result.
1848 public function testApiStatusesUserTimelineWithRss()
1850 $result = api_statuses_user_timeline('rss');
1851 $this->assertXml($result, 'statuses');
1855 * Test the api_statuses_user_timeline() function with an unallowed user.
1857 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1859 public function testApiStatusesUserTimelineWithUnallowedUser()
1861 $_SESSION['allow_api'] = false;
1862 $_GET['screen_name'] = $this->selfUser['nick'];
1863 api_statuses_user_timeline('json');
1867 * Test the api_favorites_create_destroy() function.
1869 * @expectedException Friendica\Network\HTTPException\BadRequestException
1871 public function testApiFavoritesCreateDestroy()
1873 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1874 $this->app->argc = count($this->app->argv);
1875 api_favorites_create_destroy('json');
1879 * Test the api_favorites_create_destroy() function with an invalid ID.
1881 * @expectedException Friendica\Network\HTTPException\BadRequestException
1883 public function testApiFavoritesCreateDestroyWithInvalidId()
1885 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1886 $this->app->argc = count($this->app->argv);
1887 api_favorites_create_destroy('json');
1891 * Test the api_favorites_create_destroy() function with an invalid action.
1893 * @expectedException Friendica\Network\HTTPException\BadRequestException
1895 public function testApiFavoritesCreateDestroyWithInvalidAction()
1897 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1898 $this->app->argc = count($this->app->argv);
1899 $_REQUEST['id'] = 1;
1900 api_favorites_create_destroy('json');
1904 * Test the api_favorites_create_destroy() function with the create action.
1907 public function testApiFavoritesCreateDestroyWithCreateAction()
1909 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1910 $this->app->argc = count($this->app->argv);
1911 $_REQUEST['id'] = 3;
1912 $result = api_favorites_create_destroy('json');
1913 $this->assertStatus($result['status']);
1917 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1920 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1922 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1923 $this->app->argc = count($this->app->argv);
1924 $_REQUEST['id'] = 3;
1925 $result = api_favorites_create_destroy('rss');
1926 $this->assertXml($result, 'status');
1930 * Test the api_favorites_create_destroy() function with the destroy action.
1933 public function testApiFavoritesCreateDestroyWithDestroyAction()
1935 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1936 $this->app->argc = count($this->app->argv);
1937 $_REQUEST['id'] = 3;
1938 $result = api_favorites_create_destroy('json');
1939 $this->assertStatus($result['status']);
1943 * Test the api_favorites_create_destroy() function without an authenticated user.
1945 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1947 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1949 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1950 $this->app->argc = count($this->app->argv);
1951 $_SESSION['authenticated'] = false;
1952 api_favorites_create_destroy('json');
1956 * Test the api_favorites() function.
1959 public function testApiFavorites()
1961 $_REQUEST['page'] = -1;
1962 $_REQUEST['max_id'] = 10;
1963 $result = api_favorites('json');
1964 foreach ($result['status'] as $status) {
1965 $this->assertStatus($status);
1970 * Test the api_favorites() function with an RSS result.
1973 public function testApiFavoritesWithRss()
1975 $result = api_favorites('rss');
1976 $this->assertXml($result, 'statuses');
1980 * Test the api_favorites() function with an unallowed user.
1982 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1984 public function testApiFavoritesWithUnallowedUser()
1986 $_SESSION['allow_api'] = false;
1987 $_GET['screen_name'] = $this->selfUser['nick'];
1988 api_favorites('json');
1992 * Test the api_format_messages() function.
1995 public function testApiFormatMessages()
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'."\n".'item_body', $result['text']);
2003 $this->assertEquals(1, $result['id']);
2004 $this->assertEquals(2, $result['recipient_id']);
2005 $this->assertEquals(3, $result['sender_id']);
2006 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2007 $this->assertEquals('sender_name', $result['sender_screen_name']);
2011 * Test the api_format_messages() function with HTML.
2014 public function testApiFormatMessagesWithHtmlText()
2016 $_GET['getText'] = 'html';
2017 $result = api_format_messages(
2018 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2019 ['id' => 2, 'screen_name' => 'recipient_name'],
2020 ['id' => 3, 'screen_name' => 'sender_name']
2022 $this->assertEquals('item_title', $result['title']);
2023 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2027 * Test the api_format_messages() function with plain text.
2030 public function testApiFormatMessagesWithPlainText()
2032 $_GET['getText'] = 'plain';
2033 $result = api_format_messages(
2034 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2035 ['id' => 2, 'screen_name' => 'recipient_name'],
2036 ['id' => 3, 'screen_name' => 'sender_name']
2038 $this->assertEquals('item_title', $result['title']);
2039 $this->assertEquals('item_body', $result['text']);
2043 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2046 public function testApiFormatMessagesWithoutUserObjects()
2048 $_GET['getUserObjects'] = 'false';
2049 $result = api_format_messages(
2050 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2051 ['id' => 2, 'screen_name' => 'recipient_name'],
2052 ['id' => 3, 'screen_name' => 'sender_name']
2054 $this->assertTrue(!isset($result['sender']));
2055 $this->assertTrue(!isset($result['recipient']));
2059 * Test the api_convert_item() function.
2062 public function testApiConvertItem()
2064 $result = api_convert_item(
2066 'network' => 'feed',
2067 'title' => 'item_title',
2068 // We need a long string to test that it is correctly cut
2069 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2070 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2071 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2072 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2073 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2074 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2075 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2076 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2077 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2078 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2079 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2080 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2081 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2082 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2083 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2084 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2085 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2086 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2087 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2088 'repellat officia illum quos impedit quam iste esse unde qui '.
2089 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2090 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2091 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2092 'plink' => 'item_plink'
2095 $this->assertStringStartsWith('item_title', $result['text']);
2096 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2100 * Test the api_convert_item() function with an empty item body.
2103 public function testApiConvertItemWithoutBody()
2105 $result = api_convert_item(
2107 'network' => 'feed',
2108 'title' => 'item_title',
2110 'plink' => 'item_plink'
2113 $this->assertEquals('item_title', $result['text']);
2114 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2118 * Test the api_convert_item() function with the title in the body.
2121 public function testApiConvertItemWithTitleInBody()
2123 $result = api_convert_item(
2125 'title' => 'item_title',
2126 'body' => 'item_title item_body'
2129 $this->assertEquals('item_title item_body', $result['text']);
2130 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2134 * Test the api_get_attachments() function.
2137 public function testApiGetAttachments()
2140 $this->assertEmpty(api_get_attachments($body));
2144 * Test the api_get_attachments() function with an img tag.
2147 public function testApiGetAttachmentsWithImage()
2149 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2150 $this->assertInternalType('array', api_get_attachments($body));
2154 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2157 public function testApiGetAttachmentsWithImageAndAndStatus()
2159 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2160 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2161 $this->assertInternalType('array', api_get_attachments($body));
2165 * Test the api_get_entitities() function.
2168 public function testApiGetEntitities()
2171 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2175 * Test the api_get_entitities() function with the include_entities parameter.
2178 public function testApiGetEntititiesWithIncludeEntities()
2180 $_REQUEST['include_entities'] = 'true';
2182 $result = api_get_entitities($text, 'bbcode');
2183 $this->assertInternalType('array', $result['hashtags']);
2184 $this->assertInternalType('array', $result['symbols']);
2185 $this->assertInternalType('array', $result['urls']);
2186 $this->assertInternalType('array', $result['user_mentions']);
2190 * Test the api_format_items_embeded_images() function.
2193 public function testApiFormatItemsEmbededImages()
2195 $this->assertEquals(
2196 'text ' . System::baseUrl() . '/display/item_guid',
2197 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2202 * Test the api_contactlink_to_array() function.
2205 public function testApiContactlinkToArray()
2207 $this->assertEquals(
2212 api_contactlink_to_array('text')
2217 * Test the api_contactlink_to_array() function with an URL.
2220 public function testApiContactlinkToArrayWithUrl()
2222 $this->assertEquals(
2224 'name' => ['link_text'],
2227 api_contactlink_to_array('text <a href="url">link_text</a>')
2232 * Test the api_format_items_activities() function.
2235 public function testApiFormatItemsActivities()
2237 $item = ['uid' => 0, 'uri' => ''];
2238 $result = api_format_items_activities($item);
2239 $this->assertArrayHasKey('like', $result);
2240 $this->assertArrayHasKey('dislike', $result);
2241 $this->assertArrayHasKey('attendyes', $result);
2242 $this->assertArrayHasKey('attendno', $result);
2243 $this->assertArrayHasKey('attendmaybe', $result);
2247 * Test the api_format_items_activities() function with an XML result.
2250 public function testApiFormatItemsActivitiesWithXml()
2252 $item = ['uid' => 0, 'uri' => ''];
2253 $result = api_format_items_activities($item, 'xml');
2254 $this->assertArrayHasKey('friendica:like', $result);
2255 $this->assertArrayHasKey('friendica:dislike', $result);
2256 $this->assertArrayHasKey('friendica:attendyes', $result);
2257 $this->assertArrayHasKey('friendica:attendno', $result);
2258 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2262 * Test the api_format_items_profiles() function.
2265 public function testApiFormatItemsProfiles()
2268 'id' => 'profile_id',
2269 'profile-name' => 'profile_name',
2270 'is-default' => true,
2271 'hide-friends' => true,
2272 'photo' => 'profile_photo',
2273 'thumb' => 'profile_thumb',
2275 'net-publish' => true,
2276 'pdesc' => 'description',
2277 'dob' => 'date_of_birth',
2278 'address' => 'address',
2279 'locality' => 'city',
2280 'region' => 'region',
2281 'postal-code' => 'postal_code',
2282 'country-name' => 'country',
2283 'hometown' => 'hometown',
2284 'gender' => 'gender',
2285 'marital' => 'marital',
2286 'with' => 'marital_with',
2287 'howlong' => 'marital_since',
2288 'sexual' => 'sexual',
2289 'politic' => 'politic',
2290 'religion' => 'religion',
2291 'pub_keywords' => 'public_keywords',
2292 'prv_keywords' => 'private_keywords',
2295 'dislikes' => 'dislikes',
2301 'interest' => 'interest',
2302 'romance' => 'romance',
2304 'education' => 'education',
2305 'contact' => 'social_networks',
2306 'homepage' => 'homepage'
2308 $result = api_format_items_profiles($profile_row);
2309 $this->assertEquals(
2311 'profile_id' => 'profile_id',
2312 'profile_name' => 'profile_name',
2313 'is_default' => true,
2314 'hide_friends' => true,
2315 'profile_photo' => 'profile_photo',
2316 'profile_thumb' => 'profile_thumb',
2318 'net_publish' => true,
2319 'description' => 'description',
2320 'date_of_birth' => 'date_of_birth',
2321 'address' => 'address',
2323 'region' => 'region',
2324 'postal_code' => 'postal_code',
2325 'country' => 'country',
2326 'hometown' => 'hometown',
2327 'gender' => 'gender',
2328 'marital' => 'marital',
2329 'marital_with' => 'marital_with',
2330 'marital_since' => 'marital_since',
2331 'sexual' => 'sexual',
2332 'politic' => 'politic',
2333 'religion' => 'religion',
2334 'public_keywords' => 'public_keywords',
2335 'private_keywords' => 'private_keywords',
2338 'dislikes' => 'dislikes',
2344 'interest' => 'interest',
2345 'romance' => 'romance',
2347 'education' => 'education',
2348 'social_networks' => 'social_networks',
2349 'homepage' => 'homepage',
2357 * Test the api_format_items() function.
2360 public function testApiFormatItems()
2364 'item_network' => 'item_network',
2370 'author-network' => Protocol::DFRN,
2371 'author-link' => 'http://localhost/profile/othercontact',
2375 $result = api_format_items($items, ['id' => 0], true);
2376 foreach ($result as $status) {
2377 $this->assertStatus($status);
2382 * Test the api_format_items() function with an XML result.
2385 public function testApiFormatItemsWithXml()
2393 'author-network' => Protocol::DFRN,
2394 'author-link' => 'http://localhost/profile/othercontact',
2398 $result = api_format_items($items, ['id' => 0], true, 'xml');
2399 foreach ($result as $status) {
2400 $this->assertStatus($status);
2405 * Test the api_format_items() function.
2408 public function testApiAccountRateLimitStatus()
2410 $result = api_account_rate_limit_status('json');
2411 $this->assertEquals(150, $result['hash']['remaining_hits']);
2412 $this->assertEquals(150, $result['hash']['hourly_limit']);
2413 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2417 * Test the api_format_items() function with an XML result.
2420 public function testApiAccountRateLimitStatusWithXml()
2422 $result = api_account_rate_limit_status('xml');
2423 $this->assertXml($result, 'hash');
2427 * Test the api_help_test() function.
2430 public function testApiHelpTest()
2432 $result = api_help_test('json');
2433 $this->assertEquals(['ok' => 'ok'], $result);
2437 * Test the api_help_test() function with an XML result.
2440 public function testApiHelpTestWithXml()
2442 $result = api_help_test('xml');
2443 $this->assertXml($result, 'ok');
2447 * Test the api_lists_list() function.
2450 public function testApiListsList()
2452 $result = api_lists_list('json');
2453 $this->assertEquals(['lists_list' => []], $result);
2457 * Test the api_lists_ownerships() function.
2460 public function testApiListsOwnerships()
2462 $result = api_lists_ownerships('json');
2463 foreach ($result['lists']['lists'] as $list) {
2464 $this->assertList($list);
2469 * Test the api_lists_ownerships() function without an authenticated user.
2471 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2473 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2475 $_SESSION['authenticated'] = false;
2476 api_lists_ownerships('json');
2480 * Test the api_lists_statuses() function.
2481 * @expectedException Friendica\Network\HTTPException\BadRequestException
2484 public function testApiListsStatuses()
2486 api_lists_statuses('json');
2490 * Test the api_lists_statuses() function with a list ID.
2493 public function testApiListsStatusesWithListId()
2495 $_REQUEST['list_id'] = 1;
2496 $_REQUEST['page'] = -1;
2497 $_REQUEST['max_id'] = 10;
2498 $result = api_lists_statuses('json');
2499 foreach ($result['status'] as $status) {
2500 $this->assertStatus($status);
2505 * Test the api_lists_statuses() function with a list ID and a RSS result.
2508 public function testApiListsStatusesWithListIdAndRss()
2510 $_REQUEST['list_id'] = 1;
2511 $result = api_lists_statuses('rss');
2512 $this->assertXml($result, 'statuses');
2516 * Test the api_lists_statuses() function with an unallowed user.
2518 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2520 public function testApiListsStatusesWithUnallowedUser()
2522 $_SESSION['allow_api'] = false;
2523 $_GET['screen_name'] = $this->selfUser['nick'];
2524 api_lists_statuses('json');
2528 * Test the api_statuses_f() function.
2531 public function testApiStatusesFWithFriends()
2534 $result = api_statuses_f('friends');
2535 $this->assertArrayHasKey('user', $result);
2539 * Test the api_statuses_f() function.
2542 public function testApiStatusesFWithFollowers()
2544 $result = api_statuses_f('followers');
2545 $this->assertArrayHasKey('user', $result);
2549 * Test the api_statuses_f() function.
2552 public function testApiStatusesFWithBlocks()
2554 $result = api_statuses_f('blocks');
2555 $this->assertArrayHasKey('user', $result);
2559 * Test the api_statuses_f() function.
2562 public function testApiStatusesFWithIncoming()
2564 $result = api_statuses_f('incoming');
2565 $this->assertArrayHasKey('user', $result);
2569 * Test the api_statuses_f() function an undefined cursor GET variable.
2572 public function testApiStatusesFWithUndefinedCursor()
2574 $_GET['cursor'] = 'undefined';
2575 $this->assertFalse(api_statuses_f('friends'));
2579 * Test the api_statuses_friends() function.
2582 public function testApiStatusesFriends()
2584 $result = api_statuses_friends('json');
2585 $this->assertArrayHasKey('user', $result);
2589 * Test the api_statuses_friends() function an undefined cursor GET variable.
2592 public function testApiStatusesFriendsWithUndefinedCursor()
2594 $_GET['cursor'] = 'undefined';
2595 $this->assertFalse(api_statuses_friends('json'));
2599 * Test the api_statuses_followers() function.
2602 public function testApiStatusesFollowers()
2604 $result = api_statuses_followers('json');
2605 $this->assertArrayHasKey('user', $result);
2609 * Test the api_statuses_followers() function an undefined cursor GET variable.
2612 public function testApiStatusesFollowersWithUndefinedCursor()
2614 $_GET['cursor'] = 'undefined';
2615 $this->assertFalse(api_statuses_followers('json'));
2619 * Test the api_blocks_list() function.
2622 public function testApiBlocksList()
2624 $result = api_blocks_list('json');
2625 $this->assertArrayHasKey('user', $result);
2629 * Test the api_blocks_list() function an undefined cursor GET variable.
2632 public function testApiBlocksListWithUndefinedCursor()
2634 $_GET['cursor'] = 'undefined';
2635 $this->assertFalse(api_blocks_list('json'));
2639 * Test the api_friendships_incoming() function.
2642 public function testApiFriendshipsIncoming()
2644 $result = api_friendships_incoming('json');
2645 $this->assertArrayHasKey('id', $result);
2649 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2652 public function testApiFriendshipsIncomingWithUndefinedCursor()
2654 $_GET['cursor'] = 'undefined';
2655 $this->assertFalse(api_friendships_incoming('json'));
2659 * Test the api_statusnet_config() function.
2662 public function testApiStatusnetConfig()
2664 $result = api_statusnet_config('json');
2665 $this->assertEquals('localhost', $result['config']['site']['server']);
2666 $this->assertEquals('default', $result['config']['site']['theme']);
2667 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2668 $this->assertTrue($result['config']['site']['fancy']);
2669 $this->assertEquals('en', $result['config']['site']['language']);
2670 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2671 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2672 $this->assertEquals('false', $result['config']['site']['private']);
2673 $this->assertEquals('false', $result['config']['site']['ssl']);
2674 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2678 * Test the api_statusnet_version() function.
2681 public function testApiStatusnetVersion()
2683 $result = api_statusnet_version('json');
2684 $this->assertEquals('0.9.7', $result['version']);
2688 * Test the api_ff_ids() function.
2691 public function testApiFfIds()
2693 $result = api_ff_ids('json');
2694 $this->assertNull($result);
2698 * Test the api_ff_ids() function with a result.
2701 public function testApiFfIdsWithResult()
2703 $this->markTestIncomplete();
2707 * Test the api_ff_ids() function without an authenticated user.
2709 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2711 public function testApiFfIdsWithoutAuthenticatedUser()
2713 $_SESSION['authenticated'] = false;
2718 * Test the api_friends_ids() function.
2721 public function testApiFriendsIds()
2723 $result = api_friends_ids('json');
2724 $this->assertNull($result);
2728 * Test the api_followers_ids() function.
2731 public function testApiFollowersIds()
2733 $result = api_followers_ids('json');
2734 $this->assertNull($result);
2738 * Test the api_direct_messages_new() function.
2741 public function testApiDirectMessagesNew()
2743 $result = api_direct_messages_new('json');
2744 $this->assertNull($result);
2748 * Test the api_direct_messages_new() function without an authenticated user.
2750 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2752 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2754 $_SESSION['authenticated'] = false;
2755 api_direct_messages_new('json');
2759 * Test the api_direct_messages_new() function with an user ID.
2762 public function testApiDirectMessagesNewWithUserId()
2764 $_POST['text'] = 'message_text';
2765 $_POST['user_id'] = $this->otherUser['id'];
2766 $result = api_direct_messages_new('json');
2767 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2771 * Test the api_direct_messages_new() function with a screen name.
2774 public function testApiDirectMessagesNewWithScreenName()
2776 $_POST['text'] = 'message_text';
2777 $_POST['screen_name'] = $this->friendUser['nick'];
2778 $result = api_direct_messages_new('json');
2779 $this->assertEquals(1, $result['direct_message']['id']);
2780 $this->assertContains('message_text', $result['direct_message']['text']);
2781 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2782 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2786 * Test the api_direct_messages_new() function with a title.
2789 public function testApiDirectMessagesNewWithTitle()
2791 $_POST['text'] = 'message_text';
2792 $_POST['screen_name'] = $this->friendUser['nick'];
2793 $_REQUEST['title'] = 'message_title';
2794 $result = api_direct_messages_new('json');
2795 $this->assertEquals(1, $result['direct_message']['id']);
2796 $this->assertContains('message_text', $result['direct_message']['text']);
2797 $this->assertContains('message_title', $result['direct_message']['text']);
2798 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2799 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2803 * Test the api_direct_messages_new() function with an RSS result.
2806 public function testApiDirectMessagesNewWithRss()
2808 $_POST['text'] = 'message_text';
2809 $_POST['screen_name'] = $this->friendUser['nick'];
2810 $result = api_direct_messages_new('rss');
2811 $this->assertXml($result, 'direct-messages');
2815 * Test the api_direct_messages_destroy() function.
2817 * @expectedException Friendica\Network\HTTPException\BadRequestException
2819 public function testApiDirectMessagesDestroy()
2821 api_direct_messages_destroy('json');
2825 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2828 public function testApiDirectMessagesDestroyWithVerbose()
2830 $_GET['friendica_verbose'] = 'true';
2831 $result = api_direct_messages_destroy('json');
2832 $this->assertEquals(
2835 'result' => 'error',
2836 'message' => 'message id or parenturi not specified'
2844 * Test the api_direct_messages_destroy() function without an authenticated user.
2846 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2848 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2850 $_SESSION['authenticated'] = false;
2851 api_direct_messages_destroy('json');
2855 * Test the api_direct_messages_destroy() function with a non-zero ID.
2857 * @expectedException Friendica\Network\HTTPException\BadRequestException
2859 public function testApiDirectMessagesDestroyWithId()
2861 $_REQUEST['id'] = 1;
2862 api_direct_messages_destroy('json');
2866 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2869 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2871 $_REQUEST['id'] = 1;
2872 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2873 $_GET['friendica_verbose'] = 'true';
2874 $result = api_direct_messages_destroy('json');
2875 $this->assertEquals(
2878 'result' => 'error',
2879 'message' => 'message id not in database'
2887 * Test the api_direct_messages_destroy() function with a non-zero ID.
2890 public function testApiDirectMessagesDestroyWithCorrectId()
2892 $this->markTestIncomplete('We need to add a dataset for this.');
2896 * Test the api_direct_messages_box() function.
2899 public function testApiDirectMessagesBoxWithSentbox()
2901 $_REQUEST['page'] = -1;
2902 $_REQUEST['max_id'] = 10;
2903 $result = api_direct_messages_box('json', 'sentbox', 'false');
2904 $this->assertArrayHasKey('direct_message', $result);
2908 * Test the api_direct_messages_box() function.
2911 public function testApiDirectMessagesBoxWithConversation()
2913 $result = api_direct_messages_box('json', 'conversation', 'false');
2914 $this->assertArrayHasKey('direct_message', $result);
2918 * Test the api_direct_messages_box() function.
2921 public function testApiDirectMessagesBoxWithAll()
2923 $result = api_direct_messages_box('json', 'all', 'false');
2924 $this->assertArrayHasKey('direct_message', $result);
2928 * Test the api_direct_messages_box() function.
2931 public function testApiDirectMessagesBoxWithInbox()
2933 $result = api_direct_messages_box('json', 'inbox', 'false');
2934 $this->assertArrayHasKey('direct_message', $result);
2938 * Test the api_direct_messages_box() function.
2941 public function testApiDirectMessagesBoxWithVerbose()
2943 $result = api_direct_messages_box('json', 'sentbox', 'true');
2944 $this->assertEquals(
2947 'result' => 'error',
2948 'message' => 'no mails available'
2956 * Test the api_direct_messages_box() function with a RSS result.
2959 public function testApiDirectMessagesBoxWithRss()
2961 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2962 $this->assertXml($result, 'direct-messages');
2966 * Test the api_direct_messages_box() function without an authenticated user.
2968 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2970 public function testApiDirectMessagesBoxWithUnallowedUser()
2972 $_SESSION['allow_api'] = false;
2973 $_GET['screen_name'] = $this->selfUser['nick'];
2974 api_direct_messages_box('json', 'sentbox', 'false');
2978 * Test the api_direct_messages_sentbox() function.
2981 public function testApiDirectMessagesSentbox()
2983 $result = api_direct_messages_sentbox('json');
2984 $this->assertArrayHasKey('direct_message', $result);
2988 * Test the api_direct_messages_inbox() function.
2991 public function testApiDirectMessagesInbox()
2993 $result = api_direct_messages_inbox('json');
2994 $this->assertArrayHasKey('direct_message', $result);
2998 * Test the api_direct_messages_all() function.
3001 public function testApiDirectMessagesAll()
3003 $result = api_direct_messages_all('json');
3004 $this->assertArrayHasKey('direct_message', $result);
3008 * Test the api_direct_messages_conversation() function.
3011 public function testApiDirectMessagesConversation()
3013 $result = api_direct_messages_conversation('json');
3014 $this->assertArrayHasKey('direct_message', $result);
3018 * Test the api_oauth_request_token() function.
3021 public function testApiOauthRequestToken()
3023 $this->markTestIncomplete('killme() kills phpunit as well');
3027 * Test the api_oauth_access_token() function.
3030 public function testApiOauthAccessToken()
3032 $this->markTestIncomplete('killme() kills phpunit as well');
3036 * Test the api_fr_photoalbum_delete() function.
3038 * @expectedException Friendica\Network\HTTPException\BadRequestException
3040 public function testApiFrPhotoalbumDelete()
3042 api_fr_photoalbum_delete('json');
3046 * Test the api_fr_photoalbum_delete() function with an album name.
3048 * @expectedException Friendica\Network\HTTPException\BadRequestException
3050 public function testApiFrPhotoalbumDeleteWithAlbum()
3052 $_REQUEST['album'] = 'album_name';
3053 api_fr_photoalbum_delete('json');
3057 * Test the api_fr_photoalbum_delete() function with an album name.
3060 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3062 $this->markTestIncomplete('We need to add a dataset for this.');
3066 * Test the api_fr_photoalbum_delete() function.
3068 * @expectedException Friendica\Network\HTTPException\BadRequestException
3070 public function testApiFrPhotoalbumUpdate()
3072 api_fr_photoalbum_update('json');
3076 * Test the api_fr_photoalbum_delete() function with an album name.
3078 * @expectedException Friendica\Network\HTTPException\BadRequestException
3080 public function testApiFrPhotoalbumUpdateWithAlbum()
3082 $_REQUEST['album'] = 'album_name';
3083 api_fr_photoalbum_update('json');
3087 * Test the api_fr_photoalbum_delete() function with an album name.
3089 * @expectedException Friendica\Network\HTTPException\BadRequestException
3091 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3093 $_REQUEST['album'] = 'album_name';
3094 $_REQUEST['album_new'] = 'album_name';
3095 api_fr_photoalbum_update('json');
3099 * Test the api_fr_photoalbum_update() function without an authenticated user.
3101 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3103 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3105 $_SESSION['authenticated'] = false;
3106 api_fr_photoalbum_update('json');
3110 * Test the api_fr_photoalbum_delete() function with an album name.
3113 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3115 $this->markTestIncomplete('We need to add a dataset for this.');
3119 * Test the api_fr_photos_list() function.
3122 public function testApiFrPhotosList()
3124 $result = api_fr_photos_list('json');
3125 $this->assertArrayHasKey('photo', $result);
3129 * Test the api_fr_photos_list() function without an authenticated user.
3131 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3133 public function testApiFrPhotosListWithoutAuthenticatedUser()
3135 $_SESSION['authenticated'] = false;
3136 api_fr_photos_list('json');
3140 * Test the api_fr_photo_create_update() function.
3142 * @expectedException Friendica\Network\HTTPException\BadRequestException
3144 public function testApiFrPhotoCreateUpdate()
3146 api_fr_photo_create_update('json');
3150 * Test the api_fr_photo_create_update() function without an authenticated user.
3152 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3154 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3156 $_SESSION['authenticated'] = false;
3157 api_fr_photo_create_update('json');
3161 * Test the api_fr_photo_create_update() function with an album name.
3163 * @expectedException Friendica\Network\HTTPException\BadRequestException
3165 public function testApiFrPhotoCreateUpdateWithAlbum()
3167 $_REQUEST['album'] = 'album_name';
3168 api_fr_photo_create_update('json');
3172 * Test the api_fr_photo_create_update() function with the update mode.
3175 public function testApiFrPhotoCreateUpdateWithUpdate()
3177 $this->markTestIncomplete('We need to create a dataset for this');
3181 * Test the api_fr_photo_create_update() function with an uploaded file.
3184 public function testApiFrPhotoCreateUpdateWithFile()
3186 $this->markTestIncomplete();
3190 * Test the api_fr_photo_delete() function.
3192 * @expectedException Friendica\Network\HTTPException\BadRequestException
3194 public function testApiFrPhotoDelete()
3196 api_fr_photo_delete('json');
3200 * Test the api_fr_photo_delete() function without an authenticated user.
3202 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3204 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3206 $_SESSION['authenticated'] = false;
3207 api_fr_photo_delete('json');
3211 * Test the api_fr_photo_delete() function with a photo ID.
3213 * @expectedException Friendica\Network\HTTPException\BadRequestException
3215 public function testApiFrPhotoDeleteWithPhotoId()
3217 $_REQUEST['photo_id'] = 1;
3218 api_fr_photo_delete('json');
3222 * Test the api_fr_photo_delete() function with a correct photo ID.
3225 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3227 $this->markTestIncomplete('We need to create a dataset for this.');
3231 * Test the api_fr_photo_detail() function.
3233 * @expectedException Friendica\Network\HTTPException\BadRequestException
3235 public function testApiFrPhotoDetail()
3237 api_fr_photo_detail('json');
3241 * Test the api_fr_photo_detail() function without an authenticated user.
3243 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3245 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3247 $_SESSION['authenticated'] = false;
3248 api_fr_photo_detail('json');
3252 * Test the api_fr_photo_detail() function with a photo ID.
3254 * @expectedException Friendica\Network\HTTPException\NotFoundException
3256 public function testApiFrPhotoDetailWithPhotoId()
3258 $_REQUEST['photo_id'] = 1;
3259 api_fr_photo_detail('json');
3263 * Test the api_fr_photo_detail() function with a correct photo ID.
3266 public function testApiFrPhotoDetailCorrectPhotoId()
3268 $this->markTestIncomplete('We need to create a dataset for this.');
3272 * Test the api_account_update_profile_image() function.
3274 * @expectedException Friendica\Network\HTTPException\BadRequestException
3276 public function testApiAccountUpdateProfileImage()
3278 api_account_update_profile_image('json');
3282 * Test the api_account_update_profile_image() function without an authenticated user.
3284 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3286 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3288 $_SESSION['authenticated'] = false;
3289 api_account_update_profile_image('json');
3293 * Test the api_account_update_profile_image() function with an uploaded file.
3295 * @expectedException Friendica\Network\HTTPException\BadRequestException
3297 public function testApiAccountUpdateProfileImageWithUpload()
3299 $this->markTestIncomplete();
3304 * Test the api_account_update_profile() function.
3307 public function testApiAccountUpdateProfile()
3309 $_POST['name'] = 'new_name';
3310 $_POST['description'] = 'new_description';
3311 $result = api_account_update_profile('json');
3312 // We can't use assertSelfUser() here because the user object is missing some properties.
3313 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3314 $this->assertEquals('DFRN', $result['user']['location']);
3315 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3316 $this->assertEquals('dfrn', $result['user']['network']);
3317 $this->assertEquals('new_name', $result['user']['name']);
3318 $this->assertEquals('new_description', $result['user']['description']);
3322 * Test the check_acl_input() function.
3325 public function testCheckAclInput()
3327 $result = check_acl_input('<aclstring>');
3328 // Where does this result come from?
3329 $this->assertEquals(1, $result);
3333 * Test the check_acl_input() function with an empty ACL string.
3336 public function testCheckAclInputWithEmptyAclString()
3338 $result = check_acl_input(' ');
3339 $this->assertFalse($result);
3343 * Test the save_media_to_database() function.
3346 public function testSaveMediaToDatabase()
3348 $this->markTestIncomplete();
3352 * Test the post_photo_item() function.
3355 public function testPostPhotoItem()
3357 $this->markTestIncomplete();
3361 * Test the prepare_photo_data() function.
3364 public function testPreparePhotoData()
3366 $this->markTestIncomplete();
3370 * Test the api_friendica_remoteauth() function.
3372 * @expectedException Friendica\Network\HTTPException\BadRequestException
3374 public function testApiFriendicaRemoteauth()
3376 api_friendica_remoteauth();
3380 * Test the api_friendica_remoteauth() function with an URL.
3382 * @expectedException Friendica\Network\HTTPException\BadRequestException
3384 public function testApiFriendicaRemoteauthWithUrl()
3386 $_GET['url'] = 'url';
3387 $_GET['c_url'] = 'url';
3388 api_friendica_remoteauth();
3392 * Test the api_friendica_remoteauth() function with a correct URL.
3395 public function testApiFriendicaRemoteauthWithCorrectUrl()
3397 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3398 $_GET['url'] = 'url';
3399 $_GET['c_url'] = $this->selfUser['nurl'];
3400 api_friendica_remoteauth();
3404 * Test the api_share_as_retweet() function.
3407 public function testApiShareAsRetweet()
3409 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3410 $result = api_share_as_retweet($item);
3411 $this->assertFalse($result);
3415 * Test the api_share_as_retweet() function with a valid item.
3418 public function testApiShareAsRetweetWithValidItem()
3420 $this->markTestIncomplete();
3424 * Test the api_get_nick() function.
3427 public function testApiGetNick()
3429 $result = api_get_nick($this->otherUser['nurl']);
3430 $this->assertEquals('othercontact', $result);
3434 * Test the api_get_nick() function with a wrong URL.
3437 public function testApiGetNickWithWrongUrl()
3439 $result = api_get_nick('wrong_url');
3440 $this->assertFalse($result);
3444 * Test the api_in_reply_to() function.
3447 public function testApiInReplyTo()
3449 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3450 $this->assertArrayHasKey('status_id', $result);
3451 $this->assertArrayHasKey('user_id', $result);
3452 $this->assertArrayHasKey('status_id_str', $result);
3453 $this->assertArrayHasKey('user_id_str', $result);
3454 $this->assertArrayHasKey('screen_name', $result);
3458 * Test the api_in_reply_to() function with a valid item.
3461 public function testApiInReplyToWithValidItem()
3463 $this->markTestIncomplete();
3467 * Test the api_clean_plain_items() function.
3470 public function testApiCleanPlainItems()
3472 $_REQUEST['include_entities'] = 'true';
3473 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3474 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3478 * Test the api_clean_attachments() function.
3481 public function testApiCleanAttachments()
3483 $this->markTestIncomplete();
3487 * Test the api_best_nickname() function.
3490 public function testApiBestNickname()
3493 $result = api_best_nickname($contacts);
3494 $this->assertNull($result);
3498 * Test the api_best_nickname() function with contacts.
3501 public function testApiBestNicknameWithContacts()
3503 $this->markTestIncomplete();
3507 * Test the api_friendica_group_show() function.
3510 public function testApiFriendicaGroupShow()
3512 $this->markTestIncomplete();
3516 * Test the api_friendica_group_delete() function.
3519 public function testApiFriendicaGroupDelete()
3521 $this->markTestIncomplete();
3525 * Test the api_lists_destroy() function.
3528 public function testApiListsDestroy()
3530 $this->markTestIncomplete();
3534 * Test the group_create() function.
3537 public function testGroupCreate()
3539 $this->markTestIncomplete();
3543 * Test the api_friendica_group_create() function.
3546 public function testApiFriendicaGroupCreate()
3548 $this->markTestIncomplete();
3552 * Test the api_lists_create() function.
3555 public function testApiListsCreate()
3557 $this->markTestIncomplete();
3561 * Test the api_friendica_group_update() function.
3564 public function testApiFriendicaGroupUpdate()
3566 $this->markTestIncomplete();
3570 * Test the api_lists_update() function.
3573 public function testApiListsUpdate()
3575 $this->markTestIncomplete();
3579 * Test the api_friendica_activity() function.
3582 public function testApiFriendicaActivity()
3584 $this->markTestIncomplete();
3588 * Test the api_friendica_notification() function.
3590 * @expectedException Friendica\Network\HTTPException\BadRequestException
3592 public function testApiFriendicaNotification()
3594 api_friendica_notification('json');
3598 * Test the api_friendica_notification() function without an authenticated user.
3600 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3602 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3604 $_SESSION['authenticated'] = false;
3605 api_friendica_notification('json');
3609 * Test the api_friendica_notification() function with an argument count.
3612 public function testApiFriendicaNotificationWithArgumentCount()
3614 $this->app->argv = ['api', 'friendica', 'notification'];
3615 $this->app->argc = count($this->app->argv);
3616 $result = api_friendica_notification('json');
3617 $this->assertEquals(['note' => false], $result);
3621 * Test the api_friendica_notification() function with an XML result.
3624 public function testApiFriendicaNotificationWithXmlResult()
3626 $this->app->argv = ['api', 'friendica', 'notification'];
3627 $this->app->argc = count($this->app->argv);
3628 $result = api_friendica_notification('xml');
3629 $this->assertXml($result, 'notes');
3633 * Test the api_friendica_notification_seen() function.
3636 public function testApiFriendicaNotificationSeen()
3638 $this->markTestIncomplete();
3642 * Test the api_friendica_direct_messages_setseen() function.
3645 public function testApiFriendicaDirectMessagesSetseen()
3647 $this->markTestIncomplete();
3651 * Test the api_friendica_direct_messages_search() function.
3654 public function testApiFriendicaDirectMessagesSearch()
3656 $this->markTestIncomplete();
3660 * Test the api_friendica_profile_show() function.
3663 public function testApiFriendicaProfileShow()
3665 $result = api_friendica_profile_show('json');
3666 // We can't use assertSelfUser() here because the user object is missing some properties.
3667 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3668 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3669 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3670 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3671 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3672 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3673 $this->assertFalse($result['$result']['multi_profiles']);
3677 * Test the api_friendica_profile_show() function with a profile ID.
3680 public function testApiFriendicaProfileShowWithProfileId()
3682 $this->markTestIncomplete('We need to add a dataset for this.');
3686 * Test the api_friendica_profile_show() function with a wrong profile ID.
3688 * @expectedException Friendica\Network\HTTPException\BadRequestException
3690 public function testApiFriendicaProfileShowWithWrongProfileId()
3692 $_REQUEST['profile_id'] = 666;
3693 api_friendica_profile_show('json');
3697 * Test the api_friendica_profile_show() function without an authenticated user.
3699 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3701 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3703 $_SESSION['authenticated'] = false;
3704 api_friendica_profile_show('json');
3708 * Test the api_saved_searches_list() function.
3711 public function testApiSavedSearchesList()
3713 $result = api_saved_searches_list('json');
3714 $this->assertEquals(1, $result['terms'][0]['id']);
3715 $this->assertEquals(1, $result['terms'][0]['id_str']);
3716 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3717 $this->assertEquals('Saved search', $result['terms'][0]['query']);