6 namespace Friendica\Test;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Core\Protocol;
11 use Friendica\Core\System;
12 use Friendica\Network\HTTPException;
15 * Tests for the API functions.
17 * Functions that use header() need to be tested in a separate process.
18 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
20 class ApiTest extends DatabaseTest
24 * Create variables used by tests.
26 protected function setUp()
30 // Reusable App object
31 $this->app = \Friendica\BaseObject::getApp();
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 * Assert that an user array contains expected keys.
73 * @param array $user User array
76 private function assertSelfUser(array $user)
78 $this->assertEquals($this->selfUser['id'], $user['uid']);
79 $this->assertEquals($this->selfUser['id'], $user['cid']);
80 $this->assertEquals(1, $user['self']);
81 $this->assertEquals('Friendica', $user['location']);
82 $this->assertEquals($this->selfUser['name'], $user['name']);
83 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
84 $this->assertEquals('dfrn', $user['network']);
85 $this->assertTrue($user['verified']);
89 * Assert that an user array contains expected keys.
90 * @param array $user User array
93 private function assertOtherUser(array $user)
95 $this->assertEquals($this->otherUser['id'], $user['id']);
96 $this->assertEquals($this->otherUser['id'], $user['id_str']);
97 $this->assertEquals(0, $user['self']);
98 $this->assertEquals($this->otherUser['name'], $user['name']);
99 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
100 $this->assertFalse($user['verified']);
104 * Assert that a status array contains expected keys.
105 * @param array $status Status array
108 private function assertStatus(array $status)
110 $this->assertInternalType('string', $status['text']);
111 $this->assertInternalType('int', $status['id']);
112 // We could probably do more checks here.
116 * Assert that a list array contains expected keys.
117 * @param array $list List array
120 private function assertList(array $list)
122 $this->assertInternalType('string', $list['name']);
123 $this->assertInternalType('int', $list['id']);
124 $this->assertInternalType('string', $list['id_str']);
125 $this->assertContains($list['mode'], ['public', 'private']);
126 // We could probably do more checks here.
130 * Assert that the string is XML and contain the root element.
131 * @param string $result XML string
132 * @param string $root_element Root element name
135 private function assertXml($result, $root_element)
137 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
138 $this->assertContains('<'.$root_element, $result);
139 // We could probably do more checks here.
143 * Get the path to a temporary empty PNG image.
144 * @return string Path
146 private function getTempImage()
148 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
152 // Empty 1x1 px PNG image
153 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
161 * Test the api_user() function.
164 public function testApiUser()
166 $this->assertEquals($this->selfUser['id'], api_user());
170 * Test the api_user() function with an unallowed user.
173 public function testApiUserWithUnallowedUser()
175 $_SESSION = ['allow_api' => false];
176 $this->assertEquals(false, api_user());
180 * Test the api_source() function.
183 public function testApiSource()
185 $this->assertEquals('api', api_source());
189 * Test the api_source() function with a Twidere user agent.
192 public function testApiSourceWithTwidere()
194 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
195 $this->assertEquals('Twidere', api_source());
199 * Test the api_source() function with a GET parameter.
202 public function testApiSourceWithGet()
204 $_GET['source'] = 'source_name';
205 $this->assertEquals('source_name', api_source());
209 * Test the api_date() function.
212 public function testApiDate()
214 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
218 * Test the api_register_func() function.
221 public function testApiRegisterFunc()
233 $this->assertTrue($API['api_path']['auth']);
234 $this->assertEquals('method', $API['api_path']['method']);
235 $this->assertTrue(is_callable($API['api_path']['func']));
239 * Test the api_login() function without any login.
241 * @runInSeparateProcess
242 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
244 public function testApiLoginWithoutLogin()
246 api_login($this->app);
250 * Test the api_login() function with a bad login.
252 * @runInSeparateProcess
253 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
255 public function testApiLoginWithBadLogin()
257 $_SERVER['PHP_AUTH_USER'] = 'user@server';
258 api_login($this->app);
262 * Test the api_login() function with oAuth.
265 public function testApiLoginWithOauth()
267 $this->markTestIncomplete('Can we test this easily?');
271 * Test the api_login() function with authentication provided by an addon.
274 public function testApiLoginWithAddonAuth()
276 $this->markTestIncomplete('Can we test this easily?');
280 * Test the api_login() function with a correct login.
282 * @runInSeparateProcess
284 public function testApiLoginWithCorrectLogin()
286 $_SERVER['PHP_AUTH_USER'] = 'Test user';
287 $_SERVER['PHP_AUTH_PW'] = 'password';
288 api_login($this->app);
292 * Test the api_login() function with a remote user.
294 * @runInSeparateProcess
295 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
297 public function testApiLoginWithRemoteUser()
299 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
300 api_login($this->app);
304 * Test the api_check_method() function.
307 public function testApiCheckMethod()
309 $this->assertFalse(api_check_method('method'));
313 * Test the api_check_method() function with a correct method.
316 public function testApiCheckMethodWithCorrectMethod()
318 $_SERVER['REQUEST_METHOD'] = 'method';
319 $this->assertTrue(api_check_method('method'));
323 * Test the api_check_method() function with a wildcard.
326 public function testApiCheckMethodWithWildcard()
328 $this->assertTrue(api_check_method('*'));
332 * Test the api_call() function.
334 * @runInSeparateProcess
336 public function testApiCall()
340 'method' => 'method',
341 'func' => function () {
342 return ['data' => ['some_data']];
345 $_SERVER['REQUEST_METHOD'] = 'method';
346 $_GET['callback'] = 'callback_name';
348 $this->app->query_string = 'api_path';
350 'callback_name(["some_data"])',
356 * Test the api_call() function with the profiled enabled.
358 * @runInSeparateProcess
360 public function testApiCallWithProfiler()
364 'method' => 'method',
365 'func' => function () {
366 return ['data' => ['some_data']];
369 $_SERVER['REQUEST_METHOD'] = 'method';
370 Config::set('system', 'profiler', true);
371 Config::set('rendertime', 'callstack', true);
372 $this->app->callstack = [
373 'database' => ['some_function' => 200],
374 'database_write' => ['some_function' => 200],
375 'cache' => ['some_function' => 200],
376 'cache_write' => ['some_function' => 200],
377 'network' => ['some_function' => 200]
380 $this->app->query_string = 'api_path';
388 * Test the api_call() function without any result.
390 * @runInSeparateProcess
392 public function testApiCallWithNoResult()
396 'method' => 'method',
397 'func' => function () {
401 $_SERVER['REQUEST_METHOD'] = 'method';
403 $this->app->query_string = 'api_path';
405 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
411 * Test the api_call() function with an unimplemented API.
413 * @runInSeparateProcess
415 public function testApiCallWithUninplementedApi()
418 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
424 * Test the api_call() function with a JSON result.
426 * @runInSeparateProcess
428 public function testApiCallWithJson()
432 'method' => 'method',
433 'func' => function () {
434 return ['data' => ['some_data']];
437 $_SERVER['REQUEST_METHOD'] = 'method';
439 $this->app->query_string = 'api_path.json';
447 * Test the api_call() function with an XML result.
449 * @runInSeparateProcess
451 public function testApiCallWithXml()
455 'method' => 'method',
456 'func' => function () {
460 $_SERVER['REQUEST_METHOD'] = 'method';
462 $this->app->query_string = 'api_path.xml';
470 * Test the api_call() function with an RSS result.
472 * @runInSeparateProcess
474 public function testApiCallWithRss()
478 'method' => 'method',
479 'func' => function () {
483 $_SERVER['REQUEST_METHOD'] = 'method';
485 $this->app->query_string = 'api_path.rss';
487 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
494 * Test the api_call() function with an Atom result.
496 * @runInSeparateProcess
498 public function testApiCallWithAtom()
502 'method' => 'method',
503 'func' => function () {
507 $_SERVER['REQUEST_METHOD'] = 'method';
509 $this->app->query_string = 'api_path.atom';
511 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
518 * Test the api_call() function with an unallowed method.
520 * @runInSeparateProcess
522 public function testApiCallWithWrongMethod()
525 $API['api_path'] = ['method' => 'method'];
527 $this->app->query_string = 'api_path';
529 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
535 * Test the api_call() function with an unauthorized user.
537 * @runInSeparateProcess
539 public function testApiCallWithWrongAuth()
543 'method' => 'method',
546 $_SERVER['REQUEST_METHOD'] = 'method';
547 $_SESSION['authenticated'] = false;
549 $this->app->query_string = 'api_path';
551 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
557 * Test the api_error() function with a JSON result.
559 * @runInSeparateProcess
561 public function testApiErrorWithJson()
564 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
565 api_error('json', new HTTPException('error_message'))
570 * Test the api_error() function with an XML result.
572 * @runInSeparateProcess
574 public function testApiErrorWithXml()
577 '<?xml version="1.0"?>'."\n".
578 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
579 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
580 'xmlns:georss="http://www.georss.org/georss">'."\n".
581 ' <error>error_message</error>'."\n".
582 ' <code>200 Friendica\Network\HTTP</code>'."\n".
585 api_error('xml', new HTTPException('error_message'))
590 * Test the api_error() function with an RSS result.
592 * @runInSeparateProcess
594 public function testApiErrorWithRss()
597 '<?xml version="1.0"?>'."\n".
598 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
599 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
600 'xmlns:georss="http://www.georss.org/georss">'."\n".
601 ' <error>error_message</error>'."\n".
602 ' <code>200 Friendica\Network\HTTP</code>'."\n".
605 api_error('rss', new HTTPException('error_message'))
610 * Test the api_error() function with an Atom result.
612 * @runInSeparateProcess
614 public function testApiErrorWithAtom()
617 '<?xml version="1.0"?>'."\n".
618 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
619 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
620 'xmlns:georss="http://www.georss.org/georss">'."\n".
621 ' <error>error_message</error>'."\n".
622 ' <code>200 Friendica\Network\HTTP</code>'."\n".
625 api_error('atom', new HTTPException('error_message'))
630 * Test the api_rss_extra() function.
633 public function testApiRssExtra()
635 $user_info = ['url' => 'user_url', 'lang' => 'en'];
636 $result = api_rss_extra($this->app, [], $user_info);
637 $this->assertEquals($user_info, $result['$user']);
638 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
639 $this->assertArrayHasKey('self', $result['$rss']);
640 $this->assertArrayHasKey('base', $result['$rss']);
641 $this->assertArrayHasKey('updated', $result['$rss']);
642 $this->assertArrayHasKey('atom_updated', $result['$rss']);
643 $this->assertArrayHasKey('language', $result['$rss']);
644 $this->assertArrayHasKey('logo', $result['$rss']);
648 * Test the api_rss_extra() function without any user info.
650 * @runInSeparateProcess
652 public function testApiRssExtraWithoutUserInfo()
654 $result = api_rss_extra($this->app, [], null);
655 $this->assertInternalType('array', $result['$user']);
656 $this->assertArrayHasKey('alternate', $result['$rss']);
657 $this->assertArrayHasKey('self', $result['$rss']);
658 $this->assertArrayHasKey('base', $result['$rss']);
659 $this->assertArrayHasKey('updated', $result['$rss']);
660 $this->assertArrayHasKey('atom_updated', $result['$rss']);
661 $this->assertArrayHasKey('language', $result['$rss']);
662 $this->assertArrayHasKey('logo', $result['$rss']);
666 * Test the api_unique_id_to_nurl() function.
669 public function testApiUniqueIdToNurl()
671 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
675 * Test the api_unique_id_to_nurl() function with a correct ID.
678 public function testApiUniqueIdToNurlWithCorrectId()
680 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
684 * Test the api_get_user() function.
686 * @runInSeparateProcess
688 public function testApiGetUser()
690 $user = api_get_user($this->app);
691 $this->assertSelfUser($user);
692 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
693 $this->assertEquals('6fdbe8', $user['profile_link_color']);
694 $this->assertEquals('ededed', $user['profile_background_color']);
698 * Test the api_get_user() function with a Frio schema.
700 * @runInSeparateProcess
702 public function testApiGetUserWithFrioSchema()
704 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
705 $user = api_get_user($this->app);
706 $this->assertSelfUser($user);
707 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
708 $this->assertEquals('6fdbe8', $user['profile_link_color']);
709 $this->assertEquals('ededed', $user['profile_background_color']);
713 * Test the api_get_user() function with a custom Frio schema.
715 * @runInSeparateProcess
717 public function testApiGetUserWithCustomFrioSchema()
719 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
720 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
721 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
722 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
723 $user = api_get_user($this->app);
724 $this->assertSelfUser($user);
725 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
726 $this->assertEquals('123456', $user['profile_link_color']);
727 $this->assertEquals('123456', $user['profile_background_color']);
731 * Test the api_get_user() function with an empty Frio schema.
733 * @runInSeparateProcess
735 public function testApiGetUserWithEmptyFrioSchema()
737 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
738 $user = api_get_user($this->app);
739 $this->assertSelfUser($user);
740 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
741 $this->assertEquals('6fdbe8', $user['profile_link_color']);
742 $this->assertEquals('ededed', $user['profile_background_color']);
746 * Test the api_get_user() function with an user that is not allowed to use the API.
748 * @runInSeparateProcess
750 public function testApiGetUserWithoutApiUser()
752 $_SERVER['PHP_AUTH_USER'] = 'Test user';
753 $_SERVER['PHP_AUTH_PW'] = 'password';
754 $_SESSION['allow_api'] = false;
755 $this->assertFalse(api_get_user($this->app));
759 * Test the api_get_user() function with an user ID in a GET parameter.
761 * @runInSeparateProcess
763 public function testApiGetUserWithGetId()
765 $_GET['user_id'] = $this->otherUser['id'];
766 $this->assertOtherUser(api_get_user($this->app));
770 * Test the api_get_user() function with a wrong user ID in a GET parameter.
772 * @runInSeparateProcess
773 * @expectedException Friendica\Network\HTTPException\BadRequestException
775 public function testApiGetUserWithWrongGetId()
777 $_GET['user_id'] = $this->wrongUserId;
778 $this->assertOtherUser(api_get_user($this->app));
782 * Test the api_get_user() function with an user name in a GET parameter.
784 * @runInSeparateProcess
786 public function testApiGetUserWithGetName()
788 $_GET['screen_name'] = $this->selfUser['nick'];
789 $this->assertSelfUser(api_get_user($this->app));
793 * Test the api_get_user() function with a profile URL in a GET parameter.
795 * @runInSeparateProcess
797 public function testApiGetUserWithGetUrl()
799 $_GET['profileurl'] = $this->selfUser['nurl'];
800 $this->assertSelfUser(api_get_user($this->app));
804 * Test the api_get_user() function with an user ID in the API path.
806 * @runInSeparateProcess
808 public function testApiGetUserWithNumericCalledApi()
811 $called_api = ['api_path'];
812 $this->app->argv[1] = $this->otherUser['id'].'.json';
813 $this->assertOtherUser(api_get_user($this->app));
817 * Test the api_get_user() function with the $called_api global variable.
819 * @runInSeparateProcess
821 public function testApiGetUserWithCalledApi()
824 $called_api = ['api', 'api_path'];
825 $this->assertSelfUser(api_get_user($this->app));
829 * Test the api_get_user() function with a valid user.
831 * @runInSeparateProcess
833 public function testApiGetUserWithCorrectUser()
835 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
839 * Test the api_get_user() function with a wrong user ID.
841 * @runInSeparateProcess
842 * @expectedException Friendica\Network\HTTPException\BadRequestException
844 public function testApiGetUserWithWrongUser()
846 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
850 * Test the api_get_user() function with a 0 user ID.
852 * @runInSeparateProcess
854 public function testApiGetUserWithZeroUser()
856 $this->assertSelfUser(api_get_user($this->app, 0));
860 * Test the api_item_get_user() function.
862 * @runInSeparateProcess
864 public function testApiItemGetUser()
866 $users = api_item_get_user($this->app, []);
867 $this->assertSelfUser($users[0]);
871 * Test the api_item_get_user() function with a different item parent.
874 public function testApiItemGetUserWithDifferentParent()
876 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
877 $this->assertSelfUser($users[0]);
878 $this->assertEquals($users[0], $users[1]);
882 * Test the api_walk_recursive() function.
885 public function testApiWalkRecursive()
893 // Should we test this with a callback that actually does something?
901 * Test the api_walk_recursive() function with an array.
904 public function testApiWalkRecursiveWithArray()
906 $array = [['item1'], ['item2']];
912 // Should we test this with a callback that actually does something?
920 * Test the api_reformat_xml() function.
923 public function testApiReformatXml()
927 $this->assertTrue(api_reformat_xml($item, $key));
928 $this->assertEquals('true', $item);
932 * Test the api_reformat_xml() function with a statusnet_api key.
935 public function testApiReformatXmlWithStatusnetKey()
938 $key = 'statusnet_api';
939 $this->assertTrue(api_reformat_xml($item, $key));
940 $this->assertEquals('statusnet:api', $key);
944 * Test the api_reformat_xml() function with a friendica_api key.
947 public function testApiReformatXmlWithFriendicaKey()
950 $key = 'friendica_api';
951 $this->assertTrue(api_reformat_xml($item, $key));
952 $this->assertEquals('friendica:api', $key);
956 * Test the api_create_xml() function.
959 public function testApiCreateXml()
962 '<?xml version="1.0"?>'."\n".
963 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
964 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
965 'xmlns:georss="http://www.georss.org/georss">'."\n".
966 ' <data>some_data</data>'."\n".
967 '</root_element>'."\n",
968 api_create_xml(['data' => ['some_data']], 'root_element')
973 * Test the api_create_xml() function without any XML namespace.
976 public function testApiCreateXmlWithoutNamespaces()
979 '<?xml version="1.0"?>'."\n".
981 ' <data>some_data</data>'."\n".
983 api_create_xml(['data' => ['some_data']], 'ok')
988 * Test the api_format_data() function.
991 public function testApiFormatData()
993 $data = ['some_data'];
994 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
998 * Test the api_format_data() function with an XML result.
1001 public function testApiFormatDataWithXml()
1003 $this->assertEquals(
1004 '<?xml version="1.0"?>'."\n".
1005 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1006 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1007 'xmlns:georss="http://www.georss.org/georss">'."\n".
1008 ' <data>some_data</data>'."\n".
1009 '</root_element>'."\n",
1010 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1015 * Test the api_account_verify_credentials() function.
1018 public function testApiAccountVerifyCredentials()
1020 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1024 * Test the api_account_verify_credentials() function without an authenticated user.
1026 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1028 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1030 $_SESSION['authenticated'] = false;
1031 api_account_verify_credentials('json');
1035 * Test the requestdata() function.
1038 public function testRequestdata()
1040 $this->assertNull(requestdata('variable_name'));
1044 * Test the requestdata() function with a POST parameter.
1047 public function testRequestdataWithPost()
1049 $_POST['variable_name'] = 'variable_value';
1050 $this->assertEquals('variable_value', requestdata('variable_name'));
1054 * Test the requestdata() function with a GET parameter.
1057 public function testRequestdataWithGet()
1059 $_GET['variable_name'] = 'variable_value';
1060 $this->assertEquals('variable_value', requestdata('variable_name'));
1064 * Test the api_statuses_mediap() function.
1067 public function testApiStatusesMediap()
1069 $this->app->argc = 2;
1077 'tmp_name' => $this->getTempImage(),
1078 'name' => 'spacer.png',
1079 'type' => 'image/png'
1082 $_GET['status'] = '<b>Status content</b>';
1084 $result = api_statuses_mediap('json');
1085 $this->assertStatus($result['status']);
1089 * Test the api_statuses_mediap() function without an authenticated user.
1091 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1093 public function testApiStatusesMediapWithoutAuthenticatedUser()
1095 $_SESSION['authenticated'] = false;
1096 api_statuses_mediap('json');
1100 * Test the api_statuses_update() function.
1103 public function testApiStatusesUpdate()
1105 $_GET['status'] = 'Status content';
1106 $_GET['in_reply_to_status_id'] = -1;
1115 'tmp_name' => $this->getTempImage(),
1116 'name' => 'spacer.png',
1117 'type' => 'image/png'
1121 $result = api_statuses_update('json');
1122 $this->assertStatus($result['status']);
1126 * Test the api_statuses_update() function with an HTML status.
1129 public function testApiStatusesUpdateWithHtml()
1131 $_GET['htmlstatus'] = '<b>Status content</b>';
1133 $result = api_statuses_update('json');
1134 $this->assertStatus($result['status']);
1138 * Test the api_statuses_update() function without an authenticated user.
1140 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1142 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1144 $_SESSION['authenticated'] = false;
1145 api_statuses_update('json');
1149 * Test the api_statuses_update() function with a parent status.
1152 public function testApiStatusesUpdateWithParent()
1154 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1158 * Test the api_statuses_update() function with a media_ids parameter.
1161 public function testApiStatusesUpdateWithMediaIds()
1163 $this->markTestIncomplete();
1167 * Test the api_statuses_update() function with the throttle limit reached.
1170 public function testApiStatusesUpdateWithDayThrottleReached()
1172 $this->markTestIncomplete();
1176 * Test the api_media_upload() function.
1178 * @expectedException Friendica\Network\HTTPException\BadRequestException
1180 public function testApiMediaUpload()
1186 * Test the api_media_upload() function without an authenticated user.
1188 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1190 public function testApiMediaUploadWithoutAuthenticatedUser()
1192 $_SESSION['authenticated'] = false;
1197 * Test the api_media_upload() function with an invalid uploaded media.
1199 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1201 public function testApiMediaUploadWithMedia()
1212 * Test the api_media_upload() function with an valid uploaded media.
1215 public function testApiMediaUploadWithValidMedia()
1223 'tmp_name' => $this->getTempImage(),
1224 'name' => 'spacer.png',
1225 'type' => 'image/png'
1231 $result = api_media_upload();
1232 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1233 $this->assertEquals(1, $result['media']['image']['w']);
1234 $this->assertEquals(1, $result['media']['image']['h']);
1238 * Test the api_status_show() function.
1241 public function testApiStatusShow()
1243 $result = api_status_show('json');
1244 $this->assertStatus($result['status']);
1248 * Test the api_status_show() function with an XML result.
1251 public function testApiStatusShowWithXml()
1253 $result = api_status_show('xml');
1254 $this->assertXml($result, 'statuses');
1258 * Test the api_status_show() function with a raw result.
1261 public function testApiStatusShowWithRaw()
1263 $this->assertStatus(api_status_show('raw'));
1267 * Test the api_users_show() function.
1270 public function testApiUsersShow()
1272 $result = api_users_show('json');
1273 // We can't use assertSelfUser() here because the user object is missing some properties.
1274 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1275 $this->assertEquals('Friendica', $result['user']['location']);
1276 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1277 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1278 $this->assertEquals('dfrn', $result['user']['network']);
1279 $this->assertTrue($result['user']['verified']);
1283 * Test the api_users_show() function with an XML result.
1286 public function testApiUsersShowWithXml()
1288 $result = api_users_show('xml');
1289 $this->assertXml($result, 'statuses');
1293 * Test the api_users_search() function.
1296 public function testApiUsersSearch()
1298 $_GET['q'] = 'othercontact';
1299 $result = api_users_search('json');
1300 $this->assertOtherUser($result['users'][0]);
1304 * Test the api_users_search() function with an XML result.
1307 public function testApiUsersSearchWithXml()
1309 $_GET['q'] = 'othercontact';
1310 $result = api_users_search('xml');
1311 $this->assertXml($result, 'users');
1315 * Test the api_users_search() function without a GET q parameter.
1317 * @expectedException Friendica\Network\HTTPException\BadRequestException
1319 public function testApiUsersSearchWithoutQuery()
1321 api_users_search('json');
1325 * Test the api_users_lookup() function.
1327 * @expectedException Friendica\Network\HTTPException\NotFoundException
1329 public function testApiUsersLookup()
1331 api_users_lookup('json');
1335 * Test the api_users_lookup() function with an user ID.
1338 public function testApiUsersLookupWithUserId()
1340 $_REQUEST['user_id'] = $this->otherUser['id'];
1341 $result = api_users_lookup('json');
1342 $this->assertOtherUser($result['users'][0]);
1346 * Test the api_search() function.
1349 public function testApiSearch()
1351 $_REQUEST['q'] = 'reply';
1352 $_REQUEST['max_id'] = 10;
1353 $result = api_search('json');
1354 foreach ($result['status'] as $status) {
1355 $this->assertStatus($status);
1356 $this->assertContains('reply', $status['text'], null, true);
1361 * Test the api_search() function a count parameter.
1364 public function testApiSearchWithCount()
1366 $_REQUEST['q'] = 'reply';
1367 $_REQUEST['count'] = 20;
1368 $result = api_search('json');
1369 foreach ($result['status'] as $status) {
1370 $this->assertStatus($status);
1371 $this->assertContains('reply', $status['text'], null, true);
1376 * Test the api_search() function with an rpp parameter.
1379 public function testApiSearchWithRpp()
1381 $_REQUEST['q'] = 'reply';
1382 $_REQUEST['rpp'] = 20;
1383 $result = api_search('json');
1384 foreach ($result['status'] as $status) {
1385 $this->assertStatus($status);
1386 $this->assertContains('reply', $status['text'], null, true);
1392 * Test the api_search() function without an authenticated user.
1394 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1396 public function testApiSearchWithUnallowedUser()
1398 $_SESSION['allow_api'] = false;
1399 $_GET['screen_name'] = $this->selfUser['nick'];
1404 * Test the api_search() function without any GET query parameter.
1406 * @expectedException Friendica\Network\HTTPException\BadRequestException
1408 public function testApiSearchWithoutQuery()
1414 * Test the api_statuses_home_timeline() function.
1417 public function testApiStatusesHomeTimeline()
1419 $_REQUEST['max_id'] = 10;
1420 $_REQUEST['exclude_replies'] = true;
1421 $_REQUEST['conversation_id'] = 1;
1422 $result = api_statuses_home_timeline('json');
1423 $this->assertNotEmpty($result['status']);
1424 foreach ($result['status'] as $status) {
1425 $this->assertStatus($status);
1430 * Test the api_statuses_home_timeline() function with a negative page parameter.
1433 public function testApiStatusesHomeTimelineWithNegativePage()
1435 $_REQUEST['page'] = -2;
1436 $result = api_statuses_home_timeline('json');
1437 $this->assertNotEmpty($result['status']);
1438 foreach ($result['status'] as $status) {
1439 $this->assertStatus($status);
1444 * Test the api_statuses_home_timeline() with an unallowed user.
1446 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1448 public function testApiStatusesHomeTimelineWithUnallowedUser()
1450 $_SESSION['allow_api'] = false;
1451 $_GET['screen_name'] = $this->selfUser['nick'];
1452 api_statuses_home_timeline('json');
1456 * Test the api_statuses_home_timeline() function with an RSS result.
1459 public function testApiStatusesHomeTimelineWithRss()
1461 $result = api_statuses_home_timeline('rss');
1462 $this->assertXml($result, 'statuses');
1466 * Test the api_statuses_public_timeline() function.
1469 public function testApiStatusesPublicTimeline()
1471 $_REQUEST['max_id'] = 10;
1472 $_REQUEST['conversation_id'] = 1;
1473 $result = api_statuses_public_timeline('json');
1474 $this->assertNotEmpty($result['status']);
1475 foreach ($result['status'] as $status) {
1476 $this->assertStatus($status);
1481 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1484 public function testApiStatusesPublicTimelineWithExcludeReplies()
1486 $_REQUEST['max_id'] = 10;
1487 $_REQUEST['exclude_replies'] = true;
1488 $result = api_statuses_public_timeline('json');
1489 $this->assertNotEmpty($result['status']);
1490 foreach ($result['status'] as $status) {
1491 $this->assertStatus($status);
1496 * Test the api_statuses_public_timeline() function with a negative page parameter.
1499 public function testApiStatusesPublicTimelineWithNegativePage()
1501 $_REQUEST['page'] = -2;
1502 $result = api_statuses_public_timeline('json');
1503 $this->assertNotEmpty($result['status']);
1504 foreach ($result['status'] as $status) {
1505 $this->assertStatus($status);
1510 * Test the api_statuses_public_timeline() function with an unallowed user.
1512 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1514 public function testApiStatusesPublicTimelineWithUnallowedUser()
1516 $_SESSION['allow_api'] = false;
1517 $_GET['screen_name'] = $this->selfUser['nick'];
1518 api_statuses_public_timeline('json');
1522 * Test the api_statuses_public_timeline() function with an RSS result.
1525 public function testApiStatusesPublicTimelineWithRss()
1527 $result = api_statuses_public_timeline('rss');
1528 $this->assertXml($result, 'statuses');
1532 * Test the api_statuses_networkpublic_timeline() function.
1535 public function testApiStatusesNetworkpublicTimeline()
1537 $_REQUEST['max_id'] = 10;
1538 $result = api_statuses_networkpublic_timeline('json');
1539 $this->assertNotEmpty($result['status']);
1540 foreach ($result['status'] as $status) {
1541 $this->assertStatus($status);
1546 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1549 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1551 $_REQUEST['page'] = -2;
1552 $result = api_statuses_networkpublic_timeline('json');
1553 $this->assertNotEmpty($result['status']);
1554 foreach ($result['status'] as $status) {
1555 $this->assertStatus($status);
1560 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1562 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1564 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1566 $_SESSION['allow_api'] = false;
1567 $_GET['screen_name'] = $this->selfUser['nick'];
1568 api_statuses_networkpublic_timeline('json');
1572 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1575 public function testApiStatusesNetworkpublicTimelineWithRss()
1577 $result = api_statuses_networkpublic_timeline('rss');
1578 $this->assertXml($result, 'statuses');
1582 * Test the api_statuses_show() function.
1584 * @expectedException Friendica\Network\HTTPException\BadRequestException
1586 public function testApiStatusesShow()
1588 api_statuses_show('json');
1592 * Test the api_statuses_show() function with an ID.
1595 public function testApiStatusesShowWithId()
1597 $this->app->argv[3] = 1;
1598 $result = api_statuses_show('json');
1599 $this->assertStatus($result['status']);
1603 * Test the api_statuses_show() function with the conversation parameter.
1606 public function testApiStatusesShowWithConversation()
1608 $this->app->argv[3] = 1;
1609 $_REQUEST['conversation'] = 1;
1610 $result = api_statuses_show('json');
1611 $this->assertNotEmpty($result['status']);
1612 foreach ($result['status'] as $status) {
1613 $this->assertStatus($status);
1618 * Test the api_statuses_show() function with an unallowed user.
1620 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1622 public function testApiStatusesShowWithUnallowedUser()
1624 $_SESSION['allow_api'] = false;
1625 $_GET['screen_name'] = $this->selfUser['nick'];
1626 api_statuses_show('json');
1630 * Test the api_conversation_show() function.
1632 * @expectedException Friendica\Network\HTTPException\BadRequestException
1634 public function testApiConversationShow()
1636 api_conversation_show('json');
1640 * Test the api_conversation_show() function with an ID.
1643 public function testApiConversationShowWithId()
1645 $this->app->argv[3] = 1;
1646 $_REQUEST['max_id'] = 10;
1647 $_REQUEST['page'] = -2;
1648 $result = api_conversation_show('json');
1649 $this->assertNotEmpty($result['status']);
1650 foreach ($result['status'] as $status) {
1651 $this->assertStatus($status);
1656 * Test the api_conversation_show() function with an unallowed user.
1658 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1660 public function testApiConversationShowWithUnallowedUser()
1662 $_SESSION['allow_api'] = false;
1663 $_GET['screen_name'] = $this->selfUser['nick'];
1664 api_conversation_show('json');
1668 * Test the api_statuses_repeat() function.
1670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1672 public function testApiStatusesRepeat()
1674 api_statuses_repeat('json');
1678 * Test the api_statuses_repeat() function without an authenticated user.
1680 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1682 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1684 $_SESSION['authenticated'] = false;
1685 api_statuses_repeat('json');
1689 * Test the api_statuses_repeat() function with an ID.
1692 public function testApiStatusesRepeatWithId()
1694 $this->app->argv[3] = 1;
1695 $result = api_statuses_repeat('json');
1696 $this->assertStatus($result['status']);
1698 // Also test with a shared status
1699 $this->app->argv[3] = 5;
1700 $result = api_statuses_repeat('json');
1701 $this->assertStatus($result['status']);
1705 * Test the api_statuses_destroy() function.
1707 * @expectedException Friendica\Network\HTTPException\BadRequestException
1709 public function testApiStatusesDestroy()
1711 api_statuses_destroy('json');
1715 * Test the api_statuses_destroy() function without an authenticated user.
1717 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1719 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1721 $_SESSION['authenticated'] = false;
1722 api_statuses_destroy('json');
1726 * Test the api_statuses_destroy() function with an ID.
1729 public function testApiStatusesDestroyWithId()
1731 $this->app->argv[3] = 1;
1732 $result = api_statuses_destroy('json');
1733 $this->assertStatus($result['status']);
1737 * Test the api_statuses_mentions() function.
1740 public function testApiStatusesMentions()
1742 $this->app->user = ['nickname' => $this->selfUser['nick']];
1743 $_REQUEST['max_id'] = 10;
1744 $result = api_statuses_mentions('json');
1745 $this->assertEmpty($result['status']);
1746 // We should test with mentions in the database.
1750 * Test the api_statuses_mentions() function with a negative page parameter.
1753 public function testApiStatusesMentionsWithNegativePage()
1755 $_REQUEST['page'] = -2;
1756 $result = api_statuses_mentions('json');
1757 $this->assertEmpty($result['status']);
1761 * Test the api_statuses_mentions() function with an unallowed user.
1763 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1765 public function testApiStatusesMentionsWithUnallowedUser()
1767 $_SESSION['allow_api'] = false;
1768 $_GET['screen_name'] = $this->selfUser['nick'];
1769 api_statuses_mentions('json');
1773 * Test the api_statuses_mentions() function with an RSS result.
1776 public function testApiStatusesMentionsWithRss()
1778 $result = api_statuses_mentions('rss');
1779 $this->assertXml($result, 'statuses');
1783 * Test the api_statuses_user_timeline() function.
1786 public function testApiStatusesUserTimeline()
1788 $_REQUEST['max_id'] = 10;
1789 $_REQUEST['exclude_replies'] = true;
1790 $_REQUEST['conversation_id'] = 1;
1791 $result = api_statuses_user_timeline('json');
1792 $this->assertNotEmpty($result['status']);
1793 foreach ($result['status'] as $status) {
1794 $this->assertStatus($status);
1799 * Test the api_statuses_user_timeline() function with a negative page parameter.
1802 public function testApiStatusesUserTimelineWithNegativePage()
1804 $_REQUEST['page'] = -2;
1805 $result = api_statuses_user_timeline('json');
1806 $this->assertNotEmpty($result['status']);
1807 foreach ($result['status'] as $status) {
1808 $this->assertStatus($status);
1813 * Test the api_statuses_user_timeline() function with an RSS result.
1816 public function testApiStatusesUserTimelineWithRss()
1818 $result = api_statuses_user_timeline('rss');
1819 $this->assertXml($result, 'statuses');
1823 * Test the api_statuses_user_timeline() function with an unallowed user.
1825 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1827 public function testApiStatusesUserTimelineWithUnallowedUser()
1829 $_SESSION['allow_api'] = false;
1830 $_GET['screen_name'] = $this->selfUser['nick'];
1831 api_statuses_user_timeline('json');
1835 * Test the api_favorites_create_destroy() function.
1837 * @expectedException Friendica\Network\HTTPException\BadRequestException
1839 public function testApiFavoritesCreateDestroy()
1841 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1842 $this->app->argc = count($this->app->argv);
1843 api_favorites_create_destroy('json');
1847 * Test the api_favorites_create_destroy() function with an invalid ID.
1849 * @expectedException Friendica\Network\HTTPException\BadRequestException
1851 public function testApiFavoritesCreateDestroyWithInvalidId()
1853 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1854 $this->app->argc = count($this->app->argv);
1855 api_favorites_create_destroy('json');
1859 * Test the api_favorites_create_destroy() function with an invalid action.
1861 * @expectedException Friendica\Network\HTTPException\BadRequestException
1863 public function testApiFavoritesCreateDestroyWithInvalidAction()
1865 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1866 $this->app->argc = count($this->app->argv);
1867 $_REQUEST['id'] = 1;
1868 api_favorites_create_destroy('json');
1872 * Test the api_favorites_create_destroy() function with the create action.
1875 public function testApiFavoritesCreateDestroyWithCreateAction()
1877 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1878 $this->app->argc = count($this->app->argv);
1879 $_REQUEST['id'] = 3;
1880 $result = api_favorites_create_destroy('json');
1881 $this->assertStatus($result['status']);
1885 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1888 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1890 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1891 $this->app->argc = count($this->app->argv);
1892 $_REQUEST['id'] = 3;
1893 $result = api_favorites_create_destroy('rss');
1894 $this->assertXml($result, 'status');
1898 * Test the api_favorites_create_destroy() function with the destroy action.
1901 public function testApiFavoritesCreateDestroyWithDestroyAction()
1903 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1904 $this->app->argc = count($this->app->argv);
1905 $_REQUEST['id'] = 3;
1906 $result = api_favorites_create_destroy('json');
1907 $this->assertStatus($result['status']);
1911 * Test the api_favorites_create_destroy() function without an authenticated user.
1913 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1915 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1917 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1918 $this->app->argc = count($this->app->argv);
1919 $_SESSION['authenticated'] = false;
1920 api_favorites_create_destroy('json');
1924 * Test the api_favorites() function.
1927 public function testApiFavorites()
1929 $_REQUEST['page'] = -1;
1930 $_REQUEST['max_id'] = 10;
1931 $result = api_favorites('json');
1932 foreach ($result['status'] as $status) {
1933 $this->assertStatus($status);
1938 * Test the api_favorites() function with an RSS result.
1941 public function testApiFavoritesWithRss()
1943 $result = api_favorites('rss');
1944 $this->assertXml($result, 'statuses');
1948 * Test the api_favorites() function with an unallowed user.
1950 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1952 public function testApiFavoritesWithUnallowedUser()
1954 $_SESSION['allow_api'] = false;
1955 $_GET['screen_name'] = $this->selfUser['nick'];
1956 api_favorites('json');
1960 * Test the api_format_messages() function.
1963 public function testApiFormatMessages()
1965 $result = api_format_messages(
1966 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1967 ['id' => 2, 'screen_name' => 'recipient_name'],
1968 ['id' => 3, 'screen_name' => 'sender_name']
1970 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1971 $this->assertEquals(1, $result['id']);
1972 $this->assertEquals(2, $result['recipient_id']);
1973 $this->assertEquals(3, $result['sender_id']);
1974 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1975 $this->assertEquals('sender_name', $result['sender_screen_name']);
1979 * Test the api_format_messages() function with HTML.
1982 public function testApiFormatMessagesWithHtmlText()
1984 $_GET['getText'] = 'html';
1985 $result = api_format_messages(
1986 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1987 ['id' => 2, 'screen_name' => 'recipient_name'],
1988 ['id' => 3, 'screen_name' => 'sender_name']
1990 $this->assertEquals('item_title', $result['title']);
1991 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1995 * Test the api_format_messages() function with plain text.
1998 public function testApiFormatMessagesWithPlainText()
2000 $_GET['getText'] = 'plain';
2001 $result = api_format_messages(
2002 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2003 ['id' => 2, 'screen_name' => 'recipient_name'],
2004 ['id' => 3, 'screen_name' => 'sender_name']
2006 $this->assertEquals('item_title', $result['title']);
2007 $this->assertEquals('item_body', $result['text']);
2011 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2014 public function testApiFormatMessagesWithoutUserObjects()
2016 $_GET['getUserObjects'] = 'false';
2017 $result = api_format_messages(
2018 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2019 ['id' => 2, 'screen_name' => 'recipient_name'],
2020 ['id' => 3, 'screen_name' => 'sender_name']
2022 $this->assertTrue(!isset($result['sender']));
2023 $this->assertTrue(!isset($result['recipient']));
2027 * Test the api_convert_item() function.
2030 public function testApiConvertItem()
2032 $result = api_convert_item(
2034 'network' => 'feed',
2035 'title' => 'item_title',
2036 // We need a long string to test that it is correctly cut
2037 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2038 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2039 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2040 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2041 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2042 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2043 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2044 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2045 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2046 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2047 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2048 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2049 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2050 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2051 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2052 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2053 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2054 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2055 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2056 'repellat officia illum quos impedit quam iste esse unde qui '.
2057 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2058 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2059 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2060 'plink' => 'item_plink'
2063 $this->assertStringStartsWith('item_title', $result['text']);
2064 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2068 * Test the api_convert_item() function with an empty item body.
2071 public function testApiConvertItemWithoutBody()
2073 $result = api_convert_item(
2075 'network' => 'feed',
2076 'title' => 'item_title',
2078 'plink' => 'item_plink'
2081 $this->assertEquals('item_title', $result['text']);
2082 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2086 * Test the api_convert_item() function with the title in the body.
2089 public function testApiConvertItemWithTitleInBody()
2091 $result = api_convert_item(
2093 'title' => 'item_title',
2094 'body' => 'item_title item_body'
2097 $this->assertEquals('item_title item_body', $result['text']);
2098 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2102 * Test the api_get_attachments() function.
2105 public function testApiGetAttachments()
2108 $this->assertEmpty(api_get_attachments($body));
2112 * Test the api_get_attachments() function with an img tag.
2115 public function testApiGetAttachmentsWithImage()
2117 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2118 $this->assertInternalType('array', api_get_attachments($body));
2122 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2125 public function testApiGetAttachmentsWithImageAndAndStatus()
2127 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2128 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2129 $this->assertInternalType('array', api_get_attachments($body));
2133 * Test the api_get_entitities() function.
2136 public function testApiGetEntitities()
2139 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2143 * Test the api_get_entitities() function with the include_entities parameter.
2146 public function testApiGetEntititiesWithIncludeEntities()
2148 $_REQUEST['include_entities'] = 'true';
2150 $result = api_get_entitities($text, 'bbcode');
2151 $this->assertInternalType('array', $result['hashtags']);
2152 $this->assertInternalType('array', $result['symbols']);
2153 $this->assertInternalType('array', $result['urls']);
2154 $this->assertInternalType('array', $result['user_mentions']);
2158 * Test the api_format_items_embeded_images() function.
2161 public function testApiFormatItemsEmbededImages()
2163 $this->assertEquals(
2164 'text ' . System::baseUrl() . '/display/item_guid',
2165 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2170 * Test the api_contactlink_to_array() function.
2173 public function testApiContactlinkToArray()
2175 $this->assertEquals(
2180 api_contactlink_to_array('text')
2185 * Test the api_contactlink_to_array() function with an URL.
2188 public function testApiContactlinkToArrayWithUrl()
2190 $this->assertEquals(
2192 'name' => ['link_text'],
2195 api_contactlink_to_array('text <a href="url">link_text</a>')
2200 * Test the api_format_items_activities() function.
2203 public function testApiFormatItemsActivities()
2205 $item = ['uid' => 0, 'uri' => ''];
2206 $result = api_format_items_activities($item);
2207 $this->assertArrayHasKey('like', $result);
2208 $this->assertArrayHasKey('dislike', $result);
2209 $this->assertArrayHasKey('attendyes', $result);
2210 $this->assertArrayHasKey('attendno', $result);
2211 $this->assertArrayHasKey('attendmaybe', $result);
2215 * Test the api_format_items_activities() function with an XML result.
2218 public function testApiFormatItemsActivitiesWithXml()
2220 $item = ['uid' => 0, 'uri' => ''];
2221 $result = api_format_items_activities($item, 'xml');
2222 $this->assertArrayHasKey('friendica:like', $result);
2223 $this->assertArrayHasKey('friendica:dislike', $result);
2224 $this->assertArrayHasKey('friendica:attendyes', $result);
2225 $this->assertArrayHasKey('friendica:attendno', $result);
2226 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2230 * Test the api_format_items_profiles() function.
2233 public function testApiFormatItemsProfiles()
2236 'id' => 'profile_id',
2237 'profile-name' => 'profile_name',
2238 'is-default' => true,
2239 'hide-friends' => true,
2240 'photo' => 'profile_photo',
2241 'thumb' => 'profile_thumb',
2243 'net-publish' => true,
2244 'pdesc' => 'description',
2245 'dob' => 'date_of_birth',
2246 'address' => 'address',
2247 'locality' => 'city',
2248 'region' => 'region',
2249 'postal-code' => 'postal_code',
2250 'country-name' => 'country',
2251 'hometown' => 'hometown',
2252 'gender' => 'gender',
2253 'marital' => 'marital',
2254 'with' => 'marital_with',
2255 'howlong' => 'marital_since',
2256 'sexual' => 'sexual',
2257 'politic' => 'politic',
2258 'religion' => 'religion',
2259 'pub_keywords' => 'public_keywords',
2260 'prv_keywords' => 'private_keywords',
2263 'dislikes' => 'dislikes',
2269 'interest' => 'interest',
2270 'romance' => 'romance',
2272 'education' => 'education',
2273 'contact' => 'social_networks',
2274 'homepage' => 'homepage'
2276 $result = api_format_items_profiles($profile_row);
2277 $this->assertEquals(
2279 'profile_id' => 'profile_id',
2280 'profile_name' => 'profile_name',
2281 'is_default' => true,
2282 'hide_friends' => true,
2283 'profile_photo' => 'profile_photo',
2284 'profile_thumb' => 'profile_thumb',
2286 'net_publish' => true,
2287 'description' => 'description',
2288 'date_of_birth' => 'date_of_birth',
2289 'address' => 'address',
2291 'region' => 'region',
2292 'postal_code' => 'postal_code',
2293 'country' => 'country',
2294 'hometown' => 'hometown',
2295 'gender' => 'gender',
2296 'marital' => 'marital',
2297 'marital_with' => 'marital_with',
2298 'marital_since' => 'marital_since',
2299 'sexual' => 'sexual',
2300 'politic' => 'politic',
2301 'religion' => 'religion',
2302 'public_keywords' => 'public_keywords',
2303 'private_keywords' => 'private_keywords',
2306 'dislikes' => 'dislikes',
2312 'interest' => 'interest',
2313 'romance' => 'romance',
2315 'education' => 'education',
2316 'social_networks' => 'social_networks',
2317 'homepage' => 'homepage',
2325 * Test the api_format_items() function.
2328 public function testApiFormatItems()
2332 'item_network' => 'item_network',
2338 'author-network' => Protocol::DFRN,
2339 'author-link' => 'http://localhost/profile/othercontact',
2343 $result = api_format_items($items, ['id' => 0], true);
2344 foreach ($result as $status) {
2345 $this->assertStatus($status);
2350 * Test the api_format_items() function with an XML result.
2353 public function testApiFormatItemsWithXml()
2361 'author-network' => Protocol::DFRN,
2362 'author-link' => 'http://localhost/profile/othercontact',
2366 $result = api_format_items($items, ['id' => 0], true, 'xml');
2367 foreach ($result as $status) {
2368 $this->assertStatus($status);
2373 * Test the api_format_items() function.
2376 public function testApiAccountRateLimitStatus()
2378 $result = api_account_rate_limit_status('json');
2379 $this->assertEquals(150, $result['hash']['remaining_hits']);
2380 $this->assertEquals(150, $result['hash']['hourly_limit']);
2381 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2385 * Test the api_format_items() function with an XML result.
2388 public function testApiAccountRateLimitStatusWithXml()
2390 $result = api_account_rate_limit_status('xml');
2391 $this->assertXml($result, 'hash');
2395 * Test the api_help_test() function.
2398 public function testApiHelpTest()
2400 $result = api_help_test('json');
2401 $this->assertEquals(['ok' => 'ok'], $result);
2405 * Test the api_help_test() function with an XML result.
2408 public function testApiHelpTestWithXml()
2410 $result = api_help_test('xml');
2411 $this->assertXml($result, 'ok');
2415 * Test the api_lists_list() function.
2418 public function testApiListsList()
2420 $result = api_lists_list('json');
2421 $this->assertEquals(['lists_list' => []], $result);
2425 * Test the api_lists_ownerships() function.
2428 public function testApiListsOwnerships()
2430 $result = api_lists_ownerships('json');
2431 foreach ($result['lists']['lists'] as $list) {
2432 $this->assertList($list);
2437 * Test the api_lists_ownerships() function without an authenticated user.
2439 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2441 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2443 $_SESSION['authenticated'] = false;
2444 api_lists_ownerships('json');
2448 * Test the api_lists_statuses() function.
2449 * @expectedException Friendica\Network\HTTPException\BadRequestException
2452 public function testApiListsStatuses()
2454 api_lists_statuses('json');
2458 * Test the api_lists_statuses() function with a list ID.
2461 public function testApiListsStatusesWithListId()
2463 $_REQUEST['list_id'] = 1;
2464 $_REQUEST['page'] = -1;
2465 $_REQUEST['max_id'] = 10;
2466 $result = api_lists_statuses('json');
2467 foreach ($result['status'] as $status) {
2468 $this->assertStatus($status);
2473 * Test the api_lists_statuses() function with a list ID and a RSS result.
2476 public function testApiListsStatusesWithListIdAndRss()
2478 $_REQUEST['list_id'] = 1;
2479 $result = api_lists_statuses('rss');
2480 $this->assertXml($result, 'statuses');
2484 * Test the api_lists_statuses() function with an unallowed user.
2486 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2488 public function testApiListsStatusesWithUnallowedUser()
2490 $_SESSION['allow_api'] = false;
2491 $_GET['screen_name'] = $this->selfUser['nick'];
2492 api_lists_statuses('json');
2496 * Test the api_statuses_f() function.
2499 public function testApiStatusesFWithFriends()
2502 $result = api_statuses_f('friends');
2503 $this->assertArrayHasKey('user', $result);
2507 * Test the api_statuses_f() function.
2510 public function testApiStatusesFWithFollowers()
2512 $result = api_statuses_f('followers');
2513 $this->assertArrayHasKey('user', $result);
2517 * Test the api_statuses_f() function.
2520 public function testApiStatusesFWithBlocks()
2522 $result = api_statuses_f('blocks');
2523 $this->assertArrayHasKey('user', $result);
2527 * Test the api_statuses_f() function.
2530 public function testApiStatusesFWithIncoming()
2532 $result = api_statuses_f('incoming');
2533 $this->assertArrayHasKey('user', $result);
2537 * Test the api_statuses_f() function an undefined cursor GET variable.
2540 public function testApiStatusesFWithUndefinedCursor()
2542 $_GET['cursor'] = 'undefined';
2543 $this->assertFalse(api_statuses_f('friends'));
2547 * Test the api_statuses_friends() function.
2550 public function testApiStatusesFriends()
2552 $result = api_statuses_friends('json');
2553 $this->assertArrayHasKey('user', $result);
2557 * Test the api_statuses_friends() function an undefined cursor GET variable.
2560 public function testApiStatusesFriendsWithUndefinedCursor()
2562 $_GET['cursor'] = 'undefined';
2563 $this->assertFalse(api_statuses_friends('json'));
2567 * Test the api_statuses_followers() function.
2570 public function testApiStatusesFollowers()
2572 $result = api_statuses_followers('json');
2573 $this->assertArrayHasKey('user', $result);
2577 * Test the api_statuses_followers() function an undefined cursor GET variable.
2580 public function testApiStatusesFollowersWithUndefinedCursor()
2582 $_GET['cursor'] = 'undefined';
2583 $this->assertFalse(api_statuses_followers('json'));
2587 * Test the api_blocks_list() function.
2590 public function testApiBlocksList()
2592 $result = api_blocks_list('json');
2593 $this->assertArrayHasKey('user', $result);
2597 * Test the api_blocks_list() function an undefined cursor GET variable.
2600 public function testApiBlocksListWithUndefinedCursor()
2602 $_GET['cursor'] = 'undefined';
2603 $this->assertFalse(api_blocks_list('json'));
2607 * Test the api_friendships_incoming() function.
2610 public function testApiFriendshipsIncoming()
2612 $result = api_friendships_incoming('json');
2613 $this->assertArrayHasKey('id', $result);
2617 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2620 public function testApiFriendshipsIncomingWithUndefinedCursor()
2622 $_GET['cursor'] = 'undefined';
2623 $this->assertFalse(api_friendships_incoming('json'));
2627 * Test the api_statusnet_config() function.
2630 public function testApiStatusnetConfig()
2632 $result = api_statusnet_config('json');
2633 $this->assertEquals('localhost', $result['config']['site']['server']);
2634 $this->assertEquals('default', $result['config']['site']['theme']);
2635 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2636 $this->assertTrue($result['config']['site']['fancy']);
2637 $this->assertEquals('en', $result['config']['site']['language']);
2638 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2639 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2640 $this->assertEquals('false', $result['config']['site']['private']);
2641 $this->assertEquals('false', $result['config']['site']['ssl']);
2642 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2646 * Test the api_statusnet_version() function.
2649 public function testApiStatusnetVersion()
2651 $result = api_statusnet_version('json');
2652 $this->assertEquals('0.9.7', $result['version']);
2656 * Test the api_ff_ids() function.
2659 public function testApiFfIds()
2661 $result = api_ff_ids('json');
2662 $this->assertNull($result);
2666 * Test the api_ff_ids() function with a result.
2669 public function testApiFfIdsWithResult()
2671 $this->markTestIncomplete();
2675 * Test the api_ff_ids() function without an authenticated user.
2677 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2679 public function testApiFfIdsWithoutAuthenticatedUser()
2681 $_SESSION['authenticated'] = false;
2686 * Test the api_friends_ids() function.
2689 public function testApiFriendsIds()
2691 $result = api_friends_ids('json');
2692 $this->assertNull($result);
2696 * Test the api_followers_ids() function.
2699 public function testApiFollowersIds()
2701 $result = api_followers_ids('json');
2702 $this->assertNull($result);
2706 * Test the api_direct_messages_new() function.
2709 public function testApiDirectMessagesNew()
2711 $result = api_direct_messages_new('json');
2712 $this->assertNull($result);
2716 * Test the api_direct_messages_new() function without an authenticated user.
2718 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2720 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2722 $_SESSION['authenticated'] = false;
2723 api_direct_messages_new('json');
2727 * Test the api_direct_messages_new() function with an user ID.
2730 public function testApiDirectMessagesNewWithUserId()
2732 $_POST['text'] = 'message_text';
2733 $_POST['user_id'] = $this->otherUser['id'];
2734 $result = api_direct_messages_new('json');
2735 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2739 * Test the api_direct_messages_new() function with a screen name.
2742 public function testApiDirectMessagesNewWithScreenName()
2744 $_POST['text'] = 'message_text';
2745 $_POST['screen_name'] = $this->friendUser['nick'];
2746 $result = api_direct_messages_new('json');
2747 $this->assertEquals(1, $result['direct_message']['id']);
2748 $this->assertContains('message_text', $result['direct_message']['text']);
2749 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2750 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2754 * Test the api_direct_messages_new() function with a title.
2757 public function testApiDirectMessagesNewWithTitle()
2759 $_POST['text'] = 'message_text';
2760 $_POST['screen_name'] = $this->friendUser['nick'];
2761 $_REQUEST['title'] = 'message_title';
2762 $result = api_direct_messages_new('json');
2763 $this->assertEquals(1, $result['direct_message']['id']);
2764 $this->assertContains('message_text', $result['direct_message']['text']);
2765 $this->assertContains('message_title', $result['direct_message']['text']);
2766 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2767 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2771 * Test the api_direct_messages_new() function with an RSS result.
2774 public function testApiDirectMessagesNewWithRss()
2776 $_POST['text'] = 'message_text';
2777 $_POST['screen_name'] = $this->friendUser['nick'];
2778 $result = api_direct_messages_new('rss');
2779 $this->assertXml($result, 'direct-messages');
2783 * Test the api_direct_messages_destroy() function.
2785 * @expectedException Friendica\Network\HTTPException\BadRequestException
2787 public function testApiDirectMessagesDestroy()
2789 api_direct_messages_destroy('json');
2793 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2796 public function testApiDirectMessagesDestroyWithVerbose()
2798 $_GET['friendica_verbose'] = 'true';
2799 $result = api_direct_messages_destroy('json');
2800 $this->assertEquals(
2803 'result' => 'error',
2804 'message' => 'message id or parenturi not specified'
2812 * Test the api_direct_messages_destroy() function without an authenticated user.
2814 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2816 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2818 $_SESSION['authenticated'] = false;
2819 api_direct_messages_destroy('json');
2823 * Test the api_direct_messages_destroy() function with a non-zero ID.
2825 * @expectedException Friendica\Network\HTTPException\BadRequestException
2827 public function testApiDirectMessagesDestroyWithId()
2829 $_REQUEST['id'] = 1;
2830 api_direct_messages_destroy('json');
2834 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2837 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2839 $_REQUEST['id'] = 1;
2840 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2841 $_GET['friendica_verbose'] = 'true';
2842 $result = api_direct_messages_destroy('json');
2843 $this->assertEquals(
2846 'result' => 'error',
2847 'message' => 'message id not in database'
2855 * Test the api_direct_messages_destroy() function with a non-zero ID.
2858 public function testApiDirectMessagesDestroyWithCorrectId()
2860 $this->markTestIncomplete('We need to add a dataset for this.');
2864 * Test the api_direct_messages_box() function.
2867 public function testApiDirectMessagesBoxWithSentbox()
2869 $_REQUEST['page'] = -1;
2870 $_REQUEST['max_id'] = 10;
2871 $result = api_direct_messages_box('json', 'sentbox', 'false');
2872 $this->assertArrayHasKey('direct_message', $result);
2876 * Test the api_direct_messages_box() function.
2879 public function testApiDirectMessagesBoxWithConversation()
2881 $result = api_direct_messages_box('json', 'conversation', 'false');
2882 $this->assertArrayHasKey('direct_message', $result);
2886 * Test the api_direct_messages_box() function.
2889 public function testApiDirectMessagesBoxWithAll()
2891 $result = api_direct_messages_box('json', 'all', 'false');
2892 $this->assertArrayHasKey('direct_message', $result);
2896 * Test the api_direct_messages_box() function.
2899 public function testApiDirectMessagesBoxWithInbox()
2901 $result = api_direct_messages_box('json', 'inbox', 'false');
2902 $this->assertArrayHasKey('direct_message', $result);
2906 * Test the api_direct_messages_box() function.
2909 public function testApiDirectMessagesBoxWithVerbose()
2911 $result = api_direct_messages_box('json', 'sentbox', 'true');
2912 $this->assertEquals(
2915 'result' => 'error',
2916 'message' => 'no mails available'
2924 * Test the api_direct_messages_box() function with a RSS result.
2927 public function testApiDirectMessagesBoxWithRss()
2929 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2930 $this->assertXml($result, 'direct-messages');
2934 * Test the api_direct_messages_box() function without an authenticated user.
2936 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2938 public function testApiDirectMessagesBoxWithUnallowedUser()
2940 $_SESSION['allow_api'] = false;
2941 $_GET['screen_name'] = $this->selfUser['nick'];
2942 api_direct_messages_box('json', 'sentbox', 'false');
2946 * Test the api_direct_messages_sentbox() function.
2949 public function testApiDirectMessagesSentbox()
2951 $result = api_direct_messages_sentbox('json');
2952 $this->assertArrayHasKey('direct_message', $result);
2956 * Test the api_direct_messages_inbox() function.
2959 public function testApiDirectMessagesInbox()
2961 $result = api_direct_messages_inbox('json');
2962 $this->assertArrayHasKey('direct_message', $result);
2966 * Test the api_direct_messages_all() function.
2969 public function testApiDirectMessagesAll()
2971 $result = api_direct_messages_all('json');
2972 $this->assertArrayHasKey('direct_message', $result);
2976 * Test the api_direct_messages_conversation() function.
2979 public function testApiDirectMessagesConversation()
2981 $result = api_direct_messages_conversation('json');
2982 $this->assertArrayHasKey('direct_message', $result);
2986 * Test the api_oauth_request_token() function.
2989 public function testApiOauthRequestToken()
2991 $this->markTestIncomplete('killme() kills phpunit as well');
2995 * Test the api_oauth_access_token() function.
2998 public function testApiOauthAccessToken()
3000 $this->markTestIncomplete('killme() kills phpunit as well');
3004 * Test the api_fr_photoalbum_delete() function.
3006 * @expectedException Friendica\Network\HTTPException\BadRequestException
3008 public function testApiFrPhotoalbumDelete()
3010 api_fr_photoalbum_delete('json');
3014 * Test the api_fr_photoalbum_delete() function with an album name.
3016 * @expectedException Friendica\Network\HTTPException\BadRequestException
3018 public function testApiFrPhotoalbumDeleteWithAlbum()
3020 $_REQUEST['album'] = 'album_name';
3021 api_fr_photoalbum_delete('json');
3025 * Test the api_fr_photoalbum_delete() function with an album name.
3028 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3030 $this->markTestIncomplete('We need to add a dataset for this.');
3034 * Test the api_fr_photoalbum_delete() function.
3036 * @expectedException Friendica\Network\HTTPException\BadRequestException
3038 public function testApiFrPhotoalbumUpdate()
3040 api_fr_photoalbum_update('json');
3044 * Test the api_fr_photoalbum_delete() function with an album name.
3046 * @expectedException Friendica\Network\HTTPException\BadRequestException
3048 public function testApiFrPhotoalbumUpdateWithAlbum()
3050 $_REQUEST['album'] = 'album_name';
3051 api_fr_photoalbum_update('json');
3055 * Test the api_fr_photoalbum_delete() function with an album name.
3057 * @expectedException Friendica\Network\HTTPException\BadRequestException
3059 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3061 $_REQUEST['album'] = 'album_name';
3062 $_REQUEST['album_new'] = 'album_name';
3063 api_fr_photoalbum_update('json');
3067 * Test the api_fr_photoalbum_update() function without an authenticated user.
3069 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3071 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3073 $_SESSION['authenticated'] = false;
3074 api_fr_photoalbum_update('json');
3078 * Test the api_fr_photoalbum_delete() function with an album name.
3081 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3083 $this->markTestIncomplete('We need to add a dataset for this.');
3087 * Test the api_fr_photos_list() function.
3090 public function testApiFrPhotosList()
3092 $result = api_fr_photos_list('json');
3093 $this->assertArrayHasKey('photo', $result);
3097 * Test the api_fr_photos_list() function without an authenticated user.
3099 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3101 public function testApiFrPhotosListWithoutAuthenticatedUser()
3103 $_SESSION['authenticated'] = false;
3104 api_fr_photos_list('json');
3108 * Test the api_fr_photo_create_update() function.
3110 * @expectedException Friendica\Network\HTTPException\BadRequestException
3112 public function testApiFrPhotoCreateUpdate()
3114 api_fr_photo_create_update('json');
3118 * Test the api_fr_photo_create_update() function without an authenticated user.
3120 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3122 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3124 $_SESSION['authenticated'] = false;
3125 api_fr_photo_create_update('json');
3129 * Test the api_fr_photo_create_update() function with an album name.
3131 * @expectedException Friendica\Network\HTTPException\BadRequestException
3133 public function testApiFrPhotoCreateUpdateWithAlbum()
3135 $_REQUEST['album'] = 'album_name';
3136 api_fr_photo_create_update('json');
3140 * Test the api_fr_photo_create_update() function with the update mode.
3143 public function testApiFrPhotoCreateUpdateWithUpdate()
3145 $this->markTestIncomplete('We need to create a dataset for this');
3149 * Test the api_fr_photo_create_update() function with an uploaded file.
3152 public function testApiFrPhotoCreateUpdateWithFile()
3154 $this->markTestIncomplete();
3158 * Test the api_fr_photo_delete() function.
3160 * @expectedException Friendica\Network\HTTPException\BadRequestException
3162 public function testApiFrPhotoDelete()
3164 api_fr_photo_delete('json');
3168 * Test the api_fr_photo_delete() function without an authenticated user.
3170 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3172 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3174 $_SESSION['authenticated'] = false;
3175 api_fr_photo_delete('json');
3179 * Test the api_fr_photo_delete() function with a photo ID.
3181 * @expectedException Friendica\Network\HTTPException\BadRequestException
3183 public function testApiFrPhotoDeleteWithPhotoId()
3185 $_REQUEST['photo_id'] = 1;
3186 api_fr_photo_delete('json');
3190 * Test the api_fr_photo_delete() function with a correct photo ID.
3193 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3195 $this->markTestIncomplete('We need to create a dataset for this.');
3199 * Test the api_fr_photo_detail() function.
3201 * @expectedException Friendica\Network\HTTPException\BadRequestException
3203 public function testApiFrPhotoDetail()
3205 api_fr_photo_detail('json');
3209 * Test the api_fr_photo_detail() function without an authenticated user.
3211 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3213 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3215 $_SESSION['authenticated'] = false;
3216 api_fr_photo_detail('json');
3220 * Test the api_fr_photo_detail() function with a photo ID.
3222 * @expectedException Friendica\Network\HTTPException\NotFoundException
3224 public function testApiFrPhotoDetailWithPhotoId()
3226 $_REQUEST['photo_id'] = 1;
3227 api_fr_photo_detail('json');
3231 * Test the api_fr_photo_detail() function with a correct photo ID.
3234 public function testApiFrPhotoDetailCorrectPhotoId()
3236 $this->markTestIncomplete('We need to create a dataset for this.');
3240 * Test the api_account_update_profile_image() function.
3242 * @expectedException Friendica\Network\HTTPException\BadRequestException
3244 public function testApiAccountUpdateProfileImage()
3246 api_account_update_profile_image('json');
3250 * Test the api_account_update_profile_image() function without an authenticated user.
3252 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3254 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3256 $_SESSION['authenticated'] = false;
3257 api_account_update_profile_image('json');
3261 * Test the api_account_update_profile_image() function with an uploaded file.
3263 * @expectedException Friendica\Network\HTTPException\BadRequestException
3265 public function testApiAccountUpdateProfileImageWithUpload()
3267 $this->markTestIncomplete();
3272 * Test the api_account_update_profile() function.
3275 public function testApiAccountUpdateProfile()
3277 $_POST['name'] = 'new_name';
3278 $_POST['description'] = 'new_description';
3279 $result = api_account_update_profile('json');
3280 // We can't use assertSelfUser() here because the user object is missing some properties.
3281 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3282 $this->assertEquals('Friendica', $result['user']['location']);
3283 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3284 $this->assertEquals('dfrn', $result['user']['network']);
3285 $this->assertEquals('new_name', $result['user']['name']);
3286 $this->assertEquals('new_description', $result['user']['description']);
3290 * Test the check_acl_input() function.
3293 public function testCheckAclInput()
3295 $result = check_acl_input('<aclstring>');
3296 // Where does this result come from?
3297 $this->assertEquals(1, $result);
3301 * Test the check_acl_input() function with an empty ACL string.
3304 public function testCheckAclInputWithEmptyAclString()
3306 $result = check_acl_input(' ');
3307 $this->assertFalse($result);
3311 * Test the save_media_to_database() function.
3314 public function testSaveMediaToDatabase()
3316 $this->markTestIncomplete();
3320 * Test the post_photo_item() function.
3323 public function testPostPhotoItem()
3325 $this->markTestIncomplete();
3329 * Test the prepare_photo_data() function.
3332 public function testPreparePhotoData()
3334 $this->markTestIncomplete();
3338 * Test the api_friendica_remoteauth() function.
3340 * @expectedException Friendica\Network\HTTPException\BadRequestException
3342 public function testApiFriendicaRemoteauth()
3344 api_friendica_remoteauth();
3348 * Test the api_friendica_remoteauth() function with an URL.
3350 * @expectedException Friendica\Network\HTTPException\BadRequestException
3352 public function testApiFriendicaRemoteauthWithUrl()
3354 $_GET['url'] = 'url';
3355 $_GET['c_url'] = 'url';
3356 api_friendica_remoteauth();
3360 * Test the api_friendica_remoteauth() function with a correct URL.
3363 public function testApiFriendicaRemoteauthWithCorrectUrl()
3365 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3366 $_GET['url'] = 'url';
3367 $_GET['c_url'] = $this->selfUser['nurl'];
3368 api_friendica_remoteauth();
3372 * Test the api_share_as_retweet() function.
3375 public function testApiShareAsRetweet()
3377 $item = ['body' => ''];
3378 $result = api_share_as_retweet($item);
3379 $this->assertFalse($result);
3383 * Test the api_share_as_retweet() function with a valid item.
3386 public function testApiShareAsRetweetWithValidItem()
3388 $this->markTestIncomplete();
3392 * Test the api_get_nick() function.
3395 public function testApiGetNick()
3397 $result = api_get_nick($this->otherUser['nurl']);
3398 $this->assertEquals('othercontact', $result);
3402 * Test the api_get_nick() function with a wrong URL.
3405 public function testApiGetNickWithWrongUrl()
3407 $result = api_get_nick('wrong_url');
3408 $this->assertFalse($result);
3412 * Test the api_in_reply_to() function.
3415 public function testApiInReplyTo()
3417 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3418 $this->assertArrayHasKey('status_id', $result);
3419 $this->assertArrayHasKey('user_id', $result);
3420 $this->assertArrayHasKey('status_id_str', $result);
3421 $this->assertArrayHasKey('user_id_str', $result);
3422 $this->assertArrayHasKey('screen_name', $result);
3426 * Test the api_in_reply_to() function with a valid item.
3429 public function testApiInReplyToWithValidItem()
3431 $this->markTestIncomplete();
3435 * Test the api_clean_plain_items() function.
3438 public function testApiCleanPlainItems()
3440 $_REQUEST['include_entities'] = 'true';
3441 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3442 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3446 * Test the api_clean_attachments() function.
3449 public function testApiCleanAttachments()
3451 $this->markTestIncomplete();
3455 * Test the api_best_nickname() function.
3458 public function testApiBestNickname()
3461 $result = api_best_nickname($contacts);
3462 $this->assertNull($result);
3466 * Test the api_best_nickname() function with contacts.
3469 public function testApiBestNicknameWithContacts()
3471 $this->markTestIncomplete();
3475 * Test the api_friendica_group_show() function.
3478 public function testApiFriendicaGroupShow()
3480 $this->markTestIncomplete();
3484 * Test the api_friendica_group_delete() function.
3487 public function testApiFriendicaGroupDelete()
3489 $this->markTestIncomplete();
3493 * Test the api_lists_destroy() function.
3496 public function testApiListsDestroy()
3498 $this->markTestIncomplete();
3502 * Test the group_create() function.
3505 public function testGroupCreate()
3507 $this->markTestIncomplete();
3511 * Test the api_friendica_group_create() function.
3514 public function testApiFriendicaGroupCreate()
3516 $this->markTestIncomplete();
3520 * Test the api_lists_create() function.
3523 public function testApiListsCreate()
3525 $this->markTestIncomplete();
3529 * Test the api_friendica_group_update() function.
3532 public function testApiFriendicaGroupUpdate()
3534 $this->markTestIncomplete();
3538 * Test the api_lists_update() function.
3541 public function testApiListsUpdate()
3543 $this->markTestIncomplete();
3547 * Test the api_friendica_activity() function.
3550 public function testApiFriendicaActivity()
3552 $this->markTestIncomplete();
3556 * Test the api_friendica_notification() function.
3558 * @expectedException Friendica\Network\HTTPException\BadRequestException
3560 public function testApiFriendicaNotification()
3562 api_friendica_notification('json');
3566 * Test the api_friendica_notification() function without an authenticated user.
3568 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3570 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3572 $_SESSION['authenticated'] = false;
3573 api_friendica_notification('json');
3577 * Test the api_friendica_notification() function with an argument count.
3580 public function testApiFriendicaNotificationWithArgumentCount()
3582 $this->app->argv = ['api', 'friendica', 'notification'];
3583 $this->app->argc = count($this->app->argv);
3584 $result = api_friendica_notification('json');
3585 $this->assertEquals(['note' => false], $result);
3589 * Test the api_friendica_notification() function with an XML result.
3592 public function testApiFriendicaNotificationWithXmlResult()
3594 $this->app->argv = ['api', 'friendica', 'notification'];
3595 $this->app->argc = count($this->app->argv);
3596 $result = api_friendica_notification('xml');
3597 $this->assertXml($result, 'notes');
3601 * Test the api_friendica_notification_seen() function.
3604 public function testApiFriendicaNotificationSeen()
3606 $this->markTestIncomplete();
3610 * Test the api_friendica_direct_messages_setseen() function.
3613 public function testApiFriendicaDirectMessagesSetseen()
3615 $this->markTestIncomplete();
3619 * Test the api_friendica_direct_messages_search() function.
3622 public function testApiFriendicaDirectMessagesSearch()
3624 $this->markTestIncomplete();
3628 * Test the api_friendica_profile_show() function.
3631 public function testApiFriendicaProfileShow()
3633 $result = api_friendica_profile_show('json');
3634 // We can't use assertSelfUser() here because the user object is missing some properties.
3635 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3636 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3637 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3638 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3639 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3640 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3641 $this->assertFalse($result['$result']['multi_profiles']);
3645 * Test the api_friendica_profile_show() function with a profile ID.
3648 public function testApiFriendicaProfileShowWithProfileId()
3650 $this->markTestIncomplete('We need to add a dataset for this.');
3654 * Test the api_friendica_profile_show() function with a wrong profile ID.
3656 * @expectedException Friendica\Network\HTTPException\BadRequestException
3658 public function testApiFriendicaProfileShowWithWrongProfileId()
3660 $_REQUEST['profile_id'] = 666;
3661 api_friendica_profile_show('json');
3665 * Test the api_friendica_profile_show() function without an authenticated user.
3667 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3669 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3671 $_SESSION['authenticated'] = false;
3672 api_friendica_profile_show('json');
3676 * Test the api_saved_searches_list() function.
3679 public function testApiSavedSearchesList()
3681 $result = api_saved_searches_list('json');
3682 $this->assertEquals(1, $result['terms'][0]['id']);
3683 $this->assertEquals(1, $result['terms'][0]['id_str']);
3684 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3685 $this->assertEquals('Saved search', $result['terms'][0]['query']);