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 $result = api_search('json');
1431 foreach ($result['status'] as $status) {
1432 $this->assertStatus($status);
1437 * Test the api_search() function without an authenticated user.
1439 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1441 public function testApiSearchWithUnallowedUser()
1443 $_SESSION['allow_api'] = false;
1444 $_GET['screen_name'] = $this->selfUser['nick'];
1449 * Test the api_search() function without any GET query parameter.
1451 * @expectedException Friendica\Network\HTTPException\BadRequestException
1453 public function testApiSearchWithoutQuery()
1459 * Test the api_statuses_home_timeline() function.
1462 public function testApiStatusesHomeTimeline()
1464 $_REQUEST['max_id'] = 10;
1465 $_REQUEST['exclude_replies'] = true;
1466 $_REQUEST['conversation_id'] = 1;
1467 $result = api_statuses_home_timeline('json');
1468 $this->assertNotEmpty($result['status']);
1469 foreach ($result['status'] as $status) {
1470 $this->assertStatus($status);
1475 * Test the api_statuses_home_timeline() function with a negative page parameter.
1478 public function testApiStatusesHomeTimelineWithNegativePage()
1480 $_REQUEST['page'] = -2;
1481 $result = api_statuses_home_timeline('json');
1482 $this->assertNotEmpty($result['status']);
1483 foreach ($result['status'] as $status) {
1484 $this->assertStatus($status);
1489 * Test the api_statuses_home_timeline() with an unallowed user.
1491 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1493 public function testApiStatusesHomeTimelineWithUnallowedUser()
1495 $_SESSION['allow_api'] = false;
1496 $_GET['screen_name'] = $this->selfUser['nick'];
1497 api_statuses_home_timeline('json');
1501 * Test the api_statuses_home_timeline() function with an RSS result.
1504 public function testApiStatusesHomeTimelineWithRss()
1506 $result = api_statuses_home_timeline('rss');
1507 $this->assertXml($result, 'statuses');
1511 * Test the api_statuses_public_timeline() function.
1514 public function testApiStatusesPublicTimeline()
1516 $_REQUEST['max_id'] = 10;
1517 $_REQUEST['conversation_id'] = 1;
1518 $result = api_statuses_public_timeline('json');
1519 $this->assertNotEmpty($result['status']);
1520 foreach ($result['status'] as $status) {
1521 $this->assertStatus($status);
1526 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1529 public function testApiStatusesPublicTimelineWithExcludeReplies()
1531 $_REQUEST['max_id'] = 10;
1532 $_REQUEST['exclude_replies'] = true;
1533 $result = api_statuses_public_timeline('json');
1534 $this->assertNotEmpty($result['status']);
1535 foreach ($result['status'] as $status) {
1536 $this->assertStatus($status);
1541 * Test the api_statuses_public_timeline() function with a negative page parameter.
1544 public function testApiStatusesPublicTimelineWithNegativePage()
1546 $_REQUEST['page'] = -2;
1547 $result = api_statuses_public_timeline('json');
1548 $this->assertNotEmpty($result['status']);
1549 foreach ($result['status'] as $status) {
1550 $this->assertStatus($status);
1555 * Test the api_statuses_public_timeline() function with an unallowed user.
1557 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1559 public function testApiStatusesPublicTimelineWithUnallowedUser()
1561 $_SESSION['allow_api'] = false;
1562 $_GET['screen_name'] = $this->selfUser['nick'];
1563 api_statuses_public_timeline('json');
1567 * Test the api_statuses_public_timeline() function with an RSS result.
1570 public function testApiStatusesPublicTimelineWithRss()
1572 $result = api_statuses_public_timeline('rss');
1573 $this->assertXml($result, 'statuses');
1577 * Test the api_statuses_networkpublic_timeline() function.
1580 public function testApiStatusesNetworkpublicTimeline()
1582 $_REQUEST['max_id'] = 10;
1583 $result = api_statuses_networkpublic_timeline('json');
1584 $this->assertNotEmpty($result['status']);
1585 foreach ($result['status'] as $status) {
1586 $this->assertStatus($status);
1591 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1594 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1596 $_REQUEST['page'] = -2;
1597 $result = api_statuses_networkpublic_timeline('json');
1598 $this->assertNotEmpty($result['status']);
1599 foreach ($result['status'] as $status) {
1600 $this->assertStatus($status);
1605 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1607 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1609 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1611 $_SESSION['allow_api'] = false;
1612 $_GET['screen_name'] = $this->selfUser['nick'];
1613 api_statuses_networkpublic_timeline('json');
1617 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1620 public function testApiStatusesNetworkpublicTimelineWithRss()
1622 $result = api_statuses_networkpublic_timeline('rss');
1623 $this->assertXml($result, 'statuses');
1627 * Test the api_statuses_show() function.
1629 * @expectedException Friendica\Network\HTTPException\BadRequestException
1631 public function testApiStatusesShow()
1633 api_statuses_show('json');
1637 * Test the api_statuses_show() function with an ID.
1640 public function testApiStatusesShowWithId()
1642 $this->app->argv[3] = 1;
1643 $result = api_statuses_show('json');
1644 $this->assertStatus($result['status']);
1648 * Test the api_statuses_show() function with the conversation parameter.
1651 public function testApiStatusesShowWithConversation()
1653 $this->app->argv[3] = 1;
1654 $_REQUEST['conversation'] = 1;
1655 $result = api_statuses_show('json');
1656 $this->assertNotEmpty($result['status']);
1657 foreach ($result['status'] as $status) {
1658 $this->assertStatus($status);
1663 * Test the api_statuses_show() function with an unallowed user.
1665 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1667 public function testApiStatusesShowWithUnallowedUser()
1669 $_SESSION['allow_api'] = false;
1670 $_GET['screen_name'] = $this->selfUser['nick'];
1671 api_statuses_show('json');
1675 * Test the api_conversation_show() function.
1677 * @expectedException Friendica\Network\HTTPException\BadRequestException
1679 public function testApiConversationShow()
1681 api_conversation_show('json');
1685 * Test the api_conversation_show() function with an ID.
1688 public function testApiConversationShowWithId()
1690 $this->app->argv[3] = 1;
1691 $_REQUEST['max_id'] = 10;
1692 $_REQUEST['page'] = -2;
1693 $result = api_conversation_show('json');
1694 $this->assertNotEmpty($result['status']);
1695 foreach ($result['status'] as $status) {
1696 $this->assertStatus($status);
1701 * Test the api_conversation_show() function with an unallowed user.
1703 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1705 public function testApiConversationShowWithUnallowedUser()
1707 $_SESSION['allow_api'] = false;
1708 $_GET['screen_name'] = $this->selfUser['nick'];
1709 api_conversation_show('json');
1713 * Test the api_statuses_repeat() function.
1715 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1717 public function testApiStatusesRepeat()
1719 api_statuses_repeat('json');
1723 * Test the api_statuses_repeat() function without an authenticated user.
1725 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1727 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1729 $_SESSION['authenticated'] = false;
1730 api_statuses_repeat('json');
1734 * Test the api_statuses_repeat() function with an ID.
1737 public function testApiStatusesRepeatWithId()
1739 $this->app->argv[3] = 1;
1740 $result = api_statuses_repeat('json');
1741 $this->assertStatus($result['status']);
1743 // Also test with a shared status
1744 $this->app->argv[3] = 5;
1745 $result = api_statuses_repeat('json');
1746 $this->assertStatus($result['status']);
1750 * Test the api_statuses_destroy() function.
1752 * @expectedException Friendica\Network\HTTPException\BadRequestException
1754 public function testApiStatusesDestroy()
1756 api_statuses_destroy('json');
1760 * Test the api_statuses_destroy() function without an authenticated user.
1762 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1764 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1766 $_SESSION['authenticated'] = false;
1767 api_statuses_destroy('json');
1771 * Test the api_statuses_destroy() function with an ID.
1774 public function testApiStatusesDestroyWithId()
1776 $this->app->argv[3] = 1;
1777 $result = api_statuses_destroy('json');
1778 $this->assertStatus($result['status']);
1782 * Test the api_statuses_mentions() function.
1785 public function testApiStatusesMentions()
1787 $this->app->user = ['nickname' => $this->selfUser['nick']];
1788 $_REQUEST['max_id'] = 10;
1789 $result = api_statuses_mentions('json');
1790 $this->assertEmpty($result['status']);
1791 // We should test with mentions in the database.
1795 * Test the api_statuses_mentions() function with a negative page parameter.
1798 public function testApiStatusesMentionsWithNegativePage()
1800 $_REQUEST['page'] = -2;
1801 $result = api_statuses_mentions('json');
1802 $this->assertEmpty($result['status']);
1806 * Test the api_statuses_mentions() function with an unallowed user.
1808 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1810 public function testApiStatusesMentionsWithUnallowedUser()
1812 $_SESSION['allow_api'] = false;
1813 $_GET['screen_name'] = $this->selfUser['nick'];
1814 api_statuses_mentions('json');
1818 * Test the api_statuses_mentions() function with an RSS result.
1821 public function testApiStatusesMentionsWithRss()
1823 $result = api_statuses_mentions('rss');
1824 $this->assertXml($result, 'statuses');
1828 * Test the api_statuses_user_timeline() function.
1831 public function testApiStatusesUserTimeline()
1833 $_REQUEST['max_id'] = 10;
1834 $_REQUEST['exclude_replies'] = true;
1835 $_REQUEST['conversation_id'] = 1;
1836 $result = api_statuses_user_timeline('json');
1837 $this->assertNotEmpty($result['status']);
1838 foreach ($result['status'] as $status) {
1839 $this->assertStatus($status);
1844 * Test the api_statuses_user_timeline() function with a negative page parameter.
1847 public function testApiStatusesUserTimelineWithNegativePage()
1849 $_REQUEST['page'] = -2;
1850 $result = api_statuses_user_timeline('json');
1851 $this->assertNotEmpty($result['status']);
1852 foreach ($result['status'] as $status) {
1853 $this->assertStatus($status);
1858 * Test the api_statuses_user_timeline() function with an RSS result.
1861 public function testApiStatusesUserTimelineWithRss()
1863 $result = api_statuses_user_timeline('rss');
1864 $this->assertXml($result, 'statuses');
1868 * Test the api_statuses_user_timeline() function with an unallowed user.
1870 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1872 public function testApiStatusesUserTimelineWithUnallowedUser()
1874 $_SESSION['allow_api'] = false;
1875 $_GET['screen_name'] = $this->selfUser['nick'];
1876 api_statuses_user_timeline('json');
1880 * Test the api_favorites_create_destroy() function.
1882 * @expectedException Friendica\Network\HTTPException\BadRequestException
1884 public function testApiFavoritesCreateDestroy()
1886 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1887 $this->app->argc = count($this->app->argv);
1888 api_favorites_create_destroy('json');
1892 * Test the api_favorites_create_destroy() function with an invalid ID.
1894 * @expectedException Friendica\Network\HTTPException\BadRequestException
1896 public function testApiFavoritesCreateDestroyWithInvalidId()
1898 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1899 $this->app->argc = count($this->app->argv);
1900 api_favorites_create_destroy('json');
1904 * Test the api_favorites_create_destroy() function with an invalid action.
1906 * @expectedException Friendica\Network\HTTPException\BadRequestException
1908 public function testApiFavoritesCreateDestroyWithInvalidAction()
1910 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1911 $this->app->argc = count($this->app->argv);
1912 $_REQUEST['id'] = 1;
1913 api_favorites_create_destroy('json');
1917 * Test the api_favorites_create_destroy() function with the create action.
1920 public function testApiFavoritesCreateDestroyWithCreateAction()
1922 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1923 $this->app->argc = count($this->app->argv);
1924 $_REQUEST['id'] = 3;
1925 $result = api_favorites_create_destroy('json');
1926 $this->assertStatus($result['status']);
1930 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1933 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1935 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1936 $this->app->argc = count($this->app->argv);
1937 $_REQUEST['id'] = 3;
1938 $result = api_favorites_create_destroy('rss');
1939 $this->assertXml($result, 'status');
1943 * Test the api_favorites_create_destroy() function with the destroy action.
1946 public function testApiFavoritesCreateDestroyWithDestroyAction()
1948 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1949 $this->app->argc = count($this->app->argv);
1950 $_REQUEST['id'] = 3;
1951 $result = api_favorites_create_destroy('json');
1952 $this->assertStatus($result['status']);
1956 * Test the api_favorites_create_destroy() function without an authenticated user.
1958 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1960 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1962 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1963 $this->app->argc = count($this->app->argv);
1964 $_SESSION['authenticated'] = false;
1965 api_favorites_create_destroy('json');
1969 * Test the api_favorites() function.
1972 public function testApiFavorites()
1974 $_REQUEST['page'] = -1;
1975 $_REQUEST['max_id'] = 10;
1976 $result = api_favorites('json');
1977 foreach ($result['status'] as $status) {
1978 $this->assertStatus($status);
1983 * Test the api_favorites() function with an RSS result.
1986 public function testApiFavoritesWithRss()
1988 $result = api_favorites('rss');
1989 $this->assertXml($result, 'statuses');
1993 * Test the api_favorites() function with an unallowed user.
1995 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1997 public function testApiFavoritesWithUnallowedUser()
1999 $_SESSION['allow_api'] = false;
2000 $_GET['screen_name'] = $this->selfUser['nick'];
2001 api_favorites('json');
2005 * Test the api_format_messages() function.
2008 public function testApiFormatMessages()
2010 $result = api_format_messages(
2011 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2012 ['id' => 2, 'screen_name' => 'recipient_name'],
2013 ['id' => 3, 'screen_name' => 'sender_name']
2015 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2016 $this->assertEquals(1, $result['id']);
2017 $this->assertEquals(2, $result['recipient_id']);
2018 $this->assertEquals(3, $result['sender_id']);
2019 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2020 $this->assertEquals('sender_name', $result['sender_screen_name']);
2024 * Test the api_format_messages() function with HTML.
2027 public function testApiFormatMessagesWithHtmlText()
2029 $_GET['getText'] = 'html';
2030 $result = api_format_messages(
2031 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2032 ['id' => 2, 'screen_name' => 'recipient_name'],
2033 ['id' => 3, 'screen_name' => 'sender_name']
2035 $this->assertEquals('item_title', $result['title']);
2036 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2040 * Test the api_format_messages() function with plain text.
2043 public function testApiFormatMessagesWithPlainText()
2045 $_GET['getText'] = 'plain';
2046 $result = api_format_messages(
2047 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2048 ['id' => 2, 'screen_name' => 'recipient_name'],
2049 ['id' => 3, 'screen_name' => 'sender_name']
2051 $this->assertEquals('item_title', $result['title']);
2052 $this->assertEquals('item_body', $result['text']);
2056 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2059 public function testApiFormatMessagesWithoutUserObjects()
2061 $_GET['getUserObjects'] = 'false';
2062 $result = api_format_messages(
2063 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2064 ['id' => 2, 'screen_name' => 'recipient_name'],
2065 ['id' => 3, 'screen_name' => 'sender_name']
2067 $this->assertTrue(!isset($result['sender']));
2068 $this->assertTrue(!isset($result['recipient']));
2072 * Test the api_convert_item() function.
2075 public function testApiConvertItem()
2077 $result = api_convert_item(
2079 'network' => 'feed',
2080 'title' => 'item_title',
2081 // We need a long string to test that it is correctly cut
2082 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2083 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2084 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2085 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2086 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2087 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2088 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2089 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2090 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2091 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2092 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2093 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2094 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2095 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2096 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2097 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2098 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2099 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2100 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2101 'repellat officia illum quos impedit quam iste esse unde qui '.
2102 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2103 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2104 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2105 'plink' => 'item_plink'
2108 $this->assertStringStartsWith('item_title', $result['text']);
2109 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2113 * Test the api_convert_item() function with an empty item body.
2116 public function testApiConvertItemWithoutBody()
2118 $result = api_convert_item(
2120 'network' => 'feed',
2121 'title' => 'item_title',
2123 'plink' => 'item_plink'
2126 $this->assertEquals('item_title', $result['text']);
2127 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2131 * Test the api_convert_item() function with the title in the body.
2134 public function testApiConvertItemWithTitleInBody()
2136 $result = api_convert_item(
2138 'title' => 'item_title',
2139 'body' => 'item_title item_body'
2142 $this->assertEquals('item_title item_body', $result['text']);
2143 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2147 * Test the api_get_attachments() function.
2150 public function testApiGetAttachments()
2153 $this->assertEmpty(api_get_attachments($body));
2157 * Test the api_get_attachments() function with an img tag.
2160 public function testApiGetAttachmentsWithImage()
2162 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2163 $this->assertInternalType('array', api_get_attachments($body));
2167 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2170 public function testApiGetAttachmentsWithImageAndAndStatus()
2172 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2173 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2174 $this->assertInternalType('array', api_get_attachments($body));
2178 * Test the api_get_entitities() function.
2181 public function testApiGetEntitities()
2184 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2188 * Test the api_get_entitities() function with the include_entities parameter.
2191 public function testApiGetEntititiesWithIncludeEntities()
2193 $_REQUEST['include_entities'] = 'true';
2195 $result = api_get_entitities($text, 'bbcode');
2196 $this->assertInternalType('array', $result['hashtags']);
2197 $this->assertInternalType('array', $result['symbols']);
2198 $this->assertInternalType('array', $result['urls']);
2199 $this->assertInternalType('array', $result['user_mentions']);
2203 * Test the api_format_items_embeded_images() function.
2206 public function testApiFormatItemsEmbededImages()
2208 $this->assertEquals(
2209 'text ' . System::baseUrl() . '/display/item_guid',
2210 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2215 * Test the api_contactlink_to_array() function.
2218 public function testApiContactlinkToArray()
2220 $this->assertEquals(
2225 api_contactlink_to_array('text')
2230 * Test the api_contactlink_to_array() function with an URL.
2233 public function testApiContactlinkToArrayWithUrl()
2235 $this->assertEquals(
2237 'name' => ['link_text'],
2240 api_contactlink_to_array('text <a href="url">link_text</a>')
2245 * Test the api_format_items_activities() function.
2248 public function testApiFormatItemsActivities()
2250 $item = ['uid' => 0, 'uri' => ''];
2251 $result = api_format_items_activities($item);
2252 $this->assertArrayHasKey('like', $result);
2253 $this->assertArrayHasKey('dislike', $result);
2254 $this->assertArrayHasKey('attendyes', $result);
2255 $this->assertArrayHasKey('attendno', $result);
2256 $this->assertArrayHasKey('attendmaybe', $result);
2260 * Test the api_format_items_activities() function with an XML result.
2263 public function testApiFormatItemsActivitiesWithXml()
2265 $item = ['uid' => 0, 'uri' => ''];
2266 $result = api_format_items_activities($item, 'xml');
2267 $this->assertArrayHasKey('friendica:like', $result);
2268 $this->assertArrayHasKey('friendica:dislike', $result);
2269 $this->assertArrayHasKey('friendica:attendyes', $result);
2270 $this->assertArrayHasKey('friendica:attendno', $result);
2271 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2275 * Test the api_format_items_profiles() function.
2278 public function testApiFormatItemsProfiles()
2281 'id' => 'profile_id',
2282 'profile-name' => 'profile_name',
2283 'is-default' => true,
2284 'hide-friends' => true,
2285 'photo' => 'profile_photo',
2286 'thumb' => 'profile_thumb',
2288 'net-publish' => true,
2289 'pdesc' => 'description',
2290 'dob' => 'date_of_birth',
2291 'address' => 'address',
2292 'locality' => 'city',
2293 'region' => 'region',
2294 'postal-code' => 'postal_code',
2295 'country-name' => 'country',
2296 'hometown' => 'hometown',
2297 'gender' => 'gender',
2298 'marital' => 'marital',
2299 'with' => 'marital_with',
2300 'howlong' => 'marital_since',
2301 'sexual' => 'sexual',
2302 'politic' => 'politic',
2303 'religion' => 'religion',
2304 'pub_keywords' => 'public_keywords',
2305 'prv_keywords' => 'private_keywords',
2308 'dislikes' => 'dislikes',
2314 'interest' => 'interest',
2315 'romance' => 'romance',
2317 'education' => 'education',
2318 'contact' => 'social_networks',
2319 'homepage' => 'homepage'
2321 $result = api_format_items_profiles($profile_row);
2322 $this->assertEquals(
2324 'profile_id' => 'profile_id',
2325 'profile_name' => 'profile_name',
2326 'is_default' => true,
2327 'hide_friends' => true,
2328 'profile_photo' => 'profile_photo',
2329 'profile_thumb' => 'profile_thumb',
2331 'net_publish' => true,
2332 'description' => 'description',
2333 'date_of_birth' => 'date_of_birth',
2334 'address' => 'address',
2336 'region' => 'region',
2337 'postal_code' => 'postal_code',
2338 'country' => 'country',
2339 'hometown' => 'hometown',
2340 'gender' => 'gender',
2341 'marital' => 'marital',
2342 'marital_with' => 'marital_with',
2343 'marital_since' => 'marital_since',
2344 'sexual' => 'sexual',
2345 'politic' => 'politic',
2346 'religion' => 'religion',
2347 'public_keywords' => 'public_keywords',
2348 'private_keywords' => 'private_keywords',
2351 'dislikes' => 'dislikes',
2357 'interest' => 'interest',
2358 'romance' => 'romance',
2360 'education' => 'education',
2361 'social_networks' => 'social_networks',
2362 'homepage' => 'homepage',
2370 * Test the api_format_items() function.
2373 public function testApiFormatItems()
2377 'item_network' => 'item_network',
2383 'author-network' => Protocol::DFRN,
2384 'author-link' => 'http://localhost/profile/othercontact',
2388 $result = api_format_items($items, ['id' => 0], true);
2389 foreach ($result as $status) {
2390 $this->assertStatus($status);
2395 * Test the api_format_items() function with an XML result.
2398 public function testApiFormatItemsWithXml()
2406 'author-network' => Protocol::DFRN,
2407 'author-link' => 'http://localhost/profile/othercontact',
2411 $result = api_format_items($items, ['id' => 0], true, 'xml');
2412 foreach ($result as $status) {
2413 $this->assertStatus($status);
2418 * Test the api_format_items() function.
2421 public function testApiAccountRateLimitStatus()
2423 $result = api_account_rate_limit_status('json');
2424 $this->assertEquals(150, $result['hash']['remaining_hits']);
2425 $this->assertEquals(150, $result['hash']['hourly_limit']);
2426 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2430 * Test the api_format_items() function with an XML result.
2433 public function testApiAccountRateLimitStatusWithXml()
2435 $result = api_account_rate_limit_status('xml');
2436 $this->assertXml($result, 'hash');
2440 * Test the api_help_test() function.
2443 public function testApiHelpTest()
2445 $result = api_help_test('json');
2446 $this->assertEquals(['ok' => 'ok'], $result);
2450 * Test the api_help_test() function with an XML result.
2453 public function testApiHelpTestWithXml()
2455 $result = api_help_test('xml');
2456 $this->assertXml($result, 'ok');
2460 * Test the api_lists_list() function.
2463 public function testApiListsList()
2465 $result = api_lists_list('json');
2466 $this->assertEquals(['lists_list' => []], $result);
2470 * Test the api_lists_ownerships() function.
2473 public function testApiListsOwnerships()
2475 $result = api_lists_ownerships('json');
2476 foreach ($result['lists']['lists'] as $list) {
2477 $this->assertList($list);
2482 * Test the api_lists_ownerships() function without an authenticated user.
2484 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2486 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2488 $_SESSION['authenticated'] = false;
2489 api_lists_ownerships('json');
2493 * Test the api_lists_statuses() function.
2494 * @expectedException Friendica\Network\HTTPException\BadRequestException
2497 public function testApiListsStatuses()
2499 api_lists_statuses('json');
2503 * Test the api_lists_statuses() function with a list ID.
2506 public function testApiListsStatusesWithListId()
2508 $_REQUEST['list_id'] = 1;
2509 $_REQUEST['page'] = -1;
2510 $_REQUEST['max_id'] = 10;
2511 $result = api_lists_statuses('json');
2512 foreach ($result['status'] as $status) {
2513 $this->assertStatus($status);
2518 * Test the api_lists_statuses() function with a list ID and a RSS result.
2521 public function testApiListsStatusesWithListIdAndRss()
2523 $_REQUEST['list_id'] = 1;
2524 $result = api_lists_statuses('rss');
2525 $this->assertXml($result, 'statuses');
2529 * Test the api_lists_statuses() function with an unallowed user.
2531 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2533 public function testApiListsStatusesWithUnallowedUser()
2535 $_SESSION['allow_api'] = false;
2536 $_GET['screen_name'] = $this->selfUser['nick'];
2537 api_lists_statuses('json');
2541 * Test the api_statuses_f() function.
2544 public function testApiStatusesFWithFriends()
2547 $result = api_statuses_f('friends');
2548 $this->assertArrayHasKey('user', $result);
2552 * Test the api_statuses_f() function.
2555 public function testApiStatusesFWithFollowers()
2557 $result = api_statuses_f('followers');
2558 $this->assertArrayHasKey('user', $result);
2562 * Test the api_statuses_f() function.
2565 public function testApiStatusesFWithBlocks()
2567 $result = api_statuses_f('blocks');
2568 $this->assertArrayHasKey('user', $result);
2572 * Test the api_statuses_f() function.
2575 public function testApiStatusesFWithIncoming()
2577 $result = api_statuses_f('incoming');
2578 $this->assertArrayHasKey('user', $result);
2582 * Test the api_statuses_f() function an undefined cursor GET variable.
2585 public function testApiStatusesFWithUndefinedCursor()
2587 $_GET['cursor'] = 'undefined';
2588 $this->assertFalse(api_statuses_f('friends'));
2592 * Test the api_statuses_friends() function.
2595 public function testApiStatusesFriends()
2597 $result = api_statuses_friends('json');
2598 $this->assertArrayHasKey('user', $result);
2602 * Test the api_statuses_friends() function an undefined cursor GET variable.
2605 public function testApiStatusesFriendsWithUndefinedCursor()
2607 $_GET['cursor'] = 'undefined';
2608 $this->assertFalse(api_statuses_friends('json'));
2612 * Test the api_statuses_followers() function.
2615 public function testApiStatusesFollowers()
2617 $result = api_statuses_followers('json');
2618 $this->assertArrayHasKey('user', $result);
2622 * Test the api_statuses_followers() function an undefined cursor GET variable.
2625 public function testApiStatusesFollowersWithUndefinedCursor()
2627 $_GET['cursor'] = 'undefined';
2628 $this->assertFalse(api_statuses_followers('json'));
2632 * Test the api_blocks_list() function.
2635 public function testApiBlocksList()
2637 $result = api_blocks_list('json');
2638 $this->assertArrayHasKey('user', $result);
2642 * Test the api_blocks_list() function an undefined cursor GET variable.
2645 public function testApiBlocksListWithUndefinedCursor()
2647 $_GET['cursor'] = 'undefined';
2648 $this->assertFalse(api_blocks_list('json'));
2652 * Test the api_friendships_incoming() function.
2655 public function testApiFriendshipsIncoming()
2657 $result = api_friendships_incoming('json');
2658 $this->assertArrayHasKey('id', $result);
2662 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2665 public function testApiFriendshipsIncomingWithUndefinedCursor()
2667 $_GET['cursor'] = 'undefined';
2668 $this->assertFalse(api_friendships_incoming('json'));
2672 * Test the api_statusnet_config() function.
2675 public function testApiStatusnetConfig()
2677 $result = api_statusnet_config('json');
2678 $this->assertEquals('localhost', $result['config']['site']['server']);
2679 $this->assertEquals('default', $result['config']['site']['theme']);
2680 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2681 $this->assertTrue($result['config']['site']['fancy']);
2682 $this->assertEquals('en', $result['config']['site']['language']);
2683 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2684 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2685 $this->assertEquals('false', $result['config']['site']['private']);
2686 $this->assertEquals('false', $result['config']['site']['ssl']);
2687 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2691 * Test the api_statusnet_version() function.
2694 public function testApiStatusnetVersion()
2696 $result = api_statusnet_version('json');
2697 $this->assertEquals('0.9.7', $result['version']);
2701 * Test the api_ff_ids() function.
2704 public function testApiFfIds()
2706 $result = api_ff_ids('json');
2707 $this->assertNull($result);
2711 * Test the api_ff_ids() function with a result.
2714 public function testApiFfIdsWithResult()
2716 $this->markTestIncomplete();
2720 * Test the api_ff_ids() function without an authenticated user.
2722 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2724 public function testApiFfIdsWithoutAuthenticatedUser()
2726 $_SESSION['authenticated'] = false;
2731 * Test the api_friends_ids() function.
2734 public function testApiFriendsIds()
2736 $result = api_friends_ids('json');
2737 $this->assertNull($result);
2741 * Test the api_followers_ids() function.
2744 public function testApiFollowersIds()
2746 $result = api_followers_ids('json');
2747 $this->assertNull($result);
2751 * Test the api_direct_messages_new() function.
2754 public function testApiDirectMessagesNew()
2756 $result = api_direct_messages_new('json');
2757 $this->assertNull($result);
2761 * Test the api_direct_messages_new() function without an authenticated user.
2763 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2765 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2767 $_SESSION['authenticated'] = false;
2768 api_direct_messages_new('json');
2772 * Test the api_direct_messages_new() function with an user ID.
2775 public function testApiDirectMessagesNewWithUserId()
2777 $_POST['text'] = 'message_text';
2778 $_POST['user_id'] = $this->otherUser['id'];
2779 $result = api_direct_messages_new('json');
2780 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2784 * Test the api_direct_messages_new() function with a screen name.
2787 public function testApiDirectMessagesNewWithScreenName()
2789 $_POST['text'] = 'message_text';
2790 $_POST['screen_name'] = $this->friendUser['nick'];
2791 $result = api_direct_messages_new('json');
2792 $this->assertEquals(1, $result['direct_message']['id']);
2793 $this->assertContains('message_text', $result['direct_message']['text']);
2794 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2795 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2799 * Test the api_direct_messages_new() function with a title.
2802 public function testApiDirectMessagesNewWithTitle()
2804 $_POST['text'] = 'message_text';
2805 $_POST['screen_name'] = $this->friendUser['nick'];
2806 $_REQUEST['title'] = 'message_title';
2807 $result = api_direct_messages_new('json');
2808 $this->assertEquals(1, $result['direct_message']['id']);
2809 $this->assertContains('message_text', $result['direct_message']['text']);
2810 $this->assertContains('message_title', $result['direct_message']['text']);
2811 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2812 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2816 * Test the api_direct_messages_new() function with an RSS result.
2819 public function testApiDirectMessagesNewWithRss()
2821 $_POST['text'] = 'message_text';
2822 $_POST['screen_name'] = $this->friendUser['nick'];
2823 $result = api_direct_messages_new('rss');
2824 $this->assertXml($result, 'direct-messages');
2828 * Test the api_direct_messages_destroy() function.
2830 * @expectedException Friendica\Network\HTTPException\BadRequestException
2832 public function testApiDirectMessagesDestroy()
2834 api_direct_messages_destroy('json');
2838 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2841 public function testApiDirectMessagesDestroyWithVerbose()
2843 $_GET['friendica_verbose'] = 'true';
2844 $result = api_direct_messages_destroy('json');
2845 $this->assertEquals(
2848 'result' => 'error',
2849 'message' => 'message id or parenturi not specified'
2857 * Test the api_direct_messages_destroy() function without an authenticated user.
2859 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2861 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2863 $_SESSION['authenticated'] = false;
2864 api_direct_messages_destroy('json');
2868 * Test the api_direct_messages_destroy() function with a non-zero ID.
2870 * @expectedException Friendica\Network\HTTPException\BadRequestException
2872 public function testApiDirectMessagesDestroyWithId()
2874 $_REQUEST['id'] = 1;
2875 api_direct_messages_destroy('json');
2879 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2882 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2884 $_REQUEST['id'] = 1;
2885 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2886 $_GET['friendica_verbose'] = 'true';
2887 $result = api_direct_messages_destroy('json');
2888 $this->assertEquals(
2891 'result' => 'error',
2892 'message' => 'message id not in database'
2900 * Test the api_direct_messages_destroy() function with a non-zero ID.
2903 public function testApiDirectMessagesDestroyWithCorrectId()
2905 $this->markTestIncomplete('We need to add a dataset for this.');
2909 * Test the api_direct_messages_box() function.
2912 public function testApiDirectMessagesBoxWithSentbox()
2914 $_REQUEST['page'] = -1;
2915 $_REQUEST['max_id'] = 10;
2916 $result = api_direct_messages_box('json', 'sentbox', 'false');
2917 $this->assertArrayHasKey('direct_message', $result);
2921 * Test the api_direct_messages_box() function.
2924 public function testApiDirectMessagesBoxWithConversation()
2926 $result = api_direct_messages_box('json', 'conversation', 'false');
2927 $this->assertArrayHasKey('direct_message', $result);
2931 * Test the api_direct_messages_box() function.
2934 public function testApiDirectMessagesBoxWithAll()
2936 $result = api_direct_messages_box('json', 'all', 'false');
2937 $this->assertArrayHasKey('direct_message', $result);
2941 * Test the api_direct_messages_box() function.
2944 public function testApiDirectMessagesBoxWithInbox()
2946 $result = api_direct_messages_box('json', 'inbox', 'false');
2947 $this->assertArrayHasKey('direct_message', $result);
2951 * Test the api_direct_messages_box() function.
2954 public function testApiDirectMessagesBoxWithVerbose()
2956 $result = api_direct_messages_box('json', 'sentbox', 'true');
2957 $this->assertEquals(
2960 'result' => 'error',
2961 'message' => 'no mails available'
2969 * Test the api_direct_messages_box() function with a RSS result.
2972 public function testApiDirectMessagesBoxWithRss()
2974 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2975 $this->assertXml($result, 'direct-messages');
2979 * Test the api_direct_messages_box() function without an authenticated user.
2981 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2983 public function testApiDirectMessagesBoxWithUnallowedUser()
2985 $_SESSION['allow_api'] = false;
2986 $_GET['screen_name'] = $this->selfUser['nick'];
2987 api_direct_messages_box('json', 'sentbox', 'false');
2991 * Test the api_direct_messages_sentbox() function.
2994 public function testApiDirectMessagesSentbox()
2996 $result = api_direct_messages_sentbox('json');
2997 $this->assertArrayHasKey('direct_message', $result);
3001 * Test the api_direct_messages_inbox() function.
3004 public function testApiDirectMessagesInbox()
3006 $result = api_direct_messages_inbox('json');
3007 $this->assertArrayHasKey('direct_message', $result);
3011 * Test the api_direct_messages_all() function.
3014 public function testApiDirectMessagesAll()
3016 $result = api_direct_messages_all('json');
3017 $this->assertArrayHasKey('direct_message', $result);
3021 * Test the api_direct_messages_conversation() function.
3024 public function testApiDirectMessagesConversation()
3026 $result = api_direct_messages_conversation('json');
3027 $this->assertArrayHasKey('direct_message', $result);
3031 * Test the api_oauth_request_token() function.
3034 public function testApiOauthRequestToken()
3036 $this->markTestIncomplete('killme() kills phpunit as well');
3040 * Test the api_oauth_access_token() function.
3043 public function testApiOauthAccessToken()
3045 $this->markTestIncomplete('killme() kills phpunit as well');
3049 * Test the api_fr_photoalbum_delete() function.
3051 * @expectedException Friendica\Network\HTTPException\BadRequestException
3053 public function testApiFrPhotoalbumDelete()
3055 api_fr_photoalbum_delete('json');
3059 * Test the api_fr_photoalbum_delete() function with an album name.
3061 * @expectedException Friendica\Network\HTTPException\BadRequestException
3063 public function testApiFrPhotoalbumDeleteWithAlbum()
3065 $_REQUEST['album'] = 'album_name';
3066 api_fr_photoalbum_delete('json');
3070 * Test the api_fr_photoalbum_delete() function with an album name.
3073 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3075 $this->markTestIncomplete('We need to add a dataset for this.');
3079 * Test the api_fr_photoalbum_delete() function.
3081 * @expectedException Friendica\Network\HTTPException\BadRequestException
3083 public function testApiFrPhotoalbumUpdate()
3085 api_fr_photoalbum_update('json');
3089 * Test the api_fr_photoalbum_delete() function with an album name.
3091 * @expectedException Friendica\Network\HTTPException\BadRequestException
3093 public function testApiFrPhotoalbumUpdateWithAlbum()
3095 $_REQUEST['album'] = 'album_name';
3096 api_fr_photoalbum_update('json');
3100 * Test the api_fr_photoalbum_delete() function with an album name.
3102 * @expectedException Friendica\Network\HTTPException\BadRequestException
3104 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3106 $_REQUEST['album'] = 'album_name';
3107 $_REQUEST['album_new'] = 'album_name';
3108 api_fr_photoalbum_update('json');
3112 * Test the api_fr_photoalbum_update() function without an authenticated user.
3114 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3116 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3118 $_SESSION['authenticated'] = false;
3119 api_fr_photoalbum_update('json');
3123 * Test the api_fr_photoalbum_delete() function with an album name.
3126 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3128 $this->markTestIncomplete('We need to add a dataset for this.');
3132 * Test the api_fr_photos_list() function.
3135 public function testApiFrPhotosList()
3137 $result = api_fr_photos_list('json');
3138 $this->assertArrayHasKey('photo', $result);
3142 * Test the api_fr_photos_list() function without an authenticated user.
3144 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3146 public function testApiFrPhotosListWithoutAuthenticatedUser()
3148 $_SESSION['authenticated'] = false;
3149 api_fr_photos_list('json');
3153 * Test the api_fr_photo_create_update() function.
3155 * @expectedException Friendica\Network\HTTPException\BadRequestException
3157 public function testApiFrPhotoCreateUpdate()
3159 api_fr_photo_create_update('json');
3163 * Test the api_fr_photo_create_update() function without an authenticated user.
3165 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3167 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3169 $_SESSION['authenticated'] = false;
3170 api_fr_photo_create_update('json');
3174 * Test the api_fr_photo_create_update() function with an album name.
3176 * @expectedException Friendica\Network\HTTPException\BadRequestException
3178 public function testApiFrPhotoCreateUpdateWithAlbum()
3180 $_REQUEST['album'] = 'album_name';
3181 api_fr_photo_create_update('json');
3185 * Test the api_fr_photo_create_update() function with the update mode.
3188 public function testApiFrPhotoCreateUpdateWithUpdate()
3190 $this->markTestIncomplete('We need to create a dataset for this');
3194 * Test the api_fr_photo_create_update() function with an uploaded file.
3197 public function testApiFrPhotoCreateUpdateWithFile()
3199 $this->markTestIncomplete();
3203 * Test the api_fr_photo_delete() function.
3205 * @expectedException Friendica\Network\HTTPException\BadRequestException
3207 public function testApiFrPhotoDelete()
3209 api_fr_photo_delete('json');
3213 * Test the api_fr_photo_delete() function without an authenticated user.
3215 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3217 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3219 $_SESSION['authenticated'] = false;
3220 api_fr_photo_delete('json');
3224 * Test the api_fr_photo_delete() function with a photo ID.
3226 * @expectedException Friendica\Network\HTTPException\BadRequestException
3228 public function testApiFrPhotoDeleteWithPhotoId()
3230 $_REQUEST['photo_id'] = 1;
3231 api_fr_photo_delete('json');
3235 * Test the api_fr_photo_delete() function with a correct photo ID.
3238 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3240 $this->markTestIncomplete('We need to create a dataset for this.');
3244 * Test the api_fr_photo_detail() function.
3246 * @expectedException Friendica\Network\HTTPException\BadRequestException
3248 public function testApiFrPhotoDetail()
3250 api_fr_photo_detail('json');
3254 * Test the api_fr_photo_detail() function without an authenticated user.
3256 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3258 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3260 $_SESSION['authenticated'] = false;
3261 api_fr_photo_detail('json');
3265 * Test the api_fr_photo_detail() function with a photo ID.
3267 * @expectedException Friendica\Network\HTTPException\NotFoundException
3269 public function testApiFrPhotoDetailWithPhotoId()
3271 $_REQUEST['photo_id'] = 1;
3272 api_fr_photo_detail('json');
3276 * Test the api_fr_photo_detail() function with a correct photo ID.
3279 public function testApiFrPhotoDetailCorrectPhotoId()
3281 $this->markTestIncomplete('We need to create a dataset for this.');
3285 * Test the api_account_update_profile_image() function.
3287 * @expectedException Friendica\Network\HTTPException\BadRequestException
3289 public function testApiAccountUpdateProfileImage()
3291 api_account_update_profile_image('json');
3295 * Test the api_account_update_profile_image() function without an authenticated user.
3297 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3299 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3301 $_SESSION['authenticated'] = false;
3302 api_account_update_profile_image('json');
3306 * Test the api_account_update_profile_image() function with an uploaded file.
3308 * @expectedException Friendica\Network\HTTPException\BadRequestException
3310 public function testApiAccountUpdateProfileImageWithUpload()
3312 $this->markTestIncomplete();
3317 * Test the api_account_update_profile() function.
3320 public function testApiAccountUpdateProfile()
3322 $_POST['name'] = 'new_name';
3323 $_POST['description'] = 'new_description';
3324 $result = api_account_update_profile('json');
3325 // We can't use assertSelfUser() here because the user object is missing some properties.
3326 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3327 $this->assertEquals('DFRN', $result['user']['location']);
3328 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3329 $this->assertEquals('dfrn', $result['user']['network']);
3330 $this->assertEquals('new_name', $result['user']['name']);
3331 $this->assertEquals('new_description', $result['user']['description']);
3335 * Test the check_acl_input() function.
3338 public function testCheckAclInput()
3340 $result = check_acl_input('<aclstring>');
3341 // Where does this result come from?
3342 $this->assertEquals(1, $result);
3346 * Test the check_acl_input() function with an empty ACL string.
3349 public function testCheckAclInputWithEmptyAclString()
3351 $result = check_acl_input(' ');
3352 $this->assertFalse($result);
3356 * Test the save_media_to_database() function.
3359 public function testSaveMediaToDatabase()
3361 $this->markTestIncomplete();
3365 * Test the post_photo_item() function.
3368 public function testPostPhotoItem()
3370 $this->markTestIncomplete();
3374 * Test the prepare_photo_data() function.
3377 public function testPreparePhotoData()
3379 $this->markTestIncomplete();
3383 * Test the api_friendica_remoteauth() function.
3385 * @expectedException Friendica\Network\HTTPException\BadRequestException
3387 public function testApiFriendicaRemoteauth()
3389 api_friendica_remoteauth();
3393 * Test the api_friendica_remoteauth() function with an URL.
3395 * @expectedException Friendica\Network\HTTPException\BadRequestException
3397 public function testApiFriendicaRemoteauthWithUrl()
3399 $_GET['url'] = 'url';
3400 $_GET['c_url'] = 'url';
3401 api_friendica_remoteauth();
3405 * Test the api_friendica_remoteauth() function with a correct URL.
3408 public function testApiFriendicaRemoteauthWithCorrectUrl()
3410 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3411 $_GET['url'] = 'url';
3412 $_GET['c_url'] = $this->selfUser['nurl'];
3413 api_friendica_remoteauth();
3417 * Test the api_share_as_retweet() function.
3420 public function testApiShareAsRetweet()
3422 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3423 $result = api_share_as_retweet($item);
3424 $this->assertFalse($result);
3428 * Test the api_share_as_retweet() function with a valid item.
3431 public function testApiShareAsRetweetWithValidItem()
3433 $this->markTestIncomplete();
3437 * Test the api_get_nick() function.
3440 public function testApiGetNick()
3442 $result = api_get_nick($this->otherUser['nurl']);
3443 $this->assertEquals('othercontact', $result);
3447 * Test the api_get_nick() function with a wrong URL.
3450 public function testApiGetNickWithWrongUrl()
3452 $result = api_get_nick('wrong_url');
3453 $this->assertFalse($result);
3457 * Test the api_in_reply_to() function.
3460 public function testApiInReplyTo()
3462 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3463 $this->assertArrayHasKey('status_id', $result);
3464 $this->assertArrayHasKey('user_id', $result);
3465 $this->assertArrayHasKey('status_id_str', $result);
3466 $this->assertArrayHasKey('user_id_str', $result);
3467 $this->assertArrayHasKey('screen_name', $result);
3471 * Test the api_in_reply_to() function with a valid item.
3474 public function testApiInReplyToWithValidItem()
3476 $this->markTestIncomplete();
3480 * Test the api_clean_plain_items() function.
3483 public function testApiCleanPlainItems()
3485 $_REQUEST['include_entities'] = 'true';
3486 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3487 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3491 * Test the api_clean_attachments() function.
3494 public function testApiCleanAttachments()
3496 $this->markTestIncomplete();
3500 * Test the api_best_nickname() function.
3503 public function testApiBestNickname()
3506 $result = api_best_nickname($contacts);
3507 $this->assertNull($result);
3511 * Test the api_best_nickname() function with contacts.
3514 public function testApiBestNicknameWithContacts()
3516 $this->markTestIncomplete();
3520 * Test the api_friendica_group_show() function.
3523 public function testApiFriendicaGroupShow()
3525 $this->markTestIncomplete();
3529 * Test the api_friendica_group_delete() function.
3532 public function testApiFriendicaGroupDelete()
3534 $this->markTestIncomplete();
3538 * Test the api_lists_destroy() function.
3541 public function testApiListsDestroy()
3543 $this->markTestIncomplete();
3547 * Test the group_create() function.
3550 public function testGroupCreate()
3552 $this->markTestIncomplete();
3556 * Test the api_friendica_group_create() function.
3559 public function testApiFriendicaGroupCreate()
3561 $this->markTestIncomplete();
3565 * Test the api_lists_create() function.
3568 public function testApiListsCreate()
3570 $this->markTestIncomplete();
3574 * Test the api_friendica_group_update() function.
3577 public function testApiFriendicaGroupUpdate()
3579 $this->markTestIncomplete();
3583 * Test the api_lists_update() function.
3586 public function testApiListsUpdate()
3588 $this->markTestIncomplete();
3592 * Test the api_friendica_activity() function.
3595 public function testApiFriendicaActivity()
3597 $this->markTestIncomplete();
3601 * Test the api_friendica_notification() function.
3603 * @expectedException Friendica\Network\HTTPException\BadRequestException
3605 public function testApiFriendicaNotification()
3607 api_friendica_notification('json');
3611 * Test the api_friendica_notification() function without an authenticated user.
3613 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3615 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3617 $_SESSION['authenticated'] = false;
3618 api_friendica_notification('json');
3622 * Test the api_friendica_notification() function with an argument count.
3625 public function testApiFriendicaNotificationWithArgumentCount()
3627 $this->app->argv = ['api', 'friendica', 'notification'];
3628 $this->app->argc = count($this->app->argv);
3629 $result = api_friendica_notification('json');
3630 $this->assertEquals(['note' => false], $result);
3634 * Test the api_friendica_notification() function with an XML result.
3637 public function testApiFriendicaNotificationWithXmlResult()
3639 $this->app->argv = ['api', 'friendica', 'notification'];
3640 $this->app->argc = count($this->app->argv);
3641 $result = api_friendica_notification('xml');
3642 $this->assertXml($result, 'notes');
3646 * Test the api_friendica_notification_seen() function.
3649 public function testApiFriendicaNotificationSeen()
3651 $this->markTestIncomplete();
3655 * Test the api_friendica_direct_messages_setseen() function.
3658 public function testApiFriendicaDirectMessagesSetseen()
3660 $this->markTestIncomplete();
3664 * Test the api_friendica_direct_messages_search() function.
3667 public function testApiFriendicaDirectMessagesSearch()
3669 $this->markTestIncomplete();
3673 * Test the api_friendica_profile_show() function.
3676 public function testApiFriendicaProfileShow()
3678 $result = api_friendica_profile_show('json');
3679 // We can't use assertSelfUser() here because the user object is missing some properties.
3680 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3681 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3682 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3683 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3684 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3685 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3686 $this->assertFalse($result['$result']['multi_profiles']);
3690 * Test the api_friendica_profile_show() function with a profile ID.
3693 public function testApiFriendicaProfileShowWithProfileId()
3695 $this->markTestIncomplete('We need to add a dataset for this.');
3699 * Test the api_friendica_profile_show() function with a wrong profile ID.
3701 * @expectedException Friendica\Network\HTTPException\BadRequestException
3703 public function testApiFriendicaProfileShowWithWrongProfileId()
3705 $_REQUEST['profile_id'] = 666;
3706 api_friendica_profile_show('json');
3710 * Test the api_friendica_profile_show() function without an authenticated user.
3712 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3714 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3716 $_SESSION['authenticated'] = false;
3717 api_friendica_profile_show('json');
3721 * Test the api_saved_searches_list() function.
3724 public function testApiSavedSearchesList()
3726 $result = api_saved_searches_list('json');
3727 $this->assertEquals(1, $result['terms'][0]['id']);
3728 $this->assertEquals(1, $result['terms'][0]['id_str']);
3729 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3730 $this->assertEquals('Saved search', $result['terms'][0]['query']);