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 an rpp parameter.
1397 public function testApiSearchWithRpp()
1399 $_REQUEST['q'] = 'reply';
1400 $_REQUEST['rpp'] = 20;
1401 $result = api_search('json');
1402 foreach ($result['status'] as $status) {
1403 $this->assertStatus($status);
1404 $this->assertContains('reply', $status['text'], null, true);
1409 * Test the api_search() function with an q parameter contains hashtag.
1412 public function testApiSearchWithHashtag()
1414 $_REQUEST['q'] = '%23friendica';
1415 $result = api_search('json');
1416 foreach ($result['status'] as $status) {
1417 $this->assertStatus($status);
1418 $this->assertContains('#friendica', $status['text'], null, true);
1423 * Test the api_search() function with an exclude_replies parameter.
1426 public function testApiSearchWithExcludeReplies()
1428 $_REQUEST['max_id'] = 10;
1429 $_REQUEST['exclude_replies'] = true;
1430 $_REQUEST['q'] = 'friendica';
1431 $result = api_search('json');
1432 foreach ($result['status'] as $status) {
1433 $this->assertStatus($status);
1438 * Test the api_search() function without an authenticated user.
1440 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1442 public function testApiSearchWithUnallowedUser()
1444 $_SESSION['allow_api'] = false;
1445 $_GET['screen_name'] = $this->selfUser['nick'];
1450 * Test the api_search() function without any GET query parameter.
1452 * @expectedException Friendica\Network\HTTPException\BadRequestException
1454 public function testApiSearchWithoutQuery()
1460 * Test the api_statuses_home_timeline() function.
1463 public function testApiStatusesHomeTimeline()
1465 $_REQUEST['max_id'] = 10;
1466 $_REQUEST['exclude_replies'] = true;
1467 $_REQUEST['conversation_id'] = 1;
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() function with a negative page parameter.
1479 public function testApiStatusesHomeTimelineWithNegativePage()
1481 $_REQUEST['page'] = -2;
1482 $result = api_statuses_home_timeline('json');
1483 $this->assertNotEmpty($result['status']);
1484 foreach ($result['status'] as $status) {
1485 $this->assertStatus($status);
1490 * Test the api_statuses_home_timeline() with an unallowed user.
1492 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1494 public function testApiStatusesHomeTimelineWithUnallowedUser()
1496 $_SESSION['allow_api'] = false;
1497 $_GET['screen_name'] = $this->selfUser['nick'];
1498 api_statuses_home_timeline('json');
1502 * Test the api_statuses_home_timeline() function with an RSS result.
1505 public function testApiStatusesHomeTimelineWithRss()
1507 $result = api_statuses_home_timeline('rss');
1508 $this->assertXml($result, 'statuses');
1512 * Test the api_statuses_public_timeline() function.
1515 public function testApiStatusesPublicTimeline()
1517 $_REQUEST['max_id'] = 10;
1518 $_REQUEST['conversation_id'] = 1;
1519 $result = api_statuses_public_timeline('json');
1520 $this->assertNotEmpty($result['status']);
1521 foreach ($result['status'] as $status) {
1522 $this->assertStatus($status);
1527 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1530 public function testApiStatusesPublicTimelineWithExcludeReplies()
1532 $_REQUEST['max_id'] = 10;
1533 $_REQUEST['exclude_replies'] = true;
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 a negative page parameter.
1545 public function testApiStatusesPublicTimelineWithNegativePage()
1547 $_REQUEST['page'] = -2;
1548 $result = api_statuses_public_timeline('json');
1549 $this->assertNotEmpty($result['status']);
1550 foreach ($result['status'] as $status) {
1551 $this->assertStatus($status);
1556 * Test the api_statuses_public_timeline() function with an unallowed user.
1558 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1560 public function testApiStatusesPublicTimelineWithUnallowedUser()
1562 $_SESSION['allow_api'] = false;
1563 $_GET['screen_name'] = $this->selfUser['nick'];
1564 api_statuses_public_timeline('json');
1568 * Test the api_statuses_public_timeline() function with an RSS result.
1571 public function testApiStatusesPublicTimelineWithRss()
1573 $result = api_statuses_public_timeline('rss');
1574 $this->assertXml($result, 'statuses');
1578 * Test the api_statuses_networkpublic_timeline() function.
1581 public function testApiStatusesNetworkpublicTimeline()
1583 $_REQUEST['max_id'] = 10;
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 a negative page parameter.
1595 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1597 $_REQUEST['page'] = -2;
1598 $result = api_statuses_networkpublic_timeline('json');
1599 $this->assertNotEmpty($result['status']);
1600 foreach ($result['status'] as $status) {
1601 $this->assertStatus($status);
1606 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1608 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1610 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1612 $_SESSION['allow_api'] = false;
1613 $_GET['screen_name'] = $this->selfUser['nick'];
1614 api_statuses_networkpublic_timeline('json');
1618 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1621 public function testApiStatusesNetworkpublicTimelineWithRss()
1623 $result = api_statuses_networkpublic_timeline('rss');
1624 $this->assertXml($result, 'statuses');
1628 * Test the api_statuses_show() function.
1630 * @expectedException Friendica\Network\HTTPException\BadRequestException
1632 public function testApiStatusesShow()
1634 api_statuses_show('json');
1638 * Test the api_statuses_show() function with an ID.
1641 public function testApiStatusesShowWithId()
1643 $this->app->argv[3] = 1;
1644 $result = api_statuses_show('json');
1645 $this->assertStatus($result['status']);
1649 * Test the api_statuses_show() function with the conversation parameter.
1652 public function testApiStatusesShowWithConversation()
1654 $this->app->argv[3] = 1;
1655 $_REQUEST['conversation'] = 1;
1656 $result = api_statuses_show('json');
1657 $this->assertNotEmpty($result['status']);
1658 foreach ($result['status'] as $status) {
1659 $this->assertStatus($status);
1664 * Test the api_statuses_show() function with an unallowed user.
1666 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1668 public function testApiStatusesShowWithUnallowedUser()
1670 $_SESSION['allow_api'] = false;
1671 $_GET['screen_name'] = $this->selfUser['nick'];
1672 api_statuses_show('json');
1676 * Test the api_conversation_show() function.
1678 * @expectedException Friendica\Network\HTTPException\BadRequestException
1680 public function testApiConversationShow()
1682 api_conversation_show('json');
1686 * Test the api_conversation_show() function with an ID.
1689 public function testApiConversationShowWithId()
1691 $this->app->argv[3] = 1;
1692 $_REQUEST['max_id'] = 10;
1693 $_REQUEST['page'] = -2;
1694 $result = api_conversation_show('json');
1695 $this->assertNotEmpty($result['status']);
1696 foreach ($result['status'] as $status) {
1697 $this->assertStatus($status);
1702 * Test the api_conversation_show() function with an unallowed user.
1704 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1706 public function testApiConversationShowWithUnallowedUser()
1708 $_SESSION['allow_api'] = false;
1709 $_GET['screen_name'] = $this->selfUser['nick'];
1710 api_conversation_show('json');
1714 * Test the api_statuses_repeat() function.
1716 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1718 public function testApiStatusesRepeat()
1720 api_statuses_repeat('json');
1724 * Test the api_statuses_repeat() function without an authenticated user.
1726 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1728 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1730 $_SESSION['authenticated'] = false;
1731 api_statuses_repeat('json');
1735 * Test the api_statuses_repeat() function with an ID.
1738 public function testApiStatusesRepeatWithId()
1740 $this->app->argv[3] = 1;
1741 $result = api_statuses_repeat('json');
1742 $this->assertStatus($result['status']);
1744 // Also test with a shared status
1745 $this->app->argv[3] = 5;
1746 $result = api_statuses_repeat('json');
1747 $this->assertStatus($result['status']);
1751 * Test the api_statuses_destroy() function.
1753 * @expectedException Friendica\Network\HTTPException\BadRequestException
1755 public function testApiStatusesDestroy()
1757 api_statuses_destroy('json');
1761 * Test the api_statuses_destroy() function without an authenticated user.
1763 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1765 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1767 $_SESSION['authenticated'] = false;
1768 api_statuses_destroy('json');
1772 * Test the api_statuses_destroy() function with an ID.
1775 public function testApiStatusesDestroyWithId()
1777 $this->app->argv[3] = 1;
1778 $result = api_statuses_destroy('json');
1779 $this->assertStatus($result['status']);
1783 * Test the api_statuses_mentions() function.
1786 public function testApiStatusesMentions()
1788 $this->app->user = ['nickname' => $this->selfUser['nick']];
1789 $_REQUEST['max_id'] = 10;
1790 $result = api_statuses_mentions('json');
1791 $this->assertEmpty($result['status']);
1792 // We should test with mentions in the database.
1796 * Test the api_statuses_mentions() function with a negative page parameter.
1799 public function testApiStatusesMentionsWithNegativePage()
1801 $_REQUEST['page'] = -2;
1802 $result = api_statuses_mentions('json');
1803 $this->assertEmpty($result['status']);
1807 * Test the api_statuses_mentions() function with an unallowed user.
1809 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1811 public function testApiStatusesMentionsWithUnallowedUser()
1813 $_SESSION['allow_api'] = false;
1814 $_GET['screen_name'] = $this->selfUser['nick'];
1815 api_statuses_mentions('json');
1819 * Test the api_statuses_mentions() function with an RSS result.
1822 public function testApiStatusesMentionsWithRss()
1824 $result = api_statuses_mentions('rss');
1825 $this->assertXml($result, 'statuses');
1829 * Test the api_statuses_user_timeline() function.
1832 public function testApiStatusesUserTimeline()
1834 $_REQUEST['max_id'] = 10;
1835 $_REQUEST['exclude_replies'] = true;
1836 $_REQUEST['conversation_id'] = 1;
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 a negative page parameter.
1848 public function testApiStatusesUserTimelineWithNegativePage()
1850 $_REQUEST['page'] = -2;
1851 $result = api_statuses_user_timeline('json');
1852 $this->assertNotEmpty($result['status']);
1853 foreach ($result['status'] as $status) {
1854 $this->assertStatus($status);
1859 * Test the api_statuses_user_timeline() function with an RSS result.
1862 public function testApiStatusesUserTimelineWithRss()
1864 $result = api_statuses_user_timeline('rss');
1865 $this->assertXml($result, 'statuses');
1869 * Test the api_statuses_user_timeline() function with an unallowed user.
1871 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1873 public function testApiStatusesUserTimelineWithUnallowedUser()
1875 $_SESSION['allow_api'] = false;
1876 $_GET['screen_name'] = $this->selfUser['nick'];
1877 api_statuses_user_timeline('json');
1881 * Test the api_favorites_create_destroy() function.
1883 * @expectedException Friendica\Network\HTTPException\BadRequestException
1885 public function testApiFavoritesCreateDestroy()
1887 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1888 $this->app->argc = count($this->app->argv);
1889 api_favorites_create_destroy('json');
1893 * Test the api_favorites_create_destroy() function with an invalid ID.
1895 * @expectedException Friendica\Network\HTTPException\BadRequestException
1897 public function testApiFavoritesCreateDestroyWithInvalidId()
1899 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1900 $this->app->argc = count($this->app->argv);
1901 api_favorites_create_destroy('json');
1905 * Test the api_favorites_create_destroy() function with an invalid action.
1907 * @expectedException Friendica\Network\HTTPException\BadRequestException
1909 public function testApiFavoritesCreateDestroyWithInvalidAction()
1911 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1912 $this->app->argc = count($this->app->argv);
1913 $_REQUEST['id'] = 1;
1914 api_favorites_create_destroy('json');
1918 * Test the api_favorites_create_destroy() function with the create action.
1921 public function testApiFavoritesCreateDestroyWithCreateAction()
1923 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1924 $this->app->argc = count($this->app->argv);
1925 $_REQUEST['id'] = 3;
1926 $result = api_favorites_create_destroy('json');
1927 $this->assertStatus($result['status']);
1931 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1934 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1936 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1937 $this->app->argc = count($this->app->argv);
1938 $_REQUEST['id'] = 3;
1939 $result = api_favorites_create_destroy('rss');
1940 $this->assertXml($result, 'status');
1944 * Test the api_favorites_create_destroy() function with the destroy action.
1947 public function testApiFavoritesCreateDestroyWithDestroyAction()
1949 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1950 $this->app->argc = count($this->app->argv);
1951 $_REQUEST['id'] = 3;
1952 $result = api_favorites_create_destroy('json');
1953 $this->assertStatus($result['status']);
1957 * Test the api_favorites_create_destroy() function without an authenticated user.
1959 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1961 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1963 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1964 $this->app->argc = count($this->app->argv);
1965 $_SESSION['authenticated'] = false;
1966 api_favorites_create_destroy('json');
1970 * Test the api_favorites() function.
1973 public function testApiFavorites()
1975 $_REQUEST['page'] = -1;
1976 $_REQUEST['max_id'] = 10;
1977 $result = api_favorites('json');
1978 foreach ($result['status'] as $status) {
1979 $this->assertStatus($status);
1984 * Test the api_favorites() function with an RSS result.
1987 public function testApiFavoritesWithRss()
1989 $result = api_favorites('rss');
1990 $this->assertXml($result, 'statuses');
1994 * Test the api_favorites() function with an unallowed user.
1996 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1998 public function testApiFavoritesWithUnallowedUser()
2000 $_SESSION['allow_api'] = false;
2001 $_GET['screen_name'] = $this->selfUser['nick'];
2002 api_favorites('json');
2006 * Test the api_format_messages() function.
2009 public function testApiFormatMessages()
2011 $result = api_format_messages(
2012 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2013 ['id' => 2, 'screen_name' => 'recipient_name'],
2014 ['id' => 3, 'screen_name' => 'sender_name']
2016 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2017 $this->assertEquals(1, $result['id']);
2018 $this->assertEquals(2, $result['recipient_id']);
2019 $this->assertEquals(3, $result['sender_id']);
2020 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2021 $this->assertEquals('sender_name', $result['sender_screen_name']);
2025 * Test the api_format_messages() function with HTML.
2028 public function testApiFormatMessagesWithHtmlText()
2030 $_GET['getText'] = 'html';
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->assertEquals('item_title', $result['title']);
2037 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2041 * Test the api_format_messages() function with plain text.
2044 public function testApiFormatMessagesWithPlainText()
2046 $_GET['getText'] = 'plain';
2047 $result = api_format_messages(
2048 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2049 ['id' => 2, 'screen_name' => 'recipient_name'],
2050 ['id' => 3, 'screen_name' => 'sender_name']
2052 $this->assertEquals('item_title', $result['title']);
2053 $this->assertEquals('item_body', $result['text']);
2057 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2060 public function testApiFormatMessagesWithoutUserObjects()
2062 $_GET['getUserObjects'] = 'false';
2063 $result = api_format_messages(
2064 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2065 ['id' => 2, 'screen_name' => 'recipient_name'],
2066 ['id' => 3, 'screen_name' => 'sender_name']
2068 $this->assertTrue(!isset($result['sender']));
2069 $this->assertTrue(!isset($result['recipient']));
2073 * Test the api_convert_item() function.
2076 public function testApiConvertItem()
2078 $result = api_convert_item(
2080 'network' => 'feed',
2081 'title' => 'item_title',
2082 // We need a long string to test that it is correctly cut
2083 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2084 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2085 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2086 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2087 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2088 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2089 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2090 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2091 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2092 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2093 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2094 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2095 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2096 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2097 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2098 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2099 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2100 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2101 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2102 'repellat officia illum quos impedit quam iste esse unde qui '.
2103 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2104 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2105 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2106 'plink' => 'item_plink'
2109 $this->assertStringStartsWith('item_title', $result['text']);
2110 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2114 * Test the api_convert_item() function with an empty item body.
2117 public function testApiConvertItemWithoutBody()
2119 $result = api_convert_item(
2121 'network' => 'feed',
2122 'title' => 'item_title',
2124 'plink' => 'item_plink'
2127 $this->assertEquals('item_title', $result['text']);
2128 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2132 * Test the api_convert_item() function with the title in the body.
2135 public function testApiConvertItemWithTitleInBody()
2137 $result = api_convert_item(
2139 'title' => 'item_title',
2140 'body' => 'item_title item_body'
2143 $this->assertEquals('item_title item_body', $result['text']);
2144 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2148 * Test the api_get_attachments() function.
2151 public function testApiGetAttachments()
2154 $this->assertEmpty(api_get_attachments($body));
2158 * Test the api_get_attachments() function with an img tag.
2161 public function testApiGetAttachmentsWithImage()
2163 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2164 $this->assertInternalType('array', api_get_attachments($body));
2168 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2171 public function testApiGetAttachmentsWithImageAndAndStatus()
2173 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2174 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2175 $this->assertInternalType('array', api_get_attachments($body));
2179 * Test the api_get_entitities() function.
2182 public function testApiGetEntitities()
2185 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2189 * Test the api_get_entitities() function with the include_entities parameter.
2192 public function testApiGetEntititiesWithIncludeEntities()
2194 $_REQUEST['include_entities'] = 'true';
2196 $result = api_get_entitities($text, 'bbcode');
2197 $this->assertInternalType('array', $result['hashtags']);
2198 $this->assertInternalType('array', $result['symbols']);
2199 $this->assertInternalType('array', $result['urls']);
2200 $this->assertInternalType('array', $result['user_mentions']);
2204 * Test the api_format_items_embeded_images() function.
2207 public function testApiFormatItemsEmbededImages()
2209 $this->assertEquals(
2210 'text ' . System::baseUrl() . '/display/item_guid',
2211 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2216 * Test the api_contactlink_to_array() function.
2219 public function testApiContactlinkToArray()
2221 $this->assertEquals(
2226 api_contactlink_to_array('text')
2231 * Test the api_contactlink_to_array() function with an URL.
2234 public function testApiContactlinkToArrayWithUrl()
2236 $this->assertEquals(
2238 'name' => ['link_text'],
2241 api_contactlink_to_array('text <a href="url">link_text</a>')
2246 * Test the api_format_items_activities() function.
2249 public function testApiFormatItemsActivities()
2251 $item = ['uid' => 0, 'uri' => ''];
2252 $result = api_format_items_activities($item);
2253 $this->assertArrayHasKey('like', $result);
2254 $this->assertArrayHasKey('dislike', $result);
2255 $this->assertArrayHasKey('attendyes', $result);
2256 $this->assertArrayHasKey('attendno', $result);
2257 $this->assertArrayHasKey('attendmaybe', $result);
2261 * Test the api_format_items_activities() function with an XML result.
2264 public function testApiFormatItemsActivitiesWithXml()
2266 $item = ['uid' => 0, 'uri' => ''];
2267 $result = api_format_items_activities($item, 'xml');
2268 $this->assertArrayHasKey('friendica:like', $result);
2269 $this->assertArrayHasKey('friendica:dislike', $result);
2270 $this->assertArrayHasKey('friendica:attendyes', $result);
2271 $this->assertArrayHasKey('friendica:attendno', $result);
2272 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2276 * Test the api_format_items_profiles() function.
2279 public function testApiFormatItemsProfiles()
2282 'id' => 'profile_id',
2283 'profile-name' => 'profile_name',
2284 'is-default' => true,
2285 'hide-friends' => true,
2286 'photo' => 'profile_photo',
2287 'thumb' => 'profile_thumb',
2289 'net-publish' => true,
2290 'pdesc' => 'description',
2291 'dob' => 'date_of_birth',
2292 'address' => 'address',
2293 'locality' => 'city',
2294 'region' => 'region',
2295 'postal-code' => 'postal_code',
2296 'country-name' => 'country',
2297 'hometown' => 'hometown',
2298 'gender' => 'gender',
2299 'marital' => 'marital',
2300 'with' => 'marital_with',
2301 'howlong' => 'marital_since',
2302 'sexual' => 'sexual',
2303 'politic' => 'politic',
2304 'religion' => 'religion',
2305 'pub_keywords' => 'public_keywords',
2306 'prv_keywords' => 'private_keywords',
2309 'dislikes' => 'dislikes',
2315 'interest' => 'interest',
2316 'romance' => 'romance',
2318 'education' => 'education',
2319 'contact' => 'social_networks',
2320 'homepage' => 'homepage'
2322 $result = api_format_items_profiles($profile_row);
2323 $this->assertEquals(
2325 'profile_id' => 'profile_id',
2326 'profile_name' => 'profile_name',
2327 'is_default' => true,
2328 'hide_friends' => true,
2329 'profile_photo' => 'profile_photo',
2330 'profile_thumb' => 'profile_thumb',
2332 'net_publish' => true,
2333 'description' => 'description',
2334 'date_of_birth' => 'date_of_birth',
2335 'address' => 'address',
2337 'region' => 'region',
2338 'postal_code' => 'postal_code',
2339 'country' => 'country',
2340 'hometown' => 'hometown',
2341 'gender' => 'gender',
2342 'marital' => 'marital',
2343 'marital_with' => 'marital_with',
2344 'marital_since' => 'marital_since',
2345 'sexual' => 'sexual',
2346 'politic' => 'politic',
2347 'religion' => 'religion',
2348 'public_keywords' => 'public_keywords',
2349 'private_keywords' => 'private_keywords',
2352 'dislikes' => 'dislikes',
2358 'interest' => 'interest',
2359 'romance' => 'romance',
2361 'education' => 'education',
2362 'social_networks' => 'social_networks',
2363 'homepage' => 'homepage',
2371 * Test the api_format_items() function.
2374 public function testApiFormatItems()
2378 'item_network' => 'item_network',
2384 'author-network' => Protocol::DFRN,
2385 'author-link' => 'http://localhost/profile/othercontact',
2389 $result = api_format_items($items, ['id' => 0], true);
2390 foreach ($result as $status) {
2391 $this->assertStatus($status);
2396 * Test the api_format_items() function with an XML result.
2399 public function testApiFormatItemsWithXml()
2407 'author-network' => Protocol::DFRN,
2408 'author-link' => 'http://localhost/profile/othercontact',
2412 $result = api_format_items($items, ['id' => 0], true, 'xml');
2413 foreach ($result as $status) {
2414 $this->assertStatus($status);
2419 * Test the api_format_items() function.
2422 public function testApiAccountRateLimitStatus()
2424 $result = api_account_rate_limit_status('json');
2425 $this->assertEquals(150, $result['hash']['remaining_hits']);
2426 $this->assertEquals(150, $result['hash']['hourly_limit']);
2427 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2431 * Test the api_format_items() function with an XML result.
2434 public function testApiAccountRateLimitStatusWithXml()
2436 $result = api_account_rate_limit_status('xml');
2437 $this->assertXml($result, 'hash');
2441 * Test the api_help_test() function.
2444 public function testApiHelpTest()
2446 $result = api_help_test('json');
2447 $this->assertEquals(['ok' => 'ok'], $result);
2451 * Test the api_help_test() function with an XML result.
2454 public function testApiHelpTestWithXml()
2456 $result = api_help_test('xml');
2457 $this->assertXml($result, 'ok');
2461 * Test the api_lists_list() function.
2464 public function testApiListsList()
2466 $result = api_lists_list('json');
2467 $this->assertEquals(['lists_list' => []], $result);
2471 * Test the api_lists_ownerships() function.
2474 public function testApiListsOwnerships()
2476 $result = api_lists_ownerships('json');
2477 foreach ($result['lists']['lists'] as $list) {
2478 $this->assertList($list);
2483 * Test the api_lists_ownerships() function without an authenticated user.
2485 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2487 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2489 $_SESSION['authenticated'] = false;
2490 api_lists_ownerships('json');
2494 * Test the api_lists_statuses() function.
2495 * @expectedException Friendica\Network\HTTPException\BadRequestException
2498 public function testApiListsStatuses()
2500 api_lists_statuses('json');
2504 * Test the api_lists_statuses() function with a list ID.
2507 public function testApiListsStatusesWithListId()
2509 $_REQUEST['list_id'] = 1;
2510 $_REQUEST['page'] = -1;
2511 $_REQUEST['max_id'] = 10;
2512 $result = api_lists_statuses('json');
2513 foreach ($result['status'] as $status) {
2514 $this->assertStatus($status);
2519 * Test the api_lists_statuses() function with a list ID and a RSS result.
2522 public function testApiListsStatusesWithListIdAndRss()
2524 $_REQUEST['list_id'] = 1;
2525 $result = api_lists_statuses('rss');
2526 $this->assertXml($result, 'statuses');
2530 * Test the api_lists_statuses() function with an unallowed user.
2532 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2534 public function testApiListsStatusesWithUnallowedUser()
2536 $_SESSION['allow_api'] = false;
2537 $_GET['screen_name'] = $this->selfUser['nick'];
2538 api_lists_statuses('json');
2542 * Test the api_statuses_f() function.
2545 public function testApiStatusesFWithFriends()
2548 $result = api_statuses_f('friends');
2549 $this->assertArrayHasKey('user', $result);
2553 * Test the api_statuses_f() function.
2556 public function testApiStatusesFWithFollowers()
2558 $result = api_statuses_f('followers');
2559 $this->assertArrayHasKey('user', $result);
2563 * Test the api_statuses_f() function.
2566 public function testApiStatusesFWithBlocks()
2568 $result = api_statuses_f('blocks');
2569 $this->assertArrayHasKey('user', $result);
2573 * Test the api_statuses_f() function.
2576 public function testApiStatusesFWithIncoming()
2578 $result = api_statuses_f('incoming');
2579 $this->assertArrayHasKey('user', $result);
2583 * Test the api_statuses_f() function an undefined cursor GET variable.
2586 public function testApiStatusesFWithUndefinedCursor()
2588 $_GET['cursor'] = 'undefined';
2589 $this->assertFalse(api_statuses_f('friends'));
2593 * Test the api_statuses_friends() function.
2596 public function testApiStatusesFriends()
2598 $result = api_statuses_friends('json');
2599 $this->assertArrayHasKey('user', $result);
2603 * Test the api_statuses_friends() function an undefined cursor GET variable.
2606 public function testApiStatusesFriendsWithUndefinedCursor()
2608 $_GET['cursor'] = 'undefined';
2609 $this->assertFalse(api_statuses_friends('json'));
2613 * Test the api_statuses_followers() function.
2616 public function testApiStatusesFollowers()
2618 $result = api_statuses_followers('json');
2619 $this->assertArrayHasKey('user', $result);
2623 * Test the api_statuses_followers() function an undefined cursor GET variable.
2626 public function testApiStatusesFollowersWithUndefinedCursor()
2628 $_GET['cursor'] = 'undefined';
2629 $this->assertFalse(api_statuses_followers('json'));
2633 * Test the api_blocks_list() function.
2636 public function testApiBlocksList()
2638 $result = api_blocks_list('json');
2639 $this->assertArrayHasKey('user', $result);
2643 * Test the api_blocks_list() function an undefined cursor GET variable.
2646 public function testApiBlocksListWithUndefinedCursor()
2648 $_GET['cursor'] = 'undefined';
2649 $this->assertFalse(api_blocks_list('json'));
2653 * Test the api_friendships_incoming() function.
2656 public function testApiFriendshipsIncoming()
2658 $result = api_friendships_incoming('json');
2659 $this->assertArrayHasKey('id', $result);
2663 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2666 public function testApiFriendshipsIncomingWithUndefinedCursor()
2668 $_GET['cursor'] = 'undefined';
2669 $this->assertFalse(api_friendships_incoming('json'));
2673 * Test the api_statusnet_config() function.
2676 public function testApiStatusnetConfig()
2678 $result = api_statusnet_config('json');
2679 $this->assertEquals('localhost', $result['config']['site']['server']);
2680 $this->assertEquals('default', $result['config']['site']['theme']);
2681 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2682 $this->assertTrue($result['config']['site']['fancy']);
2683 $this->assertEquals('en', $result['config']['site']['language']);
2684 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2685 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2686 $this->assertEquals('false', $result['config']['site']['private']);
2687 $this->assertEquals('false', $result['config']['site']['ssl']);
2688 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2692 * Test the api_statusnet_version() function.
2695 public function testApiStatusnetVersion()
2697 $result = api_statusnet_version('json');
2698 $this->assertEquals('0.9.7', $result['version']);
2702 * Test the api_ff_ids() function.
2705 public function testApiFfIds()
2707 $result = api_ff_ids('json');
2708 $this->assertNull($result);
2712 * Test the api_ff_ids() function with a result.
2715 public function testApiFfIdsWithResult()
2717 $this->markTestIncomplete();
2721 * Test the api_ff_ids() function without an authenticated user.
2723 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2725 public function testApiFfIdsWithoutAuthenticatedUser()
2727 $_SESSION['authenticated'] = false;
2732 * Test the api_friends_ids() function.
2735 public function testApiFriendsIds()
2737 $result = api_friends_ids('json');
2738 $this->assertNull($result);
2742 * Test the api_followers_ids() function.
2745 public function testApiFollowersIds()
2747 $result = api_followers_ids('json');
2748 $this->assertNull($result);
2752 * Test the api_direct_messages_new() function.
2755 public function testApiDirectMessagesNew()
2757 $result = api_direct_messages_new('json');
2758 $this->assertNull($result);
2762 * Test the api_direct_messages_new() function without an authenticated user.
2764 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2766 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2768 $_SESSION['authenticated'] = false;
2769 api_direct_messages_new('json');
2773 * Test the api_direct_messages_new() function with an user ID.
2776 public function testApiDirectMessagesNewWithUserId()
2778 $_POST['text'] = 'message_text';
2779 $_POST['user_id'] = $this->otherUser['id'];
2780 $result = api_direct_messages_new('json');
2781 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2785 * Test the api_direct_messages_new() function with a screen name.
2788 public function testApiDirectMessagesNewWithScreenName()
2790 $_POST['text'] = 'message_text';
2791 $_POST['screen_name'] = $this->friendUser['nick'];
2792 $result = api_direct_messages_new('json');
2793 $this->assertEquals(1, $result['direct_message']['id']);
2794 $this->assertContains('message_text', $result['direct_message']['text']);
2795 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2796 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2800 * Test the api_direct_messages_new() function with a title.
2803 public function testApiDirectMessagesNewWithTitle()
2805 $_POST['text'] = 'message_text';
2806 $_POST['screen_name'] = $this->friendUser['nick'];
2807 $_REQUEST['title'] = 'message_title';
2808 $result = api_direct_messages_new('json');
2809 $this->assertEquals(1, $result['direct_message']['id']);
2810 $this->assertContains('message_text', $result['direct_message']['text']);
2811 $this->assertContains('message_title', $result['direct_message']['text']);
2812 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2813 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2817 * Test the api_direct_messages_new() function with an RSS result.
2820 public function testApiDirectMessagesNewWithRss()
2822 $_POST['text'] = 'message_text';
2823 $_POST['screen_name'] = $this->friendUser['nick'];
2824 $result = api_direct_messages_new('rss');
2825 $this->assertXml($result, 'direct-messages');
2829 * Test the api_direct_messages_destroy() function.
2831 * @expectedException Friendica\Network\HTTPException\BadRequestException
2833 public function testApiDirectMessagesDestroy()
2835 api_direct_messages_destroy('json');
2839 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2842 public function testApiDirectMessagesDestroyWithVerbose()
2844 $_GET['friendica_verbose'] = 'true';
2845 $result = api_direct_messages_destroy('json');
2846 $this->assertEquals(
2849 'result' => 'error',
2850 'message' => 'message id or parenturi not specified'
2858 * Test the api_direct_messages_destroy() function without an authenticated user.
2860 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2862 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2864 $_SESSION['authenticated'] = false;
2865 api_direct_messages_destroy('json');
2869 * Test the api_direct_messages_destroy() function with a non-zero ID.
2871 * @expectedException Friendica\Network\HTTPException\BadRequestException
2873 public function testApiDirectMessagesDestroyWithId()
2875 $_REQUEST['id'] = 1;
2876 api_direct_messages_destroy('json');
2880 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2883 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2885 $_REQUEST['id'] = 1;
2886 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2887 $_GET['friendica_verbose'] = 'true';
2888 $result = api_direct_messages_destroy('json');
2889 $this->assertEquals(
2892 'result' => 'error',
2893 'message' => 'message id not in database'
2901 * Test the api_direct_messages_destroy() function with a non-zero ID.
2904 public function testApiDirectMessagesDestroyWithCorrectId()
2906 $this->markTestIncomplete('We need to add a dataset for this.');
2910 * Test the api_direct_messages_box() function.
2913 public function testApiDirectMessagesBoxWithSentbox()
2915 $_REQUEST['page'] = -1;
2916 $_REQUEST['max_id'] = 10;
2917 $result = api_direct_messages_box('json', 'sentbox', 'false');
2918 $this->assertArrayHasKey('direct_message', $result);
2922 * Test the api_direct_messages_box() function.
2925 public function testApiDirectMessagesBoxWithConversation()
2927 $result = api_direct_messages_box('json', 'conversation', 'false');
2928 $this->assertArrayHasKey('direct_message', $result);
2932 * Test the api_direct_messages_box() function.
2935 public function testApiDirectMessagesBoxWithAll()
2937 $result = api_direct_messages_box('json', 'all', 'false');
2938 $this->assertArrayHasKey('direct_message', $result);
2942 * Test the api_direct_messages_box() function.
2945 public function testApiDirectMessagesBoxWithInbox()
2947 $result = api_direct_messages_box('json', 'inbox', 'false');
2948 $this->assertArrayHasKey('direct_message', $result);
2952 * Test the api_direct_messages_box() function.
2955 public function testApiDirectMessagesBoxWithVerbose()
2957 $result = api_direct_messages_box('json', 'sentbox', 'true');
2958 $this->assertEquals(
2961 'result' => 'error',
2962 'message' => 'no mails available'
2970 * Test the api_direct_messages_box() function with a RSS result.
2973 public function testApiDirectMessagesBoxWithRss()
2975 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2976 $this->assertXml($result, 'direct-messages');
2980 * Test the api_direct_messages_box() function without an authenticated user.
2982 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2984 public function testApiDirectMessagesBoxWithUnallowedUser()
2986 $_SESSION['allow_api'] = false;
2987 $_GET['screen_name'] = $this->selfUser['nick'];
2988 api_direct_messages_box('json', 'sentbox', 'false');
2992 * Test the api_direct_messages_sentbox() function.
2995 public function testApiDirectMessagesSentbox()
2997 $result = api_direct_messages_sentbox('json');
2998 $this->assertArrayHasKey('direct_message', $result);
3002 * Test the api_direct_messages_inbox() function.
3005 public function testApiDirectMessagesInbox()
3007 $result = api_direct_messages_inbox('json');
3008 $this->assertArrayHasKey('direct_message', $result);
3012 * Test the api_direct_messages_all() function.
3015 public function testApiDirectMessagesAll()
3017 $result = api_direct_messages_all('json');
3018 $this->assertArrayHasKey('direct_message', $result);
3022 * Test the api_direct_messages_conversation() function.
3025 public function testApiDirectMessagesConversation()
3027 $result = api_direct_messages_conversation('json');
3028 $this->assertArrayHasKey('direct_message', $result);
3032 * Test the api_oauth_request_token() function.
3035 public function testApiOauthRequestToken()
3037 $this->markTestIncomplete('killme() kills phpunit as well');
3041 * Test the api_oauth_access_token() function.
3044 public function testApiOauthAccessToken()
3046 $this->markTestIncomplete('killme() kills phpunit as well');
3050 * Test the api_fr_photoalbum_delete() function.
3052 * @expectedException Friendica\Network\HTTPException\BadRequestException
3054 public function testApiFrPhotoalbumDelete()
3056 api_fr_photoalbum_delete('json');
3060 * Test the api_fr_photoalbum_delete() function with an album name.
3062 * @expectedException Friendica\Network\HTTPException\BadRequestException
3064 public function testApiFrPhotoalbumDeleteWithAlbum()
3066 $_REQUEST['album'] = 'album_name';
3067 api_fr_photoalbum_delete('json');
3071 * Test the api_fr_photoalbum_delete() function with an album name.
3074 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3076 $this->markTestIncomplete('We need to add a dataset for this.');
3080 * Test the api_fr_photoalbum_delete() function.
3082 * @expectedException Friendica\Network\HTTPException\BadRequestException
3084 public function testApiFrPhotoalbumUpdate()
3086 api_fr_photoalbum_update('json');
3090 * Test the api_fr_photoalbum_delete() function with an album name.
3092 * @expectedException Friendica\Network\HTTPException\BadRequestException
3094 public function testApiFrPhotoalbumUpdateWithAlbum()
3096 $_REQUEST['album'] = 'album_name';
3097 api_fr_photoalbum_update('json');
3101 * Test the api_fr_photoalbum_delete() function with an album name.
3103 * @expectedException Friendica\Network\HTTPException\BadRequestException
3105 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3107 $_REQUEST['album'] = 'album_name';
3108 $_REQUEST['album_new'] = 'album_name';
3109 api_fr_photoalbum_update('json');
3113 * Test the api_fr_photoalbum_update() function without an authenticated user.
3115 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3117 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3119 $_SESSION['authenticated'] = false;
3120 api_fr_photoalbum_update('json');
3124 * Test the api_fr_photoalbum_delete() function with an album name.
3127 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3129 $this->markTestIncomplete('We need to add a dataset for this.');
3133 * Test the api_fr_photos_list() function.
3136 public function testApiFrPhotosList()
3138 $result = api_fr_photos_list('json');
3139 $this->assertArrayHasKey('photo', $result);
3143 * Test the api_fr_photos_list() function without an authenticated user.
3145 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3147 public function testApiFrPhotosListWithoutAuthenticatedUser()
3149 $_SESSION['authenticated'] = false;
3150 api_fr_photos_list('json');
3154 * Test the api_fr_photo_create_update() function.
3156 * @expectedException Friendica\Network\HTTPException\BadRequestException
3158 public function testApiFrPhotoCreateUpdate()
3160 api_fr_photo_create_update('json');
3164 * Test the api_fr_photo_create_update() function without an authenticated user.
3166 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3168 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3170 $_SESSION['authenticated'] = false;
3171 api_fr_photo_create_update('json');
3175 * Test the api_fr_photo_create_update() function with an album name.
3177 * @expectedException Friendica\Network\HTTPException\BadRequestException
3179 public function testApiFrPhotoCreateUpdateWithAlbum()
3181 $_REQUEST['album'] = 'album_name';
3182 api_fr_photo_create_update('json');
3186 * Test the api_fr_photo_create_update() function with the update mode.
3189 public function testApiFrPhotoCreateUpdateWithUpdate()
3191 $this->markTestIncomplete('We need to create a dataset for this');
3195 * Test the api_fr_photo_create_update() function with an uploaded file.
3198 public function testApiFrPhotoCreateUpdateWithFile()
3200 $this->markTestIncomplete();
3204 * Test the api_fr_photo_delete() function.
3206 * @expectedException Friendica\Network\HTTPException\BadRequestException
3208 public function testApiFrPhotoDelete()
3210 api_fr_photo_delete('json');
3214 * Test the api_fr_photo_delete() function without an authenticated user.
3216 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3218 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3220 $_SESSION['authenticated'] = false;
3221 api_fr_photo_delete('json');
3225 * Test the api_fr_photo_delete() function with a photo ID.
3227 * @expectedException Friendica\Network\HTTPException\BadRequestException
3229 public function testApiFrPhotoDeleteWithPhotoId()
3231 $_REQUEST['photo_id'] = 1;
3232 api_fr_photo_delete('json');
3236 * Test the api_fr_photo_delete() function with a correct photo ID.
3239 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3241 $this->markTestIncomplete('We need to create a dataset for this.');
3245 * Test the api_fr_photo_detail() function.
3247 * @expectedException Friendica\Network\HTTPException\BadRequestException
3249 public function testApiFrPhotoDetail()
3251 api_fr_photo_detail('json');
3255 * Test the api_fr_photo_detail() function without an authenticated user.
3257 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3259 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3261 $_SESSION['authenticated'] = false;
3262 api_fr_photo_detail('json');
3266 * Test the api_fr_photo_detail() function with a photo ID.
3268 * @expectedException Friendica\Network\HTTPException\NotFoundException
3270 public function testApiFrPhotoDetailWithPhotoId()
3272 $_REQUEST['photo_id'] = 1;
3273 api_fr_photo_detail('json');
3277 * Test the api_fr_photo_detail() function with a correct photo ID.
3280 public function testApiFrPhotoDetailCorrectPhotoId()
3282 $this->markTestIncomplete('We need to create a dataset for this.');
3286 * Test the api_account_update_profile_image() function.
3288 * @expectedException Friendica\Network\HTTPException\BadRequestException
3290 public function testApiAccountUpdateProfileImage()
3292 api_account_update_profile_image('json');
3296 * Test the api_account_update_profile_image() function without an authenticated user.
3298 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3300 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3302 $_SESSION['authenticated'] = false;
3303 api_account_update_profile_image('json');
3307 * Test the api_account_update_profile_image() function with an uploaded file.
3309 * @expectedException Friendica\Network\HTTPException\BadRequestException
3311 public function testApiAccountUpdateProfileImageWithUpload()
3313 $this->markTestIncomplete();
3318 * Test the api_account_update_profile() function.
3321 public function testApiAccountUpdateProfile()
3323 $_POST['name'] = 'new_name';
3324 $_POST['description'] = 'new_description';
3325 $result = api_account_update_profile('json');
3326 // We can't use assertSelfUser() here because the user object is missing some properties.
3327 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3328 $this->assertEquals('DFRN', $result['user']['location']);
3329 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3330 $this->assertEquals('dfrn', $result['user']['network']);
3331 $this->assertEquals('new_name', $result['user']['name']);
3332 $this->assertEquals('new_description', $result['user']['description']);
3336 * Test the check_acl_input() function.
3339 public function testCheckAclInput()
3341 $result = check_acl_input('<aclstring>');
3342 // Where does this result come from?
3343 $this->assertEquals(1, $result);
3347 * Test the check_acl_input() function with an empty ACL string.
3350 public function testCheckAclInputWithEmptyAclString()
3352 $result = check_acl_input(' ');
3353 $this->assertFalse($result);
3357 * Test the save_media_to_database() function.
3360 public function testSaveMediaToDatabase()
3362 $this->markTestIncomplete();
3366 * Test the post_photo_item() function.
3369 public function testPostPhotoItem()
3371 $this->markTestIncomplete();
3375 * Test the prepare_photo_data() function.
3378 public function testPreparePhotoData()
3380 $this->markTestIncomplete();
3384 * Test the api_friendica_remoteauth() function.
3386 * @expectedException Friendica\Network\HTTPException\BadRequestException
3388 public function testApiFriendicaRemoteauth()
3390 api_friendica_remoteauth();
3394 * Test the api_friendica_remoteauth() function with an URL.
3396 * @expectedException Friendica\Network\HTTPException\BadRequestException
3398 public function testApiFriendicaRemoteauthWithUrl()
3400 $_GET['url'] = 'url';
3401 $_GET['c_url'] = 'url';
3402 api_friendica_remoteauth();
3406 * Test the api_friendica_remoteauth() function with a correct URL.
3409 public function testApiFriendicaRemoteauthWithCorrectUrl()
3411 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3412 $_GET['url'] = 'url';
3413 $_GET['c_url'] = $this->selfUser['nurl'];
3414 api_friendica_remoteauth();
3418 * Test the api_share_as_retweet() function.
3421 public function testApiShareAsRetweet()
3423 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3424 $result = api_share_as_retweet($item);
3425 $this->assertFalse($result);
3429 * Test the api_share_as_retweet() function with a valid item.
3432 public function testApiShareAsRetweetWithValidItem()
3434 $this->markTestIncomplete();
3438 * Test the api_get_nick() function.
3441 public function testApiGetNick()
3443 $result = api_get_nick($this->otherUser['nurl']);
3444 $this->assertEquals('othercontact', $result);
3448 * Test the api_get_nick() function with a wrong URL.
3451 public function testApiGetNickWithWrongUrl()
3453 $result = api_get_nick('wrong_url');
3454 $this->assertFalse($result);
3458 * Test the api_in_reply_to() function.
3461 public function testApiInReplyTo()
3463 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3464 $this->assertArrayHasKey('status_id', $result);
3465 $this->assertArrayHasKey('user_id', $result);
3466 $this->assertArrayHasKey('status_id_str', $result);
3467 $this->assertArrayHasKey('user_id_str', $result);
3468 $this->assertArrayHasKey('screen_name', $result);
3472 * Test the api_in_reply_to() function with a valid item.
3475 public function testApiInReplyToWithValidItem()
3477 $this->markTestIncomplete();
3481 * Test the api_clean_plain_items() function.
3484 public function testApiCleanPlainItems()
3486 $_REQUEST['include_entities'] = 'true';
3487 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3488 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3492 * Test the api_clean_attachments() function.
3495 public function testApiCleanAttachments()
3497 $this->markTestIncomplete();
3501 * Test the api_best_nickname() function.
3504 public function testApiBestNickname()
3507 $result = api_best_nickname($contacts);
3508 $this->assertNull($result);
3512 * Test the api_best_nickname() function with contacts.
3515 public function testApiBestNicknameWithContacts()
3517 $this->markTestIncomplete();
3521 * Test the api_friendica_group_show() function.
3524 public function testApiFriendicaGroupShow()
3526 $this->markTestIncomplete();
3530 * Test the api_friendica_group_delete() function.
3533 public function testApiFriendicaGroupDelete()
3535 $this->markTestIncomplete();
3539 * Test the api_lists_destroy() function.
3542 public function testApiListsDestroy()
3544 $this->markTestIncomplete();
3548 * Test the group_create() function.
3551 public function testGroupCreate()
3553 $this->markTestIncomplete();
3557 * Test the api_friendica_group_create() function.
3560 public function testApiFriendicaGroupCreate()
3562 $this->markTestIncomplete();
3566 * Test the api_lists_create() function.
3569 public function testApiListsCreate()
3571 $this->markTestIncomplete();
3575 * Test the api_friendica_group_update() function.
3578 public function testApiFriendicaGroupUpdate()
3580 $this->markTestIncomplete();
3584 * Test the api_lists_update() function.
3587 public function testApiListsUpdate()
3589 $this->markTestIncomplete();
3593 * Test the api_friendica_activity() function.
3596 public function testApiFriendicaActivity()
3598 $this->markTestIncomplete();
3602 * Test the api_friendica_notification() function.
3604 * @expectedException Friendica\Network\HTTPException\BadRequestException
3606 public function testApiFriendicaNotification()
3608 api_friendica_notification('json');
3612 * Test the api_friendica_notification() function without an authenticated user.
3614 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3616 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3618 $_SESSION['authenticated'] = false;
3619 api_friendica_notification('json');
3623 * Test the api_friendica_notification() function with an argument count.
3626 public function testApiFriendicaNotificationWithArgumentCount()
3628 $this->app->argv = ['api', 'friendica', 'notification'];
3629 $this->app->argc = count($this->app->argv);
3630 $result = api_friendica_notification('json');
3631 $this->assertEquals(['note' => false], $result);
3635 * Test the api_friendica_notification() function with an XML result.
3638 public function testApiFriendicaNotificationWithXmlResult()
3640 $this->app->argv = ['api', 'friendica', 'notification'];
3641 $this->app->argc = count($this->app->argv);
3642 $result = api_friendica_notification('xml');
3643 $this->assertXml($result, 'notes');
3647 * Test the api_friendica_notification_seen() function.
3650 public function testApiFriendicaNotificationSeen()
3652 $this->markTestIncomplete();
3656 * Test the api_friendica_direct_messages_setseen() function.
3659 public function testApiFriendicaDirectMessagesSetseen()
3661 $this->markTestIncomplete();
3665 * Test the api_friendica_direct_messages_search() function.
3668 public function testApiFriendicaDirectMessagesSearch()
3670 $this->markTestIncomplete();
3674 * Test the api_friendica_profile_show() function.
3677 public function testApiFriendicaProfileShow()
3679 $result = api_friendica_profile_show('json');
3680 // We can't use assertSelfUser() here because the user object is missing some properties.
3681 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3682 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3683 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3684 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3685 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3686 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3687 $this->assertFalse($result['$result']['multi_profiles']);
3691 * Test the api_friendica_profile_show() function with a profile ID.
3694 public function testApiFriendicaProfileShowWithProfileId()
3696 $this->markTestIncomplete('We need to add a dataset for this.');
3700 * Test the api_friendica_profile_show() function with a wrong profile ID.
3702 * @expectedException Friendica\Network\HTTPException\BadRequestException
3704 public function testApiFriendicaProfileShowWithWrongProfileId()
3706 $_REQUEST['profile_id'] = 666;
3707 api_friendica_profile_show('json');
3711 * Test the api_friendica_profile_show() function without an authenticated user.
3713 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3715 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3717 $_SESSION['authenticated'] = false;
3718 api_friendica_profile_show('json');
3722 * Test the api_saved_searches_list() function.
3725 public function testApiSavedSearchesList()
3727 $result = api_saved_searches_list('json');
3728 $this->assertEquals(1, $result['terms'][0]['id']);
3729 $this->assertEquals(1, $result['terms'][0]['id_str']);
3730 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3731 $this->assertEquals('Saved search', $result['terms'][0]['query']);