6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Network\BadRequestException;
12 use Friendica\Network\HTTPException;
13 use Friendica\Render\FriendicaSmarty;
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 protected function setUp()
32 // Reusable App object
33 $this->app = new App(__DIR__.'/../');
36 // User data that the test database is populated with
39 'name' => 'Self contact',
40 'nick' => 'selfcontact',
41 'nurl' => 'http://localhost/profile/selfcontact'
45 'name' => 'Friend contact',
46 'nick' => 'friendcontact',
47 'nurl' => 'http://localhost/profile/friendcontact'
51 'name' => 'othercontact',
52 'nick' => 'othercontact',
53 'nurl' => 'http://localhost/profile/othercontact'
56 // User ID that we know is not in the database
57 $this->wrongUserId = 666;
59 // Most API require login so we force the session
62 'authenticated' => true,
63 'uid' => $this->selfUser['id']
67 Config::set('config', 'hostname', 'localhost');
68 Config::set('system', 'throttle_limit_day', 100);
69 Config::set('system', 'throttle_limit_week', 100);
70 Config::set('system', 'throttle_limit_month', 100);
71 Config::set('system', 'theme', 'system_theme');
75 * Assert that an user array contains expected keys.
76 * @param array $user User array
79 private function assertSelfUser(array $user)
81 $this->assertEquals($this->selfUser['id'], $user['uid']);
82 $this->assertEquals($this->selfUser['id'], $user['cid']);
83 $this->assertEquals(1, $user['self']);
84 $this->assertEquals('Friendica', $user['location']);
85 $this->assertEquals($this->selfUser['name'], $user['name']);
86 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
87 $this->assertEquals('dfrn', $user['network']);
88 $this->assertTrue($user['verified']);
92 * Assert that an user array contains expected keys.
93 * @param array $user User array
96 private function assertOtherUser(array $user)
98 $this->assertEquals($this->otherUser['id'], $user['id']);
99 $this->assertEquals($this->otherUser['id'], $user['id_str']);
100 $this->assertEquals(0, $user['self']);
101 $this->assertEquals($this->otherUser['name'], $user['name']);
102 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
103 $this->assertFalse($user['verified']);
107 * Assert that a status array contains expected keys.
108 * @param array $status Status array
111 private function assertStatus(array $status)
113 $this->assertInternalType('string', $status['text']);
114 $this->assertInternalType('int', $status['id']);
115 // We could probably do more checks here.
119 * Assert that a list array contains expected keys.
120 * @param array $list List array
123 private function assertList(array $list)
125 $this->assertInternalType('string', $list['name']);
126 $this->assertInternalType('int', $list['id']);
127 $this->assertInternalType('string', $list['id_str']);
128 $this->assertContains($list['mode'], ['public', 'private']);
129 // We could probably do more checks here.
133 * Assert that the string is XML and contain the root element.
134 * @param string $result XML string
135 * @param string $root_element Root element name
138 private function assertXml($result, $root_element)
140 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
141 $this->assertContains('<'.$root_element, $result);
142 // We could probably do more checks here.
146 * Get the path to a temporary empty PNG image.
147 * @return string Path
149 private function getTempImage()
151 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
155 // Empty 1x1 px PNG image
156 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
164 * Test the api_user() function.
167 public function testApiUser()
169 $this->assertEquals($this->selfUser['id'], api_user());
173 * Test the api_user() function with an unallowed user.
176 public function testApiUserWithUnallowedUser()
178 $_SESSION = ['allow_api' => false];
179 $this->assertEquals(false, api_user());
183 * Test the api_source() function.
186 public function testApiSource()
188 $this->assertEquals('api', api_source());
192 * Test the api_source() function with a Twidere user agent.
195 public function testApiSourceWithTwidere()
197 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
198 $this->assertEquals('Twidere', api_source());
202 * Test the api_source() function with a GET parameter.
205 public function testApiSourceWithGet()
207 $_GET['source'] = 'source_name';
208 $this->assertEquals('source_name', api_source());
212 * Test the api_date() function.
215 public function testApiDate()
217 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
221 * Test the api_register_func() function.
224 public function testApiRegisterFunc()
236 $this->assertTrue($API['api_path']['auth']);
237 $this->assertEquals('method', $API['api_path']['method']);
238 $this->assertTrue(is_callable($API['api_path']['func']));
242 * Test the api_login() function without any login.
244 * @runInSeparateProcess
245 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
247 public function testApiLoginWithoutLogin()
249 api_login($this->app);
253 * Test the api_login() function with a bad login.
255 * @runInSeparateProcess
256 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
258 public function testApiLoginWithBadLogin()
260 $_SERVER['PHP_AUTH_USER'] = 'user@server';
261 api_login($this->app);
265 * Test the api_login() function with oAuth.
268 public function testApiLoginWithOauth()
270 $this->markTestIncomplete('Can we test this easily?');
274 * Test the api_login() function with authentication provided by an addon.
277 public function testApiLoginWithAddonAuth()
279 $this->markTestIncomplete('Can we test this easily?');
283 * Test the api_login() function with a correct login.
285 * @runInSeparateProcess
287 public function testApiLoginWithCorrectLogin()
289 $_SERVER['PHP_AUTH_USER'] = 'Test user';
290 $_SERVER['PHP_AUTH_PW'] = 'password';
291 api_login($this->app);
295 * Test the api_login() function with a remote user.
297 * @runInSeparateProcess
298 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
300 public function testApiLoginWithRemoteUser()
302 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
303 api_login($this->app);
307 * Test the api_check_method() function.
310 public function testApiCheckMethod()
312 $this->assertFalse(api_check_method('method'));
316 * Test the api_check_method() function with a correct method.
319 public function testApiCheckMethodWithCorrectMethod()
321 $_SERVER['REQUEST_METHOD'] = 'method';
322 $this->assertTrue(api_check_method('method'));
326 * Test the api_check_method() function with a wildcard.
329 public function testApiCheckMethodWithWildcard()
331 $this->assertTrue(api_check_method('*'));
335 * Test the api_call() function.
337 * @runInSeparateProcess
339 public function testApiCall()
343 'method' => 'method',
344 'func' => function () {
345 return ['data' => ['some_data']];
348 $_SERVER['REQUEST_METHOD'] = 'method';
349 $_GET['callback'] = 'callback_name';
351 $this->app->query_string = 'api_path';
353 'callback_name(["some_data"])',
359 * Test the api_call() function with the profiled enabled.
361 * @runInSeparateProcess
363 public function testApiCallWithProfiler()
367 'method' => 'method',
368 'func' => function () {
369 return ['data' => ['some_data']];
372 $_SERVER['REQUEST_METHOD'] = 'method';
373 Config::set('system', 'profiler', true);
374 Config::set('rendertime', 'callstack', true);
375 $this->app->callstack = [
376 'database' => ['some_function' => 200],
377 'database_write' => ['some_function' => 200],
378 'cache' => ['some_function' => 200],
379 'cache_write' => ['some_function' => 200],
380 'network' => ['some_function' => 200]
383 $this->app->query_string = 'api_path';
391 * Test the api_call() function without any result.
393 * @runInSeparateProcess
395 public function testApiCallWithNoResult()
399 'method' => 'method',
400 'func' => function () {
404 $_SERVER['REQUEST_METHOD'] = 'method';
406 $this->app->query_string = 'api_path';
408 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
414 * Test the api_call() function with an unimplemented API.
416 * @runInSeparateProcess
418 public function testApiCallWithUninplementedApi()
421 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
427 * Test the api_call() function with a JSON result.
429 * @runInSeparateProcess
431 public function testApiCallWithJson()
435 'method' => 'method',
436 'func' => function () {
437 return ['data' => ['some_data']];
440 $_SERVER['REQUEST_METHOD'] = 'method';
442 $this->app->query_string = 'api_path.json';
450 * Test the api_call() function with an XML result.
452 * @runInSeparateProcess
454 public function testApiCallWithXml()
458 'method' => 'method',
459 'func' => function () {
463 $_SERVER['REQUEST_METHOD'] = 'method';
465 $this->app->query_string = 'api_path.xml';
473 * Test the api_call() function with an RSS result.
475 * @runInSeparateProcess
477 public function testApiCallWithRss()
481 'method' => 'method',
482 'func' => function () {
486 $_SERVER['REQUEST_METHOD'] = 'method';
488 $this->app->query_string = 'api_path.rss';
490 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
497 * Test the api_call() function with an Atom result.
499 * @runInSeparateProcess
501 public function testApiCallWithAtom()
505 'method' => 'method',
506 'func' => function () {
510 $_SERVER['REQUEST_METHOD'] = 'method';
512 $this->app->query_string = 'api_path.atom';
514 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
521 * Test the api_call() function with an unallowed method.
523 * @runInSeparateProcess
525 public function testApiCallWithWrongMethod()
528 $API['api_path'] = ['method' => 'method'];
530 $this->app->query_string = 'api_path';
532 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
538 * Test the api_call() function with an unauthorized user.
540 * @runInSeparateProcess
542 public function testApiCallWithWrongAuth()
546 'method' => 'method',
549 $_SERVER['REQUEST_METHOD'] = 'method';
550 $_SESSION['authenticated'] = false;
552 $this->app->query_string = 'api_path';
554 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
560 * Test the api_error() function with a JSON result.
562 * @runInSeparateProcess
564 public function testApiErrorWithJson()
567 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
568 api_error('json', new HTTPException('error_message'))
573 * Test the api_error() function with an XML result.
575 * @runInSeparateProcess
577 public function testApiErrorWithXml()
580 '<?xml version="1.0"?>'."\n".
581 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
582 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
583 'xmlns:georss="http://www.georss.org/georss">'."\n".
584 ' <error>error_message</error>'."\n".
585 ' <code>200 Friendica\Network\HTTP</code>'."\n".
588 api_error('xml', new HTTPException('error_message'))
593 * Test the api_error() function with an RSS result.
595 * @runInSeparateProcess
597 public function testApiErrorWithRss()
600 '<?xml version="1.0"?>'."\n".
601 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
602 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
603 'xmlns:georss="http://www.georss.org/georss">'."\n".
604 ' <error>error_message</error>'."\n".
605 ' <code>200 Friendica\Network\HTTP</code>'."\n".
608 api_error('rss', new HTTPException('error_message'))
613 * Test the api_error() function with an Atom result.
615 * @runInSeparateProcess
617 public function testApiErrorWithAtom()
620 '<?xml version="1.0"?>'."\n".
621 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
622 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
623 'xmlns:georss="http://www.georss.org/georss">'."\n".
624 ' <error>error_message</error>'."\n".
625 ' <code>200 Friendica\Network\HTTP</code>'."\n".
628 api_error('atom', new HTTPException('error_message'))
633 * Test the api_rss_extra() function.
636 public function testApiRssExtra()
638 $user_info = ['url' => 'user_url', 'lang' => 'en'];
639 $result = api_rss_extra($this->app, [], $user_info);
640 $this->assertEquals($user_info, $result['$user']);
641 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
642 $this->assertArrayHasKey('self', $result['$rss']);
643 $this->assertArrayHasKey('base', $result['$rss']);
644 $this->assertArrayHasKey('updated', $result['$rss']);
645 $this->assertArrayHasKey('atom_updated', $result['$rss']);
646 $this->assertArrayHasKey('language', $result['$rss']);
647 $this->assertArrayHasKey('logo', $result['$rss']);
651 * Test the api_rss_extra() function without any user info.
653 * @runInSeparateProcess
655 public function testApiRssExtraWithoutUserInfo()
657 $result = api_rss_extra($this->app, [], null);
658 $this->assertInternalType('array', $result['$user']);
659 $this->assertArrayHasKey('alternate', $result['$rss']);
660 $this->assertArrayHasKey('self', $result['$rss']);
661 $this->assertArrayHasKey('base', $result['$rss']);
662 $this->assertArrayHasKey('updated', $result['$rss']);
663 $this->assertArrayHasKey('atom_updated', $result['$rss']);
664 $this->assertArrayHasKey('language', $result['$rss']);
665 $this->assertArrayHasKey('logo', $result['$rss']);
669 * Test the api_unique_id_to_nurl() function.
672 public function testApiUniqueIdToNurl()
674 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
678 * Test the api_unique_id_to_nurl() function with a correct ID.
681 public function testApiUniqueIdToNurlWithCorrectId()
683 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
687 * Test the api_get_user() function.
689 * @runInSeparateProcess
691 public function testApiGetUser()
693 $user = api_get_user($this->app);
694 $this->assertSelfUser($user);
695 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
696 $this->assertEquals('6fdbe8', $user['profile_link_color']);
697 $this->assertEquals('ededed', $user['profile_background_color']);
701 * Test the api_get_user() function with a Frio schema.
703 * @runInSeparateProcess
705 public function testApiGetUserWithFrioSchema()
707 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
708 $user = api_get_user($this->app);
709 $this->assertSelfUser($user);
710 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
711 $this->assertEquals('6fdbe8', $user['profile_link_color']);
712 $this->assertEquals('ededed', $user['profile_background_color']);
716 * Test the api_get_user() function with a custom Frio schema.
718 * @runInSeparateProcess
720 public function testApiGetUserWithCustomFrioSchema()
722 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
723 PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
724 PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
725 PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
726 $user = api_get_user($this->app);
727 $this->assertSelfUser($user);
728 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
729 $this->assertEquals('123456', $user['profile_link_color']);
730 $this->assertEquals('123456', $user['profile_background_color']);
734 * Test the api_get_user() function with an empty Frio schema.
736 * @runInSeparateProcess
738 public function testApiGetUserWithEmptyFrioSchema()
740 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
741 $user = api_get_user($this->app);
742 $this->assertSelfUser($user);
743 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
744 $this->assertEquals('6fdbe8', $user['profile_link_color']);
745 $this->assertEquals('ededed', $user['profile_background_color']);
749 * Test the api_get_user() function with an user that is not allowed to use the API.
751 * @runInSeparateProcess
753 public function testApiGetUserWithoutApiUser()
755 $_SERVER['PHP_AUTH_USER'] = 'Test user';
756 $_SERVER['PHP_AUTH_PW'] = 'password';
757 $_SESSION['allow_api'] = false;
758 $this->assertFalse(api_get_user($this->app));
762 * Test the api_get_user() function with an user ID in a GET parameter.
764 * @runInSeparateProcess
766 public function testApiGetUserWithGetId()
768 $_GET['user_id'] = $this->otherUser['id'];
769 $this->assertOtherUser(api_get_user($this->app));
773 * Test the api_get_user() function with a wrong user ID in a GET parameter.
775 * @runInSeparateProcess
776 * @expectedException Friendica\Network\HTTPException\BadRequestException
778 public function testApiGetUserWithWrongGetId()
780 $_GET['user_id'] = $this->wrongUserId;
781 $this->assertOtherUser(api_get_user($this->app));
785 * Test the api_get_user() function with an user name in a GET parameter.
787 * @runInSeparateProcess
789 public function testApiGetUserWithGetName()
791 $_GET['screen_name'] = $this->selfUser['nick'];
792 $this->assertSelfUser(api_get_user($this->app));
796 * Test the api_get_user() function with a profile URL in a GET parameter.
798 * @runInSeparateProcess
800 public function testApiGetUserWithGetUrl()
802 $_GET['profileurl'] = $this->selfUser['nurl'];
803 $this->assertSelfUser(api_get_user($this->app));
807 * Test the api_get_user() function with an user ID in the API path.
809 * @runInSeparateProcess
811 public function testApiGetUserWithNumericCalledApi()
814 $called_api = ['api_path'];
815 $this->app->argv[1] = $this->otherUser['id'].'.json';
816 $this->assertOtherUser(api_get_user($this->app));
820 * Test the api_get_user() function with the $called_api global variable.
822 * @runInSeparateProcess
824 public function testApiGetUserWithCalledApi()
827 $called_api = ['api', 'api_path'];
828 $this->assertSelfUser(api_get_user($this->app));
832 * Test the api_get_user() function with a valid user.
834 * @runInSeparateProcess
836 public function testApiGetUserWithCorrectUser()
838 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
842 * Test the api_get_user() function with a wrong user ID.
844 * @runInSeparateProcess
845 * @expectedException Friendica\Network\HTTPException\BadRequestException
847 public function testApiGetUserWithWrongUser()
849 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
853 * Test the api_get_user() function with a 0 user ID.
855 * @runInSeparateProcess
857 public function testApiGetUserWithZeroUser()
859 $this->assertSelfUser(api_get_user($this->app, 0));
863 * Test the api_item_get_user() function.
865 * @runInSeparateProcess
867 public function testApiItemGetUser()
869 $users = api_item_get_user($this->app, []);
870 $this->assertSelfUser($users[0]);
874 * Test the api_item_get_user() function with a different item parent.
877 public function testApiItemGetUserWithDifferentParent()
879 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
880 $this->assertSelfUser($users[0]);
881 $this->assertEquals($users[0], $users[1]);
885 * Test the api_walk_recursive() function.
888 public function testApiWalkRecursive()
896 // Should we test this with a callback that actually does something?
904 * Test the api_walk_recursive() function with an array.
907 public function testApiWalkRecursiveWithArray()
909 $array = [['item1'], ['item2']];
915 // Should we test this with a callback that actually does something?
923 * Test the api_reformat_xml() function.
926 public function testApiReformatXml()
930 $this->assertTrue(api_reformat_xml($item, $key));
931 $this->assertEquals('true', $item);
935 * Test the api_reformat_xml() function with a statusnet_api key.
938 public function testApiReformatXmlWithStatusnetKey()
941 $key = 'statusnet_api';
942 $this->assertTrue(api_reformat_xml($item, $key));
943 $this->assertEquals('statusnet:api', $key);
947 * Test the api_reformat_xml() function with a friendica_api key.
950 public function testApiReformatXmlWithFriendicaKey()
953 $key = 'friendica_api';
954 $this->assertTrue(api_reformat_xml($item, $key));
955 $this->assertEquals('friendica:api', $key);
959 * Test the api_create_xml() function.
962 public function testApiCreateXml()
965 '<?xml version="1.0"?>'."\n".
966 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
967 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
968 'xmlns:georss="http://www.georss.org/georss">'."\n".
969 ' <data>some_data</data>'."\n".
970 '</root_element>'."\n",
971 api_create_xml(['data' => ['some_data']], 'root_element')
976 * Test the api_create_xml() function without any XML namespace.
979 public function testApiCreateXmlWithoutNamespaces()
982 '<?xml version="1.0"?>'."\n".
984 ' <data>some_data</data>'."\n".
986 api_create_xml(['data' => ['some_data']], 'ok')
991 * Test the api_format_data() function.
994 public function testApiFormatData()
996 $data = ['some_data'];
997 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1001 * Test the api_format_data() function with an XML result.
1004 public function testApiFormatDataWithXml()
1006 $this->assertEquals(
1007 '<?xml version="1.0"?>'."\n".
1008 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1009 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1010 'xmlns:georss="http://www.georss.org/georss">'."\n".
1011 ' <data>some_data</data>'."\n".
1012 '</root_element>'."\n",
1013 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1018 * Test the api_account_verify_credentials() function.
1021 public function testApiAccountVerifyCredentials()
1023 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1027 * Test the api_account_verify_credentials() function without an authenticated user.
1029 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1031 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1033 $_SESSION['authenticated'] = false;
1034 api_account_verify_credentials('json');
1038 * Test the requestdata() function.
1041 public function testRequestdata()
1043 $this->assertNull(requestdata('variable_name'));
1047 * Test the requestdata() function with a POST parameter.
1050 public function testRequestdataWithPost()
1052 $_POST['variable_name'] = 'variable_value';
1053 $this->assertEquals('variable_value', requestdata('variable_name'));
1057 * Test the requestdata() function with a GET parameter.
1060 public function testRequestdataWithGet()
1062 $_GET['variable_name'] = 'variable_value';
1063 $this->assertEquals('variable_value', requestdata('variable_name'));
1067 * Test the api_statuses_mediap() function.
1070 public function testApiStatusesMediap()
1072 $this->app->argc = 2;
1080 'tmp_name' => $this->getTempImage(),
1081 'name' => 'spacer.png',
1082 'type' => 'image/png'
1085 $_GET['status'] = '<b>Status content</b>';
1087 $result = api_statuses_mediap('json');
1088 $this->assertStatus($result['status']);
1092 * Test the api_statuses_mediap() function without an authenticated user.
1094 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1096 public function testApiStatusesMediapWithoutAuthenticatedUser()
1098 $_SESSION['authenticated'] = false;
1099 api_statuses_mediap('json');
1103 * Test the api_statuses_update() function.
1106 public function testApiStatusesUpdate()
1108 $_GET['status'] = 'Status content';
1109 $_GET['in_reply_to_status_id'] = -1;
1118 'tmp_name' => $this->getTempImage(),
1119 'name' => 'spacer.png',
1120 'type' => 'image/png'
1124 $result = api_statuses_update('json');
1125 $this->assertStatus($result['status']);
1129 * Test the api_statuses_update() function with an HTML status.
1132 public function testApiStatusesUpdateWithHtml()
1134 $_GET['htmlstatus'] = '<b>Status content</b>';
1136 $result = api_statuses_update('json');
1137 $this->assertStatus($result['status']);
1141 * Test the api_statuses_update() function without an authenticated user.
1143 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1145 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1147 $_SESSION['authenticated'] = false;
1148 api_statuses_update('json');
1152 * Test the api_statuses_update() function with a parent status.
1155 public function testApiStatusesUpdateWithParent()
1157 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1161 * Test the api_statuses_update() function with a media_ids parameter.
1164 public function testApiStatusesUpdateWithMediaIds()
1166 $this->markTestIncomplete();
1170 * Test the api_statuses_update() function with the throttle limit reached.
1173 public function testApiStatusesUpdateWithDayThrottleReached()
1175 $this->markTestIncomplete();
1179 * Test the api_media_upload() function.
1181 * @expectedException Friendica\Network\HTTPException\BadRequestException
1183 public function testApiMediaUpload()
1189 * Test the api_media_upload() function without an authenticated user.
1191 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1193 public function testApiMediaUploadWithoutAuthenticatedUser()
1195 $_SESSION['authenticated'] = false;
1200 * Test the api_media_upload() function with an invalid uploaded media.
1202 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1204 public function testApiMediaUploadWithMedia()
1215 * Test the api_media_upload() function with an valid uploaded media.
1218 public function testApiMediaUploadWithValidMedia()
1226 'tmp_name' => $this->getTempImage(),
1227 'name' => 'spacer.png',
1228 'type' => 'image/png'
1234 $result = api_media_upload();
1235 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1236 $this->assertEquals(1, $result['media']['image']['w']);
1237 $this->assertEquals(1, $result['media']['image']['h']);
1241 * Test the api_status_show() function.
1244 public function testApiStatusShow()
1246 $result = api_status_show('json');
1247 $this->assertStatus($result['status']);
1251 * Test the api_status_show() function with an XML result.
1254 public function testApiStatusShowWithXml()
1256 $result = api_status_show('xml');
1257 $this->assertXml($result, 'statuses');
1261 * Test the api_status_show() function with a raw result.
1264 public function testApiStatusShowWithRaw()
1266 $this->assertStatus(api_status_show('raw'));
1270 * Test the api_users_show() function.
1273 public function testApiUsersShow()
1275 $result = api_users_show('json');
1276 // We can't use assertSelfUser() here because the user object is missing some properties.
1277 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1278 $this->assertEquals('Friendica', $result['user']['location']);
1279 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1280 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1281 $this->assertEquals('dfrn', $result['user']['network']);
1282 $this->assertTrue($result['user']['verified']);
1286 * Test the api_users_show() function with an XML result.
1289 public function testApiUsersShowWithXml()
1291 $result = api_users_show('xml');
1292 $this->assertXml($result, 'statuses');
1296 * Test the api_users_search() function.
1299 public function testApiUsersSearch()
1301 $_GET['q'] = 'othercontact';
1302 $result = api_users_search('json');
1303 $this->assertOtherUser($result['users'][0]);
1307 * Test the api_users_search() function with an XML result.
1310 public function testApiUsersSearchWithXml()
1312 $_GET['q'] = 'othercontact';
1313 $result = api_users_search('xml');
1314 $this->assertXml($result, 'users');
1318 * Test the api_users_search() function without a GET q parameter.
1320 * @expectedException Friendica\Network\HTTPException\BadRequestException
1322 public function testApiUsersSearchWithoutQuery()
1324 api_users_search('json');
1328 * Test the api_users_lookup() function.
1330 * @expectedException Friendica\Network\HTTPException\NotFoundException
1332 public function testApiUsersLookup()
1334 api_users_lookup('json');
1338 * Test the api_users_lookup() function with an user ID.
1341 public function testApiUsersLookupWithUserId()
1343 $_REQUEST['user_id'] = $this->otherUser['id'];
1344 $result = api_users_lookup('json');
1345 $this->assertOtherUser($result['users'][0]);
1349 * Test the api_search() function.
1352 public function testApiSearch()
1354 $_REQUEST['q'] = 'reply';
1355 $_REQUEST['max_id'] = 10;
1356 $result = api_search('json');
1357 foreach ($result['status'] as $status) {
1358 $this->assertStatus($status);
1359 $this->assertContains('reply', $status['text'], null, true);
1364 * Test the api_search() function a count parameter.
1367 public function testApiSearchWithCount()
1369 $_REQUEST['q'] = 'reply';
1370 $_REQUEST['count'] = 20;
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 with an rpp parameter.
1382 public function testApiSearchWithRpp()
1384 $_REQUEST['q'] = 'reply';
1385 $_REQUEST['rpp'] = 20;
1386 $result = api_search('json');
1387 foreach ($result['status'] as $status) {
1388 $this->assertStatus($status);
1389 $this->assertContains('reply', $status['text'], null, true);
1395 * Test the api_search() function without an authenticated user.
1397 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1399 public function testApiSearchWithUnallowedUser()
1401 $_SESSION['allow_api'] = false;
1402 $_GET['screen_name'] = $this->selfUser['nick'];
1407 * Test the api_search() function without any GET query parameter.
1409 * @expectedException Friendica\Network\HTTPException\BadRequestException
1411 public function testApiSearchWithoutQuery()
1417 * Test the api_statuses_home_timeline() function.
1420 public function testApiStatusesHomeTimeline()
1422 $_REQUEST['max_id'] = 10;
1423 $_REQUEST['exclude_replies'] = true;
1424 $_REQUEST['conversation_id'] = 1;
1425 $result = api_statuses_home_timeline('json');
1426 $this->assertNotEmpty($result['status']);
1427 foreach ($result['status'] as $status) {
1428 $this->assertStatus($status);
1433 * Test the api_statuses_home_timeline() function with a negative page parameter.
1436 public function testApiStatusesHomeTimelineWithNegativePage()
1438 $_REQUEST['page'] = -2;
1439 $result = api_statuses_home_timeline('json');
1440 $this->assertNotEmpty($result['status']);
1441 foreach ($result['status'] as $status) {
1442 $this->assertStatus($status);
1447 * Test the api_statuses_home_timeline() with an unallowed user.
1449 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1451 public function testApiStatusesHomeTimelineWithUnallowedUser()
1453 $_SESSION['allow_api'] = false;
1454 $_GET['screen_name'] = $this->selfUser['nick'];
1455 api_statuses_home_timeline('json');
1459 * Test the api_statuses_home_timeline() function with an RSS result.
1462 public function testApiStatusesHomeTimelineWithRss()
1464 $result = api_statuses_home_timeline('rss');
1465 $this->assertXml($result, 'statuses');
1469 * Test the api_statuses_public_timeline() function.
1472 public function testApiStatusesPublicTimeline()
1474 $_REQUEST['max_id'] = 10;
1475 $_REQUEST['conversation_id'] = 1;
1476 $result = api_statuses_public_timeline('json');
1477 $this->assertNotEmpty($result['status']);
1478 foreach ($result['status'] as $status) {
1479 $this->assertStatus($status);
1484 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1487 public function testApiStatusesPublicTimelineWithExcludeReplies()
1489 $_REQUEST['max_id'] = 10;
1490 $_REQUEST['exclude_replies'] = true;
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 a negative page parameter.
1502 public function testApiStatusesPublicTimelineWithNegativePage()
1504 $_REQUEST['page'] = -2;
1505 $result = api_statuses_public_timeline('json');
1506 $this->assertNotEmpty($result['status']);
1507 foreach ($result['status'] as $status) {
1508 $this->assertStatus($status);
1513 * Test the api_statuses_public_timeline() function with an unallowed user.
1515 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1517 public function testApiStatusesPublicTimelineWithUnallowedUser()
1519 $_SESSION['allow_api'] = false;
1520 $_GET['screen_name'] = $this->selfUser['nick'];
1521 api_statuses_public_timeline('json');
1525 * Test the api_statuses_public_timeline() function with an RSS result.
1528 public function testApiStatusesPublicTimelineWithRss()
1530 $result = api_statuses_public_timeline('rss');
1531 $this->assertXml($result, 'statuses');
1535 * Test the api_statuses_networkpublic_timeline() function.
1538 public function testApiStatusesNetworkpublicTimeline()
1540 $_REQUEST['max_id'] = 10;
1541 $result = api_statuses_networkpublic_timeline('json');
1542 $this->assertNotEmpty($result['status']);
1543 foreach ($result['status'] as $status) {
1544 $this->assertStatus($status);
1549 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1552 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1554 $_REQUEST['page'] = -2;
1555 $result = api_statuses_networkpublic_timeline('json');
1556 $this->assertNotEmpty($result['status']);
1557 foreach ($result['status'] as $status) {
1558 $this->assertStatus($status);
1563 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1565 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1567 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1569 $_SESSION['allow_api'] = false;
1570 $_GET['screen_name'] = $this->selfUser['nick'];
1571 api_statuses_networkpublic_timeline('json');
1575 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1578 public function testApiStatusesNetworkpublicTimelineWithRss()
1580 $result = api_statuses_networkpublic_timeline('rss');
1581 $this->assertXml($result, 'statuses');
1585 * Test the api_statuses_show() function.
1587 * @expectedException Friendica\Network\HTTPException\BadRequestException
1589 public function testApiStatusesShow()
1591 api_statuses_show('json');
1595 * Test the api_statuses_show() function with an ID.
1598 public function testApiStatusesShowWithId()
1600 $this->app->argv[3] = 1;
1601 $result = api_statuses_show('json');
1602 $this->assertStatus($result['status']);
1606 * Test the api_statuses_show() function with the conversation parameter.
1609 public function testApiStatusesShowWithConversation()
1611 $this->app->argv[3] = 1;
1612 $_REQUEST['conversation'] = 1;
1613 $result = api_statuses_show('json');
1614 $this->assertNotEmpty($result['status']);
1615 foreach ($result['status'] as $status) {
1616 $this->assertStatus($status);
1621 * Test the api_statuses_show() function with an unallowed user.
1623 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1625 public function testApiStatusesShowWithUnallowedUser()
1627 $_SESSION['allow_api'] = false;
1628 $_GET['screen_name'] = $this->selfUser['nick'];
1629 api_statuses_show('json');
1633 * Test the api_conversation_show() function.
1635 * @expectedException Friendica\Network\HTTPException\BadRequestException
1637 public function testApiConversationShow()
1639 api_conversation_show('json');
1643 * Test the api_conversation_show() function with an ID.
1646 public function testApiConversationShowWithId()
1648 $this->app->argv[3] = 1;
1649 $_REQUEST['max_id'] = 10;
1650 $_REQUEST['page'] = -2;
1651 $result = api_conversation_show('json');
1652 $this->assertNotEmpty($result['status']);
1653 foreach ($result['status'] as $status) {
1654 $this->assertStatus($status);
1659 * Test the api_conversation_show() function with an unallowed user.
1661 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1663 public function testApiConversationShowWithUnallowedUser()
1665 $_SESSION['allow_api'] = false;
1666 $_GET['screen_name'] = $this->selfUser['nick'];
1667 api_conversation_show('json');
1671 * Test the api_statuses_repeat() function.
1673 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1675 public function testApiStatusesRepeat()
1677 api_statuses_repeat('json');
1681 * Test the api_statuses_repeat() function without an authenticated user.
1683 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1685 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1687 $_SESSION['authenticated'] = false;
1688 api_statuses_repeat('json');
1692 * Test the api_statuses_repeat() function with an ID.
1695 public function testApiStatusesRepeatWithId()
1697 $this->app->argv[3] = 1;
1698 $result = api_statuses_repeat('json');
1699 $this->assertStatus($result['status']);
1701 // Also test with a shared status
1702 $this->app->argv[3] = 5;
1703 $result = api_statuses_repeat('json');
1704 $this->assertStatus($result['status']);
1708 * Test the api_statuses_destroy() function.
1710 * @expectedException Friendica\Network\HTTPException\BadRequestException
1712 public function testApiStatusesDestroy()
1714 api_statuses_destroy('json');
1718 * Test the api_statuses_destroy() function without an authenticated user.
1720 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1722 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1724 $_SESSION['authenticated'] = false;
1725 api_statuses_destroy('json');
1729 * Test the api_statuses_destroy() function with an ID.
1732 public function testApiStatusesDestroyWithId()
1734 $this->app->argv[3] = 1;
1735 $result = api_statuses_destroy('json');
1736 $this->assertStatus($result['status']);
1740 * Test the api_statuses_mentions() function.
1743 public function testApiStatusesMentions()
1745 $this->app->user = ['nickname' => $this->selfUser['nick']];
1746 $_REQUEST['max_id'] = 10;
1747 $result = api_statuses_mentions('json');
1748 $this->assertEmpty($result['status']);
1749 // We should test with mentions in the database.
1753 * Test the api_statuses_mentions() function with a negative page parameter.
1756 public function testApiStatusesMentionsWithNegativePage()
1758 $_REQUEST['page'] = -2;
1759 $result = api_statuses_mentions('json');
1760 $this->assertEmpty($result['status']);
1764 * Test the api_statuses_mentions() function with an unallowed user.
1766 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1768 public function testApiStatusesMentionsWithUnallowedUser()
1770 $_SESSION['allow_api'] = false;
1771 $_GET['screen_name'] = $this->selfUser['nick'];
1772 api_statuses_mentions('json');
1776 * Test the api_statuses_mentions() function with an RSS result.
1779 public function testApiStatusesMentionsWithRss()
1781 $result = api_statuses_mentions('rss');
1782 $this->assertXml($result, 'statuses');
1786 * Test the api_statuses_user_timeline() function.
1789 public function testApiStatusesUserTimeline()
1791 $_REQUEST['max_id'] = 10;
1792 $_REQUEST['exclude_replies'] = true;
1793 $_REQUEST['conversation_id'] = 1;
1794 $result = api_statuses_user_timeline('json');
1795 $this->assertNotEmpty($result['status']);
1796 foreach ($result['status'] as $status) {
1797 $this->assertStatus($status);
1802 * Test the api_statuses_user_timeline() function with a negative page parameter.
1805 public function testApiStatusesUserTimelineWithNegativePage()
1807 $_REQUEST['page'] = -2;
1808 $result = api_statuses_user_timeline('json');
1809 $this->assertNotEmpty($result['status']);
1810 foreach ($result['status'] as $status) {
1811 $this->assertStatus($status);
1816 * Test the api_statuses_user_timeline() function with an RSS result.
1819 public function testApiStatusesUserTimelineWithRss()
1821 $result = api_statuses_user_timeline('rss');
1822 $this->assertXml($result, 'statuses');
1826 * Test the api_statuses_user_timeline() function with an unallowed user.
1828 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1830 public function testApiStatusesUserTimelineWithUnallowedUser()
1832 $_SESSION['allow_api'] = false;
1833 $_GET['screen_name'] = $this->selfUser['nick'];
1834 api_statuses_user_timeline('json');
1838 * Test the api_favorites_create_destroy() function.
1840 * @expectedException Friendica\Network\HTTPException\BadRequestException
1842 public function testApiFavoritesCreateDestroy()
1844 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1845 $this->app->argc = count($this->app->argv);
1846 api_favorites_create_destroy('json');
1850 * Test the api_favorites_create_destroy() function with an invalid ID.
1852 * @expectedException Friendica\Network\HTTPException\BadRequestException
1854 public function testApiFavoritesCreateDestroyWithInvalidId()
1856 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1857 $this->app->argc = count($this->app->argv);
1858 api_favorites_create_destroy('json');
1862 * Test the api_favorites_create_destroy() function with an invalid action.
1864 * @expectedException Friendica\Network\HTTPException\BadRequestException
1866 public function testApiFavoritesCreateDestroyWithInvalidAction()
1868 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1869 $this->app->argc = count($this->app->argv);
1870 $_REQUEST['id'] = 1;
1871 api_favorites_create_destroy('json');
1875 * Test the api_favorites_create_destroy() function with the create action.
1878 public function testApiFavoritesCreateDestroyWithCreateAction()
1880 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1881 $this->app->argc = count($this->app->argv);
1882 $_REQUEST['id'] = 3;
1883 $result = api_favorites_create_destroy('json');
1884 $this->assertStatus($result['status']);
1888 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1891 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1893 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1894 $this->app->argc = count($this->app->argv);
1895 $_REQUEST['id'] = 3;
1896 $result = api_favorites_create_destroy('rss');
1897 $this->assertXml($result, 'status');
1901 * Test the api_favorites_create_destroy() function with the destroy action.
1904 public function testApiFavoritesCreateDestroyWithDestroyAction()
1906 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1907 $this->app->argc = count($this->app->argv);
1908 $_REQUEST['id'] = 3;
1909 $result = api_favorites_create_destroy('json');
1910 $this->assertStatus($result['status']);
1914 * Test the api_favorites_create_destroy() function without an authenticated user.
1916 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1918 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1920 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1921 $this->app->argc = count($this->app->argv);
1922 $_SESSION['authenticated'] = false;
1923 api_favorites_create_destroy('json');
1927 * Test the api_favorites() function.
1930 public function testApiFavorites()
1932 $_REQUEST['page'] = -1;
1933 $_REQUEST['max_id'] = 10;
1934 $result = api_favorites('json');
1935 foreach ($result['status'] as $status) {
1936 $this->assertStatus($status);
1941 * Test the api_favorites() function with an RSS result.
1944 public function testApiFavoritesWithRss()
1946 $result = api_favorites('rss');
1947 $this->assertXml($result, 'statuses');
1951 * Test the api_favorites() function with an unallowed user.
1953 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1955 public function testApiFavoritesWithUnallowedUser()
1957 $_SESSION['allow_api'] = false;
1958 $_GET['screen_name'] = $this->selfUser['nick'];
1959 api_favorites('json');
1963 * Test the api_format_messages() function.
1966 public function testApiFormatMessages()
1968 $result = api_format_messages(
1969 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1970 ['id' => 2, 'screen_name' => 'recipient_name'],
1971 ['id' => 3, 'screen_name' => 'sender_name']
1973 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1974 $this->assertEquals(1, $result['id']);
1975 $this->assertEquals(2, $result['recipient_id']);
1976 $this->assertEquals(3, $result['sender_id']);
1977 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1978 $this->assertEquals('sender_name', $result['sender_screen_name']);
1982 * Test the api_format_messages() function with HTML.
1985 public function testApiFormatMessagesWithHtmlText()
1987 $_GET['getText'] = 'html';
1988 $result = api_format_messages(
1989 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1990 ['id' => 2, 'screen_name' => 'recipient_name'],
1991 ['id' => 3, 'screen_name' => 'sender_name']
1993 $this->assertEquals('item_title', $result['title']);
1994 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1998 * Test the api_format_messages() function with plain text.
2001 public function testApiFormatMessagesWithPlainText()
2003 $_GET['getText'] = 'plain';
2004 $result = api_format_messages(
2005 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2006 ['id' => 2, 'screen_name' => 'recipient_name'],
2007 ['id' => 3, 'screen_name' => 'sender_name']
2009 $this->assertEquals('item_title', $result['title']);
2010 $this->assertEquals('item_body', $result['text']);
2014 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2017 public function testApiFormatMessagesWithoutUserObjects()
2019 $_GET['getUserObjects'] = 'false';
2020 $result = api_format_messages(
2021 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2022 ['id' => 2, 'screen_name' => 'recipient_name'],
2023 ['id' => 3, 'screen_name' => 'sender_name']
2025 $this->assertTrue(!isset($result['sender']));
2026 $this->assertTrue(!isset($result['recipient']));
2030 * Test the api_convert_item() function.
2033 public function testApiConvertItem()
2035 $result = api_convert_item(
2037 'network' => 'feed',
2038 'title' => 'item_title',
2039 // We need a long string to test that it is correctly cut
2040 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2041 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2042 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2043 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2044 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2045 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2046 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2047 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2048 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2049 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2050 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2051 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2052 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2053 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2054 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2055 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2056 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2057 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2058 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2059 'repellat officia illum quos impedit quam iste esse unde qui '.
2060 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2061 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2062 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2063 'plink' => 'item_plink'
2066 $this->assertStringStartsWith('item_title', $result['text']);
2067 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2071 * Test the api_convert_item() function with an empty item body.
2074 public function testApiConvertItemWithoutBody()
2076 $result = api_convert_item(
2078 'network' => 'feed',
2079 'title' => 'item_title',
2081 'plink' => 'item_plink'
2084 $this->assertEquals('item_title', $result['text']);
2085 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2089 * Test the api_convert_item() function with the title in the body.
2092 public function testApiConvertItemWithTitleInBody()
2094 $result = api_convert_item(
2096 'title' => 'item_title',
2097 'body' => 'item_title item_body'
2100 $this->assertEquals('item_title item_body', $result['text']);
2101 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2105 * Test the api_get_attachments() function.
2108 public function testApiGetAttachments()
2111 $this->assertEmpty(api_get_attachments($body));
2115 * Test the api_get_attachments() function with an img tag.
2118 public function testApiGetAttachmentsWithImage()
2120 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2121 $this->assertInternalType('array', api_get_attachments($body));
2125 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2128 public function testApiGetAttachmentsWithImageAndAndStatus()
2130 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2131 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2132 $this->assertInternalType('array', api_get_attachments($body));
2136 * Test the api_get_entitities() function.
2139 public function testApiGetEntitities()
2142 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2146 * Test the api_get_entitities() function with the include_entities parameter.
2149 public function testApiGetEntititiesWithIncludeEntities()
2151 $_REQUEST['include_entities'] = 'true';
2153 $result = api_get_entitities($text, 'bbcode');
2154 $this->assertInternalType('array', $result['hashtags']);
2155 $this->assertInternalType('array', $result['symbols']);
2156 $this->assertInternalType('array', $result['urls']);
2157 $this->assertInternalType('array', $result['user_mentions']);
2161 * Test the api_format_items_embeded_images() function.
2164 public function testApiFormatItemsEmbededImages()
2166 $this->assertEquals(
2167 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
2168 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2173 * Test the api_contactlink_to_array() function.
2176 public function testApiContactlinkToArray()
2178 $this->assertEquals(
2183 api_contactlink_to_array('text')
2188 * Test the api_contactlink_to_array() function with an URL.
2191 public function testApiContactlinkToArrayWithUrl()
2193 $this->assertEquals(
2195 'name' => ['link_text'],
2198 api_contactlink_to_array('text <a href="url">link_text</a>')
2203 * Test the api_format_items_activities() function.
2206 public function testApiFormatItemsActivities()
2208 $item = ['uid' => 0, 'uri' => ''];
2209 $result = api_format_items_activities($item);
2210 $this->assertArrayHasKey('like', $result);
2211 $this->assertArrayHasKey('dislike', $result);
2212 $this->assertArrayHasKey('attendyes', $result);
2213 $this->assertArrayHasKey('attendno', $result);
2214 $this->assertArrayHasKey('attendmaybe', $result);
2218 * Test the api_format_items_activities() function with an XML result.
2221 public function testApiFormatItemsActivitiesWithXml()
2223 $item = ['uid' => 0, 'uri' => ''];
2224 $result = api_format_items_activities($item, 'xml');
2225 $this->assertArrayHasKey('friendica:like', $result);
2226 $this->assertArrayHasKey('friendica:dislike', $result);
2227 $this->assertArrayHasKey('friendica:attendyes', $result);
2228 $this->assertArrayHasKey('friendica:attendno', $result);
2229 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2233 * Test the api_format_items_profiles() function.
2236 public function testApiFormatItemsProfiles()
2239 'id' => 'profile_id',
2240 'profile-name' => 'profile_name',
2241 'is-default' => true,
2242 'hide-friends' => true,
2243 'photo' => 'profile_photo',
2244 'thumb' => 'profile_thumb',
2246 'net-publish' => true,
2247 'pdesc' => 'description',
2248 'dob' => 'date_of_birth',
2249 'address' => 'address',
2250 'locality' => 'city',
2251 'region' => 'region',
2252 'postal-code' => 'postal_code',
2253 'country-name' => 'country',
2254 'hometown' => 'hometown',
2255 'gender' => 'gender',
2256 'marital' => 'marital',
2257 'with' => 'marital_with',
2258 'howlong' => 'marital_since',
2259 'sexual' => 'sexual',
2260 'politic' => 'politic',
2261 'religion' => 'religion',
2262 'pub_keywords' => 'public_keywords',
2263 'prv_keywords' => 'private_keywords',
2266 'dislikes' => 'dislikes',
2272 'interest' => 'interest',
2273 'romance' => 'romance',
2275 'education' => 'education',
2276 'contact' => 'social_networks',
2277 'homepage' => 'homepage'
2279 $result = api_format_items_profiles($profile_row);
2280 $this->assertEquals(
2282 'profile_id' => 'profile_id',
2283 'profile_name' => 'profile_name',
2284 'is_default' => true,
2285 'hide_friends' => true,
2286 'profile_photo' => 'profile_photo',
2287 'profile_thumb' => 'profile_thumb',
2289 'net_publish' => true,
2290 'description' => 'description',
2291 'date_of_birth' => 'date_of_birth',
2292 'address' => 'address',
2294 'region' => 'region',
2295 'postal_code' => 'postal_code',
2296 'country' => 'country',
2297 'hometown' => 'hometown',
2298 'gender' => 'gender',
2299 'marital' => 'marital',
2300 'marital_with' => 'marital_with',
2301 'marital_since' => 'marital_since',
2302 'sexual' => 'sexual',
2303 'politic' => 'politic',
2304 'religion' => 'religion',
2305 'public_keywords' => 'public_keywords',
2306 'private_keywords' => 'private_keywords',
2309 'dislikes' => 'dislikes',
2315 'interest' => 'interest',
2316 'romance' => 'romance',
2318 'education' => 'education',
2319 'social_networks' => 'social_networks',
2320 'homepage' => 'homepage',
2328 * Test the api_format_items() function.
2331 public function testApiFormatItems()
2335 'item_network' => 'item_network',
2341 'author-network' => \Friendica\Core\Protocol::DFRN,
2342 'author-link' => 'http://localhost/profile/othercontact',
2346 $result = api_format_items($items, ['id' => 0], true);
2347 foreach ($result as $status) {
2348 $this->assertStatus($status);
2353 * Test the api_format_items() function with an XML result.
2356 public function testApiFormatItemsWithXml()
2364 'author-network' => \Friendica\Core\Protocol::DFRN,
2365 'author-link' => 'http://localhost/profile/othercontact',
2369 $result = api_format_items($items, ['id' => 0], true, 'xml');
2370 foreach ($result as $status) {
2371 $this->assertStatus($status);
2376 * Test the api_format_items() function.
2379 public function testApiAccountRateLimitStatus()
2381 $result = api_account_rate_limit_status('json');
2382 $this->assertEquals(150, $result['hash']['remaining_hits']);
2383 $this->assertEquals(150, $result['hash']['hourly_limit']);
2384 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2388 * Test the api_format_items() function with an XML result.
2391 public function testApiAccountRateLimitStatusWithXml()
2393 $result = api_account_rate_limit_status('xml');
2394 $this->assertXml($result, 'hash');
2398 * Test the api_help_test() function.
2401 public function testApiHelpTest()
2403 $result = api_help_test('json');
2404 $this->assertEquals(['ok' => 'ok'], $result);
2408 * Test the api_help_test() function with an XML result.
2411 public function testApiHelpTestWithXml()
2413 $result = api_help_test('xml');
2414 $this->assertXml($result, 'ok');
2418 * Test the api_lists_list() function.
2421 public function testApiListsList()
2423 $result = api_lists_list('json');
2424 $this->assertEquals(['lists_list' => []], $result);
2428 * Test the api_lists_ownerships() function.
2431 public function testApiListsOwnerships()
2433 $result = api_lists_ownerships('json');
2434 foreach ($result['lists']['lists'] as $list) {
2435 $this->assertList($list);
2440 * Test the api_lists_ownerships() function without an authenticated user.
2442 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2444 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2446 $_SESSION['authenticated'] = false;
2447 api_lists_ownerships('json');
2451 * Test the api_lists_statuses() function.
2452 * @expectedException Friendica\Network\HTTPException\BadRequestException
2455 public function testApiListsStatuses()
2457 api_lists_statuses('json');
2461 * Test the api_lists_statuses() function with a list ID.
2464 public function testApiListsStatusesWithListId()
2466 $_REQUEST['list_id'] = 1;
2467 $_REQUEST['page'] = -1;
2468 $_REQUEST['max_id'] = 10;
2469 $result = api_lists_statuses('json');
2470 foreach ($result['status'] as $status) {
2471 $this->assertStatus($status);
2476 * Test the api_lists_statuses() function with a list ID and a RSS result.
2479 public function testApiListsStatusesWithListIdAndRss()
2481 $_REQUEST['list_id'] = 1;
2482 $result = api_lists_statuses('rss');
2483 $this->assertXml($result, 'statuses');
2487 * Test the api_lists_statuses() function with an unallowed user.
2489 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2491 public function testApiListsStatusesWithUnallowedUser()
2493 $_SESSION['allow_api'] = false;
2494 $_GET['screen_name'] = $this->selfUser['nick'];
2495 api_lists_statuses('json');
2499 * Test the api_statuses_f() function.
2502 public function testApiStatusesFWithFriends()
2505 $result = api_statuses_f('friends');
2506 $this->assertArrayHasKey('user', $result);
2510 * Test the api_statuses_f() function.
2513 public function testApiStatusesFWithFollowers()
2515 $result = api_statuses_f('followers');
2516 $this->assertArrayHasKey('user', $result);
2520 * Test the api_statuses_f() function.
2523 public function testApiStatusesFWithBlocks()
2525 $result = api_statuses_f('blocks');
2526 $this->assertArrayHasKey('user', $result);
2530 * Test the api_statuses_f() function.
2533 public function testApiStatusesFWithIncoming()
2535 $result = api_statuses_f('incoming');
2536 $this->assertArrayHasKey('user', $result);
2540 * Test the api_statuses_f() function an undefined cursor GET variable.
2543 public function testApiStatusesFWithUndefinedCursor()
2545 $_GET['cursor'] = 'undefined';
2546 $this->assertFalse(api_statuses_f('friends'));
2550 * Test the api_statuses_friends() function.
2553 public function testApiStatusesFriends()
2555 $result = api_statuses_friends('json');
2556 $this->assertArrayHasKey('user', $result);
2560 * Test the api_statuses_friends() function an undefined cursor GET variable.
2563 public function testApiStatusesFriendsWithUndefinedCursor()
2565 $_GET['cursor'] = 'undefined';
2566 $this->assertFalse(api_statuses_friends('json'));
2570 * Test the api_statuses_followers() function.
2573 public function testApiStatusesFollowers()
2575 $result = api_statuses_followers('json');
2576 $this->assertArrayHasKey('user', $result);
2580 * Test the api_statuses_followers() function an undefined cursor GET variable.
2583 public function testApiStatusesFollowersWithUndefinedCursor()
2585 $_GET['cursor'] = 'undefined';
2586 $this->assertFalse(api_statuses_followers('json'));
2590 * Test the api_blocks_list() function.
2593 public function testApiBlocksList()
2595 $result = api_blocks_list('json');
2596 $this->assertArrayHasKey('user', $result);
2600 * Test the api_blocks_list() function an undefined cursor GET variable.
2603 public function testApiBlocksListWithUndefinedCursor()
2605 $_GET['cursor'] = 'undefined';
2606 $this->assertFalse(api_blocks_list('json'));
2610 * Test the api_friendships_incoming() function.
2613 public function testApiFriendshipsIncoming()
2615 $result = api_friendships_incoming('json');
2616 $this->assertArrayHasKey('id', $result);
2620 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2623 public function testApiFriendshipsIncomingWithUndefinedCursor()
2625 $_GET['cursor'] = 'undefined';
2626 $this->assertFalse(api_friendships_incoming('json'));
2630 * Test the api_statusnet_config() function.
2633 public function testApiStatusnetConfig()
2635 $result = api_statusnet_config('json');
2636 $this->assertEquals('localhost', $result['config']['site']['server']);
2637 $this->assertEquals('default', $result['config']['site']['theme']);
2638 $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2639 $this->assertTrue($result['config']['site']['fancy']);
2640 $this->assertEquals('en', $result['config']['site']['language']);
2641 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2642 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2643 $this->assertEquals('false', $result['config']['site']['private']);
2644 $this->assertEquals('false', $result['config']['site']['ssl']);
2645 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2649 * Test the api_statusnet_version() function.
2652 public function testApiStatusnetVersion()
2654 $result = api_statusnet_version('json');
2655 $this->assertEquals('0.9.7', $result['version']);
2659 * Test the api_ff_ids() function.
2662 public function testApiFfIds()
2664 $result = api_ff_ids('json');
2665 $this->assertNull($result);
2669 * Test the api_ff_ids() function with a result.
2672 public function testApiFfIdsWithResult()
2674 $this->markTestIncomplete();
2678 * Test the api_ff_ids() function without an authenticated user.
2680 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2682 public function testApiFfIdsWithoutAuthenticatedUser()
2684 $_SESSION['authenticated'] = false;
2689 * Test the api_friends_ids() function.
2692 public function testApiFriendsIds()
2694 $result = api_friends_ids('json');
2695 $this->assertNull($result);
2699 * Test the api_followers_ids() function.
2702 public function testApiFollowersIds()
2704 $result = api_followers_ids('json');
2705 $this->assertNull($result);
2709 * Test the api_direct_messages_new() function.
2712 public function testApiDirectMessagesNew()
2714 $result = api_direct_messages_new('json');
2715 $this->assertNull($result);
2719 * Test the api_direct_messages_new() function without an authenticated user.
2721 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2723 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2725 $_SESSION['authenticated'] = false;
2726 api_direct_messages_new('json');
2730 * Test the api_direct_messages_new() function with an user ID.
2733 public function testApiDirectMessagesNewWithUserId()
2735 $_POST['text'] = 'message_text';
2736 $_POST['user_id'] = $this->otherUser['id'];
2737 $result = api_direct_messages_new('json');
2738 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2742 * Test the api_direct_messages_new() function with a screen name.
2745 public function testApiDirectMessagesNewWithScreenName()
2747 $_POST['text'] = 'message_text';
2748 $_POST['screen_name'] = $this->friendUser['nick'];
2749 $result = api_direct_messages_new('json');
2750 $this->assertEquals(1, $result['direct_message']['id']);
2751 $this->assertContains('message_text', $result['direct_message']['text']);
2752 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2753 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2757 * Test the api_direct_messages_new() function with a title.
2760 public function testApiDirectMessagesNewWithTitle()
2762 $_POST['text'] = 'message_text';
2763 $_POST['screen_name'] = $this->friendUser['nick'];
2764 $_REQUEST['title'] = 'message_title';
2765 $result = api_direct_messages_new('json');
2766 $this->assertEquals(1, $result['direct_message']['id']);
2767 $this->assertContains('message_text', $result['direct_message']['text']);
2768 $this->assertContains('message_title', $result['direct_message']['text']);
2769 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2770 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2774 * Test the api_direct_messages_new() function with an RSS result.
2777 public function testApiDirectMessagesNewWithRss()
2779 $_POST['text'] = 'message_text';
2780 $_POST['screen_name'] = $this->friendUser['nick'];
2781 $result = api_direct_messages_new('rss');
2782 $this->assertXml($result, 'direct-messages');
2786 * Test the api_direct_messages_destroy() function.
2788 * @expectedException Friendica\Network\HTTPException\BadRequestException
2790 public function testApiDirectMessagesDestroy()
2792 api_direct_messages_destroy('json');
2796 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2799 public function testApiDirectMessagesDestroyWithVerbose()
2801 $_GET['friendica_verbose'] = 'true';
2802 $result = api_direct_messages_destroy('json');
2803 $this->assertEquals(
2806 'result' => 'error',
2807 'message' => 'message id or parenturi not specified'
2815 * Test the api_direct_messages_destroy() function without an authenticated user.
2817 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2819 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2821 $_SESSION['authenticated'] = false;
2822 api_direct_messages_destroy('json');
2826 * Test the api_direct_messages_destroy() function with a non-zero ID.
2828 * @expectedException Friendica\Network\HTTPException\BadRequestException
2830 public function testApiDirectMessagesDestroyWithId()
2832 $_REQUEST['id'] = 1;
2833 api_direct_messages_destroy('json');
2837 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2840 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2842 $_REQUEST['id'] = 1;
2843 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2844 $_GET['friendica_verbose'] = 'true';
2845 $result = api_direct_messages_destroy('json');
2846 $this->assertEquals(
2849 'result' => 'error',
2850 'message' => 'message id not in database'
2858 * Test the api_direct_messages_destroy() function with a non-zero ID.
2861 public function testApiDirectMessagesDestroyWithCorrectId()
2863 $this->markTestIncomplete('We need to add a dataset for this.');
2867 * Test the api_direct_messages_box() function.
2870 public function testApiDirectMessagesBoxWithSentbox()
2872 $_REQUEST['page'] = -1;
2873 $_REQUEST['max_id'] = 10;
2874 $result = api_direct_messages_box('json', 'sentbox', 'false');
2875 $this->assertArrayHasKey('direct_message', $result);
2879 * Test the api_direct_messages_box() function.
2882 public function testApiDirectMessagesBoxWithConversation()
2884 $result = api_direct_messages_box('json', 'conversation', 'false');
2885 $this->assertArrayHasKey('direct_message', $result);
2889 * Test the api_direct_messages_box() function.
2892 public function testApiDirectMessagesBoxWithAll()
2894 $result = api_direct_messages_box('json', 'all', 'false');
2895 $this->assertArrayHasKey('direct_message', $result);
2899 * Test the api_direct_messages_box() function.
2902 public function testApiDirectMessagesBoxWithInbox()
2904 $result = api_direct_messages_box('json', 'inbox', 'false');
2905 $this->assertArrayHasKey('direct_message', $result);
2909 * Test the api_direct_messages_box() function.
2912 public function testApiDirectMessagesBoxWithVerbose()
2914 $result = api_direct_messages_box('json', 'sentbox', 'true');
2915 $this->assertEquals(
2918 'result' => 'error',
2919 'message' => 'no mails available'
2927 * Test the api_direct_messages_box() function with a RSS result.
2930 public function testApiDirectMessagesBoxWithRss()
2932 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2933 $this->assertXml($result, 'direct-messages');
2937 * Test the api_direct_messages_box() function without an authenticated user.
2939 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2941 public function testApiDirectMessagesBoxWithUnallowedUser()
2943 $_SESSION['allow_api'] = false;
2944 $_GET['screen_name'] = $this->selfUser['nick'];
2945 api_direct_messages_box('json', 'sentbox', 'false');
2949 * Test the api_direct_messages_sentbox() function.
2952 public function testApiDirectMessagesSentbox()
2954 $result = api_direct_messages_sentbox('json');
2955 $this->assertArrayHasKey('direct_message', $result);
2959 * Test the api_direct_messages_inbox() function.
2962 public function testApiDirectMessagesInbox()
2964 $result = api_direct_messages_inbox('json');
2965 $this->assertArrayHasKey('direct_message', $result);
2969 * Test the api_direct_messages_all() function.
2972 public function testApiDirectMessagesAll()
2974 $result = api_direct_messages_all('json');
2975 $this->assertArrayHasKey('direct_message', $result);
2979 * Test the api_direct_messages_conversation() function.
2982 public function testApiDirectMessagesConversation()
2984 $result = api_direct_messages_conversation('json');
2985 $this->assertArrayHasKey('direct_message', $result);
2989 * Test the api_oauth_request_token() function.
2992 public function testApiOauthRequestToken()
2994 $this->markTestIncomplete('killme() kills phpunit as well');
2998 * Test the api_oauth_access_token() function.
3001 public function testApiOauthAccessToken()
3003 $this->markTestIncomplete('killme() kills phpunit as well');
3007 * Test the api_fr_photoalbum_delete() function.
3009 * @expectedException Friendica\Network\HTTPException\BadRequestException
3011 public function testApiFrPhotoalbumDelete()
3013 api_fr_photoalbum_delete('json');
3017 * Test the api_fr_photoalbum_delete() function with an album name.
3019 * @expectedException Friendica\Network\HTTPException\BadRequestException
3021 public function testApiFrPhotoalbumDeleteWithAlbum()
3023 $_REQUEST['album'] = 'album_name';
3024 api_fr_photoalbum_delete('json');
3028 * Test the api_fr_photoalbum_delete() function with an album name.
3031 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3033 $this->markTestIncomplete('We need to add a dataset for this.');
3037 * Test the api_fr_photoalbum_delete() function.
3039 * @expectedException Friendica\Network\HTTPException\BadRequestException
3041 public function testApiFrPhotoalbumUpdate()
3043 api_fr_photoalbum_update('json');
3047 * Test the api_fr_photoalbum_delete() function with an album name.
3049 * @expectedException Friendica\Network\HTTPException\BadRequestException
3051 public function testApiFrPhotoalbumUpdateWithAlbum()
3053 $_REQUEST['album'] = 'album_name';
3054 api_fr_photoalbum_update('json');
3058 * Test the api_fr_photoalbum_delete() function with an album name.
3060 * @expectedException Friendica\Network\HTTPException\BadRequestException
3062 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3064 $_REQUEST['album'] = 'album_name';
3065 $_REQUEST['album_new'] = 'album_name';
3066 api_fr_photoalbum_update('json');
3070 * Test the api_fr_photoalbum_update() function without an authenticated user.
3072 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3074 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3076 $_SESSION['authenticated'] = false;
3077 api_fr_photoalbum_update('json');
3081 * Test the api_fr_photoalbum_delete() function with an album name.
3084 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3086 $this->markTestIncomplete('We need to add a dataset for this.');
3090 * Test the api_fr_photos_list() function.
3093 public function testApiFrPhotosList()
3095 $result = api_fr_photos_list('json');
3096 $this->assertArrayHasKey('photo', $result);
3100 * Test the api_fr_photos_list() function without an authenticated user.
3102 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3104 public function testApiFrPhotosListWithoutAuthenticatedUser()
3106 $_SESSION['authenticated'] = false;
3107 api_fr_photos_list('json');
3111 * Test the api_fr_photo_create_update() function.
3113 * @expectedException Friendica\Network\HTTPException\BadRequestException
3115 public function testApiFrPhotoCreateUpdate()
3117 api_fr_photo_create_update('json');
3121 * Test the api_fr_photo_create_update() function without an authenticated user.
3123 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3125 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3127 $_SESSION['authenticated'] = false;
3128 api_fr_photo_create_update('json');
3132 * Test the api_fr_photo_create_update() function with an album name.
3134 * @expectedException Friendica\Network\HTTPException\BadRequestException
3136 public function testApiFrPhotoCreateUpdateWithAlbum()
3138 $_REQUEST['album'] = 'album_name';
3139 api_fr_photo_create_update('json');
3143 * Test the api_fr_photo_create_update() function with the update mode.
3146 public function testApiFrPhotoCreateUpdateWithUpdate()
3148 $this->markTestIncomplete('We need to create a dataset for this');
3152 * Test the api_fr_photo_create_update() function with an uploaded file.
3155 public function testApiFrPhotoCreateUpdateWithFile()
3157 $this->markTestIncomplete();
3161 * Test the api_fr_photo_delete() function.
3163 * @expectedException Friendica\Network\HTTPException\BadRequestException
3165 public function testApiFrPhotoDelete()
3167 api_fr_photo_delete('json');
3171 * Test the api_fr_photo_delete() function without an authenticated user.
3173 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3175 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3177 $_SESSION['authenticated'] = false;
3178 api_fr_photo_delete('json');
3182 * Test the api_fr_photo_delete() function with a photo ID.
3184 * @expectedException Friendica\Network\HTTPException\BadRequestException
3186 public function testApiFrPhotoDeleteWithPhotoId()
3188 $_REQUEST['photo_id'] = 1;
3189 api_fr_photo_delete('json');
3193 * Test the api_fr_photo_delete() function with a correct photo ID.
3196 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3198 $this->markTestIncomplete('We need to create a dataset for this.');
3202 * Test the api_fr_photo_detail() function.
3204 * @expectedException Friendica\Network\HTTPException\BadRequestException
3206 public function testApiFrPhotoDetail()
3208 api_fr_photo_detail('json');
3212 * Test the api_fr_photo_detail() function without an authenticated user.
3214 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3216 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3218 $_SESSION['authenticated'] = false;
3219 api_fr_photo_detail('json');
3223 * Test the api_fr_photo_detail() function with a photo ID.
3225 * @expectedException Friendica\Network\HTTPException\NotFoundException
3227 public function testApiFrPhotoDetailWithPhotoId()
3229 $_REQUEST['photo_id'] = 1;
3230 api_fr_photo_detail('json');
3234 * Test the api_fr_photo_detail() function with a correct photo ID.
3237 public function testApiFrPhotoDetailCorrectPhotoId()
3239 $this->markTestIncomplete('We need to create a dataset for this.');
3243 * Test the api_account_update_profile_image() function.
3245 * @expectedException Friendica\Network\HTTPException\BadRequestException
3247 public function testApiAccountUpdateProfileImage()
3249 api_account_update_profile_image('json');
3253 * Test the api_account_update_profile_image() function without an authenticated user.
3255 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3257 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3259 $_SESSION['authenticated'] = false;
3260 api_account_update_profile_image('json');
3264 * Test the api_account_update_profile_image() function with an uploaded file.
3266 * @expectedException Friendica\Network\HTTPException\BadRequestException
3268 public function testApiAccountUpdateProfileImageWithUpload()
3270 $this->markTestIncomplete();
3275 * Test the api_account_update_profile() function.
3278 public function testApiAccountUpdateProfile()
3280 $_POST['name'] = 'new_name';
3281 $_POST['description'] = 'new_description';
3282 $result = api_account_update_profile('json');
3283 // We can't use assertSelfUser() here because the user object is missing some properties.
3284 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3285 $this->assertEquals('Friendica', $result['user']['location']);
3286 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3287 $this->assertEquals('dfrn', $result['user']['network']);
3288 $this->assertEquals('new_name', $result['user']['name']);
3289 $this->assertEquals('new_description', $result['user']['description']);
3293 * Test the check_acl_input() function.
3296 public function testCheckAclInput()
3298 $result = check_acl_input('<aclstring>');
3299 // Where does this result come from?
3300 $this->assertEquals(1, $result);
3304 * Test the check_acl_input() function with an empty ACL string.
3307 public function testCheckAclInputWithEmptyAclString()
3309 $result = check_acl_input(' ');
3310 $this->assertFalse($result);
3314 * Test the save_media_to_database() function.
3317 public function testSaveMediaToDatabase()
3319 $this->markTestIncomplete();
3323 * Test the post_photo_item() function.
3326 public function testPostPhotoItem()
3328 $this->markTestIncomplete();
3332 * Test the prepare_photo_data() function.
3335 public function testPreparePhotoData()
3337 $this->markTestIncomplete();
3341 * Test the api_friendica_remoteauth() function.
3343 * @expectedException Friendica\Network\HTTPException\BadRequestException
3345 public function testApiFriendicaRemoteauth()
3347 api_friendica_remoteauth();
3351 * Test the api_friendica_remoteauth() function with an URL.
3353 * @expectedException Friendica\Network\HTTPException\BadRequestException
3355 public function testApiFriendicaRemoteauthWithUrl()
3357 $_GET['url'] = 'url';
3358 $_GET['c_url'] = 'url';
3359 api_friendica_remoteauth();
3363 * Test the api_friendica_remoteauth() function with a correct URL.
3366 public function testApiFriendicaRemoteauthWithCorrectUrl()
3368 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3369 $_GET['url'] = 'url';
3370 $_GET['c_url'] = $this->selfUser['nurl'];
3371 api_friendica_remoteauth();
3375 * Test the api_share_as_retweet() function.
3378 public function testApiShareAsRetweet()
3380 $item = ['body' => ''];
3381 $result = api_share_as_retweet($item);
3382 $this->assertFalse($result);
3386 * Test the api_share_as_retweet() function with a valid item.
3389 public function testApiShareAsRetweetWithValidItem()
3391 $this->markTestIncomplete();
3395 * Test the api_get_nick() function.
3398 public function testApiGetNick()
3400 $result = api_get_nick($this->otherUser['nurl']);
3401 $this->assertEquals('othercontact', $result);
3405 * Test the api_get_nick() function with a wrong URL.
3408 public function testApiGetNickWithWrongUrl()
3410 $result = api_get_nick('wrong_url');
3411 $this->assertFalse($result);
3415 * Test the api_in_reply_to() function.
3418 public function testApiInReplyTo()
3420 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3421 $this->assertArrayHasKey('status_id', $result);
3422 $this->assertArrayHasKey('user_id', $result);
3423 $this->assertArrayHasKey('status_id_str', $result);
3424 $this->assertArrayHasKey('user_id_str', $result);
3425 $this->assertArrayHasKey('screen_name', $result);
3429 * Test the api_in_reply_to() function with a valid item.
3432 public function testApiInReplyToWithValidItem()
3434 $this->markTestIncomplete();
3438 * Test the api_clean_plain_items() function.
3441 public function testApiCleanPlainItems()
3443 $_REQUEST['include_entities'] = 'true';
3444 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3445 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3449 * Test the api_clean_attachments() function.
3452 public function testApiCleanAttachments()
3454 $this->markTestIncomplete();
3458 * Test the api_best_nickname() function.
3461 public function testApiBestNickname()
3464 $result = api_best_nickname($contacts);
3465 $this->assertNull($result);
3469 * Test the api_best_nickname() function with contacts.
3472 public function testApiBestNicknameWithContacts()
3474 $this->markTestIncomplete();
3478 * Test the api_friendica_group_show() function.
3481 public function testApiFriendicaGroupShow()
3483 $this->markTestIncomplete();
3487 * Test the api_friendica_group_delete() function.
3490 public function testApiFriendicaGroupDelete()
3492 $this->markTestIncomplete();
3496 * Test the api_lists_destroy() function.
3499 public function testApiListsDestroy()
3501 $this->markTestIncomplete();
3505 * Test the group_create() function.
3508 public function testGroupCreate()
3510 $this->markTestIncomplete();
3514 * Test the api_friendica_group_create() function.
3517 public function testApiFriendicaGroupCreate()
3519 $this->markTestIncomplete();
3523 * Test the api_lists_create() function.
3526 public function testApiListsCreate()
3528 $this->markTestIncomplete();
3532 * Test the api_friendica_group_update() function.
3535 public function testApiFriendicaGroupUpdate()
3537 $this->markTestIncomplete();
3541 * Test the api_lists_update() function.
3544 public function testApiListsUpdate()
3546 $this->markTestIncomplete();
3550 * Test the api_friendica_activity() function.
3553 public function testApiFriendicaActivity()
3555 $this->markTestIncomplete();
3559 * Test the api_friendica_notification() function.
3561 * @expectedException Friendica\Network\HTTPException\BadRequestException
3563 public function testApiFriendicaNotification()
3565 api_friendica_notification('json');
3569 * Test the api_friendica_notification() function without an authenticated user.
3571 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3573 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3575 $_SESSION['authenticated'] = false;
3576 api_friendica_notification('json');
3580 * Test the api_friendica_notification() function with an argument count.
3583 public function testApiFriendicaNotificationWithArgumentCount()
3585 $this->app->argv = ['api', 'friendica', 'notification'];
3586 $this->app->argc = count($this->app->argv);
3587 $result = api_friendica_notification('json');
3588 $this->assertEquals(['note' => false], $result);
3592 * Test the api_friendica_notification() function with an XML result.
3595 public function testApiFriendicaNotificationWithXmlResult()
3597 $this->app->argv = ['api', 'friendica', 'notification'];
3598 $this->app->argc = count($this->app->argv);
3599 $result = api_friendica_notification('xml');
3600 $this->assertXml($result, 'notes');
3604 * Test the api_friendica_notification_seen() function.
3607 public function testApiFriendicaNotificationSeen()
3609 $this->markTestIncomplete();
3613 * Test the api_friendica_direct_messages_setseen() function.
3616 public function testApiFriendicaDirectMessagesSetseen()
3618 $this->markTestIncomplete();
3622 * Test the api_friendica_direct_messages_search() function.
3625 public function testApiFriendicaDirectMessagesSearch()
3627 $this->markTestIncomplete();
3631 * Test the api_friendica_profile_show() function.
3634 public function testApiFriendicaProfileShow()
3636 $result = api_friendica_profile_show('json');
3637 // We can't use assertSelfUser() here because the user object is missing some properties.
3638 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3639 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3640 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3641 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3642 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3643 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3644 $this->assertFalse($result['$result']['multi_profiles']);
3648 * Test the api_friendica_profile_show() function with a profile ID.
3651 public function testApiFriendicaProfileShowWithProfileId()
3653 $this->markTestIncomplete('We need to add a dataset for this.');
3657 * Test the api_friendica_profile_show() function with a wrong profile ID.
3659 * @expectedException Friendica\Network\HTTPException\BadRequestException
3661 public function testApiFriendicaProfileShowWithWrongProfileId()
3663 $_REQUEST['profile_id'] = 666;
3664 api_friendica_profile_show('json');
3668 * Test the api_friendica_profile_show() function without an authenticated user.
3670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3672 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3674 $_SESSION['authenticated'] = false;
3675 api_friendica_profile_show('json');
3679 * Test the api_saved_searches_list() function.
3682 public function testApiSavedSearchesList()
3684 $result = api_saved_searches_list('json');
3685 $this->assertEquals(1, $result['terms'][0]['id']);
3686 $this->assertEquals(1, $result['terms'][0]['id_str']);
3687 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3688 $this->assertEquals('Saved search', $result['terms'][0]['query']);