6 namespace Friendica\Test;
8 use Friendica\BaseObject;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Network\HTTPException;
16 * Tests for the API functions.
18 * Functions that use header() need to be tested in a separate process.
19 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
21 class ApiTest extends DatabaseTest
25 * Create variables used by tests.
27 public function setUp()
31 require_once __DIR__.'/../include/api.php';
33 // User data that the test database is populated with
36 'name' => 'Self contact',
37 'nick' => 'selfcontact',
38 'nurl' => 'http://localhost/profile/selfcontact'
42 'name' => 'Friend contact',
43 'nick' => 'friendcontact',
44 'nurl' => 'http://localhost/profile/friendcontact'
48 'name' => 'othercontact',
49 'nick' => 'othercontact',
50 'nurl' => 'http://localhost/profile/othercontact'
53 // User ID that we know is not in the database
54 $this->wrongUserId = 666;
56 // Most API require login so we force the session
59 'authenticated' => true,
60 'uid' => $this->selfUser['id']
64 Config::set('config', 'hostname', 'localhost');
65 Config::set('system', 'throttle_limit_day', 100);
66 Config::set('system', 'throttle_limit_week', 100);
67 Config::set('system', 'throttle_limit_month', 100);
68 Config::set('system', 'theme', 'system_theme');
72 * Cleanup variables used by tests.
74 protected function tearDown()
80 $app->argv = ['home'];
84 * Assert that an user array contains expected keys.
85 * @param array $user User array
88 private function assertSelfUser(array $user)
90 $this->assertEquals($this->selfUser['id'], $user['uid']);
91 $this->assertEquals($this->selfUser['id'], $user['cid']);
92 $this->assertEquals(1, $user['self']);
93 $this->assertEquals('Friendica', $user['location']);
94 $this->assertEquals($this->selfUser['name'], $user['name']);
95 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
96 $this->assertEquals('dfrn', $user['network']);
97 $this->assertTrue($user['verified']);
101 * Assert that an user array contains expected keys.
102 * @param array $user User array
105 private function assertOtherUser(array $user)
107 $this->assertEquals($this->otherUser['id'], $user['id']);
108 $this->assertEquals($this->otherUser['id'], $user['id_str']);
109 $this->assertEquals(0, $user['self']);
110 $this->assertEquals($this->otherUser['name'], $user['name']);
111 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
112 $this->assertFalse($user['verified']);
116 * Assert that a status array contains expected keys.
117 * @param array $status Status array
120 private function assertStatus(array $status)
122 $this->assertInternalType('string', $status['text']);
123 $this->assertInternalType('int', $status['id']);
124 // We could probably do more checks here.
128 * Assert that a list array contains expected keys.
129 * @param array $list List array
132 private function assertList(array $list)
134 $this->assertInternalType('string', $list['name']);
135 $this->assertInternalType('int', $list['id']);
136 $this->assertInternalType('string', $list['id_str']);
137 $this->assertContains($list['mode'], ['public', 'private']);
138 // We could probably do more checks here.
142 * Assert that the string is XML and contain the root element.
143 * @param string $result XML string
144 * @param string $root_element Root element name
147 private function assertXml($result, $root_element)
149 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
150 $this->assertContains('<'.$root_element, $result);
151 // We could probably do more checks here.
155 * Get the path to a temporary empty PNG image.
156 * @return string Path
158 private function getTempImage()
160 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
164 // Empty 1x1 px PNG image
165 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
173 * Test the api_user() function.
176 public function testApiUser()
178 $this->assertEquals($this->selfUser['id'], api_user());
182 * Test the api_user() function with an unallowed user.
185 public function testApiUserWithUnallowedUser()
187 $_SESSION = ['allow_api' => false];
188 $this->assertEquals(false, api_user());
192 * Test the api_source() function.
195 public function testApiSource()
197 $this->assertEquals('api', api_source());
201 * Test the api_source() function with a Twidere user agent.
204 public function testApiSourceWithTwidere()
206 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
207 $this->assertEquals('Twidere', api_source());
211 * Test the api_source() function with a GET parameter.
214 public function testApiSourceWithGet()
216 $_GET['source'] = 'source_name';
217 $this->assertEquals('source_name', api_source());
221 * Test the api_date() function.
224 public function testApiDate()
226 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
230 * Test the api_register_func() function.
233 public function testApiRegisterFunc()
245 $this->assertTrue($API['api_path']['auth']);
246 $this->assertEquals('method', $API['api_path']['method']);
247 $this->assertTrue(is_callable($API['api_path']['func']));
251 * Test the api_login() function without any login.
253 * @runInSeparateProcess
254 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
256 public function testApiLoginWithoutLogin()
258 api_login($this->app);
262 * Test the api_login() function with a bad login.
264 * @runInSeparateProcess
265 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
267 public function testApiLoginWithBadLogin()
269 $_SERVER['PHP_AUTH_USER'] = 'user@server';
270 api_login($this->app);
274 * Test the api_login() function with oAuth.
277 public function testApiLoginWithOauth()
279 $this->markTestIncomplete('Can we test this easily?');
283 * Test the api_login() function with authentication provided by an addon.
286 public function testApiLoginWithAddonAuth()
288 $this->markTestIncomplete('Can we test this easily?');
292 * Test the api_login() function with a correct login.
294 * @runInSeparateProcess
296 public function testApiLoginWithCorrectLogin()
298 $_SERVER['PHP_AUTH_USER'] = 'Test user';
299 $_SERVER['PHP_AUTH_PW'] = 'password';
300 api_login($this->app);
304 * Test the api_login() function with a remote user.
306 * @runInSeparateProcess
307 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
309 public function testApiLoginWithRemoteUser()
311 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
312 api_login($this->app);
316 * Test the api_check_method() function.
319 public function testApiCheckMethod()
321 $this->assertFalse(api_check_method('method'));
325 * Test the api_check_method() function with a correct method.
328 public function testApiCheckMethodWithCorrectMethod()
330 $_SERVER['REQUEST_METHOD'] = 'method';
331 $this->assertTrue(api_check_method('method'));
335 * Test the api_check_method() function with a wildcard.
338 public function testApiCheckMethodWithWildcard()
340 $this->assertTrue(api_check_method('*'));
344 * Test the api_call() function.
346 * @runInSeparateProcess
348 public function testApiCall()
352 'method' => 'method',
353 'func' => function () {
354 return ['data' => ['some_data']];
357 $_SERVER['REQUEST_METHOD'] = 'method';
358 $_GET['callback'] = 'callback_name';
360 $this->app->query_string = 'api_path';
362 'callback_name(["some_data"])',
368 * Test the api_call() function with the profiled enabled.
370 * @runInSeparateProcess
372 public function testApiCallWithProfiler()
376 'method' => 'method',
377 'func' => function () {
378 return ['data' => ['some_data']];
381 $_SERVER['REQUEST_METHOD'] = 'method';
382 Config::set('system', 'profiler', true);
383 Config::set('rendertime', 'callstack', true);
384 $this->app->callstack = [
385 'database' => ['some_function' => 200],
386 'database_write' => ['some_function' => 200],
387 'cache' => ['some_function' => 200],
388 'cache_write' => ['some_function' => 200],
389 'network' => ['some_function' => 200]
392 $this->app->query_string = 'api_path';
400 * Test the api_call() function without any result.
402 * @runInSeparateProcess
404 public function testApiCallWithNoResult()
408 'method' => 'method',
409 'func' => function () {
413 $_SERVER['REQUEST_METHOD'] = 'method';
415 $this->app->query_string = 'api_path';
417 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
423 * Test the api_call() function with an unimplemented API.
425 * @runInSeparateProcess
427 public function testApiCallWithUninplementedApi()
430 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
436 * Test the api_call() function with a JSON result.
438 * @runInSeparateProcess
440 public function testApiCallWithJson()
444 'method' => 'method',
445 'func' => function () {
446 return ['data' => ['some_data']];
449 $_SERVER['REQUEST_METHOD'] = 'method';
451 $this->app->query_string = 'api_path.json';
459 * Test the api_call() function with an XML result.
461 * @runInSeparateProcess
463 public function testApiCallWithXml()
467 'method' => 'method',
468 'func' => function () {
472 $_SERVER['REQUEST_METHOD'] = 'method';
474 $this->app->query_string = 'api_path.xml';
482 * Test the api_call() function with an RSS result.
484 * @runInSeparateProcess
486 public function testApiCallWithRss()
490 'method' => 'method',
491 'func' => function () {
495 $_SERVER['REQUEST_METHOD'] = 'method';
497 $this->app->query_string = 'api_path.rss';
499 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
506 * Test the api_call() function with an Atom result.
508 * @runInSeparateProcess
510 public function testApiCallWithAtom()
514 'method' => 'method',
515 'func' => function () {
519 $_SERVER['REQUEST_METHOD'] = 'method';
521 $this->app->query_string = 'api_path.atom';
523 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
530 * Test the api_call() function with an unallowed method.
532 * @runInSeparateProcess
534 public function testApiCallWithWrongMethod()
537 $API['api_path'] = ['method' => 'method'];
539 $this->app->query_string = 'api_path';
541 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
547 * Test the api_call() function with an unauthorized user.
549 * @runInSeparateProcess
551 public function testApiCallWithWrongAuth()
555 'method' => 'method',
558 $_SERVER['REQUEST_METHOD'] = 'method';
559 $_SESSION['authenticated'] = false;
561 $this->app->query_string = 'api_path';
563 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
569 * Test the api_error() function with a JSON result.
571 * @runInSeparateProcess
573 public function testApiErrorWithJson()
576 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
577 api_error('json', new HTTPException('error_message'))
582 * Test the api_error() function with an XML result.
584 * @runInSeparateProcess
586 public function testApiErrorWithXml()
589 '<?xml version="1.0"?>'."\n".
590 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
591 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
592 'xmlns:georss="http://www.georss.org/georss">'."\n".
593 ' <error>error_message</error>'."\n".
594 ' <code>200 Friendica\Network\HTTP</code>'."\n".
597 api_error('xml', new HTTPException('error_message'))
602 * Test the api_error() function with an RSS result.
604 * @runInSeparateProcess
606 public function testApiErrorWithRss()
609 '<?xml version="1.0"?>'."\n".
610 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
611 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
612 'xmlns:georss="http://www.georss.org/georss">'."\n".
613 ' <error>error_message</error>'."\n".
614 ' <code>200 Friendica\Network\HTTP</code>'."\n".
617 api_error('rss', new HTTPException('error_message'))
622 * Test the api_error() function with an Atom result.
624 * @runInSeparateProcess
626 public function testApiErrorWithAtom()
629 '<?xml version="1.0"?>'."\n".
630 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
631 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
632 'xmlns:georss="http://www.georss.org/georss">'."\n".
633 ' <error>error_message</error>'."\n".
634 ' <code>200 Friendica\Network\HTTP</code>'."\n".
637 api_error('atom', new HTTPException('error_message'))
642 * Test the api_rss_extra() function.
645 public function testApiRssExtra()
647 $user_info = ['url' => 'user_url', 'lang' => 'en'];
648 $result = api_rss_extra($this->app, [], $user_info);
649 $this->assertEquals($user_info, $result['$user']);
650 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
651 $this->assertArrayHasKey('self', $result['$rss']);
652 $this->assertArrayHasKey('base', $result['$rss']);
653 $this->assertArrayHasKey('updated', $result['$rss']);
654 $this->assertArrayHasKey('atom_updated', $result['$rss']);
655 $this->assertArrayHasKey('language', $result['$rss']);
656 $this->assertArrayHasKey('logo', $result['$rss']);
660 * Test the api_rss_extra() function without any user info.
662 * @runInSeparateProcess
664 public function testApiRssExtraWithoutUserInfo()
666 $result = api_rss_extra($this->app, [], null);
667 $this->assertInternalType('array', $result['$user']);
668 $this->assertArrayHasKey('alternate', $result['$rss']);
669 $this->assertArrayHasKey('self', $result['$rss']);
670 $this->assertArrayHasKey('base', $result['$rss']);
671 $this->assertArrayHasKey('updated', $result['$rss']);
672 $this->assertArrayHasKey('atom_updated', $result['$rss']);
673 $this->assertArrayHasKey('language', $result['$rss']);
674 $this->assertArrayHasKey('logo', $result['$rss']);
678 * Test the api_unique_id_to_nurl() function.
681 public function testApiUniqueIdToNurl()
683 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
687 * Test the api_unique_id_to_nurl() function with a correct ID.
690 public function testApiUniqueIdToNurlWithCorrectId()
692 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
696 * Test the api_get_user() function.
698 * @runInSeparateProcess
700 public function testApiGetUser()
702 $user = api_get_user($this->app);
703 $this->assertSelfUser($user);
704 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
705 $this->assertEquals('6fdbe8', $user['profile_link_color']);
706 $this->assertEquals('ededed', $user['profile_background_color']);
710 * Test the api_get_user() function with a Frio schema.
712 * @runInSeparateProcess
714 public function testApiGetUserWithFrioSchema()
716 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
717 $user = api_get_user($this->app);
718 $this->assertSelfUser($user);
719 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
720 $this->assertEquals('6fdbe8', $user['profile_link_color']);
721 $this->assertEquals('ededed', $user['profile_background_color']);
725 * Test the api_get_user() function with a custom Frio schema.
727 * @runInSeparateProcess
729 public function testApiGetUserWithCustomFrioSchema()
731 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
732 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
733 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
734 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
735 $user = api_get_user($this->app);
736 $this->assertSelfUser($user);
737 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
738 $this->assertEquals('123456', $user['profile_link_color']);
739 $this->assertEquals('123456', $user['profile_background_color']);
743 * Test the api_get_user() function with an empty Frio schema.
745 * @runInSeparateProcess
747 public function testApiGetUserWithEmptyFrioSchema()
749 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
750 $user = api_get_user($this->app);
751 $this->assertSelfUser($user);
752 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
753 $this->assertEquals('6fdbe8', $user['profile_link_color']);
754 $this->assertEquals('ededed', $user['profile_background_color']);
758 * Test the api_get_user() function with an user that is not allowed to use the API.
760 * @runInSeparateProcess
762 public function testApiGetUserWithoutApiUser()
764 $_SERVER['PHP_AUTH_USER'] = 'Test user';
765 $_SERVER['PHP_AUTH_PW'] = 'password';
766 $_SESSION['allow_api'] = false;
767 $this->assertFalse(api_get_user($this->app));
771 * Test the api_get_user() function with an user ID in a GET parameter.
773 * @runInSeparateProcess
775 public function testApiGetUserWithGetId()
777 $_GET['user_id'] = $this->otherUser['id'];
778 $this->assertOtherUser(api_get_user($this->app));
782 * Test the api_get_user() function with a wrong user ID in a GET parameter.
784 * @runInSeparateProcess
785 * @expectedException Friendica\Network\HTTPException\BadRequestException
787 public function testApiGetUserWithWrongGetId()
789 $_GET['user_id'] = $this->wrongUserId;
790 $this->assertOtherUser(api_get_user($this->app));
794 * Test the api_get_user() function with an user name in a GET parameter.
796 * @runInSeparateProcess
798 public function testApiGetUserWithGetName()
800 $_GET['screen_name'] = $this->selfUser['nick'];
801 $this->assertSelfUser(api_get_user($this->app));
805 * Test the api_get_user() function with a profile URL in a GET parameter.
807 * @runInSeparateProcess
809 public function testApiGetUserWithGetUrl()
811 $_GET['profileurl'] = $this->selfUser['nurl'];
812 $this->assertSelfUser(api_get_user($this->app));
816 * Test the api_get_user() function with an user ID in the API path.
818 * @runInSeparateProcess
820 public function testApiGetUserWithNumericCalledApi()
823 $called_api = ['api_path'];
824 $this->app->argv[1] = $this->otherUser['id'].'.json';
825 $this->assertOtherUser(api_get_user($this->app));
829 * Test the api_get_user() function with the $called_api global variable.
831 * @runInSeparateProcess
833 public function testApiGetUserWithCalledApi()
836 $called_api = ['api', 'api_path'];
837 $this->assertSelfUser(api_get_user($this->app));
841 * Test the api_get_user() function with a valid user.
843 * @runInSeparateProcess
845 public function testApiGetUserWithCorrectUser()
847 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
851 * Test the api_get_user() function with a wrong user ID.
853 * @runInSeparateProcess
854 * @expectedException Friendica\Network\HTTPException\BadRequestException
856 public function testApiGetUserWithWrongUser()
858 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
862 * Test the api_get_user() function with a 0 user ID.
864 * @runInSeparateProcess
866 public function testApiGetUserWithZeroUser()
868 $this->assertSelfUser(api_get_user($this->app, 0));
872 * Test the api_item_get_user() function.
874 * @runInSeparateProcess
876 public function testApiItemGetUser()
878 $users = api_item_get_user($this->app, []);
879 $this->assertSelfUser($users[0]);
883 * Test the api_item_get_user() function with a different item parent.
886 public function testApiItemGetUserWithDifferentParent()
888 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
889 $this->assertSelfUser($users[0]);
890 $this->assertEquals($users[0], $users[1]);
894 * Test the api_walk_recursive() function.
897 public function testApiWalkRecursive()
905 // Should we test this with a callback that actually does something?
913 * Test the api_walk_recursive() function with an array.
916 public function testApiWalkRecursiveWithArray()
918 $array = [['item1'], ['item2']];
924 // Should we test this with a callback that actually does something?
932 * Test the api_reformat_xml() function.
935 public function testApiReformatXml()
939 $this->assertTrue(api_reformat_xml($item, $key));
940 $this->assertEquals('true', $item);
944 * Test the api_reformat_xml() function with a statusnet_api key.
947 public function testApiReformatXmlWithStatusnetKey()
950 $key = 'statusnet_api';
951 $this->assertTrue(api_reformat_xml($item, $key));
952 $this->assertEquals('statusnet:api', $key);
956 * Test the api_reformat_xml() function with a friendica_api key.
959 public function testApiReformatXmlWithFriendicaKey()
962 $key = 'friendica_api';
963 $this->assertTrue(api_reformat_xml($item, $key));
964 $this->assertEquals('friendica:api', $key);
968 * Test the api_create_xml() function.
971 public function testApiCreateXml()
974 '<?xml version="1.0"?>'."\n".
975 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
976 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
977 'xmlns:georss="http://www.georss.org/georss">'."\n".
978 ' <data>some_data</data>'."\n".
979 '</root_element>'."\n",
980 api_create_xml(['data' => ['some_data']], 'root_element')
985 * Test the api_create_xml() function without any XML namespace.
988 public function testApiCreateXmlWithoutNamespaces()
991 '<?xml version="1.0"?>'."\n".
993 ' <data>some_data</data>'."\n".
995 api_create_xml(['data' => ['some_data']], 'ok')
1000 * Test the api_format_data() function.
1003 public function testApiFormatData()
1005 $data = ['some_data'];
1006 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1010 * Test the api_format_data() function with an XML result.
1013 public function testApiFormatDataWithXml()
1015 $this->assertEquals(
1016 '<?xml version="1.0"?>'."\n".
1017 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1018 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1019 'xmlns:georss="http://www.georss.org/georss">'."\n".
1020 ' <data>some_data</data>'."\n".
1021 '</root_element>'."\n",
1022 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1027 * Test the api_account_verify_credentials() function.
1030 public function testApiAccountVerifyCredentials()
1032 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1036 * Test the api_account_verify_credentials() function without an authenticated user.
1038 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1040 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1042 $_SESSION['authenticated'] = false;
1043 api_account_verify_credentials('json');
1047 * Test the requestdata() function.
1050 public function testRequestdata()
1052 $this->assertNull(requestdata('variable_name'));
1056 * Test the requestdata() function with a POST parameter.
1059 public function testRequestdataWithPost()
1061 $_POST['variable_name'] = 'variable_value';
1062 $this->assertEquals('variable_value', requestdata('variable_name'));
1066 * Test the requestdata() function with a GET parameter.
1069 public function testRequestdataWithGet()
1071 $_GET['variable_name'] = 'variable_value';
1072 $this->assertEquals('variable_value', requestdata('variable_name'));
1076 * Test the api_statuses_mediap() function.
1079 public function testApiStatusesMediap()
1081 $this->app->argc = 2;
1089 'tmp_name' => $this->getTempImage(),
1090 'name' => 'spacer.png',
1091 'type' => 'image/png'
1094 $_GET['status'] = '<b>Status content</b>';
1096 $result = api_statuses_mediap('json');
1097 $this->assertStatus($result['status']);
1101 * Test the api_statuses_mediap() function without an authenticated user.
1103 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1105 public function testApiStatusesMediapWithoutAuthenticatedUser()
1107 $_SESSION['authenticated'] = false;
1108 api_statuses_mediap('json');
1112 * Test the api_statuses_update() function.
1115 public function testApiStatusesUpdate()
1117 $_GET['status'] = 'Status content';
1118 $_GET['in_reply_to_status_id'] = -1;
1127 'tmp_name' => $this->getTempImage(),
1128 'name' => 'spacer.png',
1129 'type' => 'image/png'
1133 $result = api_statuses_update('json');
1134 $this->assertStatus($result['status']);
1138 * Test the api_statuses_update() function with an HTML status.
1141 public function testApiStatusesUpdateWithHtml()
1143 $_GET['htmlstatus'] = '<b>Status content</b>';
1145 $result = api_statuses_update('json');
1146 $this->assertStatus($result['status']);
1150 * Test the api_statuses_update() function without an authenticated user.
1152 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1154 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1156 $_SESSION['authenticated'] = false;
1157 api_statuses_update('json');
1161 * Test the api_statuses_update() function with a parent status.
1164 public function testApiStatusesUpdateWithParent()
1166 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1170 * Test the api_statuses_update() function with a media_ids parameter.
1173 public function testApiStatusesUpdateWithMediaIds()
1175 $this->markTestIncomplete();
1179 * Test the api_statuses_update() function with the throttle limit reached.
1182 public function testApiStatusesUpdateWithDayThrottleReached()
1184 $this->markTestIncomplete();
1188 * Test the api_media_upload() function.
1190 * @expectedException Friendica\Network\HTTPException\BadRequestException
1192 public function testApiMediaUpload()
1198 * Test the api_media_upload() function without an authenticated user.
1200 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1202 public function testApiMediaUploadWithoutAuthenticatedUser()
1204 $_SESSION['authenticated'] = false;
1209 * Test the api_media_upload() function with an invalid uploaded media.
1211 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1213 public function testApiMediaUploadWithMedia()
1218 'tmp_name' => 'tmp_name'
1225 * Test the api_media_upload() function with an valid uploaded media.
1228 public function testApiMediaUploadWithValidMedia()
1236 'tmp_name' => $this->getTempImage(),
1237 'name' => 'spacer.png',
1238 'type' => 'image/png'
1244 $result = api_media_upload();
1245 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1246 $this->assertEquals(1, $result['media']['image']['w']);
1247 $this->assertEquals(1, $result['media']['image']['h']);
1251 * Test the api_status_show() function.
1254 public function testApiStatusShow()
1256 $result = api_status_show('json');
1257 $this->assertStatus($result['status']);
1261 * Test the api_status_show() function with an XML result.
1264 public function testApiStatusShowWithXml()
1266 $result = api_status_show('xml');
1267 $this->assertXml($result, 'statuses');
1271 * Test the api_status_show() function with a raw result.
1274 public function testApiStatusShowWithRaw()
1276 $this->assertStatus(api_status_show('raw'));
1280 * Test the api_users_show() function.
1283 public function testApiUsersShow()
1285 $result = api_users_show('json');
1286 // We can't use assertSelfUser() here because the user object is missing some properties.
1287 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1288 $this->assertEquals('Friendica', $result['user']['location']);
1289 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1290 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1291 $this->assertEquals('dfrn', $result['user']['network']);
1292 $this->assertTrue($result['user']['verified']);
1296 * Test the api_users_show() function with an XML result.
1299 public function testApiUsersShowWithXml()
1301 $result = api_users_show('xml');
1302 $this->assertXml($result, 'statuses');
1306 * Test the api_users_search() function.
1309 public function testApiUsersSearch()
1311 $_GET['q'] = 'othercontact';
1312 $result = api_users_search('json');
1313 $this->assertOtherUser($result['users'][0]);
1317 * Test the api_users_search() function with an XML result.
1320 public function testApiUsersSearchWithXml()
1322 $_GET['q'] = 'othercontact';
1323 $result = api_users_search('xml');
1324 $this->assertXml($result, 'users');
1328 * Test the api_users_search() function without a GET q parameter.
1330 * @expectedException Friendica\Network\HTTPException\BadRequestException
1332 public function testApiUsersSearchWithoutQuery()
1334 api_users_search('json');
1338 * Test the api_users_lookup() function.
1340 * @expectedException Friendica\Network\HTTPException\NotFoundException
1342 public function testApiUsersLookup()
1344 api_users_lookup('json');
1348 * Test the api_users_lookup() function with an user ID.
1351 public function testApiUsersLookupWithUserId()
1353 $_REQUEST['user_id'] = $this->otherUser['id'];
1354 $result = api_users_lookup('json');
1355 $this->assertOtherUser($result['users'][0]);
1359 * Test the api_search() function.
1362 public function testApiSearch()
1364 $_REQUEST['q'] = 'reply';
1365 $_REQUEST['max_id'] = 10;
1366 $result = api_search('json');
1367 foreach ($result['status'] as $status) {
1368 $this->assertStatus($status);
1369 $this->assertContains('reply', $status['text'], null, true);
1374 * Test the api_search() function a count parameter.
1377 public function testApiSearchWithCount()
1379 $_REQUEST['q'] = 'reply';
1380 $_REQUEST['count'] = 20;
1381 $result = api_search('json');
1382 foreach ($result['status'] as $status) {
1383 $this->assertStatus($status);
1384 $this->assertContains('reply', $status['text'], null, true);
1389 * Test the api_search() function with an rpp parameter.
1392 public function testApiSearchWithRpp()
1394 $_REQUEST['q'] = 'reply';
1395 $_REQUEST['rpp'] = 20;
1396 $result = api_search('json');
1397 foreach ($result['status'] as $status) {
1398 $this->assertStatus($status);
1399 $this->assertContains('reply', $status['text'], null, true);
1405 * Test the api_search() function without an authenticated user.
1407 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1409 public function testApiSearchWithUnallowedUser()
1411 $_SESSION['allow_api'] = false;
1412 $_GET['screen_name'] = $this->selfUser['nick'];
1417 * Test the api_search() function without any GET query parameter.
1419 * @expectedException Friendica\Network\HTTPException\BadRequestException
1421 public function testApiSearchWithoutQuery()
1427 * Test the api_statuses_home_timeline() function.
1430 public function testApiStatusesHomeTimeline()
1432 $_REQUEST['max_id'] = 10;
1433 $_REQUEST['exclude_replies'] = true;
1434 $_REQUEST['conversation_id'] = 1;
1435 $result = api_statuses_home_timeline('json');
1436 $this->assertNotEmpty($result['status']);
1437 foreach ($result['status'] as $status) {
1438 $this->assertStatus($status);
1443 * Test the api_statuses_home_timeline() function with a negative page parameter.
1446 public function testApiStatusesHomeTimelineWithNegativePage()
1448 $_REQUEST['page'] = -2;
1449 $result = api_statuses_home_timeline('json');
1450 $this->assertNotEmpty($result['status']);
1451 foreach ($result['status'] as $status) {
1452 $this->assertStatus($status);
1457 * Test the api_statuses_home_timeline() with an unallowed user.
1459 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1461 public function testApiStatusesHomeTimelineWithUnallowedUser()
1463 $_SESSION['allow_api'] = false;
1464 $_GET['screen_name'] = $this->selfUser['nick'];
1465 api_statuses_home_timeline('json');
1469 * Test the api_statuses_home_timeline() function with an RSS result.
1472 public function testApiStatusesHomeTimelineWithRss()
1474 $result = api_statuses_home_timeline('rss');
1475 $this->assertXml($result, 'statuses');
1479 * Test the api_statuses_public_timeline() function.
1482 public function testApiStatusesPublicTimeline()
1484 $_REQUEST['max_id'] = 10;
1485 $_REQUEST['conversation_id'] = 1;
1486 $result = api_statuses_public_timeline('json');
1487 $this->assertNotEmpty($result['status']);
1488 foreach ($result['status'] as $status) {
1489 $this->assertStatus($status);
1494 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1497 public function testApiStatusesPublicTimelineWithExcludeReplies()
1499 $_REQUEST['max_id'] = 10;
1500 $_REQUEST['exclude_replies'] = true;
1501 $result = api_statuses_public_timeline('json');
1502 $this->assertNotEmpty($result['status']);
1503 foreach ($result['status'] as $status) {
1504 $this->assertStatus($status);
1509 * Test the api_statuses_public_timeline() function with a negative page parameter.
1512 public function testApiStatusesPublicTimelineWithNegativePage()
1514 $_REQUEST['page'] = -2;
1515 $result = api_statuses_public_timeline('json');
1516 $this->assertNotEmpty($result['status']);
1517 foreach ($result['status'] as $status) {
1518 $this->assertStatus($status);
1523 * Test the api_statuses_public_timeline() function with an unallowed user.
1525 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1527 public function testApiStatusesPublicTimelineWithUnallowedUser()
1529 $_SESSION['allow_api'] = false;
1530 $_GET['screen_name'] = $this->selfUser['nick'];
1531 api_statuses_public_timeline('json');
1535 * Test the api_statuses_public_timeline() function with an RSS result.
1538 public function testApiStatusesPublicTimelineWithRss()
1540 $result = api_statuses_public_timeline('rss');
1541 $this->assertXml($result, 'statuses');
1545 * Test the api_statuses_networkpublic_timeline() function.
1548 public function testApiStatusesNetworkpublicTimeline()
1550 $_REQUEST['max_id'] = 10;
1551 $result = api_statuses_networkpublic_timeline('json');
1552 $this->assertNotEmpty($result['status']);
1553 foreach ($result['status'] as $status) {
1554 $this->assertStatus($status);
1559 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1562 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1564 $_REQUEST['page'] = -2;
1565 $result = api_statuses_networkpublic_timeline('json');
1566 $this->assertNotEmpty($result['status']);
1567 foreach ($result['status'] as $status) {
1568 $this->assertStatus($status);
1573 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1575 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1577 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1579 $_SESSION['allow_api'] = false;
1580 $_GET['screen_name'] = $this->selfUser['nick'];
1581 api_statuses_networkpublic_timeline('json');
1585 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1588 public function testApiStatusesNetworkpublicTimelineWithRss()
1590 $result = api_statuses_networkpublic_timeline('rss');
1591 $this->assertXml($result, 'statuses');
1595 * Test the api_statuses_show() function.
1597 * @expectedException Friendica\Network\HTTPException\BadRequestException
1599 public function testApiStatusesShow()
1601 api_statuses_show('json');
1605 * Test the api_statuses_show() function with an ID.
1608 public function testApiStatusesShowWithId()
1610 $this->app->argv[3] = 1;
1611 $result = api_statuses_show('json');
1612 $this->assertStatus($result['status']);
1616 * Test the api_statuses_show() function with the conversation parameter.
1619 public function testApiStatusesShowWithConversation()
1621 $this->app->argv[3] = 1;
1622 $_REQUEST['conversation'] = 1;
1623 $result = api_statuses_show('json');
1624 $this->assertNotEmpty($result['status']);
1625 foreach ($result['status'] as $status) {
1626 $this->assertStatus($status);
1631 * Test the api_statuses_show() function with an unallowed user.
1633 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1635 public function testApiStatusesShowWithUnallowedUser()
1637 $_SESSION['allow_api'] = false;
1638 $_GET['screen_name'] = $this->selfUser['nick'];
1639 api_statuses_show('json');
1643 * Test the api_conversation_show() function.
1645 * @expectedException Friendica\Network\HTTPException\BadRequestException
1647 public function testApiConversationShow()
1649 api_conversation_show('json');
1653 * Test the api_conversation_show() function with an ID.
1656 public function testApiConversationShowWithId()
1658 $this->app->argv[3] = 1;
1659 $_REQUEST['max_id'] = 10;
1660 $_REQUEST['page'] = -2;
1661 $result = api_conversation_show('json');
1662 $this->assertNotEmpty($result['status']);
1663 foreach ($result['status'] as $status) {
1664 $this->assertStatus($status);
1669 * Test the api_conversation_show() function with an unallowed user.
1671 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1673 public function testApiConversationShowWithUnallowedUser()
1675 $_SESSION['allow_api'] = false;
1676 $_GET['screen_name'] = $this->selfUser['nick'];
1677 api_conversation_show('json');
1681 * Test the api_statuses_repeat() function.
1683 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1685 public function testApiStatusesRepeat()
1687 api_statuses_repeat('json');
1691 * Test the api_statuses_repeat() function without an authenticated user.
1693 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1695 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1697 $_SESSION['authenticated'] = false;
1698 api_statuses_repeat('json');
1702 * Test the api_statuses_repeat() function with an ID.
1705 public function testApiStatusesRepeatWithId()
1707 $this->app->argv[3] = 1;
1708 $result = api_statuses_repeat('json');
1709 $this->assertStatus($result['status']);
1711 // Also test with a shared status
1712 $this->app->argv[3] = 5;
1713 $result = api_statuses_repeat('json');
1714 $this->assertStatus($result['status']);
1718 * Test the api_statuses_destroy() function.
1720 * @expectedException Friendica\Network\HTTPException\BadRequestException
1722 public function testApiStatusesDestroy()
1724 api_statuses_destroy('json');
1728 * Test the api_statuses_destroy() function without an authenticated user.
1730 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1732 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1734 $_SESSION['authenticated'] = false;
1735 api_statuses_destroy('json');
1739 * Test the api_statuses_destroy() function with an ID.
1742 public function testApiStatusesDestroyWithId()
1744 $this->app->argv[3] = 1;
1745 $result = api_statuses_destroy('json');
1746 $this->assertStatus($result['status']);
1750 * Test the api_statuses_mentions() function.
1753 public function testApiStatusesMentions()
1755 $this->app->user = ['nickname' => $this->selfUser['nick']];
1756 $_REQUEST['max_id'] = 10;
1757 $result = api_statuses_mentions('json');
1758 $this->assertEmpty($result['status']);
1759 // We should test with mentions in the database.
1763 * Test the api_statuses_mentions() function with a negative page parameter.
1766 public function testApiStatusesMentionsWithNegativePage()
1768 $_REQUEST['page'] = -2;
1769 $result = api_statuses_mentions('json');
1770 $this->assertEmpty($result['status']);
1774 * Test the api_statuses_mentions() function with an unallowed user.
1776 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1778 public function testApiStatusesMentionsWithUnallowedUser()
1780 $_SESSION['allow_api'] = false;
1781 $_GET['screen_name'] = $this->selfUser['nick'];
1782 api_statuses_mentions('json');
1786 * Test the api_statuses_mentions() function with an RSS result.
1789 public function testApiStatusesMentionsWithRss()
1791 $result = api_statuses_mentions('rss');
1792 $this->assertXml($result, 'statuses');
1796 * Test the api_statuses_user_timeline() function.
1799 public function testApiStatusesUserTimeline()
1801 $_REQUEST['max_id'] = 10;
1802 $_REQUEST['exclude_replies'] = true;
1803 $_REQUEST['conversation_id'] = 1;
1804 $result = api_statuses_user_timeline('json');
1805 $this->assertNotEmpty($result['status']);
1806 foreach ($result['status'] as $status) {
1807 $this->assertStatus($status);
1812 * Test the api_statuses_user_timeline() function with a negative page parameter.
1815 public function testApiStatusesUserTimelineWithNegativePage()
1817 $_REQUEST['page'] = -2;
1818 $result = api_statuses_user_timeline('json');
1819 $this->assertNotEmpty($result['status']);
1820 foreach ($result['status'] as $status) {
1821 $this->assertStatus($status);
1826 * Test the api_statuses_user_timeline() function with an RSS result.
1829 public function testApiStatusesUserTimelineWithRss()
1831 $result = api_statuses_user_timeline('rss');
1832 $this->assertXml($result, 'statuses');
1836 * Test the api_statuses_user_timeline() function with an unallowed user.
1838 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1840 public function testApiStatusesUserTimelineWithUnallowedUser()
1842 $_SESSION['allow_api'] = false;
1843 $_GET['screen_name'] = $this->selfUser['nick'];
1844 api_statuses_user_timeline('json');
1848 * Test the api_favorites_create_destroy() function.
1850 * @expectedException Friendica\Network\HTTPException\BadRequestException
1852 public function testApiFavoritesCreateDestroy()
1854 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1855 $this->app->argc = count($this->app->argv);
1856 api_favorites_create_destroy('json');
1860 * Test the api_favorites_create_destroy() function with an invalid ID.
1862 * @expectedException Friendica\Network\HTTPException\BadRequestException
1864 public function testApiFavoritesCreateDestroyWithInvalidId()
1866 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1867 $this->app->argc = count($this->app->argv);
1868 api_favorites_create_destroy('json');
1872 * Test the api_favorites_create_destroy() function with an invalid action.
1874 * @expectedException Friendica\Network\HTTPException\BadRequestException
1876 public function testApiFavoritesCreateDestroyWithInvalidAction()
1878 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1879 $this->app->argc = count($this->app->argv);
1880 $_REQUEST['id'] = 1;
1881 api_favorites_create_destroy('json');
1885 * Test the api_favorites_create_destroy() function with the create action.
1888 public function testApiFavoritesCreateDestroyWithCreateAction()
1890 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1891 $this->app->argc = count($this->app->argv);
1892 $_REQUEST['id'] = 3;
1893 $result = api_favorites_create_destroy('json');
1894 $this->assertStatus($result['status']);
1898 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1901 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1903 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1904 $this->app->argc = count($this->app->argv);
1905 $_REQUEST['id'] = 3;
1906 $result = api_favorites_create_destroy('rss');
1907 $this->assertXml($result, 'status');
1911 * Test the api_favorites_create_destroy() function with the destroy action.
1914 public function testApiFavoritesCreateDestroyWithDestroyAction()
1916 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1917 $this->app->argc = count($this->app->argv);
1918 $_REQUEST['id'] = 3;
1919 $result = api_favorites_create_destroy('json');
1920 $this->assertStatus($result['status']);
1924 * Test the api_favorites_create_destroy() function without an authenticated user.
1926 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1928 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1930 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1931 $this->app->argc = count($this->app->argv);
1932 $_SESSION['authenticated'] = false;
1933 api_favorites_create_destroy('json');
1937 * Test the api_favorites() function.
1940 public function testApiFavorites()
1942 $_REQUEST['page'] = -1;
1943 $_REQUEST['max_id'] = 10;
1944 $result = api_favorites('json');
1945 foreach ($result['status'] as $status) {
1946 $this->assertStatus($status);
1951 * Test the api_favorites() function with an RSS result.
1954 public function testApiFavoritesWithRss()
1956 $result = api_favorites('rss');
1957 $this->assertXml($result, 'statuses');
1961 * Test the api_favorites() function with an unallowed user.
1963 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1965 public function testApiFavoritesWithUnallowedUser()
1967 $_SESSION['allow_api'] = false;
1968 $_GET['screen_name'] = $this->selfUser['nick'];
1969 api_favorites('json');
1973 * Test the api_format_messages() function.
1976 public function testApiFormatMessages()
1978 $result = api_format_messages(
1979 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1980 ['id' => 2, 'screen_name' => 'recipient_name'],
1981 ['id' => 3, 'screen_name' => 'sender_name']
1983 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1984 $this->assertEquals(1, $result['id']);
1985 $this->assertEquals(2, $result['recipient_id']);
1986 $this->assertEquals(3, $result['sender_id']);
1987 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1988 $this->assertEquals('sender_name', $result['sender_screen_name']);
1992 * Test the api_format_messages() function with HTML.
1995 public function testApiFormatMessagesWithHtmlText()
1997 $_GET['getText'] = 'html';
1998 $result = api_format_messages(
1999 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2000 ['id' => 2, 'screen_name' => 'recipient_name'],
2001 ['id' => 3, 'screen_name' => 'sender_name']
2003 $this->assertEquals('item_title', $result['title']);
2004 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2008 * Test the api_format_messages() function with plain text.
2011 public function testApiFormatMessagesWithPlainText()
2013 $_GET['getText'] = 'plain';
2014 $result = api_format_messages(
2015 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2016 ['id' => 2, 'screen_name' => 'recipient_name'],
2017 ['id' => 3, 'screen_name' => 'sender_name']
2019 $this->assertEquals('item_title', $result['title']);
2020 $this->assertEquals('item_body', $result['text']);
2024 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2027 public function testApiFormatMessagesWithoutUserObjects()
2029 $_GET['getUserObjects'] = 'false';
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->assertTrue(!isset($result['sender']));
2036 $this->assertTrue(!isset($result['recipient']));
2040 * Test the api_convert_item() function.
2043 public function testApiConvertItem()
2045 $result = api_convert_item(
2047 'network' => 'feed',
2048 'title' => 'item_title',
2049 // We need a long string to test that it is correctly cut
2050 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2051 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2052 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2053 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2054 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2055 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2056 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2057 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2058 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2059 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2060 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2061 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2062 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2063 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2064 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2065 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2066 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2067 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2068 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2069 'repellat officia illum quos impedit quam iste esse unde qui '.
2070 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2071 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2072 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2073 'plink' => 'item_plink'
2076 $this->assertStringStartsWith('item_title', $result['text']);
2077 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2081 * Test the api_convert_item() function with an empty item body.
2084 public function testApiConvertItemWithoutBody()
2086 $result = api_convert_item(
2088 'network' => 'feed',
2089 'title' => 'item_title',
2091 'plink' => 'item_plink'
2094 $this->assertEquals('item_title', $result['text']);
2095 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2099 * Test the api_convert_item() function with the title in the body.
2102 public function testApiConvertItemWithTitleInBody()
2104 $result = api_convert_item(
2106 'title' => 'item_title',
2107 'body' => 'item_title item_body'
2110 $this->assertEquals('item_title item_body', $result['text']);
2111 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2115 * Test the api_get_attachments() function.
2118 public function testApiGetAttachments()
2121 $this->assertEmpty(api_get_attachments($body));
2125 * Test the api_get_attachments() function with an img tag.
2128 public function testApiGetAttachmentsWithImage()
2130 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2131 $this->assertInternalType('array', api_get_attachments($body));
2135 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2138 public function testApiGetAttachmentsWithImageAndAndStatus()
2140 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2141 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2142 $this->assertInternalType('array', api_get_attachments($body));
2146 * Test the api_get_entitities() function.
2149 public function testApiGetEntitities()
2152 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2156 * Test the api_get_entitities() function with the include_entities parameter.
2159 public function testApiGetEntititiesWithIncludeEntities()
2161 $_REQUEST['include_entities'] = 'true';
2163 $result = api_get_entitities($text, 'bbcode');
2164 $this->assertInternalType('array', $result['hashtags']);
2165 $this->assertInternalType('array', $result['symbols']);
2166 $this->assertInternalType('array', $result['urls']);
2167 $this->assertInternalType('array', $result['user_mentions']);
2171 * Test the api_format_items_embeded_images() function.
2174 public function testApiFormatItemsEmbededImages()
2176 $this->assertEquals(
2177 'text ' . System::baseUrl() . '/display/item_guid',
2178 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2183 * Test the api_contactlink_to_array() function.
2186 public function testApiContactlinkToArray()
2188 $this->assertEquals(
2193 api_contactlink_to_array('text')
2198 * Test the api_contactlink_to_array() function with an URL.
2201 public function testApiContactlinkToArrayWithUrl()
2203 $this->assertEquals(
2205 'name' => ['link_text'],
2208 api_contactlink_to_array('text <a href="url">link_text</a>')
2213 * Test the api_format_items_activities() function.
2216 public function testApiFormatItemsActivities()
2218 $item = ['uid' => 0, 'uri' => ''];
2219 $result = api_format_items_activities($item);
2220 $this->assertArrayHasKey('like', $result);
2221 $this->assertArrayHasKey('dislike', $result);
2222 $this->assertArrayHasKey('attendyes', $result);
2223 $this->assertArrayHasKey('attendno', $result);
2224 $this->assertArrayHasKey('attendmaybe', $result);
2228 * Test the api_format_items_activities() function with an XML result.
2231 public function testApiFormatItemsActivitiesWithXml()
2233 $item = ['uid' => 0, 'uri' => ''];
2234 $result = api_format_items_activities($item, 'xml');
2235 $this->assertArrayHasKey('friendica:like', $result);
2236 $this->assertArrayHasKey('friendica:dislike', $result);
2237 $this->assertArrayHasKey('friendica:attendyes', $result);
2238 $this->assertArrayHasKey('friendica:attendno', $result);
2239 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2243 * Test the api_format_items_profiles() function.
2246 public function testApiFormatItemsProfiles()
2249 'id' => 'profile_id',
2250 'profile-name' => 'profile_name',
2251 'is-default' => true,
2252 'hide-friends' => true,
2253 'photo' => 'profile_photo',
2254 'thumb' => 'profile_thumb',
2256 'net-publish' => true,
2257 'pdesc' => 'description',
2258 'dob' => 'date_of_birth',
2259 'address' => 'address',
2260 'locality' => 'city',
2261 'region' => 'region',
2262 'postal-code' => 'postal_code',
2263 'country-name' => 'country',
2264 'hometown' => 'hometown',
2265 'gender' => 'gender',
2266 'marital' => 'marital',
2267 'with' => 'marital_with',
2268 'howlong' => 'marital_since',
2269 'sexual' => 'sexual',
2270 'politic' => 'politic',
2271 'religion' => 'religion',
2272 'pub_keywords' => 'public_keywords',
2273 'prv_keywords' => 'private_keywords',
2276 'dislikes' => 'dislikes',
2282 'interest' => 'interest',
2283 'romance' => 'romance',
2285 'education' => 'education',
2286 'contact' => 'social_networks',
2287 'homepage' => 'homepage'
2289 $result = api_format_items_profiles($profile_row);
2290 $this->assertEquals(
2292 'profile_id' => 'profile_id',
2293 'profile_name' => 'profile_name',
2294 'is_default' => true,
2295 'hide_friends' => true,
2296 'profile_photo' => 'profile_photo',
2297 'profile_thumb' => 'profile_thumb',
2299 'net_publish' => true,
2300 'description' => 'description',
2301 'date_of_birth' => 'date_of_birth',
2302 'address' => 'address',
2304 'region' => 'region',
2305 'postal_code' => 'postal_code',
2306 'country' => 'country',
2307 'hometown' => 'hometown',
2308 'gender' => 'gender',
2309 'marital' => 'marital',
2310 'marital_with' => 'marital_with',
2311 'marital_since' => 'marital_since',
2312 'sexual' => 'sexual',
2313 'politic' => 'politic',
2314 'religion' => 'religion',
2315 'public_keywords' => 'public_keywords',
2316 'private_keywords' => 'private_keywords',
2319 'dislikes' => 'dislikes',
2325 'interest' => 'interest',
2326 'romance' => 'romance',
2328 'education' => 'education',
2329 'social_networks' => 'social_networks',
2330 'homepage' => 'homepage',
2338 * Test the api_format_items() function.
2341 public function testApiFormatItems()
2345 'item_network' => 'item_network',
2351 'author-network' => Protocol::DFRN,
2352 'author-link' => 'http://localhost/profile/othercontact',
2356 $result = api_format_items($items, ['id' => 0], true);
2357 foreach ($result as $status) {
2358 $this->assertStatus($status);
2363 * Test the api_format_items() function with an XML result.
2366 public function testApiFormatItemsWithXml()
2374 'author-network' => Protocol::DFRN,
2375 'author-link' => 'http://localhost/profile/othercontact',
2379 $result = api_format_items($items, ['id' => 0], true, 'xml');
2380 foreach ($result as $status) {
2381 $this->assertStatus($status);
2386 * Test the api_format_items() function.
2389 public function testApiAccountRateLimitStatus()
2391 $result = api_account_rate_limit_status('json');
2392 $this->assertEquals(150, $result['hash']['remaining_hits']);
2393 $this->assertEquals(150, $result['hash']['hourly_limit']);
2394 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2398 * Test the api_format_items() function with an XML result.
2401 public function testApiAccountRateLimitStatusWithXml()
2403 $result = api_account_rate_limit_status('xml');
2404 $this->assertXml($result, 'hash');
2408 * Test the api_help_test() function.
2411 public function testApiHelpTest()
2413 $result = api_help_test('json');
2414 $this->assertEquals(['ok' => 'ok'], $result);
2418 * Test the api_help_test() function with an XML result.
2421 public function testApiHelpTestWithXml()
2423 $result = api_help_test('xml');
2424 $this->assertXml($result, 'ok');
2428 * Test the api_lists_list() function.
2431 public function testApiListsList()
2433 $result = api_lists_list('json');
2434 $this->assertEquals(['lists_list' => []], $result);
2438 * Test the api_lists_ownerships() function.
2441 public function testApiListsOwnerships()
2443 $result = api_lists_ownerships('json');
2444 foreach ($result['lists']['lists'] as $list) {
2445 $this->assertList($list);
2450 * Test the api_lists_ownerships() function without an authenticated user.
2452 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2454 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2456 $_SESSION['authenticated'] = false;
2457 api_lists_ownerships('json');
2461 * Test the api_lists_statuses() function.
2462 * @expectedException Friendica\Network\HTTPException\BadRequestException
2465 public function testApiListsStatuses()
2467 api_lists_statuses('json');
2471 * Test the api_lists_statuses() function with a list ID.
2474 public function testApiListsStatusesWithListId()
2476 $_REQUEST['list_id'] = 1;
2477 $_REQUEST['page'] = -1;
2478 $_REQUEST['max_id'] = 10;
2479 $result = api_lists_statuses('json');
2480 foreach ($result['status'] as $status) {
2481 $this->assertStatus($status);
2486 * Test the api_lists_statuses() function with a list ID and a RSS result.
2489 public function testApiListsStatusesWithListIdAndRss()
2491 $_REQUEST['list_id'] = 1;
2492 $result = api_lists_statuses('rss');
2493 $this->assertXml($result, 'statuses');
2497 * Test the api_lists_statuses() function with an unallowed user.
2499 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2501 public function testApiListsStatusesWithUnallowedUser()
2503 $_SESSION['allow_api'] = false;
2504 $_GET['screen_name'] = $this->selfUser['nick'];
2505 api_lists_statuses('json');
2509 * Test the api_statuses_f() function.
2512 public function testApiStatusesFWithFriends()
2515 $result = api_statuses_f('friends');
2516 $this->assertArrayHasKey('user', $result);
2520 * Test the api_statuses_f() function.
2523 public function testApiStatusesFWithFollowers()
2525 $result = api_statuses_f('followers');
2526 $this->assertArrayHasKey('user', $result);
2530 * Test the api_statuses_f() function.
2533 public function testApiStatusesFWithBlocks()
2535 $result = api_statuses_f('blocks');
2536 $this->assertArrayHasKey('user', $result);
2540 * Test the api_statuses_f() function.
2543 public function testApiStatusesFWithIncoming()
2545 $result = api_statuses_f('incoming');
2546 $this->assertArrayHasKey('user', $result);
2550 * Test the api_statuses_f() function an undefined cursor GET variable.
2553 public function testApiStatusesFWithUndefinedCursor()
2555 $_GET['cursor'] = 'undefined';
2556 $this->assertFalse(api_statuses_f('friends'));
2560 * Test the api_statuses_friends() function.
2563 public function testApiStatusesFriends()
2565 $result = api_statuses_friends('json');
2566 $this->assertArrayHasKey('user', $result);
2570 * Test the api_statuses_friends() function an undefined cursor GET variable.
2573 public function testApiStatusesFriendsWithUndefinedCursor()
2575 $_GET['cursor'] = 'undefined';
2576 $this->assertFalse(api_statuses_friends('json'));
2580 * Test the api_statuses_followers() function.
2583 public function testApiStatusesFollowers()
2585 $result = api_statuses_followers('json');
2586 $this->assertArrayHasKey('user', $result);
2590 * Test the api_statuses_followers() function an undefined cursor GET variable.
2593 public function testApiStatusesFollowersWithUndefinedCursor()
2595 $_GET['cursor'] = 'undefined';
2596 $this->assertFalse(api_statuses_followers('json'));
2600 * Test the api_blocks_list() function.
2603 public function testApiBlocksList()
2605 $result = api_blocks_list('json');
2606 $this->assertArrayHasKey('user', $result);
2610 * Test the api_blocks_list() function an undefined cursor GET variable.
2613 public function testApiBlocksListWithUndefinedCursor()
2615 $_GET['cursor'] = 'undefined';
2616 $this->assertFalse(api_blocks_list('json'));
2620 * Test the api_friendships_incoming() function.
2623 public function testApiFriendshipsIncoming()
2625 $result = api_friendships_incoming('json');
2626 $this->assertArrayHasKey('id', $result);
2630 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2633 public function testApiFriendshipsIncomingWithUndefinedCursor()
2635 $_GET['cursor'] = 'undefined';
2636 $this->assertFalse(api_friendships_incoming('json'));
2640 * Test the api_statusnet_config() function.
2643 public function testApiStatusnetConfig()
2645 $result = api_statusnet_config('json');
2646 $this->assertEquals('localhost', $result['config']['site']['server']);
2647 $this->assertEquals('default', $result['config']['site']['theme']);
2648 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2649 $this->assertTrue($result['config']['site']['fancy']);
2650 $this->assertEquals('en', $result['config']['site']['language']);
2651 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2652 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2653 $this->assertEquals('false', $result['config']['site']['private']);
2654 $this->assertEquals('false', $result['config']['site']['ssl']);
2655 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2659 * Test the api_statusnet_version() function.
2662 public function testApiStatusnetVersion()
2664 $result = api_statusnet_version('json');
2665 $this->assertEquals('0.9.7', $result['version']);
2669 * Test the api_ff_ids() function.
2672 public function testApiFfIds()
2674 $result = api_ff_ids('json');
2675 $this->assertNull($result);
2679 * Test the api_ff_ids() function with a result.
2682 public function testApiFfIdsWithResult()
2684 $this->markTestIncomplete();
2688 * Test the api_ff_ids() function without an authenticated user.
2690 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2692 public function testApiFfIdsWithoutAuthenticatedUser()
2694 $_SESSION['authenticated'] = false;
2699 * Test the api_friends_ids() function.
2702 public function testApiFriendsIds()
2704 $result = api_friends_ids('json');
2705 $this->assertNull($result);
2709 * Test the api_followers_ids() function.
2712 public function testApiFollowersIds()
2714 $result = api_followers_ids('json');
2715 $this->assertNull($result);
2719 * Test the api_direct_messages_new() function.
2722 public function testApiDirectMessagesNew()
2724 $result = api_direct_messages_new('json');
2725 $this->assertNull($result);
2729 * Test the api_direct_messages_new() function without an authenticated user.
2731 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2733 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2735 $_SESSION['authenticated'] = false;
2736 api_direct_messages_new('json');
2740 * Test the api_direct_messages_new() function with an user ID.
2743 public function testApiDirectMessagesNewWithUserId()
2745 $_POST['text'] = 'message_text';
2746 $_POST['user_id'] = $this->otherUser['id'];
2747 $result = api_direct_messages_new('json');
2748 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2752 * Test the api_direct_messages_new() function with a screen name.
2755 public function testApiDirectMessagesNewWithScreenName()
2757 $_POST['text'] = 'message_text';
2758 $_POST['screen_name'] = $this->friendUser['nick'];
2759 $result = api_direct_messages_new('json');
2760 $this->assertEquals(1, $result['direct_message']['id']);
2761 $this->assertContains('message_text', $result['direct_message']['text']);
2762 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2763 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2767 * Test the api_direct_messages_new() function with a title.
2770 public function testApiDirectMessagesNewWithTitle()
2772 $_POST['text'] = 'message_text';
2773 $_POST['screen_name'] = $this->friendUser['nick'];
2774 $_REQUEST['title'] = 'message_title';
2775 $result = api_direct_messages_new('json');
2776 $this->assertEquals(1, $result['direct_message']['id']);
2777 $this->assertContains('message_text', $result['direct_message']['text']);
2778 $this->assertContains('message_title', $result['direct_message']['text']);
2779 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2780 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2784 * Test the api_direct_messages_new() function with an RSS result.
2787 public function testApiDirectMessagesNewWithRss()
2789 $_POST['text'] = 'message_text';
2790 $_POST['screen_name'] = $this->friendUser['nick'];
2791 $result = api_direct_messages_new('rss');
2792 $this->assertXml($result, 'direct-messages');
2796 * Test the api_direct_messages_destroy() function.
2798 * @expectedException Friendica\Network\HTTPException\BadRequestException
2800 public function testApiDirectMessagesDestroy()
2802 api_direct_messages_destroy('json');
2806 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2809 public function testApiDirectMessagesDestroyWithVerbose()
2811 $_GET['friendica_verbose'] = 'true';
2812 $result = api_direct_messages_destroy('json');
2813 $this->assertEquals(
2816 'result' => 'error',
2817 'message' => 'message id or parenturi not specified'
2825 * Test the api_direct_messages_destroy() function without an authenticated user.
2827 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2829 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2831 $_SESSION['authenticated'] = false;
2832 api_direct_messages_destroy('json');
2836 * Test the api_direct_messages_destroy() function with a non-zero ID.
2838 * @expectedException Friendica\Network\HTTPException\BadRequestException
2840 public function testApiDirectMessagesDestroyWithId()
2842 $_REQUEST['id'] = 1;
2843 api_direct_messages_destroy('json');
2847 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2850 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2852 $_REQUEST['id'] = 1;
2853 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2854 $_GET['friendica_verbose'] = 'true';
2855 $result = api_direct_messages_destroy('json');
2856 $this->assertEquals(
2859 'result' => 'error',
2860 'message' => 'message id not in database'
2868 * Test the api_direct_messages_destroy() function with a non-zero ID.
2871 public function testApiDirectMessagesDestroyWithCorrectId()
2873 $this->markTestIncomplete('We need to add a dataset for this.');
2877 * Test the api_direct_messages_box() function.
2880 public function testApiDirectMessagesBoxWithSentbox()
2882 $_REQUEST['page'] = -1;
2883 $_REQUEST['max_id'] = 10;
2884 $result = api_direct_messages_box('json', 'sentbox', 'false');
2885 $this->assertArrayHasKey('direct_message', $result);
2889 * Test the api_direct_messages_box() function.
2892 public function testApiDirectMessagesBoxWithConversation()
2894 $result = api_direct_messages_box('json', 'conversation', 'false');
2895 $this->assertArrayHasKey('direct_message', $result);
2899 * Test the api_direct_messages_box() function.
2902 public function testApiDirectMessagesBoxWithAll()
2904 $result = api_direct_messages_box('json', 'all', 'false');
2905 $this->assertArrayHasKey('direct_message', $result);
2909 * Test the api_direct_messages_box() function.
2912 public function testApiDirectMessagesBoxWithInbox()
2914 $result = api_direct_messages_box('json', 'inbox', 'false');
2915 $this->assertArrayHasKey('direct_message', $result);
2919 * Test the api_direct_messages_box() function.
2922 public function testApiDirectMessagesBoxWithVerbose()
2924 $result = api_direct_messages_box('json', 'sentbox', 'true');
2925 $this->assertEquals(
2928 'result' => 'error',
2929 'message' => 'no mails available'
2937 * Test the api_direct_messages_box() function with a RSS result.
2940 public function testApiDirectMessagesBoxWithRss()
2942 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2943 $this->assertXml($result, 'direct-messages');
2947 * Test the api_direct_messages_box() function without an authenticated user.
2949 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2951 public function testApiDirectMessagesBoxWithUnallowedUser()
2953 $_SESSION['allow_api'] = false;
2954 $_GET['screen_name'] = $this->selfUser['nick'];
2955 api_direct_messages_box('json', 'sentbox', 'false');
2959 * Test the api_direct_messages_sentbox() function.
2962 public function testApiDirectMessagesSentbox()
2964 $result = api_direct_messages_sentbox('json');
2965 $this->assertArrayHasKey('direct_message', $result);
2969 * Test the api_direct_messages_inbox() function.
2972 public function testApiDirectMessagesInbox()
2974 $result = api_direct_messages_inbox('json');
2975 $this->assertArrayHasKey('direct_message', $result);
2979 * Test the api_direct_messages_all() function.
2982 public function testApiDirectMessagesAll()
2984 $result = api_direct_messages_all('json');
2985 $this->assertArrayHasKey('direct_message', $result);
2989 * Test the api_direct_messages_conversation() function.
2992 public function testApiDirectMessagesConversation()
2994 $result = api_direct_messages_conversation('json');
2995 $this->assertArrayHasKey('direct_message', $result);
2999 * Test the api_oauth_request_token() function.
3002 public function testApiOauthRequestToken()
3004 $this->markTestIncomplete('killme() kills phpunit as well');
3008 * Test the api_oauth_access_token() function.
3011 public function testApiOauthAccessToken()
3013 $this->markTestIncomplete('killme() kills phpunit as well');
3017 * Test the api_fr_photoalbum_delete() function.
3019 * @expectedException Friendica\Network\HTTPException\BadRequestException
3021 public function testApiFrPhotoalbumDelete()
3023 api_fr_photoalbum_delete('json');
3027 * Test the api_fr_photoalbum_delete() function with an album name.
3029 * @expectedException Friendica\Network\HTTPException\BadRequestException
3031 public function testApiFrPhotoalbumDeleteWithAlbum()
3033 $_REQUEST['album'] = 'album_name';
3034 api_fr_photoalbum_delete('json');
3038 * Test the api_fr_photoalbum_delete() function with an album name.
3041 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3043 $this->markTestIncomplete('We need to add a dataset for this.');
3047 * Test the api_fr_photoalbum_delete() function.
3049 * @expectedException Friendica\Network\HTTPException\BadRequestException
3051 public function testApiFrPhotoalbumUpdate()
3053 api_fr_photoalbum_update('json');
3057 * Test the api_fr_photoalbum_delete() function with an album name.
3059 * @expectedException Friendica\Network\HTTPException\BadRequestException
3061 public function testApiFrPhotoalbumUpdateWithAlbum()
3063 $_REQUEST['album'] = 'album_name';
3064 api_fr_photoalbum_update('json');
3068 * Test the api_fr_photoalbum_delete() function with an album name.
3070 * @expectedException Friendica\Network\HTTPException\BadRequestException
3072 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3074 $_REQUEST['album'] = 'album_name';
3075 $_REQUEST['album_new'] = 'album_name';
3076 api_fr_photoalbum_update('json');
3080 * Test the api_fr_photoalbum_update() function without an authenticated user.
3082 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3084 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3086 $_SESSION['authenticated'] = false;
3087 api_fr_photoalbum_update('json');
3091 * Test the api_fr_photoalbum_delete() function with an album name.
3094 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3096 $this->markTestIncomplete('We need to add a dataset for this.');
3100 * Test the api_fr_photos_list() function.
3103 public function testApiFrPhotosList()
3105 $result = api_fr_photos_list('json');
3106 $this->assertArrayHasKey('photo', $result);
3110 * Test the api_fr_photos_list() function without an authenticated user.
3112 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3114 public function testApiFrPhotosListWithoutAuthenticatedUser()
3116 $_SESSION['authenticated'] = false;
3117 api_fr_photos_list('json');
3121 * Test the api_fr_photo_create_update() function.
3123 * @expectedException Friendica\Network\HTTPException\BadRequestException
3125 public function testApiFrPhotoCreateUpdate()
3127 api_fr_photo_create_update('json');
3131 * Test the api_fr_photo_create_update() function without an authenticated user.
3133 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3135 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3137 $_SESSION['authenticated'] = false;
3138 api_fr_photo_create_update('json');
3142 * Test the api_fr_photo_create_update() function with an album name.
3144 * @expectedException Friendica\Network\HTTPException\BadRequestException
3146 public function testApiFrPhotoCreateUpdateWithAlbum()
3148 $_REQUEST['album'] = 'album_name';
3149 api_fr_photo_create_update('json');
3153 * Test the api_fr_photo_create_update() function with the update mode.
3156 public function testApiFrPhotoCreateUpdateWithUpdate()
3158 $this->markTestIncomplete('We need to create a dataset for this');
3162 * Test the api_fr_photo_create_update() function with an uploaded file.
3165 public function testApiFrPhotoCreateUpdateWithFile()
3167 $this->markTestIncomplete();
3171 * Test the api_fr_photo_delete() function.
3173 * @expectedException Friendica\Network\HTTPException\BadRequestException
3175 public function testApiFrPhotoDelete()
3177 api_fr_photo_delete('json');
3181 * Test the api_fr_photo_delete() function without an authenticated user.
3183 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3185 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3187 $_SESSION['authenticated'] = false;
3188 api_fr_photo_delete('json');
3192 * Test the api_fr_photo_delete() function with a photo ID.
3194 * @expectedException Friendica\Network\HTTPException\BadRequestException
3196 public function testApiFrPhotoDeleteWithPhotoId()
3198 $_REQUEST['photo_id'] = 1;
3199 api_fr_photo_delete('json');
3203 * Test the api_fr_photo_delete() function with a correct photo ID.
3206 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3208 $this->markTestIncomplete('We need to create a dataset for this.');
3212 * Test the api_fr_photo_detail() function.
3214 * @expectedException Friendica\Network\HTTPException\BadRequestException
3216 public function testApiFrPhotoDetail()
3218 api_fr_photo_detail('json');
3222 * Test the api_fr_photo_detail() function without an authenticated user.
3224 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3226 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3228 $_SESSION['authenticated'] = false;
3229 api_fr_photo_detail('json');
3233 * Test the api_fr_photo_detail() function with a photo ID.
3235 * @expectedException Friendica\Network\HTTPException\NotFoundException
3237 public function testApiFrPhotoDetailWithPhotoId()
3239 $_REQUEST['photo_id'] = 1;
3240 api_fr_photo_detail('json');
3244 * Test the api_fr_photo_detail() function with a correct photo ID.
3247 public function testApiFrPhotoDetailCorrectPhotoId()
3249 $this->markTestIncomplete('We need to create a dataset for this.');
3253 * Test the api_account_update_profile_image() function.
3255 * @expectedException Friendica\Network\HTTPException\BadRequestException
3257 public function testApiAccountUpdateProfileImage()
3259 api_account_update_profile_image('json');
3263 * Test the api_account_update_profile_image() function without an authenticated user.
3265 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3267 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3269 $_SESSION['authenticated'] = false;
3270 api_account_update_profile_image('json');
3274 * Test the api_account_update_profile_image() function with an uploaded file.
3276 * @expectedException Friendica\Network\HTTPException\BadRequestException
3278 public function testApiAccountUpdateProfileImageWithUpload()
3280 $this->markTestIncomplete();
3285 * Test the api_account_update_profile() function.
3288 public function testApiAccountUpdateProfile()
3290 $_POST['name'] = 'new_name';
3291 $_POST['description'] = 'new_description';
3292 $result = api_account_update_profile('json');
3293 // We can't use assertSelfUser() here because the user object is missing some properties.
3294 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3295 $this->assertEquals('Friendica', $result['user']['location']);
3296 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3297 $this->assertEquals('dfrn', $result['user']['network']);
3298 $this->assertEquals('new_name', $result['user']['name']);
3299 $this->assertEquals('new_description', $result['user']['description']);
3303 * Test the check_acl_input() function.
3306 public function testCheckAclInput()
3308 $result = check_acl_input('<aclstring>');
3309 // Where does this result come from?
3310 $this->assertEquals(1, $result);
3314 * Test the check_acl_input() function with an empty ACL string.
3317 public function testCheckAclInputWithEmptyAclString()
3319 $result = check_acl_input(' ');
3320 $this->assertFalse($result);
3324 * Test the save_media_to_database() function.
3327 public function testSaveMediaToDatabase()
3329 $this->markTestIncomplete();
3333 * Test the post_photo_item() function.
3336 public function testPostPhotoItem()
3338 $this->markTestIncomplete();
3342 * Test the prepare_photo_data() function.
3345 public function testPreparePhotoData()
3347 $this->markTestIncomplete();
3351 * Test the api_friendica_remoteauth() function.
3353 * @expectedException Friendica\Network\HTTPException\BadRequestException
3355 public function testApiFriendicaRemoteauth()
3357 api_friendica_remoteauth();
3361 * Test the api_friendica_remoteauth() function with an URL.
3363 * @expectedException Friendica\Network\HTTPException\BadRequestException
3365 public function testApiFriendicaRemoteauthWithUrl()
3367 $_GET['url'] = 'url';
3368 $_GET['c_url'] = 'url';
3369 api_friendica_remoteauth();
3373 * Test the api_friendica_remoteauth() function with a correct URL.
3376 public function testApiFriendicaRemoteauthWithCorrectUrl()
3378 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3379 $_GET['url'] = 'url';
3380 $_GET['c_url'] = $this->selfUser['nurl'];
3381 api_friendica_remoteauth();
3385 * Test the api_share_as_retweet() function.
3388 public function testApiShareAsRetweet()
3390 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3391 $result = api_share_as_retweet($item);
3392 $this->assertFalse($result);
3396 * Test the api_share_as_retweet() function with a valid item.
3399 public function testApiShareAsRetweetWithValidItem()
3401 $this->markTestIncomplete();
3405 * Test the api_get_nick() function.
3408 public function testApiGetNick()
3410 $result = api_get_nick($this->otherUser['nurl']);
3411 $this->assertEquals('othercontact', $result);
3415 * Test the api_get_nick() function with a wrong URL.
3418 public function testApiGetNickWithWrongUrl()
3420 $result = api_get_nick('wrong_url');
3421 $this->assertFalse($result);
3425 * Test the api_in_reply_to() function.
3428 public function testApiInReplyTo()
3430 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3431 $this->assertArrayHasKey('status_id', $result);
3432 $this->assertArrayHasKey('user_id', $result);
3433 $this->assertArrayHasKey('status_id_str', $result);
3434 $this->assertArrayHasKey('user_id_str', $result);
3435 $this->assertArrayHasKey('screen_name', $result);
3439 * Test the api_in_reply_to() function with a valid item.
3442 public function testApiInReplyToWithValidItem()
3444 $this->markTestIncomplete();
3448 * Test the api_clean_plain_items() function.
3451 public function testApiCleanPlainItems()
3453 $_REQUEST['include_entities'] = 'true';
3454 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3455 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3459 * Test the api_clean_attachments() function.
3462 public function testApiCleanAttachments()
3464 $this->markTestIncomplete();
3468 * Test the api_best_nickname() function.
3471 public function testApiBestNickname()
3474 $result = api_best_nickname($contacts);
3475 $this->assertNull($result);
3479 * Test the api_best_nickname() function with contacts.
3482 public function testApiBestNicknameWithContacts()
3484 $this->markTestIncomplete();
3488 * Test the api_friendica_group_show() function.
3491 public function testApiFriendicaGroupShow()
3493 $this->markTestIncomplete();
3497 * Test the api_friendica_group_delete() function.
3500 public function testApiFriendicaGroupDelete()
3502 $this->markTestIncomplete();
3506 * Test the api_lists_destroy() function.
3509 public function testApiListsDestroy()
3511 $this->markTestIncomplete();
3515 * Test the group_create() function.
3518 public function testGroupCreate()
3520 $this->markTestIncomplete();
3524 * Test the api_friendica_group_create() function.
3527 public function testApiFriendicaGroupCreate()
3529 $this->markTestIncomplete();
3533 * Test the api_lists_create() function.
3536 public function testApiListsCreate()
3538 $this->markTestIncomplete();
3542 * Test the api_friendica_group_update() function.
3545 public function testApiFriendicaGroupUpdate()
3547 $this->markTestIncomplete();
3551 * Test the api_lists_update() function.
3554 public function testApiListsUpdate()
3556 $this->markTestIncomplete();
3560 * Test the api_friendica_activity() function.
3563 public function testApiFriendicaActivity()
3565 $this->markTestIncomplete();
3569 * Test the api_friendica_notification() function.
3571 * @expectedException Friendica\Network\HTTPException\BadRequestException
3573 public function testApiFriendicaNotification()
3575 api_friendica_notification('json');
3579 * Test the api_friendica_notification() function without an authenticated user.
3581 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3583 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3585 $_SESSION['authenticated'] = false;
3586 api_friendica_notification('json');
3590 * Test the api_friendica_notification() function with an argument count.
3593 public function testApiFriendicaNotificationWithArgumentCount()
3595 $this->app->argv = ['api', 'friendica', 'notification'];
3596 $this->app->argc = count($this->app->argv);
3597 $result = api_friendica_notification('json');
3598 $this->assertEquals(['note' => false], $result);
3602 * Test the api_friendica_notification() function with an XML result.
3605 public function testApiFriendicaNotificationWithXmlResult()
3607 $this->app->argv = ['api', 'friendica', 'notification'];
3608 $this->app->argc = count($this->app->argv);
3609 $result = api_friendica_notification('xml');
3610 $this->assertXml($result, 'notes');
3614 * Test the api_friendica_notification_seen() function.
3617 public function testApiFriendicaNotificationSeen()
3619 $this->markTestIncomplete();
3623 * Test the api_friendica_direct_messages_setseen() function.
3626 public function testApiFriendicaDirectMessagesSetseen()
3628 $this->markTestIncomplete();
3632 * Test the api_friendica_direct_messages_search() function.
3635 public function testApiFriendicaDirectMessagesSearch()
3637 $this->markTestIncomplete();
3641 * Test the api_friendica_profile_show() function.
3644 public function testApiFriendicaProfileShow()
3646 $result = api_friendica_profile_show('json');
3647 // We can't use assertSelfUser() here because the user object is missing some properties.
3648 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3649 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3650 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3651 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3652 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3653 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3654 $this->assertFalse($result['$result']['multi_profiles']);
3658 * Test the api_friendica_profile_show() function with a profile ID.
3661 public function testApiFriendicaProfileShowWithProfileId()
3663 $this->markTestIncomplete('We need to add a dataset for this.');
3667 * Test the api_friendica_profile_show() function with a wrong profile ID.
3669 * @expectedException Friendica\Network\HTTPException\BadRequestException
3671 public function testApiFriendicaProfileShowWithWrongProfileId()
3673 $_REQUEST['profile_id'] = 666;
3674 api_friendica_profile_show('json');
3678 * Test the api_friendica_profile_show() function without an authenticated user.
3680 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3682 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3684 $_SESSION['authenticated'] = false;
3685 api_friendica_profile_show('json');
3689 * Test the api_saved_searches_list() function.
3692 public function testApiSavedSearchesList()
3694 $result = api_saved_searches_list('json');
3695 $this->assertEquals(1, $result['terms'][0]['id']);
3696 $this->assertEquals(1, $result['terms'][0]['id_str']);
3697 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3698 $this->assertEquals('Saved search', $result['terms'][0]['query']);