6 namespace Friendica\Test;
10 use Friendica\BaseObject;
11 use Friendica\Core\Config;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\System;
15 use Friendica\Database\Database;
16 use Friendica\Network\HTTPException;
17 use Friendica\Test\Util\Database\StaticDatabase;
18 use Monolog\Handler\TestHandler;
20 require_once __DIR__ . '/../../include/api.php';
23 * Tests for the API functions.
25 * Functions that use header() need to be tested in a separate process.
26 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
28 class ApiTest extends DatabaseTest
31 * @var TestHandler Can handle log-outputs
38 protected $friendUser;
42 protected $wrongUserId;
48 * Create variables used by tests.
50 public function setUp()
52 StaticDatabase::statRollback();
55 $dice = $dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
56 $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
57 BaseObject::setDependencyInjection($dice);
58 $this->app = BaseObject::getApp();
63 $this->app->argv = ['home'];
65 // User data that the test database is populated with
68 'name' => 'Self contact',
69 'nick' => 'selfcontact',
70 'nurl' => 'http://localhost/profile/selfcontact'
74 'name' => 'Friend contact',
75 'nick' => 'friendcontact',
76 'nurl' => 'http://localhost/profile/friendcontact'
80 'name' => 'othercontact',
81 'nick' => 'othercontact',
82 'nurl' => 'http://localhost/profile/othercontact'
85 // User ID that we know is not in the database
86 $this->wrongUserId = 666;
88 // Most API require login so we force the session
91 'authenticated' => true,
92 'uid' => $this->selfUser['id']
95 Config::set('system', 'url', 'http://localhost');
96 Config::set('system', 'hostname', 'localhost');
97 Config::set('system', 'worker_dont_fork', true);
100 Config::set('config', 'hostname', 'localhost');
101 Config::set('system', 'throttle_limit_day', 100);
102 Config::set('system', 'throttle_limit_week', 100);
103 Config::set('system', 'throttle_limit_month', 100);
104 Config::set('system', 'theme', 'system_theme');
107 protected function tearDown()
109 StaticDatabase::statRollback();
113 * Assert that an user array contains expected keys.
114 * @param array $user User array
117 private function assertSelfUser(array $user)
119 $this->assertEquals($this->selfUser['id'], $user['uid']);
120 $this->assertEquals($this->selfUser['id'], $user['cid']);
121 $this->assertEquals(1, $user['self']);
122 $this->assertEquals('DFRN', $user['location']);
123 $this->assertEquals($this->selfUser['name'], $user['name']);
124 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
125 $this->assertEquals('dfrn', $user['network']);
126 $this->assertTrue($user['verified']);
130 * Assert that an user array contains expected keys.
131 * @param array $user User array
134 private function assertOtherUser(array $user)
136 $this->assertEquals($this->otherUser['id'], $user['id']);
137 $this->assertEquals($this->otherUser['id'], $user['id_str']);
138 $this->assertEquals(0, $user['self']);
139 $this->assertEquals($this->otherUser['name'], $user['name']);
140 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
141 $this->assertFalse($user['verified']);
145 * Assert that a status array contains expected keys.
146 * @param array $status Status array
149 private function assertStatus(array $status)
151 $this->assertInternalType('string', $status['text']);
152 $this->assertInternalType('int', $status['id']);
153 // We could probably do more checks here.
157 * Assert that a list array contains expected keys.
158 * @param array $list List array
161 private function assertList(array $list)
163 $this->assertInternalType('string', $list['name']);
164 $this->assertInternalType('int', $list['id']);
165 $this->assertInternalType('string', $list['id_str']);
166 $this->assertContains($list['mode'], ['public', 'private']);
167 // We could probably do more checks here.
171 * Assert that the string is XML and contain the root element.
172 * @param string $result XML string
173 * @param string $root_element Root element name
176 private function assertXml($result, $root_element)
178 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
179 $this->assertContains('<'.$root_element, $result);
180 // We could probably do more checks here.
184 * Get the path to a temporary empty PNG image.
185 * @return string Path
187 private function getTempImage()
189 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
193 // Empty 1x1 px PNG image
194 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
202 * Test the api_user() function.
205 public function testApiUser()
207 $this->assertEquals($this->selfUser['id'], api_user());
211 * Test the api_user() function with an unallowed user.
214 public function testApiUserWithUnallowedUser()
216 $_SESSION = ['allow_api' => false];
217 $this->assertEquals(false, api_user());
221 * Test the api_source() function.
224 public function testApiSource()
226 $this->assertEquals('api', api_source());
230 * Test the api_source() function with a Twidere user agent.
233 public function testApiSourceWithTwidere()
235 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
236 $this->assertEquals('Twidere', api_source());
240 * Test the api_source() function with a GET parameter.
243 public function testApiSourceWithGet()
245 $_GET['source'] = 'source_name';
246 $this->assertEquals('source_name', api_source());
250 * Test the api_date() function.
253 public function testApiDate()
255 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
259 * Test the api_register_func() function.
262 public function testApiRegisterFunc()
274 $this->assertTrue($API['api_path']['auth']);
275 $this->assertEquals('method', $API['api_path']['method']);
276 $this->assertTrue(is_callable($API['api_path']['func']));
280 * Test the api_login() function without any login.
282 * @runInSeparateProcess
283 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
285 public function testApiLoginWithoutLogin()
287 api_login($this->app);
291 * Test the api_login() function with a bad login.
293 * @runInSeparateProcess
294 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
296 public function testApiLoginWithBadLogin()
298 $_SERVER['PHP_AUTH_USER'] = 'user@server';
299 api_login($this->app);
303 * Test the api_login() function with oAuth.
306 public function testApiLoginWithOauth()
308 $this->markTestIncomplete('Can we test this easily?');
312 * Test the api_login() function with authentication provided by an addon.
315 public function testApiLoginWithAddonAuth()
317 $this->markTestIncomplete('Can we test this easily?');
321 * Test the api_login() function with a correct login.
323 * @runInSeparateProcess
325 public function testApiLoginWithCorrectLogin()
327 $_SERVER['PHP_AUTH_USER'] = 'Test user';
328 $_SERVER['PHP_AUTH_PW'] = 'password';
329 api_login($this->app);
333 * Test the api_login() function with a remote user.
335 * @runInSeparateProcess
336 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
338 public function testApiLoginWithRemoteUser()
340 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
341 api_login($this->app);
345 * Test the api_check_method() function.
348 public function testApiCheckMethod()
350 $this->assertFalse(api_check_method('method'));
354 * Test the api_check_method() function with a correct method.
357 public function testApiCheckMethodWithCorrectMethod()
359 $_SERVER['REQUEST_METHOD'] = 'method';
360 $this->assertTrue(api_check_method('method'));
364 * Test the api_check_method() function with a wildcard.
367 public function testApiCheckMethodWithWildcard()
369 $this->assertTrue(api_check_method('*'));
373 * Test the api_call() function.
375 * @runInSeparateProcess
377 public function testApiCall()
381 'method' => 'method',
382 'func' => function () {
383 return ['data' => ['some_data']];
386 $_SERVER['REQUEST_METHOD'] = 'method';
387 $_GET['callback'] = 'callback_name';
389 $this->app->query_string = 'api_path';
391 'callback_name(["some_data"])',
397 * Test the api_call() function with the profiled enabled.
399 * @runInSeparateProcess
401 public function testApiCallWithProfiler()
405 'method' => 'method',
406 'func' => function () {
407 return ['data' => ['some_data']];
410 $_SERVER['REQUEST_METHOD'] = 'method';
411 Config::set('system', 'profiler', true);
412 Config::set('rendertime', 'callstack', true);
413 $this->app->callstack = [
414 'database' => ['some_function' => 200],
415 'database_write' => ['some_function' => 200],
416 'cache' => ['some_function' => 200],
417 'cache_write' => ['some_function' => 200],
418 'network' => ['some_function' => 200]
421 $this->app->query_string = 'api_path';
429 * Test the api_call() function without any result.
431 * @runInSeparateProcess
433 public function testApiCallWithNoResult()
437 'method' => 'method',
438 'func' => function () {
442 $_SERVER['REQUEST_METHOD'] = 'method';
444 $this->app->query_string = 'api_path';
446 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
452 * Test the api_call() function with an unimplemented API.
454 * @runInSeparateProcess
456 public function testApiCallWithUninplementedApi()
459 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
465 * Test the api_call() function with a JSON result.
467 * @runInSeparateProcess
469 public function testApiCallWithJson()
473 'method' => 'method',
474 'func' => function () {
475 return ['data' => ['some_data']];
478 $_SERVER['REQUEST_METHOD'] = 'method';
480 $this->app->query_string = 'api_path.json';
488 * Test the api_call() function with an XML result.
490 * @runInSeparateProcess
492 public function testApiCallWithXml()
496 'method' => 'method',
497 'func' => function () {
501 $_SERVER['REQUEST_METHOD'] = 'method';
503 $this->app->query_string = 'api_path.xml';
511 * Test the api_call() function with an RSS result.
513 * @runInSeparateProcess
515 public function testApiCallWithRss()
519 'method' => 'method',
520 'func' => function () {
524 $_SERVER['REQUEST_METHOD'] = 'method';
526 $this->app->query_string = 'api_path.rss';
528 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
535 * Test the api_call() function with an Atom result.
537 * @runInSeparateProcess
539 public function testApiCallWithAtom()
543 'method' => 'method',
544 'func' => function () {
548 $_SERVER['REQUEST_METHOD'] = 'method';
550 $this->app->query_string = 'api_path.atom';
552 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
559 * Test the api_call() function with an unallowed method.
561 * @runInSeparateProcess
563 public function testApiCallWithWrongMethod()
566 $API['api_path'] = ['method' => 'method'];
568 $this->app->query_string = 'api_path';
570 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
576 * Test the api_call() function with an unauthorized user.
578 * @runInSeparateProcess
580 public function testApiCallWithWrongAuth()
584 'method' => 'method',
587 $_SERVER['REQUEST_METHOD'] = 'method';
588 $_SESSION['authenticated'] = false;
590 $this->app->query_string = 'api_path';
592 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
598 * Test the api_error() function with a JSON result.
600 * @runInSeparateProcess
602 public function testApiErrorWithJson()
605 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
606 api_error('json', new HTTPException\OKException('error_message'))
611 * Test the api_error() function with an XML result.
613 * @runInSeparateProcess
615 public function testApiErrorWithXml()
618 '<?xml version="1.0"?>'."\n".
619 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
620 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
621 'xmlns:georss="http://www.georss.org/georss">'."\n".
622 ' <error>error_message</error>'."\n".
623 ' <code>200 OK</code>'."\n".
626 api_error('xml', new HTTPException\OKException('error_message'))
631 * Test the api_error() function with an RSS result.
633 * @runInSeparateProcess
635 public function testApiErrorWithRss()
638 '<?xml version="1.0"?>'."\n".
639 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
640 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
641 'xmlns:georss="http://www.georss.org/georss">'."\n".
642 ' <error>error_message</error>'."\n".
643 ' <code>200 OK</code>'."\n".
646 api_error('rss', new HTTPException\OKException('error_message'))
651 * Test the api_error() function with an Atom result.
653 * @runInSeparateProcess
655 public function testApiErrorWithAtom()
658 '<?xml version="1.0"?>'."\n".
659 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
660 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
661 'xmlns:georss="http://www.georss.org/georss">'."\n".
662 ' <error>error_message</error>'."\n".
663 ' <code>200 OK</code>'."\n".
666 api_error('atom', new HTTPException\OKException('error_message'))
671 * Test the api_rss_extra() function.
674 public function testApiRssExtra()
676 $user_info = ['url' => 'user_url', 'lang' => 'en'];
677 $result = api_rss_extra($this->app, [], $user_info);
678 $this->assertEquals($user_info, $result['$user']);
679 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
680 $this->assertArrayHasKey('self', $result['$rss']);
681 $this->assertArrayHasKey('base', $result['$rss']);
682 $this->assertArrayHasKey('updated', $result['$rss']);
683 $this->assertArrayHasKey('atom_updated', $result['$rss']);
684 $this->assertArrayHasKey('language', $result['$rss']);
685 $this->assertArrayHasKey('logo', $result['$rss']);
689 * Test the api_rss_extra() function without any user info.
691 * @runInSeparateProcess
693 public function testApiRssExtraWithoutUserInfo()
695 $result = api_rss_extra($this->app, [], null);
696 $this->assertInternalType('array', $result['$user']);
697 $this->assertArrayHasKey('alternate', $result['$rss']);
698 $this->assertArrayHasKey('self', $result['$rss']);
699 $this->assertArrayHasKey('base', $result['$rss']);
700 $this->assertArrayHasKey('updated', $result['$rss']);
701 $this->assertArrayHasKey('atom_updated', $result['$rss']);
702 $this->assertArrayHasKey('language', $result['$rss']);
703 $this->assertArrayHasKey('logo', $result['$rss']);
707 * Test the api_unique_id_to_nurl() function.
710 public function testApiUniqueIdToNurl()
712 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
716 * Test the api_unique_id_to_nurl() function with a correct ID.
719 public function testApiUniqueIdToNurlWithCorrectId()
721 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
725 * Test the api_get_user() function.
727 * @runInSeparateProcess
729 public function testApiGetUser()
731 $user = api_get_user($this->app);
732 $this->assertSelfUser($user);
733 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
734 $this->assertEquals('6fdbe8', $user['profile_link_color']);
735 $this->assertEquals('ededed', $user['profile_background_color']);
739 * Test the api_get_user() function with a Frio schema.
741 * @runInSeparateProcess
743 public function testApiGetUserWithFrioSchema()
745 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
746 $user = api_get_user($this->app);
747 $this->assertSelfUser($user);
748 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
749 $this->assertEquals('6fdbe8', $user['profile_link_color']);
750 $this->assertEquals('ededed', $user['profile_background_color']);
754 * Test the api_get_user() function with a custom Frio schema.
756 * @runInSeparateProcess
758 public function testApiGetUserWithCustomFrioSchema()
760 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
761 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
762 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
763 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
764 $user = api_get_user($this->app);
765 $this->assertSelfUser($user);
766 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
767 $this->assertEquals('123456', $user['profile_link_color']);
768 $this->assertEquals('123456', $user['profile_background_color']);
772 * Test the api_get_user() function with an empty Frio schema.
774 * @runInSeparateProcess
776 public function testApiGetUserWithEmptyFrioSchema()
778 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
779 $user = api_get_user($this->app);
780 $this->assertSelfUser($user);
781 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
782 $this->assertEquals('6fdbe8', $user['profile_link_color']);
783 $this->assertEquals('ededed', $user['profile_background_color']);
787 * Test the api_get_user() function with an user that is not allowed to use the API.
789 * @runInSeparateProcess
791 public function testApiGetUserWithoutApiUser()
793 $_SERVER['PHP_AUTH_USER'] = 'Test user';
794 $_SERVER['PHP_AUTH_PW'] = 'password';
795 $_SESSION['allow_api'] = false;
796 $this->assertFalse(api_get_user($this->app));
800 * Test the api_get_user() function with an user ID in a GET parameter.
802 * @runInSeparateProcess
804 public function testApiGetUserWithGetId()
806 $_GET['user_id'] = $this->otherUser['id'];
807 $this->assertOtherUser(api_get_user($this->app));
811 * Test the api_get_user() function with a wrong user ID in a GET parameter.
813 * @runInSeparateProcess
814 * @expectedException Friendica\Network\HTTPException\BadRequestException
816 public function testApiGetUserWithWrongGetId()
818 $_GET['user_id'] = $this->wrongUserId;
819 $this->assertOtherUser(api_get_user($this->app));
823 * Test the api_get_user() function with an user name in a GET parameter.
825 * @runInSeparateProcess
827 public function testApiGetUserWithGetName()
829 $_GET['screen_name'] = $this->selfUser['nick'];
830 $this->assertSelfUser(api_get_user($this->app));
834 * Test the api_get_user() function with a profile URL in a GET parameter.
836 * @runInSeparateProcess
838 public function testApiGetUserWithGetUrl()
840 $_GET['profileurl'] = $this->selfUser['nurl'];
841 $this->assertSelfUser(api_get_user($this->app));
845 * Test the api_get_user() function with an user ID in the API path.
847 * @runInSeparateProcess
849 public function testApiGetUserWithNumericCalledApi()
852 $called_api = ['api_path'];
853 $this->app->argv[1] = $this->otherUser['id'].'.json';
854 $this->assertOtherUser(api_get_user($this->app));
858 * Test the api_get_user() function with the $called_api global variable.
860 * @runInSeparateProcess
862 public function testApiGetUserWithCalledApi()
865 $called_api = ['api', 'api_path'];
866 $this->assertSelfUser(api_get_user($this->app));
870 * Test the api_get_user() function with a valid user.
872 * @runInSeparateProcess
874 public function testApiGetUserWithCorrectUser()
876 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
880 * Test the api_get_user() function with a wrong user ID.
882 * @runInSeparateProcess
883 * @expectedException Friendica\Network\HTTPException\BadRequestException
885 public function testApiGetUserWithWrongUser()
887 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
891 * Test the api_get_user() function with a 0 user ID.
893 * @runInSeparateProcess
895 public function testApiGetUserWithZeroUser()
897 $this->assertSelfUser(api_get_user($this->app, 0));
901 * Test the api_item_get_user() function.
903 * @runInSeparateProcess
905 public function testApiItemGetUser()
907 $users = api_item_get_user($this->app, []);
908 $this->assertSelfUser($users[0]);
912 * Test the api_item_get_user() function with a different item parent.
915 public function testApiItemGetUserWithDifferentParent()
917 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
918 $this->assertSelfUser($users[0]);
919 $this->assertEquals($users[0], $users[1]);
923 * Test the api_walk_recursive() function.
926 public function testApiWalkRecursive()
934 // Should we test this with a callback that actually does something?
942 * Test the api_walk_recursive() function with an array.
945 public function testApiWalkRecursiveWithArray()
947 $array = [['item1'], ['item2']];
953 // Should we test this with a callback that actually does something?
961 * Test the api_reformat_xml() function.
964 public function testApiReformatXml()
968 $this->assertTrue(api_reformat_xml($item, $key));
969 $this->assertEquals('true', $item);
973 * Test the api_reformat_xml() function with a statusnet_api key.
976 public function testApiReformatXmlWithStatusnetKey()
979 $key = 'statusnet_api';
980 $this->assertTrue(api_reformat_xml($item, $key));
981 $this->assertEquals('statusnet:api', $key);
985 * Test the api_reformat_xml() function with a friendica_api key.
988 public function testApiReformatXmlWithFriendicaKey()
991 $key = 'friendica_api';
992 $this->assertTrue(api_reformat_xml($item, $key));
993 $this->assertEquals('friendica:api', $key);
997 * Test the api_create_xml() function.
1000 public function testApiCreateXml()
1002 $this->assertEquals(
1003 '<?xml version="1.0"?>'."\n".
1004 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1005 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1006 'xmlns:georss="http://www.georss.org/georss">'."\n".
1007 ' <data>some_data</data>'."\n".
1008 '</root_element>'."\n",
1009 api_create_xml(['data' => ['some_data']], 'root_element')
1014 * Test the api_create_xml() function without any XML namespace.
1017 public function testApiCreateXmlWithoutNamespaces()
1019 $this->assertEquals(
1020 '<?xml version="1.0"?>'."\n".
1022 ' <data>some_data</data>'."\n".
1024 api_create_xml(['data' => ['some_data']], 'ok')
1029 * Test the api_format_data() function.
1032 public function testApiFormatData()
1034 $data = ['some_data'];
1035 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1039 * Test the api_format_data() function with an XML result.
1042 public function testApiFormatDataWithXml()
1044 $this->assertEquals(
1045 '<?xml version="1.0"?>'."\n".
1046 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1047 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1048 'xmlns:georss="http://www.georss.org/georss">'."\n".
1049 ' <data>some_data</data>'."\n".
1050 '</root_element>'."\n",
1051 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1056 * Test the api_account_verify_credentials() function.
1059 public function testApiAccountVerifyCredentials()
1061 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1065 * Test the api_account_verify_credentials() function without an authenticated user.
1067 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1069 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1071 $_SESSION['authenticated'] = false;
1072 api_account_verify_credentials('json');
1076 * Test the requestdata() function.
1079 public function testRequestdata()
1081 $this->assertNull(requestdata('variable_name'));
1085 * Test the requestdata() function with a POST parameter.
1088 public function testRequestdataWithPost()
1090 $_POST['variable_name'] = 'variable_value';
1091 $this->assertEquals('variable_value', requestdata('variable_name'));
1095 * Test the requestdata() function with a GET parameter.
1098 public function testRequestdataWithGet()
1100 $_GET['variable_name'] = 'variable_value';
1101 $this->assertEquals('variable_value', requestdata('variable_name'));
1105 * Test the api_statuses_mediap() function.
1108 public function testApiStatusesMediap()
1110 $this->app->argc = 2;
1118 'tmp_name' => $this->getTempImage(),
1119 'name' => 'spacer.png',
1120 'type' => 'image/png'
1123 $_GET['status'] = '<b>Status content</b>';
1125 $result = api_statuses_mediap('json');
1126 $this->assertStatus($result['status']);
1130 * Test the api_statuses_mediap() function without an authenticated user.
1132 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1134 public function testApiStatusesMediapWithoutAuthenticatedUser()
1136 $_SESSION['authenticated'] = false;
1137 api_statuses_mediap('json');
1141 * Test the api_statuses_update() function.
1144 public function testApiStatusesUpdate()
1146 $_GET['status'] = 'Status content #friendica';
1147 $_GET['in_reply_to_status_id'] = -1;
1156 'tmp_name' => $this->getTempImage(),
1157 'name' => 'spacer.png',
1158 'type' => 'image/png'
1162 $result = api_statuses_update('json');
1163 $this->assertStatus($result['status']);
1167 * Test the api_statuses_update() function with an HTML status.
1170 public function testApiStatusesUpdateWithHtml()
1172 $_GET['htmlstatus'] = '<b>Status content</b>';
1174 $result = api_statuses_update('json');
1175 $this->assertStatus($result['status']);
1179 * Test the api_statuses_update() function without an authenticated user.
1181 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1183 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1185 $_SESSION['authenticated'] = false;
1186 api_statuses_update('json');
1190 * Test the api_statuses_update() function with a parent status.
1193 public function testApiStatusesUpdateWithParent()
1195 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1199 * Test the api_statuses_update() function with a media_ids parameter.
1202 public function testApiStatusesUpdateWithMediaIds()
1204 $this->markTestIncomplete();
1208 * Test the api_statuses_update() function with the throttle limit reached.
1211 public function testApiStatusesUpdateWithDayThrottleReached()
1213 $this->markTestIncomplete();
1217 * Test the api_media_upload() function.
1219 * @expectedException Friendica\Network\HTTPException\BadRequestException
1221 public function testApiMediaUpload()
1227 * Test the api_media_upload() function without an authenticated user.
1229 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1231 public function testApiMediaUploadWithoutAuthenticatedUser()
1233 $_SESSION['authenticated'] = false;
1238 * Test the api_media_upload() function with an invalid uploaded media.
1240 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1242 public function testApiMediaUploadWithMedia()
1247 'tmp_name' => 'tmp_name'
1254 * Test the api_media_upload() function with an valid uploaded media.
1257 public function testApiMediaUploadWithValidMedia()
1265 'tmp_name' => $this->getTempImage(),
1266 'name' => 'spacer.png',
1267 'type' => 'image/png'
1273 $result = api_media_upload();
1274 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1275 $this->assertEquals(1, $result['media']['image']['w']);
1276 $this->assertEquals(1, $result['media']['image']['h']);
1277 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1281 * Test the api_status_show() function.
1283 public function testApiStatusShowWithJson()
1285 $result = api_status_show('json', 1);
1286 $this->assertStatus($result['status']);
1290 * Test the api_status_show() function with an XML result.
1292 public function testApiStatusShowWithXml()
1294 $result = api_status_show('xml', 1);
1295 $this->assertXml($result, 'statuses');
1299 * Test the api_get_last_status() function
1301 public function testApiGetLastStatus()
1303 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1305 $this->assertNotNull($item);
1309 * Test the api_users_show() function.
1312 public function testApiUsersShow()
1314 $result = api_users_show('json');
1315 // We can't use assertSelfUser() here because the user object is missing some properties.
1316 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1317 $this->assertEquals('DFRN', $result['user']['location']);
1318 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1319 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1320 $this->assertEquals('dfrn', $result['user']['network']);
1321 $this->assertTrue($result['user']['verified']);
1325 * Test the api_users_show() function with an XML result.
1328 public function testApiUsersShowWithXml()
1330 $result = api_users_show('xml');
1331 $this->assertXml($result, 'statuses');
1335 * Test the api_users_search() function.
1338 public function testApiUsersSearch()
1340 $_GET['q'] = 'othercontact';
1341 $result = api_users_search('json');
1342 $this->assertOtherUser($result['users'][0]);
1346 * Test the api_users_search() function with an XML result.
1349 public function testApiUsersSearchWithXml()
1351 $_GET['q'] = 'othercontact';
1352 $result = api_users_search('xml');
1353 $this->assertXml($result, 'users');
1357 * Test the api_users_search() function without a GET q parameter.
1359 * @expectedException Friendica\Network\HTTPException\BadRequestException
1361 public function testApiUsersSearchWithoutQuery()
1363 api_users_search('json');
1367 * Test the api_users_lookup() function.
1369 * @expectedException Friendica\Network\HTTPException\NotFoundException
1371 public function testApiUsersLookup()
1373 api_users_lookup('json');
1377 * Test the api_users_lookup() function with an user ID.
1380 public function testApiUsersLookupWithUserId()
1382 $_REQUEST['user_id'] = $this->otherUser['id'];
1383 $result = api_users_lookup('json');
1384 $this->assertOtherUser($result['users'][0]);
1388 * Test the api_search() function.
1391 public function testApiSearch()
1393 $_REQUEST['q'] = 'reply';
1394 $_REQUEST['max_id'] = 10;
1395 $result = api_search('json');
1396 foreach ($result['status'] as $status) {
1397 $this->assertStatus($status);
1398 $this->assertContains('reply', $status['text'], null, true);
1403 * Test the api_search() function a count parameter.
1406 public function testApiSearchWithCount()
1408 $_REQUEST['q'] = 'reply';
1409 $_REQUEST['count'] = 20;
1410 $result = api_search('json');
1411 foreach ($result['status'] as $status) {
1412 $this->assertStatus($status);
1413 $this->assertContains('reply', $status['text'], null, true);
1418 * Test the api_search() function with an rpp parameter.
1421 public function testApiSearchWithRpp()
1423 $_REQUEST['q'] = 'reply';
1424 $_REQUEST['rpp'] = 20;
1425 $result = api_search('json');
1426 foreach ($result['status'] as $status) {
1427 $this->assertStatus($status);
1428 $this->assertContains('reply', $status['text'], null, true);
1433 * Test the api_search() function with an q parameter contains hashtag.
1436 public function testApiSearchWithHashtag()
1438 $_REQUEST['q'] = '%23friendica';
1439 $result = api_search('json');
1440 foreach ($result['status'] as $status) {
1441 $this->assertStatus($status);
1442 $this->assertContains('#friendica', $status['text'], null, true);
1447 * Test the api_search() function with an exclude_replies parameter.
1450 public function testApiSearchWithExcludeReplies()
1452 $_REQUEST['max_id'] = 10;
1453 $_REQUEST['exclude_replies'] = true;
1454 $_REQUEST['q'] = 'friendica';
1455 $result = api_search('json');
1456 foreach ($result['status'] as $status) {
1457 $this->assertStatus($status);
1462 * Test the api_search() function without an authenticated user.
1464 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1466 public function testApiSearchWithUnallowedUser()
1468 $_SESSION['allow_api'] = false;
1469 $_GET['screen_name'] = $this->selfUser['nick'];
1474 * Test the api_search() function without any GET query parameter.
1476 * @expectedException Friendica\Network\HTTPException\BadRequestException
1478 public function testApiSearchWithoutQuery()
1484 * Test the api_statuses_home_timeline() function.
1487 public function testApiStatusesHomeTimeline()
1489 $_REQUEST['max_id'] = 10;
1490 $_REQUEST['exclude_replies'] = true;
1491 $_REQUEST['conversation_id'] = 1;
1492 $result = api_statuses_home_timeline('json');
1493 $this->assertNotEmpty($result['status']);
1494 foreach ($result['status'] as $status) {
1495 $this->assertStatus($status);
1500 * Test the api_statuses_home_timeline() function with a negative page parameter.
1503 public function testApiStatusesHomeTimelineWithNegativePage()
1505 $_REQUEST['page'] = -2;
1506 $result = api_statuses_home_timeline('json');
1507 $this->assertNotEmpty($result['status']);
1508 foreach ($result['status'] as $status) {
1509 $this->assertStatus($status);
1514 * Test the api_statuses_home_timeline() with an unallowed user.
1516 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1518 public function testApiStatusesHomeTimelineWithUnallowedUser()
1520 $_SESSION['allow_api'] = false;
1521 $_GET['screen_name'] = $this->selfUser['nick'];
1522 api_statuses_home_timeline('json');
1526 * Test the api_statuses_home_timeline() function with an RSS result.
1529 public function testApiStatusesHomeTimelineWithRss()
1531 $result = api_statuses_home_timeline('rss');
1532 $this->assertXml($result, 'statuses');
1536 * Test the api_statuses_public_timeline() function.
1539 public function testApiStatusesPublicTimeline()
1541 $_REQUEST['max_id'] = 10;
1542 $_REQUEST['conversation_id'] = 1;
1543 $result = api_statuses_public_timeline('json');
1544 $this->assertNotEmpty($result['status']);
1545 foreach ($result['status'] as $status) {
1546 $this->assertStatus($status);
1551 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1554 public function testApiStatusesPublicTimelineWithExcludeReplies()
1556 $_REQUEST['max_id'] = 10;
1557 $_REQUEST['exclude_replies'] = true;
1558 $result = api_statuses_public_timeline('json');
1559 $this->assertNotEmpty($result['status']);
1560 foreach ($result['status'] as $status) {
1561 $this->assertStatus($status);
1566 * Test the api_statuses_public_timeline() function with a negative page parameter.
1569 public function testApiStatusesPublicTimelineWithNegativePage()
1571 $_REQUEST['page'] = -2;
1572 $result = api_statuses_public_timeline('json');
1573 $this->assertNotEmpty($result['status']);
1574 foreach ($result['status'] as $status) {
1575 $this->assertStatus($status);
1580 * Test the api_statuses_public_timeline() function with an unallowed user.
1582 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1584 public function testApiStatusesPublicTimelineWithUnallowedUser()
1586 $_SESSION['allow_api'] = false;
1587 $_GET['screen_name'] = $this->selfUser['nick'];
1588 api_statuses_public_timeline('json');
1592 * Test the api_statuses_public_timeline() function with an RSS result.
1595 public function testApiStatusesPublicTimelineWithRss()
1597 $result = api_statuses_public_timeline('rss');
1598 $this->assertXml($result, 'statuses');
1602 * Test the api_statuses_networkpublic_timeline() function.
1605 public function testApiStatusesNetworkpublicTimeline()
1607 $_REQUEST['max_id'] = 10;
1608 $result = api_statuses_networkpublic_timeline('json');
1609 $this->assertNotEmpty($result['status']);
1610 foreach ($result['status'] as $status) {
1611 $this->assertStatus($status);
1616 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1619 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1621 $_REQUEST['page'] = -2;
1622 $result = api_statuses_networkpublic_timeline('json');
1623 $this->assertNotEmpty($result['status']);
1624 foreach ($result['status'] as $status) {
1625 $this->assertStatus($status);
1630 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1632 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1634 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1636 $_SESSION['allow_api'] = false;
1637 $_GET['screen_name'] = $this->selfUser['nick'];
1638 api_statuses_networkpublic_timeline('json');
1642 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1645 public function testApiStatusesNetworkpublicTimelineWithRss()
1647 $result = api_statuses_networkpublic_timeline('rss');
1648 $this->assertXml($result, 'statuses');
1652 * Test the api_statuses_show() function.
1654 * @expectedException Friendica\Network\HTTPException\BadRequestException
1656 public function testApiStatusesShow()
1658 api_statuses_show('json');
1662 * Test the api_statuses_show() function with an ID.
1665 public function testApiStatusesShowWithId()
1667 $this->app->argv[3] = 1;
1668 $result = api_statuses_show('json');
1669 $this->assertStatus($result['status']);
1673 * Test the api_statuses_show() function with the conversation parameter.
1676 public function testApiStatusesShowWithConversation()
1678 $this->app->argv[3] = 1;
1679 $_REQUEST['conversation'] = 1;
1680 $result = api_statuses_show('json');
1681 $this->assertNotEmpty($result['status']);
1682 foreach ($result['status'] as $status) {
1683 $this->assertStatus($status);
1688 * Test the api_statuses_show() function with an unallowed user.
1690 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1692 public function testApiStatusesShowWithUnallowedUser()
1694 $_SESSION['allow_api'] = false;
1695 $_GET['screen_name'] = $this->selfUser['nick'];
1696 api_statuses_show('json');
1700 * Test the api_conversation_show() function.
1702 * @expectedException Friendica\Network\HTTPException\BadRequestException
1704 public function testApiConversationShow()
1706 api_conversation_show('json');
1710 * Test the api_conversation_show() function with an ID.
1713 public function testApiConversationShowWithId()
1715 $this->app->argv[3] = 1;
1716 $_REQUEST['max_id'] = 10;
1717 $_REQUEST['page'] = -2;
1718 $result = api_conversation_show('json');
1719 $this->assertNotEmpty($result['status']);
1720 foreach ($result['status'] as $status) {
1721 $this->assertStatus($status);
1726 * Test the api_conversation_show() function with an unallowed user.
1728 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1730 public function testApiConversationShowWithUnallowedUser()
1732 $_SESSION['allow_api'] = false;
1733 $_GET['screen_name'] = $this->selfUser['nick'];
1734 api_conversation_show('json');
1738 * Test the api_statuses_repeat() function.
1740 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1742 public function testApiStatusesRepeat()
1744 api_statuses_repeat('json');
1748 * Test the api_statuses_repeat() function without an authenticated user.
1750 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1752 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1754 $_SESSION['authenticated'] = false;
1755 api_statuses_repeat('json');
1759 * Test the api_statuses_repeat() function with an ID.
1762 public function testApiStatusesRepeatWithId()
1764 $this->app->argv[3] = 1;
1765 $result = api_statuses_repeat('json');
1766 $this->assertStatus($result['status']);
1768 // Also test with a shared status
1769 $this->app->argv[3] = 5;
1770 $result = api_statuses_repeat('json');
1771 $this->assertStatus($result['status']);
1775 * Test the api_statuses_destroy() function.
1777 * @expectedException Friendica\Network\HTTPException\BadRequestException
1779 public function testApiStatusesDestroy()
1781 api_statuses_destroy('json');
1785 * Test the api_statuses_destroy() function without an authenticated user.
1787 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1789 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1791 $_SESSION['authenticated'] = false;
1792 api_statuses_destroy('json');
1796 * Test the api_statuses_destroy() function with an ID.
1799 public function testApiStatusesDestroyWithId()
1801 $this->app->argv[3] = 1;
1802 $result = api_statuses_destroy('json');
1803 $this->assertStatus($result['status']);
1807 * Test the api_statuses_mentions() function.
1810 public function testApiStatusesMentions()
1812 $this->app->user = ['nickname' => $this->selfUser['nick']];
1813 $_REQUEST['max_id'] = 10;
1814 $result = api_statuses_mentions('json');
1815 $this->assertEmpty($result['status']);
1816 // We should test with mentions in the database.
1820 * Test the api_statuses_mentions() function with a negative page parameter.
1823 public function testApiStatusesMentionsWithNegativePage()
1825 $_REQUEST['page'] = -2;
1826 $result = api_statuses_mentions('json');
1827 $this->assertEmpty($result['status']);
1831 * Test the api_statuses_mentions() function with an unallowed user.
1833 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1835 public function testApiStatusesMentionsWithUnallowedUser()
1837 $_SESSION['allow_api'] = false;
1838 $_GET['screen_name'] = $this->selfUser['nick'];
1839 api_statuses_mentions('json');
1843 * Test the api_statuses_mentions() function with an RSS result.
1846 public function testApiStatusesMentionsWithRss()
1848 $result = api_statuses_mentions('rss');
1849 $this->assertXml($result, 'statuses');
1853 * Test the api_statuses_user_timeline() function.
1856 public function testApiStatusesUserTimeline()
1858 $_REQUEST['max_id'] = 10;
1859 $_REQUEST['exclude_replies'] = true;
1860 $_REQUEST['conversation_id'] = 1;
1861 $result = api_statuses_user_timeline('json');
1862 $this->assertNotEmpty($result['status']);
1863 foreach ($result['status'] as $status) {
1864 $this->assertStatus($status);
1869 * Test the api_statuses_user_timeline() function with a negative page parameter.
1872 public function testApiStatusesUserTimelineWithNegativePage()
1874 $_REQUEST['page'] = -2;
1875 $result = api_statuses_user_timeline('json');
1876 $this->assertNotEmpty($result['status']);
1877 foreach ($result['status'] as $status) {
1878 $this->assertStatus($status);
1883 * Test the api_statuses_user_timeline() function with an RSS result.
1886 public function testApiStatusesUserTimelineWithRss()
1888 $result = api_statuses_user_timeline('rss');
1889 $this->assertXml($result, 'statuses');
1893 * Test the api_statuses_user_timeline() function with an unallowed user.
1895 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1897 public function testApiStatusesUserTimelineWithUnallowedUser()
1899 $_SESSION['allow_api'] = false;
1900 $_GET['screen_name'] = $this->selfUser['nick'];
1901 api_statuses_user_timeline('json');
1905 * Test the api_favorites_create_destroy() function.
1907 * @expectedException Friendica\Network\HTTPException\BadRequestException
1909 public function testApiFavoritesCreateDestroy()
1911 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1912 $this->app->argc = count($this->app->argv);
1913 api_favorites_create_destroy('json');
1917 * Test the api_favorites_create_destroy() function with an invalid ID.
1919 * @expectedException Friendica\Network\HTTPException\BadRequestException
1921 public function testApiFavoritesCreateDestroyWithInvalidId()
1923 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1924 $this->app->argc = count($this->app->argv);
1925 api_favorites_create_destroy('json');
1929 * Test the api_favorites_create_destroy() function with an invalid action.
1931 * @expectedException Friendica\Network\HTTPException\BadRequestException
1933 public function testApiFavoritesCreateDestroyWithInvalidAction()
1935 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1936 $this->app->argc = count($this->app->argv);
1937 $_REQUEST['id'] = 1;
1938 api_favorites_create_destroy('json');
1942 * Test the api_favorites_create_destroy() function with the create action.
1945 public function testApiFavoritesCreateDestroyWithCreateAction()
1947 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1948 $this->app->argc = count($this->app->argv);
1949 $_REQUEST['id'] = 3;
1950 $result = api_favorites_create_destroy('json');
1951 $this->assertStatus($result['status']);
1955 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1958 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1960 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1961 $this->app->argc = count($this->app->argv);
1962 $_REQUEST['id'] = 3;
1963 $result = api_favorites_create_destroy('rss');
1964 $this->assertXml($result, 'status');
1968 * Test the api_favorites_create_destroy() function with the destroy action.
1971 public function testApiFavoritesCreateDestroyWithDestroyAction()
1973 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1974 $this->app->argc = count($this->app->argv);
1975 $_REQUEST['id'] = 3;
1976 $result = api_favorites_create_destroy('json');
1977 $this->assertStatus($result['status']);
1981 * Test the api_favorites_create_destroy() function without an authenticated user.
1983 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1985 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1987 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1988 $this->app->argc = count($this->app->argv);
1989 $_SESSION['authenticated'] = false;
1990 api_favorites_create_destroy('json');
1994 * Test the api_favorites() function.
1997 public function testApiFavorites()
1999 $_REQUEST['page'] = -1;
2000 $_REQUEST['max_id'] = 10;
2001 $result = api_favorites('json');
2002 foreach ($result['status'] as $status) {
2003 $this->assertStatus($status);
2008 * Test the api_favorites() function with an RSS result.
2011 public function testApiFavoritesWithRss()
2013 $result = api_favorites('rss');
2014 $this->assertXml($result, 'statuses');
2018 * Test the api_favorites() function with an unallowed user.
2020 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2022 public function testApiFavoritesWithUnallowedUser()
2024 $_SESSION['allow_api'] = false;
2025 $_GET['screen_name'] = $this->selfUser['nick'];
2026 api_favorites('json');
2030 * Test the api_format_messages() function.
2033 public function testApiFormatMessages()
2035 $result = api_format_messages(
2036 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2037 ['id' => 2, 'screen_name' => 'recipient_name'],
2038 ['id' => 3, 'screen_name' => 'sender_name']
2040 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2041 $this->assertEquals(1, $result['id']);
2042 $this->assertEquals(2, $result['recipient_id']);
2043 $this->assertEquals(3, $result['sender_id']);
2044 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2045 $this->assertEquals('sender_name', $result['sender_screen_name']);
2049 * Test the api_format_messages() function with HTML.
2052 public function testApiFormatMessagesWithHtmlText()
2054 $_GET['getText'] = 'html';
2055 $result = api_format_messages(
2056 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2057 ['id' => 2, 'screen_name' => 'recipient_name'],
2058 ['id' => 3, 'screen_name' => 'sender_name']
2060 $this->assertEquals('item_title', $result['title']);
2061 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2065 * Test the api_format_messages() function with plain text.
2068 public function testApiFormatMessagesWithPlainText()
2070 $_GET['getText'] = 'plain';
2071 $result = api_format_messages(
2072 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2073 ['id' => 2, 'screen_name' => 'recipient_name'],
2074 ['id' => 3, 'screen_name' => 'sender_name']
2076 $this->assertEquals('item_title', $result['title']);
2077 $this->assertEquals('item_body', $result['text']);
2081 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2084 public function testApiFormatMessagesWithoutUserObjects()
2086 $_GET['getUserObjects'] = 'false';
2087 $result = api_format_messages(
2088 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2089 ['id' => 2, 'screen_name' => 'recipient_name'],
2090 ['id' => 3, 'screen_name' => 'sender_name']
2092 $this->assertTrue(!isset($result['sender']));
2093 $this->assertTrue(!isset($result['recipient']));
2097 * Test the api_convert_item() function.
2100 public function testApiConvertItem()
2102 $result = api_convert_item(
2104 'network' => 'feed',
2105 'title' => 'item_title',
2106 // We need a long string to test that it is correctly cut
2107 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2108 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2109 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2110 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2111 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2112 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2113 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2114 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2115 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2116 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2117 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2118 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2119 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2120 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2121 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2122 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2123 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2124 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2125 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2126 'repellat officia illum quos impedit quam iste esse unde qui '.
2127 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2128 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2129 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2130 'plink' => 'item_plink'
2133 $this->assertStringStartsWith('item_title', $result['text']);
2134 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2138 * Test the api_convert_item() function with an empty item body.
2141 public function testApiConvertItemWithoutBody()
2143 $result = api_convert_item(
2145 'network' => 'feed',
2146 'title' => 'item_title',
2148 'plink' => 'item_plink'
2151 $this->assertEquals('item_title', $result['text']);
2152 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2156 * Test the api_convert_item() function with the title in the body.
2159 public function testApiConvertItemWithTitleInBody()
2161 $result = api_convert_item(
2163 'title' => 'item_title',
2164 'body' => 'item_title item_body'
2167 $this->assertEquals('item_title item_body', $result['text']);
2168 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2172 * Test the api_get_attachments() function.
2175 public function testApiGetAttachments()
2178 $this->assertEmpty(api_get_attachments($body));
2182 * Test the api_get_attachments() function with an img tag.
2185 public function testApiGetAttachmentsWithImage()
2187 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2188 $this->assertInternalType('array', api_get_attachments($body));
2192 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2195 public function testApiGetAttachmentsWithImageAndAndStatus()
2197 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2198 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2199 $this->assertInternalType('array', api_get_attachments($body));
2203 * Test the api_get_entitities() function.
2206 public function testApiGetEntitities()
2209 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2213 * Test the api_get_entitities() function with the include_entities parameter.
2216 public function testApiGetEntititiesWithIncludeEntities()
2218 $_REQUEST['include_entities'] = 'true';
2220 $result = api_get_entitities($text, 'bbcode');
2221 $this->assertInternalType('array', $result['hashtags']);
2222 $this->assertInternalType('array', $result['symbols']);
2223 $this->assertInternalType('array', $result['urls']);
2224 $this->assertInternalType('array', $result['user_mentions']);
2228 * Test the api_format_items_embeded_images() function.
2231 public function testApiFormatItemsEmbededImages()
2233 $this->assertEquals(
2234 'text ' . System::baseUrl() . '/display/item_guid',
2235 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2240 * Test the api_contactlink_to_array() function.
2243 public function testApiContactlinkToArray()
2245 $this->assertEquals(
2250 api_contactlink_to_array('text')
2255 * Test the api_contactlink_to_array() function with an URL.
2258 public function testApiContactlinkToArrayWithUrl()
2260 $this->assertEquals(
2262 'name' => ['link_text'],
2265 api_contactlink_to_array('text <a href="url">link_text</a>')
2270 * Test the api_format_items_activities() function.
2273 public function testApiFormatItemsActivities()
2275 $item = ['uid' => 0, 'uri' => ''];
2276 $result = api_format_items_activities($item);
2277 $this->assertArrayHasKey('like', $result);
2278 $this->assertArrayHasKey('dislike', $result);
2279 $this->assertArrayHasKey('attendyes', $result);
2280 $this->assertArrayHasKey('attendno', $result);
2281 $this->assertArrayHasKey('attendmaybe', $result);
2285 * Test the api_format_items_activities() function with an XML result.
2288 public function testApiFormatItemsActivitiesWithXml()
2290 $item = ['uid' => 0, 'uri' => ''];
2291 $result = api_format_items_activities($item, 'xml');
2292 $this->assertArrayHasKey('friendica:like', $result);
2293 $this->assertArrayHasKey('friendica:dislike', $result);
2294 $this->assertArrayHasKey('friendica:attendyes', $result);
2295 $this->assertArrayHasKey('friendica:attendno', $result);
2296 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2300 * Test the api_format_items_profiles() function.
2303 public function testApiFormatItemsProfiles()
2306 'id' => 'profile_id',
2307 'profile-name' => 'profile_name',
2308 'is-default' => true,
2309 'hide-friends' => true,
2310 'photo' => 'profile_photo',
2311 'thumb' => 'profile_thumb',
2313 'net-publish' => true,
2314 'pdesc' => 'description',
2315 'dob' => 'date_of_birth',
2316 'address' => 'address',
2317 'locality' => 'city',
2318 'region' => 'region',
2319 'postal-code' => 'postal_code',
2320 'country-name' => 'country',
2321 'hometown' => 'hometown',
2322 'gender' => 'gender',
2323 'marital' => 'marital',
2324 'with' => 'marital_with',
2325 'howlong' => 'marital_since',
2326 'sexual' => 'sexual',
2327 'politic' => 'politic',
2328 'religion' => 'religion',
2329 'pub_keywords' => 'public_keywords',
2330 'prv_keywords' => 'private_keywords',
2333 'dislikes' => 'dislikes',
2339 'interest' => 'interest',
2340 'romance' => 'romance',
2342 'education' => 'education',
2343 'contact' => 'social_networks',
2344 'homepage' => 'homepage'
2346 $result = api_format_items_profiles($profile_row);
2347 $this->assertEquals(
2349 'profile_id' => 'profile_id',
2350 'profile_name' => 'profile_name',
2351 'is_default' => true,
2352 'hide_friends' => true,
2353 'profile_photo' => 'profile_photo',
2354 'profile_thumb' => 'profile_thumb',
2356 'net_publish' => true,
2357 'description' => 'description',
2358 'date_of_birth' => 'date_of_birth',
2359 'address' => 'address',
2361 'region' => 'region',
2362 'postal_code' => 'postal_code',
2363 'country' => 'country',
2364 'hometown' => 'hometown',
2365 'gender' => 'gender',
2366 'marital' => 'marital',
2367 'marital_with' => 'marital_with',
2368 'marital_since' => 'marital_since',
2369 'sexual' => 'sexual',
2370 'politic' => 'politic',
2371 'religion' => 'religion',
2372 'public_keywords' => 'public_keywords',
2373 'private_keywords' => 'private_keywords',
2376 'dislikes' => 'dislikes',
2382 'interest' => 'interest',
2383 'romance' => 'romance',
2385 'education' => 'education',
2386 'social_networks' => 'social_networks',
2387 'homepage' => 'homepage',
2395 * Test the api_format_items() function.
2398 public function testApiFormatItems()
2402 'item_network' => 'item_network',
2408 'author-network' => Protocol::DFRN,
2409 'author-link' => 'http://localhost/profile/othercontact',
2413 $result = api_format_items($items, ['id' => 0], true);
2414 foreach ($result as $status) {
2415 $this->assertStatus($status);
2420 * Test the api_format_items() function with an XML result.
2423 public function testApiFormatItemsWithXml()
2431 'author-network' => Protocol::DFRN,
2432 'author-link' => 'http://localhost/profile/othercontact',
2436 $result = api_format_items($items, ['id' => 0], true, 'xml');
2437 foreach ($result as $status) {
2438 $this->assertStatus($status);
2443 * Test the api_format_items() function.
2446 public function testApiAccountRateLimitStatus()
2448 $result = api_account_rate_limit_status('json');
2449 $this->assertEquals(150, $result['hash']['remaining_hits']);
2450 $this->assertEquals(150, $result['hash']['hourly_limit']);
2451 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2455 * Test the api_format_items() function with an XML result.
2458 public function testApiAccountRateLimitStatusWithXml()
2460 $result = api_account_rate_limit_status('xml');
2461 $this->assertXml($result, 'hash');
2465 * Test the api_help_test() function.
2468 public function testApiHelpTest()
2470 $result = api_help_test('json');
2471 $this->assertEquals(['ok' => 'ok'], $result);
2475 * Test the api_help_test() function with an XML result.
2478 public function testApiHelpTestWithXml()
2480 $result = api_help_test('xml');
2481 $this->assertXml($result, 'ok');
2485 * Test the api_lists_list() function.
2488 public function testApiListsList()
2490 $result = api_lists_list('json');
2491 $this->assertEquals(['lists_list' => []], $result);
2495 * Test the api_lists_ownerships() function.
2498 public function testApiListsOwnerships()
2500 $result = api_lists_ownerships('json');
2501 foreach ($result['lists']['lists'] as $list) {
2502 $this->assertList($list);
2507 * Test the api_lists_ownerships() function without an authenticated user.
2509 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2511 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2513 $_SESSION['authenticated'] = false;
2514 api_lists_ownerships('json');
2518 * Test the api_lists_statuses() function.
2519 * @expectedException Friendica\Network\HTTPException\BadRequestException
2522 public function testApiListsStatuses()
2524 api_lists_statuses('json');
2528 * Test the api_lists_statuses() function with a list ID.
2531 public function testApiListsStatusesWithListId()
2533 $_REQUEST['list_id'] = 1;
2534 $_REQUEST['page'] = -1;
2535 $_REQUEST['max_id'] = 10;
2536 $result = api_lists_statuses('json');
2537 foreach ($result['status'] as $status) {
2538 $this->assertStatus($status);
2543 * Test the api_lists_statuses() function with a list ID and a RSS result.
2546 public function testApiListsStatusesWithListIdAndRss()
2548 $_REQUEST['list_id'] = 1;
2549 $result = api_lists_statuses('rss');
2550 $this->assertXml($result, 'statuses');
2554 * Test the api_lists_statuses() function with an unallowed user.
2556 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2558 public function testApiListsStatusesWithUnallowedUser()
2560 $_SESSION['allow_api'] = false;
2561 $_GET['screen_name'] = $this->selfUser['nick'];
2562 api_lists_statuses('json');
2566 * Test the api_statuses_f() function.
2569 public function testApiStatusesFWithFriends()
2572 $result = api_statuses_f('friends');
2573 $this->assertArrayHasKey('user', $result);
2577 * Test the api_statuses_f() function.
2580 public function testApiStatusesFWithFollowers()
2582 $result = api_statuses_f('followers');
2583 $this->assertArrayHasKey('user', $result);
2587 * Test the api_statuses_f() function.
2590 public function testApiStatusesFWithBlocks()
2592 $result = api_statuses_f('blocks');
2593 $this->assertArrayHasKey('user', $result);
2597 * Test the api_statuses_f() function.
2600 public function testApiStatusesFWithIncoming()
2602 $result = api_statuses_f('incoming');
2603 $this->assertArrayHasKey('user', $result);
2607 * Test the api_statuses_f() function an undefined cursor GET variable.
2610 public function testApiStatusesFWithUndefinedCursor()
2612 $_GET['cursor'] = 'undefined';
2613 $this->assertFalse(api_statuses_f('friends'));
2617 * Test the api_statuses_friends() function.
2620 public function testApiStatusesFriends()
2622 $result = api_statuses_friends('json');
2623 $this->assertArrayHasKey('user', $result);
2627 * Test the api_statuses_friends() function an undefined cursor GET variable.
2630 public function testApiStatusesFriendsWithUndefinedCursor()
2632 $_GET['cursor'] = 'undefined';
2633 $this->assertFalse(api_statuses_friends('json'));
2637 * Test the api_statuses_followers() function.
2640 public function testApiStatusesFollowers()
2642 $result = api_statuses_followers('json');
2643 $this->assertArrayHasKey('user', $result);
2647 * Test the api_statuses_followers() function an undefined cursor GET variable.
2650 public function testApiStatusesFollowersWithUndefinedCursor()
2652 $_GET['cursor'] = 'undefined';
2653 $this->assertFalse(api_statuses_followers('json'));
2657 * Test the api_blocks_list() function.
2660 public function testApiBlocksList()
2662 $result = api_blocks_list('json');
2663 $this->assertArrayHasKey('user', $result);
2667 * Test the api_blocks_list() function an undefined cursor GET variable.
2670 public function testApiBlocksListWithUndefinedCursor()
2672 $_GET['cursor'] = 'undefined';
2673 $this->assertFalse(api_blocks_list('json'));
2677 * Test the api_friendships_incoming() function.
2680 public function testApiFriendshipsIncoming()
2682 $result = api_friendships_incoming('json');
2683 $this->assertArrayHasKey('id', $result);
2687 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2690 public function testApiFriendshipsIncomingWithUndefinedCursor()
2692 $_GET['cursor'] = 'undefined';
2693 $this->assertFalse(api_friendships_incoming('json'));
2697 * Test the api_statusnet_config() function.
2700 public function testApiStatusnetConfig()
2702 $result = api_statusnet_config('json');
2703 $this->assertEquals('localhost', $result['config']['site']['server']);
2704 $this->assertEquals('default', $result['config']['site']['theme']);
2705 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2706 $this->assertTrue($result['config']['site']['fancy']);
2707 $this->assertEquals('en', $result['config']['site']['language']);
2708 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2709 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2710 $this->assertEquals('false', $result['config']['site']['private']);
2711 $this->assertEquals('false', $result['config']['site']['ssl']);
2712 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2716 * Test the api_statusnet_version() function.
2719 public function testApiStatusnetVersion()
2721 $result = api_statusnet_version('json');
2722 $this->assertEquals('0.9.7', $result['version']);
2726 * Test the api_ff_ids() function.
2729 public function testApiFfIds()
2731 $result = api_ff_ids('json');
2732 $this->assertNull($result);
2736 * Test the api_ff_ids() function with a result.
2739 public function testApiFfIdsWithResult()
2741 $this->markTestIncomplete();
2745 * Test the api_ff_ids() function without an authenticated user.
2747 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2749 public function testApiFfIdsWithoutAuthenticatedUser()
2751 $_SESSION['authenticated'] = false;
2756 * Test the api_friends_ids() function.
2759 public function testApiFriendsIds()
2761 $result = api_friends_ids('json');
2762 $this->assertNull($result);
2766 * Test the api_followers_ids() function.
2769 public function testApiFollowersIds()
2771 $result = api_followers_ids('json');
2772 $this->assertNull($result);
2776 * Test the api_direct_messages_new() function.
2779 public function testApiDirectMessagesNew()
2781 $result = api_direct_messages_new('json');
2782 $this->assertNull($result);
2786 * Test the api_direct_messages_new() function without an authenticated user.
2788 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2790 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2792 $_SESSION['authenticated'] = false;
2793 api_direct_messages_new('json');
2797 * Test the api_direct_messages_new() function with an user ID.
2800 public function testApiDirectMessagesNewWithUserId()
2802 $_POST['text'] = 'message_text';
2803 $_POST['user_id'] = $this->otherUser['id'];
2804 $result = api_direct_messages_new('json');
2805 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2809 * Test the api_direct_messages_new() function with a screen name.
2812 public function testApiDirectMessagesNewWithScreenName()
2814 $_POST['text'] = 'message_text';
2815 $_POST['screen_name'] = $this->friendUser['nick'];
2816 $result = api_direct_messages_new('json');
2817 $this->assertEquals(1, $result['direct_message']['id']);
2818 $this->assertContains('message_text', $result['direct_message']['text']);
2819 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2820 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2824 * Test the api_direct_messages_new() function with a title.
2827 public function testApiDirectMessagesNewWithTitle()
2829 $_POST['text'] = 'message_text';
2830 $_POST['screen_name'] = $this->friendUser['nick'];
2831 $_REQUEST['title'] = 'message_title';
2832 $result = api_direct_messages_new('json');
2833 $this->assertEquals(1, $result['direct_message']['id']);
2834 $this->assertContains('message_text', $result['direct_message']['text']);
2835 $this->assertContains('message_title', $result['direct_message']['text']);
2836 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2837 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2841 * Test the api_direct_messages_new() function with an RSS result.
2844 public function testApiDirectMessagesNewWithRss()
2846 $_POST['text'] = 'message_text';
2847 $_POST['screen_name'] = $this->friendUser['nick'];
2848 $result = api_direct_messages_new('rss');
2849 $this->assertXml($result, 'direct-messages');
2853 * Test the api_direct_messages_destroy() function.
2855 * @expectedException Friendica\Network\HTTPException\BadRequestException
2857 public function testApiDirectMessagesDestroy()
2859 api_direct_messages_destroy('json');
2863 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2866 public function testApiDirectMessagesDestroyWithVerbose()
2868 $_GET['friendica_verbose'] = 'true';
2869 $result = api_direct_messages_destroy('json');
2870 $this->assertEquals(
2873 'result' => 'error',
2874 'message' => 'message id or parenturi not specified'
2882 * Test the api_direct_messages_destroy() function without an authenticated user.
2884 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2886 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2888 $_SESSION['authenticated'] = false;
2889 api_direct_messages_destroy('json');
2893 * Test the api_direct_messages_destroy() function with a non-zero ID.
2895 * @expectedException Friendica\Network\HTTPException\BadRequestException
2897 public function testApiDirectMessagesDestroyWithId()
2899 $_REQUEST['id'] = 1;
2900 api_direct_messages_destroy('json');
2904 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2907 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2909 $_REQUEST['id'] = 1;
2910 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2911 $_GET['friendica_verbose'] = 'true';
2912 $result = api_direct_messages_destroy('json');
2913 $this->assertEquals(
2916 'result' => 'error',
2917 'message' => 'message id not in database'
2925 * Test the api_direct_messages_destroy() function with a non-zero ID.
2928 public function testApiDirectMessagesDestroyWithCorrectId()
2930 $this->markTestIncomplete('We need to add a dataset for this.');
2934 * Test the api_direct_messages_box() function.
2937 public function testApiDirectMessagesBoxWithSentbox()
2939 $_REQUEST['page'] = -1;
2940 $_REQUEST['max_id'] = 10;
2941 $result = api_direct_messages_box('json', 'sentbox', 'false');
2942 $this->assertArrayHasKey('direct_message', $result);
2946 * Test the api_direct_messages_box() function.
2949 public function testApiDirectMessagesBoxWithConversation()
2951 $result = api_direct_messages_box('json', 'conversation', 'false');
2952 $this->assertArrayHasKey('direct_message', $result);
2956 * Test the api_direct_messages_box() function.
2959 public function testApiDirectMessagesBoxWithAll()
2961 $result = api_direct_messages_box('json', 'all', 'false');
2962 $this->assertArrayHasKey('direct_message', $result);
2966 * Test the api_direct_messages_box() function.
2969 public function testApiDirectMessagesBoxWithInbox()
2971 $result = api_direct_messages_box('json', 'inbox', 'false');
2972 $this->assertArrayHasKey('direct_message', $result);
2976 * Test the api_direct_messages_box() function.
2979 public function testApiDirectMessagesBoxWithVerbose()
2981 $result = api_direct_messages_box('json', 'sentbox', 'true');
2982 $this->assertEquals(
2985 'result' => 'error',
2986 'message' => 'no mails available'
2994 * Test the api_direct_messages_box() function with a RSS result.
2997 public function testApiDirectMessagesBoxWithRss()
2999 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3000 $this->assertXml($result, 'direct-messages');
3004 * Test the api_direct_messages_box() function without an authenticated user.
3006 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3008 public function testApiDirectMessagesBoxWithUnallowedUser()
3010 $_SESSION['allow_api'] = false;
3011 $_GET['screen_name'] = $this->selfUser['nick'];
3012 api_direct_messages_box('json', 'sentbox', 'false');
3016 * Test the api_direct_messages_sentbox() function.
3019 public function testApiDirectMessagesSentbox()
3021 $result = api_direct_messages_sentbox('json');
3022 $this->assertArrayHasKey('direct_message', $result);
3026 * Test the api_direct_messages_inbox() function.
3029 public function testApiDirectMessagesInbox()
3031 $result = api_direct_messages_inbox('json');
3032 $this->assertArrayHasKey('direct_message', $result);
3036 * Test the api_direct_messages_all() function.
3039 public function testApiDirectMessagesAll()
3041 $result = api_direct_messages_all('json');
3042 $this->assertArrayHasKey('direct_message', $result);
3046 * Test the api_direct_messages_conversation() function.
3049 public function testApiDirectMessagesConversation()
3051 $result = api_direct_messages_conversation('json');
3052 $this->assertArrayHasKey('direct_message', $result);
3056 * Test the api_oauth_request_token() function.
3059 public function testApiOauthRequestToken()
3061 $this->markTestIncomplete('killme() kills phpunit as well');
3065 * Test the api_oauth_access_token() function.
3068 public function testApiOauthAccessToken()
3070 $this->markTestIncomplete('killme() kills phpunit as well');
3074 * Test the api_fr_photoalbum_delete() function.
3076 * @expectedException Friendica\Network\HTTPException\BadRequestException
3078 public function testApiFrPhotoalbumDelete()
3080 api_fr_photoalbum_delete('json');
3084 * Test the api_fr_photoalbum_delete() function with an album name.
3086 * @expectedException Friendica\Network\HTTPException\BadRequestException
3088 public function testApiFrPhotoalbumDeleteWithAlbum()
3090 $_REQUEST['album'] = 'album_name';
3091 api_fr_photoalbum_delete('json');
3095 * Test the api_fr_photoalbum_delete() function with an album name.
3098 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3100 $this->markTestIncomplete('We need to add a dataset for this.');
3104 * Test the api_fr_photoalbum_delete() function.
3106 * @expectedException Friendica\Network\HTTPException\BadRequestException
3108 public function testApiFrPhotoalbumUpdate()
3110 api_fr_photoalbum_update('json');
3114 * Test the api_fr_photoalbum_delete() function with an album name.
3116 * @expectedException Friendica\Network\HTTPException\BadRequestException
3118 public function testApiFrPhotoalbumUpdateWithAlbum()
3120 $_REQUEST['album'] = 'album_name';
3121 api_fr_photoalbum_update('json');
3125 * Test the api_fr_photoalbum_delete() function with an album name.
3127 * @expectedException Friendica\Network\HTTPException\BadRequestException
3129 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3131 $_REQUEST['album'] = 'album_name';
3132 $_REQUEST['album_new'] = 'album_name';
3133 api_fr_photoalbum_update('json');
3137 * Test the api_fr_photoalbum_update() function without an authenticated user.
3139 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3141 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3143 $_SESSION['authenticated'] = false;
3144 api_fr_photoalbum_update('json');
3148 * Test the api_fr_photoalbum_delete() function with an album name.
3151 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3153 $this->markTestIncomplete('We need to add a dataset for this.');
3157 * Test the api_fr_photos_list() function.
3160 public function testApiFrPhotosList()
3162 $result = api_fr_photos_list('json');
3163 $this->assertArrayHasKey('photo', $result);
3167 * Test the api_fr_photos_list() function without an authenticated user.
3169 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3171 public function testApiFrPhotosListWithoutAuthenticatedUser()
3173 $_SESSION['authenticated'] = false;
3174 api_fr_photos_list('json');
3178 * Test the api_fr_photo_create_update() function.
3180 * @expectedException Friendica\Network\HTTPException\BadRequestException
3182 public function testApiFrPhotoCreateUpdate()
3184 api_fr_photo_create_update('json');
3188 * Test the api_fr_photo_create_update() function without an authenticated user.
3190 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3192 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3194 $_SESSION['authenticated'] = false;
3195 api_fr_photo_create_update('json');
3199 * Test the api_fr_photo_create_update() function with an album name.
3201 * @expectedException Friendica\Network\HTTPException\BadRequestException
3203 public function testApiFrPhotoCreateUpdateWithAlbum()
3205 $_REQUEST['album'] = 'album_name';
3206 api_fr_photo_create_update('json');
3210 * Test the api_fr_photo_create_update() function with the update mode.
3213 public function testApiFrPhotoCreateUpdateWithUpdate()
3215 $this->markTestIncomplete('We need to create a dataset for this');
3219 * Test the api_fr_photo_create_update() function with an uploaded file.
3222 public function testApiFrPhotoCreateUpdateWithFile()
3224 $this->markTestIncomplete();
3228 * Test the api_fr_photo_delete() function.
3230 * @expectedException Friendica\Network\HTTPException\BadRequestException
3232 public function testApiFrPhotoDelete()
3234 api_fr_photo_delete('json');
3238 * Test the api_fr_photo_delete() function without an authenticated user.
3240 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3242 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3244 $_SESSION['authenticated'] = false;
3245 api_fr_photo_delete('json');
3249 * Test the api_fr_photo_delete() function with a photo ID.
3251 * @expectedException Friendica\Network\HTTPException\BadRequestException
3253 public function testApiFrPhotoDeleteWithPhotoId()
3255 $_REQUEST['photo_id'] = 1;
3256 api_fr_photo_delete('json');
3260 * Test the api_fr_photo_delete() function with a correct photo ID.
3263 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3265 $this->markTestIncomplete('We need to create a dataset for this.');
3269 * Test the api_fr_photo_detail() function.
3271 * @expectedException Friendica\Network\HTTPException\BadRequestException
3273 public function testApiFrPhotoDetail()
3275 api_fr_photo_detail('json');
3279 * Test the api_fr_photo_detail() function without an authenticated user.
3281 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3283 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3285 $_SESSION['authenticated'] = false;
3286 api_fr_photo_detail('json');
3290 * Test the api_fr_photo_detail() function with a photo ID.
3292 * @expectedException Friendica\Network\HTTPException\NotFoundException
3294 public function testApiFrPhotoDetailWithPhotoId()
3296 $_REQUEST['photo_id'] = 1;
3297 api_fr_photo_detail('json');
3301 * Test the api_fr_photo_detail() function with a correct photo ID.
3304 public function testApiFrPhotoDetailCorrectPhotoId()
3306 $this->markTestIncomplete('We need to create a dataset for this.');
3310 * Test the api_account_update_profile_image() function.
3312 * @expectedException Friendica\Network\HTTPException\BadRequestException
3314 public function testApiAccountUpdateProfileImage()
3316 api_account_update_profile_image('json');
3320 * Test the api_account_update_profile_image() function without an authenticated user.
3322 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3324 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3326 $_SESSION['authenticated'] = false;
3327 api_account_update_profile_image('json');
3331 * Test the api_account_update_profile_image() function with an uploaded file.
3333 * @expectedException Friendica\Network\HTTPException\BadRequestException
3335 public function testApiAccountUpdateProfileImageWithUpload()
3337 $this->markTestIncomplete();
3342 * Test the api_account_update_profile() function.
3345 public function testApiAccountUpdateProfile()
3347 $_POST['name'] = 'new_name';
3348 $_POST['description'] = 'new_description';
3349 $result = api_account_update_profile('json');
3350 // We can't use assertSelfUser() here because the user object is missing some properties.
3351 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3352 $this->assertEquals('DFRN', $result['user']['location']);
3353 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3354 $this->assertEquals('dfrn', $result['user']['network']);
3355 $this->assertEquals('new_name', $result['user']['name']);
3356 $this->assertEquals('new_description', $result['user']['description']);
3360 * Test the check_acl_input() function.
3363 public function testCheckAclInput()
3365 $result = check_acl_input('<aclstring>');
3366 // Where does this result come from?
3367 $this->assertEquals(1, $result);
3371 * Test the check_acl_input() function with an empty ACL string.
3374 public function testCheckAclInputWithEmptyAclString()
3376 $result = check_acl_input(' ');
3377 $this->assertFalse($result);
3381 * Test the save_media_to_database() function.
3384 public function testSaveMediaToDatabase()
3386 $this->markTestIncomplete();
3390 * Test the post_photo_item() function.
3393 public function testPostPhotoItem()
3395 $this->markTestIncomplete();
3399 * Test the prepare_photo_data() function.
3402 public function testPreparePhotoData()
3404 $this->markTestIncomplete();
3408 * Test the api_friendica_remoteauth() function.
3410 * @expectedException Friendica\Network\HTTPException\BadRequestException
3412 public function testApiFriendicaRemoteauth()
3414 api_friendica_remoteauth();
3418 * Test the api_friendica_remoteauth() function with an URL.
3420 * @expectedException Friendica\Network\HTTPException\BadRequestException
3422 public function testApiFriendicaRemoteauthWithUrl()
3424 $_GET['url'] = 'url';
3425 $_GET['c_url'] = 'url';
3426 api_friendica_remoteauth();
3430 * Test the api_friendica_remoteauth() function with a correct URL.
3433 public function testApiFriendicaRemoteauthWithCorrectUrl()
3435 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3436 $_GET['url'] = 'url';
3437 $_GET['c_url'] = $this->selfUser['nurl'];
3438 api_friendica_remoteauth();
3442 * Test the api_share_as_retweet() function.
3445 public function testApiShareAsRetweet()
3447 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3448 $result = api_share_as_retweet($item);
3449 $this->assertFalse($result);
3453 * Test the api_share_as_retweet() function with a valid item.
3456 public function testApiShareAsRetweetWithValidItem()
3458 $this->markTestIncomplete();
3462 * Test the api_get_nick() function.
3465 public function testApiGetNick()
3467 $result = api_get_nick($this->otherUser['nurl']);
3468 $this->assertEquals('othercontact', $result);
3472 * Test the api_get_nick() function with a wrong URL.
3475 public function testApiGetNickWithWrongUrl()
3477 $result = api_get_nick('wrong_url');
3478 $this->assertFalse($result);
3482 * Test the api_in_reply_to() function.
3485 public function testApiInReplyTo()
3487 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3488 $this->assertArrayHasKey('status_id', $result);
3489 $this->assertArrayHasKey('user_id', $result);
3490 $this->assertArrayHasKey('status_id_str', $result);
3491 $this->assertArrayHasKey('user_id_str', $result);
3492 $this->assertArrayHasKey('screen_name', $result);
3496 * Test the api_in_reply_to() function with a valid item.
3499 public function testApiInReplyToWithValidItem()
3501 $this->markTestIncomplete();
3505 * Test the api_clean_plain_items() function.
3508 public function testApiCleanPlainItems()
3510 $_REQUEST['include_entities'] = 'true';
3511 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3512 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3516 * Test the api_clean_attachments() function.
3519 public function testApiCleanAttachments()
3521 $this->markTestIncomplete();
3525 * Test the api_best_nickname() function.
3528 public function testApiBestNickname()
3531 $result = api_best_nickname($contacts);
3532 $this->assertNull($result);
3536 * Test the api_best_nickname() function with contacts.
3539 public function testApiBestNicknameWithContacts()
3541 $this->markTestIncomplete();
3545 * Test the api_friendica_group_show() function.
3548 public function testApiFriendicaGroupShow()
3550 $this->markTestIncomplete();
3554 * Test the api_friendica_group_delete() function.
3557 public function testApiFriendicaGroupDelete()
3559 $this->markTestIncomplete();
3563 * Test the api_lists_destroy() function.
3566 public function testApiListsDestroy()
3568 $this->markTestIncomplete();
3572 * Test the group_create() function.
3575 public function testGroupCreate()
3577 $this->markTestIncomplete();
3581 * Test the api_friendica_group_create() function.
3584 public function testApiFriendicaGroupCreate()
3586 $this->markTestIncomplete();
3590 * Test the api_lists_create() function.
3593 public function testApiListsCreate()
3595 $this->markTestIncomplete();
3599 * Test the api_friendica_group_update() function.
3602 public function testApiFriendicaGroupUpdate()
3604 $this->markTestIncomplete();
3608 * Test the api_lists_update() function.
3611 public function testApiListsUpdate()
3613 $this->markTestIncomplete();
3617 * Test the api_friendica_activity() function.
3620 public function testApiFriendicaActivity()
3622 $this->markTestIncomplete();
3626 * Test the api_friendica_notification() function.
3628 * @expectedException Friendica\Network\HTTPException\BadRequestException
3630 public function testApiFriendicaNotification()
3632 api_friendica_notification('json');
3636 * Test the api_friendica_notification() function without an authenticated user.
3638 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3640 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3642 $_SESSION['authenticated'] = false;
3643 api_friendica_notification('json');
3647 * Test the api_friendica_notification() function with an argument count.
3650 public function testApiFriendicaNotificationWithArgumentCount()
3652 $this->app->argv = ['api', 'friendica', 'notification'];
3653 $this->app->argc = count($this->app->argv);
3654 $result = api_friendica_notification('json');
3655 $this->assertEquals(['note' => false], $result);
3659 * Test the api_friendica_notification() function with an XML result.
3662 public function testApiFriendicaNotificationWithXmlResult()
3664 $this->app->argv = ['api', 'friendica', 'notification'];
3665 $this->app->argc = count($this->app->argv);
3666 $result = api_friendica_notification('xml');
3667 $this->assertXml($result, 'notes');
3671 * Test the api_friendica_notification_seen() function.
3674 public function testApiFriendicaNotificationSeen()
3676 $this->markTestIncomplete();
3680 * Test the api_friendica_direct_messages_setseen() function.
3683 public function testApiFriendicaDirectMessagesSetseen()
3685 $this->markTestIncomplete();
3689 * Test the api_friendica_direct_messages_search() function.
3692 public function testApiFriendicaDirectMessagesSearch()
3694 $this->markTestIncomplete();
3698 * Test the api_friendica_profile_show() function.
3701 public function testApiFriendicaProfileShow()
3703 $result = api_friendica_profile_show('json');
3704 // We can't use assertSelfUser() here because the user object is missing some properties.
3705 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3706 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3707 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3708 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3709 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3710 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3711 $this->assertFalse($result['$result']['multi_profiles']);
3715 * Test the api_friendica_profile_show() function with a profile ID.
3718 public function testApiFriendicaProfileShowWithProfileId()
3720 $this->markTestIncomplete('We need to add a dataset for this.');
3724 * Test the api_friendica_profile_show() function with a wrong profile ID.
3726 * @expectedException Friendica\Network\HTTPException\BadRequestException
3728 public function testApiFriendicaProfileShowWithWrongProfileId()
3730 $_REQUEST['profile_id'] = 666;
3731 api_friendica_profile_show('json');
3735 * Test the api_friendica_profile_show() function without an authenticated user.
3737 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3739 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3741 $_SESSION['authenticated'] = false;
3742 api_friendica_profile_show('json');
3746 * Test the api_saved_searches_list() function.
3749 public function testApiSavedSearchesList()
3751 $result = api_saved_searches_list('json');
3752 $this->assertEquals(1, $result['terms'][0]['id']);
3753 $this->assertEquals(1, $result['terms'][0]['id_str']);
3754 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3755 $this->assertEquals('Saved search', $result['terms'][0]['query']);