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()
1206 'tmp_name' => 'tmp_name'
1213 * Test the api_media_upload() function with an valid uploaded media.
1216 public function testApiMediaUploadWithValidMedia()
1224 'tmp_name' => $this->getTempImage(),
1225 'name' => 'spacer.png',
1226 'type' => 'image/png'
1232 $result = api_media_upload();
1233 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1234 $this->assertEquals(1, $result['media']['image']['w']);
1235 $this->assertEquals(1, $result['media']['image']['h']);
1239 * Test the api_status_show() function.
1242 public function testApiStatusShow()
1244 $result = api_status_show('json');
1245 $this->assertStatus($result['status']);
1249 * Test the api_status_show() function with an XML result.
1252 public function testApiStatusShowWithXml()
1254 $result = api_status_show('xml');
1255 $this->assertXml($result, 'statuses');
1259 * Test the api_status_show() function with a raw result.
1262 public function testApiStatusShowWithRaw()
1264 $this->assertStatus(api_status_show('raw'));
1268 * Test the api_users_show() function.
1271 public function testApiUsersShow()
1273 $result = api_users_show('json');
1274 // We can't use assertSelfUser() here because the user object is missing some properties.
1275 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1276 $this->assertEquals('Friendica', $result['user']['location']);
1277 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1278 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1279 $this->assertEquals('dfrn', $result['user']['network']);
1280 $this->assertTrue($result['user']['verified']);
1284 * Test the api_users_show() function with an XML result.
1287 public function testApiUsersShowWithXml()
1289 $result = api_users_show('xml');
1290 $this->assertXml($result, 'statuses');
1294 * Test the api_users_search() function.
1297 public function testApiUsersSearch()
1299 $_GET['q'] = 'othercontact';
1300 $result = api_users_search('json');
1301 $this->assertOtherUser($result['users'][0]);
1305 * Test the api_users_search() function with an XML result.
1308 public function testApiUsersSearchWithXml()
1310 $_GET['q'] = 'othercontact';
1311 $result = api_users_search('xml');
1312 $this->assertXml($result, 'users');
1316 * Test the api_users_search() function without a GET q parameter.
1318 * @expectedException Friendica\Network\HTTPException\BadRequestException
1320 public function testApiUsersSearchWithoutQuery()
1322 api_users_search('json');
1326 * Test the api_users_lookup() function.
1328 * @expectedException Friendica\Network\HTTPException\NotFoundException
1330 public function testApiUsersLookup()
1332 api_users_lookup('json');
1336 * Test the api_users_lookup() function with an user ID.
1339 public function testApiUsersLookupWithUserId()
1341 $_REQUEST['user_id'] = $this->otherUser['id'];
1342 $result = api_users_lookup('json');
1343 $this->assertOtherUser($result['users'][0]);
1347 * Test the api_search() function.
1350 public function testApiSearch()
1352 $_REQUEST['q'] = 'reply';
1353 $_REQUEST['max_id'] = 10;
1354 $result = api_search('json');
1355 foreach ($result['status'] as $status) {
1356 $this->assertStatus($status);
1357 $this->assertContains('reply', $status['text'], null, true);
1362 * Test the api_search() function a count parameter.
1365 public function testApiSearchWithCount()
1367 $_REQUEST['q'] = 'reply';
1368 $_REQUEST['count'] = 20;
1369 $result = api_search('json');
1370 foreach ($result['status'] as $status) {
1371 $this->assertStatus($status);
1372 $this->assertContains('reply', $status['text'], null, true);
1377 * Test the api_search() function with an rpp parameter.
1380 public function testApiSearchWithRpp()
1382 $_REQUEST['q'] = 'reply';
1383 $_REQUEST['rpp'] = 20;
1384 $result = api_search('json');
1385 foreach ($result['status'] as $status) {
1386 $this->assertStatus($status);
1387 $this->assertContains('reply', $status['text'], null, true);
1393 * Test the api_search() function without an authenticated user.
1395 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1397 public function testApiSearchWithUnallowedUser()
1399 $_SESSION['allow_api'] = false;
1400 $_GET['screen_name'] = $this->selfUser['nick'];
1405 * Test the api_search() function without any GET query parameter.
1407 * @expectedException Friendica\Network\HTTPException\BadRequestException
1409 public function testApiSearchWithoutQuery()
1415 * Test the api_statuses_home_timeline() function.
1418 public function testApiStatusesHomeTimeline()
1420 $_REQUEST['max_id'] = 10;
1421 $_REQUEST['exclude_replies'] = true;
1422 $_REQUEST['conversation_id'] = 1;
1423 $result = api_statuses_home_timeline('json');
1424 $this->assertNotEmpty($result['status']);
1425 foreach ($result['status'] as $status) {
1426 $this->assertStatus($status);
1431 * Test the api_statuses_home_timeline() function with a negative page parameter.
1434 public function testApiStatusesHomeTimelineWithNegativePage()
1436 $_REQUEST['page'] = -2;
1437 $result = api_statuses_home_timeline('json');
1438 $this->assertNotEmpty($result['status']);
1439 foreach ($result['status'] as $status) {
1440 $this->assertStatus($status);
1445 * Test the api_statuses_home_timeline() with an unallowed user.
1447 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1449 public function testApiStatusesHomeTimelineWithUnallowedUser()
1451 $_SESSION['allow_api'] = false;
1452 $_GET['screen_name'] = $this->selfUser['nick'];
1453 api_statuses_home_timeline('json');
1457 * Test the api_statuses_home_timeline() function with an RSS result.
1460 public function testApiStatusesHomeTimelineWithRss()
1462 $result = api_statuses_home_timeline('rss');
1463 $this->assertXml($result, 'statuses');
1467 * Test the api_statuses_public_timeline() function.
1470 public function testApiStatusesPublicTimeline()
1472 $_REQUEST['max_id'] = 10;
1473 $_REQUEST['conversation_id'] = 1;
1474 $result = api_statuses_public_timeline('json');
1475 $this->assertNotEmpty($result['status']);
1476 foreach ($result['status'] as $status) {
1477 $this->assertStatus($status);
1482 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1485 public function testApiStatusesPublicTimelineWithExcludeReplies()
1487 $_REQUEST['max_id'] = 10;
1488 $_REQUEST['exclude_replies'] = true;
1489 $result = api_statuses_public_timeline('json');
1490 $this->assertNotEmpty($result['status']);
1491 foreach ($result['status'] as $status) {
1492 $this->assertStatus($status);
1497 * Test the api_statuses_public_timeline() function with a negative page parameter.
1500 public function testApiStatusesPublicTimelineWithNegativePage()
1502 $_REQUEST['page'] = -2;
1503 $result = api_statuses_public_timeline('json');
1504 $this->assertNotEmpty($result['status']);
1505 foreach ($result['status'] as $status) {
1506 $this->assertStatus($status);
1511 * Test the api_statuses_public_timeline() function with an unallowed user.
1513 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1515 public function testApiStatusesPublicTimelineWithUnallowedUser()
1517 $_SESSION['allow_api'] = false;
1518 $_GET['screen_name'] = $this->selfUser['nick'];
1519 api_statuses_public_timeline('json');
1523 * Test the api_statuses_public_timeline() function with an RSS result.
1526 public function testApiStatusesPublicTimelineWithRss()
1528 $result = api_statuses_public_timeline('rss');
1529 $this->assertXml($result, 'statuses');
1533 * Test the api_statuses_networkpublic_timeline() function.
1536 public function testApiStatusesNetworkpublicTimeline()
1538 $_REQUEST['max_id'] = 10;
1539 $result = api_statuses_networkpublic_timeline('json');
1540 $this->assertNotEmpty($result['status']);
1541 foreach ($result['status'] as $status) {
1542 $this->assertStatus($status);
1547 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1550 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1552 $_REQUEST['page'] = -2;
1553 $result = api_statuses_networkpublic_timeline('json');
1554 $this->assertNotEmpty($result['status']);
1555 foreach ($result['status'] as $status) {
1556 $this->assertStatus($status);
1561 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1563 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1565 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1567 $_SESSION['allow_api'] = false;
1568 $_GET['screen_name'] = $this->selfUser['nick'];
1569 api_statuses_networkpublic_timeline('json');
1573 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1576 public function testApiStatusesNetworkpublicTimelineWithRss()
1578 $result = api_statuses_networkpublic_timeline('rss');
1579 $this->assertXml($result, 'statuses');
1583 * Test the api_statuses_show() function.
1585 * @expectedException Friendica\Network\HTTPException\BadRequestException
1587 public function testApiStatusesShow()
1589 api_statuses_show('json');
1593 * Test the api_statuses_show() function with an ID.
1596 public function testApiStatusesShowWithId()
1598 $this->app->argv[3] = 1;
1599 $result = api_statuses_show('json');
1600 $this->assertStatus($result['status']);
1604 * Test the api_statuses_show() function with the conversation parameter.
1607 public function testApiStatusesShowWithConversation()
1609 $this->app->argv[3] = 1;
1610 $_REQUEST['conversation'] = 1;
1611 $result = api_statuses_show('json');
1612 $this->assertNotEmpty($result['status']);
1613 foreach ($result['status'] as $status) {
1614 $this->assertStatus($status);
1619 * Test the api_statuses_show() function with an unallowed user.
1621 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1623 public function testApiStatusesShowWithUnallowedUser()
1625 $_SESSION['allow_api'] = false;
1626 $_GET['screen_name'] = $this->selfUser['nick'];
1627 api_statuses_show('json');
1631 * Test the api_conversation_show() function.
1633 * @expectedException Friendica\Network\HTTPException\BadRequestException
1635 public function testApiConversationShow()
1637 api_conversation_show('json');
1641 * Test the api_conversation_show() function with an ID.
1644 public function testApiConversationShowWithId()
1646 $this->app->argv[3] = 1;
1647 $_REQUEST['max_id'] = 10;
1648 $_REQUEST['page'] = -2;
1649 $result = api_conversation_show('json');
1650 $this->assertNotEmpty($result['status']);
1651 foreach ($result['status'] as $status) {
1652 $this->assertStatus($status);
1657 * Test the api_conversation_show() function with an unallowed user.
1659 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1661 public function testApiConversationShowWithUnallowedUser()
1663 $_SESSION['allow_api'] = false;
1664 $_GET['screen_name'] = $this->selfUser['nick'];
1665 api_conversation_show('json');
1669 * Test the api_statuses_repeat() function.
1671 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1673 public function testApiStatusesRepeat()
1675 api_statuses_repeat('json');
1679 * Test the api_statuses_repeat() function without an authenticated user.
1681 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1683 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1685 $_SESSION['authenticated'] = false;
1686 api_statuses_repeat('json');
1690 * Test the api_statuses_repeat() function with an ID.
1693 public function testApiStatusesRepeatWithId()
1695 $this->app->argv[3] = 1;
1696 $result = api_statuses_repeat('json');
1697 $this->assertStatus($result['status']);
1699 // Also test with a shared status
1700 $this->app->argv[3] = 5;
1701 $result = api_statuses_repeat('json');
1702 $this->assertStatus($result['status']);
1706 * Test the api_statuses_destroy() function.
1708 * @expectedException Friendica\Network\HTTPException\BadRequestException
1710 public function testApiStatusesDestroy()
1712 api_statuses_destroy('json');
1716 * Test the api_statuses_destroy() function without an authenticated user.
1718 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1720 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1722 $_SESSION['authenticated'] = false;
1723 api_statuses_destroy('json');
1727 * Test the api_statuses_destroy() function with an ID.
1730 public function testApiStatusesDestroyWithId()
1732 $this->app->argv[3] = 1;
1733 $result = api_statuses_destroy('json');
1734 $this->assertStatus($result['status']);
1738 * Test the api_statuses_mentions() function.
1741 public function testApiStatusesMentions()
1743 $this->app->user = ['nickname' => $this->selfUser['nick']];
1744 $_REQUEST['max_id'] = 10;
1745 $result = api_statuses_mentions('json');
1746 $this->assertEmpty($result['status']);
1747 // We should test with mentions in the database.
1751 * Test the api_statuses_mentions() function with a negative page parameter.
1754 public function testApiStatusesMentionsWithNegativePage()
1756 $_REQUEST['page'] = -2;
1757 $result = api_statuses_mentions('json');
1758 $this->assertEmpty($result['status']);
1762 * Test the api_statuses_mentions() function with an unallowed user.
1764 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1766 public function testApiStatusesMentionsWithUnallowedUser()
1768 $_SESSION['allow_api'] = false;
1769 $_GET['screen_name'] = $this->selfUser['nick'];
1770 api_statuses_mentions('json');
1774 * Test the api_statuses_mentions() function with an RSS result.
1777 public function testApiStatusesMentionsWithRss()
1779 $result = api_statuses_mentions('rss');
1780 $this->assertXml($result, 'statuses');
1784 * Test the api_statuses_user_timeline() function.
1787 public function testApiStatusesUserTimeline()
1789 $_REQUEST['max_id'] = 10;
1790 $_REQUEST['exclude_replies'] = true;
1791 $_REQUEST['conversation_id'] = 1;
1792 $result = api_statuses_user_timeline('json');
1793 $this->assertNotEmpty($result['status']);
1794 foreach ($result['status'] as $status) {
1795 $this->assertStatus($status);
1800 * Test the api_statuses_user_timeline() function with a negative page parameter.
1803 public function testApiStatusesUserTimelineWithNegativePage()
1805 $_REQUEST['page'] = -2;
1806 $result = api_statuses_user_timeline('json');
1807 $this->assertNotEmpty($result['status']);
1808 foreach ($result['status'] as $status) {
1809 $this->assertStatus($status);
1814 * Test the api_statuses_user_timeline() function with an RSS result.
1817 public function testApiStatusesUserTimelineWithRss()
1819 $result = api_statuses_user_timeline('rss');
1820 $this->assertXml($result, 'statuses');
1824 * Test the api_statuses_user_timeline() function with an unallowed user.
1826 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1828 public function testApiStatusesUserTimelineWithUnallowedUser()
1830 $_SESSION['allow_api'] = false;
1831 $_GET['screen_name'] = $this->selfUser['nick'];
1832 api_statuses_user_timeline('json');
1836 * Test the api_favorites_create_destroy() function.
1838 * @expectedException Friendica\Network\HTTPException\BadRequestException
1840 public function testApiFavoritesCreateDestroy()
1842 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1843 $this->app->argc = count($this->app->argv);
1844 api_favorites_create_destroy('json');
1848 * Test the api_favorites_create_destroy() function with an invalid ID.
1850 * @expectedException Friendica\Network\HTTPException\BadRequestException
1852 public function testApiFavoritesCreateDestroyWithInvalidId()
1854 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1855 $this->app->argc = count($this->app->argv);
1856 api_favorites_create_destroy('json');
1860 * Test the api_favorites_create_destroy() function with an invalid action.
1862 * @expectedException Friendica\Network\HTTPException\BadRequestException
1864 public function testApiFavoritesCreateDestroyWithInvalidAction()
1866 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1867 $this->app->argc = count($this->app->argv);
1868 $_REQUEST['id'] = 1;
1869 api_favorites_create_destroy('json');
1873 * Test the api_favorites_create_destroy() function with the create action.
1876 public function testApiFavoritesCreateDestroyWithCreateAction()
1878 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1879 $this->app->argc = count($this->app->argv);
1880 $_REQUEST['id'] = 3;
1881 $result = api_favorites_create_destroy('json');
1882 $this->assertStatus($result['status']);
1886 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1889 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1891 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1892 $this->app->argc = count($this->app->argv);
1893 $_REQUEST['id'] = 3;
1894 $result = api_favorites_create_destroy('rss');
1895 $this->assertXml($result, 'status');
1899 * Test the api_favorites_create_destroy() function with the destroy action.
1902 public function testApiFavoritesCreateDestroyWithDestroyAction()
1904 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1905 $this->app->argc = count($this->app->argv);
1906 $_REQUEST['id'] = 3;
1907 $result = api_favorites_create_destroy('json');
1908 $this->assertStatus($result['status']);
1912 * Test the api_favorites_create_destroy() function without an authenticated user.
1914 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1916 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1918 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1919 $this->app->argc = count($this->app->argv);
1920 $_SESSION['authenticated'] = false;
1921 api_favorites_create_destroy('json');
1925 * Test the api_favorites() function.
1928 public function testApiFavorites()
1930 $_REQUEST['page'] = -1;
1931 $_REQUEST['max_id'] = 10;
1932 $result = api_favorites('json');
1933 foreach ($result['status'] as $status) {
1934 $this->assertStatus($status);
1939 * Test the api_favorites() function with an RSS result.
1942 public function testApiFavoritesWithRss()
1944 $result = api_favorites('rss');
1945 $this->assertXml($result, 'statuses');
1949 * Test the api_favorites() function with an unallowed user.
1951 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1953 public function testApiFavoritesWithUnallowedUser()
1955 $_SESSION['allow_api'] = false;
1956 $_GET['screen_name'] = $this->selfUser['nick'];
1957 api_favorites('json');
1961 * Test the api_format_messages() function.
1964 public function testApiFormatMessages()
1966 $result = api_format_messages(
1967 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1968 ['id' => 2, 'screen_name' => 'recipient_name'],
1969 ['id' => 3, 'screen_name' => 'sender_name']
1971 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1972 $this->assertEquals(1, $result['id']);
1973 $this->assertEquals(2, $result['recipient_id']);
1974 $this->assertEquals(3, $result['sender_id']);
1975 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1976 $this->assertEquals('sender_name', $result['sender_screen_name']);
1980 * Test the api_format_messages() function with HTML.
1983 public function testApiFormatMessagesWithHtmlText()
1985 $_GET['getText'] = 'html';
1986 $result = api_format_messages(
1987 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1988 ['id' => 2, 'screen_name' => 'recipient_name'],
1989 ['id' => 3, 'screen_name' => 'sender_name']
1991 $this->assertEquals('item_title', $result['title']);
1992 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1996 * Test the api_format_messages() function with plain text.
1999 public function testApiFormatMessagesWithPlainText()
2001 $_GET['getText'] = 'plain';
2002 $result = api_format_messages(
2003 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2004 ['id' => 2, 'screen_name' => 'recipient_name'],
2005 ['id' => 3, 'screen_name' => 'sender_name']
2007 $this->assertEquals('item_title', $result['title']);
2008 $this->assertEquals('item_body', $result['text']);
2012 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2015 public function testApiFormatMessagesWithoutUserObjects()
2017 $_GET['getUserObjects'] = 'false';
2018 $result = api_format_messages(
2019 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2020 ['id' => 2, 'screen_name' => 'recipient_name'],
2021 ['id' => 3, 'screen_name' => 'sender_name']
2023 $this->assertTrue(!isset($result['sender']));
2024 $this->assertTrue(!isset($result['recipient']));
2028 * Test the api_convert_item() function.
2031 public function testApiConvertItem()
2033 $result = api_convert_item(
2035 'network' => 'feed',
2036 'title' => 'item_title',
2037 // We need a long string to test that it is correctly cut
2038 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2039 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2040 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2041 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2042 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2043 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2044 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2045 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2046 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2047 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2048 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2049 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2050 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2051 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2052 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2053 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2054 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2055 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2056 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2057 'repellat officia illum quos impedit quam iste esse unde qui '.
2058 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2059 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2060 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2061 'plink' => 'item_plink'
2064 $this->assertStringStartsWith('item_title', $result['text']);
2065 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2069 * Test the api_convert_item() function with an empty item body.
2072 public function testApiConvertItemWithoutBody()
2074 $result = api_convert_item(
2076 'network' => 'feed',
2077 'title' => 'item_title',
2079 'plink' => 'item_plink'
2082 $this->assertEquals('item_title', $result['text']);
2083 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2087 * Test the api_convert_item() function with the title in the body.
2090 public function testApiConvertItemWithTitleInBody()
2092 $result = api_convert_item(
2094 'title' => 'item_title',
2095 'body' => 'item_title item_body'
2098 $this->assertEquals('item_title item_body', $result['text']);
2099 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2103 * Test the api_get_attachments() function.
2106 public function testApiGetAttachments()
2109 $this->assertEmpty(api_get_attachments($body));
2113 * Test the api_get_attachments() function with an img tag.
2116 public function testApiGetAttachmentsWithImage()
2118 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2119 $this->assertInternalType('array', api_get_attachments($body));
2123 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2126 public function testApiGetAttachmentsWithImageAndAndStatus()
2128 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2129 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2130 $this->assertInternalType('array', api_get_attachments($body));
2134 * Test the api_get_entitities() function.
2137 public function testApiGetEntitities()
2140 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2144 * Test the api_get_entitities() function with the include_entities parameter.
2147 public function testApiGetEntititiesWithIncludeEntities()
2149 $_REQUEST['include_entities'] = 'true';
2151 $result = api_get_entitities($text, 'bbcode');
2152 $this->assertInternalType('array', $result['hashtags']);
2153 $this->assertInternalType('array', $result['symbols']);
2154 $this->assertInternalType('array', $result['urls']);
2155 $this->assertInternalType('array', $result['user_mentions']);
2159 * Test the api_format_items_embeded_images() function.
2162 public function testApiFormatItemsEmbededImages()
2164 $this->assertEquals(
2165 'text ' . System::baseUrl() . '/display/item_guid',
2166 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2171 * Test the api_contactlink_to_array() function.
2174 public function testApiContactlinkToArray()
2176 $this->assertEquals(
2181 api_contactlink_to_array('text')
2186 * Test the api_contactlink_to_array() function with an URL.
2189 public function testApiContactlinkToArrayWithUrl()
2191 $this->assertEquals(
2193 'name' => ['link_text'],
2196 api_contactlink_to_array('text <a href="url">link_text</a>')
2201 * Test the api_format_items_activities() function.
2204 public function testApiFormatItemsActivities()
2206 $item = ['uid' => 0, 'uri' => ''];
2207 $result = api_format_items_activities($item);
2208 $this->assertArrayHasKey('like', $result);
2209 $this->assertArrayHasKey('dislike', $result);
2210 $this->assertArrayHasKey('attendyes', $result);
2211 $this->assertArrayHasKey('attendno', $result);
2212 $this->assertArrayHasKey('attendmaybe', $result);
2216 * Test the api_format_items_activities() function with an XML result.
2219 public function testApiFormatItemsActivitiesWithXml()
2221 $item = ['uid' => 0, 'uri' => ''];
2222 $result = api_format_items_activities($item, 'xml');
2223 $this->assertArrayHasKey('friendica:like', $result);
2224 $this->assertArrayHasKey('friendica:dislike', $result);
2225 $this->assertArrayHasKey('friendica:attendyes', $result);
2226 $this->assertArrayHasKey('friendica:attendno', $result);
2227 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2231 * Test the api_format_items_profiles() function.
2234 public function testApiFormatItemsProfiles()
2237 'id' => 'profile_id',
2238 'profile-name' => 'profile_name',
2239 'is-default' => true,
2240 'hide-friends' => true,
2241 'photo' => 'profile_photo',
2242 'thumb' => 'profile_thumb',
2244 'net-publish' => true,
2245 'pdesc' => 'description',
2246 'dob' => 'date_of_birth',
2247 'address' => 'address',
2248 'locality' => 'city',
2249 'region' => 'region',
2250 'postal-code' => 'postal_code',
2251 'country-name' => 'country',
2252 'hometown' => 'hometown',
2253 'gender' => 'gender',
2254 'marital' => 'marital',
2255 'with' => 'marital_with',
2256 'howlong' => 'marital_since',
2257 'sexual' => 'sexual',
2258 'politic' => 'politic',
2259 'religion' => 'religion',
2260 'pub_keywords' => 'public_keywords',
2261 'prv_keywords' => 'private_keywords',
2264 'dislikes' => 'dislikes',
2270 'interest' => 'interest',
2271 'romance' => 'romance',
2273 'education' => 'education',
2274 'contact' => 'social_networks',
2275 'homepage' => 'homepage'
2277 $result = api_format_items_profiles($profile_row);
2278 $this->assertEquals(
2280 'profile_id' => 'profile_id',
2281 'profile_name' => 'profile_name',
2282 'is_default' => true,
2283 'hide_friends' => true,
2284 'profile_photo' => 'profile_photo',
2285 'profile_thumb' => 'profile_thumb',
2287 'net_publish' => true,
2288 'description' => 'description',
2289 'date_of_birth' => 'date_of_birth',
2290 'address' => 'address',
2292 'region' => 'region',
2293 'postal_code' => 'postal_code',
2294 'country' => 'country',
2295 'hometown' => 'hometown',
2296 'gender' => 'gender',
2297 'marital' => 'marital',
2298 'marital_with' => 'marital_with',
2299 'marital_since' => 'marital_since',
2300 'sexual' => 'sexual',
2301 'politic' => 'politic',
2302 'religion' => 'religion',
2303 'public_keywords' => 'public_keywords',
2304 'private_keywords' => 'private_keywords',
2307 'dislikes' => 'dislikes',
2313 'interest' => 'interest',
2314 'romance' => 'romance',
2316 'education' => 'education',
2317 'social_networks' => 'social_networks',
2318 'homepage' => 'homepage',
2326 * Test the api_format_items() function.
2329 public function testApiFormatItems()
2333 'item_network' => 'item_network',
2339 'author-network' => Protocol::DFRN,
2340 'author-link' => 'http://localhost/profile/othercontact',
2344 $result = api_format_items($items, ['id' => 0], true);
2345 foreach ($result as $status) {
2346 $this->assertStatus($status);
2351 * Test the api_format_items() function with an XML result.
2354 public function testApiFormatItemsWithXml()
2362 'author-network' => Protocol::DFRN,
2363 'author-link' => 'http://localhost/profile/othercontact',
2367 $result = api_format_items($items, ['id' => 0], true, 'xml');
2368 foreach ($result as $status) {
2369 $this->assertStatus($status);
2374 * Test the api_format_items() function.
2377 public function testApiAccountRateLimitStatus()
2379 $result = api_account_rate_limit_status('json');
2380 $this->assertEquals(150, $result['hash']['remaining_hits']);
2381 $this->assertEquals(150, $result['hash']['hourly_limit']);
2382 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2386 * Test the api_format_items() function with an XML result.
2389 public function testApiAccountRateLimitStatusWithXml()
2391 $result = api_account_rate_limit_status('xml');
2392 $this->assertXml($result, 'hash');
2396 * Test the api_help_test() function.
2399 public function testApiHelpTest()
2401 $result = api_help_test('json');
2402 $this->assertEquals(['ok' => 'ok'], $result);
2406 * Test the api_help_test() function with an XML result.
2409 public function testApiHelpTestWithXml()
2411 $result = api_help_test('xml');
2412 $this->assertXml($result, 'ok');
2416 * Test the api_lists_list() function.
2419 public function testApiListsList()
2421 $result = api_lists_list('json');
2422 $this->assertEquals(['lists_list' => []], $result);
2426 * Test the api_lists_ownerships() function.
2429 public function testApiListsOwnerships()
2431 $result = api_lists_ownerships('json');
2432 foreach ($result['lists']['lists'] as $list) {
2433 $this->assertList($list);
2438 * Test the api_lists_ownerships() function without an authenticated user.
2440 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2442 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2444 $_SESSION['authenticated'] = false;
2445 api_lists_ownerships('json');
2449 * Test the api_lists_statuses() function.
2450 * @expectedException Friendica\Network\HTTPException\BadRequestException
2453 public function testApiListsStatuses()
2455 api_lists_statuses('json');
2459 * Test the api_lists_statuses() function with a list ID.
2462 public function testApiListsStatusesWithListId()
2464 $_REQUEST['list_id'] = 1;
2465 $_REQUEST['page'] = -1;
2466 $_REQUEST['max_id'] = 10;
2467 $result = api_lists_statuses('json');
2468 foreach ($result['status'] as $status) {
2469 $this->assertStatus($status);
2474 * Test the api_lists_statuses() function with a list ID and a RSS result.
2477 public function testApiListsStatusesWithListIdAndRss()
2479 $_REQUEST['list_id'] = 1;
2480 $result = api_lists_statuses('rss');
2481 $this->assertXml($result, 'statuses');
2485 * Test the api_lists_statuses() function with an unallowed user.
2487 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2489 public function testApiListsStatusesWithUnallowedUser()
2491 $_SESSION['allow_api'] = false;
2492 $_GET['screen_name'] = $this->selfUser['nick'];
2493 api_lists_statuses('json');
2497 * Test the api_statuses_f() function.
2500 public function testApiStatusesFWithFriends()
2503 $result = api_statuses_f('friends');
2504 $this->assertArrayHasKey('user', $result);
2508 * Test the api_statuses_f() function.
2511 public function testApiStatusesFWithFollowers()
2513 $result = api_statuses_f('followers');
2514 $this->assertArrayHasKey('user', $result);
2518 * Test the api_statuses_f() function.
2521 public function testApiStatusesFWithBlocks()
2523 $result = api_statuses_f('blocks');
2524 $this->assertArrayHasKey('user', $result);
2528 * Test the api_statuses_f() function.
2531 public function testApiStatusesFWithIncoming()
2533 $result = api_statuses_f('incoming');
2534 $this->assertArrayHasKey('user', $result);
2538 * Test the api_statuses_f() function an undefined cursor GET variable.
2541 public function testApiStatusesFWithUndefinedCursor()
2543 $_GET['cursor'] = 'undefined';
2544 $this->assertFalse(api_statuses_f('friends'));
2548 * Test the api_statuses_friends() function.
2551 public function testApiStatusesFriends()
2553 $result = api_statuses_friends('json');
2554 $this->assertArrayHasKey('user', $result);
2558 * Test the api_statuses_friends() function an undefined cursor GET variable.
2561 public function testApiStatusesFriendsWithUndefinedCursor()
2563 $_GET['cursor'] = 'undefined';
2564 $this->assertFalse(api_statuses_friends('json'));
2568 * Test the api_statuses_followers() function.
2571 public function testApiStatusesFollowers()
2573 $result = api_statuses_followers('json');
2574 $this->assertArrayHasKey('user', $result);
2578 * Test the api_statuses_followers() function an undefined cursor GET variable.
2581 public function testApiStatusesFollowersWithUndefinedCursor()
2583 $_GET['cursor'] = 'undefined';
2584 $this->assertFalse(api_statuses_followers('json'));
2588 * Test the api_blocks_list() function.
2591 public function testApiBlocksList()
2593 $result = api_blocks_list('json');
2594 $this->assertArrayHasKey('user', $result);
2598 * Test the api_blocks_list() function an undefined cursor GET variable.
2601 public function testApiBlocksListWithUndefinedCursor()
2603 $_GET['cursor'] = 'undefined';
2604 $this->assertFalse(api_blocks_list('json'));
2608 * Test the api_friendships_incoming() function.
2611 public function testApiFriendshipsIncoming()
2613 $result = api_friendships_incoming('json');
2614 $this->assertArrayHasKey('id', $result);
2618 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2621 public function testApiFriendshipsIncomingWithUndefinedCursor()
2623 $_GET['cursor'] = 'undefined';
2624 $this->assertFalse(api_friendships_incoming('json'));
2628 * Test the api_statusnet_config() function.
2631 public function testApiStatusnetConfig()
2633 $result = api_statusnet_config('json');
2634 $this->assertEquals('localhost', $result['config']['site']['server']);
2635 $this->assertEquals('default', $result['config']['site']['theme']);
2636 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2637 $this->assertTrue($result['config']['site']['fancy']);
2638 $this->assertEquals('en', $result['config']['site']['language']);
2639 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2640 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2641 $this->assertEquals('false', $result['config']['site']['private']);
2642 $this->assertEquals('false', $result['config']['site']['ssl']);
2643 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2647 * Test the api_statusnet_version() function.
2650 public function testApiStatusnetVersion()
2652 $result = api_statusnet_version('json');
2653 $this->assertEquals('0.9.7', $result['version']);
2657 * Test the api_ff_ids() function.
2660 public function testApiFfIds()
2662 $result = api_ff_ids('json');
2663 $this->assertNull($result);
2667 * Test the api_ff_ids() function with a result.
2670 public function testApiFfIdsWithResult()
2672 $this->markTestIncomplete();
2676 * Test the api_ff_ids() function without an authenticated user.
2678 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2680 public function testApiFfIdsWithoutAuthenticatedUser()
2682 $_SESSION['authenticated'] = false;
2687 * Test the api_friends_ids() function.
2690 public function testApiFriendsIds()
2692 $result = api_friends_ids('json');
2693 $this->assertNull($result);
2697 * Test the api_followers_ids() function.
2700 public function testApiFollowersIds()
2702 $result = api_followers_ids('json');
2703 $this->assertNull($result);
2707 * Test the api_direct_messages_new() function.
2710 public function testApiDirectMessagesNew()
2712 $result = api_direct_messages_new('json');
2713 $this->assertNull($result);
2717 * Test the api_direct_messages_new() function without an authenticated user.
2719 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2721 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2723 $_SESSION['authenticated'] = false;
2724 api_direct_messages_new('json');
2728 * Test the api_direct_messages_new() function with an user ID.
2731 public function testApiDirectMessagesNewWithUserId()
2733 $_POST['text'] = 'message_text';
2734 $_POST['user_id'] = $this->otherUser['id'];
2735 $result = api_direct_messages_new('json');
2736 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2740 * Test the api_direct_messages_new() function with a screen name.
2743 public function testApiDirectMessagesNewWithScreenName()
2745 $_POST['text'] = 'message_text';
2746 $_POST['screen_name'] = $this->friendUser['nick'];
2747 $result = api_direct_messages_new('json');
2748 $this->assertEquals(1, $result['direct_message']['id']);
2749 $this->assertContains('message_text', $result['direct_message']['text']);
2750 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2751 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2755 * Test the api_direct_messages_new() function with a title.
2758 public function testApiDirectMessagesNewWithTitle()
2760 $_POST['text'] = 'message_text';
2761 $_POST['screen_name'] = $this->friendUser['nick'];
2762 $_REQUEST['title'] = 'message_title';
2763 $result = api_direct_messages_new('json');
2764 $this->assertEquals(1, $result['direct_message']['id']);
2765 $this->assertContains('message_text', $result['direct_message']['text']);
2766 $this->assertContains('message_title', $result['direct_message']['text']);
2767 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2768 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2772 * Test the api_direct_messages_new() function with an RSS result.
2775 public function testApiDirectMessagesNewWithRss()
2777 $_POST['text'] = 'message_text';
2778 $_POST['screen_name'] = $this->friendUser['nick'];
2779 $result = api_direct_messages_new('rss');
2780 $this->assertXml($result, 'direct-messages');
2784 * Test the api_direct_messages_destroy() function.
2786 * @expectedException Friendica\Network\HTTPException\BadRequestException
2788 public function testApiDirectMessagesDestroy()
2790 api_direct_messages_destroy('json');
2794 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2797 public function testApiDirectMessagesDestroyWithVerbose()
2799 $_GET['friendica_verbose'] = 'true';
2800 $result = api_direct_messages_destroy('json');
2801 $this->assertEquals(
2804 'result' => 'error',
2805 'message' => 'message id or parenturi not specified'
2813 * Test the api_direct_messages_destroy() function without an authenticated user.
2815 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2817 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2819 $_SESSION['authenticated'] = false;
2820 api_direct_messages_destroy('json');
2824 * Test the api_direct_messages_destroy() function with a non-zero ID.
2826 * @expectedException Friendica\Network\HTTPException\BadRequestException
2828 public function testApiDirectMessagesDestroyWithId()
2830 $_REQUEST['id'] = 1;
2831 api_direct_messages_destroy('json');
2835 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2838 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2840 $_REQUEST['id'] = 1;
2841 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2842 $_GET['friendica_verbose'] = 'true';
2843 $result = api_direct_messages_destroy('json');
2844 $this->assertEquals(
2847 'result' => 'error',
2848 'message' => 'message id not in database'
2856 * Test the api_direct_messages_destroy() function with a non-zero ID.
2859 public function testApiDirectMessagesDestroyWithCorrectId()
2861 $this->markTestIncomplete('We need to add a dataset for this.');
2865 * Test the api_direct_messages_box() function.
2868 public function testApiDirectMessagesBoxWithSentbox()
2870 $_REQUEST['page'] = -1;
2871 $_REQUEST['max_id'] = 10;
2872 $result = api_direct_messages_box('json', 'sentbox', 'false');
2873 $this->assertArrayHasKey('direct_message', $result);
2877 * Test the api_direct_messages_box() function.
2880 public function testApiDirectMessagesBoxWithConversation()
2882 $result = api_direct_messages_box('json', 'conversation', 'false');
2883 $this->assertArrayHasKey('direct_message', $result);
2887 * Test the api_direct_messages_box() function.
2890 public function testApiDirectMessagesBoxWithAll()
2892 $result = api_direct_messages_box('json', 'all', 'false');
2893 $this->assertArrayHasKey('direct_message', $result);
2897 * Test the api_direct_messages_box() function.
2900 public function testApiDirectMessagesBoxWithInbox()
2902 $result = api_direct_messages_box('json', 'inbox', 'false');
2903 $this->assertArrayHasKey('direct_message', $result);
2907 * Test the api_direct_messages_box() function.
2910 public function testApiDirectMessagesBoxWithVerbose()
2912 $result = api_direct_messages_box('json', 'sentbox', 'true');
2913 $this->assertEquals(
2916 'result' => 'error',
2917 'message' => 'no mails available'
2925 * Test the api_direct_messages_box() function with a RSS result.
2928 public function testApiDirectMessagesBoxWithRss()
2930 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2931 $this->assertXml($result, 'direct-messages');
2935 * Test the api_direct_messages_box() function without an authenticated user.
2937 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2939 public function testApiDirectMessagesBoxWithUnallowedUser()
2941 $_SESSION['allow_api'] = false;
2942 $_GET['screen_name'] = $this->selfUser['nick'];
2943 api_direct_messages_box('json', 'sentbox', 'false');
2947 * Test the api_direct_messages_sentbox() function.
2950 public function testApiDirectMessagesSentbox()
2952 $result = api_direct_messages_sentbox('json');
2953 $this->assertArrayHasKey('direct_message', $result);
2957 * Test the api_direct_messages_inbox() function.
2960 public function testApiDirectMessagesInbox()
2962 $result = api_direct_messages_inbox('json');
2963 $this->assertArrayHasKey('direct_message', $result);
2967 * Test the api_direct_messages_all() function.
2970 public function testApiDirectMessagesAll()
2972 $result = api_direct_messages_all('json');
2973 $this->assertArrayHasKey('direct_message', $result);
2977 * Test the api_direct_messages_conversation() function.
2980 public function testApiDirectMessagesConversation()
2982 $result = api_direct_messages_conversation('json');
2983 $this->assertArrayHasKey('direct_message', $result);
2987 * Test the api_oauth_request_token() function.
2990 public function testApiOauthRequestToken()
2992 $this->markTestIncomplete('killme() kills phpunit as well');
2996 * Test the api_oauth_access_token() function.
2999 public function testApiOauthAccessToken()
3001 $this->markTestIncomplete('killme() kills phpunit as well');
3005 * Test the api_fr_photoalbum_delete() function.
3007 * @expectedException Friendica\Network\HTTPException\BadRequestException
3009 public function testApiFrPhotoalbumDelete()
3011 api_fr_photoalbum_delete('json');
3015 * Test the api_fr_photoalbum_delete() function with an album name.
3017 * @expectedException Friendica\Network\HTTPException\BadRequestException
3019 public function testApiFrPhotoalbumDeleteWithAlbum()
3021 $_REQUEST['album'] = 'album_name';
3022 api_fr_photoalbum_delete('json');
3026 * Test the api_fr_photoalbum_delete() function with an album name.
3029 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3031 $this->markTestIncomplete('We need to add a dataset for this.');
3035 * Test the api_fr_photoalbum_delete() function.
3037 * @expectedException Friendica\Network\HTTPException\BadRequestException
3039 public function testApiFrPhotoalbumUpdate()
3041 api_fr_photoalbum_update('json');
3045 * Test the api_fr_photoalbum_delete() function with an album name.
3047 * @expectedException Friendica\Network\HTTPException\BadRequestException
3049 public function testApiFrPhotoalbumUpdateWithAlbum()
3051 $_REQUEST['album'] = 'album_name';
3052 api_fr_photoalbum_update('json');
3056 * Test the api_fr_photoalbum_delete() function with an album name.
3058 * @expectedException Friendica\Network\HTTPException\BadRequestException
3060 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3062 $_REQUEST['album'] = 'album_name';
3063 $_REQUEST['album_new'] = 'album_name';
3064 api_fr_photoalbum_update('json');
3068 * Test the api_fr_photoalbum_update() function without an authenticated user.
3070 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3072 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3074 $_SESSION['authenticated'] = false;
3075 api_fr_photoalbum_update('json');
3079 * Test the api_fr_photoalbum_delete() function with an album name.
3082 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3084 $this->markTestIncomplete('We need to add a dataset for this.');
3088 * Test the api_fr_photos_list() function.
3091 public function testApiFrPhotosList()
3093 $result = api_fr_photos_list('json');
3094 $this->assertArrayHasKey('photo', $result);
3098 * Test the api_fr_photos_list() function without an authenticated user.
3100 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3102 public function testApiFrPhotosListWithoutAuthenticatedUser()
3104 $_SESSION['authenticated'] = false;
3105 api_fr_photos_list('json');
3109 * Test the api_fr_photo_create_update() function.
3111 * @expectedException Friendica\Network\HTTPException\BadRequestException
3113 public function testApiFrPhotoCreateUpdate()
3115 api_fr_photo_create_update('json');
3119 * Test the api_fr_photo_create_update() function without an authenticated user.
3121 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3123 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3125 $_SESSION['authenticated'] = false;
3126 api_fr_photo_create_update('json');
3130 * Test the api_fr_photo_create_update() function with an album name.
3132 * @expectedException Friendica\Network\HTTPException\BadRequestException
3134 public function testApiFrPhotoCreateUpdateWithAlbum()
3136 $_REQUEST['album'] = 'album_name';
3137 api_fr_photo_create_update('json');
3141 * Test the api_fr_photo_create_update() function with the update mode.
3144 public function testApiFrPhotoCreateUpdateWithUpdate()
3146 $this->markTestIncomplete('We need to create a dataset for this');
3150 * Test the api_fr_photo_create_update() function with an uploaded file.
3153 public function testApiFrPhotoCreateUpdateWithFile()
3155 $this->markTestIncomplete();
3159 * Test the api_fr_photo_delete() function.
3161 * @expectedException Friendica\Network\HTTPException\BadRequestException
3163 public function testApiFrPhotoDelete()
3165 api_fr_photo_delete('json');
3169 * Test the api_fr_photo_delete() function without an authenticated user.
3171 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3173 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3175 $_SESSION['authenticated'] = false;
3176 api_fr_photo_delete('json');
3180 * Test the api_fr_photo_delete() function with a photo ID.
3182 * @expectedException Friendica\Network\HTTPException\BadRequestException
3184 public function testApiFrPhotoDeleteWithPhotoId()
3186 $_REQUEST['photo_id'] = 1;
3187 api_fr_photo_delete('json');
3191 * Test the api_fr_photo_delete() function with a correct photo ID.
3194 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3196 $this->markTestIncomplete('We need to create a dataset for this.');
3200 * Test the api_fr_photo_detail() function.
3202 * @expectedException Friendica\Network\HTTPException\BadRequestException
3204 public function testApiFrPhotoDetail()
3206 api_fr_photo_detail('json');
3210 * Test the api_fr_photo_detail() function without an authenticated user.
3212 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3214 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3216 $_SESSION['authenticated'] = false;
3217 api_fr_photo_detail('json');
3221 * Test the api_fr_photo_detail() function with a photo ID.
3223 * @expectedException Friendica\Network\HTTPException\NotFoundException
3225 public function testApiFrPhotoDetailWithPhotoId()
3227 $_REQUEST['photo_id'] = 1;
3228 api_fr_photo_detail('json');
3232 * Test the api_fr_photo_detail() function with a correct photo ID.
3235 public function testApiFrPhotoDetailCorrectPhotoId()
3237 $this->markTestIncomplete('We need to create a dataset for this.');
3241 * Test the api_account_update_profile_image() function.
3243 * @expectedException Friendica\Network\HTTPException\BadRequestException
3245 public function testApiAccountUpdateProfileImage()
3247 api_account_update_profile_image('json');
3251 * Test the api_account_update_profile_image() function without an authenticated user.
3253 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3255 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3257 $_SESSION['authenticated'] = false;
3258 api_account_update_profile_image('json');
3262 * Test the api_account_update_profile_image() function with an uploaded file.
3264 * @expectedException Friendica\Network\HTTPException\BadRequestException
3266 public function testApiAccountUpdateProfileImageWithUpload()
3268 $this->markTestIncomplete();
3273 * Test the api_account_update_profile() function.
3276 public function testApiAccountUpdateProfile()
3278 $_POST['name'] = 'new_name';
3279 $_POST['description'] = 'new_description';
3280 $result = api_account_update_profile('json');
3281 // We can't use assertSelfUser() here because the user object is missing some properties.
3282 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3283 $this->assertEquals('Friendica', $result['user']['location']);
3284 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3285 $this->assertEquals('dfrn', $result['user']['network']);
3286 $this->assertEquals('new_name', $result['user']['name']);
3287 $this->assertEquals('new_description', $result['user']['description']);
3291 * Test the check_acl_input() function.
3294 public function testCheckAclInput()
3296 $result = check_acl_input('<aclstring>');
3297 // Where does this result come from?
3298 $this->assertEquals(1, $result);
3302 * Test the check_acl_input() function with an empty ACL string.
3305 public function testCheckAclInputWithEmptyAclString()
3307 $result = check_acl_input(' ');
3308 $this->assertFalse($result);
3312 * Test the save_media_to_database() function.
3315 public function testSaveMediaToDatabase()
3317 $this->markTestIncomplete();
3321 * Test the post_photo_item() function.
3324 public function testPostPhotoItem()
3326 $this->markTestIncomplete();
3330 * Test the prepare_photo_data() function.
3333 public function testPreparePhotoData()
3335 $this->markTestIncomplete();
3339 * Test the api_friendica_remoteauth() function.
3341 * @expectedException Friendica\Network\HTTPException\BadRequestException
3343 public function testApiFriendicaRemoteauth()
3345 api_friendica_remoteauth();
3349 * Test the api_friendica_remoteauth() function with an URL.
3351 * @expectedException Friendica\Network\HTTPException\BadRequestException
3353 public function testApiFriendicaRemoteauthWithUrl()
3355 $_GET['url'] = 'url';
3356 $_GET['c_url'] = 'url';
3357 api_friendica_remoteauth();
3361 * Test the api_friendica_remoteauth() function with a correct URL.
3364 public function testApiFriendicaRemoteauthWithCorrectUrl()
3366 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3367 $_GET['url'] = 'url';
3368 $_GET['c_url'] = $this->selfUser['nurl'];
3369 api_friendica_remoteauth();
3373 * Test the api_share_as_retweet() function.
3376 public function testApiShareAsRetweet()
3378 $item = ['body' => ''];
3379 $result = api_share_as_retweet($item);
3380 $this->assertFalse($result);
3384 * Test the api_share_as_retweet() function with a valid item.
3387 public function testApiShareAsRetweetWithValidItem()
3389 $this->markTestIncomplete();
3393 * Test the api_get_nick() function.
3396 public function testApiGetNick()
3398 $result = api_get_nick($this->otherUser['nurl']);
3399 $this->assertEquals('othercontact', $result);
3403 * Test the api_get_nick() function with a wrong URL.
3406 public function testApiGetNickWithWrongUrl()
3408 $result = api_get_nick('wrong_url');
3409 $this->assertFalse($result);
3413 * Test the api_in_reply_to() function.
3416 public function testApiInReplyTo()
3418 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3419 $this->assertArrayHasKey('status_id', $result);
3420 $this->assertArrayHasKey('user_id', $result);
3421 $this->assertArrayHasKey('status_id_str', $result);
3422 $this->assertArrayHasKey('user_id_str', $result);
3423 $this->assertArrayHasKey('screen_name', $result);
3427 * Test the api_in_reply_to() function with a valid item.
3430 public function testApiInReplyToWithValidItem()
3432 $this->markTestIncomplete();
3436 * Test the api_clean_plain_items() function.
3439 public function testApiCleanPlainItems()
3441 $_REQUEST['include_entities'] = 'true';
3442 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3443 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3447 * Test the api_clean_attachments() function.
3450 public function testApiCleanAttachments()
3452 $this->markTestIncomplete();
3456 * Test the api_best_nickname() function.
3459 public function testApiBestNickname()
3462 $result = api_best_nickname($contacts);
3463 $this->assertNull($result);
3467 * Test the api_best_nickname() function with contacts.
3470 public function testApiBestNicknameWithContacts()
3472 $this->markTestIncomplete();
3476 * Test the api_friendica_group_show() function.
3479 public function testApiFriendicaGroupShow()
3481 $this->markTestIncomplete();
3485 * Test the api_friendica_group_delete() function.
3488 public function testApiFriendicaGroupDelete()
3490 $this->markTestIncomplete();
3494 * Test the api_lists_destroy() function.
3497 public function testApiListsDestroy()
3499 $this->markTestIncomplete();
3503 * Test the group_create() function.
3506 public function testGroupCreate()
3508 $this->markTestIncomplete();
3512 * Test the api_friendica_group_create() function.
3515 public function testApiFriendicaGroupCreate()
3517 $this->markTestIncomplete();
3521 * Test the api_lists_create() function.
3524 public function testApiListsCreate()
3526 $this->markTestIncomplete();
3530 * Test the api_friendica_group_update() function.
3533 public function testApiFriendicaGroupUpdate()
3535 $this->markTestIncomplete();
3539 * Test the api_lists_update() function.
3542 public function testApiListsUpdate()
3544 $this->markTestIncomplete();
3548 * Test the api_friendica_activity() function.
3551 public function testApiFriendicaActivity()
3553 $this->markTestIncomplete();
3557 * Test the api_friendica_notification() function.
3559 * @expectedException Friendica\Network\HTTPException\BadRequestException
3561 public function testApiFriendicaNotification()
3563 api_friendica_notification('json');
3567 * Test the api_friendica_notification() function without an authenticated user.
3569 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3571 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3573 $_SESSION['authenticated'] = false;
3574 api_friendica_notification('json');
3578 * Test the api_friendica_notification() function with an argument count.
3581 public function testApiFriendicaNotificationWithArgumentCount()
3583 $this->app->argv = ['api', 'friendica', 'notification'];
3584 $this->app->argc = count($this->app->argv);
3585 $result = api_friendica_notification('json');
3586 $this->assertEquals(['note' => false], $result);
3590 * Test the api_friendica_notification() function with an XML result.
3593 public function testApiFriendicaNotificationWithXmlResult()
3595 $this->app->argv = ['api', 'friendica', 'notification'];
3596 $this->app->argc = count($this->app->argv);
3597 $result = api_friendica_notification('xml');
3598 $this->assertXml($result, 'notes');
3602 * Test the api_friendica_notification_seen() function.
3605 public function testApiFriendicaNotificationSeen()
3607 $this->markTestIncomplete();
3611 * Test the api_friendica_direct_messages_setseen() function.
3614 public function testApiFriendicaDirectMessagesSetseen()
3616 $this->markTestIncomplete();
3620 * Test the api_friendica_direct_messages_search() function.
3623 public function testApiFriendicaDirectMessagesSearch()
3625 $this->markTestIncomplete();
3629 * Test the api_friendica_profile_show() function.
3632 public function testApiFriendicaProfileShow()
3634 $result = api_friendica_profile_show('json');
3635 // We can't use assertSelfUser() here because the user object is missing some properties.
3636 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3637 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3638 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3639 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3640 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3641 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3642 $this->assertFalse($result['$result']['multi_profiles']);
3646 * Test the api_friendica_profile_show() function with a profile ID.
3649 public function testApiFriendicaProfileShowWithProfileId()
3651 $this->markTestIncomplete('We need to add a dataset for this.');
3655 * Test the api_friendica_profile_show() function with a wrong profile ID.
3657 * @expectedException Friendica\Network\HTTPException\BadRequestException
3659 public function testApiFriendicaProfileShowWithWrongProfileId()
3661 $_REQUEST['profile_id'] = 666;
3662 api_friendica_profile_show('json');
3666 * Test the api_friendica_profile_show() function without an authenticated user.
3668 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3670 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3672 $_SESSION['authenticated'] = false;
3673 api_friendica_profile_show('json');
3677 * Test the api_saved_searches_list() function.
3680 public function testApiSavedSearchesList()
3682 $result = api_saved_searches_list('json');
3683 $this->assertEquals(1, $result['terms'][0]['id']);
3684 $this->assertEquals(1, $result['terms'][0]['id_str']);
3685 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3686 $this->assertEquals('Saved search', $result['terms'][0]['query']);