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 BasicAuth::setCurrentUserID();
315 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
316 BasicAuth::getCurrentUserID(true);
320 * Test the BasicAuth::getCurrentUserID() function with a bad login.
322 * @runInSeparateProcess
323 * @preserveGlobalState disabled
324 * @preserveGlobalState disabled
326 public function testApiLoginWithBadLogin()
328 BasicAuth::setCurrentUserID();
329 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
330 $_SERVER['PHP_AUTH_USER'] = 'user@server';
331 BasicAuth::getCurrentUserID(true);
335 * Test the BasicAuth::getCurrentUserID() function with oAuth.
339 public function testApiLoginWithOauth()
341 $this->markTestIncomplete('Can we test this easily?');
345 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
349 public function testApiLoginWithAddonAuth()
351 $this->markTestIncomplete('Can we test this easily?');
355 * Test the BasicAuth::getCurrentUserID() function with a correct login.
357 * @runInSeparateProcess
358 * @preserveGlobalState disabled
359 * @doesNotPerformAssertions
361 public function testApiLoginWithCorrectLogin()
363 BasicAuth::setCurrentUserID();
364 $_SERVER['PHP_AUTH_USER'] = 'Test user';
365 $_SERVER['PHP_AUTH_PW'] = 'password';
366 BasicAuth::getCurrentUserID(true);
370 * Test the BasicAuth::getCurrentUserID() function with a remote user.
372 * @runInSeparateProcess
373 * @preserveGlobalState disabled
375 public function testApiLoginWithRemoteUser()
377 BasicAuth::setCurrentUserID();
378 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
379 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
380 BasicAuth::getCurrentUserID(true);
384 * Test the api_check_method() function.
388 public function testApiCheckMethod()
390 self::assertFalse(api_check_method('method'));
394 * Test the api_check_method() function with a correct method.
398 public function testApiCheckMethodWithCorrectMethod()
400 $_SERVER['REQUEST_METHOD'] = 'method';
401 self::assertTrue(api_check_method('method'));
405 * Test the api_check_method() function with a wildcard.
409 public function testApiCheckMethodWithWildcard()
411 self::assertTrue(api_check_method('*'));
415 * Test the api_call() function.
417 * @runInSeparateProcess
418 * @preserveGlobalState disabled
420 public function testApiCall()
424 'method' => 'method',
425 'func' => function () {
426 return ['data' => ['some_data']];
429 $_SERVER['REQUEST_METHOD'] = 'method';
430 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
431 $_GET['callback'] = 'callback_name';
433 $args = DI::args()->determine($_SERVER, $_GET);
436 'callback_name(["some_data"])',
437 api_call($this->app, $args)
442 * Test the api_call() function with the profiled enabled.
444 * @runInSeparateProcess
445 * @preserveGlobalState disabled
447 public function testApiCallWithProfiler()
451 'method' => 'method',
452 'func' => function () {
453 return ['data' => ['some_data']];
457 $_SERVER['REQUEST_METHOD'] = 'method';
458 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
460 $args = DI::args()->determine($_SERVER, $_GET);
462 $this->config->set('system', 'profiler', true);
463 $this->config->set('rendertime', 'callstack', true);
464 $this->app->callstack = [
465 'database' => ['some_function' => 200],
466 'database_write' => ['some_function' => 200],
467 'cache' => ['some_function' => 200],
468 'cache_write' => ['some_function' => 200],
469 'network' => ['some_function' => 200]
474 api_call($this->app, $args)
479 * Test the api_call() function with a JSON result.
481 * @runInSeparateProcess
482 * @preserveGlobalState disabled
484 public function testApiCallWithJson()
488 'method' => 'method',
489 'func' => function () {
490 return ['data' => ['some_data']];
493 $_SERVER['REQUEST_METHOD'] = 'method';
494 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
496 $args = DI::args()->determine($_SERVER, $_GET);
500 api_call($this->app, $args)
505 * Test the api_call() function with an XML result.
507 * @runInSeparateProcess
508 * @preserveGlobalState disabled
510 public function testApiCallWithXml()
514 'method' => 'method',
515 'func' => function () {
519 $_SERVER['REQUEST_METHOD'] = 'method';
520 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
522 $args = DI::args()->determine($_SERVER, $_GET);
526 api_call($this->app, $args)
531 * Test the api_call() function with an RSS result.
533 * @runInSeparateProcess
534 * @preserveGlobalState disabled
536 public function testApiCallWithRss()
540 'method' => 'method',
541 'func' => function () {
545 $_SERVER['REQUEST_METHOD'] = 'method';
546 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
548 $args = DI::args()->determine($_SERVER, $_GET);
551 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
553 api_call($this->app, $args)
558 * Test the api_call() function with an Atom result.
560 * @runInSeparateProcess
561 * @preserveGlobalState disabled
563 public function testApiCallWithAtom()
567 'method' => 'method',
568 'func' => function () {
572 $_SERVER['REQUEST_METHOD'] = 'method';
573 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
575 $args = DI::args()->determine($_SERVER, $_GET);
578 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
580 api_call($this->app, $args)
585 * Test the api_rss_extra() function.
589 public function testApiRssExtra()
591 $user_info = ['url' => 'user_url', 'lang' => 'en'];
592 $result = api_rss_extra([], $user_info);
593 self::assertEquals($user_info, $result['$user']);
594 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
595 self::assertArrayHasKey('self', $result['$rss']);
596 self::assertArrayHasKey('base', $result['$rss']);
597 self::assertArrayHasKey('updated', $result['$rss']);
598 self::assertArrayHasKey('atom_updated', $result['$rss']);
599 self::assertArrayHasKey('language', $result['$rss']);
600 self::assertArrayHasKey('logo', $result['$rss']);
604 * Test the api_rss_extra() function without any user info.
608 public function testApiRssExtraWithoutUserInfo()
610 $result = api_rss_extra([], null);
611 self::assertIsArray($result['$user']);
612 self::assertArrayHasKey('alternate', $result['$rss']);
613 self::assertArrayHasKey('self', $result['$rss']);
614 self::assertArrayHasKey('base', $result['$rss']);
615 self::assertArrayHasKey('updated', $result['$rss']);
616 self::assertArrayHasKey('atom_updated', $result['$rss']);
617 self::assertArrayHasKey('language', $result['$rss']);
618 self::assertArrayHasKey('logo', $result['$rss']);
622 * Test the api_unique_id_to_nurl() function.
626 public function testApiUniqueIdToNurl()
628 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
632 * Test the api_unique_id_to_nurl() function with a correct ID.
636 public function testApiUniqueIdToNurlWithCorrectId()
638 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
642 * Test the api_get_user() function.
646 public function testApiGetUser()
648 $user = api_get_user();
649 self::assertSelfUser($user);
650 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
651 // self::assertEquals('6fdbe8', $user['profile_link_color']);
652 // self::assertEquals('ededed', $user['profile_background_color']);
656 * Test the api_get_user() function with a Frio schema.
660 public function testApiGetUserWithFrioSchema()
662 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
663 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
664 $user = api_get_user();
665 self::assertSelfUser($user);
666 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
667 // self::assertEquals('6fdbe8', $user['profile_link_color']);
668 // self::assertEquals('ededed', $user['profile_background_color']);
672 * Test the api_get_user() function with an empty Frio schema.
676 public function testApiGetUserWithEmptyFrioSchema()
678 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
679 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
680 $user = api_get_user();
681 self::assertSelfUser($user);
682 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
683 // self::assertEquals('6fdbe8', $user['profile_link_color']);
684 // self::assertEquals('ededed', $user['profile_background_color']);
688 * Test the api_get_user() function with a custom Frio schema.
692 public function testApiGetUserWithCustomFrioSchema()
694 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
695 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
696 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
697 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
698 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
699 $user = api_get_user();
700 self::assertSelfUser($user);
701 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
702 // self::assertEquals('123456', $user['profile_link_color']);
703 // self::assertEquals('123456', $user['profile_background_color']);
707 * Test the api_get_user() function with an user that is not allowed to use the API.
709 * @runInSeparateProcess
710 * @preserveGlobalState disabled
712 public function testApiGetUserWithoutApiUser()
714 $_SERVER['PHP_AUTH_USER'] = 'Test user';
715 $_SERVER['PHP_AUTH_PW'] = 'password';
716 $_SESSION['allow_api'] = false;
717 BasicAuth::setCurrentUserID();
718 self::assertFalse(api_get_user());
722 * Test the api_get_user() function with an user ID in a GET parameter.
726 public function testApiGetUserWithGetId()
728 $_GET['user_id'] = $this->otherUser['id'];
729 self::assertOtherUser(api_get_user());
733 * Test the api_get_user() function with a wrong user ID in a GET parameter.
737 public function testApiGetUserWithWrongGetId()
739 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
740 $_GET['user_id'] = $this->wrongUserId;
741 self::assertOtherUser(api_get_user());
745 * Test the api_get_user() function with an user name in a GET parameter.
749 public function testApiGetUserWithGetName()
751 $_GET['screen_name'] = $this->selfUser['nick'];
752 self::assertSelfUser(api_get_user());
756 * Test the api_get_user() function with a profile URL in a GET parameter.
760 public function testApiGetUserWithGetUrl()
762 $_GET['profileurl'] = $this->selfUser['nurl'];
763 self::assertSelfUser(api_get_user());
767 * Test the api_get_user() function with an user ID in the API path.
771 public function testApiGetUserWithNumericCalledApi()
774 $called_api = ['api_path'];
775 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
776 self::assertOtherUser(api_get_user());
780 * Test the api_get_user() function with the $called_api global variable.
784 public function testApiGetUserWithCalledApi()
787 $called_api = ['api', 'api_path'];
788 self::assertSelfUser(api_get_user());
792 * Test the api_get_user() function with a valid user.
796 public function testApiGetUserWithCorrectUser()
798 self::assertOtherUser(api_get_user($this->otherUser['id']));
802 * Test the api_get_user() function with a wrong user ID.
806 public function testApiGetUserWithWrongUser()
808 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
809 self::assertOtherUser(api_get_user($this->wrongUserId));
813 * Test the api_get_user() function with a 0 user ID.
817 public function testApiGetUserWithZeroUser()
819 self::assertSelfUser(api_get_user(0));
823 * Test the api_item_get_user() function.
827 public function testApiItemGetUser()
829 $users = api_item_get_user($this->app, []);
830 self::assertSelfUser($users[0]);
834 * Test the api_item_get_user() function with a different item parent.
838 public function testApiItemGetUserWithDifferentParent()
840 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
841 self::assertSelfUser($users[0]);
842 self::assertEquals($users[0], $users[1]);
846 * Test the Arrays::walkRecursive() function.
850 public function testApiWalkRecursive()
855 Arrays::walkRecursive(
858 // Should we test this with a callback that actually does something?
866 * Test the Arrays::walkRecursive() function with an array.
870 public function testApiWalkRecursiveWithArray()
872 $array = [['item1'], ['item2']];
875 Arrays::walkRecursive(
878 // Should we test this with a callback that actually does something?
886 * Test the BaseApi::reformatXML() function.
890 public function testApiReformatXml()
894 self::assertTrue(ApiResponse::reformatXML($item, $key));
895 self::assertEquals('true', $item);
899 * Test the BaseApi::reformatXML() function with a statusnet_api key.
903 public function testApiReformatXmlWithStatusnetKey()
906 $key = 'statusnet_api';
907 self::assertTrue(ApiResponse::reformatXML($item, $key));
908 self::assertEquals('statusnet:api', $key);
912 * Test the BaseApi::reformatXML() function with a friendica_api key.
916 public function testApiReformatXmlWithFriendicaKey()
919 $key = 'friendica_api';
920 self::assertTrue(ApiResponse::reformatXML($item, $key));
921 self::assertEquals('friendica:api', $key);
925 * Test the BaseApi::createXML() function.
929 public function testApiCreateXml()
932 '<?xml version="1.0"?>' . "\n" .
933 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
934 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
935 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
936 ' <data>some_data</data>' . "\n" .
937 '</root_element>' . "\n",
938 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
943 * Test the BaseApi::createXML() function without any XML namespace.
947 public function testApiCreateXmlWithoutNamespaces()
950 '<?xml version="1.0"?>' . "\n" .
952 ' <data>some_data</data>' . "\n" .
954 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
959 * Test the BaseApi::formatData() function.
963 public function testApiFormatData()
965 $data = ['some_data'];
966 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
970 * Test the BaseApi::formatData() function with an XML result.
974 public function testApiFormatDataWithXml()
977 '<?xml version="1.0"?>' . "\n" .
978 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
979 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
980 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
981 ' <data>some_data</data>' . "\n" .
982 '</root_element>' . "\n",
983 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
988 * Test the api_account_verify_credentials() function.
992 public function testApiAccountVerifyCredentials()
994 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
998 * Test the api_account_verify_credentials() function without an authenticated user.
1002 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1004 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1005 $_SESSION['authenticated'] = false;
1006 api_account_verify_credentials('json');
1010 * Test the requestdata() function.
1014 public function testRequestdata()
1016 self::assertNull(requestdata('variable_name'));
1020 * Test the requestdata() function with a POST parameter.
1024 public function testRequestdataWithPost()
1026 $_POST['variable_name'] = 'variable_value';
1027 self::assertEquals('variable_value', requestdata('variable_name'));
1031 * Test the requestdata() function with a GET parameter.
1035 public function testRequestdataWithGet()
1037 $_GET['variable_name'] = 'variable_value';
1038 self::assertEquals('variable_value', requestdata('variable_name'));
1042 * Test the api_statuses_mediap() function.
1046 public function testApiStatusesMediap()
1048 DI::args()->setArgc(2);
1056 'tmp_name' => $this->getTempImage(),
1057 'name' => 'spacer.png',
1058 'type' => 'image/png'
1061 $_GET['status'] = '<b>Status content</b>';
1063 $result = api_statuses_mediap('json');
1064 self::assertStatus($result['status']);
1068 * Test the api_statuses_mediap() function without an authenticated user.
1072 public function testApiStatusesMediapWithoutAuthenticatedUser()
1074 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1075 $_SESSION['authenticated'] = false;
1076 BasicAuth::setCurrentUserID();
1077 api_statuses_mediap('json');
1081 * Test the api_statuses_update() function.
1085 public function testApiStatusesUpdate()
1087 $_GET['status'] = 'Status content #friendica';
1088 $_GET['in_reply_to_status_id'] = -1;
1097 'tmp_name' => $this->getTempImage(),
1098 'name' => 'spacer.png',
1099 'type' => 'image/png'
1103 $result = api_statuses_update('json');
1104 self::assertStatus($result['status']);
1108 * Test the api_statuses_update() function with an HTML status.
1112 public function testApiStatusesUpdateWithHtml()
1114 $_GET['htmlstatus'] = '<b>Status content</b>';
1116 $result = api_statuses_update('json');
1117 self::assertStatus($result['status']);
1121 * Test the api_statuses_update() function without an authenticated user.
1125 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1127 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1128 $_SESSION['authenticated'] = false;
1129 api_statuses_update('json');
1133 * Test the api_statuses_update() function with a parent status.
1137 public function testApiStatusesUpdateWithParent()
1139 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1143 * Test the api_statuses_update() function with a media_ids parameter.
1147 public function testApiStatusesUpdateWithMediaIds()
1149 $this->markTestIncomplete();
1153 * Test the api_statuses_update() function with the throttle limit reached.
1157 public function testApiStatusesUpdateWithDayThrottleReached()
1159 $this->markTestIncomplete();
1163 * Test the api_media_upload() function.
1164 * @runInSeparateProcess
1165 * @preserveGlobalState disabled
1167 public function testApiMediaUpload()
1169 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1174 * Test the api_media_upload() function without an authenticated user.
1178 public function testApiMediaUploadWithoutAuthenticatedUser()
1180 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1181 $_SESSION['authenticated'] = false;
1186 * Test the api_media_upload() function with an invalid uploaded media.
1190 public function testApiMediaUploadWithMedia()
1192 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1196 'tmp_name' => 'tmp_name'
1203 * Test the api_media_upload() function with an valid uploaded media.
1207 public function testApiMediaUploadWithValidMedia()
1215 'tmp_name' => $this->getTempImage(),
1216 'name' => 'spacer.png',
1217 'type' => 'image/png'
1221 DI::args()->setArgc(2);
1223 $result = api_media_upload();
1224 self::assertEquals('image/png', $result['media']['image']['image_type']);
1225 self::assertEquals(1, $result['media']['image']['w']);
1226 self::assertEquals(1, $result['media']['image']['h']);
1227 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1231 * Test the api_status_show() function.
1233 public function testApiStatusShowWithJson()
1235 $result = api_status_show('json', 1);
1236 self::assertStatus($result['status']);
1240 * Test the api_status_show() function with an XML result.
1242 public function testApiStatusShowWithXml()
1244 $result = api_status_show('xml', 1);
1245 self::assertXml($result, 'statuses');
1249 * Test the api_get_last_status() function
1251 public function testApiGetLastStatus()
1253 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1255 self::assertNotNull($item);
1259 * Test the api_users_show() function.
1263 public function testApiUsersShow()
1265 $result = api_users_show('json');
1266 // We can't use assertSelfUser() here because the user object is missing some properties.
1267 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1268 self::assertEquals('DFRN', $result['user']['location']);
1269 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1270 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1271 self::assertEquals('dfrn', $result['user']['network']);
1272 self::assertTrue($result['user']['verified']);
1276 * Test the api_users_show() function with an XML result.
1280 public function testApiUsersShowWithXml()
1282 $result = api_users_show('xml');
1283 self::assertXml($result, 'statuses');
1287 * Test the api_users_search() function.
1291 public function testApiUsersSearch()
1293 $_GET['q'] = 'othercontact';
1294 $result = api_users_search('json');
1295 self::assertOtherUser($result['users'][0]);
1299 * Test the api_users_search() function with an XML result.
1303 public function testApiUsersSearchWithXml()
1305 $_GET['q'] = 'othercontact';
1306 $result = api_users_search('xml');
1307 self::assertXml($result, 'users');
1311 * Test the api_users_search() function without a GET q parameter.
1315 public function testApiUsersSearchWithoutQuery()
1317 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1318 api_users_search('json');
1322 * Test the api_users_lookup() function.
1326 public function testApiUsersLookup()
1328 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1329 api_users_lookup('json');
1333 * Test the api_users_lookup() function with an user ID.
1337 public function testApiUsersLookupWithUserId()
1339 $_REQUEST['user_id'] = $this->otherUser['id'];
1340 $result = api_users_lookup('json');
1341 self::assertOtherUser($result['users'][0]);
1345 * Test the api_search() function.
1349 public function testApiSearch()
1351 $_REQUEST['q'] = 'reply';
1352 $_REQUEST['max_id'] = 10;
1353 $result = api_search('json');
1354 foreach ($result['status'] as $status) {
1355 self::assertStatus($status);
1356 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1361 * Test the api_search() function a count parameter.
1365 public function testApiSearchWithCount()
1367 $_REQUEST['q'] = 'reply';
1368 $_REQUEST['count'] = 20;
1369 $result = api_search('json');
1370 foreach ($result['status'] as $status) {
1371 self::assertStatus($status);
1372 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1377 * Test the api_search() function with an rpp parameter.
1381 public function testApiSearchWithRpp()
1383 $_REQUEST['q'] = 'reply';
1384 $_REQUEST['rpp'] = 20;
1385 $result = api_search('json');
1386 foreach ($result['status'] as $status) {
1387 self::assertStatus($status);
1388 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1393 * Test the api_search() function with an q parameter contains hashtag.
1394 * @doesNotPerformAssertions
1396 public function testApiSearchWithHashtag()
1398 $_REQUEST['q'] = '%23friendica';
1399 $result = api_search('json');
1400 foreach ($result['status'] as $status) {
1401 self::assertStatus($status);
1402 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1407 * Test the api_search() function with an exclude_replies parameter.
1408 * @doesNotPerformAssertions
1410 public function testApiSearchWithExcludeReplies()
1412 $_REQUEST['max_id'] = 10;
1413 $_REQUEST['exclude_replies'] = true;
1414 $_REQUEST['q'] = 'friendica';
1415 $result = api_search('json');
1416 foreach ($result['status'] as $status) {
1417 self::assertStatus($status);
1422 * Test the api_search() function without an authenticated user.
1426 public function testApiSearchWithUnallowedUser()
1428 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1429 $_SESSION['allow_api'] = false;
1430 $_GET['screen_name'] = $this->selfUser['nick'];
1431 BasicAuth::setCurrentUserID();
1436 * Test the api_search() function without any GET query parameter.
1440 public function testApiSearchWithoutQuery()
1442 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1447 * Test the api_statuses_home_timeline() function.
1451 public function testApiStatusesHomeTimeline()
1453 $_REQUEST['max_id'] = 10;
1454 $_REQUEST['exclude_replies'] = true;
1455 $_REQUEST['conversation_id'] = 1;
1456 $result = api_statuses_home_timeline('json');
1457 self::assertNotEmpty($result['status']);
1458 foreach ($result['status'] as $status) {
1459 self::assertStatus($status);
1464 * Test the api_statuses_home_timeline() function with a negative page parameter.
1468 public function testApiStatusesHomeTimelineWithNegativePage()
1470 $_REQUEST['page'] = -2;
1471 $result = api_statuses_home_timeline('json');
1472 self::assertNotEmpty($result['status']);
1473 foreach ($result['status'] as $status) {
1474 self::assertStatus($status);
1479 * Test the api_statuses_home_timeline() with an unallowed user.
1483 public function testApiStatusesHomeTimelineWithUnallowedUser()
1485 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1486 $_SESSION['allow_api'] = false;
1487 $_GET['screen_name'] = $this->selfUser['nick'];
1488 BasicAuth::setCurrentUserID();
1489 api_statuses_home_timeline('json');
1493 * Test the api_statuses_home_timeline() function with an RSS result.
1497 public function testApiStatusesHomeTimelineWithRss()
1499 $result = api_statuses_home_timeline('rss');
1500 self::assertXml($result, 'statuses');
1504 * Test the api_statuses_public_timeline() function.
1508 public function testApiStatusesPublicTimeline()
1510 $_REQUEST['max_id'] = 10;
1511 $_REQUEST['conversation_id'] = 1;
1512 $result = api_statuses_public_timeline('json');
1513 self::assertNotEmpty($result['status']);
1514 foreach ($result['status'] as $status) {
1515 self::assertStatus($status);
1520 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1524 public function testApiStatusesPublicTimelineWithExcludeReplies()
1526 $_REQUEST['max_id'] = 10;
1527 $_REQUEST['exclude_replies'] = true;
1528 $result = api_statuses_public_timeline('json');
1529 self::assertNotEmpty($result['status']);
1530 foreach ($result['status'] as $status) {
1531 self::assertStatus($status);
1536 * Test the api_statuses_public_timeline() function with a negative page parameter.
1540 public function testApiStatusesPublicTimelineWithNegativePage()
1542 $_REQUEST['page'] = -2;
1543 $result = api_statuses_public_timeline('json');
1544 self::assertNotEmpty($result['status']);
1545 foreach ($result['status'] as $status) {
1546 self::assertStatus($status);
1551 * Test the api_statuses_public_timeline() function with an unallowed user.
1555 public function testApiStatusesPublicTimelineWithUnallowedUser()
1557 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1558 $_SESSION['allow_api'] = false;
1559 $_GET['screen_name'] = $this->selfUser['nick'];
1560 BasicAuth::setCurrentUserID();
1561 api_statuses_public_timeline('json');
1565 * Test the api_statuses_public_timeline() function with an RSS result.
1569 public function testApiStatusesPublicTimelineWithRss()
1571 $result = api_statuses_public_timeline('rss');
1572 self::assertXml($result, 'statuses');
1576 * Test the api_statuses_networkpublic_timeline() function.
1580 public function testApiStatusesNetworkpublicTimeline()
1582 $_REQUEST['max_id'] = 10;
1583 $result = api_statuses_networkpublic_timeline('json');
1584 self::assertNotEmpty($result['status']);
1585 foreach ($result['status'] as $status) {
1586 self::assertStatus($status);
1591 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1595 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1597 $_REQUEST['page'] = -2;
1598 $result = api_statuses_networkpublic_timeline('json');
1599 self::assertNotEmpty($result['status']);
1600 foreach ($result['status'] as $status) {
1601 self::assertStatus($status);
1606 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1610 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1612 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1613 $_SESSION['allow_api'] = false;
1614 $_GET['screen_name'] = $this->selfUser['nick'];
1615 BasicAuth::setCurrentUserID();
1616 api_statuses_networkpublic_timeline('json');
1620 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1624 public function testApiStatusesNetworkpublicTimelineWithRss()
1626 $result = api_statuses_networkpublic_timeline('rss');
1627 self::assertXml($result, 'statuses');
1631 * Test the api_statuses_show() function.
1635 public function testApiStatusesShow()
1637 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1638 api_statuses_show('json');
1642 * Test the api_statuses_show() function with an ID.
1646 public function testApiStatusesShowWithId()
1648 DI::args()->setArgv(['', '', '', 1]);
1649 $result = api_statuses_show('json');
1650 self::assertStatus($result['status']);
1654 * Test the api_statuses_show() function with the conversation parameter.
1658 public function testApiStatusesShowWithConversation()
1660 DI::args()->setArgv(['', '', '', 1]);
1661 $_REQUEST['conversation'] = 1;
1662 $result = api_statuses_show('json');
1663 self::assertNotEmpty($result['status']);
1664 foreach ($result['status'] as $status) {
1665 self::assertStatus($status);
1670 * Test the api_statuses_show() function with an unallowed user.
1674 public function testApiStatusesShowWithUnallowedUser()
1676 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1677 $_SESSION['allow_api'] = false;
1678 $_GET['screen_name'] = $this->selfUser['nick'];
1679 BasicAuth::setCurrentUserID();
1680 api_statuses_show('json');
1684 * Test the api_conversation_show() function.
1688 public function testApiConversationShow()
1690 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1691 api_conversation_show('json');
1695 * Test the api_conversation_show() function with an ID.
1699 public function testApiConversationShowWithId()
1701 DI::args()->setArgv(['', '', '', 1]);
1702 $_REQUEST['max_id'] = 10;
1703 $_REQUEST['page'] = -2;
1704 $result = api_conversation_show('json');
1705 self::assertNotEmpty($result['status']);
1706 foreach ($result['status'] as $status) {
1707 self::assertStatus($status);
1712 * Test the api_conversation_show() function with an unallowed user.
1716 public function testApiConversationShowWithUnallowedUser()
1718 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1719 $_SESSION['allow_api'] = false;
1720 $_GET['screen_name'] = $this->selfUser['nick'];
1721 BasicAuth::setCurrentUserID();
1722 api_conversation_show('json');
1726 * Test the api_statuses_repeat() function.
1730 public function testApiStatusesRepeat()
1732 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1733 api_statuses_repeat('json');
1737 * Test the api_statuses_repeat() function without an authenticated user.
1741 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1743 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1744 $_SESSION['authenticated'] = false;
1745 api_statuses_repeat('json');
1749 * Test the api_statuses_repeat() function with an ID.
1753 public function testApiStatusesRepeatWithId()
1755 DI::args()->setArgv(['', '', '', 1]);
1756 $result = api_statuses_repeat('json');
1757 self::assertStatus($result['status']);
1759 // Also test with a shared status
1760 DI::args()->setArgv(['', '', '', 5]);
1761 $result = api_statuses_repeat('json');
1762 self::assertStatus($result['status']);
1766 * Test the api_statuses_destroy() function.
1770 public function testApiStatusesDestroy()
1772 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1773 api_statuses_destroy('json');
1777 * Test the api_statuses_destroy() function without an authenticated user.
1781 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1783 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1784 $_SESSION['authenticated'] = false;
1785 api_statuses_destroy('json');
1789 * Test the api_statuses_destroy() function with an ID.
1793 public function testApiStatusesDestroyWithId()
1795 DI::args()->setArgv(['', '', '', 1]);
1796 $result = api_statuses_destroy('json');
1797 self::assertStatus($result['status']);
1801 * Test the api_statuses_mentions() function.
1805 public function testApiStatusesMentions()
1807 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1808 $_REQUEST['max_id'] = 10;
1809 $result = api_statuses_mentions('json');
1810 self::assertEmpty($result['status']);
1811 // We should test with mentions in the database.
1815 * Test the api_statuses_mentions() function with a negative page parameter.
1819 public function testApiStatusesMentionsWithNegativePage()
1821 $_REQUEST['page'] = -2;
1822 $result = api_statuses_mentions('json');
1823 self::assertEmpty($result['status']);
1827 * Test the api_statuses_mentions() function with an unallowed user.
1831 public function testApiStatusesMentionsWithUnallowedUser()
1833 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1834 $_SESSION['allow_api'] = false;
1835 $_GET['screen_name'] = $this->selfUser['nick'];
1836 BasicAuth::setCurrentUserID();
1837 api_statuses_mentions('json');
1841 * Test the api_statuses_mentions() function with an RSS result.
1845 public function testApiStatusesMentionsWithRss()
1847 $result = api_statuses_mentions('rss');
1848 self::assertXml($result, 'statuses');
1852 * Test the api_statuses_user_timeline() function.
1856 public function testApiStatusesUserTimeline()
1858 $_REQUEST['max_id'] = 10;
1859 $_REQUEST['exclude_replies'] = true;
1860 $_REQUEST['conversation_id'] = 1;
1861 $result = api_statuses_user_timeline('json');
1862 self::assertNotEmpty($result['status']);
1863 foreach ($result['status'] as $status) {
1864 self::assertStatus($status);
1869 * Test the api_statuses_user_timeline() function with a negative page parameter.
1873 public function testApiStatusesUserTimelineWithNegativePage()
1875 $_REQUEST['page'] = -2;
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 an RSS result.
1888 public function testApiStatusesUserTimelineWithRss()
1890 $result = api_statuses_user_timeline('rss');
1891 self::assertXml($result, 'statuses');
1895 * Test the api_statuses_user_timeline() function with an unallowed user.
1899 public function testApiStatusesUserTimelineWithUnallowedUser()
1901 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1902 $_SESSION['allow_api'] = false;
1903 $_GET['screen_name'] = $this->selfUser['nick'];
1904 BasicAuth::setCurrentUserID();
1905 api_statuses_user_timeline('json');
1909 * Test the api_favorites_create_destroy() function.
1913 public function testApiFavoritesCreateDestroy()
1915 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1916 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1917 api_favorites_create_destroy('json');
1921 * Test the api_favorites_create_destroy() function with an invalid ID.
1925 public function testApiFavoritesCreateDestroyWithInvalidId()
1927 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1928 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1929 api_favorites_create_destroy('json');
1933 * Test the api_favorites_create_destroy() function with an invalid action.
1937 public function testApiFavoritesCreateDestroyWithInvalidAction()
1939 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1940 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1941 $_REQUEST['id'] = 1;
1942 api_favorites_create_destroy('json');
1946 * Test the api_favorites_create_destroy() function with the create action.
1950 public function testApiFavoritesCreateDestroyWithCreateAction()
1952 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1953 $_REQUEST['id'] = 3;
1954 $result = api_favorites_create_destroy('json');
1955 self::assertStatus($result['status']);
1959 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1963 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1965 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1966 $_REQUEST['id'] = 3;
1967 $result = api_favorites_create_destroy('rss');
1968 self::assertXml($result, 'status');
1972 * Test the api_favorites_create_destroy() function with the destroy action.
1976 public function testApiFavoritesCreateDestroyWithDestroyAction()
1978 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1979 $_REQUEST['id'] = 3;
1980 $result = api_favorites_create_destroy('json');
1981 self::assertStatus($result['status']);
1985 * Test the api_favorites_create_destroy() function without an authenticated user.
1989 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1991 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1992 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1993 $_SESSION['authenticated'] = false;
1994 api_favorites_create_destroy('json');
1998 * Test the api_favorites() function.
2002 public function testApiFavorites()
2004 $_REQUEST['page'] = -1;
2005 $_REQUEST['max_id'] = 10;
2006 $result = api_favorites('json');
2007 foreach ($result['status'] as $status) {
2008 self::assertStatus($status);
2013 * Test the api_favorites() function with an RSS result.
2017 public function testApiFavoritesWithRss()
2019 $result = api_favorites('rss');
2020 self::assertXml($result, 'statuses');
2024 * Test the api_favorites() function with an unallowed user.
2028 public function testApiFavoritesWithUnallowedUser()
2030 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2031 $_SESSION['allow_api'] = false;
2032 $_GET['screen_name'] = $this->selfUser['nick'];
2033 BasicAuth::setCurrentUserID();
2034 api_favorites('json');
2038 * Test the api_format_messages() function.
2042 public function testApiFormatMessages()
2044 $result = api_format_messages(
2045 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2046 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2047 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2049 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2050 self::assertEquals(1, $result['id']);
2051 self::assertEquals(2, $result['recipient_id']);
2052 self::assertEquals(3, $result['sender_id']);
2053 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2054 self::assertEquals('sender_name', $result['sender_screen_name']);
2058 * Test the api_format_messages() function with HTML.
2062 public function testApiFormatMessagesWithHtmlText()
2064 $_GET['getText'] = 'html';
2065 $result = api_format_messages(
2066 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2067 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2068 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2070 self::assertEquals('item_title', $result['title']);
2071 self::assertEquals('<strong>item_body</strong>', $result['text']);
2075 * Test the api_format_messages() function with plain text.
2079 public function testApiFormatMessagesWithPlainText()
2081 $_GET['getText'] = 'plain';
2082 $result = api_format_messages(
2083 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2084 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2085 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2087 self::assertEquals('item_title', $result['title']);
2088 self::assertEquals('item_body', $result['text']);
2092 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2096 public function testApiFormatMessagesWithoutUserObjects()
2098 $_GET['getUserObjects'] = 'false';
2099 $result = api_format_messages(
2100 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2101 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2102 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2104 self::assertTrue(!isset($result['sender']));
2105 self::assertTrue(!isset($result['recipient']));
2109 * Test the api_convert_item() function.
2113 public function testApiConvertItem()
2115 $result = api_convert_item(
2117 'network' => 'feed',
2118 'title' => 'item_title',
2120 // We need a long string to test that it is correctly cut
2121 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2122 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2123 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2124 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2125 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2126 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2127 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2128 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2129 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2130 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2131 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2132 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2133 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2134 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2135 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2136 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2137 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2138 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2139 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2140 'repellat officia illum quos impedit quam iste esse unde qui ' .
2141 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2142 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2143 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2144 'plink' => 'item_plink'
2147 self::assertStringStartsWith('item_title', $result['text']);
2148 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2152 * Test the api_convert_item() function with an empty item body.
2156 public function testApiConvertItemWithoutBody()
2158 $result = api_convert_item(
2160 'network' => 'feed',
2161 'title' => 'item_title',
2164 'plink' => 'item_plink'
2167 self::assertEquals("item_title", $result['text']);
2168 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2172 * Test the api_convert_item() function with the title in the body.
2176 public function testApiConvertItemWithTitleInBody()
2178 $result = api_convert_item(
2180 'title' => 'item_title',
2181 'body' => 'item_title item_body',
2185 self::assertEquals('item_title item_body', $result['text']);
2186 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2190 * Test the api_get_attachments() function.
2194 public function testApiGetAttachments()
2197 self::assertEmpty(api_get_attachments($body, 0));
2201 * Test the api_get_attachments() function with an img tag.
2205 public function testApiGetAttachmentsWithImage()
2207 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2208 self::assertIsArray(api_get_attachments($body, 0));
2212 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2216 public function testApiGetAttachmentsWithImageAndAndStatus()
2218 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2219 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2220 self::assertIsArray(api_get_attachments($body, 0));
2224 * Test the api_get_entitities() function.
2228 public function testApiGetEntitities()
2231 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2235 * Test the api_get_entitities() function with the include_entities parameter.
2239 public function testApiGetEntititiesWithIncludeEntities()
2241 $_REQUEST['include_entities'] = 'true';
2243 $result = api_get_entitities($text, 'bbcode', 0);
2244 self::assertIsArray($result['hashtags']);
2245 self::assertIsArray($result['symbols']);
2246 self::assertIsArray($result['urls']);
2247 self::assertIsArray($result['user_mentions']);
2251 * Test the api_format_items_embeded_images() function.
2255 public function testApiFormatItemsEmbededImages()
2258 'text ' . DI::baseUrl() . '/display/item_guid',
2259 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2264 * Test the api_contactlink_to_array() function.
2268 public function testApiContactlinkToArray()
2275 api_contactlink_to_array('text')
2280 * Test the api_contactlink_to_array() function with an URL.
2284 public function testApiContactlinkToArrayWithUrl()
2288 'name' => ['link_text'],
2291 api_contactlink_to_array('text <a href="url">link_text</a>')
2296 * Test the api_format_items_activities() function.
2300 public function testApiFormatItemsActivities()
2302 $item = ['uid' => 0, 'uri' => ''];
2303 $result = api_format_items_activities($item);
2304 self::assertArrayHasKey('like', $result);
2305 self::assertArrayHasKey('dislike', $result);
2306 self::assertArrayHasKey('attendyes', $result);
2307 self::assertArrayHasKey('attendno', $result);
2308 self::assertArrayHasKey('attendmaybe', $result);
2312 * Test the api_format_items_activities() function with an XML result.
2316 public function testApiFormatItemsActivitiesWithXml()
2318 $item = ['uid' => 0, 'uri' => ''];
2319 $result = api_format_items_activities($item, 'xml');
2320 self::assertArrayHasKey('friendica:like', $result);
2321 self::assertArrayHasKey('friendica:dislike', $result);
2322 self::assertArrayHasKey('friendica:attendyes', $result);
2323 self::assertArrayHasKey('friendica:attendno', $result);
2324 self::assertArrayHasKey('friendica:attendmaybe', $result);
2328 * Test the api_format_items() function.
2329 * @doesNotPerformAssertions
2331 public function testApiFormatItems()
2335 'item_network' => 'item_network',
2341 'author-network' => Protocol::DFRN,
2342 'author-link' => 'http://localhost/profile/othercontact',
2346 $result = api_format_items($items, ['id' => 0], true);
2347 foreach ($result as $status) {
2348 self::assertStatus($status);
2353 * Test the api_format_items() function with an XML result.
2354 * @doesNotPerformAssertions
2356 public function testApiFormatItemsWithXml()
2364 'author-network' => Protocol::DFRN,
2365 'author-link' => 'http://localhost/profile/othercontact',
2369 $result = api_format_items($items, ['id' => 0], true, 'xml');
2370 foreach ($result as $status) {
2371 self::assertStatus($status);
2376 * Test the api_lists_list() function.
2380 public function testApiListsList()
2382 $result = api_lists_list('json');
2383 self::assertEquals(['lists_list' => []], $result);
2387 * Test the api_lists_ownerships() function.
2391 public function testApiListsOwnerships()
2393 $result = api_lists_ownerships('json');
2394 foreach ($result['lists']['lists'] as $list) {
2395 self::assertList($list);
2400 * Test the api_lists_ownerships() function without an authenticated user.
2404 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2406 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2407 $_SESSION['authenticated'] = false;
2408 api_lists_ownerships('json');
2412 * Test the api_lists_statuses() function.
2416 public function testApiListsStatuses()
2418 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2419 api_lists_statuses('json');
2423 * Test the api_lists_statuses() function with a list ID.
2424 * @doesNotPerformAssertions
2426 public function testApiListsStatusesWithListId()
2428 $_REQUEST['list_id'] = 1;
2429 $_REQUEST['page'] = -1;
2430 $_REQUEST['max_id'] = 10;
2431 $result = api_lists_statuses('json');
2432 foreach ($result['status'] as $status) {
2433 self::assertStatus($status);
2438 * Test the api_lists_statuses() function with a list ID and a RSS result.
2442 public function testApiListsStatusesWithListIdAndRss()
2444 $_REQUEST['list_id'] = 1;
2445 $result = api_lists_statuses('rss');
2446 self::assertXml($result, 'statuses');
2450 * Test the api_lists_statuses() function with an unallowed user.
2454 public function testApiListsStatusesWithUnallowedUser()
2456 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2457 $_SESSION['allow_api'] = false;
2458 $_GET['screen_name'] = $this->selfUser['nick'];
2459 BasicAuth::setCurrentUserID();
2460 api_lists_statuses('json');
2464 * Test the api_statuses_f() function.
2468 public function testApiStatusesFWithFriends()
2471 $result = api_statuses_f('friends');
2472 self::assertArrayHasKey('user', $result);
2476 * Test the api_statuses_f() function.
2480 public function testApiStatusesFWithFollowers()
2482 $result = api_statuses_f('followers');
2483 self::assertArrayHasKey('user', $result);
2487 * Test the api_statuses_f() function.
2491 public function testApiStatusesFWithBlocks()
2493 $result = api_statuses_f('blocks');
2494 self::assertArrayHasKey('user', $result);
2498 * Test the api_statuses_f() function.
2502 public function testApiStatusesFWithIncoming()
2504 $result = api_statuses_f('incoming');
2505 self::assertArrayHasKey('user', $result);
2509 * Test the api_statuses_f() function an undefined cursor GET variable.
2513 public function testApiStatusesFWithUndefinedCursor()
2515 $_GET['cursor'] = 'undefined';
2516 self::assertFalse(api_statuses_f('friends'));
2520 * Test the api_statuses_friends() function.
2524 public function testApiStatusesFriends()
2526 $result = api_statuses_friends('json');
2527 self::assertArrayHasKey('user', $result);
2531 * Test the api_statuses_friends() function an undefined cursor GET variable.
2535 public function testApiStatusesFriendsWithUndefinedCursor()
2537 $_GET['cursor'] = 'undefined';
2538 self::assertFalse(api_statuses_friends('json'));
2542 * Test the api_statuses_followers() function.
2546 public function testApiStatusesFollowers()
2548 $result = api_statuses_followers('json');
2549 self::assertArrayHasKey('user', $result);
2553 * Test the api_statuses_followers() function an undefined cursor GET variable.
2557 public function testApiStatusesFollowersWithUndefinedCursor()
2559 $_GET['cursor'] = 'undefined';
2560 self::assertFalse(api_statuses_followers('json'));
2564 * Test the api_blocks_list() function.
2568 public function testApiBlocksList()
2570 $result = api_blocks_list('json');
2571 self::assertArrayHasKey('user', $result);
2575 * Test the api_blocks_list() function an undefined cursor GET variable.
2579 public function testApiBlocksListWithUndefinedCursor()
2581 $_GET['cursor'] = 'undefined';
2582 self::assertFalse(api_blocks_list('json'));
2586 * Test the api_friendships_incoming() function.
2590 public function testApiFriendshipsIncoming()
2592 $result = api_friendships_incoming('json');
2593 self::assertArrayHasKey('id', $result);
2597 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2601 public function testApiFriendshipsIncomingWithUndefinedCursor()
2603 $_GET['cursor'] = 'undefined';
2604 self::assertFalse(api_friendships_incoming('json'));
2608 * Test the api_statusnet_config() function.
2612 public function testApiStatusnetConfig()
2615 $result = api_statusnet_config('json');
2616 self::assertEquals('localhost', $result['config']['site']['server']);
2617 self::assertEquals('default', $result['config']['site']['theme']);
2618 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2619 self::assertTrue($result['config']['site']['fancy']);
2620 self::assertEquals('en', $result['config']['site']['language']);
2621 self::assertEquals('UTC', $result['config']['site']['timezone']);
2622 self::assertEquals(200000, $result['config']['site']['textlimit']);
2623 self::assertEquals('false', $result['config']['site']['private']);
2624 self::assertEquals('false', $result['config']['site']['ssl']);
2625 self::assertEquals(30, $result['config']['site']['shorturllength']);
2630 * Test the api_direct_messages_new() function.
2634 public function testApiDirectMessagesNew()
2636 $result = api_direct_messages_new('json');
2637 self::assertNull($result);
2641 * Test the api_direct_messages_new() function without an authenticated user.
2645 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2647 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2648 $_SESSION['authenticated'] = false;
2649 api_direct_messages_new('json');
2653 * Test the api_direct_messages_new() function with an user ID.
2657 public function testApiDirectMessagesNewWithUserId()
2659 $_POST['text'] = 'message_text';
2660 $_POST['user_id'] = $this->otherUser['id'];
2661 $result = api_direct_messages_new('json');
2662 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2666 * Test the api_direct_messages_new() function with a screen name.
2670 public function testApiDirectMessagesNewWithScreenName()
2672 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2673 $_POST['text'] = 'message_text';
2674 $_POST['screen_name'] = $this->friendUser['nick'];
2675 $result = api_direct_messages_new('json');
2676 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2677 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2678 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2682 * Test the api_direct_messages_new() function with a title.
2686 public function testApiDirectMessagesNewWithTitle()
2688 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2689 $_POST['text'] = 'message_text';
2690 $_POST['screen_name'] = $this->friendUser['nick'];
2691 $_REQUEST['title'] = 'message_title';
2692 $result = api_direct_messages_new('json');
2693 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2694 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2695 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2696 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2700 * Test the api_direct_messages_new() function with an RSS result.
2704 public function testApiDirectMessagesNewWithRss()
2706 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2707 $_POST['text'] = 'message_text';
2708 $_POST['screen_name'] = $this->friendUser['nick'];
2709 $result = api_direct_messages_new('rss');
2710 self::assertXml($result, 'direct-messages');
2714 * Test the api_direct_messages_destroy() function.
2718 public function testApiDirectMessagesDestroy()
2720 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2721 api_direct_messages_destroy('json');
2725 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2729 public function testApiDirectMessagesDestroyWithVerbose()
2731 $_GET['friendica_verbose'] = 'true';
2732 $result = api_direct_messages_destroy('json');
2736 'result' => 'error',
2737 'message' => 'message id or parenturi not specified'
2745 * Test the api_direct_messages_destroy() function without an authenticated user.
2749 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2751 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2752 $_SESSION['authenticated'] = false;
2753 api_direct_messages_destroy('json');
2757 * Test the api_direct_messages_destroy() function with a non-zero ID.
2761 public function testApiDirectMessagesDestroyWithId()
2763 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2764 $_REQUEST['id'] = 1;
2765 api_direct_messages_destroy('json');
2769 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2773 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2775 $_REQUEST['id'] = 1;
2776 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2777 $_GET['friendica_verbose'] = 'true';
2778 $result = api_direct_messages_destroy('json');
2782 'result' => 'error',
2783 'message' => 'message id not in database'
2791 * Test the api_direct_messages_destroy() function with a non-zero ID.
2795 public function testApiDirectMessagesDestroyWithCorrectId()
2797 $this->markTestIncomplete('We need to add a dataset for this.');
2801 * Test the api_direct_messages_box() function.
2805 public function testApiDirectMessagesBoxWithSentbox()
2807 $_REQUEST['page'] = -1;
2808 $_REQUEST['max_id'] = 10;
2809 $result = api_direct_messages_box('json', 'sentbox', 'false');
2810 self::assertArrayHasKey('direct_message', $result);
2814 * Test the api_direct_messages_box() function.
2818 public function testApiDirectMessagesBoxWithConversation()
2820 $result = api_direct_messages_box('json', 'conversation', 'false');
2821 self::assertArrayHasKey('direct_message', $result);
2825 * Test the api_direct_messages_box() function.
2829 public function testApiDirectMessagesBoxWithAll()
2831 $result = api_direct_messages_box('json', 'all', 'false');
2832 self::assertArrayHasKey('direct_message', $result);
2836 * Test the api_direct_messages_box() function.
2840 public function testApiDirectMessagesBoxWithInbox()
2842 $result = api_direct_messages_box('json', 'inbox', 'false');
2843 self::assertArrayHasKey('direct_message', $result);
2847 * Test the api_direct_messages_box() function.
2851 public function testApiDirectMessagesBoxWithVerbose()
2853 $result = api_direct_messages_box('json', 'sentbox', 'true');
2857 'result' => 'error',
2858 'message' => 'no mails available'
2866 * Test the api_direct_messages_box() function with a RSS result.
2870 public function testApiDirectMessagesBoxWithRss()
2872 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2873 self::assertXml($result, 'direct-messages');
2877 * Test the api_direct_messages_box() function without an authenticated user.
2881 public function testApiDirectMessagesBoxWithUnallowedUser()
2883 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2884 $_SESSION['allow_api'] = false;
2885 $_GET['screen_name'] = $this->selfUser['nick'];
2886 BasicAuth::setCurrentUserID();
2887 api_direct_messages_box('json', 'sentbox', 'false');
2891 * Test the api_direct_messages_sentbox() function.
2895 public function testApiDirectMessagesSentbox()
2897 $result = api_direct_messages_sentbox('json');
2898 self::assertArrayHasKey('direct_message', $result);
2902 * Test the api_direct_messages_inbox() function.
2906 public function testApiDirectMessagesInbox()
2908 $result = api_direct_messages_inbox('json');
2909 self::assertArrayHasKey('direct_message', $result);
2913 * Test the api_direct_messages_all() function.
2917 public function testApiDirectMessagesAll()
2919 $result = api_direct_messages_all('json');
2920 self::assertArrayHasKey('direct_message', $result);
2924 * Test the api_direct_messages_conversation() function.
2928 public function testApiDirectMessagesConversation()
2930 $result = api_direct_messages_conversation('json');
2931 self::assertArrayHasKey('direct_message', $result);
2935 * Test the api_oauth_request_token() function.
2939 public function testApiOauthRequestToken()
2941 $this->markTestIncomplete('exit() kills phpunit as well');
2945 * Test the api_oauth_access_token() function.
2949 public function testApiOauthAccessToken()
2951 $this->markTestIncomplete('exit() kills phpunit as well');
2955 * Test the api_fr_photos_list() function.
2959 public function testApiFrPhotosList()
2961 $result = api_fr_photos_list('json');
2962 self::assertArrayHasKey('photo', $result);
2966 * Test the api_fr_photos_list() function without an authenticated user.
2970 public function testApiFrPhotosListWithoutAuthenticatedUser()
2972 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2973 $_SESSION['authenticated'] = false;
2974 api_fr_photos_list('json');
2978 * Test the api_fr_photo_create_update() function.
2980 public function testApiFrPhotoCreateUpdate()
2982 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2983 api_fr_photo_create_update('json');
2987 * Test the api_fr_photo_create_update() function without an authenticated user.
2991 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
2993 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2994 $_SESSION['authenticated'] = false;
2995 api_fr_photo_create_update('json');
2999 * Test the api_fr_photo_create_update() function with an album name.
3003 public function testApiFrPhotoCreateUpdateWithAlbum()
3005 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3006 $_REQUEST['album'] = 'album_name';
3007 api_fr_photo_create_update('json');
3011 * Test the api_fr_photo_create_update() function with the update mode.
3015 public function testApiFrPhotoCreateUpdateWithUpdate()
3017 $this->markTestIncomplete('We need to create a dataset for this');
3021 * Test the api_fr_photo_create_update() function with an uploaded file.
3025 public function testApiFrPhotoCreateUpdateWithFile()
3027 $this->markTestIncomplete();
3031 * Test the api_fr_photo_detail() function.
3035 public function testApiFrPhotoDetail()
3037 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3038 api_fr_photo_detail('json');
3042 * Test the api_fr_photo_detail() function without an authenticated user.
3046 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3048 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3049 $_SESSION['authenticated'] = false;
3050 api_fr_photo_detail('json');
3054 * Test the api_fr_photo_detail() function with a photo ID.
3058 public function testApiFrPhotoDetailWithPhotoId()
3060 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3061 $_REQUEST['photo_id'] = 1;
3062 api_fr_photo_detail('json');
3066 * Test the api_fr_photo_detail() function with a correct photo ID.
3070 public function testApiFrPhotoDetailCorrectPhotoId()
3072 $this->markTestIncomplete('We need to create a dataset for this.');
3076 * Test the api_account_update_profile_image() function.
3080 public function testApiAccountUpdateProfileImage()
3082 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3083 api_account_update_profile_image('json');
3087 * Test the api_account_update_profile_image() function without an authenticated user.
3091 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3093 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3094 $_SESSION['authenticated'] = false;
3095 api_account_update_profile_image('json');
3099 * Test the api_account_update_profile_image() function with an uploaded file.
3103 public function testApiAccountUpdateProfileImageWithUpload()
3105 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3106 $this->markTestIncomplete();
3111 * Test the api_account_update_profile() function.
3115 public function testApiAccountUpdateProfile()
3117 $_POST['name'] = 'new_name';
3118 $_POST['description'] = 'new_description';
3119 $result = api_account_update_profile('json');
3120 // We can't use assertSelfUser() here because the user object is missing some properties.
3121 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3122 self::assertEquals('DFRN', $result['user']['location']);
3123 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3124 self::assertEquals('dfrn', $result['user']['network']);
3125 self::assertEquals('new_name', $result['user']['name']);
3126 self::assertEquals('new_description', $result['user']['description']);
3130 * Test the check_acl_input() function.
3134 public function testCheckAclInput()
3136 $result = check_acl_input('<aclstring>');
3137 // Where does this result come from?
3138 self::assertEquals(1, $result);
3142 * Test the check_acl_input() function with an empty ACL string.
3146 public function testCheckAclInputWithEmptyAclString()
3148 $result = check_acl_input(' ');
3149 self::assertFalse($result);
3153 * Test the save_media_to_database() function.
3157 public function testSaveMediaToDatabase()
3159 $this->markTestIncomplete();
3163 * Test the post_photo_item() function.
3167 public function testPostPhotoItem()
3169 $this->markTestIncomplete();
3173 * Test the prepare_photo_data() function.
3177 public function testPreparePhotoData()
3179 $this->markTestIncomplete();
3183 * Test the api_share_as_retweet() function with a valid item.
3187 public function testApiShareAsRetweetWithValidItem()
3189 $this->markTestIncomplete();
3193 * Test the api_in_reply_to() function.
3197 public function testApiInReplyTo()
3199 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3200 self::assertArrayHasKey('status_id', $result);
3201 self::assertArrayHasKey('user_id', $result);
3202 self::assertArrayHasKey('status_id_str', $result);
3203 self::assertArrayHasKey('user_id_str', $result);
3204 self::assertArrayHasKey('screen_name', $result);
3208 * Test the api_in_reply_to() function with a valid item.
3212 public function testApiInReplyToWithValidItem()
3214 $this->markTestIncomplete();
3218 * Test the api_clean_plain_items() function.
3222 public function testApiCleanPlainItems()
3224 $_REQUEST['include_entities'] = 'true';
3225 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3226 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3230 * Test the api_best_nickname() function.
3234 public function testApiBestNickname()
3237 $result = api_best_nickname($contacts);
3238 self::assertNull($result);
3242 * Test the api_best_nickname() function with contacts.
3246 public function testApiBestNicknameWithContacts()
3248 $this->markTestIncomplete();
3252 * Test the api_friendica_group_show() function.
3256 public function testApiFriendicaGroupShow()
3258 $this->markTestIncomplete();
3262 * Test the api_friendica_group_delete() function.
3266 public function testApiFriendicaGroupDelete()
3268 $this->markTestIncomplete();
3272 * Test the api_lists_destroy() function.
3276 public function testApiListsDestroy()
3278 $this->markTestIncomplete();
3282 * Test the group_create() function.
3286 public function testGroupCreate()
3288 $this->markTestIncomplete();
3292 * Test the api_friendica_group_create() function.
3296 public function testApiFriendicaGroupCreate()
3298 $this->markTestIncomplete();
3302 * Test the api_lists_create() function.
3306 public function testApiListsCreate()
3308 $this->markTestIncomplete();
3312 * Test the api_friendica_group_update() function.
3316 public function testApiFriendicaGroupUpdate()
3318 $this->markTestIncomplete();
3322 * Test the api_lists_update() function.
3326 public function testApiListsUpdate()
3328 $this->markTestIncomplete();
3332 * Test the api_friendica_activity() function.
3336 public function testApiFriendicaActivity()
3338 $this->markTestIncomplete();
3342 * Test the api_friendica_notification_seen() function.
3346 public function testApiFriendicaNotificationSeen()
3348 $this->markTestIncomplete();
3352 * Test the api_friendica_direct_messages_setseen() function.
3356 public function testApiFriendicaDirectMessagesSetseen()
3358 $this->markTestIncomplete();
3362 * Test the api_friendica_direct_messages_search() function.
3366 public function testApiFriendicaDirectMessagesSearch()
3368 $this->markTestIncomplete();