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']
117 BasicAuth::setCurrentUserID($this->selfUser['id']);
121 * Assert that an user array contains expected keys.
123 * @param array $user User array
127 private function assertSelfUser(array $user)
129 self::assertEquals($this->selfUser['id'], $user['uid']);
130 self::assertEquals($this->selfUser['id'], $user['cid']);
131 self::assertEquals(1, $user['self']);
132 self::assertEquals('DFRN', $user['location']);
133 self::assertEquals($this->selfUser['name'], $user['name']);
134 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
135 self::assertEquals('dfrn', $user['network']);
136 self::assertTrue($user['verified']);
140 * Assert that an user array contains expected keys.
142 * @param array $user User array
146 private function assertOtherUser(array $user = [])
148 self::assertEquals($this->otherUser['id'], $user['id']);
149 self::assertEquals($this->otherUser['id'], $user['id_str']);
150 self::assertEquals(0, $user['self']);
151 self::assertEquals($this->otherUser['name'], $user['name']);
152 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
153 self::assertFalse($user['verified']);
157 * Assert that a status array contains expected keys.
159 * @param array $status Status array
163 private function assertStatus(array $status = [])
165 self::assertIsString($status['text'] ?? '');
166 self::assertIsInt($status['id'] ?? '');
167 // We could probably do more checks here.
171 * Assert that a list array contains expected keys.
173 * @param array $list List array
177 private function assertList(array $list = [])
179 self::assertIsString($list['name']);
180 self::assertIsInt($list['id']);
181 self::assertIsString('string', $list['id_str']);
182 self::assertContains($list['mode'], ['public', 'private']);
183 // We could probably do more checks here.
187 * Assert that the string is XML and contain the root element.
189 * @param string $result XML string
190 * @param string $root_element Root element name
194 private function assertXml($result = '', $root_element = '')
196 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
197 self::assertStringContainsString('<' . $root_element, $result);
198 // We could probably do more checks here.
202 * Get the path to a temporary empty PNG image.
204 * @return string Path
206 private function getTempImage()
208 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
212 // Empty 1x1 px PNG image
213 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
221 * Test the api_user() function.
225 public function testApiUser()
227 self::assertEquals($this->selfUser['id'], api_user());
231 * Test the api_user() function with an unallowed user.
235 public function testApiUserWithUnallowedUser()
237 $_SESSION = ['allow_api' => false];
238 self::assertEquals(false, api_user());
242 * Test the api_source() function.
246 public function testApiSource()
248 self::assertEquals('api', api_source());
252 * Test the api_source() function with a Twidere user agent.
256 public function testApiSourceWithTwidere()
258 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
259 self::assertEquals('Twidere', api_source());
263 * Test the api_source() function with a GET parameter.
267 public function testApiSourceWithGet()
269 $_GET['source'] = 'source_name';
270 self::assertEquals('source_name', api_source());
274 * Test the api_date() function.
278 public function testApiDate()
280 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
284 * Test the api_register_func() function.
288 public function testApiRegisterFunc()
300 self::assertTrue($API['api_path']['auth']);
301 self::assertEquals('method', $API['api_path']['method']);
302 self::assertTrue(is_callable($API['api_path']['func']));
306 * Test the BasicAuth::getCurrentUserID() function without any login.
308 * @runInSeparateProcess
309 * @preserveGlobalState disabled
310 * @preserveGlobalState disabled
312 public function testApiLoginWithoutLogin()
314 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
315 BasicAuth::getCurrentUserID(true);
319 * Test the BasicAuth::getCurrentUserID() function with a bad login.
321 * @runInSeparateProcess
322 * @preserveGlobalState disabled
323 * @preserveGlobalState disabled
325 public function testApiLoginWithBadLogin()
327 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
328 $_SERVER['PHP_AUTH_USER'] = 'user@server';
329 BasicAuth::getCurrentUserID(true);
333 * Test the BasicAuth::getCurrentUserID() function with oAuth.
337 public function testApiLoginWithOauth()
339 $this->markTestIncomplete('Can we test this easily?');
343 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
347 public function testApiLoginWithAddonAuth()
349 $this->markTestIncomplete('Can we test this easily?');
353 * Test the BasicAuth::getCurrentUserID() function with a correct login.
355 * @runInSeparateProcess
356 * @preserveGlobalState disabled
357 * @doesNotPerformAssertions
359 public function testApiLoginWithCorrectLogin()
361 $_SERVER['PHP_AUTH_USER'] = 'Test user';
362 $_SERVER['PHP_AUTH_PW'] = 'password';
363 BasicAuth::getCurrentUserID(true);
367 * Test the BasicAuth::getCurrentUserID() function with a remote user.
369 * @runInSeparateProcess
370 * @preserveGlobalState disabled
372 public function testApiLoginWithRemoteUser()
374 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
375 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
376 BasicAuth::getCurrentUserID(true);
380 * Test the api_check_method() function.
384 public function testApiCheckMethod()
386 self::assertFalse(api_check_method('method'));
390 * Test the api_check_method() function with a correct method.
394 public function testApiCheckMethodWithCorrectMethod()
396 $_SERVER['REQUEST_METHOD'] = 'method';
397 self::assertTrue(api_check_method('method'));
401 * Test the api_check_method() function with a wildcard.
405 public function testApiCheckMethodWithWildcard()
407 self::assertTrue(api_check_method('*'));
411 * Test the api_call() function.
413 * @runInSeparateProcess
414 * @preserveGlobalState disabled
416 public function testApiCall()
420 'method' => 'method',
421 'func' => function () {
422 return ['data' => ['some_data']];
425 $_SERVER['REQUEST_METHOD'] = 'method';
426 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
427 $_GET['callback'] = 'callback_name';
429 $args = DI::args()->determine($_SERVER, $_GET);
432 'callback_name(["some_data"])',
433 api_call($this->app, $args)
438 * Test the api_call() function with the profiled enabled.
440 * @runInSeparateProcess
441 * @preserveGlobalState disabled
443 public function testApiCallWithProfiler()
447 'method' => 'method',
448 'func' => function () {
449 return ['data' => ['some_data']];
453 $_SERVER['REQUEST_METHOD'] = 'method';
454 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
456 $args = DI::args()->determine($_SERVER, $_GET);
458 $this->config->set('system', 'profiler', true);
459 $this->config->set('rendertime', 'callstack', true);
460 $this->app->callstack = [
461 'database' => ['some_function' => 200],
462 'database_write' => ['some_function' => 200],
463 'cache' => ['some_function' => 200],
464 'cache_write' => ['some_function' => 200],
465 'network' => ['some_function' => 200]
470 api_call($this->app, $args)
475 * Test the api_call() function with a JSON result.
477 * @runInSeparateProcess
478 * @preserveGlobalState disabled
480 public function testApiCallWithJson()
484 'method' => 'method',
485 'func' => function () {
486 return ['data' => ['some_data']];
489 $_SERVER['REQUEST_METHOD'] = 'method';
490 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
492 $args = DI::args()->determine($_SERVER, $_GET);
496 api_call($this->app, $args)
501 * Test the api_call() function with an XML result.
503 * @runInSeparateProcess
504 * @preserveGlobalState disabled
506 public function testApiCallWithXml()
510 'method' => 'method',
511 'func' => function () {
515 $_SERVER['REQUEST_METHOD'] = 'method';
516 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
518 $args = DI::args()->determine($_SERVER, $_GET);
522 api_call($this->app, $args)
527 * Test the api_call() function with an RSS result.
529 * @runInSeparateProcess
530 * @preserveGlobalState disabled
532 public function testApiCallWithRss()
536 'method' => 'method',
537 'func' => function () {
541 $_SERVER['REQUEST_METHOD'] = 'method';
542 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
544 $args = DI::args()->determine($_SERVER, $_GET);
547 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
549 api_call($this->app, $args)
554 * Test the api_call() function with an Atom result.
556 * @runInSeparateProcess
557 * @preserveGlobalState disabled
559 public function testApiCallWithAtom()
563 'method' => 'method',
564 'func' => function () {
568 $_SERVER['REQUEST_METHOD'] = 'method';
569 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
571 $args = DI::args()->determine($_SERVER, $_GET);
574 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
576 api_call($this->app, $args)
581 * Test the api_rss_extra() function.
585 public function testApiRssExtra()
587 $user_info = ['url' => 'user_url', 'lang' => 'en'];
588 $result = api_rss_extra([], $user_info);
589 self::assertEquals($user_info, $result['$user']);
590 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
591 self::assertArrayHasKey('self', $result['$rss']);
592 self::assertArrayHasKey('base', $result['$rss']);
593 self::assertArrayHasKey('updated', $result['$rss']);
594 self::assertArrayHasKey('atom_updated', $result['$rss']);
595 self::assertArrayHasKey('language', $result['$rss']);
596 self::assertArrayHasKey('logo', $result['$rss']);
600 * Test the api_rss_extra() function without any user info.
604 public function testApiRssExtraWithoutUserInfo()
606 $result = api_rss_extra([], null);
607 self::assertIsArray($result['$user']);
608 self::assertArrayHasKey('alternate', $result['$rss']);
609 self::assertArrayHasKey('self', $result['$rss']);
610 self::assertArrayHasKey('base', $result['$rss']);
611 self::assertArrayHasKey('updated', $result['$rss']);
612 self::assertArrayHasKey('atom_updated', $result['$rss']);
613 self::assertArrayHasKey('language', $result['$rss']);
614 self::assertArrayHasKey('logo', $result['$rss']);
618 * Test the api_unique_id_to_nurl() function.
622 public function testApiUniqueIdToNurl()
624 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
628 * Test the api_unique_id_to_nurl() function with a correct ID.
632 public function testApiUniqueIdToNurlWithCorrectId()
634 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
638 * Test the api_get_user() function.
642 public function testApiGetUser()
644 $user = api_get_user();
645 self::assertSelfUser($user);
646 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
647 // self::assertEquals('6fdbe8', $user['profile_link_color']);
648 // self::assertEquals('ededed', $user['profile_background_color']);
652 * Test the api_get_user() function with a Frio schema.
656 public function testApiGetUserWithFrioSchema()
658 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
659 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
660 $user = api_get_user();
661 self::assertSelfUser($user);
662 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
663 // self::assertEquals('6fdbe8', $user['profile_link_color']);
664 // self::assertEquals('ededed', $user['profile_background_color']);
668 * Test the api_get_user() function with an empty Frio schema.
672 public function testApiGetUserWithEmptyFrioSchema()
674 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
675 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
676 $user = api_get_user();
677 self::assertSelfUser($user);
678 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
679 // self::assertEquals('6fdbe8', $user['profile_link_color']);
680 // self::assertEquals('ededed', $user['profile_background_color']);
684 * Test the api_get_user() function with a custom Frio schema.
688 public function testApiGetUserWithCustomFrioSchema()
690 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
691 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
692 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
693 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
694 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
695 $user = api_get_user();
696 self::assertSelfUser($user);
697 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
698 // self::assertEquals('123456', $user['profile_link_color']);
699 // self::assertEquals('123456', $user['profile_background_color']);
703 * Test the api_get_user() function with an user that is not allowed to use the API.
705 * @runInSeparateProcess
706 * @preserveGlobalState disabled
708 public function testApiGetUserWithoutApiUser()
710 $_SERVER['PHP_AUTH_USER'] = 'Test user';
711 $_SERVER['PHP_AUTH_PW'] = 'password';
712 $_SESSION['allow_api'] = false;
713 BasicAuth::setCurrentUserID();
714 self::assertFalse(api_get_user());
718 * Test the api_get_user() function with an user ID in a GET parameter.
722 public function testApiGetUserWithGetId()
724 $_GET['user_id'] = $this->otherUser['id'];
725 self::assertOtherUser(api_get_user());
729 * Test the api_get_user() function with a wrong user ID in a GET parameter.
733 public function testApiGetUserWithWrongGetId()
735 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
736 $_GET['user_id'] = $this->wrongUserId;
737 self::assertOtherUser(api_get_user());
741 * Test the api_get_user() function with an user name in a GET parameter.
745 public function testApiGetUserWithGetName()
747 $_GET['screen_name'] = $this->selfUser['nick'];
748 self::assertSelfUser(api_get_user());
752 * Test the api_get_user() function with a profile URL in a GET parameter.
756 public function testApiGetUserWithGetUrl()
758 $_GET['profileurl'] = $this->selfUser['nurl'];
759 self::assertSelfUser(api_get_user());
763 * Test the api_get_user() function with an user ID in the API path.
767 public function testApiGetUserWithNumericCalledApi()
770 $called_api = ['api_path'];
771 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
772 self::assertOtherUser(api_get_user());
776 * Test the api_get_user() function with the $called_api global variable.
780 public function testApiGetUserWithCalledApi()
783 $called_api = ['api', 'api_path'];
784 self::assertSelfUser(api_get_user());
788 * Test the api_get_user() function with a valid user.
792 public function testApiGetUserWithCorrectUser()
794 self::assertOtherUser(api_get_user($this->otherUser['id']));
798 * Test the api_get_user() function with a wrong user ID.
802 public function testApiGetUserWithWrongUser()
804 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
805 self::assertOtherUser(api_get_user($this->wrongUserId));
809 * Test the api_get_user() function with a 0 user ID.
813 public function testApiGetUserWithZeroUser()
815 self::assertSelfUser(api_get_user(0));
819 * Test the api_item_get_user() function.
823 public function testApiItemGetUser()
825 $users = api_item_get_user($this->app, []);
826 self::assertSelfUser($users[0]);
830 * Test the api_item_get_user() function with a different item parent.
834 public function testApiItemGetUserWithDifferentParent()
836 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
837 self::assertSelfUser($users[0]);
838 self::assertEquals($users[0], $users[1]);
842 * Test the Arrays::walkRecursive() function.
846 public function testApiWalkRecursive()
851 Arrays::walkRecursive(
854 // Should we test this with a callback that actually does something?
862 * Test the Arrays::walkRecursive() function with an array.
866 public function testApiWalkRecursiveWithArray()
868 $array = [['item1'], ['item2']];
871 Arrays::walkRecursive(
874 // Should we test this with a callback that actually does something?
882 * Test the BaseApi::reformatXML() function.
886 public function testApiReformatXml()
890 self::assertTrue(ApiResponse::reformatXML($item, $key));
891 self::assertEquals('true', $item);
895 * Test the BaseApi::reformatXML() function with a statusnet_api key.
899 public function testApiReformatXmlWithStatusnetKey()
902 $key = 'statusnet_api';
903 self::assertTrue(ApiResponse::reformatXML($item, $key));
904 self::assertEquals('statusnet:api', $key);
908 * Test the BaseApi::reformatXML() function with a friendica_api key.
912 public function testApiReformatXmlWithFriendicaKey()
915 $key = 'friendica_api';
916 self::assertTrue(ApiResponse::reformatXML($item, $key));
917 self::assertEquals('friendica:api', $key);
921 * Test the BaseApi::createXML() function.
925 public function testApiCreateXml()
928 '<?xml version="1.0"?>' . "\n" .
929 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
930 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
931 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
932 ' <data>some_data</data>' . "\n" .
933 '</root_element>' . "\n",
934 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
939 * Test the BaseApi::createXML() function without any XML namespace.
943 public function testApiCreateXmlWithoutNamespaces()
946 '<?xml version="1.0"?>' . "\n" .
948 ' <data>some_data</data>' . "\n" .
950 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
955 * Test the BaseApi::formatData() function.
959 public function testApiFormatData()
961 $data = ['some_data'];
962 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
966 * Test the BaseApi::formatData() function with an XML result.
970 public function testApiFormatDataWithXml()
973 '<?xml version="1.0"?>' . "\n" .
974 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
975 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
976 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
977 ' <data>some_data</data>' . "\n" .
978 '</root_element>' . "\n",
979 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
984 * Test the api_account_verify_credentials() function.
988 public function testApiAccountVerifyCredentials()
990 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
994 * Test the api_account_verify_credentials() function without an authenticated user.
998 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1000 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1001 $_SESSION['authenticated'] = false;
1002 api_account_verify_credentials('json');
1006 * Test the requestdata() function.
1010 public function testRequestdata()
1012 self::assertNull(requestdata('variable_name'));
1016 * Test the requestdata() function with a POST parameter.
1020 public function testRequestdataWithPost()
1022 $_POST['variable_name'] = 'variable_value';
1023 self::assertEquals('variable_value', requestdata('variable_name'));
1027 * Test the requestdata() function with a GET parameter.
1031 public function testRequestdataWithGet()
1033 $_GET['variable_name'] = 'variable_value';
1034 self::assertEquals('variable_value', requestdata('variable_name'));
1038 * Test the api_statuses_mediap() function.
1042 public function testApiStatusesMediap()
1044 DI::args()->setArgc(2);
1052 'tmp_name' => $this->getTempImage(),
1053 'name' => 'spacer.png',
1054 'type' => 'image/png'
1057 $_GET['status'] = '<b>Status content</b>';
1059 $result = api_statuses_mediap('json');
1060 self::assertStatus($result['status']);
1064 * Test the api_statuses_mediap() function without an authenticated user.
1068 public function testApiStatusesMediapWithoutAuthenticatedUser()
1070 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1071 $_SESSION['authenticated'] = false;
1072 BasicAuth::setCurrentUserID();
1073 api_statuses_mediap('json');
1077 * Test the api_statuses_update() function.
1081 public function testApiStatusesUpdate()
1083 $_GET['status'] = 'Status content #friendica';
1084 $_GET['in_reply_to_status_id'] = -1;
1093 'tmp_name' => $this->getTempImage(),
1094 'name' => 'spacer.png',
1095 'type' => 'image/png'
1099 $result = api_statuses_update('json');
1100 self::assertStatus($result['status']);
1104 * Test the api_statuses_update() function with an HTML status.
1108 public function testApiStatusesUpdateWithHtml()
1110 $_GET['htmlstatus'] = '<b>Status content</b>';
1112 $result = api_statuses_update('json');
1113 self::assertStatus($result['status']);
1117 * Test the api_statuses_update() function without an authenticated user.
1121 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1123 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1124 $_SESSION['authenticated'] = false;
1125 api_statuses_update('json');
1129 * Test the api_statuses_update() function with a parent status.
1133 public function testApiStatusesUpdateWithParent()
1135 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1139 * Test the api_statuses_update() function with a media_ids parameter.
1143 public function testApiStatusesUpdateWithMediaIds()
1145 $this->markTestIncomplete();
1149 * Test the api_statuses_update() function with the throttle limit reached.
1153 public function testApiStatusesUpdateWithDayThrottleReached()
1155 $this->markTestIncomplete();
1159 * Test the api_media_upload() function.
1160 * @runInSeparateProcess
1161 * @preserveGlobalState disabled
1163 public function testApiMediaUpload()
1165 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1170 * Test the api_media_upload() function without an authenticated user.
1174 public function testApiMediaUploadWithoutAuthenticatedUser()
1176 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1177 $_SESSION['authenticated'] = false;
1182 * Test the api_media_upload() function with an invalid uploaded media.
1186 public function testApiMediaUploadWithMedia()
1188 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1192 'tmp_name' => 'tmp_name'
1199 * Test the api_media_upload() function with an valid uploaded media.
1203 public function testApiMediaUploadWithValidMedia()
1211 'tmp_name' => $this->getTempImage(),
1212 'name' => 'spacer.png',
1213 'type' => 'image/png'
1217 DI::args()->setArgc(2);
1219 $result = api_media_upload();
1220 self::assertEquals('image/png', $result['media']['image']['image_type']);
1221 self::assertEquals(1, $result['media']['image']['w']);
1222 self::assertEquals(1, $result['media']['image']['h']);
1223 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1227 * Test the api_status_show() function.
1229 public function testApiStatusShowWithJson()
1231 $result = api_status_show('json', 1);
1232 self::assertStatus($result['status']);
1236 * Test the api_status_show() function with an XML result.
1238 public function testApiStatusShowWithXml()
1240 $result = api_status_show('xml', 1);
1241 self::assertXml($result, 'statuses');
1245 * Test the api_get_last_status() function
1247 public function testApiGetLastStatus()
1249 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1251 self::assertNotNull($item);
1255 * Test the api_users_show() function.
1259 public function testApiUsersShow()
1261 $result = api_users_show('json');
1262 // We can't use assertSelfUser() here because the user object is missing some properties.
1263 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1264 self::assertEquals('DFRN', $result['user']['location']);
1265 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1266 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1267 self::assertEquals('dfrn', $result['user']['network']);
1268 self::assertTrue($result['user']['verified']);
1272 * Test the api_users_show() function with an XML result.
1276 public function testApiUsersShowWithXml()
1278 $result = api_users_show('xml');
1279 self::assertXml($result, 'statuses');
1283 * Test the api_users_search() function.
1287 public function testApiUsersSearch()
1289 $_GET['q'] = 'othercontact';
1290 $result = api_users_search('json');
1291 self::assertOtherUser($result['users'][0]);
1295 * Test the api_users_search() function with an XML result.
1299 public function testApiUsersSearchWithXml()
1301 $_GET['q'] = 'othercontact';
1302 $result = api_users_search('xml');
1303 self::assertXml($result, 'users');
1307 * Test the api_users_search() function without a GET q parameter.
1311 public function testApiUsersSearchWithoutQuery()
1313 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1314 api_users_search('json');
1318 * Test the api_users_lookup() function.
1322 public function testApiUsersLookup()
1324 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1325 api_users_lookup('json');
1329 * Test the api_users_lookup() function with an user ID.
1333 public function testApiUsersLookupWithUserId()
1335 $_REQUEST['user_id'] = $this->otherUser['id'];
1336 $result = api_users_lookup('json');
1337 self::assertOtherUser($result['users'][0]);
1341 * Test the api_search() function.
1345 public function testApiSearch()
1347 $_REQUEST['q'] = 'reply';
1348 $_REQUEST['max_id'] = 10;
1349 $result = api_search('json');
1350 foreach ($result['status'] as $status) {
1351 self::assertStatus($status);
1352 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1357 * Test the api_search() function a count parameter.
1361 public function testApiSearchWithCount()
1363 $_REQUEST['q'] = 'reply';
1364 $_REQUEST['count'] = 20;
1365 $result = api_search('json');
1366 foreach ($result['status'] as $status) {
1367 self::assertStatus($status);
1368 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1373 * Test the api_search() function with an rpp parameter.
1377 public function testApiSearchWithRpp()
1379 $_REQUEST['q'] = 'reply';
1380 $_REQUEST['rpp'] = 20;
1381 $result = api_search('json');
1382 foreach ($result['status'] as $status) {
1383 self::assertStatus($status);
1384 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1389 * Test the api_search() function with an q parameter contains hashtag.
1390 * @doesNotPerformAssertions
1392 public function testApiSearchWithHashtag()
1394 $_REQUEST['q'] = '%23friendica';
1395 $result = api_search('json');
1396 foreach ($result['status'] as $status) {
1397 self::assertStatus($status);
1398 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1403 * Test the api_search() function with an exclude_replies parameter.
1404 * @doesNotPerformAssertions
1406 public function testApiSearchWithExcludeReplies()
1408 $_REQUEST['max_id'] = 10;
1409 $_REQUEST['exclude_replies'] = true;
1410 $_REQUEST['q'] = 'friendica';
1411 $result = api_search('json');
1412 foreach ($result['status'] as $status) {
1413 self::assertStatus($status);
1418 * Test the api_search() function without an authenticated user.
1422 public function testApiSearchWithUnallowedUser()
1424 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1425 $_SESSION['allow_api'] = false;
1426 $_GET['screen_name'] = $this->selfUser['nick'];
1427 BasicAuth::setCurrentUserID();
1432 * Test the api_search() function without any GET query parameter.
1436 public function testApiSearchWithoutQuery()
1438 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1443 * Test the api_statuses_home_timeline() function.
1447 public function testApiStatusesHomeTimeline()
1449 $_REQUEST['max_id'] = 10;
1450 $_REQUEST['exclude_replies'] = true;
1451 $_REQUEST['conversation_id'] = 1;
1452 $result = api_statuses_home_timeline('json');
1453 self::assertNotEmpty($result['status']);
1454 foreach ($result['status'] as $status) {
1455 self::assertStatus($status);
1460 * Test the api_statuses_home_timeline() function with a negative page parameter.
1464 public function testApiStatusesHomeTimelineWithNegativePage()
1466 $_REQUEST['page'] = -2;
1467 $result = api_statuses_home_timeline('json');
1468 self::assertNotEmpty($result['status']);
1469 foreach ($result['status'] as $status) {
1470 self::assertStatus($status);
1475 * Test the api_statuses_home_timeline() with an unallowed user.
1479 public function testApiStatusesHomeTimelineWithUnallowedUser()
1481 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1482 $_SESSION['allow_api'] = false;
1483 $_GET['screen_name'] = $this->selfUser['nick'];
1484 BasicAuth::setCurrentUserID();
1485 api_statuses_home_timeline('json');
1489 * Test the api_statuses_home_timeline() function with an RSS result.
1493 public function testApiStatusesHomeTimelineWithRss()
1495 $result = api_statuses_home_timeline('rss');
1496 self::assertXml($result, 'statuses');
1500 * Test the api_statuses_public_timeline() function.
1504 public function testApiStatusesPublicTimeline()
1506 $_REQUEST['max_id'] = 10;
1507 $_REQUEST['conversation_id'] = 1;
1508 $result = api_statuses_public_timeline('json');
1509 self::assertNotEmpty($result['status']);
1510 foreach ($result['status'] as $status) {
1511 self::assertStatus($status);
1516 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1520 public function testApiStatusesPublicTimelineWithExcludeReplies()
1522 $_REQUEST['max_id'] = 10;
1523 $_REQUEST['exclude_replies'] = true;
1524 $result = api_statuses_public_timeline('json');
1525 self::assertNotEmpty($result['status']);
1526 foreach ($result['status'] as $status) {
1527 self::assertStatus($status);
1532 * Test the api_statuses_public_timeline() function with a negative page parameter.
1536 public function testApiStatusesPublicTimelineWithNegativePage()
1538 $_REQUEST['page'] = -2;
1539 $result = api_statuses_public_timeline('json');
1540 self::assertNotEmpty($result['status']);
1541 foreach ($result['status'] as $status) {
1542 self::assertStatus($status);
1547 * Test the api_statuses_public_timeline() function with an unallowed user.
1551 public function testApiStatusesPublicTimelineWithUnallowedUser()
1553 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1554 $_SESSION['allow_api'] = false;
1555 $_GET['screen_name'] = $this->selfUser['nick'];
1556 BasicAuth::setCurrentUserID();
1557 api_statuses_public_timeline('json');
1561 * Test the api_statuses_public_timeline() function with an RSS result.
1565 public function testApiStatusesPublicTimelineWithRss()
1567 $result = api_statuses_public_timeline('rss');
1568 self::assertXml($result, 'statuses');
1572 * Test the api_statuses_networkpublic_timeline() function.
1576 public function testApiStatusesNetworkpublicTimeline()
1578 $_REQUEST['max_id'] = 10;
1579 $result = api_statuses_networkpublic_timeline('json');
1580 self::assertNotEmpty($result['status']);
1581 foreach ($result['status'] as $status) {
1582 self::assertStatus($status);
1587 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1591 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1593 $_REQUEST['page'] = -2;
1594 $result = api_statuses_networkpublic_timeline('json');
1595 self::assertNotEmpty($result['status']);
1596 foreach ($result['status'] as $status) {
1597 self::assertStatus($status);
1602 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1606 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1608 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1609 $_SESSION['allow_api'] = false;
1610 $_GET['screen_name'] = $this->selfUser['nick'];
1611 BasicAuth::setCurrentUserID();
1612 api_statuses_networkpublic_timeline('json');
1616 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1620 public function testApiStatusesNetworkpublicTimelineWithRss()
1622 $result = api_statuses_networkpublic_timeline('rss');
1623 self::assertXml($result, 'statuses');
1627 * Test the api_statuses_show() function.
1631 public function testApiStatusesShow()
1633 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1634 api_statuses_show('json');
1638 * Test the api_statuses_show() function with an ID.
1642 public function testApiStatusesShowWithId()
1644 DI::args()->setArgv(['', '', '', 1]);
1645 $result = api_statuses_show('json');
1646 self::assertStatus($result['status']);
1650 * Test the api_statuses_show() function with the conversation parameter.
1654 public function testApiStatusesShowWithConversation()
1656 DI::args()->setArgv(['', '', '', 1]);
1657 $_REQUEST['conversation'] = 1;
1658 $result = api_statuses_show('json');
1659 self::assertNotEmpty($result['status']);
1660 foreach ($result['status'] as $status) {
1661 self::assertStatus($status);
1666 * Test the api_statuses_show() function with an unallowed user.
1670 public function testApiStatusesShowWithUnallowedUser()
1672 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1673 $_SESSION['allow_api'] = false;
1674 $_GET['screen_name'] = $this->selfUser['nick'];
1675 BasicAuth::setCurrentUserID();
1676 api_statuses_show('json');
1680 * Test the api_conversation_show() function.
1684 public function testApiConversationShow()
1686 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1687 api_conversation_show('json');
1691 * Test the api_conversation_show() function with an ID.
1695 public function testApiConversationShowWithId()
1697 DI::args()->setArgv(['', '', '', 1]);
1698 $_REQUEST['max_id'] = 10;
1699 $_REQUEST['page'] = -2;
1700 $result = api_conversation_show('json');
1701 self::assertNotEmpty($result['status']);
1702 foreach ($result['status'] as $status) {
1703 self::assertStatus($status);
1708 * Test the api_conversation_show() function with an unallowed user.
1712 public function testApiConversationShowWithUnallowedUser()
1714 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1715 $_SESSION['allow_api'] = false;
1716 $_GET['screen_name'] = $this->selfUser['nick'];
1717 BasicAuth::setCurrentUserID();
1718 api_conversation_show('json');
1722 * Test the api_statuses_repeat() function.
1726 public function testApiStatusesRepeat()
1728 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1729 api_statuses_repeat('json');
1733 * Test the api_statuses_repeat() function without an authenticated user.
1737 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1739 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1740 $_SESSION['authenticated'] = false;
1741 api_statuses_repeat('json');
1745 * Test the api_statuses_repeat() function with an ID.
1749 public function testApiStatusesRepeatWithId()
1751 DI::args()->setArgv(['', '', '', 1]);
1752 $result = api_statuses_repeat('json');
1753 self::assertStatus($result['status']);
1755 // Also test with a shared status
1756 DI::args()->setArgv(['', '', '', 5]);
1757 $result = api_statuses_repeat('json');
1758 self::assertStatus($result['status']);
1762 * Test the api_statuses_destroy() function.
1766 public function testApiStatusesDestroy()
1768 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1769 api_statuses_destroy('json');
1773 * Test the api_statuses_destroy() function without an authenticated user.
1777 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1779 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1780 $_SESSION['authenticated'] = false;
1781 api_statuses_destroy('json');
1785 * Test the api_statuses_destroy() function with an ID.
1789 public function testApiStatusesDestroyWithId()
1791 DI::args()->setArgv(['', '', '', 1]);
1792 $result = api_statuses_destroy('json');
1793 self::assertStatus($result['status']);
1797 * Test the api_statuses_mentions() function.
1801 public function testApiStatusesMentions()
1803 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1804 $_REQUEST['max_id'] = 10;
1805 $result = api_statuses_mentions('json');
1806 self::assertEmpty($result['status']);
1807 // We should test with mentions in the database.
1811 * Test the api_statuses_mentions() function with a negative page parameter.
1815 public function testApiStatusesMentionsWithNegativePage()
1817 $_REQUEST['page'] = -2;
1818 $result = api_statuses_mentions('json');
1819 self::assertEmpty($result['status']);
1823 * Test the api_statuses_mentions() function with an unallowed user.
1827 public function testApiStatusesMentionsWithUnallowedUser()
1829 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1830 $_SESSION['allow_api'] = false;
1831 $_GET['screen_name'] = $this->selfUser['nick'];
1832 BasicAuth::setCurrentUserID();
1833 api_statuses_mentions('json');
1837 * Test the api_statuses_mentions() function with an RSS result.
1841 public function testApiStatusesMentionsWithRss()
1843 $result = api_statuses_mentions('rss');
1844 self::assertXml($result, 'statuses');
1848 * Test the api_statuses_user_timeline() function.
1852 public function testApiStatusesUserTimeline()
1854 $_REQUEST['max_id'] = 10;
1855 $_REQUEST['exclude_replies'] = true;
1856 $_REQUEST['conversation_id'] = 1;
1857 $result = api_statuses_user_timeline('json');
1858 self::assertNotEmpty($result['status']);
1859 foreach ($result['status'] as $status) {
1860 self::assertStatus($status);
1865 * Test the api_statuses_user_timeline() function with a negative page parameter.
1869 public function testApiStatusesUserTimelineWithNegativePage()
1871 $_REQUEST['page'] = -2;
1872 $result = api_statuses_user_timeline('json');
1873 self::assertNotEmpty($result['status']);
1874 foreach ($result['status'] as $status) {
1875 self::assertStatus($status);
1880 * Test the api_statuses_user_timeline() function with an RSS result.
1884 public function testApiStatusesUserTimelineWithRss()
1886 $result = api_statuses_user_timeline('rss');
1887 self::assertXml($result, 'statuses');
1891 * Test the api_statuses_user_timeline() function with an unallowed user.
1895 public function testApiStatusesUserTimelineWithUnallowedUser()
1897 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1898 $_SESSION['allow_api'] = false;
1899 $_GET['screen_name'] = $this->selfUser['nick'];
1900 BasicAuth::setCurrentUserID();
1901 api_statuses_user_timeline('json');
1905 * Test the api_favorites_create_destroy() function.
1909 public function testApiFavoritesCreateDestroy()
1911 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1912 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1913 api_favorites_create_destroy('json');
1917 * Test the api_favorites_create_destroy() function with an invalid ID.
1921 public function testApiFavoritesCreateDestroyWithInvalidId()
1923 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1924 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1925 api_favorites_create_destroy('json');
1929 * Test the api_favorites_create_destroy() function with an invalid action.
1933 public function testApiFavoritesCreateDestroyWithInvalidAction()
1935 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1936 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1937 $_REQUEST['id'] = 1;
1938 api_favorites_create_destroy('json');
1942 * Test the api_favorites_create_destroy() function with the create action.
1946 public function testApiFavoritesCreateDestroyWithCreateAction()
1948 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1949 $_REQUEST['id'] = 3;
1950 $result = api_favorites_create_destroy('json');
1951 self::assertStatus($result['status']);
1955 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1959 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1961 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1962 $_REQUEST['id'] = 3;
1963 $result = api_favorites_create_destroy('rss');
1964 self::assertXml($result, 'status');
1968 * Test the api_favorites_create_destroy() function with the destroy action.
1972 public function testApiFavoritesCreateDestroyWithDestroyAction()
1974 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1975 $_REQUEST['id'] = 3;
1976 $result = api_favorites_create_destroy('json');
1977 self::assertStatus($result['status']);
1981 * Test the api_favorites_create_destroy() function without an authenticated user.
1985 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1987 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1988 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1989 $_SESSION['authenticated'] = false;
1990 api_favorites_create_destroy('json');
1994 * Test the api_favorites() function.
1998 public function testApiFavorites()
2000 $_REQUEST['page'] = -1;
2001 $_REQUEST['max_id'] = 10;
2002 $result = api_favorites('json');
2003 foreach ($result['status'] as $status) {
2004 self::assertStatus($status);
2009 * Test the api_favorites() function with an RSS result.
2013 public function testApiFavoritesWithRss()
2015 $result = api_favorites('rss');
2016 self::assertXml($result, 'statuses');
2020 * Test the api_favorites() function with an unallowed user.
2024 public function testApiFavoritesWithUnallowedUser()
2026 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2027 $_SESSION['allow_api'] = false;
2028 $_GET['screen_name'] = $this->selfUser['nick'];
2029 BasicAuth::setCurrentUserID();
2030 api_favorites('json');
2034 * Test the api_format_messages() function.
2038 public function testApiFormatMessages()
2040 $result = api_format_messages(
2041 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2042 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2043 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2045 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2046 self::assertEquals(1, $result['id']);
2047 self::assertEquals(2, $result['recipient_id']);
2048 self::assertEquals(3, $result['sender_id']);
2049 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2050 self::assertEquals('sender_name', $result['sender_screen_name']);
2054 * Test the api_format_messages() function with HTML.
2058 public function testApiFormatMessagesWithHtmlText()
2060 $_GET['getText'] = 'html';
2061 $result = api_format_messages(
2062 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2063 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2064 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2066 self::assertEquals('item_title', $result['title']);
2067 self::assertEquals('<strong>item_body</strong>', $result['text']);
2071 * Test the api_format_messages() function with plain text.
2075 public function testApiFormatMessagesWithPlainText()
2077 $_GET['getText'] = 'plain';
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('item_body', $result['text']);
2088 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2092 public function testApiFormatMessagesWithoutUserObjects()
2094 $_GET['getUserObjects'] = 'false';
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::assertTrue(!isset($result['sender']));
2101 self::assertTrue(!isset($result['recipient']));
2105 * Test the api_convert_item() function.
2109 public function testApiConvertItem()
2111 $result = api_convert_item(
2113 'network' => 'feed',
2114 'title' => 'item_title',
2116 // We need a long string to test that it is correctly cut
2117 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2118 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2119 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2120 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2121 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2122 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2123 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2124 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2125 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2126 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2127 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2128 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2129 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2130 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2131 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2132 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2133 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2134 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2135 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2136 'repellat officia illum quos impedit quam iste esse unde qui ' .
2137 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2138 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2139 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2140 'plink' => 'item_plink'
2143 self::assertStringStartsWith('item_title', $result['text']);
2144 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2148 * Test the api_convert_item() function with an empty item body.
2152 public function testApiConvertItemWithoutBody()
2154 $result = api_convert_item(
2156 'network' => 'feed',
2157 'title' => 'item_title',
2160 'plink' => 'item_plink'
2163 self::assertEquals("item_title", $result['text']);
2164 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2168 * Test the api_convert_item() function with the title in the body.
2172 public function testApiConvertItemWithTitleInBody()
2174 $result = api_convert_item(
2176 'title' => 'item_title',
2177 'body' => 'item_title item_body',
2181 self::assertEquals('item_title item_body', $result['text']);
2182 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2186 * Test the api_get_attachments() function.
2190 public function testApiGetAttachments()
2193 self::assertEmpty(api_get_attachments($body, 0));
2197 * Test the api_get_attachments() function with an img tag.
2201 public function testApiGetAttachmentsWithImage()
2203 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2204 self::assertIsArray(api_get_attachments($body, 0));
2208 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2212 public function testApiGetAttachmentsWithImageAndAndStatus()
2214 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2215 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2216 self::assertIsArray(api_get_attachments($body, 0));
2220 * Test the api_get_entitities() function.
2224 public function testApiGetEntitities()
2227 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2231 * Test the api_get_entitities() function with the include_entities parameter.
2235 public function testApiGetEntititiesWithIncludeEntities()
2237 $_REQUEST['include_entities'] = 'true';
2239 $result = api_get_entitities($text, 'bbcode', 0);
2240 self::assertIsArray($result['hashtags']);
2241 self::assertIsArray($result['symbols']);
2242 self::assertIsArray($result['urls']);
2243 self::assertIsArray($result['user_mentions']);
2247 * Test the api_format_items_embeded_images() function.
2251 public function testApiFormatItemsEmbededImages()
2254 'text ' . DI::baseUrl() . '/display/item_guid',
2255 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2260 * Test the api_contactlink_to_array() function.
2264 public function testApiContactlinkToArray()
2271 api_contactlink_to_array('text')
2276 * Test the api_contactlink_to_array() function with an URL.
2280 public function testApiContactlinkToArrayWithUrl()
2284 'name' => ['link_text'],
2287 api_contactlink_to_array('text <a href="url">link_text</a>')
2292 * Test the api_format_items_activities() function.
2296 public function testApiFormatItemsActivities()
2298 $item = ['uid' => 0, 'uri' => ''];
2299 $result = api_format_items_activities($item);
2300 self::assertArrayHasKey('like', $result);
2301 self::assertArrayHasKey('dislike', $result);
2302 self::assertArrayHasKey('attendyes', $result);
2303 self::assertArrayHasKey('attendno', $result);
2304 self::assertArrayHasKey('attendmaybe', $result);
2308 * Test the api_format_items_activities() function with an XML result.
2312 public function testApiFormatItemsActivitiesWithXml()
2314 $item = ['uid' => 0, 'uri' => ''];
2315 $result = api_format_items_activities($item, 'xml');
2316 self::assertArrayHasKey('friendica:like', $result);
2317 self::assertArrayHasKey('friendica:dislike', $result);
2318 self::assertArrayHasKey('friendica:attendyes', $result);
2319 self::assertArrayHasKey('friendica:attendno', $result);
2320 self::assertArrayHasKey('friendica:attendmaybe', $result);
2324 * Test the api_format_items() function.
2325 * @doesNotPerformAssertions
2327 public function testApiFormatItems()
2331 'item_network' => 'item_network',
2337 'author-network' => Protocol::DFRN,
2338 'author-link' => 'http://localhost/profile/othercontact',
2342 $result = api_format_items($items, ['id' => 0], true);
2343 foreach ($result as $status) {
2344 self::assertStatus($status);
2349 * Test the api_format_items() function with an XML result.
2350 * @doesNotPerformAssertions
2352 public function testApiFormatItemsWithXml()
2360 'author-network' => Protocol::DFRN,
2361 'author-link' => 'http://localhost/profile/othercontact',
2365 $result = api_format_items($items, ['id' => 0], true, 'xml');
2366 foreach ($result as $status) {
2367 self::assertStatus($status);
2372 * Test the api_lists_list() function.
2376 public function testApiListsList()
2378 $result = api_lists_list('json');
2379 self::assertEquals(['lists_list' => []], $result);
2383 * Test the api_lists_ownerships() function.
2387 public function testApiListsOwnerships()
2389 $result = api_lists_ownerships('json');
2390 foreach ($result['lists']['lists'] as $list) {
2391 self::assertList($list);
2396 * Test the api_lists_ownerships() function without an authenticated user.
2400 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2402 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2403 $_SESSION['authenticated'] = false;
2404 api_lists_ownerships('json');
2408 * Test the api_lists_statuses() function.
2412 public function testApiListsStatuses()
2414 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2415 api_lists_statuses('json');
2419 * Test the api_lists_statuses() function with a list ID.
2420 * @doesNotPerformAssertions
2422 public function testApiListsStatusesWithListId()
2424 $_REQUEST['list_id'] = 1;
2425 $_REQUEST['page'] = -1;
2426 $_REQUEST['max_id'] = 10;
2427 $result = api_lists_statuses('json');
2428 foreach ($result['status'] as $status) {
2429 self::assertStatus($status);
2434 * Test the api_lists_statuses() function with a list ID and a RSS result.
2438 public function testApiListsStatusesWithListIdAndRss()
2440 $_REQUEST['list_id'] = 1;
2441 $result = api_lists_statuses('rss');
2442 self::assertXml($result, 'statuses');
2446 * Test the api_lists_statuses() function with an unallowed user.
2450 public function testApiListsStatusesWithUnallowedUser()
2452 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2453 $_SESSION['allow_api'] = false;
2454 $_GET['screen_name'] = $this->selfUser['nick'];
2455 BasicAuth::setCurrentUserID();
2456 api_lists_statuses('json');
2460 * Test the api_statuses_f() function.
2464 public function testApiStatusesFWithFriends()
2467 $result = api_statuses_f('friends');
2468 self::assertArrayHasKey('user', $result);
2472 * Test the api_statuses_f() function.
2476 public function testApiStatusesFWithFollowers()
2478 $result = api_statuses_f('followers');
2479 self::assertArrayHasKey('user', $result);
2483 * Test the api_statuses_f() function.
2487 public function testApiStatusesFWithBlocks()
2489 $result = api_statuses_f('blocks');
2490 self::assertArrayHasKey('user', $result);
2494 * Test the api_statuses_f() function.
2498 public function testApiStatusesFWithIncoming()
2500 $result = api_statuses_f('incoming');
2501 self::assertArrayHasKey('user', $result);
2505 * Test the api_statuses_f() function an undefined cursor GET variable.
2509 public function testApiStatusesFWithUndefinedCursor()
2511 $_GET['cursor'] = 'undefined';
2512 self::assertFalse(api_statuses_f('friends'));
2516 * Test the api_statuses_friends() function.
2520 public function testApiStatusesFriends()
2522 $result = api_statuses_friends('json');
2523 self::assertArrayHasKey('user', $result);
2527 * Test the api_statuses_friends() function an undefined cursor GET variable.
2531 public function testApiStatusesFriendsWithUndefinedCursor()
2533 $_GET['cursor'] = 'undefined';
2534 self::assertFalse(api_statuses_friends('json'));
2538 * Test the api_statuses_followers() function.
2542 public function testApiStatusesFollowers()
2544 $result = api_statuses_followers('json');
2545 self::assertArrayHasKey('user', $result);
2549 * Test the api_statuses_followers() function an undefined cursor GET variable.
2553 public function testApiStatusesFollowersWithUndefinedCursor()
2555 $_GET['cursor'] = 'undefined';
2556 self::assertFalse(api_statuses_followers('json'));
2560 * Test the api_blocks_list() function.
2564 public function testApiBlocksList()
2566 $result = api_blocks_list('json');
2567 self::assertArrayHasKey('user', $result);
2571 * Test the api_blocks_list() function an undefined cursor GET variable.
2575 public function testApiBlocksListWithUndefinedCursor()
2577 $_GET['cursor'] = 'undefined';
2578 self::assertFalse(api_blocks_list('json'));
2582 * Test the api_friendships_incoming() function.
2586 public function testApiFriendshipsIncoming()
2588 $result = api_friendships_incoming('json');
2589 self::assertArrayHasKey('id', $result);
2593 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2597 public function testApiFriendshipsIncomingWithUndefinedCursor()
2599 $_GET['cursor'] = 'undefined';
2600 self::assertFalse(api_friendships_incoming('json'));
2604 * Test the api_statusnet_config() function.
2608 public function testApiStatusnetConfig()
2611 $result = api_statusnet_config('json');
2612 self::assertEquals('localhost', $result['config']['site']['server']);
2613 self::assertEquals('default', $result['config']['site']['theme']);
2614 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2615 self::assertTrue($result['config']['site']['fancy']);
2616 self::assertEquals('en', $result['config']['site']['language']);
2617 self::assertEquals('UTC', $result['config']['site']['timezone']);
2618 self::assertEquals(200000, $result['config']['site']['textlimit']);
2619 self::assertEquals('false', $result['config']['site']['private']);
2620 self::assertEquals('false', $result['config']['site']['ssl']);
2621 self::assertEquals(30, $result['config']['site']['shorturllength']);
2626 * Test the api_direct_messages_new() function.
2630 public function testApiDirectMessagesNew()
2632 $result = api_direct_messages_new('json');
2633 self::assertNull($result);
2637 * Test the api_direct_messages_new() function without an authenticated user.
2641 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2643 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2644 $_SESSION['authenticated'] = false;
2645 api_direct_messages_new('json');
2649 * Test the api_direct_messages_new() function with an user ID.
2653 public function testApiDirectMessagesNewWithUserId()
2655 $_POST['text'] = 'message_text';
2656 $_POST['user_id'] = $this->otherUser['id'];
2657 $result = api_direct_messages_new('json');
2658 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2662 * Test the api_direct_messages_new() function with a screen name.
2666 public function testApiDirectMessagesNewWithScreenName()
2668 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2669 $_POST['text'] = 'message_text';
2670 $_POST['screen_name'] = $this->friendUser['nick'];
2671 $result = api_direct_messages_new('json');
2672 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2673 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2674 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2678 * Test the api_direct_messages_new() function with a title.
2682 public function testApiDirectMessagesNewWithTitle()
2684 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2685 $_POST['text'] = 'message_text';
2686 $_POST['screen_name'] = $this->friendUser['nick'];
2687 $_REQUEST['title'] = 'message_title';
2688 $result = api_direct_messages_new('json');
2689 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2690 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2691 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2692 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2696 * Test the api_direct_messages_new() function with an RSS result.
2700 public function testApiDirectMessagesNewWithRss()
2702 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2703 $_POST['text'] = 'message_text';
2704 $_POST['screen_name'] = $this->friendUser['nick'];
2705 $result = api_direct_messages_new('rss');
2706 self::assertXml($result, 'direct-messages');
2710 * Test the api_direct_messages_destroy() function.
2714 public function testApiDirectMessagesDestroy()
2716 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2717 api_direct_messages_destroy('json');
2721 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2725 public function testApiDirectMessagesDestroyWithVerbose()
2727 $_GET['friendica_verbose'] = 'true';
2728 $result = api_direct_messages_destroy('json');
2732 'result' => 'error',
2733 'message' => 'message id or parenturi not specified'
2741 * Test the api_direct_messages_destroy() function without an authenticated user.
2745 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2747 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2748 $_SESSION['authenticated'] = false;
2749 api_direct_messages_destroy('json');
2753 * Test the api_direct_messages_destroy() function with a non-zero ID.
2757 public function testApiDirectMessagesDestroyWithId()
2759 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2760 $_REQUEST['id'] = 1;
2761 api_direct_messages_destroy('json');
2765 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2769 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2771 $_REQUEST['id'] = 1;
2772 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2773 $_GET['friendica_verbose'] = 'true';
2774 $result = api_direct_messages_destroy('json');
2778 'result' => 'error',
2779 'message' => 'message id not in database'
2787 * Test the api_direct_messages_destroy() function with a non-zero ID.
2791 public function testApiDirectMessagesDestroyWithCorrectId()
2793 $this->markTestIncomplete('We need to add a dataset for this.');
2797 * Test the api_direct_messages_box() function.
2801 public function testApiDirectMessagesBoxWithSentbox()
2803 $_REQUEST['page'] = -1;
2804 $_REQUEST['max_id'] = 10;
2805 $result = api_direct_messages_box('json', 'sentbox', 'false');
2806 self::assertArrayHasKey('direct_message', $result);
2810 * Test the api_direct_messages_box() function.
2814 public function testApiDirectMessagesBoxWithConversation()
2816 $result = api_direct_messages_box('json', 'conversation', 'false');
2817 self::assertArrayHasKey('direct_message', $result);
2821 * Test the api_direct_messages_box() function.
2825 public function testApiDirectMessagesBoxWithAll()
2827 $result = api_direct_messages_box('json', 'all', 'false');
2828 self::assertArrayHasKey('direct_message', $result);
2832 * Test the api_direct_messages_box() function.
2836 public function testApiDirectMessagesBoxWithInbox()
2838 $result = api_direct_messages_box('json', 'inbox', 'false');
2839 self::assertArrayHasKey('direct_message', $result);
2843 * Test the api_direct_messages_box() function.
2847 public function testApiDirectMessagesBoxWithVerbose()
2849 $result = api_direct_messages_box('json', 'sentbox', 'true');
2853 'result' => 'error',
2854 'message' => 'no mails available'
2862 * Test the api_direct_messages_box() function with a RSS result.
2866 public function testApiDirectMessagesBoxWithRss()
2868 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2869 self::assertXml($result, 'direct-messages');
2873 * Test the api_direct_messages_box() function without an authenticated user.
2877 public function testApiDirectMessagesBoxWithUnallowedUser()
2879 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2880 $_SESSION['allow_api'] = false;
2881 $_GET['screen_name'] = $this->selfUser['nick'];
2882 BasicAuth::setCurrentUserID();
2883 api_direct_messages_box('json', 'sentbox', 'false');
2887 * Test the api_direct_messages_sentbox() function.
2891 public function testApiDirectMessagesSentbox()
2893 $result = api_direct_messages_sentbox('json');
2894 self::assertArrayHasKey('direct_message', $result);
2898 * Test the api_direct_messages_inbox() function.
2902 public function testApiDirectMessagesInbox()
2904 $result = api_direct_messages_inbox('json');
2905 self::assertArrayHasKey('direct_message', $result);
2909 * Test the api_direct_messages_all() function.
2913 public function testApiDirectMessagesAll()
2915 $result = api_direct_messages_all('json');
2916 self::assertArrayHasKey('direct_message', $result);
2920 * Test the api_direct_messages_conversation() function.
2924 public function testApiDirectMessagesConversation()
2926 $result = api_direct_messages_conversation('json');
2927 self::assertArrayHasKey('direct_message', $result);
2931 * Test the api_oauth_request_token() function.
2935 public function testApiOauthRequestToken()
2937 $this->markTestIncomplete('exit() kills phpunit as well');
2941 * Test the api_oauth_access_token() function.
2945 public function testApiOauthAccessToken()
2947 $this->markTestIncomplete('exit() kills phpunit as well');
2951 * Test the api_fr_photos_list() function.
2955 public function testApiFrPhotosList()
2957 $result = api_fr_photos_list('json');
2958 self::assertArrayHasKey('photo', $result);
2962 * Test the api_fr_photos_list() function without an authenticated user.
2966 public function testApiFrPhotosListWithoutAuthenticatedUser()
2968 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2969 $_SESSION['authenticated'] = false;
2970 api_fr_photos_list('json');
2974 * Test the api_fr_photo_create_update() function.
2976 public function testApiFrPhotoCreateUpdate()
2978 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2979 api_fr_photo_create_update('json');
2983 * Test the api_fr_photo_create_update() function without an authenticated user.
2987 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
2989 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2990 $_SESSION['authenticated'] = false;
2991 api_fr_photo_create_update('json');
2995 * Test the api_fr_photo_create_update() function with an album name.
2999 public function testApiFrPhotoCreateUpdateWithAlbum()
3001 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3002 $_REQUEST['album'] = 'album_name';
3003 api_fr_photo_create_update('json');
3007 * Test the api_fr_photo_create_update() function with the update mode.
3011 public function testApiFrPhotoCreateUpdateWithUpdate()
3013 $this->markTestIncomplete('We need to create a dataset for this');
3017 * Test the api_fr_photo_create_update() function with an uploaded file.
3021 public function testApiFrPhotoCreateUpdateWithFile()
3023 $this->markTestIncomplete();
3027 * Test the api_fr_photo_detail() function.
3031 public function testApiFrPhotoDetail()
3033 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3034 api_fr_photo_detail('json');
3038 * Test the api_fr_photo_detail() function without an authenticated user.
3042 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3044 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3045 $_SESSION['authenticated'] = false;
3046 api_fr_photo_detail('json');
3050 * Test the api_fr_photo_detail() function with a photo ID.
3054 public function testApiFrPhotoDetailWithPhotoId()
3056 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3057 $_REQUEST['photo_id'] = 1;
3058 api_fr_photo_detail('json');
3062 * Test the api_fr_photo_detail() function with a correct photo ID.
3066 public function testApiFrPhotoDetailCorrectPhotoId()
3068 $this->markTestIncomplete('We need to create a dataset for this.');
3072 * Test the api_account_update_profile_image() function.
3076 public function testApiAccountUpdateProfileImage()
3078 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3079 api_account_update_profile_image('json');
3083 * Test the api_account_update_profile_image() function without an authenticated user.
3087 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3089 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3090 $_SESSION['authenticated'] = false;
3091 api_account_update_profile_image('json');
3095 * Test the api_account_update_profile_image() function with an uploaded file.
3099 public function testApiAccountUpdateProfileImageWithUpload()
3101 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3102 $this->markTestIncomplete();
3107 * Test the api_account_update_profile() function.
3111 public function testApiAccountUpdateProfile()
3113 $_POST['name'] = 'new_name';
3114 $_POST['description'] = 'new_description';
3115 $result = api_account_update_profile('json');
3116 // We can't use assertSelfUser() here because the user object is missing some properties.
3117 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3118 self::assertEquals('DFRN', $result['user']['location']);
3119 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3120 self::assertEquals('dfrn', $result['user']['network']);
3121 self::assertEquals('new_name', $result['user']['name']);
3122 self::assertEquals('new_description', $result['user']['description']);
3126 * Test the check_acl_input() function.
3130 public function testCheckAclInput()
3132 $result = check_acl_input('<aclstring>');
3133 // Where does this result come from?
3134 self::assertEquals(1, $result);
3138 * Test the check_acl_input() function with an empty ACL string.
3142 public function testCheckAclInputWithEmptyAclString()
3144 $result = check_acl_input(' ');
3145 self::assertFalse($result);
3149 * Test the save_media_to_database() function.
3153 public function testSaveMediaToDatabase()
3155 $this->markTestIncomplete();
3159 * Test the post_photo_item() function.
3163 public function testPostPhotoItem()
3165 $this->markTestIncomplete();
3169 * Test the prepare_photo_data() function.
3173 public function testPreparePhotoData()
3175 $this->markTestIncomplete();
3179 * Test the api_share_as_retweet() function with a valid item.
3183 public function testApiShareAsRetweetWithValidItem()
3185 $this->markTestIncomplete();
3189 * Test the api_in_reply_to() function.
3193 public function testApiInReplyTo()
3195 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3196 self::assertArrayHasKey('status_id', $result);
3197 self::assertArrayHasKey('user_id', $result);
3198 self::assertArrayHasKey('status_id_str', $result);
3199 self::assertArrayHasKey('user_id_str', $result);
3200 self::assertArrayHasKey('screen_name', $result);
3204 * Test the api_in_reply_to() function with a valid item.
3208 public function testApiInReplyToWithValidItem()
3210 $this->markTestIncomplete();
3214 * Test the api_clean_plain_items() function.
3218 public function testApiCleanPlainItems()
3220 $_REQUEST['include_entities'] = 'true';
3221 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3222 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3226 * Test the api_best_nickname() function.
3230 public function testApiBestNickname()
3233 $result = api_best_nickname($contacts);
3234 self::assertNull($result);
3238 * Test the api_best_nickname() function with contacts.
3242 public function testApiBestNicknameWithContacts()
3244 $this->markTestIncomplete();
3248 * Test the api_friendica_group_show() function.
3252 public function testApiFriendicaGroupShow()
3254 $this->markTestIncomplete();
3258 * Test the api_friendica_group_delete() function.
3262 public function testApiFriendicaGroupDelete()
3264 $this->markTestIncomplete();
3268 * Test the api_lists_destroy() function.
3272 public function testApiListsDestroy()
3274 $this->markTestIncomplete();
3278 * Test the group_create() function.
3282 public function testGroupCreate()
3284 $this->markTestIncomplete();
3288 * Test the api_friendica_group_create() function.
3292 public function testApiFriendicaGroupCreate()
3294 $this->markTestIncomplete();
3298 * Test the api_lists_create() function.
3302 public function testApiListsCreate()
3304 $this->markTestIncomplete();
3308 * Test the api_friendica_group_update() function.
3312 public function testApiFriendicaGroupUpdate()
3314 $this->markTestIncomplete();
3318 * Test the api_lists_update() function.
3322 public function testApiListsUpdate()
3324 $this->markTestIncomplete();
3328 * Test the api_friendica_activity() function.
3332 public function testApiFriendicaActivity()
3334 $this->markTestIncomplete();
3338 * Test the api_friendica_notification_seen() function.
3342 public function testApiFriendicaNotificationSeen()
3344 $this->markTestIncomplete();
3348 * Test the api_friendica_direct_messages_setseen() function.
3352 public function testApiFriendicaDirectMessagesSetseen()
3354 $this->markTestIncomplete();
3358 * Test the api_friendica_direct_messages_search() function.
3362 public function testApiFriendicaDirectMessagesSearch()
3364 $this->markTestIncomplete();