6 namespace Friendica\Test\legacy;
9 use Friendica\Core\Config\Capability\IManageConfigValues;
10 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
11 use Friendica\Core\Protocol;
13 use Friendica\Module\Api\ApiResponse;
14 use Friendica\Module\BaseApi;
15 use Friendica\Network\HTTPException;
16 use Friendica\Security\BasicAuth;
17 use Friendica\Test\FixtureTest;
18 use Friendica\Util\Arrays;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Temporal;
21 use Monolog\Handler\TestHandler;
23 require_once __DIR__ . '/../../include/api.php';
26 * Tests for the API functions.
28 * Functions that use header() need to be tested in a separate process.
29 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31 * @backupGlobals enabled
33 class ApiTest extends FixtureTest
36 * @var TestHandler Can handle log-outputs
43 protected $friendUser;
47 protected $wrongUserId;
52 /** @var IManageConfigValues */
56 * Create variables used by tests.
58 protected function setUp() : void
60 global $API, $called_api;
66 /** @var IManageConfigValues $config */
67 $this->config = $this->dice->create(IManageConfigValues::class);
69 $this->config->set('system', 'url', 'http://localhost');
70 $this->config->set('system', 'hostname', 'localhost');
71 $this->config->set('system', 'worker_dont_fork', true);
74 $this->config->set('config', 'hostname', 'localhost');
75 $this->config->set('system', 'throttle_limit_day', 100);
76 $this->config->set('system', 'throttle_limit_week', 100);
77 $this->config->set('system', 'throttle_limit_month', 100);
78 $this->config->set('system', 'theme', 'system_theme');
82 $this->app = DI::app();
84 DI::args()->setArgc(1);
86 // User data that the test database is populated with
89 'name' => 'Self contact',
90 'nick' => 'selfcontact',
91 'nurl' => 'http://localhost/profile/selfcontact'
95 'name' => 'Friend contact',
96 'nick' => 'friendcontact',
97 'nurl' => 'http://localhost/profile/friendcontact'
101 'name' => 'othercontact',
102 'nick' => 'othercontact',
103 'nurl' => 'http://localhost/profile/othercontact'
106 // User ID that we know is not in the database
107 $this->wrongUserId = 666;
109 DI::session()->start();
111 // Most API require login so we force the session
114 'authenticated' => true,
115 'uid' => $this->selfUser['id']
120 * Assert that an user array contains expected keys.
122 * @param array $user User array
126 private function assertSelfUser(array $user)
128 self::assertEquals($this->selfUser['id'], $user['uid']);
129 self::assertEquals($this->selfUser['id'], $user['cid']);
130 self::assertEquals(1, $user['self']);
131 self::assertEquals('DFRN', $user['location']);
132 self::assertEquals($this->selfUser['name'], $user['name']);
133 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
134 self::assertEquals('dfrn', $user['network']);
135 self::assertTrue($user['verified']);
139 * Assert that an user array contains expected keys.
141 * @param array $user User array
145 private function assertOtherUser(array $user = [])
147 self::assertEquals($this->otherUser['id'], $user['id']);
148 self::assertEquals($this->otherUser['id'], $user['id_str']);
149 self::assertEquals(0, $user['self']);
150 self::assertEquals($this->otherUser['name'], $user['name']);
151 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
152 self::assertFalse($user['verified']);
156 * Assert that a status array contains expected keys.
158 * @param array $status Status array
162 private function assertStatus(array $status = [])
164 self::assertIsString($status['text'] ?? '');
165 self::assertIsInt($status['id'] ?? '');
166 // We could probably do more checks here.
170 * Assert that a list array contains expected keys.
172 * @param array $list List array
176 private function assertList(array $list = [])
178 self::assertIsString($list['name']);
179 self::assertIsInt($list['id']);
180 self::assertIsString('string', $list['id_str']);
181 self::assertContains($list['mode'], ['public', 'private']);
182 // We could probably do more checks here.
186 * Assert that the string is XML and contain the root element.
188 * @param string $result XML string
189 * @param string $root_element Root element name
193 private function assertXml($result = '', $root_element = '')
195 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
196 self::assertStringContainsString('<' . $root_element, $result);
197 // We could probably do more checks here.
201 * Get the path to a temporary empty PNG image.
203 * @return string Path
205 private function getTempImage()
207 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
211 // Empty 1x1 px PNG image
212 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
220 * Test the api_user() function.
224 public function testApiUser()
226 self::assertEquals($this->selfUser['id'], api_user());
230 * Test the api_user() function with an unallowed user.
234 public function testApiUserWithUnallowedUser()
236 $_SESSION = ['allow_api' => false];
237 self::assertEquals(false, api_user());
241 * Test the api_source() function.
245 public function testApiSource()
247 self::assertEquals('api', api_source());
251 * Test the api_source() function with a Twidere user agent.
255 public function testApiSourceWithTwidere()
257 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
258 self::assertEquals('Twidere', api_source());
262 * Test the api_source() function with a GET parameter.
266 public function testApiSourceWithGet()
268 $_GET['source'] = 'source_name';
269 self::assertEquals('source_name', api_source());
273 * Test the api_date() function.
277 public function testApiDate()
279 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
283 * Test the api_register_func() function.
287 public function testApiRegisterFunc()
299 self::assertTrue($API['api_path']['auth']);
300 self::assertEquals('method', $API['api_path']['method']);
301 self::assertTrue(is_callable($API['api_path']['func']));
305 * Test the BasicAuth::getCurrentUserID() function without any login.
307 * @runInSeparateProcess
308 * @preserveGlobalState disabled
309 * @preserveGlobalState disabled
311 public function testApiLoginWithoutLogin()
313 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314 BasicAuth::getCurrentUserID(true);
318 * Test the BasicAuth::getCurrentUserID() function with a bad login.
320 * @runInSeparateProcess
321 * @preserveGlobalState disabled
322 * @preserveGlobalState disabled
324 public function testApiLoginWithBadLogin()
326 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
327 $_SERVER['PHP_AUTH_USER'] = 'user@server';
328 BasicAuth::getCurrentUserID(true);
332 * Test the BasicAuth::getCurrentUserID() function with oAuth.
336 public function testApiLoginWithOauth()
338 $this->markTestIncomplete('Can we test this easily?');
342 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
346 public function testApiLoginWithAddonAuth()
348 $this->markTestIncomplete('Can we test this easily?');
352 * Test the BasicAuth::getCurrentUserID() function with a correct login.
354 * @runInSeparateProcess
355 * @preserveGlobalState disabled
356 * @doesNotPerformAssertions
358 public function testApiLoginWithCorrectLogin()
360 $_SERVER['PHP_AUTH_USER'] = 'Test user';
361 $_SERVER['PHP_AUTH_PW'] = 'password';
362 BasicAuth::getCurrentUserID(true);
366 * Test the BasicAuth::getCurrentUserID() function with a remote user.
368 * @runInSeparateProcess
369 * @preserveGlobalState disabled
371 public function testApiLoginWithRemoteUser()
373 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
374 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
375 BasicAuth::getCurrentUserID(true);
379 * Test the api_check_method() function.
383 public function testApiCheckMethod()
385 self::assertFalse(api_check_method('method'));
389 * Test the api_check_method() function with a correct method.
393 public function testApiCheckMethodWithCorrectMethod()
395 $_SERVER['REQUEST_METHOD'] = 'method';
396 self::assertTrue(api_check_method('method'));
400 * Test the api_check_method() function with a wildcard.
404 public function testApiCheckMethodWithWildcard()
406 self::assertTrue(api_check_method('*'));
410 * Test the api_call() function.
412 * @runInSeparateProcess
413 * @preserveGlobalState disabled
415 public function testApiCall()
419 'method' => 'method',
420 'func' => function () {
421 return ['data' => ['some_data']];
424 $_SERVER['REQUEST_METHOD'] = 'method';
425 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
426 $_GET['callback'] = 'callback_name';
428 $args = DI::args()->determine($_SERVER, $_GET);
431 'callback_name(["some_data"])',
432 api_call($this->app, $args)
437 * Test the api_call() function with the profiled enabled.
439 * @runInSeparateProcess
440 * @preserveGlobalState disabled
442 public function testApiCallWithProfiler()
446 'method' => 'method',
447 'func' => function () {
448 return ['data' => ['some_data']];
452 $_SERVER['REQUEST_METHOD'] = 'method';
453 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
455 $args = DI::args()->determine($_SERVER, $_GET);
457 $this->config->set('system', 'profiler', true);
458 $this->config->set('rendertime', 'callstack', true);
459 $this->app->callstack = [
460 'database' => ['some_function' => 200],
461 'database_write' => ['some_function' => 200],
462 'cache' => ['some_function' => 200],
463 'cache_write' => ['some_function' => 200],
464 'network' => ['some_function' => 200]
469 api_call($this->app, $args)
474 * Test the api_call() function without any result.
476 * @runInSeparateProcess
477 * @preserveGlobalState disabled
479 public function testApiCallWithNoResult()
481 // @todo How to test the new API?
485 'method' => 'method',
486 'func' => function () {
490 $_SERVER['REQUEST_METHOD'] = 'method';
491 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
493 $args = DI::args()->determine($_SERVER, $_GET);
496 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
497 api_call($this->app, $args)
503 * Test the api_call() function with a JSON result.
505 * @runInSeparateProcess
506 * @preserveGlobalState disabled
508 public function testApiCallWithJson()
512 'method' => 'method',
513 'func' => function () {
514 return ['data' => ['some_data']];
517 $_SERVER['REQUEST_METHOD'] = 'method';
518 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
520 $args = DI::args()->determine($_SERVER, $_GET);
524 api_call($this->app, $args)
529 * Test the api_call() function with an XML result.
531 * @runInSeparateProcess
532 * @preserveGlobalState disabled
534 public function testApiCallWithXml()
538 'method' => 'method',
539 'func' => function () {
543 $_SERVER['REQUEST_METHOD'] = 'method';
544 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
546 $args = DI::args()->determine($_SERVER, $_GET);
550 api_call($this->app, $args)
555 * Test the api_call() function with an RSS result.
557 * @runInSeparateProcess
558 * @preserveGlobalState disabled
560 public function testApiCallWithRss()
564 'method' => 'method',
565 'func' => function () {
569 $_SERVER['REQUEST_METHOD'] = 'method';
570 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
572 $args = DI::args()->determine($_SERVER, $_GET);
575 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
577 api_call($this->app, $args)
582 * Test the api_call() function with an Atom result.
584 * @runInSeparateProcess
585 * @preserveGlobalState disabled
587 public function testApiCallWithAtom()
591 'method' => 'method',
592 'func' => function () {
596 $_SERVER['REQUEST_METHOD'] = 'method';
597 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
599 $args = DI::args()->determine($_SERVER, $_GET);
602 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
604 api_call($this->app, $args)
609 * Test the api_rss_extra() function.
613 public function testApiRssExtra()
615 $user_info = ['url' => 'user_url', 'lang' => 'en'];
616 $result = api_rss_extra($this->app, [], $user_info);
617 self::assertEquals($user_info, $result['$user']);
618 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
619 self::assertArrayHasKey('self', $result['$rss']);
620 self::assertArrayHasKey('base', $result['$rss']);
621 self::assertArrayHasKey('updated', $result['$rss']);
622 self::assertArrayHasKey('atom_updated', $result['$rss']);
623 self::assertArrayHasKey('language', $result['$rss']);
624 self::assertArrayHasKey('logo', $result['$rss']);
628 * Test the api_rss_extra() function without any user info.
632 public function testApiRssExtraWithoutUserInfo()
634 $result = api_rss_extra($this->app, [], null);
635 self::assertIsArray($result['$user']);
636 self::assertArrayHasKey('alternate', $result['$rss']);
637 self::assertArrayHasKey('self', $result['$rss']);
638 self::assertArrayHasKey('base', $result['$rss']);
639 self::assertArrayHasKey('updated', $result['$rss']);
640 self::assertArrayHasKey('atom_updated', $result['$rss']);
641 self::assertArrayHasKey('language', $result['$rss']);
642 self::assertArrayHasKey('logo', $result['$rss']);
646 * Test the api_unique_id_to_nurl() function.
650 public function testApiUniqueIdToNurl()
652 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
656 * Test the api_unique_id_to_nurl() function with a correct ID.
660 public function testApiUniqueIdToNurlWithCorrectId()
662 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
666 * Test the api_get_user() function.
670 public function testApiGetUser()
672 $user = api_get_user();
673 self::assertSelfUser($user);
674 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
675 self::assertEquals('6fdbe8', $user['profile_link_color']);
676 self::assertEquals('ededed', $user['profile_background_color']);
680 * Test the api_get_user() function with a Frio schema.
684 public function testApiGetUserWithFrioSchema()
686 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
687 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
688 $user = api_get_user();
689 self::assertSelfUser($user);
690 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
691 self::assertEquals('6fdbe8', $user['profile_link_color']);
692 self::assertEquals('ededed', $user['profile_background_color']);
696 * Test the api_get_user() function with an empty Frio schema.
700 public function testApiGetUserWithEmptyFrioSchema()
702 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
703 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
704 $user = api_get_user();
705 self::assertSelfUser($user);
706 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
707 self::assertEquals('6fdbe8', $user['profile_link_color']);
708 self::assertEquals('ededed', $user['profile_background_color']);
712 * Test the api_get_user() function with a custom Frio schema.
716 public function testApiGetUserWithCustomFrioSchema()
718 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
719 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
720 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
721 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
722 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
723 $user = api_get_user();
724 self::assertSelfUser($user);
725 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
726 self::assertEquals('123456', $user['profile_link_color']);
727 self::assertEquals('123456', $user['profile_background_color']);
731 * Test the api_get_user() function with an user that is not allowed to use the API.
733 * @runInSeparateProcess
734 * @preserveGlobalState disabled
736 public function testApiGetUserWithoutApiUser()
738 $_SERVER['PHP_AUTH_USER'] = 'Test user';
739 $_SERVER['PHP_AUTH_PW'] = 'password';
740 $_SESSION['allow_api'] = false;
741 self::assertFalse(api_get_user());
745 * Test the api_get_user() function with an user ID in a GET parameter.
749 public function testApiGetUserWithGetId()
751 $_GET['user_id'] = $this->otherUser['id'];
752 self::assertOtherUser(api_get_user());
756 * Test the api_get_user() function with a wrong user ID in a GET parameter.
760 public function testApiGetUserWithWrongGetId()
762 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
763 $_GET['user_id'] = $this->wrongUserId;
764 self::assertOtherUser(api_get_user());
768 * Test the api_get_user() function with an user name in a GET parameter.
772 public function testApiGetUserWithGetName()
774 $_GET['screen_name'] = $this->selfUser['nick'];
775 self::assertSelfUser(api_get_user());
779 * Test the api_get_user() function with a profile URL in a GET parameter.
783 public function testApiGetUserWithGetUrl()
785 $_GET['profileurl'] = $this->selfUser['nurl'];
786 self::assertSelfUser(api_get_user());
790 * Test the api_get_user() function with an user ID in the API path.
794 public function testApiGetUserWithNumericCalledApi()
797 $called_api = ['api_path'];
798 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
799 self::assertOtherUser(api_get_user());
803 * Test the api_get_user() function with the $called_api global variable.
807 public function testApiGetUserWithCalledApi()
810 $called_api = ['api', 'api_path'];
811 self::assertSelfUser(api_get_user());
815 * Test the api_get_user() function with a valid user.
819 public function testApiGetUserWithCorrectUser()
821 self::assertOtherUser(api_get_user($this->otherUser['id']));
825 * Test the api_get_user() function with a wrong user ID.
829 public function testApiGetUserWithWrongUser()
831 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
832 self::assertOtherUser(api_get_user($this->wrongUserId));
836 * Test the api_get_user() function with a 0 user ID.
840 public function testApiGetUserWithZeroUser()
842 self::assertSelfUser(api_get_user(0));
846 * Test the api_item_get_user() function.
850 public function testApiItemGetUser()
852 $users = api_item_get_user($this->app, []);
853 self::assertSelfUser($users[0]);
857 * Test the api_item_get_user() function with a different item parent.
861 public function testApiItemGetUserWithDifferentParent()
863 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
864 self::assertSelfUser($users[0]);
865 self::assertEquals($users[0], $users[1]);
869 * Test the Arrays::walkRecursive() function.
873 public function testApiWalkRecursive()
878 Arrays::walkRecursive(
881 // Should we test this with a callback that actually does something?
889 * Test the Arrays::walkRecursive() function with an array.
893 public function testApiWalkRecursiveWithArray()
895 $array = [['item1'], ['item2']];
898 Arrays::walkRecursive(
901 // Should we test this with a callback that actually does something?
909 * Test the BaseApi::reformatXML() function.
913 public function testApiReformatXml()
917 self::assertTrue(ApiResponse::reformatXML($item, $key));
918 self::assertEquals('true', $item);
922 * Test the BaseApi::reformatXML() function with a statusnet_api key.
926 public function testApiReformatXmlWithStatusnetKey()
929 $key = 'statusnet_api';
930 self::assertTrue(ApiResponse::reformatXML($item, $key));
931 self::assertEquals('statusnet:api', $key);
935 * Test the BaseApi::reformatXML() function with a friendica_api key.
939 public function testApiReformatXmlWithFriendicaKey()
942 $key = 'friendica_api';
943 self::assertTrue(ApiResponse::reformatXML($item, $key));
944 self::assertEquals('friendica:api', $key);
948 * Test the BaseApi::createXML() function.
952 public function testApiCreateXml()
955 '<?xml version="1.0"?>' . "\n" .
956 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
957 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
958 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
959 ' <data>some_data</data>' . "\n" .
960 '</root_element>' . "\n",
961 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
966 * Test the BaseApi::createXML() function without any XML namespace.
970 public function testApiCreateXmlWithoutNamespaces()
973 '<?xml version="1.0"?>' . "\n" .
975 ' <data>some_data</data>' . "\n" .
977 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
982 * Test the BaseApi::formatData() function.
986 public function testApiFormatData()
988 $data = ['some_data'];
989 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
993 * Test the BaseApi::formatData() function with an XML result.
997 public function testApiFormatDataWithXml()
1000 '<?xml version="1.0"?>' . "\n" .
1001 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1002 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1003 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1004 ' <data>some_data</data>' . "\n" .
1005 '</root_element>' . "\n",
1006 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
1011 * Test the api_account_verify_credentials() function.
1015 public function testApiAccountVerifyCredentials()
1017 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1021 * Test the api_account_verify_credentials() function without an authenticated user.
1025 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1027 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1028 $_SESSION['authenticated'] = false;
1029 api_account_verify_credentials('json');
1033 * Test the requestdata() function.
1037 public function testRequestdata()
1039 self::assertNull(requestdata('variable_name'));
1043 * Test the requestdata() function with a POST parameter.
1047 public function testRequestdataWithPost()
1049 $_POST['variable_name'] = 'variable_value';
1050 self::assertEquals('variable_value', requestdata('variable_name'));
1054 * Test the requestdata() function with a GET parameter.
1058 public function testRequestdataWithGet()
1060 $_GET['variable_name'] = 'variable_value';
1061 self::assertEquals('variable_value', requestdata('variable_name'));
1065 * Test the api_statuses_mediap() function.
1069 public function testApiStatusesMediap()
1071 DI::args()->setArgc(2);
1079 'tmp_name' => $this->getTempImage(),
1080 'name' => 'spacer.png',
1081 'type' => 'image/png'
1084 $_GET['status'] = '<b>Status content</b>';
1086 $result = api_statuses_mediap('json');
1087 self::assertStatus($result['status']);
1091 * Test the api_statuses_mediap() function without an authenticated user.
1095 public function testApiStatusesMediapWithoutAuthenticatedUser()
1097 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1098 $_SESSION['authenticated'] = false;
1099 api_statuses_mediap('json');
1103 * Test the api_statuses_update() function.
1107 public function testApiStatusesUpdate()
1109 $_GET['status'] = 'Status content #friendica';
1110 $_GET['in_reply_to_status_id'] = -1;
1119 'tmp_name' => $this->getTempImage(),
1120 'name' => 'spacer.png',
1121 'type' => 'image/png'
1125 $result = api_statuses_update('json');
1126 self::assertStatus($result['status']);
1130 * Test the api_statuses_update() function with an HTML status.
1134 public function testApiStatusesUpdateWithHtml()
1136 $_GET['htmlstatus'] = '<b>Status content</b>';
1138 $result = api_statuses_update('json');
1139 self::assertStatus($result['status']);
1143 * Test the api_statuses_update() function without an authenticated user.
1147 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1149 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1150 $_SESSION['authenticated'] = false;
1151 api_statuses_update('json');
1155 * Test the api_statuses_update() function with a parent status.
1159 public function testApiStatusesUpdateWithParent()
1161 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1165 * Test the api_statuses_update() function with a media_ids parameter.
1169 public function testApiStatusesUpdateWithMediaIds()
1171 $this->markTestIncomplete();
1175 * Test the api_statuses_update() function with the throttle limit reached.
1179 public function testApiStatusesUpdateWithDayThrottleReached()
1181 $this->markTestIncomplete();
1185 * Test the api_media_upload() function.
1186 * @runInSeparateProcess
1187 * @preserveGlobalState disabled
1189 public function testApiMediaUpload()
1191 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1196 * Test the api_media_upload() function without an authenticated user.
1200 public function testApiMediaUploadWithoutAuthenticatedUser()
1202 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1203 $_SESSION['authenticated'] = false;
1208 * Test the api_media_upload() function with an invalid uploaded media.
1212 public function testApiMediaUploadWithMedia()
1214 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1218 'tmp_name' => 'tmp_name'
1225 * Test the api_media_upload() function with an valid uploaded media.
1229 public function testApiMediaUploadWithValidMedia()
1237 'tmp_name' => $this->getTempImage(),
1238 'name' => 'spacer.png',
1239 'type' => 'image/png'
1243 DI::args()->setArgc(2);
1245 $result = api_media_upload();
1246 self::assertEquals('image/png', $result['media']['image']['image_type']);
1247 self::assertEquals(1, $result['media']['image']['w']);
1248 self::assertEquals(1, $result['media']['image']['h']);
1249 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1253 * Test the api_status_show() function.
1255 public function testApiStatusShowWithJson()
1257 $result = api_status_show('json', 1);
1258 self::assertStatus($result['status']);
1262 * Test the api_status_show() function with an XML result.
1264 public function testApiStatusShowWithXml()
1266 $result = api_status_show('xml', 1);
1267 self::assertXml($result, 'statuses');
1271 * Test the api_get_last_status() function
1273 public function testApiGetLastStatus()
1275 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1277 self::assertNotNull($item);
1281 * Test the api_users_show() function.
1285 public function testApiUsersShow()
1287 $result = api_users_show('json');
1288 // We can't use assertSelfUser() here because the user object is missing some properties.
1289 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1290 self::assertEquals('DFRN', $result['user']['location']);
1291 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1292 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1293 self::assertEquals('dfrn', $result['user']['network']);
1294 self::assertTrue($result['user']['verified']);
1298 * Test the api_users_show() function with an XML result.
1302 public function testApiUsersShowWithXml()
1304 $result = api_users_show('xml');
1305 self::assertXml($result, 'statuses');
1309 * Test the api_users_search() function.
1313 public function testApiUsersSearch()
1315 $_GET['q'] = 'othercontact';
1316 $result = api_users_search('json');
1317 self::assertOtherUser($result['users'][0]);
1321 * Test the api_users_search() function with an XML result.
1325 public function testApiUsersSearchWithXml()
1327 $_GET['q'] = 'othercontact';
1328 $result = api_users_search('xml');
1329 self::assertXml($result, 'users');
1333 * Test the api_users_search() function without a GET q parameter.
1337 public function testApiUsersSearchWithoutQuery()
1339 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1340 api_users_search('json');
1344 * Test the api_users_lookup() function.
1348 public function testApiUsersLookup()
1350 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1351 api_users_lookup('json');
1355 * Test the api_users_lookup() function with an user ID.
1359 public function testApiUsersLookupWithUserId()
1361 $_REQUEST['user_id'] = $this->otherUser['id'];
1362 $result = api_users_lookup('json');
1363 self::assertOtherUser($result['users'][0]);
1367 * Test the api_search() function.
1371 public function testApiSearch()
1373 $_REQUEST['q'] = 'reply';
1374 $_REQUEST['max_id'] = 10;
1375 $result = api_search('json');
1376 foreach ($result['status'] as $status) {
1377 self::assertStatus($status);
1378 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1383 * Test the api_search() function a count parameter.
1387 public function testApiSearchWithCount()
1389 $_REQUEST['q'] = 'reply';
1390 $_REQUEST['count'] = 20;
1391 $result = api_search('json');
1392 foreach ($result['status'] as $status) {
1393 self::assertStatus($status);
1394 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1399 * Test the api_search() function with an rpp parameter.
1403 public function testApiSearchWithRpp()
1405 $_REQUEST['q'] = 'reply';
1406 $_REQUEST['rpp'] = 20;
1407 $result = api_search('json');
1408 foreach ($result['status'] as $status) {
1409 self::assertStatus($status);
1410 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1415 * Test the api_search() function with an q parameter contains hashtag.
1416 * @doesNotPerformAssertions
1418 public function testApiSearchWithHashtag()
1420 $_REQUEST['q'] = '%23friendica';
1421 $result = api_search('json');
1422 foreach ($result['status'] as $status) {
1423 self::assertStatus($status);
1424 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1429 * Test the api_search() function with an exclude_replies parameter.
1430 * @doesNotPerformAssertions
1432 public function testApiSearchWithExcludeReplies()
1434 $_REQUEST['max_id'] = 10;
1435 $_REQUEST['exclude_replies'] = true;
1436 $_REQUEST['q'] = 'friendica';
1437 $result = api_search('json');
1438 foreach ($result['status'] as $status) {
1439 self::assertStatus($status);
1444 * Test the api_search() function without an authenticated user.
1448 public function testApiSearchWithUnallowedUser()
1450 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1451 $_SESSION['allow_api'] = false;
1452 $_GET['screen_name'] = $this->selfUser['nick'];
1457 * Test the api_search() function without any GET query parameter.
1461 public function testApiSearchWithoutQuery()
1463 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1468 * Test the api_statuses_home_timeline() function.
1472 public function testApiStatusesHomeTimeline()
1474 $_REQUEST['max_id'] = 10;
1475 $_REQUEST['exclude_replies'] = true;
1476 $_REQUEST['conversation_id'] = 1;
1477 $result = api_statuses_home_timeline('json');
1478 self::assertNotEmpty($result['status']);
1479 foreach ($result['status'] as $status) {
1480 self::assertStatus($status);
1485 * Test the api_statuses_home_timeline() function with a negative page parameter.
1489 public function testApiStatusesHomeTimelineWithNegativePage()
1491 $_REQUEST['page'] = -2;
1492 $result = api_statuses_home_timeline('json');
1493 self::assertNotEmpty($result['status']);
1494 foreach ($result['status'] as $status) {
1495 self::assertStatus($status);
1500 * Test the api_statuses_home_timeline() with an unallowed user.
1504 public function testApiStatusesHomeTimelineWithUnallowedUser()
1506 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1507 $_SESSION['allow_api'] = false;
1508 $_GET['screen_name'] = $this->selfUser['nick'];
1509 api_statuses_home_timeline('json');
1513 * Test the api_statuses_home_timeline() function with an RSS result.
1517 public function testApiStatusesHomeTimelineWithRss()
1519 $result = api_statuses_home_timeline('rss');
1520 self::assertXml($result, 'statuses');
1524 * Test the api_statuses_public_timeline() function.
1528 public function testApiStatusesPublicTimeline()
1530 $_REQUEST['max_id'] = 10;
1531 $_REQUEST['conversation_id'] = 1;
1532 $result = api_statuses_public_timeline('json');
1533 self::assertNotEmpty($result['status']);
1534 foreach ($result['status'] as $status) {
1535 self::assertStatus($status);
1540 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1544 public function testApiStatusesPublicTimelineWithExcludeReplies()
1546 $_REQUEST['max_id'] = 10;
1547 $_REQUEST['exclude_replies'] = true;
1548 $result = api_statuses_public_timeline('json');
1549 self::assertNotEmpty($result['status']);
1550 foreach ($result['status'] as $status) {
1551 self::assertStatus($status);
1556 * Test the api_statuses_public_timeline() function with a negative page parameter.
1560 public function testApiStatusesPublicTimelineWithNegativePage()
1562 $_REQUEST['page'] = -2;
1563 $result = api_statuses_public_timeline('json');
1564 self::assertNotEmpty($result['status']);
1565 foreach ($result['status'] as $status) {
1566 self::assertStatus($status);
1571 * Test the api_statuses_public_timeline() function with an unallowed user.
1575 public function testApiStatusesPublicTimelineWithUnallowedUser()
1577 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1578 $_SESSION['allow_api'] = false;
1579 $_GET['screen_name'] = $this->selfUser['nick'];
1580 api_statuses_public_timeline('json');
1584 * Test the api_statuses_public_timeline() function with an RSS result.
1588 public function testApiStatusesPublicTimelineWithRss()
1590 $result = api_statuses_public_timeline('rss');
1591 self::assertXml($result, 'statuses');
1595 * Test the api_statuses_networkpublic_timeline() function.
1599 public function testApiStatusesNetworkpublicTimeline()
1601 $_REQUEST['max_id'] = 10;
1602 $result = api_statuses_networkpublic_timeline('json');
1603 self::assertNotEmpty($result['status']);
1604 foreach ($result['status'] as $status) {
1605 self::assertStatus($status);
1610 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1614 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1616 $_REQUEST['page'] = -2;
1617 $result = api_statuses_networkpublic_timeline('json');
1618 self::assertNotEmpty($result['status']);
1619 foreach ($result['status'] as $status) {
1620 self::assertStatus($status);
1625 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1629 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1631 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1632 $_SESSION['allow_api'] = false;
1633 $_GET['screen_name'] = $this->selfUser['nick'];
1634 api_statuses_networkpublic_timeline('json');
1638 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1642 public function testApiStatusesNetworkpublicTimelineWithRss()
1644 $result = api_statuses_networkpublic_timeline('rss');
1645 self::assertXml($result, 'statuses');
1649 * Test the api_statuses_show() function.
1653 public function testApiStatusesShow()
1655 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1656 api_statuses_show('json');
1660 * Test the api_statuses_show() function with an ID.
1664 public function testApiStatusesShowWithId()
1666 DI::args()->setArgv(['', '', '', 1]);
1667 $result = api_statuses_show('json');
1668 self::assertStatus($result['status']);
1672 * Test the api_statuses_show() function with the conversation parameter.
1676 public function testApiStatusesShowWithConversation()
1678 DI::args()->setArgv(['', '', '', 1]);
1679 $_REQUEST['conversation'] = 1;
1680 $result = api_statuses_show('json');
1681 self::assertNotEmpty($result['status']);
1682 foreach ($result['status'] as $status) {
1683 self::assertStatus($status);
1688 * Test the api_statuses_show() function with an unallowed user.
1692 public function testApiStatusesShowWithUnallowedUser()
1694 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1695 $_SESSION['allow_api'] = false;
1696 $_GET['screen_name'] = $this->selfUser['nick'];
1697 api_statuses_show('json');
1701 * Test the api_conversation_show() function.
1705 public function testApiConversationShow()
1707 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1708 api_conversation_show('json');
1712 * Test the api_conversation_show() function with an ID.
1716 public function testApiConversationShowWithId()
1718 DI::args()->setArgv(['', '', '', 1]);
1719 $_REQUEST['max_id'] = 10;
1720 $_REQUEST['page'] = -2;
1721 $result = api_conversation_show('json');
1722 self::assertNotEmpty($result['status']);
1723 foreach ($result['status'] as $status) {
1724 self::assertStatus($status);
1729 * Test the api_conversation_show() function with an unallowed user.
1733 public function testApiConversationShowWithUnallowedUser()
1735 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1736 $_SESSION['allow_api'] = false;
1737 $_GET['screen_name'] = $this->selfUser['nick'];
1738 api_conversation_show('json');
1742 * Test the api_statuses_repeat() function.
1746 public function testApiStatusesRepeat()
1748 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1749 api_statuses_repeat('json');
1753 * Test the api_statuses_repeat() function without an authenticated user.
1757 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1759 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1760 $_SESSION['authenticated'] = false;
1761 api_statuses_repeat('json');
1765 * Test the api_statuses_repeat() function with an ID.
1769 public function testApiStatusesRepeatWithId()
1771 DI::args()->setArgv(['', '', '', 1]);
1772 $result = api_statuses_repeat('json');
1773 self::assertStatus($result['status']);
1775 // Also test with a shared status
1776 DI::args()->setArgv(['', '', '', 5]);
1777 $result = api_statuses_repeat('json');
1778 self::assertStatus($result['status']);
1782 * Test the api_statuses_destroy() function.
1786 public function testApiStatusesDestroy()
1788 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1789 api_statuses_destroy('json');
1793 * Test the api_statuses_destroy() function without an authenticated user.
1797 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1799 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1800 $_SESSION['authenticated'] = false;
1801 api_statuses_destroy('json');
1805 * Test the api_statuses_destroy() function with an ID.
1809 public function testApiStatusesDestroyWithId()
1811 DI::args()->setArgv(['', '', '', 1]);
1812 $result = api_statuses_destroy('json');
1813 self::assertStatus($result['status']);
1817 * Test the api_statuses_mentions() function.
1821 public function testApiStatusesMentions()
1823 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1824 $_REQUEST['max_id'] = 10;
1825 $result = api_statuses_mentions('json');
1826 self::assertEmpty($result['status']);
1827 // We should test with mentions in the database.
1831 * Test the api_statuses_mentions() function with a negative page parameter.
1835 public function testApiStatusesMentionsWithNegativePage()
1837 $_REQUEST['page'] = -2;
1838 $result = api_statuses_mentions('json');
1839 self::assertEmpty($result['status']);
1843 * Test the api_statuses_mentions() function with an unallowed user.
1847 public function testApiStatusesMentionsWithUnallowedUser()
1849 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1850 $_SESSION['allow_api'] = false;
1851 $_GET['screen_name'] = $this->selfUser['nick'];
1852 api_statuses_mentions('json');
1856 * Test the api_statuses_mentions() function with an RSS result.
1860 public function testApiStatusesMentionsWithRss()
1862 $result = api_statuses_mentions('rss');
1863 self::assertXml($result, 'statuses');
1867 * Test the api_statuses_user_timeline() function.
1871 public function testApiStatusesUserTimeline()
1873 $_REQUEST['max_id'] = 10;
1874 $_REQUEST['exclude_replies'] = true;
1875 $_REQUEST['conversation_id'] = 1;
1876 $result = api_statuses_user_timeline('json');
1877 self::assertNotEmpty($result['status']);
1878 foreach ($result['status'] as $status) {
1879 self::assertStatus($status);
1884 * Test the api_statuses_user_timeline() function with a negative page parameter.
1888 public function testApiStatusesUserTimelineWithNegativePage()
1890 $_REQUEST['page'] = -2;
1891 $result = api_statuses_user_timeline('json');
1892 self::assertNotEmpty($result['status']);
1893 foreach ($result['status'] as $status) {
1894 self::assertStatus($status);
1899 * Test the api_statuses_user_timeline() function with an RSS result.
1903 public function testApiStatusesUserTimelineWithRss()
1905 $result = api_statuses_user_timeline('rss');
1906 self::assertXml($result, 'statuses');
1910 * Test the api_statuses_user_timeline() function with an unallowed user.
1914 public function testApiStatusesUserTimelineWithUnallowedUser()
1916 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1917 $_SESSION['allow_api'] = false;
1918 $_GET['screen_name'] = $this->selfUser['nick'];
1919 api_statuses_user_timeline('json');
1923 * Test the api_favorites_create_destroy() function.
1927 public function testApiFavoritesCreateDestroy()
1929 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1930 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1931 api_favorites_create_destroy('json');
1935 * Test the api_favorites_create_destroy() function with an invalid ID.
1939 public function testApiFavoritesCreateDestroyWithInvalidId()
1941 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1942 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1943 api_favorites_create_destroy('json');
1947 * Test the api_favorites_create_destroy() function with an invalid action.
1951 public function testApiFavoritesCreateDestroyWithInvalidAction()
1953 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1954 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1955 $_REQUEST['id'] = 1;
1956 api_favorites_create_destroy('json');
1960 * Test the api_favorites_create_destroy() function with the create action.
1964 public function testApiFavoritesCreateDestroyWithCreateAction()
1966 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1967 $_REQUEST['id'] = 3;
1968 $result = api_favorites_create_destroy('json');
1969 self::assertStatus($result['status']);
1973 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1977 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1979 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1980 $_REQUEST['id'] = 3;
1981 $result = api_favorites_create_destroy('rss');
1982 self::assertXml($result, 'status');
1986 * Test the api_favorites_create_destroy() function with the destroy action.
1990 public function testApiFavoritesCreateDestroyWithDestroyAction()
1992 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1993 $_REQUEST['id'] = 3;
1994 $result = api_favorites_create_destroy('json');
1995 self::assertStatus($result['status']);
1999 * Test the api_favorites_create_destroy() function without an authenticated user.
2003 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2005 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2006 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2007 $_SESSION['authenticated'] = false;
2008 api_favorites_create_destroy('json');
2012 * Test the api_favorites() function.
2016 public function testApiFavorites()
2018 $_REQUEST['page'] = -1;
2019 $_REQUEST['max_id'] = 10;
2020 $result = api_favorites('json');
2021 foreach ($result['status'] as $status) {
2022 self::assertStatus($status);
2027 * Test the api_favorites() function with an RSS result.
2031 public function testApiFavoritesWithRss()
2033 $result = api_favorites('rss');
2034 self::assertXml($result, 'statuses');
2038 * Test the api_favorites() function with an unallowed user.
2042 public function testApiFavoritesWithUnallowedUser()
2044 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2045 $_SESSION['allow_api'] = false;
2046 $_GET['screen_name'] = $this->selfUser['nick'];
2047 api_favorites('json');
2051 * Test the api_format_messages() function.
2055 public function testApiFormatMessages()
2057 $result = api_format_messages(
2058 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2059 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2060 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2062 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2063 self::assertEquals(1, $result['id']);
2064 self::assertEquals(2, $result['recipient_id']);
2065 self::assertEquals(3, $result['sender_id']);
2066 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2067 self::assertEquals('sender_name', $result['sender_screen_name']);
2071 * Test the api_format_messages() function with HTML.
2075 public function testApiFormatMessagesWithHtmlText()
2077 $_GET['getText'] = 'html';
2078 $result = api_format_messages(
2079 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2080 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2081 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2083 self::assertEquals('item_title', $result['title']);
2084 self::assertEquals('<strong>item_body</strong>', $result['text']);
2088 * Test the api_format_messages() function with plain text.
2092 public function testApiFormatMessagesWithPlainText()
2094 $_GET['getText'] = 'plain';
2095 $result = api_format_messages(
2096 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2097 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2098 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2100 self::assertEquals('item_title', $result['title']);
2101 self::assertEquals('item_body', $result['text']);
2105 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2109 public function testApiFormatMessagesWithoutUserObjects()
2111 $_GET['getUserObjects'] = 'false';
2112 $result = api_format_messages(
2113 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2114 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2115 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2117 self::assertTrue(!isset($result['sender']));
2118 self::assertTrue(!isset($result['recipient']));
2122 * Test the api_convert_item() function.
2126 public function testApiConvertItem()
2128 $result = api_convert_item(
2130 'network' => 'feed',
2131 'title' => 'item_title',
2133 // We need a long string to test that it is correctly cut
2134 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2135 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2136 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2137 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2138 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2139 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2140 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2141 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2142 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2143 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2144 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2145 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2146 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2147 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2148 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2149 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2150 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2151 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2152 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2153 'repellat officia illum quos impedit quam iste esse unde qui ' .
2154 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2155 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2156 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2157 'plink' => 'item_plink'
2160 self::assertStringStartsWith('item_title', $result['text']);
2161 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2165 * Test the api_convert_item() function with an empty item body.
2169 public function testApiConvertItemWithoutBody()
2171 $result = api_convert_item(
2173 'network' => 'feed',
2174 'title' => 'item_title',
2177 'plink' => 'item_plink'
2180 self::assertEquals("item_title", $result['text']);
2181 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2185 * Test the api_convert_item() function with the title in the body.
2189 public function testApiConvertItemWithTitleInBody()
2191 $result = api_convert_item(
2193 'title' => 'item_title',
2194 'body' => 'item_title item_body',
2198 self::assertEquals('item_title item_body', $result['text']);
2199 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2203 * Test the api_get_attachments() function.
2207 public function testApiGetAttachments()
2210 self::assertEmpty(api_get_attachments($body, 0));
2214 * Test the api_get_attachments() function with an img tag.
2218 public function testApiGetAttachmentsWithImage()
2220 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2221 self::assertIsArray(api_get_attachments($body, 0));
2225 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2229 public function testApiGetAttachmentsWithImageAndAndStatus()
2231 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2232 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2233 self::assertIsArray(api_get_attachments($body, 0));
2237 * Test the api_get_entitities() function.
2241 public function testApiGetEntitities()
2244 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2248 * Test the api_get_entitities() function with the include_entities parameter.
2252 public function testApiGetEntititiesWithIncludeEntities()
2254 $_REQUEST['include_entities'] = 'true';
2256 $result = api_get_entitities($text, 'bbcode', 0);
2257 self::assertIsArray($result['hashtags']);
2258 self::assertIsArray($result['symbols']);
2259 self::assertIsArray($result['urls']);
2260 self::assertIsArray($result['user_mentions']);
2264 * Test the api_format_items_embeded_images() function.
2268 public function testApiFormatItemsEmbededImages()
2271 'text ' . DI::baseUrl() . '/display/item_guid',
2272 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2277 * Test the api_contactlink_to_array() function.
2281 public function testApiContactlinkToArray()
2288 api_contactlink_to_array('text')
2293 * Test the api_contactlink_to_array() function with an URL.
2297 public function testApiContactlinkToArrayWithUrl()
2301 'name' => ['link_text'],
2304 api_contactlink_to_array('text <a href="url">link_text</a>')
2309 * Test the api_format_items_activities() function.
2313 public function testApiFormatItemsActivities()
2315 $item = ['uid' => 0, 'uri' => ''];
2316 $result = api_format_items_activities($item);
2317 self::assertArrayHasKey('like', $result);
2318 self::assertArrayHasKey('dislike', $result);
2319 self::assertArrayHasKey('attendyes', $result);
2320 self::assertArrayHasKey('attendno', $result);
2321 self::assertArrayHasKey('attendmaybe', $result);
2325 * Test the api_format_items_activities() function with an XML result.
2329 public function testApiFormatItemsActivitiesWithXml()
2331 $item = ['uid' => 0, 'uri' => ''];
2332 $result = api_format_items_activities($item, 'xml');
2333 self::assertArrayHasKey('friendica:like', $result);
2334 self::assertArrayHasKey('friendica:dislike', $result);
2335 self::assertArrayHasKey('friendica:attendyes', $result);
2336 self::assertArrayHasKey('friendica:attendno', $result);
2337 self::assertArrayHasKey('friendica:attendmaybe', $result);
2341 * Test the api_format_items() function.
2342 * @doesNotPerformAssertions
2344 public function testApiFormatItems()
2348 'item_network' => 'item_network',
2354 'author-network' => Protocol::DFRN,
2355 'author-link' => 'http://localhost/profile/othercontact',
2359 $result = api_format_items($items, ['id' => 0], true);
2360 foreach ($result as $status) {
2361 self::assertStatus($status);
2366 * Test the api_format_items() function with an XML result.
2367 * @doesNotPerformAssertions
2369 public function testApiFormatItemsWithXml()
2377 'author-network' => Protocol::DFRN,
2378 'author-link' => 'http://localhost/profile/othercontact',
2382 $result = api_format_items($items, ['id' => 0], true, 'xml');
2383 foreach ($result as $status) {
2384 self::assertStatus($status);
2389 * Test the api_lists_list() function.
2393 public function testApiListsList()
2395 $result = api_lists_list('json');
2396 self::assertEquals(['lists_list' => []], $result);
2400 * Test the api_lists_ownerships() function.
2404 public function testApiListsOwnerships()
2406 $result = api_lists_ownerships('json');
2407 foreach ($result['lists']['lists'] as $list) {
2408 self::assertList($list);
2413 * Test the api_lists_ownerships() function without an authenticated user.
2417 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2419 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2420 $_SESSION['authenticated'] = false;
2421 api_lists_ownerships('json');
2425 * Test the api_lists_statuses() function.
2429 public function testApiListsStatuses()
2431 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2432 api_lists_statuses('json');
2436 * Test the api_lists_statuses() function with a list ID.
2437 * @doesNotPerformAssertions
2439 public function testApiListsStatusesWithListId()
2441 $_REQUEST['list_id'] = 1;
2442 $_REQUEST['page'] = -1;
2443 $_REQUEST['max_id'] = 10;
2444 $result = api_lists_statuses('json');
2445 foreach ($result['status'] as $status) {
2446 self::assertStatus($status);
2451 * Test the api_lists_statuses() function with a list ID and a RSS result.
2455 public function testApiListsStatusesWithListIdAndRss()
2457 $_REQUEST['list_id'] = 1;
2458 $result = api_lists_statuses('rss');
2459 self::assertXml($result, 'statuses');
2463 * Test the api_lists_statuses() function with an unallowed user.
2467 public function testApiListsStatusesWithUnallowedUser()
2469 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2470 $_SESSION['allow_api'] = false;
2471 $_GET['screen_name'] = $this->selfUser['nick'];
2472 api_lists_statuses('json');
2476 * Test the api_statuses_f() function.
2480 public function testApiStatusesFWithFriends()
2483 $result = api_statuses_f('friends');
2484 self::assertArrayHasKey('user', $result);
2488 * Test the api_statuses_f() function.
2492 public function testApiStatusesFWithFollowers()
2494 $result = api_statuses_f('followers');
2495 self::assertArrayHasKey('user', $result);
2499 * Test the api_statuses_f() function.
2503 public function testApiStatusesFWithBlocks()
2505 $result = api_statuses_f('blocks');
2506 self::assertArrayHasKey('user', $result);
2510 * Test the api_statuses_f() function.
2514 public function testApiStatusesFWithIncoming()
2516 $result = api_statuses_f('incoming');
2517 self::assertArrayHasKey('user', $result);
2521 * Test the api_statuses_f() function an undefined cursor GET variable.
2525 public function testApiStatusesFWithUndefinedCursor()
2527 $_GET['cursor'] = 'undefined';
2528 self::assertFalse(api_statuses_f('friends'));
2532 * Test the api_statuses_friends() function.
2536 public function testApiStatusesFriends()
2538 $result = api_statuses_friends('json');
2539 self::assertArrayHasKey('user', $result);
2543 * Test the api_statuses_friends() function an undefined cursor GET variable.
2547 public function testApiStatusesFriendsWithUndefinedCursor()
2549 $_GET['cursor'] = 'undefined';
2550 self::assertFalse(api_statuses_friends('json'));
2554 * Test the api_statuses_followers() function.
2558 public function testApiStatusesFollowers()
2560 $result = api_statuses_followers('json');
2561 self::assertArrayHasKey('user', $result);
2565 * Test the api_statuses_followers() function an undefined cursor GET variable.
2569 public function testApiStatusesFollowersWithUndefinedCursor()
2571 $_GET['cursor'] = 'undefined';
2572 self::assertFalse(api_statuses_followers('json'));
2576 * Test the api_blocks_list() function.
2580 public function testApiBlocksList()
2582 $result = api_blocks_list('json');
2583 self::assertArrayHasKey('user', $result);
2587 * Test the api_blocks_list() function an undefined cursor GET variable.
2591 public function testApiBlocksListWithUndefinedCursor()
2593 $_GET['cursor'] = 'undefined';
2594 self::assertFalse(api_blocks_list('json'));
2598 * Test the api_friendships_incoming() function.
2602 public function testApiFriendshipsIncoming()
2604 $result = api_friendships_incoming('json');
2605 self::assertArrayHasKey('id', $result);
2609 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2613 public function testApiFriendshipsIncomingWithUndefinedCursor()
2615 $_GET['cursor'] = 'undefined';
2616 self::assertFalse(api_friendships_incoming('json'));
2620 * Test the api_statusnet_config() function.
2624 public function testApiStatusnetConfig()
2626 $result = api_statusnet_config('json');
2627 self::assertEquals('localhost', $result['config']['site']['server']);
2628 self::assertEquals('default', $result['config']['site']['theme']);
2629 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2630 self::assertTrue($result['config']['site']['fancy']);
2631 self::assertEquals('en', $result['config']['site']['language']);
2632 self::assertEquals('UTC', $result['config']['site']['timezone']);
2633 self::assertEquals(200000, $result['config']['site']['textlimit']);
2634 self::assertEquals('false', $result['config']['site']['private']);
2635 self::assertEquals('false', $result['config']['site']['ssl']);
2636 self::assertEquals(30, $result['config']['site']['shorturllength']);
2640 * Test the api_direct_messages_new() function.
2644 public function testApiDirectMessagesNew()
2646 $result = api_direct_messages_new('json');
2647 self::assertNull($result);
2651 * Test the api_direct_messages_new() function without an authenticated user.
2655 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2657 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2658 $_SESSION['authenticated'] = false;
2659 api_direct_messages_new('json');
2663 * Test the api_direct_messages_new() function with an user ID.
2667 public function testApiDirectMessagesNewWithUserId()
2669 $_POST['text'] = 'message_text';
2670 $_POST['user_id'] = $this->otherUser['id'];
2671 $result = api_direct_messages_new('json');
2672 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2676 * Test the api_direct_messages_new() function with a screen name.
2680 public function testApiDirectMessagesNewWithScreenName()
2682 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2683 $_POST['text'] = 'message_text';
2684 $_POST['screen_name'] = $this->friendUser['nick'];
2685 $result = api_direct_messages_new('json');
2686 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2687 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2688 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2692 * Test the api_direct_messages_new() function with a title.
2696 public function testApiDirectMessagesNewWithTitle()
2698 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2699 $_POST['text'] = 'message_text';
2700 $_POST['screen_name'] = $this->friendUser['nick'];
2701 $_REQUEST['title'] = 'message_title';
2702 $result = api_direct_messages_new('json');
2703 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2704 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2705 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2706 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2710 * Test the api_direct_messages_new() function with an RSS result.
2714 public function testApiDirectMessagesNewWithRss()
2716 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2717 $_POST['text'] = 'message_text';
2718 $_POST['screen_name'] = $this->friendUser['nick'];
2719 $result = api_direct_messages_new('rss');
2720 self::assertXml($result, 'direct-messages');
2724 * Test the api_direct_messages_destroy() function.
2728 public function testApiDirectMessagesDestroy()
2730 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2731 api_direct_messages_destroy('json');
2735 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2739 public function testApiDirectMessagesDestroyWithVerbose()
2741 $_GET['friendica_verbose'] = 'true';
2742 $result = api_direct_messages_destroy('json');
2746 'result' => 'error',
2747 'message' => 'message id or parenturi not specified'
2755 * Test the api_direct_messages_destroy() function without an authenticated user.
2759 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2761 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2762 $_SESSION['authenticated'] = false;
2763 api_direct_messages_destroy('json');
2767 * Test the api_direct_messages_destroy() function with a non-zero ID.
2771 public function testApiDirectMessagesDestroyWithId()
2773 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2774 $_REQUEST['id'] = 1;
2775 api_direct_messages_destroy('json');
2779 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2783 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2785 $_REQUEST['id'] = 1;
2786 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2787 $_GET['friendica_verbose'] = 'true';
2788 $result = api_direct_messages_destroy('json');
2792 'result' => 'error',
2793 'message' => 'message id not in database'
2801 * Test the api_direct_messages_destroy() function with a non-zero ID.
2805 public function testApiDirectMessagesDestroyWithCorrectId()
2807 $this->markTestIncomplete('We need to add a dataset for this.');
2811 * Test the api_direct_messages_box() function.
2815 public function testApiDirectMessagesBoxWithSentbox()
2817 $_REQUEST['page'] = -1;
2818 $_REQUEST['max_id'] = 10;
2819 $result = api_direct_messages_box('json', 'sentbox', 'false');
2820 self::assertArrayHasKey('direct_message', $result);
2824 * Test the api_direct_messages_box() function.
2828 public function testApiDirectMessagesBoxWithConversation()
2830 $result = api_direct_messages_box('json', 'conversation', 'false');
2831 self::assertArrayHasKey('direct_message', $result);
2835 * Test the api_direct_messages_box() function.
2839 public function testApiDirectMessagesBoxWithAll()
2841 $result = api_direct_messages_box('json', 'all', 'false');
2842 self::assertArrayHasKey('direct_message', $result);
2846 * Test the api_direct_messages_box() function.
2850 public function testApiDirectMessagesBoxWithInbox()
2852 $result = api_direct_messages_box('json', 'inbox', 'false');
2853 self::assertArrayHasKey('direct_message', $result);
2857 * Test the api_direct_messages_box() function.
2861 public function testApiDirectMessagesBoxWithVerbose()
2863 $result = api_direct_messages_box('json', 'sentbox', 'true');
2867 'result' => 'error',
2868 'message' => 'no mails available'
2876 * Test the api_direct_messages_box() function with a RSS result.
2880 public function testApiDirectMessagesBoxWithRss()
2882 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2883 self::assertXml($result, 'direct-messages');
2887 * Test the api_direct_messages_box() function without an authenticated user.
2891 public function testApiDirectMessagesBoxWithUnallowedUser()
2893 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2894 $_SESSION['allow_api'] = false;
2895 $_GET['screen_name'] = $this->selfUser['nick'];
2896 api_direct_messages_box('json', 'sentbox', 'false');
2900 * Test the api_direct_messages_sentbox() function.
2904 public function testApiDirectMessagesSentbox()
2906 $result = api_direct_messages_sentbox('json');
2907 self::assertArrayHasKey('direct_message', $result);
2911 * Test the api_direct_messages_inbox() function.
2915 public function testApiDirectMessagesInbox()
2917 $result = api_direct_messages_inbox('json');
2918 self::assertArrayHasKey('direct_message', $result);
2922 * Test the api_direct_messages_all() function.
2926 public function testApiDirectMessagesAll()
2928 $result = api_direct_messages_all('json');
2929 self::assertArrayHasKey('direct_message', $result);
2933 * Test the api_direct_messages_conversation() function.
2937 public function testApiDirectMessagesConversation()
2939 $result = api_direct_messages_conversation('json');
2940 self::assertArrayHasKey('direct_message', $result);
2944 * Test the api_oauth_request_token() function.
2948 public function testApiOauthRequestToken()
2950 $this->markTestIncomplete('exit() kills phpunit as well');
2954 * Test the api_oauth_access_token() function.
2958 public function testApiOauthAccessToken()
2960 $this->markTestIncomplete('exit() kills phpunit as well');
2964 * Test the api_fr_photos_list() function.
2968 public function testApiFrPhotosList()
2970 $result = api_fr_photos_list('json');
2971 self::assertArrayHasKey('photo', $result);
2975 * Test the api_fr_photos_list() function without an authenticated user.
2979 public function testApiFrPhotosListWithoutAuthenticatedUser()
2981 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2982 $_SESSION['authenticated'] = false;
2983 api_fr_photos_list('json');
2987 * Test the api_fr_photo_create_update() function.
2989 public function testApiFrPhotoCreateUpdate()
2991 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2992 api_fr_photo_create_update('json');
2996 * Test the api_fr_photo_create_update() function without an authenticated user.
3000 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3002 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3003 $_SESSION['authenticated'] = false;
3004 api_fr_photo_create_update('json');
3008 * Test the api_fr_photo_create_update() function with an album name.
3012 public function testApiFrPhotoCreateUpdateWithAlbum()
3014 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3015 $_REQUEST['album'] = 'album_name';
3016 api_fr_photo_create_update('json');
3020 * Test the api_fr_photo_create_update() function with the update mode.
3024 public function testApiFrPhotoCreateUpdateWithUpdate()
3026 $this->markTestIncomplete('We need to create a dataset for this');
3030 * Test the api_fr_photo_create_update() function with an uploaded file.
3034 public function testApiFrPhotoCreateUpdateWithFile()
3036 $this->markTestIncomplete();
3040 * Test the api_fr_photo_detail() function.
3044 public function testApiFrPhotoDetail()
3046 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3047 api_fr_photo_detail('json');
3051 * Test the api_fr_photo_detail() function without an authenticated user.
3055 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3057 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3058 $_SESSION['authenticated'] = false;
3059 api_fr_photo_detail('json');
3063 * Test the api_fr_photo_detail() function with a photo ID.
3067 public function testApiFrPhotoDetailWithPhotoId()
3069 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3070 $_REQUEST['photo_id'] = 1;
3071 api_fr_photo_detail('json');
3075 * Test the api_fr_photo_detail() function with a correct photo ID.
3079 public function testApiFrPhotoDetailCorrectPhotoId()
3081 $this->markTestIncomplete('We need to create a dataset for this.');
3085 * Test the api_account_update_profile_image() function.
3089 public function testApiAccountUpdateProfileImage()
3091 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3092 api_account_update_profile_image('json');
3096 * Test the api_account_update_profile_image() function without an authenticated user.
3100 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3102 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3103 $_SESSION['authenticated'] = false;
3104 api_account_update_profile_image('json');
3108 * Test the api_account_update_profile_image() function with an uploaded file.
3112 public function testApiAccountUpdateProfileImageWithUpload()
3114 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3115 $this->markTestIncomplete();
3120 * Test the api_account_update_profile() function.
3124 public function testApiAccountUpdateProfile()
3126 $_POST['name'] = 'new_name';
3127 $_POST['description'] = 'new_description';
3128 $result = api_account_update_profile('json');
3129 // We can't use assertSelfUser() here because the user object is missing some properties.
3130 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3131 self::assertEquals('DFRN', $result['user']['location']);
3132 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3133 self::assertEquals('dfrn', $result['user']['network']);
3134 self::assertEquals('new_name', $result['user']['name']);
3135 self::assertEquals('new_description', $result['user']['description']);
3139 * Test the check_acl_input() function.
3143 public function testCheckAclInput()
3145 $result = check_acl_input('<aclstring>');
3146 // Where does this result come from?
3147 self::assertEquals(1, $result);
3151 * Test the check_acl_input() function with an empty ACL string.
3155 public function testCheckAclInputWithEmptyAclString()
3157 $result = check_acl_input(' ');
3158 self::assertFalse($result);
3162 * Test the save_media_to_database() function.
3166 public function testSaveMediaToDatabase()
3168 $this->markTestIncomplete();
3172 * Test the post_photo_item() function.
3176 public function testPostPhotoItem()
3178 $this->markTestIncomplete();
3182 * Test the prepare_photo_data() function.
3186 public function testPreparePhotoData()
3188 $this->markTestIncomplete();
3192 * Test the api_share_as_retweet() function with a valid item.
3196 public function testApiShareAsRetweetWithValidItem()
3198 $this->markTestIncomplete();
3202 * Test the api_in_reply_to() function.
3206 public function testApiInReplyTo()
3208 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3209 self::assertArrayHasKey('status_id', $result);
3210 self::assertArrayHasKey('user_id', $result);
3211 self::assertArrayHasKey('status_id_str', $result);
3212 self::assertArrayHasKey('user_id_str', $result);
3213 self::assertArrayHasKey('screen_name', $result);
3217 * Test the api_in_reply_to() function with a valid item.
3221 public function testApiInReplyToWithValidItem()
3223 $this->markTestIncomplete();
3227 * Test the api_clean_plain_items() function.
3231 public function testApiCleanPlainItems()
3233 $_REQUEST['include_entities'] = 'true';
3234 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3235 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3239 * Test the api_best_nickname() function.
3243 public function testApiBestNickname()
3246 $result = api_best_nickname($contacts);
3247 self::assertNull($result);
3251 * Test the api_best_nickname() function with contacts.
3255 public function testApiBestNicknameWithContacts()
3257 $this->markTestIncomplete();
3261 * Test the api_friendica_group_show() function.
3265 public function testApiFriendicaGroupShow()
3267 $this->markTestIncomplete();
3271 * Test the api_friendica_group_delete() function.
3275 public function testApiFriendicaGroupDelete()
3277 $this->markTestIncomplete();
3281 * Test the api_lists_destroy() function.
3285 public function testApiListsDestroy()
3287 $this->markTestIncomplete();
3291 * Test the group_create() function.
3295 public function testGroupCreate()
3297 $this->markTestIncomplete();
3301 * Test the api_friendica_group_create() function.
3305 public function testApiFriendicaGroupCreate()
3307 $this->markTestIncomplete();
3311 * Test the api_lists_create() function.
3315 public function testApiListsCreate()
3317 $this->markTestIncomplete();
3321 * Test the api_friendica_group_update() function.
3325 public function testApiFriendicaGroupUpdate()
3327 $this->markTestIncomplete();
3331 * Test the api_lists_update() function.
3335 public function testApiListsUpdate()
3337 $this->markTestIncomplete();
3341 * Test the api_friendica_activity() function.
3345 public function testApiFriendicaActivity()
3347 $this->markTestIncomplete();
3351 * Test the api_friendica_notification_seen() function.
3355 public function testApiFriendicaNotificationSeen()
3357 $this->markTestIncomplete();
3361 * Test the api_friendica_direct_messages_setseen() function.
3365 public function testApiFriendicaDirectMessagesSetseen()
3367 $this->markTestIncomplete();
3371 * Test the api_friendica_direct_messages_search() function.
3375 public function testApiFriendicaDirectMessagesSearch()
3377 $this->markTestIncomplete();