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 protected function setUp()
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);
59 /** @var Database $dba */
60 $dba = $dice->create(Database::class);
62 // Load the API dataset for the whole API
63 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
65 $this->app = BaseObject::getApp();
68 $this->app->argv = ['home'];
70 // User data that the test database is populated with
73 'name' => 'Self contact',
74 'nick' => 'selfcontact',
75 'nurl' => 'http://localhost/profile/selfcontact'
79 'name' => 'Friend contact',
80 'nick' => 'friendcontact',
81 'nurl' => 'http://localhost/profile/friendcontact'
85 'name' => 'othercontact',
86 'nick' => 'othercontact',
87 'nurl' => 'http://localhost/profile/othercontact'
90 // User ID that we know is not in the database
91 $this->wrongUserId = 666;
93 // Most API require login so we force the session
96 'authenticated' => true,
97 'uid' => $this->selfUser['id']
104 Config::set('system', 'url', 'http://localhost');
105 Config::set('system', 'hostname', 'localhost');
106 Config::set('system', 'worker_dont_fork', true);
109 Config::set('config', 'hostname', 'localhost');
110 Config::set('system', 'throttle_limit_day', 100);
111 Config::set('system', 'throttle_limit_week', 100);
112 Config::set('system', 'throttle_limit_month', 100);
113 Config::set('system', 'theme', 'system_theme');
117 * Assert that an user array contains expected keys.
119 * @param array $user User array
123 private function assertSelfUser(array $user)
125 $this->assertEquals($this->selfUser['id'], $user['uid']);
126 $this->assertEquals($this->selfUser['id'], $user['cid']);
127 $this->assertEquals(1, $user['self']);
128 $this->assertEquals('DFRN', $user['location']);
129 $this->assertEquals($this->selfUser['name'], $user['name']);
130 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
131 $this->assertEquals('dfrn', $user['network']);
132 $this->assertTrue($user['verified']);
136 * Assert that an user array contains expected keys.
138 * @param array $user User array
142 private function assertOtherUser(array $user)
144 $this->assertEquals($this->otherUser['id'], $user['id']);
145 $this->assertEquals($this->otherUser['id'], $user['id_str']);
146 $this->assertEquals(0, $user['self']);
147 $this->assertEquals($this->otherUser['name'], $user['name']);
148 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
149 $this->assertFalse($user['verified']);
153 * Assert that a status array contains expected keys.
155 * @param array $status Status array
159 private function assertStatus(array $status)
161 $this->assertInternalType('string', $status['text']);
162 $this->assertInternalType('int', $status['id']);
163 // We could probably do more checks here.
167 * Assert that a list array contains expected keys.
169 * @param array $list List array
173 private function assertList(array $list)
175 $this->assertInternalType('string', $list['name']);
176 $this->assertInternalType('int', $list['id']);
177 $this->assertInternalType('string', $list['id_str']);
178 $this->assertContains($list['mode'], ['public', 'private']);
179 // We could probably do more checks here.
183 * Assert that the string is XML and contain the root element.
185 * @param string $result XML string
186 * @param string $root_element Root element name
190 private function assertXml($result, $root_element)
192 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
193 $this->assertContains('<' . $root_element, $result);
194 // We could probably do more checks here.
198 * Get the path to a temporary empty PNG image.
200 * @return string Path
202 private function getTempImage()
204 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
208 // Empty 1x1 px PNG image
209 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
217 * Test the api_user() function.
221 public function testApiUser()
223 $this->assertEquals($this->selfUser['id'], api_user());
227 * Test the api_user() function with an unallowed user.
231 public function testApiUserWithUnallowedUser()
233 $_SESSION = ['allow_api' => false];
234 $this->assertEquals(false, api_user());
238 * Test the api_source() function.
242 public function testApiSource()
244 $this->assertEquals('api', api_source());
248 * Test the api_source() function with a Twidere user agent.
252 public function testApiSourceWithTwidere()
254 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
255 $this->assertEquals('Twidere', api_source());
259 * Test the api_source() function with a GET parameter.
263 public function testApiSourceWithGet()
265 $_GET['source'] = 'source_name';
266 $this->assertEquals('source_name', api_source());
270 * Test the api_date() function.
274 public function testApiDate()
276 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
280 * Test the api_register_func() function.
284 public function testApiRegisterFunc()
296 $this->assertTrue($API['api_path']['auth']);
297 $this->assertEquals('method', $API['api_path']['method']);
298 $this->assertTrue(is_callable($API['api_path']['func']));
302 * Test the api_login() function without any login.
305 * @runInSeparateProcess
306 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
308 public function testApiLoginWithoutLogin()
310 api_login($this->app);
314 * Test the api_login() function with a bad login.
317 * @runInSeparateProcess
318 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
320 public function testApiLoginWithBadLogin()
322 $_SERVER['PHP_AUTH_USER'] = 'user@server';
323 api_login($this->app);
327 * Test the api_login() function with oAuth.
331 public function testApiLoginWithOauth()
333 $this->markTestIncomplete('Can we test this easily?');
337 * Test the api_login() function with authentication provided by an addon.
341 public function testApiLoginWithAddonAuth()
343 $this->markTestIncomplete('Can we test this easily?');
347 * Test the api_login() function with a correct login.
350 * @runInSeparateProcess
352 public function testApiLoginWithCorrectLogin()
354 $_SERVER['PHP_AUTH_USER'] = 'Test user';
355 $_SERVER['PHP_AUTH_PW'] = 'password';
356 api_login($this->app);
360 * Test the api_login() function with a remote user.
363 * @runInSeparateProcess
364 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
366 public function testApiLoginWithRemoteUser()
368 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
369 api_login($this->app);
373 * Test the api_check_method() function.
377 public function testApiCheckMethod()
379 $this->assertFalse(api_check_method('method'));
383 * Test the api_check_method() function with a correct method.
387 public function testApiCheckMethodWithCorrectMethod()
389 $_SERVER['REQUEST_METHOD'] = 'method';
390 $this->assertTrue(api_check_method('method'));
394 * Test the api_check_method() function with a wildcard.
398 public function testApiCheckMethodWithWildcard()
400 $this->assertTrue(api_check_method('*'));
404 * Test the api_call() function.
407 * @runInSeparateProcess
409 public function testApiCall()
413 'method' => 'method',
414 'func' => function () {
415 return ['data' => ['some_data']];
418 $_SERVER['REQUEST_METHOD'] = 'method';
419 $_GET['callback'] = 'callback_name';
421 $this->app->query_string = 'api_path';
423 'callback_name(["some_data"])',
429 * Test the api_call() function with the profiled enabled.
432 * @runInSeparateProcess
434 public function testApiCallWithProfiler()
438 'method' => 'method',
439 'func' => function () {
440 return ['data' => ['some_data']];
443 $_SERVER['REQUEST_METHOD'] = 'method';
444 Config::set('system', 'profiler', true);
445 Config::set('rendertime', 'callstack', true);
446 $this->app->callstack = [
447 'database' => ['some_function' => 200],
448 'database_write' => ['some_function' => 200],
449 'cache' => ['some_function' => 200],
450 'cache_write' => ['some_function' => 200],
451 'network' => ['some_function' => 200]
454 $this->app->query_string = 'api_path';
462 * Test the api_call() function without any result.
465 * @runInSeparateProcess
467 public function testApiCallWithNoResult()
471 'method' => 'method',
472 'func' => function () {
476 $_SERVER['REQUEST_METHOD'] = 'method';
478 $this->app->query_string = 'api_path';
480 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
486 * Test the api_call() function with an unimplemented API.
489 * @runInSeparateProcess
491 public function testApiCallWithUninplementedApi()
494 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
500 * Test the api_call() function with a JSON result.
503 * @runInSeparateProcess
505 public function testApiCallWithJson()
509 'method' => 'method',
510 'func' => function () {
511 return ['data' => ['some_data']];
514 $_SERVER['REQUEST_METHOD'] = 'method';
516 $this->app->query_string = 'api_path.json';
524 * Test the api_call() function with an XML result.
527 * @runInSeparateProcess
529 public function testApiCallWithXml()
533 'method' => 'method',
534 'func' => function () {
538 $_SERVER['REQUEST_METHOD'] = 'method';
540 $this->app->query_string = 'api_path.xml';
548 * Test the api_call() function with an RSS result.
551 * @runInSeparateProcess
553 public function testApiCallWithRss()
557 'method' => 'method',
558 'func' => function () {
562 $_SERVER['REQUEST_METHOD'] = 'method';
564 $this->app->query_string = 'api_path.rss';
566 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
573 * Test the api_call() function with an Atom result.
576 * @runInSeparateProcess
578 public function testApiCallWithAtom()
582 'method' => 'method',
583 'func' => function () {
587 $_SERVER['REQUEST_METHOD'] = 'method';
589 $this->app->query_string = 'api_path.atom';
591 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
598 * Test the api_call() function with an unallowed method.
601 * @runInSeparateProcess
603 public function testApiCallWithWrongMethod()
606 $API['api_path'] = ['method' => 'method'];
608 $this->app->query_string = 'api_path';
610 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
616 * Test the api_call() function with an unauthorized user.
619 * @runInSeparateProcess
621 public function testApiCallWithWrongAuth()
625 'method' => 'method',
628 $_SERVER['REQUEST_METHOD'] = 'method';
629 $_SESSION['authenticated'] = false;
631 $this->app->query_string = 'api_path';
633 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
639 * Test the api_error() function with a JSON result.
642 * @runInSeparateProcess
644 public function testApiErrorWithJson()
647 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
648 api_error('json', new HTTPException\OKException('error_message'))
653 * Test the api_error() function with an XML result.
656 * @runInSeparateProcess
658 public function testApiErrorWithXml()
661 '<?xml version="1.0"?>' . "\n" .
662 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
663 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
664 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
665 ' <error>error_message</error>' . "\n" .
666 ' <code>200 OK</code>' . "\n" .
667 ' <request/>' . "\n" .
669 api_error('xml', new HTTPException\OKException('error_message'))
674 * Test the api_error() function with an RSS result.
677 * @runInSeparateProcess
679 public function testApiErrorWithRss()
682 '<?xml version="1.0"?>' . "\n" .
683 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
684 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
685 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
686 ' <error>error_message</error>' . "\n" .
687 ' <code>200 OK</code>' . "\n" .
688 ' <request/>' . "\n" .
690 api_error('rss', new HTTPException\OKException('error_message'))
695 * Test the api_error() function with an Atom result.
698 * @runInSeparateProcess
700 public function testApiErrorWithAtom()
703 '<?xml version="1.0"?>' . "\n" .
704 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
705 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
706 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
707 ' <error>error_message</error>' . "\n" .
708 ' <code>200 OK</code>' . "\n" .
709 ' <request/>' . "\n" .
711 api_error('atom', new HTTPException\OKException('error_message'))
716 * Test the api_rss_extra() function.
720 public function testApiRssExtra()
722 $user_info = ['url' => 'user_url', 'lang' => 'en'];
723 $result = api_rss_extra($this->app, [], $user_info);
724 $this->assertEquals($user_info, $result['$user']);
725 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
726 $this->assertArrayHasKey('self', $result['$rss']);
727 $this->assertArrayHasKey('base', $result['$rss']);
728 $this->assertArrayHasKey('updated', $result['$rss']);
729 $this->assertArrayHasKey('atom_updated', $result['$rss']);
730 $this->assertArrayHasKey('language', $result['$rss']);
731 $this->assertArrayHasKey('logo', $result['$rss']);
735 * Test the api_rss_extra() function without any user info.
739 public function testApiRssExtraWithoutUserInfo()
741 $result = api_rss_extra($this->app, [], null);
742 $this->assertInternalType('array', $result['$user']);
743 $this->assertArrayHasKey('alternate', $result['$rss']);
744 $this->assertArrayHasKey('self', $result['$rss']);
745 $this->assertArrayHasKey('base', $result['$rss']);
746 $this->assertArrayHasKey('updated', $result['$rss']);
747 $this->assertArrayHasKey('atom_updated', $result['$rss']);
748 $this->assertArrayHasKey('language', $result['$rss']);
749 $this->assertArrayHasKey('logo', $result['$rss']);
753 * Test the api_unique_id_to_nurl() function.
757 public function testApiUniqueIdToNurl()
759 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
763 * Test the api_unique_id_to_nurl() function with a correct ID.
767 public function testApiUniqueIdToNurlWithCorrectId()
769 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
773 * Test the api_get_user() function.
777 public function testApiGetUser()
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 a Frio schema.
791 public function testApiGetUserWithFrioSchema()
793 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
794 $user = api_get_user($this->app);
795 $this->assertSelfUser($user);
796 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
797 $this->assertEquals('6fdbe8', $user['profile_link_color']);
798 $this->assertEquals('ededed', $user['profile_background_color']);
802 * Test the api_get_user() function with a custom Frio schema.
806 public function testApiGetUserWithCustomFrioSchema()
808 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
809 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
810 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
811 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
812 $user = api_get_user($this->app);
813 $this->assertSelfUser($user);
814 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
815 $this->assertEquals('123456', $user['profile_link_color']);
816 $this->assertEquals('123456', $user['profile_background_color']);
820 * Test the api_get_user() function with an empty Frio schema.
824 public function testApiGetUserWithEmptyFrioSchema()
826 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
827 $user = api_get_user($this->app);
828 $this->assertSelfUser($user);
829 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
830 $this->assertEquals('6fdbe8', $user['profile_link_color']);
831 $this->assertEquals('ededed', $user['profile_background_color']);
835 * Test the api_get_user() function with an user that is not allowed to use the API.
838 * @runInSeparateProcess
840 public function testApiGetUserWithoutApiUser()
842 $_SERVER['PHP_AUTH_USER'] = 'Test user';
843 $_SERVER['PHP_AUTH_PW'] = 'password';
844 $_SESSION['allow_api'] = false;
845 $this->assertFalse(api_get_user($this->app));
849 * Test the api_get_user() function with an user ID in a GET parameter.
853 public function testApiGetUserWithGetId()
855 $_GET['user_id'] = $this->otherUser['id'];
856 $this->assertOtherUser(api_get_user($this->app));
860 * Test the api_get_user() function with a wrong user ID in a GET parameter.
863 * @expectedException Friendica\Network\HTTPException\BadRequestException
865 public function testApiGetUserWithWrongGetId()
867 $_GET['user_id'] = $this->wrongUserId;
868 $this->assertOtherUser(api_get_user($this->app));
872 * Test the api_get_user() function with an user name in a GET parameter.
876 public function testApiGetUserWithGetName()
878 $_GET['screen_name'] = $this->selfUser['nick'];
879 $this->assertSelfUser(api_get_user($this->app));
883 * Test the api_get_user() function with a profile URL in a GET parameter.
887 public function testApiGetUserWithGetUrl()
889 $_GET['profileurl'] = $this->selfUser['nurl'];
890 $this->assertSelfUser(api_get_user($this->app));
894 * Test the api_get_user() function with an user ID in the API path.
898 public function testApiGetUserWithNumericCalledApi()
901 $called_api = ['api_path'];
902 $this->app->argv[1] = $this->otherUser['id'] . '.json';
903 $this->assertOtherUser(api_get_user($this->app));
907 * Test the api_get_user() function with the $called_api global variable.
911 public function testApiGetUserWithCalledApi()
914 $called_api = ['api', 'api_path'];
915 $this->assertSelfUser(api_get_user($this->app));
919 * Test the api_get_user() function with a valid user.
923 public function testApiGetUserWithCorrectUser()
925 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
929 * Test the api_get_user() function with a wrong user ID.
932 * @expectedException Friendica\Network\HTTPException\BadRequestException
934 public function testApiGetUserWithWrongUser()
936 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
940 * Test the api_get_user() function with a 0 user ID.
944 public function testApiGetUserWithZeroUser()
946 $this->assertSelfUser(api_get_user($this->app, 0));
950 * Test the api_item_get_user() function.
954 public function testApiItemGetUser()
956 $users = api_item_get_user($this->app, []);
957 $this->assertSelfUser($users[0]);
961 * Test the api_item_get_user() function with a different item parent.
965 public function testApiItemGetUserWithDifferentParent()
967 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
968 $this->assertSelfUser($users[0]);
969 $this->assertEquals($users[0], $users[1]);
973 * Test the api_walk_recursive() function.
977 public function testApiWalkRecursive()
985 // Should we test this with a callback that actually does something?
993 * Test the api_walk_recursive() function with an array.
997 public function testApiWalkRecursiveWithArray()
999 $array = [['item1'], ['item2']];
1000 $this->assertEquals(
1005 // Should we test this with a callback that actually does something?
1013 * Test the api_reformat_xml() function.
1017 public function testApiReformatXml()
1021 $this->assertTrue(api_reformat_xml($item, $key));
1022 $this->assertEquals('true', $item);
1026 * Test the api_reformat_xml() function with a statusnet_api key.
1030 public function testApiReformatXmlWithStatusnetKey()
1033 $key = 'statusnet_api';
1034 $this->assertTrue(api_reformat_xml($item, $key));
1035 $this->assertEquals('statusnet:api', $key);
1039 * Test the api_reformat_xml() function with a friendica_api key.
1043 public function testApiReformatXmlWithFriendicaKey()
1046 $key = 'friendica_api';
1047 $this->assertTrue(api_reformat_xml($item, $key));
1048 $this->assertEquals('friendica:api', $key);
1052 * Test the api_create_xml() function.
1056 public function testApiCreateXml()
1058 $this->assertEquals(
1059 '<?xml version="1.0"?>' . "\n" .
1060 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1061 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1062 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1063 ' <data>some_data</data>' . "\n" .
1064 '</root_element>' . "\n",
1065 api_create_xml(['data' => ['some_data']], 'root_element')
1070 * Test the api_create_xml() function without any XML namespace.
1074 public function testApiCreateXmlWithoutNamespaces()
1076 $this->assertEquals(
1077 '<?xml version="1.0"?>' . "\n" .
1079 ' <data>some_data</data>' . "\n" .
1081 api_create_xml(['data' => ['some_data']], 'ok')
1086 * Test the api_format_data() function.
1090 public function testApiFormatData()
1092 $data = ['some_data'];
1093 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1097 * Test the api_format_data() function with an XML result.
1101 public function testApiFormatDataWithXml()
1103 $this->assertEquals(
1104 '<?xml version="1.0"?>' . "\n" .
1105 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1106 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1107 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1108 ' <data>some_data</data>' . "\n" .
1109 '</root_element>' . "\n",
1110 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1115 * Test the api_account_verify_credentials() function.
1119 public function testApiAccountVerifyCredentials()
1121 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1125 * Test the api_account_verify_credentials() function without an authenticated user.
1128 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1130 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1132 $_SESSION['authenticated'] = false;
1133 api_account_verify_credentials('json');
1137 * Test the requestdata() function.
1141 public function testRequestdata()
1143 $this->assertNull(requestdata('variable_name'));
1147 * Test the requestdata() function with a POST parameter.
1151 public function testRequestdataWithPost()
1153 $_POST['variable_name'] = 'variable_value';
1154 $this->assertEquals('variable_value', requestdata('variable_name'));
1158 * Test the requestdata() function with a GET parameter.
1162 public function testRequestdataWithGet()
1164 $_GET['variable_name'] = 'variable_value';
1165 $this->assertEquals('variable_value', requestdata('variable_name'));
1169 * Test the api_statuses_mediap() function.
1173 public function testApiStatusesMediap()
1175 $this->app->argc = 2;
1183 'tmp_name' => $this->getTempImage(),
1184 'name' => 'spacer.png',
1185 'type' => 'image/png'
1188 $_GET['status'] = '<b>Status content</b>';
1190 $result = api_statuses_mediap('json');
1191 $this->assertStatus($result['status']);
1195 * Test the api_statuses_mediap() function without an authenticated user.
1198 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1200 public function testApiStatusesMediapWithoutAuthenticatedUser()
1202 $_SESSION['authenticated'] = false;
1203 api_statuses_mediap('json');
1207 * Test the api_statuses_update() function.
1211 public function testApiStatusesUpdate()
1213 $_GET['status'] = 'Status content #friendica';
1214 $_GET['in_reply_to_status_id'] = -1;
1223 'tmp_name' => $this->getTempImage(),
1224 'name' => 'spacer.png',
1225 'type' => 'image/png'
1229 $result = api_statuses_update('json');
1230 $this->assertStatus($result['status']);
1234 * Test the api_statuses_update() function with an HTML status.
1238 public function testApiStatusesUpdateWithHtml()
1240 $_GET['htmlstatus'] = '<b>Status content</b>';
1242 $result = api_statuses_update('json');
1243 $this->assertStatus($result['status']);
1247 * Test the api_statuses_update() function without an authenticated user.
1250 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1252 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1254 $_SESSION['authenticated'] = false;
1255 api_statuses_update('json');
1259 * Test the api_statuses_update() function with a parent status.
1263 public function testApiStatusesUpdateWithParent()
1265 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1269 * Test the api_statuses_update() function with a media_ids parameter.
1273 public function testApiStatusesUpdateWithMediaIds()
1275 $this->markTestIncomplete();
1279 * Test the api_statuses_update() function with the throttle limit reached.
1283 public function testApiStatusesUpdateWithDayThrottleReached()
1285 $this->markTestIncomplete();
1289 * Test the api_media_upload() function.
1292 * @expectedException Friendica\Network\HTTPException\BadRequestException
1294 public function testApiMediaUpload()
1300 * Test the api_media_upload() function without an authenticated user.
1303 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1305 public function testApiMediaUploadWithoutAuthenticatedUser()
1307 $_SESSION['authenticated'] = false;
1312 * Test the api_media_upload() function with an invalid uploaded media.
1315 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1317 public function testApiMediaUploadWithMedia()
1322 'tmp_name' => 'tmp_name'
1329 * Test the api_media_upload() function with an valid uploaded media.
1333 public function testApiMediaUploadWithValidMedia()
1341 'tmp_name' => $this->getTempImage(),
1342 'name' => 'spacer.png',
1343 'type' => 'image/png'
1349 $result = api_media_upload();
1350 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1351 $this->assertEquals(1, $result['media']['image']['w']);
1352 $this->assertEquals(1, $result['media']['image']['h']);
1353 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1357 * Test the api_status_show() function.
1359 public function testApiStatusShowWithJson()
1361 $result = api_status_show('json', 1);
1362 $this->assertStatus($result['status']);
1366 * Test the api_status_show() function with an XML result.
1368 public function testApiStatusShowWithXml()
1370 $result = api_status_show('xml', 1);
1371 $this->assertXml($result, 'statuses');
1375 * Test the api_get_last_status() function
1377 public function testApiGetLastStatus()
1379 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1381 $this->assertNotNull($item);
1385 * Test the api_users_show() function.
1389 public function testApiUsersShow()
1391 $result = api_users_show('json');
1392 // We can't use assertSelfUser() here because the user object is missing some properties.
1393 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1394 $this->assertEquals('DFRN', $result['user']['location']);
1395 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1396 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1397 $this->assertEquals('dfrn', $result['user']['network']);
1398 $this->assertTrue($result['user']['verified']);
1402 * Test the api_users_show() function with an XML result.
1406 public function testApiUsersShowWithXml()
1408 $result = api_users_show('xml');
1409 $this->assertXml($result, 'statuses');
1413 * Test the api_users_search() function.
1417 public function testApiUsersSearch()
1419 $_GET['q'] = 'othercontact';
1420 $result = api_users_search('json');
1421 $this->assertOtherUser($result['users'][0]);
1425 * Test the api_users_search() function with an XML result.
1429 public function testApiUsersSearchWithXml()
1431 $_GET['q'] = 'othercontact';
1432 $result = api_users_search('xml');
1433 $this->assertXml($result, 'users');
1437 * Test the api_users_search() function without a GET q parameter.
1440 * @expectedException Friendica\Network\HTTPException\BadRequestException
1442 public function testApiUsersSearchWithoutQuery()
1444 api_users_search('json');
1448 * Test the api_users_lookup() function.
1451 * @expectedException Friendica\Network\HTTPException\NotFoundException
1453 public function testApiUsersLookup()
1455 api_users_lookup('json');
1459 * Test the api_users_lookup() function with an user ID.
1463 public function testApiUsersLookupWithUserId()
1465 $_REQUEST['user_id'] = $this->otherUser['id'];
1466 $result = api_users_lookup('json');
1467 $this->assertOtherUser($result['users'][0]);
1471 * Test the api_search() function.
1475 public function testApiSearch()
1477 $_REQUEST['q'] = 'reply';
1478 $_REQUEST['max_id'] = 10;
1479 $result = api_search('json');
1480 foreach ($result['status'] as $status) {
1481 $this->assertStatus($status);
1482 $this->assertContains('reply', $status['text'], null, true);
1487 * Test the api_search() function a count parameter.
1491 public function testApiSearchWithCount()
1493 $_REQUEST['q'] = 'reply';
1494 $_REQUEST['count'] = 20;
1495 $result = api_search('json');
1496 foreach ($result['status'] as $status) {
1497 $this->assertStatus($status);
1498 $this->assertContains('reply', $status['text'], null, true);
1503 * Test the api_search() function with an rpp parameter.
1507 public function testApiSearchWithRpp()
1509 $_REQUEST['q'] = 'reply';
1510 $_REQUEST['rpp'] = 20;
1511 $result = api_search('json');
1512 foreach ($result['status'] as $status) {
1513 $this->assertStatus($status);
1514 $this->assertContains('reply', $status['text'], null, true);
1519 * Test the api_search() function with an q parameter contains hashtag.
1523 public function testApiSearchWithHashtag()
1525 $_REQUEST['q'] = '%23friendica';
1526 $result = api_search('json');
1527 foreach ($result['status'] as $status) {
1528 $this->assertStatus($status);
1529 $this->assertContains('#friendica', $status['text'], null, true);
1534 * Test the api_search() function with an exclude_replies parameter.
1538 public function testApiSearchWithExcludeReplies()
1540 $_REQUEST['max_id'] = 10;
1541 $_REQUEST['exclude_replies'] = true;
1542 $_REQUEST['q'] = 'friendica';
1543 $result = api_search('json');
1544 foreach ($result['status'] as $status) {
1545 $this->assertStatus($status);
1550 * Test the api_search() function without an authenticated user.
1553 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1555 public function testApiSearchWithUnallowedUser()
1557 $_SESSION['allow_api'] = false;
1558 $_GET['screen_name'] = $this->selfUser['nick'];
1563 * Test the api_search() function without any GET query parameter.
1566 * @expectedException Friendica\Network\HTTPException\BadRequestException
1568 public function testApiSearchWithoutQuery()
1574 * Test the api_statuses_home_timeline() function.
1578 public function testApiStatusesHomeTimeline()
1580 $_REQUEST['max_id'] = 10;
1581 $_REQUEST['exclude_replies'] = true;
1582 $_REQUEST['conversation_id'] = 1;
1583 $result = api_statuses_home_timeline('json');
1584 $this->assertNotEmpty($result['status']);
1585 foreach ($result['status'] as $status) {
1586 $this->assertStatus($status);
1591 * Test the api_statuses_home_timeline() function with a negative page parameter.
1595 public function testApiStatusesHomeTimelineWithNegativePage()
1597 $_REQUEST['page'] = -2;
1598 $result = api_statuses_home_timeline('json');
1599 $this->assertNotEmpty($result['status']);
1600 foreach ($result['status'] as $status) {
1601 $this->assertStatus($status);
1606 * Test the api_statuses_home_timeline() with an unallowed user.
1609 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1611 public function testApiStatusesHomeTimelineWithUnallowedUser()
1613 $_SESSION['allow_api'] = false;
1614 $_GET['screen_name'] = $this->selfUser['nick'];
1615 api_statuses_home_timeline('json');
1619 * Test the api_statuses_home_timeline() function with an RSS result.
1623 public function testApiStatusesHomeTimelineWithRss()
1625 $result = api_statuses_home_timeline('rss');
1626 $this->assertXml($result, 'statuses');
1630 * Test the api_statuses_public_timeline() function.
1634 public function testApiStatusesPublicTimeline()
1636 $_REQUEST['max_id'] = 10;
1637 $_REQUEST['conversation_id'] = 1;
1638 $result = api_statuses_public_timeline('json');
1639 $this->assertNotEmpty($result['status']);
1640 foreach ($result['status'] as $status) {
1641 $this->assertStatus($status);
1646 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1650 public function testApiStatusesPublicTimelineWithExcludeReplies()
1652 $_REQUEST['max_id'] = 10;
1653 $_REQUEST['exclude_replies'] = true;
1654 $result = api_statuses_public_timeline('json');
1655 $this->assertNotEmpty($result['status']);
1656 foreach ($result['status'] as $status) {
1657 $this->assertStatus($status);
1662 * Test the api_statuses_public_timeline() function with a negative page parameter.
1666 public function testApiStatusesPublicTimelineWithNegativePage()
1668 $_REQUEST['page'] = -2;
1669 $result = api_statuses_public_timeline('json');
1670 $this->assertNotEmpty($result['status']);
1671 foreach ($result['status'] as $status) {
1672 $this->assertStatus($status);
1677 * Test the api_statuses_public_timeline() function with an unallowed user.
1680 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1682 public function testApiStatusesPublicTimelineWithUnallowedUser()
1684 $_SESSION['allow_api'] = false;
1685 $_GET['screen_name'] = $this->selfUser['nick'];
1686 api_statuses_public_timeline('json');
1690 * Test the api_statuses_public_timeline() function with an RSS result.
1694 public function testApiStatusesPublicTimelineWithRss()
1696 $result = api_statuses_public_timeline('rss');
1697 $this->assertXml($result, 'statuses');
1701 * Test the api_statuses_networkpublic_timeline() function.
1705 public function testApiStatusesNetworkpublicTimeline()
1707 $_REQUEST['max_id'] = 10;
1708 $result = api_statuses_networkpublic_timeline('json');
1709 $this->assertNotEmpty($result['status']);
1710 foreach ($result['status'] as $status) {
1711 $this->assertStatus($status);
1716 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1720 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1722 $_REQUEST['page'] = -2;
1723 $result = api_statuses_networkpublic_timeline('json');
1724 $this->assertNotEmpty($result['status']);
1725 foreach ($result['status'] as $status) {
1726 $this->assertStatus($status);
1731 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1734 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1736 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1738 $_SESSION['allow_api'] = false;
1739 $_GET['screen_name'] = $this->selfUser['nick'];
1740 api_statuses_networkpublic_timeline('json');
1744 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1748 public function testApiStatusesNetworkpublicTimelineWithRss()
1750 $result = api_statuses_networkpublic_timeline('rss');
1751 $this->assertXml($result, 'statuses');
1755 * Test the api_statuses_show() function.
1758 * @expectedException Friendica\Network\HTTPException\BadRequestException
1760 public function testApiStatusesShow()
1762 api_statuses_show('json');
1766 * Test the api_statuses_show() function with an ID.
1770 public function testApiStatusesShowWithId()
1772 $this->app->argv[3] = 1;
1773 $result = api_statuses_show('json');
1774 $this->assertStatus($result['status']);
1778 * Test the api_statuses_show() function with the conversation parameter.
1782 public function testApiStatusesShowWithConversation()
1784 $this->app->argv[3] = 1;
1785 $_REQUEST['conversation'] = 1;
1786 $result = api_statuses_show('json');
1787 $this->assertNotEmpty($result['status']);
1788 foreach ($result['status'] as $status) {
1789 $this->assertStatus($status);
1794 * Test the api_statuses_show() function with an unallowed user.
1797 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1799 public function testApiStatusesShowWithUnallowedUser()
1801 $_SESSION['allow_api'] = false;
1802 $_GET['screen_name'] = $this->selfUser['nick'];
1803 api_statuses_show('json');
1807 * Test the api_conversation_show() function.
1810 * @expectedException Friendica\Network\HTTPException\BadRequestException
1812 public function testApiConversationShow()
1814 api_conversation_show('json');
1818 * Test the api_conversation_show() function with an ID.
1822 public function testApiConversationShowWithId()
1824 $this->app->argv[3] = 1;
1825 $_REQUEST['max_id'] = 10;
1826 $_REQUEST['page'] = -2;
1827 $result = api_conversation_show('json');
1828 $this->assertNotEmpty($result['status']);
1829 foreach ($result['status'] as $status) {
1830 $this->assertStatus($status);
1835 * Test the api_conversation_show() function with an unallowed user.
1838 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1840 public function testApiConversationShowWithUnallowedUser()
1842 $_SESSION['allow_api'] = false;
1843 $_GET['screen_name'] = $this->selfUser['nick'];
1844 api_conversation_show('json');
1848 * Test the api_statuses_repeat() function.
1851 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1853 public function testApiStatusesRepeat()
1855 api_statuses_repeat('json');
1859 * Test the api_statuses_repeat() function without an authenticated user.
1862 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1864 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1866 $_SESSION['authenticated'] = false;
1867 api_statuses_repeat('json');
1871 * Test the api_statuses_repeat() function with an ID.
1875 public function testApiStatusesRepeatWithId()
1877 $this->app->argv[3] = 1;
1878 $result = api_statuses_repeat('json');
1879 $this->assertStatus($result['status']);
1881 // Also test with a shared status
1882 $this->app->argv[3] = 5;
1883 $result = api_statuses_repeat('json');
1884 $this->assertStatus($result['status']);
1888 * Test the api_statuses_destroy() function.
1891 * @expectedException Friendica\Network\HTTPException\BadRequestException
1893 public function testApiStatusesDestroy()
1895 api_statuses_destroy('json');
1899 * Test the api_statuses_destroy() function without an authenticated user.
1902 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1904 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1906 $_SESSION['authenticated'] = false;
1907 api_statuses_destroy('json');
1911 * Test the api_statuses_destroy() function with an ID.
1915 public function testApiStatusesDestroyWithId()
1917 $this->app->argv[3] = 1;
1918 $result = api_statuses_destroy('json');
1919 $this->assertStatus($result['status']);
1923 * Test the api_statuses_mentions() function.
1927 public function testApiStatusesMentions()
1929 $this->app->user = ['nickname' => $this->selfUser['nick']];
1930 $_REQUEST['max_id'] = 10;
1931 $result = api_statuses_mentions('json');
1932 $this->assertEmpty($result['status']);
1933 // We should test with mentions in the database.
1937 * Test the api_statuses_mentions() function with a negative page parameter.
1941 public function testApiStatusesMentionsWithNegativePage()
1943 $_REQUEST['page'] = -2;
1944 $result = api_statuses_mentions('json');
1945 $this->assertEmpty($result['status']);
1949 * Test the api_statuses_mentions() function with an unallowed user.
1952 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1954 public function testApiStatusesMentionsWithUnallowedUser()
1956 $_SESSION['allow_api'] = false;
1957 $_GET['screen_name'] = $this->selfUser['nick'];
1958 api_statuses_mentions('json');
1962 * Test the api_statuses_mentions() function with an RSS result.
1966 public function testApiStatusesMentionsWithRss()
1968 $result = api_statuses_mentions('rss');
1969 $this->assertXml($result, 'statuses');
1973 * Test the api_statuses_user_timeline() function.
1977 public function testApiStatusesUserTimeline()
1979 $_REQUEST['max_id'] = 10;
1980 $_REQUEST['exclude_replies'] = true;
1981 $_REQUEST['conversation_id'] = 1;
1982 $result = api_statuses_user_timeline('json');
1983 $this->assertNotEmpty($result['status']);
1984 foreach ($result['status'] as $status) {
1985 $this->assertStatus($status);
1990 * Test the api_statuses_user_timeline() function with a negative page parameter.
1994 public function testApiStatusesUserTimelineWithNegativePage()
1996 $_REQUEST['page'] = -2;
1997 $result = api_statuses_user_timeline('json');
1998 $this->assertNotEmpty($result['status']);
1999 foreach ($result['status'] as $status) {
2000 $this->assertStatus($status);
2005 * Test the api_statuses_user_timeline() function with an RSS result.
2009 public function testApiStatusesUserTimelineWithRss()
2011 $result = api_statuses_user_timeline('rss');
2012 $this->assertXml($result, 'statuses');
2016 * Test the api_statuses_user_timeline() function with an unallowed user.
2019 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2021 public function testApiStatusesUserTimelineWithUnallowedUser()
2023 $_SESSION['allow_api'] = false;
2024 $_GET['screen_name'] = $this->selfUser['nick'];
2025 api_statuses_user_timeline('json');
2029 * Test the api_favorites_create_destroy() function.
2032 * @expectedException Friendica\Network\HTTPException\BadRequestException
2034 public function testApiFavoritesCreateDestroy()
2036 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2037 $this->app->argc = count($this->app->argv);
2038 api_favorites_create_destroy('json');
2042 * Test the api_favorites_create_destroy() function with an invalid ID.
2045 * @expectedException Friendica\Network\HTTPException\BadRequestException
2047 public function testApiFavoritesCreateDestroyWithInvalidId()
2049 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2050 $this->app->argc = count($this->app->argv);
2051 api_favorites_create_destroy('json');
2055 * Test the api_favorites_create_destroy() function with an invalid action.
2058 * @expectedException Friendica\Network\HTTPException\BadRequestException
2060 public function testApiFavoritesCreateDestroyWithInvalidAction()
2062 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2063 $this->app->argc = count($this->app->argv);
2064 $_REQUEST['id'] = 1;
2065 api_favorites_create_destroy('json');
2069 * Test the api_favorites_create_destroy() function with the create action.
2073 public function testApiFavoritesCreateDestroyWithCreateAction()
2075 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2076 $this->app->argc = count($this->app->argv);
2077 $_REQUEST['id'] = 3;
2078 $result = api_favorites_create_destroy('json');
2079 $this->assertStatus($result['status']);
2083 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2087 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2089 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2090 $this->app->argc = count($this->app->argv);
2091 $_REQUEST['id'] = 3;
2092 $result = api_favorites_create_destroy('rss');
2093 $this->assertXml($result, 'status');
2097 * Test the api_favorites_create_destroy() function with the destroy action.
2101 public function testApiFavoritesCreateDestroyWithDestroyAction()
2103 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2104 $this->app->argc = count($this->app->argv);
2105 $_REQUEST['id'] = 3;
2106 $result = api_favorites_create_destroy('json');
2107 $this->assertStatus($result['status']);
2111 * Test the api_favorites_create_destroy() function without an authenticated user.
2114 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2116 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2118 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2119 $this->app->argc = count($this->app->argv);
2120 $_SESSION['authenticated'] = false;
2121 api_favorites_create_destroy('json');
2125 * Test the api_favorites() function.
2129 public function testApiFavorites()
2131 $_REQUEST['page'] = -1;
2132 $_REQUEST['max_id'] = 10;
2133 $result = api_favorites('json');
2134 foreach ($result['status'] as $status) {
2135 $this->assertStatus($status);
2140 * Test the api_favorites() function with an RSS result.
2144 public function testApiFavoritesWithRss()
2146 $result = api_favorites('rss');
2147 $this->assertXml($result, 'statuses');
2151 * Test the api_favorites() function with an unallowed user.
2154 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2156 public function testApiFavoritesWithUnallowedUser()
2158 $_SESSION['allow_api'] = false;
2159 $_GET['screen_name'] = $this->selfUser['nick'];
2160 api_favorites('json');
2164 * Test the api_format_messages() function.
2168 public function testApiFormatMessages()
2170 $result = api_format_messages(
2171 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2172 ['id' => 2, 'screen_name' => 'recipient_name'],
2173 ['id' => 3, 'screen_name' => 'sender_name']
2175 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2176 $this->assertEquals(1, $result['id']);
2177 $this->assertEquals(2, $result['recipient_id']);
2178 $this->assertEquals(3, $result['sender_id']);
2179 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2180 $this->assertEquals('sender_name', $result['sender_screen_name']);
2184 * Test the api_format_messages() function with HTML.
2188 public function testApiFormatMessagesWithHtmlText()
2190 $_GET['getText'] = 'html';
2191 $result = api_format_messages(
2192 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2193 ['id' => 2, 'screen_name' => 'recipient_name'],
2194 ['id' => 3, 'screen_name' => 'sender_name']
2196 $this->assertEquals('item_title', $result['title']);
2197 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2201 * Test the api_format_messages() function with plain text.
2205 public function testApiFormatMessagesWithPlainText()
2207 $_GET['getText'] = 'plain';
2208 $result = api_format_messages(
2209 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2210 ['id' => 2, 'screen_name' => 'recipient_name'],
2211 ['id' => 3, 'screen_name' => 'sender_name']
2213 $this->assertEquals('item_title', $result['title']);
2214 $this->assertEquals('item_body', $result['text']);
2218 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2222 public function testApiFormatMessagesWithoutUserObjects()
2224 $_GET['getUserObjects'] = 'false';
2225 $result = api_format_messages(
2226 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2227 ['id' => 2, 'screen_name' => 'recipient_name'],
2228 ['id' => 3, 'screen_name' => 'sender_name']
2230 $this->assertTrue(!isset($result['sender']));
2231 $this->assertTrue(!isset($result['recipient']));
2235 * Test the api_convert_item() function.
2239 public function testApiConvertItem()
2241 $result = api_convert_item(
2243 'network' => 'feed',
2244 'title' => 'item_title',
2245 // We need a long string to test that it is correctly cut
2246 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2247 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2248 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2249 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2250 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2251 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2252 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2253 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2254 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2255 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2256 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2257 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2258 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2259 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2260 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2261 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2262 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2263 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2264 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2265 'repellat officia illum quos impedit quam iste esse unde qui ' .
2266 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2267 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2268 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2269 'plink' => 'item_plink'
2272 $this->assertStringStartsWith('item_title', $result['text']);
2273 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2277 * Test the api_convert_item() function with an empty item body.
2281 public function testApiConvertItemWithoutBody()
2283 $result = api_convert_item(
2285 'network' => 'feed',
2286 'title' => 'item_title',
2288 'plink' => 'item_plink'
2291 $this->assertEquals('item_title', $result['text']);
2292 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2296 * Test the api_convert_item() function with the title in the body.
2300 public function testApiConvertItemWithTitleInBody()
2302 $result = api_convert_item(
2304 'title' => 'item_title',
2305 'body' => 'item_title item_body'
2308 $this->assertEquals('item_title item_body', $result['text']);
2309 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2313 * Test the api_get_attachments() function.
2317 public function testApiGetAttachments()
2320 $this->assertEmpty(api_get_attachments($body));
2324 * Test the api_get_attachments() function with an img tag.
2328 public function testApiGetAttachmentsWithImage()
2330 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2331 $this->assertInternalType('array', api_get_attachments($body));
2335 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2339 public function testApiGetAttachmentsWithImageAndAndStatus()
2341 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2342 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2343 $this->assertInternalType('array', api_get_attachments($body));
2347 * Test the api_get_entitities() function.
2351 public function testApiGetEntitities()
2354 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2358 * Test the api_get_entitities() function with the include_entities parameter.
2362 public function testApiGetEntititiesWithIncludeEntities()
2364 $_REQUEST['include_entities'] = 'true';
2366 $result = api_get_entitities($text, 'bbcode');
2367 $this->assertInternalType('array', $result['hashtags']);
2368 $this->assertInternalType('array', $result['symbols']);
2369 $this->assertInternalType('array', $result['urls']);
2370 $this->assertInternalType('array', $result['user_mentions']);
2374 * Test the api_format_items_embeded_images() function.
2378 public function testApiFormatItemsEmbededImages()
2380 $this->assertEquals(
2381 'text ' . System::baseUrl() . '/display/item_guid',
2382 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2387 * Test the api_contactlink_to_array() function.
2391 public function testApiContactlinkToArray()
2393 $this->assertEquals(
2398 api_contactlink_to_array('text')
2403 * Test the api_contactlink_to_array() function with an URL.
2407 public function testApiContactlinkToArrayWithUrl()
2409 $this->assertEquals(
2411 'name' => ['link_text'],
2414 api_contactlink_to_array('text <a href="url">link_text</a>')
2419 * Test the api_format_items_activities() function.
2423 public function testApiFormatItemsActivities()
2425 $item = ['uid' => 0, 'uri' => ''];
2426 $result = api_format_items_activities($item);
2427 $this->assertArrayHasKey('like', $result);
2428 $this->assertArrayHasKey('dislike', $result);
2429 $this->assertArrayHasKey('attendyes', $result);
2430 $this->assertArrayHasKey('attendno', $result);
2431 $this->assertArrayHasKey('attendmaybe', $result);
2435 * Test the api_format_items_activities() function with an XML result.
2439 public function testApiFormatItemsActivitiesWithXml()
2441 $item = ['uid' => 0, 'uri' => ''];
2442 $result = api_format_items_activities($item, 'xml');
2443 $this->assertArrayHasKey('friendica:like', $result);
2444 $this->assertArrayHasKey('friendica:dislike', $result);
2445 $this->assertArrayHasKey('friendica:attendyes', $result);
2446 $this->assertArrayHasKey('friendica:attendno', $result);
2447 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2451 * Test the api_format_items_profiles() function.
2455 public function testApiFormatItemsProfiles()
2458 'id' => 'profile_id',
2459 'profile-name' => 'profile_name',
2460 'is-default' => true,
2461 'hide-friends' => true,
2462 'photo' => 'profile_photo',
2463 'thumb' => 'profile_thumb',
2465 'net-publish' => true,
2466 'pdesc' => 'description',
2467 'dob' => 'date_of_birth',
2468 'address' => 'address',
2469 'locality' => 'city',
2470 'region' => 'region',
2471 'postal-code' => 'postal_code',
2472 'country-name' => 'country',
2473 'hometown' => 'hometown',
2474 'gender' => 'gender',
2475 'marital' => 'marital',
2476 'with' => 'marital_with',
2477 'howlong' => 'marital_since',
2478 'sexual' => 'sexual',
2479 'politic' => 'politic',
2480 'religion' => 'religion',
2481 'pub_keywords' => 'public_keywords',
2482 'prv_keywords' => 'private_keywords',
2485 'dislikes' => 'dislikes',
2491 'interest' => 'interest',
2492 'romance' => 'romance',
2494 'education' => 'education',
2495 'contact' => 'social_networks',
2496 'homepage' => 'homepage'
2498 $result = api_format_items_profiles($profile_row);
2499 $this->assertEquals(
2501 'profile_id' => 'profile_id',
2502 'profile_name' => 'profile_name',
2503 'is_default' => true,
2504 'hide_friends' => true,
2505 'profile_photo' => 'profile_photo',
2506 'profile_thumb' => 'profile_thumb',
2508 'net_publish' => true,
2509 'description' => 'description',
2510 'date_of_birth' => 'date_of_birth',
2511 'address' => 'address',
2513 'region' => 'region',
2514 'postal_code' => 'postal_code',
2515 'country' => 'country',
2516 'hometown' => 'hometown',
2517 'gender' => 'gender',
2518 'marital' => 'marital',
2519 'marital_with' => 'marital_with',
2520 'marital_since' => 'marital_since',
2521 'sexual' => 'sexual',
2522 'politic' => 'politic',
2523 'religion' => 'religion',
2524 'public_keywords' => 'public_keywords',
2525 'private_keywords' => 'private_keywords',
2528 'dislikes' => 'dislikes',
2534 'interest' => 'interest',
2535 'romance' => 'romance',
2537 'education' => 'education',
2538 'social_networks' => 'social_networks',
2539 'homepage' => 'homepage',
2547 * Test the api_format_items() function.
2551 public function testApiFormatItems()
2555 'item_network' => 'item_network',
2561 'author-network' => Protocol::DFRN,
2562 'author-link' => 'http://localhost/profile/othercontact',
2566 $result = api_format_items($items, ['id' => 0], true);
2567 foreach ($result as $status) {
2568 $this->assertStatus($status);
2573 * Test the api_format_items() function with an XML result.
2577 public function testApiFormatItemsWithXml()
2585 'author-network' => Protocol::DFRN,
2586 'author-link' => 'http://localhost/profile/othercontact',
2590 $result = api_format_items($items, ['id' => 0], true, 'xml');
2591 foreach ($result as $status) {
2592 $this->assertStatus($status);
2597 * Test the api_format_items() function.
2601 public function testApiAccountRateLimitStatus()
2603 $result = api_account_rate_limit_status('json');
2604 $this->assertEquals(150, $result['hash']['remaining_hits']);
2605 $this->assertEquals(150, $result['hash']['hourly_limit']);
2606 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2610 * Test the api_format_items() function with an XML result.
2614 public function testApiAccountRateLimitStatusWithXml()
2616 $result = api_account_rate_limit_status('xml');
2617 $this->assertXml($result, 'hash');
2621 * Test the api_help_test() function.
2625 public function testApiHelpTest()
2627 $result = api_help_test('json');
2628 $this->assertEquals(['ok' => 'ok'], $result);
2632 * Test the api_help_test() function with an XML result.
2636 public function testApiHelpTestWithXml()
2638 $result = api_help_test('xml');
2639 $this->assertXml($result, 'ok');
2643 * Test the api_lists_list() function.
2647 public function testApiListsList()
2649 $result = api_lists_list('json');
2650 $this->assertEquals(['lists_list' => []], $result);
2654 * Test the api_lists_ownerships() function.
2658 public function testApiListsOwnerships()
2660 $result = api_lists_ownerships('json');
2661 foreach ($result['lists']['lists'] as $list) {
2662 $this->assertList($list);
2667 * Test the api_lists_ownerships() function without an authenticated user.
2670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2672 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2674 $_SESSION['authenticated'] = false;
2675 api_lists_ownerships('json');
2679 * Test the api_lists_statuses() function.
2681 * @expectedException Friendica\Network\HTTPException\BadRequestException
2684 public function testApiListsStatuses()
2686 api_lists_statuses('json');
2690 * Test the api_lists_statuses() function with a list ID.
2694 public function testApiListsStatusesWithListId()
2696 $_REQUEST['list_id'] = 1;
2697 $_REQUEST['page'] = -1;
2698 $_REQUEST['max_id'] = 10;
2699 $result = api_lists_statuses('json');
2700 foreach ($result['status'] as $status) {
2701 $this->assertStatus($status);
2706 * Test the api_lists_statuses() function with a list ID and a RSS result.
2710 public function testApiListsStatusesWithListIdAndRss()
2712 $_REQUEST['list_id'] = 1;
2713 $result = api_lists_statuses('rss');
2714 $this->assertXml($result, 'statuses');
2718 * Test the api_lists_statuses() function with an unallowed user.
2721 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2723 public function testApiListsStatusesWithUnallowedUser()
2725 $_SESSION['allow_api'] = false;
2726 $_GET['screen_name'] = $this->selfUser['nick'];
2727 api_lists_statuses('json');
2731 * Test the api_statuses_f() function.
2735 public function testApiStatusesFWithFriends()
2738 $result = api_statuses_f('friends');
2739 $this->assertArrayHasKey('user', $result);
2743 * Test the api_statuses_f() function.
2747 public function testApiStatusesFWithFollowers()
2749 $result = api_statuses_f('followers');
2750 $this->assertArrayHasKey('user', $result);
2754 * Test the api_statuses_f() function.
2758 public function testApiStatusesFWithBlocks()
2760 $result = api_statuses_f('blocks');
2761 $this->assertArrayHasKey('user', $result);
2765 * Test the api_statuses_f() function.
2769 public function testApiStatusesFWithIncoming()
2771 $result = api_statuses_f('incoming');
2772 $this->assertArrayHasKey('user', $result);
2776 * Test the api_statuses_f() function an undefined cursor GET variable.
2780 public function testApiStatusesFWithUndefinedCursor()
2782 $_GET['cursor'] = 'undefined';
2783 $this->assertFalse(api_statuses_f('friends'));
2787 * Test the api_statuses_friends() function.
2791 public function testApiStatusesFriends()
2793 $result = api_statuses_friends('json');
2794 $this->assertArrayHasKey('user', $result);
2798 * Test the api_statuses_friends() function an undefined cursor GET variable.
2802 public function testApiStatusesFriendsWithUndefinedCursor()
2804 $_GET['cursor'] = 'undefined';
2805 $this->assertFalse(api_statuses_friends('json'));
2809 * Test the api_statuses_followers() function.
2813 public function testApiStatusesFollowers()
2815 $result = api_statuses_followers('json');
2816 $this->assertArrayHasKey('user', $result);
2820 * Test the api_statuses_followers() function an undefined cursor GET variable.
2824 public function testApiStatusesFollowersWithUndefinedCursor()
2826 $_GET['cursor'] = 'undefined';
2827 $this->assertFalse(api_statuses_followers('json'));
2831 * Test the api_blocks_list() function.
2835 public function testApiBlocksList()
2837 $result = api_blocks_list('json');
2838 $this->assertArrayHasKey('user', $result);
2842 * Test the api_blocks_list() function an undefined cursor GET variable.
2846 public function testApiBlocksListWithUndefinedCursor()
2848 $_GET['cursor'] = 'undefined';
2849 $this->assertFalse(api_blocks_list('json'));
2853 * Test the api_friendships_incoming() function.
2857 public function testApiFriendshipsIncoming()
2859 $result = api_friendships_incoming('json');
2860 $this->assertArrayHasKey('id', $result);
2864 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2868 public function testApiFriendshipsIncomingWithUndefinedCursor()
2870 $_GET['cursor'] = 'undefined';
2871 $this->assertFalse(api_friendships_incoming('json'));
2875 * Test the api_statusnet_config() function.
2879 public function testApiStatusnetConfig()
2881 $result = api_statusnet_config('json');
2882 $this->assertEquals('localhost', $result['config']['site']['server']);
2883 $this->assertEquals('default', $result['config']['site']['theme']);
2884 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2885 $this->assertTrue($result['config']['site']['fancy']);
2886 $this->assertEquals('en', $result['config']['site']['language']);
2887 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2888 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2889 $this->assertEquals('false', $result['config']['site']['private']);
2890 $this->assertEquals('false', $result['config']['site']['ssl']);
2891 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2895 * Test the api_statusnet_version() function.
2899 public function testApiStatusnetVersion()
2901 $result = api_statusnet_version('json');
2902 $this->assertEquals('0.9.7', $result['version']);
2906 * Test the api_ff_ids() function.
2910 public function testApiFfIds()
2912 $result = api_ff_ids('json');
2913 $this->assertNull($result);
2917 * Test the api_ff_ids() function with a result.
2921 public function testApiFfIdsWithResult()
2923 $this->markTestIncomplete();
2927 * Test the api_ff_ids() function without an authenticated user.
2930 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2932 public function testApiFfIdsWithoutAuthenticatedUser()
2934 $_SESSION['authenticated'] = false;
2939 * Test the api_friends_ids() function.
2943 public function testApiFriendsIds()
2945 $result = api_friends_ids('json');
2946 $this->assertNull($result);
2950 * Test the api_followers_ids() function.
2954 public function testApiFollowersIds()
2956 $result = api_followers_ids('json');
2957 $this->assertNull($result);
2961 * Test the api_direct_messages_new() function.
2965 public function testApiDirectMessagesNew()
2967 $result = api_direct_messages_new('json');
2968 $this->assertNull($result);
2972 * Test the api_direct_messages_new() function without an authenticated user.
2975 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2977 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2979 $_SESSION['authenticated'] = false;
2980 api_direct_messages_new('json');
2984 * Test the api_direct_messages_new() function with an user ID.
2988 public function testApiDirectMessagesNewWithUserId()
2990 $_POST['text'] = 'message_text';
2991 $_POST['user_id'] = $this->otherUser['id'];
2992 $result = api_direct_messages_new('json');
2993 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2997 * Test the api_direct_messages_new() function with a screen name.
3001 public function testApiDirectMessagesNewWithScreenName()
3003 $_POST['text'] = 'message_text';
3004 $_POST['screen_name'] = $this->friendUser['nick'];
3005 $result = api_direct_messages_new('json');
3006 $this->assertContains('message_text', $result['direct_message']['text']);
3007 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3008 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3012 * Test the api_direct_messages_new() function with a title.
3016 public function testApiDirectMessagesNewWithTitle()
3018 $_POST['text'] = 'message_text';
3019 $_POST['screen_name'] = $this->friendUser['nick'];
3020 $_REQUEST['title'] = 'message_title';
3021 $result = api_direct_messages_new('json');
3022 $this->assertContains('message_text', $result['direct_message']['text']);
3023 $this->assertContains('message_title', $result['direct_message']['text']);
3024 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3025 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3029 * Test the api_direct_messages_new() function with an RSS result.
3033 public function testApiDirectMessagesNewWithRss()
3035 $_POST['text'] = 'message_text';
3036 $_POST['screen_name'] = $this->friendUser['nick'];
3037 $result = api_direct_messages_new('rss');
3038 $this->assertXml($result, 'direct-messages');
3042 * Test the api_direct_messages_destroy() function.
3045 * @expectedException Friendica\Network\HTTPException\BadRequestException
3047 public function testApiDirectMessagesDestroy()
3049 api_direct_messages_destroy('json');
3053 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3057 public function testApiDirectMessagesDestroyWithVerbose()
3059 $_GET['friendica_verbose'] = 'true';
3060 $result = api_direct_messages_destroy('json');
3061 $this->assertEquals(
3064 'result' => 'error',
3065 'message' => 'message id or parenturi not specified'
3073 * Test the api_direct_messages_destroy() function without an authenticated user.
3076 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3078 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3080 $_SESSION['authenticated'] = false;
3081 api_direct_messages_destroy('json');
3085 * Test the api_direct_messages_destroy() function with a non-zero ID.
3088 * @expectedException Friendica\Network\HTTPException\BadRequestException
3090 public function testApiDirectMessagesDestroyWithId()
3092 $_REQUEST['id'] = 1;
3093 api_direct_messages_destroy('json');
3097 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3101 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3103 $_REQUEST['id'] = 1;
3104 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3105 $_GET['friendica_verbose'] = 'true';
3106 $result = api_direct_messages_destroy('json');
3107 $this->assertEquals(
3110 'result' => 'error',
3111 'message' => 'message id not in database'
3119 * Test the api_direct_messages_destroy() function with a non-zero ID.
3123 public function testApiDirectMessagesDestroyWithCorrectId()
3125 $this->markTestIncomplete('We need to add a dataset for this.');
3129 * Test the api_direct_messages_box() function.
3133 public function testApiDirectMessagesBoxWithSentbox()
3135 $_REQUEST['page'] = -1;
3136 $_REQUEST['max_id'] = 10;
3137 $result = api_direct_messages_box('json', 'sentbox', 'false');
3138 $this->assertArrayHasKey('direct_message', $result);
3142 * Test the api_direct_messages_box() function.
3146 public function testApiDirectMessagesBoxWithConversation()
3148 $result = api_direct_messages_box('json', 'conversation', 'false');
3149 $this->assertArrayHasKey('direct_message', $result);
3153 * Test the api_direct_messages_box() function.
3157 public function testApiDirectMessagesBoxWithAll()
3159 $result = api_direct_messages_box('json', 'all', 'false');
3160 $this->assertArrayHasKey('direct_message', $result);
3164 * Test the api_direct_messages_box() function.
3168 public function testApiDirectMessagesBoxWithInbox()
3170 $result = api_direct_messages_box('json', 'inbox', 'false');
3171 $this->assertArrayHasKey('direct_message', $result);
3175 * Test the api_direct_messages_box() function.
3179 public function testApiDirectMessagesBoxWithVerbose()
3181 $result = api_direct_messages_box('json', 'sentbox', 'true');
3182 $this->assertEquals(
3185 'result' => 'error',
3186 'message' => 'no mails available'
3194 * Test the api_direct_messages_box() function with a RSS result.
3198 public function testApiDirectMessagesBoxWithRss()
3200 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3201 $this->assertXml($result, 'direct-messages');
3205 * Test the api_direct_messages_box() function without an authenticated user.
3208 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3210 public function testApiDirectMessagesBoxWithUnallowedUser()
3212 $_SESSION['allow_api'] = false;
3213 $_GET['screen_name'] = $this->selfUser['nick'];
3214 api_direct_messages_box('json', 'sentbox', 'false');
3218 * Test the api_direct_messages_sentbox() function.
3222 public function testApiDirectMessagesSentbox()
3224 $result = api_direct_messages_sentbox('json');
3225 $this->assertArrayHasKey('direct_message', $result);
3229 * Test the api_direct_messages_inbox() function.
3233 public function testApiDirectMessagesInbox()
3235 $result = api_direct_messages_inbox('json');
3236 $this->assertArrayHasKey('direct_message', $result);
3240 * Test the api_direct_messages_all() function.
3244 public function testApiDirectMessagesAll()
3246 $result = api_direct_messages_all('json');
3247 $this->assertArrayHasKey('direct_message', $result);
3251 * Test the api_direct_messages_conversation() function.
3255 public function testApiDirectMessagesConversation()
3257 $result = api_direct_messages_conversation('json');
3258 $this->assertArrayHasKey('direct_message', $result);
3262 * Test the api_oauth_request_token() function.
3266 public function testApiOauthRequestToken()
3268 $this->markTestIncomplete('killme() kills phpunit as well');
3272 * Test the api_oauth_access_token() function.
3276 public function testApiOauthAccessToken()
3278 $this->markTestIncomplete('killme() kills phpunit as well');
3282 * Test the api_fr_photoalbum_delete() function.
3285 * @expectedException Friendica\Network\HTTPException\BadRequestException
3287 public function testApiFrPhotoalbumDelete()
3289 api_fr_photoalbum_delete('json');
3293 * Test the api_fr_photoalbum_delete() function with an album name.
3296 * @expectedException Friendica\Network\HTTPException\BadRequestException
3298 public function testApiFrPhotoalbumDeleteWithAlbum()
3300 $_REQUEST['album'] = 'album_name';
3301 api_fr_photoalbum_delete('json');
3305 * Test the api_fr_photoalbum_delete() function with an album name.
3309 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3311 $this->markTestIncomplete('We need to add a dataset for this.');
3315 * Test the api_fr_photoalbum_delete() function.
3318 * @expectedException Friendica\Network\HTTPException\BadRequestException
3320 public function testApiFrPhotoalbumUpdate()
3322 api_fr_photoalbum_update('json');
3326 * Test the api_fr_photoalbum_delete() function with an album name.
3329 * @expectedException Friendica\Network\HTTPException\BadRequestException
3331 public function testApiFrPhotoalbumUpdateWithAlbum()
3333 $_REQUEST['album'] = 'album_name';
3334 api_fr_photoalbum_update('json');
3338 * Test the api_fr_photoalbum_delete() function with an album name.
3341 * @expectedException Friendica\Network\HTTPException\BadRequestException
3343 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3345 $_REQUEST['album'] = 'album_name';
3346 $_REQUEST['album_new'] = 'album_name';
3347 api_fr_photoalbum_update('json');
3351 * Test the api_fr_photoalbum_update() function without an authenticated user.
3354 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3356 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3358 $_SESSION['authenticated'] = false;
3359 api_fr_photoalbum_update('json');
3363 * Test the api_fr_photoalbum_delete() function with an album name.
3367 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3369 $this->markTestIncomplete('We need to add a dataset for this.');
3373 * Test the api_fr_photos_list() function.
3377 public function testApiFrPhotosList()
3379 $result = api_fr_photos_list('json');
3380 $this->assertArrayHasKey('photo', $result);
3384 * Test the api_fr_photos_list() function without an authenticated user.
3387 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3389 public function testApiFrPhotosListWithoutAuthenticatedUser()
3391 $_SESSION['authenticated'] = false;
3392 api_fr_photos_list('json');
3396 * Test the api_fr_photo_create_update() function.
3399 * @expectedException Friendica\Network\HTTPException\BadRequestException
3401 public function testApiFrPhotoCreateUpdate()
3403 api_fr_photo_create_update('json');
3407 * Test the api_fr_photo_create_update() function without an authenticated user.
3410 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3412 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3414 $_SESSION['authenticated'] = false;
3415 api_fr_photo_create_update('json');
3419 * Test the api_fr_photo_create_update() function with an album name.
3422 * @expectedException Friendica\Network\HTTPException\BadRequestException
3424 public function testApiFrPhotoCreateUpdateWithAlbum()
3426 $_REQUEST['album'] = 'album_name';
3427 api_fr_photo_create_update('json');
3431 * Test the api_fr_photo_create_update() function with the update mode.
3435 public function testApiFrPhotoCreateUpdateWithUpdate()
3437 $this->markTestIncomplete('We need to create a dataset for this');
3441 * Test the api_fr_photo_create_update() function with an uploaded file.
3445 public function testApiFrPhotoCreateUpdateWithFile()
3447 $this->markTestIncomplete();
3451 * Test the api_fr_photo_delete() function.
3454 * @expectedException Friendica\Network\HTTPException\BadRequestException
3456 public function testApiFrPhotoDelete()
3458 api_fr_photo_delete('json');
3462 * Test the api_fr_photo_delete() function without an authenticated user.
3465 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3467 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3469 $_SESSION['authenticated'] = false;
3470 api_fr_photo_delete('json');
3474 * Test the api_fr_photo_delete() function with a photo ID.
3477 * @expectedException Friendica\Network\HTTPException\BadRequestException
3479 public function testApiFrPhotoDeleteWithPhotoId()
3481 $_REQUEST['photo_id'] = 1;
3482 api_fr_photo_delete('json');
3486 * Test the api_fr_photo_delete() function with a correct photo ID.
3490 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3492 $this->markTestIncomplete('We need to create a dataset for this.');
3496 * Test the api_fr_photo_detail() function.
3499 * @expectedException Friendica\Network\HTTPException\BadRequestException
3501 public function testApiFrPhotoDetail()
3503 api_fr_photo_detail('json');
3507 * Test the api_fr_photo_detail() function without an authenticated user.
3510 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3512 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3514 $_SESSION['authenticated'] = false;
3515 api_fr_photo_detail('json');
3519 * Test the api_fr_photo_detail() function with a photo ID.
3522 * @expectedException Friendica\Network\HTTPException\NotFoundException
3524 public function testApiFrPhotoDetailWithPhotoId()
3526 $_REQUEST['photo_id'] = 1;
3527 api_fr_photo_detail('json');
3531 * Test the api_fr_photo_detail() function with a correct photo ID.
3535 public function testApiFrPhotoDetailCorrectPhotoId()
3537 $this->markTestIncomplete('We need to create a dataset for this.');
3541 * Test the api_account_update_profile_image() function.
3544 * @expectedException Friendica\Network\HTTPException\BadRequestException
3546 public function testApiAccountUpdateProfileImage()
3548 api_account_update_profile_image('json');
3552 * Test the api_account_update_profile_image() function without an authenticated user.
3555 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3557 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3559 $_SESSION['authenticated'] = false;
3560 api_account_update_profile_image('json');
3564 * Test the api_account_update_profile_image() function with an uploaded file.
3567 * @expectedException Friendica\Network\HTTPException\BadRequestException
3569 public function testApiAccountUpdateProfileImageWithUpload()
3571 $this->markTestIncomplete();
3576 * Test the api_account_update_profile() function.
3580 public function testApiAccountUpdateProfile()
3582 $_POST['name'] = 'new_name';
3583 $_POST['description'] = 'new_description';
3584 $result = api_account_update_profile('json');
3585 // We can't use assertSelfUser() here because the user object is missing some properties.
3586 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3587 $this->assertEquals('DFRN', $result['user']['location']);
3588 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3589 $this->assertEquals('dfrn', $result['user']['network']);
3590 $this->assertEquals('new_name', $result['user']['name']);
3591 $this->assertEquals('new_description', $result['user']['description']);
3595 * Test the check_acl_input() function.
3599 public function testCheckAclInput()
3601 $result = check_acl_input('<aclstring>');
3602 // Where does this result come from?
3603 $this->assertEquals(1, $result);
3607 * Test the check_acl_input() function with an empty ACL string.
3611 public function testCheckAclInputWithEmptyAclString()
3613 $result = check_acl_input(' ');
3614 $this->assertFalse($result);
3618 * Test the save_media_to_database() function.
3622 public function testSaveMediaToDatabase()
3624 $this->markTestIncomplete();
3628 * Test the post_photo_item() function.
3632 public function testPostPhotoItem()
3634 $this->markTestIncomplete();
3638 * Test the prepare_photo_data() function.
3642 public function testPreparePhotoData()
3644 $this->markTestIncomplete();
3648 * Test the api_friendica_remoteauth() function.
3651 * @expectedException Friendica\Network\HTTPException\BadRequestException
3653 public function testApiFriendicaRemoteauth()
3655 api_friendica_remoteauth();
3659 * Test the api_friendica_remoteauth() function with an URL.
3662 * @expectedException Friendica\Network\HTTPException\BadRequestException
3664 public function testApiFriendicaRemoteauthWithUrl()
3666 $_GET['url'] = 'url';
3667 $_GET['c_url'] = 'url';
3668 api_friendica_remoteauth();
3672 * Test the api_friendica_remoteauth() function with a correct URL.
3676 public function testApiFriendicaRemoteauthWithCorrectUrl()
3678 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3679 $_GET['url'] = 'url';
3680 $_GET['c_url'] = $this->selfUser['nurl'];
3681 api_friendica_remoteauth();
3685 * Test the api_share_as_retweet() function.
3689 public function testApiShareAsRetweet()
3691 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3692 $result = api_share_as_retweet($item);
3693 $this->assertFalse($result);
3697 * Test the api_share_as_retweet() function with a valid item.
3701 public function testApiShareAsRetweetWithValidItem()
3703 $this->markTestIncomplete();
3707 * Test the api_get_nick() function.
3711 public function testApiGetNick()
3713 $result = api_get_nick($this->otherUser['nurl']);
3714 $this->assertEquals('othercontact', $result);
3718 * Test the api_get_nick() function with a wrong URL.
3722 public function testApiGetNickWithWrongUrl()
3724 $result = api_get_nick('wrong_url');
3725 $this->assertFalse($result);
3729 * Test the api_in_reply_to() function.
3733 public function testApiInReplyTo()
3735 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3736 $this->assertArrayHasKey('status_id', $result);
3737 $this->assertArrayHasKey('user_id', $result);
3738 $this->assertArrayHasKey('status_id_str', $result);
3739 $this->assertArrayHasKey('user_id_str', $result);
3740 $this->assertArrayHasKey('screen_name', $result);
3744 * Test the api_in_reply_to() function with a valid item.
3748 public function testApiInReplyToWithValidItem()
3750 $this->markTestIncomplete();
3754 * Test the api_clean_plain_items() function.
3758 public function testApiCleanPlainItems()
3760 $_REQUEST['include_entities'] = 'true';
3761 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3762 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3766 * Test the api_clean_attachments() function.
3770 public function testApiCleanAttachments()
3772 $this->markTestIncomplete();
3776 * Test the api_best_nickname() function.
3780 public function testApiBestNickname()
3783 $result = api_best_nickname($contacts);
3784 $this->assertNull($result);
3788 * Test the api_best_nickname() function with contacts.
3792 public function testApiBestNicknameWithContacts()
3794 $this->markTestIncomplete();
3798 * Test the api_friendica_group_show() function.
3802 public function testApiFriendicaGroupShow()
3804 $this->markTestIncomplete();
3808 * Test the api_friendica_group_delete() function.
3812 public function testApiFriendicaGroupDelete()
3814 $this->markTestIncomplete();
3818 * Test the api_lists_destroy() function.
3822 public function testApiListsDestroy()
3824 $this->markTestIncomplete();
3828 * Test the group_create() function.
3832 public function testGroupCreate()
3834 $this->markTestIncomplete();
3838 * Test the api_friendica_group_create() function.
3842 public function testApiFriendicaGroupCreate()
3844 $this->markTestIncomplete();
3848 * Test the api_lists_create() function.
3852 public function testApiListsCreate()
3854 $this->markTestIncomplete();
3858 * Test the api_friendica_group_update() function.
3862 public function testApiFriendicaGroupUpdate()
3864 $this->markTestIncomplete();
3868 * Test the api_lists_update() function.
3872 public function testApiListsUpdate()
3874 $this->markTestIncomplete();
3878 * Test the api_friendica_activity() function.
3882 public function testApiFriendicaActivity()
3884 $this->markTestIncomplete();
3888 * Test the api_friendica_notification() function.
3891 * @expectedException Friendica\Network\HTTPException\BadRequestException
3893 public function testApiFriendicaNotification()
3895 api_friendica_notification('json');
3899 * Test the api_friendica_notification() function without an authenticated user.
3902 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3904 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3906 $_SESSION['authenticated'] = false;
3907 api_friendica_notification('json');
3911 * Test the api_friendica_notification() function with an argument count.
3915 public function testApiFriendicaNotificationWithArgumentCount()
3917 $this->app->argv = ['api', 'friendica', 'notification'];
3918 $this->app->argc = count($this->app->argv);
3919 $result = api_friendica_notification('json');
3920 $this->assertEquals(['note' => false], $result);
3924 * Test the api_friendica_notification() function with an XML result.
3928 public function testApiFriendicaNotificationWithXmlResult()
3930 $this->app->argv = ['api', 'friendica', 'notification'];
3931 $this->app->argc = count($this->app->argv);
3932 $result = api_friendica_notification('xml');
3933 $this->assertXml($result, 'notes');
3937 * Test the api_friendica_notification_seen() function.
3941 public function testApiFriendicaNotificationSeen()
3943 $this->markTestIncomplete();
3947 * Test the api_friendica_direct_messages_setseen() function.
3951 public function testApiFriendicaDirectMessagesSetseen()
3953 $this->markTestIncomplete();
3957 * Test the api_friendica_direct_messages_search() function.
3961 public function testApiFriendicaDirectMessagesSearch()
3963 $this->markTestIncomplete();
3967 * Test the api_friendica_profile_show() function.
3971 public function testApiFriendicaProfileShow()
3973 $result = api_friendica_profile_show('json');
3974 // We can't use assertSelfUser() here because the user object is missing some properties.
3975 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3976 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3977 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3978 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3979 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3980 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3981 $this->assertFalse($result['$result']['multi_profiles']);
3985 * Test the api_friendica_profile_show() function with a profile ID.
3989 public function testApiFriendicaProfileShowWithProfileId()
3991 $this->markTestIncomplete('We need to add a dataset for this.');
3995 * Test the api_friendica_profile_show() function with a wrong profile ID.
3998 * @expectedException Friendica\Network\HTTPException\BadRequestException
4000 public function testApiFriendicaProfileShowWithWrongProfileId()
4002 $_REQUEST['profile_id'] = 666;
4003 api_friendica_profile_show('json');
4007 * Test the api_friendica_profile_show() function without an authenticated user.
4010 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4012 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4014 $_SESSION['authenticated'] = false;
4015 api_friendica_profile_show('json');
4019 * Test the api_saved_searches_list() function.
4023 public function testApiSavedSearchesList()
4025 $result = api_saved_searches_list('json');
4026 $this->assertEquals(1, $result['terms'][0]['id']);
4027 $this->assertEquals(1, $result['terms'][0]['id_str']);
4028 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4029 $this->assertEquals('Saved search', $result['terms'][0]['query']);