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);
1410 * Test the api_search() function without an authenticated user.
1412 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1414 public function testApiSearchWithUnallowedUser()
1416 $_SESSION['allow_api'] = false;
1417 $_GET['screen_name'] = $this->selfUser['nick'];
1422 * Test the api_search() function without any GET query parameter.
1424 * @expectedException Friendica\Network\HTTPException\BadRequestException
1426 public function testApiSearchWithoutQuery()
1432 * Test the api_statuses_home_timeline() function.
1435 public function testApiStatusesHomeTimeline()
1437 $_REQUEST['max_id'] = 10;
1438 $_REQUEST['exclude_replies'] = true;
1439 $_REQUEST['conversation_id'] = 1;
1440 $result = api_statuses_home_timeline('json');
1441 $this->assertNotEmpty($result['status']);
1442 foreach ($result['status'] as $status) {
1443 $this->assertStatus($status);
1448 * Test the api_statuses_home_timeline() function with a negative page parameter.
1451 public function testApiStatusesHomeTimelineWithNegativePage()
1453 $_REQUEST['page'] = -2;
1454 $result = api_statuses_home_timeline('json');
1455 $this->assertNotEmpty($result['status']);
1456 foreach ($result['status'] as $status) {
1457 $this->assertStatus($status);
1462 * Test the api_statuses_home_timeline() with an unallowed user.
1464 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1466 public function testApiStatusesHomeTimelineWithUnallowedUser()
1468 $_SESSION['allow_api'] = false;
1469 $_GET['screen_name'] = $this->selfUser['nick'];
1470 api_statuses_home_timeline('json');
1474 * Test the api_statuses_home_timeline() function with an RSS result.
1477 public function testApiStatusesHomeTimelineWithRss()
1479 $result = api_statuses_home_timeline('rss');
1480 $this->assertXml($result, 'statuses');
1484 * Test the api_statuses_public_timeline() function.
1487 public function testApiStatusesPublicTimeline()
1489 $_REQUEST['max_id'] = 10;
1490 $_REQUEST['conversation_id'] = 1;
1491 $result = api_statuses_public_timeline('json');
1492 $this->assertNotEmpty($result['status']);
1493 foreach ($result['status'] as $status) {
1494 $this->assertStatus($status);
1499 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1502 public function testApiStatusesPublicTimelineWithExcludeReplies()
1504 $_REQUEST['max_id'] = 10;
1505 $_REQUEST['exclude_replies'] = true;
1506 $result = api_statuses_public_timeline('json');
1507 $this->assertNotEmpty($result['status']);
1508 foreach ($result['status'] as $status) {
1509 $this->assertStatus($status);
1514 * Test the api_statuses_public_timeline() function with a negative page parameter.
1517 public function testApiStatusesPublicTimelineWithNegativePage()
1519 $_REQUEST['page'] = -2;
1520 $result = api_statuses_public_timeline('json');
1521 $this->assertNotEmpty($result['status']);
1522 foreach ($result['status'] as $status) {
1523 $this->assertStatus($status);
1528 * Test the api_statuses_public_timeline() function with an unallowed user.
1530 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1532 public function testApiStatusesPublicTimelineWithUnallowedUser()
1534 $_SESSION['allow_api'] = false;
1535 $_GET['screen_name'] = $this->selfUser['nick'];
1536 api_statuses_public_timeline('json');
1540 * Test the api_statuses_public_timeline() function with an RSS result.
1543 public function testApiStatusesPublicTimelineWithRss()
1545 $result = api_statuses_public_timeline('rss');
1546 $this->assertXml($result, 'statuses');
1550 * Test the api_statuses_networkpublic_timeline() function.
1553 public function testApiStatusesNetworkpublicTimeline()
1555 $_REQUEST['max_id'] = 10;
1556 $result = api_statuses_networkpublic_timeline('json');
1557 $this->assertNotEmpty($result['status']);
1558 foreach ($result['status'] as $status) {
1559 $this->assertStatus($status);
1564 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1567 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1569 $_REQUEST['page'] = -2;
1570 $result = api_statuses_networkpublic_timeline('json');
1571 $this->assertNotEmpty($result['status']);
1572 foreach ($result['status'] as $status) {
1573 $this->assertStatus($status);
1578 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1580 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1582 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1584 $_SESSION['allow_api'] = false;
1585 $_GET['screen_name'] = $this->selfUser['nick'];
1586 api_statuses_networkpublic_timeline('json');
1590 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1593 public function testApiStatusesNetworkpublicTimelineWithRss()
1595 $result = api_statuses_networkpublic_timeline('rss');
1596 $this->assertXml($result, 'statuses');
1600 * Test the api_statuses_show() function.
1602 * @expectedException Friendica\Network\HTTPException\BadRequestException
1604 public function testApiStatusesShow()
1606 api_statuses_show('json');
1610 * Test the api_statuses_show() function with an ID.
1613 public function testApiStatusesShowWithId()
1615 $this->app->argv[3] = 1;
1616 $result = api_statuses_show('json');
1617 $this->assertStatus($result['status']);
1621 * Test the api_statuses_show() function with the conversation parameter.
1624 public function testApiStatusesShowWithConversation()
1626 $this->app->argv[3] = 1;
1627 $_REQUEST['conversation'] = 1;
1628 $result = api_statuses_show('json');
1629 $this->assertNotEmpty($result['status']);
1630 foreach ($result['status'] as $status) {
1631 $this->assertStatus($status);
1636 * Test the api_statuses_show() function with an unallowed user.
1638 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1640 public function testApiStatusesShowWithUnallowedUser()
1642 $_SESSION['allow_api'] = false;
1643 $_GET['screen_name'] = $this->selfUser['nick'];
1644 api_statuses_show('json');
1648 * Test the api_conversation_show() function.
1650 * @expectedException Friendica\Network\HTTPException\BadRequestException
1652 public function testApiConversationShow()
1654 api_conversation_show('json');
1658 * Test the api_conversation_show() function with an ID.
1661 public function testApiConversationShowWithId()
1663 $this->app->argv[3] = 1;
1664 $_REQUEST['max_id'] = 10;
1665 $_REQUEST['page'] = -2;
1666 $result = api_conversation_show('json');
1667 $this->assertNotEmpty($result['status']);
1668 foreach ($result['status'] as $status) {
1669 $this->assertStatus($status);
1674 * Test the api_conversation_show() function with an unallowed user.
1676 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1678 public function testApiConversationShowWithUnallowedUser()
1680 $_SESSION['allow_api'] = false;
1681 $_GET['screen_name'] = $this->selfUser['nick'];
1682 api_conversation_show('json');
1686 * Test the api_statuses_repeat() function.
1688 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1690 public function testApiStatusesRepeat()
1692 api_statuses_repeat('json');
1696 * Test the api_statuses_repeat() function without an authenticated user.
1698 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1700 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1702 $_SESSION['authenticated'] = false;
1703 api_statuses_repeat('json');
1707 * Test the api_statuses_repeat() function with an ID.
1710 public function testApiStatusesRepeatWithId()
1712 $this->app->argv[3] = 1;
1713 $result = api_statuses_repeat('json');
1714 $this->assertStatus($result['status']);
1716 // Also test with a shared status
1717 $this->app->argv[3] = 5;
1718 $result = api_statuses_repeat('json');
1719 $this->assertStatus($result['status']);
1723 * Test the api_statuses_destroy() function.
1725 * @expectedException Friendica\Network\HTTPException\BadRequestException
1727 public function testApiStatusesDestroy()
1729 api_statuses_destroy('json');
1733 * Test the api_statuses_destroy() function without an authenticated user.
1735 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1737 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1739 $_SESSION['authenticated'] = false;
1740 api_statuses_destroy('json');
1744 * Test the api_statuses_destroy() function with an ID.
1747 public function testApiStatusesDestroyWithId()
1749 $this->app->argv[3] = 1;
1750 $result = api_statuses_destroy('json');
1751 $this->assertStatus($result['status']);
1755 * Test the api_statuses_mentions() function.
1758 public function testApiStatusesMentions()
1760 $this->app->user = ['nickname' => $this->selfUser['nick']];
1761 $_REQUEST['max_id'] = 10;
1762 $result = api_statuses_mentions('json');
1763 $this->assertEmpty($result['status']);
1764 // We should test with mentions in the database.
1768 * Test the api_statuses_mentions() function with a negative page parameter.
1771 public function testApiStatusesMentionsWithNegativePage()
1773 $_REQUEST['page'] = -2;
1774 $result = api_statuses_mentions('json');
1775 $this->assertEmpty($result['status']);
1779 * Test the api_statuses_mentions() function with an unallowed user.
1781 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1783 public function testApiStatusesMentionsWithUnallowedUser()
1785 $_SESSION['allow_api'] = false;
1786 $_GET['screen_name'] = $this->selfUser['nick'];
1787 api_statuses_mentions('json');
1791 * Test the api_statuses_mentions() function with an RSS result.
1794 public function testApiStatusesMentionsWithRss()
1796 $result = api_statuses_mentions('rss');
1797 $this->assertXml($result, 'statuses');
1801 * Test the api_statuses_user_timeline() function.
1804 public function testApiStatusesUserTimeline()
1806 $_REQUEST['max_id'] = 10;
1807 $_REQUEST['exclude_replies'] = true;
1808 $_REQUEST['conversation_id'] = 1;
1809 $result = api_statuses_user_timeline('json');
1810 $this->assertNotEmpty($result['status']);
1811 foreach ($result['status'] as $status) {
1812 $this->assertStatus($status);
1817 * Test the api_statuses_user_timeline() function with a negative page parameter.
1820 public function testApiStatusesUserTimelineWithNegativePage()
1822 $_REQUEST['page'] = -2;
1823 $result = api_statuses_user_timeline('json');
1824 $this->assertNotEmpty($result['status']);
1825 foreach ($result['status'] as $status) {
1826 $this->assertStatus($status);
1831 * Test the api_statuses_user_timeline() function with an RSS result.
1834 public function testApiStatusesUserTimelineWithRss()
1836 $result = api_statuses_user_timeline('rss');
1837 $this->assertXml($result, 'statuses');
1841 * Test the api_statuses_user_timeline() function with an unallowed user.
1843 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1845 public function testApiStatusesUserTimelineWithUnallowedUser()
1847 $_SESSION['allow_api'] = false;
1848 $_GET['screen_name'] = $this->selfUser['nick'];
1849 api_statuses_user_timeline('json');
1853 * Test the api_favorites_create_destroy() function.
1855 * @expectedException Friendica\Network\HTTPException\BadRequestException
1857 public function testApiFavoritesCreateDestroy()
1859 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1860 $this->app->argc = count($this->app->argv);
1861 api_favorites_create_destroy('json');
1865 * Test the api_favorites_create_destroy() function with an invalid ID.
1867 * @expectedException Friendica\Network\HTTPException\BadRequestException
1869 public function testApiFavoritesCreateDestroyWithInvalidId()
1871 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1872 $this->app->argc = count($this->app->argv);
1873 api_favorites_create_destroy('json');
1877 * Test the api_favorites_create_destroy() function with an invalid action.
1879 * @expectedException Friendica\Network\HTTPException\BadRequestException
1881 public function testApiFavoritesCreateDestroyWithInvalidAction()
1883 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1884 $this->app->argc = count($this->app->argv);
1885 $_REQUEST['id'] = 1;
1886 api_favorites_create_destroy('json');
1890 * Test the api_favorites_create_destroy() function with the create action.
1893 public function testApiFavoritesCreateDestroyWithCreateAction()
1895 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1896 $this->app->argc = count($this->app->argv);
1897 $_REQUEST['id'] = 3;
1898 $result = api_favorites_create_destroy('json');
1899 $this->assertStatus($result['status']);
1903 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1906 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1908 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1909 $this->app->argc = count($this->app->argv);
1910 $_REQUEST['id'] = 3;
1911 $result = api_favorites_create_destroy('rss');
1912 $this->assertXml($result, 'status');
1916 * Test the api_favorites_create_destroy() function with the destroy action.
1919 public function testApiFavoritesCreateDestroyWithDestroyAction()
1921 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1922 $this->app->argc = count($this->app->argv);
1923 $_REQUEST['id'] = 3;
1924 $result = api_favorites_create_destroy('json');
1925 $this->assertStatus($result['status']);
1929 * Test the api_favorites_create_destroy() function without an authenticated user.
1931 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1933 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1935 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1936 $this->app->argc = count($this->app->argv);
1937 $_SESSION['authenticated'] = false;
1938 api_favorites_create_destroy('json');
1942 * Test the api_favorites() function.
1945 public function testApiFavorites()
1947 $_REQUEST['page'] = -1;
1948 $_REQUEST['max_id'] = 10;
1949 $result = api_favorites('json');
1950 foreach ($result['status'] as $status) {
1951 $this->assertStatus($status);
1956 * Test the api_favorites() function with an RSS result.
1959 public function testApiFavoritesWithRss()
1961 $result = api_favorites('rss');
1962 $this->assertXml($result, 'statuses');
1966 * Test the api_favorites() function with an unallowed user.
1968 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1970 public function testApiFavoritesWithUnallowedUser()
1972 $_SESSION['allow_api'] = false;
1973 $_GET['screen_name'] = $this->selfUser['nick'];
1974 api_favorites('json');
1978 * Test the api_format_messages() function.
1981 public function testApiFormatMessages()
1983 $result = api_format_messages(
1984 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1985 ['id' => 2, 'screen_name' => 'recipient_name'],
1986 ['id' => 3, 'screen_name' => 'sender_name']
1988 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1989 $this->assertEquals(1, $result['id']);
1990 $this->assertEquals(2, $result['recipient_id']);
1991 $this->assertEquals(3, $result['sender_id']);
1992 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1993 $this->assertEquals('sender_name', $result['sender_screen_name']);
1997 * Test the api_format_messages() function with HTML.
2000 public function testApiFormatMessagesWithHtmlText()
2002 $_GET['getText'] = 'html';
2003 $result = api_format_messages(
2004 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2005 ['id' => 2, 'screen_name' => 'recipient_name'],
2006 ['id' => 3, 'screen_name' => 'sender_name']
2008 $this->assertEquals('item_title', $result['title']);
2009 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2013 * Test the api_format_messages() function with plain text.
2016 public function testApiFormatMessagesWithPlainText()
2018 $_GET['getText'] = 'plain';
2019 $result = api_format_messages(
2020 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2021 ['id' => 2, 'screen_name' => 'recipient_name'],
2022 ['id' => 3, 'screen_name' => 'sender_name']
2024 $this->assertEquals('item_title', $result['title']);
2025 $this->assertEquals('item_body', $result['text']);
2029 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2032 public function testApiFormatMessagesWithoutUserObjects()
2034 $_GET['getUserObjects'] = 'false';
2035 $result = api_format_messages(
2036 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2037 ['id' => 2, 'screen_name' => 'recipient_name'],
2038 ['id' => 3, 'screen_name' => 'sender_name']
2040 $this->assertTrue(!isset($result['sender']));
2041 $this->assertTrue(!isset($result['recipient']));
2045 * Test the api_convert_item() function.
2048 public function testApiConvertItem()
2050 $result = api_convert_item(
2052 'network' => 'feed',
2053 'title' => 'item_title',
2054 // We need a long string to test that it is correctly cut
2055 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2056 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2057 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2058 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2059 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2060 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2061 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2062 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2063 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2064 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2065 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2066 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2067 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2068 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2069 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2070 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2071 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2072 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2073 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2074 'repellat officia illum quos impedit quam iste esse unde qui '.
2075 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2076 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2077 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2078 'plink' => 'item_plink'
2081 $this->assertStringStartsWith('item_title', $result['text']);
2082 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2086 * Test the api_convert_item() function with an empty item body.
2089 public function testApiConvertItemWithoutBody()
2091 $result = api_convert_item(
2093 'network' => 'feed',
2094 'title' => 'item_title',
2096 'plink' => 'item_plink'
2099 $this->assertEquals('item_title', $result['text']);
2100 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2104 * Test the api_convert_item() function with the title in the body.
2107 public function testApiConvertItemWithTitleInBody()
2109 $result = api_convert_item(
2111 'title' => 'item_title',
2112 'body' => 'item_title item_body'
2115 $this->assertEquals('item_title item_body', $result['text']);
2116 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2120 * Test the api_get_attachments() function.
2123 public function testApiGetAttachments()
2126 $this->assertEmpty(api_get_attachments($body));
2130 * Test the api_get_attachments() function with an img tag.
2133 public function testApiGetAttachmentsWithImage()
2135 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2136 $this->assertInternalType('array', api_get_attachments($body));
2140 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2143 public function testApiGetAttachmentsWithImageAndAndStatus()
2145 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2146 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2147 $this->assertInternalType('array', api_get_attachments($body));
2151 * Test the api_get_entitities() function.
2154 public function testApiGetEntitities()
2157 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2161 * Test the api_get_entitities() function with the include_entities parameter.
2164 public function testApiGetEntititiesWithIncludeEntities()
2166 $_REQUEST['include_entities'] = 'true';
2168 $result = api_get_entitities($text, 'bbcode');
2169 $this->assertInternalType('array', $result['hashtags']);
2170 $this->assertInternalType('array', $result['symbols']);
2171 $this->assertInternalType('array', $result['urls']);
2172 $this->assertInternalType('array', $result['user_mentions']);
2176 * Test the api_format_items_embeded_images() function.
2179 public function testApiFormatItemsEmbededImages()
2181 $this->assertEquals(
2182 'text ' . System::baseUrl() . '/display/item_guid',
2183 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2188 * Test the api_contactlink_to_array() function.
2191 public function testApiContactlinkToArray()
2193 $this->assertEquals(
2198 api_contactlink_to_array('text')
2203 * Test the api_contactlink_to_array() function with an URL.
2206 public function testApiContactlinkToArrayWithUrl()
2208 $this->assertEquals(
2210 'name' => ['link_text'],
2213 api_contactlink_to_array('text <a href="url">link_text</a>')
2218 * Test the api_format_items_activities() function.
2221 public function testApiFormatItemsActivities()
2223 $item = ['uid' => 0, 'uri' => ''];
2224 $result = api_format_items_activities($item);
2225 $this->assertArrayHasKey('like', $result);
2226 $this->assertArrayHasKey('dislike', $result);
2227 $this->assertArrayHasKey('attendyes', $result);
2228 $this->assertArrayHasKey('attendno', $result);
2229 $this->assertArrayHasKey('attendmaybe', $result);
2233 * Test the api_format_items_activities() function with an XML result.
2236 public function testApiFormatItemsActivitiesWithXml()
2238 $item = ['uid' => 0, 'uri' => ''];
2239 $result = api_format_items_activities($item, 'xml');
2240 $this->assertArrayHasKey('friendica:like', $result);
2241 $this->assertArrayHasKey('friendica:dislike', $result);
2242 $this->assertArrayHasKey('friendica:attendyes', $result);
2243 $this->assertArrayHasKey('friendica:attendno', $result);
2244 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2248 * Test the api_format_items_profiles() function.
2251 public function testApiFormatItemsProfiles()
2254 'id' => 'profile_id',
2255 'profile-name' => 'profile_name',
2256 'is-default' => true,
2257 'hide-friends' => true,
2258 'photo' => 'profile_photo',
2259 'thumb' => 'profile_thumb',
2261 'net-publish' => true,
2262 'pdesc' => 'description',
2263 'dob' => 'date_of_birth',
2264 'address' => 'address',
2265 'locality' => 'city',
2266 'region' => 'region',
2267 'postal-code' => 'postal_code',
2268 'country-name' => 'country',
2269 'hometown' => 'hometown',
2270 'gender' => 'gender',
2271 'marital' => 'marital',
2272 'with' => 'marital_with',
2273 'howlong' => 'marital_since',
2274 'sexual' => 'sexual',
2275 'politic' => 'politic',
2276 'religion' => 'religion',
2277 'pub_keywords' => 'public_keywords',
2278 'prv_keywords' => 'private_keywords',
2281 'dislikes' => 'dislikes',
2287 'interest' => 'interest',
2288 'romance' => 'romance',
2290 'education' => 'education',
2291 'contact' => 'social_networks',
2292 'homepage' => 'homepage'
2294 $result = api_format_items_profiles($profile_row);
2295 $this->assertEquals(
2297 'profile_id' => 'profile_id',
2298 'profile_name' => 'profile_name',
2299 'is_default' => true,
2300 'hide_friends' => true,
2301 'profile_photo' => 'profile_photo',
2302 'profile_thumb' => 'profile_thumb',
2304 'net_publish' => true,
2305 'description' => 'description',
2306 'date_of_birth' => 'date_of_birth',
2307 'address' => 'address',
2309 'region' => 'region',
2310 'postal_code' => 'postal_code',
2311 'country' => 'country',
2312 'hometown' => 'hometown',
2313 'gender' => 'gender',
2314 'marital' => 'marital',
2315 'marital_with' => 'marital_with',
2316 'marital_since' => 'marital_since',
2317 'sexual' => 'sexual',
2318 'politic' => 'politic',
2319 'religion' => 'religion',
2320 'public_keywords' => 'public_keywords',
2321 'private_keywords' => 'private_keywords',
2324 'dislikes' => 'dislikes',
2330 'interest' => 'interest',
2331 'romance' => 'romance',
2333 'education' => 'education',
2334 'social_networks' => 'social_networks',
2335 'homepage' => 'homepage',
2343 * Test the api_format_items() function.
2346 public function testApiFormatItems()
2350 'item_network' => 'item_network',
2356 'author-network' => Protocol::DFRN,
2357 'author-link' => 'http://localhost/profile/othercontact',
2361 $result = api_format_items($items, ['id' => 0], true);
2362 foreach ($result as $status) {
2363 $this->assertStatus($status);
2368 * Test the api_format_items() function with an XML result.
2371 public function testApiFormatItemsWithXml()
2379 'author-network' => Protocol::DFRN,
2380 'author-link' => 'http://localhost/profile/othercontact',
2384 $result = api_format_items($items, ['id' => 0], true, 'xml');
2385 foreach ($result as $status) {
2386 $this->assertStatus($status);
2391 * Test the api_format_items() function.
2394 public function testApiAccountRateLimitStatus()
2396 $result = api_account_rate_limit_status('json');
2397 $this->assertEquals(150, $result['hash']['remaining_hits']);
2398 $this->assertEquals(150, $result['hash']['hourly_limit']);
2399 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2403 * Test the api_format_items() function with an XML result.
2406 public function testApiAccountRateLimitStatusWithXml()
2408 $result = api_account_rate_limit_status('xml');
2409 $this->assertXml($result, 'hash');
2413 * Test the api_help_test() function.
2416 public function testApiHelpTest()
2418 $result = api_help_test('json');
2419 $this->assertEquals(['ok' => 'ok'], $result);
2423 * Test the api_help_test() function with an XML result.
2426 public function testApiHelpTestWithXml()
2428 $result = api_help_test('xml');
2429 $this->assertXml($result, 'ok');
2433 * Test the api_lists_list() function.
2436 public function testApiListsList()
2438 $result = api_lists_list('json');
2439 $this->assertEquals(['lists_list' => []], $result);
2443 * Test the api_lists_ownerships() function.
2446 public function testApiListsOwnerships()
2448 $result = api_lists_ownerships('json');
2449 foreach ($result['lists']['lists'] as $list) {
2450 $this->assertList($list);
2455 * Test the api_lists_ownerships() function without an authenticated user.
2457 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2459 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2461 $_SESSION['authenticated'] = false;
2462 api_lists_ownerships('json');
2466 * Test the api_lists_statuses() function.
2467 * @expectedException Friendica\Network\HTTPException\BadRequestException
2470 public function testApiListsStatuses()
2472 api_lists_statuses('json');
2476 * Test the api_lists_statuses() function with a list ID.
2479 public function testApiListsStatusesWithListId()
2481 $_REQUEST['list_id'] = 1;
2482 $_REQUEST['page'] = -1;
2483 $_REQUEST['max_id'] = 10;
2484 $result = api_lists_statuses('json');
2485 foreach ($result['status'] as $status) {
2486 $this->assertStatus($status);
2491 * Test the api_lists_statuses() function with a list ID and a RSS result.
2494 public function testApiListsStatusesWithListIdAndRss()
2496 $_REQUEST['list_id'] = 1;
2497 $result = api_lists_statuses('rss');
2498 $this->assertXml($result, 'statuses');
2502 * Test the api_lists_statuses() function with an unallowed user.
2504 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2506 public function testApiListsStatusesWithUnallowedUser()
2508 $_SESSION['allow_api'] = false;
2509 $_GET['screen_name'] = $this->selfUser['nick'];
2510 api_lists_statuses('json');
2514 * Test the api_statuses_f() function.
2517 public function testApiStatusesFWithFriends()
2520 $result = api_statuses_f('friends');
2521 $this->assertArrayHasKey('user', $result);
2525 * Test the api_statuses_f() function.
2528 public function testApiStatusesFWithFollowers()
2530 $result = api_statuses_f('followers');
2531 $this->assertArrayHasKey('user', $result);
2535 * Test the api_statuses_f() function.
2538 public function testApiStatusesFWithBlocks()
2540 $result = api_statuses_f('blocks');
2541 $this->assertArrayHasKey('user', $result);
2545 * Test the api_statuses_f() function.
2548 public function testApiStatusesFWithIncoming()
2550 $result = api_statuses_f('incoming');
2551 $this->assertArrayHasKey('user', $result);
2555 * Test the api_statuses_f() function an undefined cursor GET variable.
2558 public function testApiStatusesFWithUndefinedCursor()
2560 $_GET['cursor'] = 'undefined';
2561 $this->assertFalse(api_statuses_f('friends'));
2565 * Test the api_statuses_friends() function.
2568 public function testApiStatusesFriends()
2570 $result = api_statuses_friends('json');
2571 $this->assertArrayHasKey('user', $result);
2575 * Test the api_statuses_friends() function an undefined cursor GET variable.
2578 public function testApiStatusesFriendsWithUndefinedCursor()
2580 $_GET['cursor'] = 'undefined';
2581 $this->assertFalse(api_statuses_friends('json'));
2585 * Test the api_statuses_followers() function.
2588 public function testApiStatusesFollowers()
2590 $result = api_statuses_followers('json');
2591 $this->assertArrayHasKey('user', $result);
2595 * Test the api_statuses_followers() function an undefined cursor GET variable.
2598 public function testApiStatusesFollowersWithUndefinedCursor()
2600 $_GET['cursor'] = 'undefined';
2601 $this->assertFalse(api_statuses_followers('json'));
2605 * Test the api_blocks_list() function.
2608 public function testApiBlocksList()
2610 $result = api_blocks_list('json');
2611 $this->assertArrayHasKey('user', $result);
2615 * Test the api_blocks_list() function an undefined cursor GET variable.
2618 public function testApiBlocksListWithUndefinedCursor()
2620 $_GET['cursor'] = 'undefined';
2621 $this->assertFalse(api_blocks_list('json'));
2625 * Test the api_friendships_incoming() function.
2628 public function testApiFriendshipsIncoming()
2630 $result = api_friendships_incoming('json');
2631 $this->assertArrayHasKey('id', $result);
2635 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2638 public function testApiFriendshipsIncomingWithUndefinedCursor()
2640 $_GET['cursor'] = 'undefined';
2641 $this->assertFalse(api_friendships_incoming('json'));
2645 * Test the api_statusnet_config() function.
2648 public function testApiStatusnetConfig()
2650 $result = api_statusnet_config('json');
2651 $this->assertEquals('localhost', $result['config']['site']['server']);
2652 $this->assertEquals('default', $result['config']['site']['theme']);
2653 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2654 $this->assertTrue($result['config']['site']['fancy']);
2655 $this->assertEquals('en', $result['config']['site']['language']);
2656 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2657 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2658 $this->assertEquals('false', $result['config']['site']['private']);
2659 $this->assertEquals('false', $result['config']['site']['ssl']);
2660 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2664 * Test the api_statusnet_version() function.
2667 public function testApiStatusnetVersion()
2669 $result = api_statusnet_version('json');
2670 $this->assertEquals('0.9.7', $result['version']);
2674 * Test the api_ff_ids() function.
2677 public function testApiFfIds()
2679 $result = api_ff_ids('json');
2680 $this->assertNull($result);
2684 * Test the api_ff_ids() function with a result.
2687 public function testApiFfIdsWithResult()
2689 $this->markTestIncomplete();
2693 * Test the api_ff_ids() function without an authenticated user.
2695 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2697 public function testApiFfIdsWithoutAuthenticatedUser()
2699 $_SESSION['authenticated'] = false;
2704 * Test the api_friends_ids() function.
2707 public function testApiFriendsIds()
2709 $result = api_friends_ids('json');
2710 $this->assertNull($result);
2714 * Test the api_followers_ids() function.
2717 public function testApiFollowersIds()
2719 $result = api_followers_ids('json');
2720 $this->assertNull($result);
2724 * Test the api_direct_messages_new() function.
2727 public function testApiDirectMessagesNew()
2729 $result = api_direct_messages_new('json');
2730 $this->assertNull($result);
2734 * Test the api_direct_messages_new() function without an authenticated user.
2736 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2738 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2740 $_SESSION['authenticated'] = false;
2741 api_direct_messages_new('json');
2745 * Test the api_direct_messages_new() function with an user ID.
2748 public function testApiDirectMessagesNewWithUserId()
2750 $_POST['text'] = 'message_text';
2751 $_POST['user_id'] = $this->otherUser['id'];
2752 $result = api_direct_messages_new('json');
2753 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2757 * Test the api_direct_messages_new() function with a screen name.
2760 public function testApiDirectMessagesNewWithScreenName()
2762 $_POST['text'] = 'message_text';
2763 $_POST['screen_name'] = $this->friendUser['nick'];
2764 $result = api_direct_messages_new('json');
2765 $this->assertEquals(1, $result['direct_message']['id']);
2766 $this->assertContains('message_text', $result['direct_message']['text']);
2767 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2768 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2772 * Test the api_direct_messages_new() function with a title.
2775 public function testApiDirectMessagesNewWithTitle()
2777 $_POST['text'] = 'message_text';
2778 $_POST['screen_name'] = $this->friendUser['nick'];
2779 $_REQUEST['title'] = 'message_title';
2780 $result = api_direct_messages_new('json');
2781 $this->assertEquals(1, $result['direct_message']['id']);
2782 $this->assertContains('message_text', $result['direct_message']['text']);
2783 $this->assertContains('message_title', $result['direct_message']['text']);
2784 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2785 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2789 * Test the api_direct_messages_new() function with an RSS result.
2792 public function testApiDirectMessagesNewWithRss()
2794 $_POST['text'] = 'message_text';
2795 $_POST['screen_name'] = $this->friendUser['nick'];
2796 $result = api_direct_messages_new('rss');
2797 $this->assertXml($result, 'direct-messages');
2801 * Test the api_direct_messages_destroy() function.
2803 * @expectedException Friendica\Network\HTTPException\BadRequestException
2805 public function testApiDirectMessagesDestroy()
2807 api_direct_messages_destroy('json');
2811 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2814 public function testApiDirectMessagesDestroyWithVerbose()
2816 $_GET['friendica_verbose'] = 'true';
2817 $result = api_direct_messages_destroy('json');
2818 $this->assertEquals(
2821 'result' => 'error',
2822 'message' => 'message id or parenturi not specified'
2830 * Test the api_direct_messages_destroy() function without an authenticated user.
2832 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2834 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2836 $_SESSION['authenticated'] = false;
2837 api_direct_messages_destroy('json');
2841 * Test the api_direct_messages_destroy() function with a non-zero ID.
2843 * @expectedException Friendica\Network\HTTPException\BadRequestException
2845 public function testApiDirectMessagesDestroyWithId()
2847 $_REQUEST['id'] = 1;
2848 api_direct_messages_destroy('json');
2852 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2855 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2857 $_REQUEST['id'] = 1;
2858 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2859 $_GET['friendica_verbose'] = 'true';
2860 $result = api_direct_messages_destroy('json');
2861 $this->assertEquals(
2864 'result' => 'error',
2865 'message' => 'message id not in database'
2873 * Test the api_direct_messages_destroy() function with a non-zero ID.
2876 public function testApiDirectMessagesDestroyWithCorrectId()
2878 $this->markTestIncomplete('We need to add a dataset for this.');
2882 * Test the api_direct_messages_box() function.
2885 public function testApiDirectMessagesBoxWithSentbox()
2887 $_REQUEST['page'] = -1;
2888 $_REQUEST['max_id'] = 10;
2889 $result = api_direct_messages_box('json', 'sentbox', 'false');
2890 $this->assertArrayHasKey('direct_message', $result);
2894 * Test the api_direct_messages_box() function.
2897 public function testApiDirectMessagesBoxWithConversation()
2899 $result = api_direct_messages_box('json', 'conversation', 'false');
2900 $this->assertArrayHasKey('direct_message', $result);
2904 * Test the api_direct_messages_box() function.
2907 public function testApiDirectMessagesBoxWithAll()
2909 $result = api_direct_messages_box('json', 'all', 'false');
2910 $this->assertArrayHasKey('direct_message', $result);
2914 * Test the api_direct_messages_box() function.
2917 public function testApiDirectMessagesBoxWithInbox()
2919 $result = api_direct_messages_box('json', 'inbox', 'false');
2920 $this->assertArrayHasKey('direct_message', $result);
2924 * Test the api_direct_messages_box() function.
2927 public function testApiDirectMessagesBoxWithVerbose()
2929 $result = api_direct_messages_box('json', 'sentbox', 'true');
2930 $this->assertEquals(
2933 'result' => 'error',
2934 'message' => 'no mails available'
2942 * Test the api_direct_messages_box() function with a RSS result.
2945 public function testApiDirectMessagesBoxWithRss()
2947 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2948 $this->assertXml($result, 'direct-messages');
2952 * Test the api_direct_messages_box() function without an authenticated user.
2954 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2956 public function testApiDirectMessagesBoxWithUnallowedUser()
2958 $_SESSION['allow_api'] = false;
2959 $_GET['screen_name'] = $this->selfUser['nick'];
2960 api_direct_messages_box('json', 'sentbox', 'false');
2964 * Test the api_direct_messages_sentbox() function.
2967 public function testApiDirectMessagesSentbox()
2969 $result = api_direct_messages_sentbox('json');
2970 $this->assertArrayHasKey('direct_message', $result);
2974 * Test the api_direct_messages_inbox() function.
2977 public function testApiDirectMessagesInbox()
2979 $result = api_direct_messages_inbox('json');
2980 $this->assertArrayHasKey('direct_message', $result);
2984 * Test the api_direct_messages_all() function.
2987 public function testApiDirectMessagesAll()
2989 $result = api_direct_messages_all('json');
2990 $this->assertArrayHasKey('direct_message', $result);
2994 * Test the api_direct_messages_conversation() function.
2997 public function testApiDirectMessagesConversation()
2999 $result = api_direct_messages_conversation('json');
3000 $this->assertArrayHasKey('direct_message', $result);
3004 * Test the api_oauth_request_token() function.
3007 public function testApiOauthRequestToken()
3009 $this->markTestIncomplete('killme() kills phpunit as well');
3013 * Test the api_oauth_access_token() function.
3016 public function testApiOauthAccessToken()
3018 $this->markTestIncomplete('killme() kills phpunit as well');
3022 * Test the api_fr_photoalbum_delete() function.
3024 * @expectedException Friendica\Network\HTTPException\BadRequestException
3026 public function testApiFrPhotoalbumDelete()
3028 api_fr_photoalbum_delete('json');
3032 * Test the api_fr_photoalbum_delete() function with an album name.
3034 * @expectedException Friendica\Network\HTTPException\BadRequestException
3036 public function testApiFrPhotoalbumDeleteWithAlbum()
3038 $_REQUEST['album'] = 'album_name';
3039 api_fr_photoalbum_delete('json');
3043 * Test the api_fr_photoalbum_delete() function with an album name.
3046 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3048 $this->markTestIncomplete('We need to add a dataset for this.');
3052 * Test the api_fr_photoalbum_delete() function.
3054 * @expectedException Friendica\Network\HTTPException\BadRequestException
3056 public function testApiFrPhotoalbumUpdate()
3058 api_fr_photoalbum_update('json');
3062 * Test the api_fr_photoalbum_delete() function with an album name.
3064 * @expectedException Friendica\Network\HTTPException\BadRequestException
3066 public function testApiFrPhotoalbumUpdateWithAlbum()
3068 $_REQUEST['album'] = 'album_name';
3069 api_fr_photoalbum_update('json');
3073 * Test the api_fr_photoalbum_delete() function with an album name.
3075 * @expectedException Friendica\Network\HTTPException\BadRequestException
3077 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3079 $_REQUEST['album'] = 'album_name';
3080 $_REQUEST['album_new'] = 'album_name';
3081 api_fr_photoalbum_update('json');
3085 * Test the api_fr_photoalbum_update() function without an authenticated user.
3087 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3089 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3091 $_SESSION['authenticated'] = false;
3092 api_fr_photoalbum_update('json');
3096 * Test the api_fr_photoalbum_delete() function with an album name.
3099 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3101 $this->markTestIncomplete('We need to add a dataset for this.');
3105 * Test the api_fr_photos_list() function.
3108 public function testApiFrPhotosList()
3110 $result = api_fr_photos_list('json');
3111 $this->assertArrayHasKey('photo', $result);
3115 * Test the api_fr_photos_list() function without an authenticated user.
3117 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3119 public function testApiFrPhotosListWithoutAuthenticatedUser()
3121 $_SESSION['authenticated'] = false;
3122 api_fr_photos_list('json');
3126 * Test the api_fr_photo_create_update() function.
3128 * @expectedException Friendica\Network\HTTPException\BadRequestException
3130 public function testApiFrPhotoCreateUpdate()
3132 api_fr_photo_create_update('json');
3136 * Test the api_fr_photo_create_update() function without an authenticated user.
3138 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3140 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3142 $_SESSION['authenticated'] = false;
3143 api_fr_photo_create_update('json');
3147 * Test the api_fr_photo_create_update() function with an album name.
3149 * @expectedException Friendica\Network\HTTPException\BadRequestException
3151 public function testApiFrPhotoCreateUpdateWithAlbum()
3153 $_REQUEST['album'] = 'album_name';
3154 api_fr_photo_create_update('json');
3158 * Test the api_fr_photo_create_update() function with the update mode.
3161 public function testApiFrPhotoCreateUpdateWithUpdate()
3163 $this->markTestIncomplete('We need to create a dataset for this');
3167 * Test the api_fr_photo_create_update() function with an uploaded file.
3170 public function testApiFrPhotoCreateUpdateWithFile()
3172 $this->markTestIncomplete();
3176 * Test the api_fr_photo_delete() function.
3178 * @expectedException Friendica\Network\HTTPException\BadRequestException
3180 public function testApiFrPhotoDelete()
3182 api_fr_photo_delete('json');
3186 * Test the api_fr_photo_delete() function without an authenticated user.
3188 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3190 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3192 $_SESSION['authenticated'] = false;
3193 api_fr_photo_delete('json');
3197 * Test the api_fr_photo_delete() function with a photo ID.
3199 * @expectedException Friendica\Network\HTTPException\BadRequestException
3201 public function testApiFrPhotoDeleteWithPhotoId()
3203 $_REQUEST['photo_id'] = 1;
3204 api_fr_photo_delete('json');
3208 * Test the api_fr_photo_delete() function with a correct photo ID.
3211 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3213 $this->markTestIncomplete('We need to create a dataset for this.');
3217 * Test the api_fr_photo_detail() function.
3219 * @expectedException Friendica\Network\HTTPException\BadRequestException
3221 public function testApiFrPhotoDetail()
3223 api_fr_photo_detail('json');
3227 * Test the api_fr_photo_detail() function without an authenticated user.
3229 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3231 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3233 $_SESSION['authenticated'] = false;
3234 api_fr_photo_detail('json');
3238 * Test the api_fr_photo_detail() function with a photo ID.
3240 * @expectedException Friendica\Network\HTTPException\NotFoundException
3242 public function testApiFrPhotoDetailWithPhotoId()
3244 $_REQUEST['photo_id'] = 1;
3245 api_fr_photo_detail('json');
3249 * Test the api_fr_photo_detail() function with a correct photo ID.
3252 public function testApiFrPhotoDetailCorrectPhotoId()
3254 $this->markTestIncomplete('We need to create a dataset for this.');
3258 * Test the api_account_update_profile_image() function.
3260 * @expectedException Friendica\Network\HTTPException\BadRequestException
3262 public function testApiAccountUpdateProfileImage()
3264 api_account_update_profile_image('json');
3268 * Test the api_account_update_profile_image() function without an authenticated user.
3270 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3272 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3274 $_SESSION['authenticated'] = false;
3275 api_account_update_profile_image('json');
3279 * Test the api_account_update_profile_image() function with an uploaded file.
3281 * @expectedException Friendica\Network\HTTPException\BadRequestException
3283 public function testApiAccountUpdateProfileImageWithUpload()
3285 $this->markTestIncomplete();
3290 * Test the api_account_update_profile() function.
3293 public function testApiAccountUpdateProfile()
3295 $_POST['name'] = 'new_name';
3296 $_POST['description'] = 'new_description';
3297 $result = api_account_update_profile('json');
3298 // We can't use assertSelfUser() here because the user object is missing some properties.
3299 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3300 $this->assertEquals('DFRN', $result['user']['location']);
3301 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3302 $this->assertEquals('dfrn', $result['user']['network']);
3303 $this->assertEquals('new_name', $result['user']['name']);
3304 $this->assertEquals('new_description', $result['user']['description']);
3308 * Test the check_acl_input() function.
3311 public function testCheckAclInput()
3313 $result = check_acl_input('<aclstring>');
3314 // Where does this result come from?
3315 $this->assertEquals(1, $result);
3319 * Test the check_acl_input() function with an empty ACL string.
3322 public function testCheckAclInputWithEmptyAclString()
3324 $result = check_acl_input(' ');
3325 $this->assertFalse($result);
3329 * Test the save_media_to_database() function.
3332 public function testSaveMediaToDatabase()
3334 $this->markTestIncomplete();
3338 * Test the post_photo_item() function.
3341 public function testPostPhotoItem()
3343 $this->markTestIncomplete();
3347 * Test the prepare_photo_data() function.
3350 public function testPreparePhotoData()
3352 $this->markTestIncomplete();
3356 * Test the api_friendica_remoteauth() function.
3358 * @expectedException Friendica\Network\HTTPException\BadRequestException
3360 public function testApiFriendicaRemoteauth()
3362 api_friendica_remoteauth();
3366 * Test the api_friendica_remoteauth() function with an URL.
3368 * @expectedException Friendica\Network\HTTPException\BadRequestException
3370 public function testApiFriendicaRemoteauthWithUrl()
3372 $_GET['url'] = 'url';
3373 $_GET['c_url'] = 'url';
3374 api_friendica_remoteauth();
3378 * Test the api_friendica_remoteauth() function with a correct URL.
3381 public function testApiFriendicaRemoteauthWithCorrectUrl()
3383 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3384 $_GET['url'] = 'url';
3385 $_GET['c_url'] = $this->selfUser['nurl'];
3386 api_friendica_remoteauth();
3390 * Test the api_share_as_retweet() function.
3393 public function testApiShareAsRetweet()
3395 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3396 $result = api_share_as_retweet($item);
3397 $this->assertFalse($result);
3401 * Test the api_share_as_retweet() function with a valid item.
3404 public function testApiShareAsRetweetWithValidItem()
3406 $this->markTestIncomplete();
3410 * Test the api_get_nick() function.
3413 public function testApiGetNick()
3415 $result = api_get_nick($this->otherUser['nurl']);
3416 $this->assertEquals('othercontact', $result);
3420 * Test the api_get_nick() function with a wrong URL.
3423 public function testApiGetNickWithWrongUrl()
3425 $result = api_get_nick('wrong_url');
3426 $this->assertFalse($result);
3430 * Test the api_in_reply_to() function.
3433 public function testApiInReplyTo()
3435 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3436 $this->assertArrayHasKey('status_id', $result);
3437 $this->assertArrayHasKey('user_id', $result);
3438 $this->assertArrayHasKey('status_id_str', $result);
3439 $this->assertArrayHasKey('user_id_str', $result);
3440 $this->assertArrayHasKey('screen_name', $result);
3444 * Test the api_in_reply_to() function with a valid item.
3447 public function testApiInReplyToWithValidItem()
3449 $this->markTestIncomplete();
3453 * Test the api_clean_plain_items() function.
3456 public function testApiCleanPlainItems()
3458 $_REQUEST['include_entities'] = 'true';
3459 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3460 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3464 * Test the api_clean_attachments() function.
3467 public function testApiCleanAttachments()
3469 $this->markTestIncomplete();
3473 * Test the api_best_nickname() function.
3476 public function testApiBestNickname()
3479 $result = api_best_nickname($contacts);
3480 $this->assertNull($result);
3484 * Test the api_best_nickname() function with contacts.
3487 public function testApiBestNicknameWithContacts()
3489 $this->markTestIncomplete();
3493 * Test the api_friendica_group_show() function.
3496 public function testApiFriendicaGroupShow()
3498 $this->markTestIncomplete();
3502 * Test the api_friendica_group_delete() function.
3505 public function testApiFriendicaGroupDelete()
3507 $this->markTestIncomplete();
3511 * Test the api_lists_destroy() function.
3514 public function testApiListsDestroy()
3516 $this->markTestIncomplete();
3520 * Test the group_create() function.
3523 public function testGroupCreate()
3525 $this->markTestIncomplete();
3529 * Test the api_friendica_group_create() function.
3532 public function testApiFriendicaGroupCreate()
3534 $this->markTestIncomplete();
3538 * Test the api_lists_create() function.
3541 public function testApiListsCreate()
3543 $this->markTestIncomplete();
3547 * Test the api_friendica_group_update() function.
3550 public function testApiFriendicaGroupUpdate()
3552 $this->markTestIncomplete();
3556 * Test the api_lists_update() function.
3559 public function testApiListsUpdate()
3561 $this->markTestIncomplete();
3565 * Test the api_friendica_activity() function.
3568 public function testApiFriendicaActivity()
3570 $this->markTestIncomplete();
3574 * Test the api_friendica_notification() function.
3576 * @expectedException Friendica\Network\HTTPException\BadRequestException
3578 public function testApiFriendicaNotification()
3580 api_friendica_notification('json');
3584 * Test the api_friendica_notification() function without an authenticated user.
3586 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3588 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3590 $_SESSION['authenticated'] = false;
3591 api_friendica_notification('json');
3595 * Test the api_friendica_notification() function with an argument count.
3598 public function testApiFriendicaNotificationWithArgumentCount()
3600 $this->app->argv = ['api', 'friendica', 'notification'];
3601 $this->app->argc = count($this->app->argv);
3602 $result = api_friendica_notification('json');
3603 $this->assertEquals(['note' => false], $result);
3607 * Test the api_friendica_notification() function with an XML result.
3610 public function testApiFriendicaNotificationWithXmlResult()
3612 $this->app->argv = ['api', 'friendica', 'notification'];
3613 $this->app->argc = count($this->app->argv);
3614 $result = api_friendica_notification('xml');
3615 $this->assertXml($result, 'notes');
3619 * Test the api_friendica_notification_seen() function.
3622 public function testApiFriendicaNotificationSeen()
3624 $this->markTestIncomplete();
3628 * Test the api_friendica_direct_messages_setseen() function.
3631 public function testApiFriendicaDirectMessagesSetseen()
3633 $this->markTestIncomplete();
3637 * Test the api_friendica_direct_messages_search() function.
3640 public function testApiFriendicaDirectMessagesSearch()
3642 $this->markTestIncomplete();
3646 * Test the api_friendica_profile_show() function.
3649 public function testApiFriendicaProfileShow()
3651 $result = api_friendica_profile_show('json');
3652 // We can't use assertSelfUser() here because the user object is missing some properties.
3653 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3654 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3655 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3656 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3657 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3658 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3659 $this->assertFalse($result['$result']['multi_profiles']);
3663 * Test the api_friendica_profile_show() function with a profile ID.
3666 public function testApiFriendicaProfileShowWithProfileId()
3668 $this->markTestIncomplete('We need to add a dataset for this.');
3672 * Test the api_friendica_profile_show() function with a wrong profile ID.
3674 * @expectedException Friendica\Network\HTTPException\BadRequestException
3676 public function testApiFriendicaProfileShowWithWrongProfileId()
3678 $_REQUEST['profile_id'] = 666;
3679 api_friendica_profile_show('json');
3683 * Test the api_friendica_profile_show() function without an authenticated user.
3685 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3687 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3689 $_SESSION['authenticated'] = false;
3690 api_friendica_profile_show('json');
3694 * Test the api_saved_searches_list() function.
3697 public function testApiSavedSearchesList()
3699 $result = api_saved_searches_list('json');
3700 $this->assertEquals(1, $result['terms'][0]['id']);
3701 $this->assertEquals(1, $result['terms'][0]['id_str']);
3702 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3703 $this->assertEquals('Saved search', $result['terms'][0]['query']);