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
113 'authenticated' => true,
114 'uid' => $this->selfUser['id']
116 BasicAuth::setCurrentUserID($this->selfUser['id']);
120 * Assert that an user array contains expected keys.
122 * @param array $user User array
126 private function assertSelfUser(array $user)
128 self::assertEquals($this->selfUser['id'], $user['uid']);
129 self::assertEquals($this->selfUser['id'], $user['cid']);
130 self::assertEquals(1, $user['self']);
131 self::assertEquals('DFRN', $user['location']);
132 self::assertEquals($this->selfUser['name'], $user['name']);
133 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
134 self::assertEquals('dfrn', $user['network']);
135 self::assertTrue($user['verified']);
139 * Assert that an user array contains expected keys.
141 * @param array $user User array
145 private function assertOtherUser(array $user = [])
147 self::assertEquals($this->otherUser['id'], $user['id']);
148 self::assertEquals($this->otherUser['id'], $user['id_str']);
149 self::assertEquals(0, $user['self']);
150 self::assertEquals($this->otherUser['name'], $user['name']);
151 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
152 self::assertFalse($user['verified']);
156 * Assert that a status array contains expected keys.
158 * @param array $status Status array
162 private function assertStatus(array $status = [])
164 self::assertIsString($status['text'] ?? '');
165 self::assertIsInt($status['id'] ?? '');
166 // We could probably do more checks here.
170 * Assert that a list array contains expected keys.
172 * @param array $list List array
176 private function assertList(array $list = [])
178 self::assertIsString($list['name']);
179 self::assertIsInt($list['id']);
180 self::assertIsString('string', $list['id_str']);
181 self::assertContains($list['mode'], ['public', 'private']);
182 // We could probably do more checks here.
186 * Assert that the string is XML and contain the root element.
188 * @param string $result XML string
189 * @param string $root_element Root element name
193 private function assertXml($result = '', $root_element = '')
195 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
196 self::assertStringContainsString('<' . $root_element, $result);
197 // We could probably do more checks here.
201 * Get the path to a temporary empty PNG image.
203 * @return string Path
205 private function getTempImage()
207 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
211 // Empty 1x1 px PNG image
212 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
220 * Test the api_user() function.
224 public function testApiUser()
226 self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
230 * Test the api_user() function with an unallowed user.
234 public function testApiUserWithUnallowedUser()
236 // self::assertEquals(false, api_user());
240 * Test the api_source() function.
244 public function testApiSource()
246 self::assertEquals('api', api_source());
250 * Test the api_source() function with a Twidere user agent.
254 public function testApiSourceWithTwidere()
256 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
257 self::assertEquals('Twidere', api_source());
261 * Test the api_source() function with a GET parameter.
265 public function testApiSourceWithGet()
267 $_GET['source'] = 'source_name';
268 self::assertEquals('source_name', api_source());
272 * Test the api_date() function.
276 public function testApiDate()
278 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
282 * Test the api_register_func() function.
286 public function testApiRegisterFunc()
298 self::assertTrue($API['api_path']['auth']);
299 self::assertEquals('method', $API['api_path']['method']);
300 self::assertTrue(is_callable($API['api_path']['func']));
304 * Test the BasicAuth::getCurrentUserID() function without any login.
306 * @runInSeparateProcess
307 * @preserveGlobalState disabled
308 * @preserveGlobalState disabled
310 public function testApiLoginWithoutLogin()
312 BasicAuth::setCurrentUserID();
313 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314 BasicAuth::getCurrentUserID(true);
318 * Test the BasicAuth::getCurrentUserID() function with a bad login.
320 * @runInSeparateProcess
321 * @preserveGlobalState disabled
322 * @preserveGlobalState disabled
324 public function testApiLoginWithBadLogin()
326 BasicAuth::setCurrentUserID();
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 BasicAuth::setCurrentUserID();
362 $_SERVER['PHP_AUTH_USER'] = 'Test user';
363 $_SERVER['PHP_AUTH_PW'] = 'password';
364 BasicAuth::getCurrentUserID(true);
368 * Test the BasicAuth::getCurrentUserID() function with a remote user.
370 * @runInSeparateProcess
371 * @preserveGlobalState disabled
373 public function testApiLoginWithRemoteUser()
375 BasicAuth::setCurrentUserID();
376 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
377 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
378 BasicAuth::getCurrentUserID(true);
382 * Test the api_check_method() function.
386 public function testApiCheckMethod()
388 self::assertFalse(api_check_method('method'));
392 * Test the api_check_method() function with a correct method.
396 public function testApiCheckMethodWithCorrectMethod()
398 $_SERVER['REQUEST_METHOD'] = 'method';
399 self::assertTrue(api_check_method('method'));
403 * Test the api_check_method() function with a wildcard.
407 public function testApiCheckMethodWithWildcard()
409 self::assertTrue(api_check_method('*'));
413 * Test the api_call() function.
415 * @runInSeparateProcess
416 * @preserveGlobalState disabled
418 public function testApiCall()
422 'method' => 'method',
423 'func' => function () {
424 return ['data' => ['some_data']];
427 $_SERVER['REQUEST_METHOD'] = 'method';
428 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
429 $_GET['callback'] = 'callback_name';
431 $args = DI::args()->determine($_SERVER, $_GET);
434 'callback_name(["some_data"])',
435 api_call($this->app, $args)
440 * Test the api_call() function with the profiled enabled.
442 * @runInSeparateProcess
443 * @preserveGlobalState disabled
445 public function testApiCallWithProfiler()
449 'method' => 'method',
450 'func' => function () {
451 return ['data' => ['some_data']];
455 $_SERVER['REQUEST_METHOD'] = 'method';
456 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
458 $args = DI::args()->determine($_SERVER, $_GET);
460 $this->config->set('system', 'profiler', true);
461 $this->config->set('rendertime', 'callstack', true);
462 $this->app->callstack = [
463 'database' => ['some_function' => 200],
464 'database_write' => ['some_function' => 200],
465 'cache' => ['some_function' => 200],
466 'cache_write' => ['some_function' => 200],
467 'network' => ['some_function' => 200]
472 api_call($this->app, $args)
477 * Test the api_call() function with a JSON result.
479 * @runInSeparateProcess
480 * @preserveGlobalState disabled
482 public function testApiCallWithJson()
486 'method' => 'method',
487 'func' => function () {
488 return ['data' => ['some_data']];
491 $_SERVER['REQUEST_METHOD'] = 'method';
492 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
494 $args = DI::args()->determine($_SERVER, $_GET);
498 api_call($this->app, $args)
503 * Test the api_call() function with an XML result.
505 * @runInSeparateProcess
506 * @preserveGlobalState disabled
508 public function testApiCallWithXml()
512 'method' => 'method',
513 'func' => function () {
517 $_SERVER['REQUEST_METHOD'] = 'method';
518 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
520 $args = DI::args()->determine($_SERVER, $_GET);
524 api_call($this->app, $args)
529 * Test the api_call() function with an RSS result.
531 * @runInSeparateProcess
532 * @preserveGlobalState disabled
534 public function testApiCallWithRss()
538 'method' => 'method',
539 'func' => function () {
543 $_SERVER['REQUEST_METHOD'] = 'method';
544 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
546 $args = DI::args()->determine($_SERVER, $_GET);
549 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
551 api_call($this->app, $args)
556 * Test the api_call() function with an Atom result.
558 * @runInSeparateProcess
559 * @preserveGlobalState disabled
561 public function testApiCallWithAtom()
565 'method' => 'method',
566 'func' => function () {
570 $_SERVER['REQUEST_METHOD'] = 'method';
571 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
573 $args = DI::args()->determine($_SERVER, $_GET);
576 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
578 api_call($this->app, $args)
583 * Test the api_rss_extra() function.
587 public function testApiRssExtra()
589 $user_info = ['url' => 'user_url', 'lang' => 'en'];
590 $result = api_rss_extra([], $user_info);
591 self::assertEquals($user_info, $result['$user']);
592 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
593 self::assertArrayHasKey('self', $result['$rss']);
594 self::assertArrayHasKey('base', $result['$rss']);
595 self::assertArrayHasKey('updated', $result['$rss']);
596 self::assertArrayHasKey('atom_updated', $result['$rss']);
597 self::assertArrayHasKey('language', $result['$rss']);
598 self::assertArrayHasKey('logo', $result['$rss']);
602 * Test the api_rss_extra() function without any user info.
606 public function testApiRssExtraWithoutUserInfo()
608 $result = api_rss_extra([], null);
609 self::assertIsArray($result['$user']);
610 self::assertArrayHasKey('alternate', $result['$rss']);
611 self::assertArrayHasKey('self', $result['$rss']);
612 self::assertArrayHasKey('base', $result['$rss']);
613 self::assertArrayHasKey('updated', $result['$rss']);
614 self::assertArrayHasKey('atom_updated', $result['$rss']);
615 self::assertArrayHasKey('language', $result['$rss']);
616 self::assertArrayHasKey('logo', $result['$rss']);
620 * Test the api_unique_id_to_nurl() function.
624 public function testApiUniqueIdToNurl()
626 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
630 * Test the api_unique_id_to_nurl() function with a correct ID.
634 public function testApiUniqueIdToNurlWithCorrectId()
636 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
640 * Test the api_get_user() function.
644 public function testApiGetUser()
646 // $user = api_get_user();
647 // self::assertSelfUser($user);
648 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
649 // self::assertEquals('6fdbe8', $user['profile_link_color']);
650 // self::assertEquals('ededed', $user['profile_background_color']);
654 * Test the api_get_user() function with a Frio schema.
658 public function testApiGetUserWithFrioSchema()
660 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
661 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
662 // $user = api_get_user();
663 // self::assertSelfUser($user);
664 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
665 // self::assertEquals('6fdbe8', $user['profile_link_color']);
666 // self::assertEquals('ededed', $user['profile_background_color']);
670 * Test the api_get_user() function with an empty Frio schema.
674 public function testApiGetUserWithEmptyFrioSchema()
676 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
677 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
678 // $user = api_get_user();
679 // self::assertSelfUser($user);
680 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
681 // self::assertEquals('6fdbe8', $user['profile_link_color']);
682 // self::assertEquals('ededed', $user['profile_background_color']);
686 * Test the api_get_user() function with a custom Frio schema.
690 public function testApiGetUserWithCustomFrioSchema()
692 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
693 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
694 // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
695 // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
696 // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
697 // $user = api_get_user();
698 // self::assertSelfUser($user);
699 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
700 // self::assertEquals('123456', $user['profile_link_color']);
701 // self::assertEquals('123456', $user['profile_background_color']);
705 * Test the api_get_user() function with an user that is not allowed to use the API.
707 * @runInSeparateProcess
708 * @preserveGlobalState disabled
710 public function testApiGetUserWithoutApiUser()
712 // api_get_user() with empty parameters is not used anymore
714 $_SERVER['PHP_AUTH_USER'] = 'Test user';
715 $_SERVER['PHP_AUTH_PW'] = 'password';
716 BasicAuth::setCurrentUserID();
717 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()
773 // global $called_api;
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()
786 // global $called_api;
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 BasicAuth::setCurrentUserID();
1006 $_SESSION['authenticated'] = false;
1007 api_account_verify_credentials('json');
1011 * Test the requestdata() function.
1015 public function testRequestdata()
1017 self::assertNull(requestdata('variable_name'));
1021 * Test the requestdata() function with a POST parameter.
1025 public function testRequestdataWithPost()
1027 $_POST['variable_name'] = 'variable_value';
1028 self::assertEquals('variable_value', requestdata('variable_name'));
1032 * Test the requestdata() function with a GET parameter.
1036 public function testRequestdataWithGet()
1038 $_GET['variable_name'] = 'variable_value';
1039 self::assertEquals('variable_value', requestdata('variable_name'));
1043 * Test the api_statuses_mediap() function.
1047 public function testApiStatusesMediap()
1049 DI::args()->setArgc(2);
1057 'tmp_name' => $this->getTempImage(),
1058 'name' => 'spacer.png',
1059 'type' => 'image/png'
1062 $_GET['status'] = '<b>Status content</b>';
1064 $result = api_statuses_mediap('json');
1065 self::assertStatus($result['status']);
1069 * Test the api_statuses_mediap() function without an authenticated user.
1073 public function testApiStatusesMediapWithoutAuthenticatedUser()
1075 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1076 BasicAuth::setCurrentUserID();
1077 $_SESSION['authenticated'] = false;
1078 api_statuses_mediap('json');
1082 * Test the api_statuses_update() function.
1086 public function testApiStatusesUpdate()
1088 $_GET['status'] = 'Status content #friendica';
1089 $_GET['in_reply_to_status_id'] = -1;
1098 'tmp_name' => $this->getTempImage(),
1099 'name' => 'spacer.png',
1100 'type' => 'image/png'
1104 $result = api_statuses_update('json');
1105 self::assertStatus($result['status']);
1109 * Test the api_statuses_update() function with an HTML status.
1113 public function testApiStatusesUpdateWithHtml()
1115 $_GET['htmlstatus'] = '<b>Status content</b>';
1117 $result = api_statuses_update('json');
1118 self::assertStatus($result['status']);
1122 * Test the api_statuses_update() function without an authenticated user.
1126 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1128 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1129 BasicAuth::setCurrentUserID();
1130 $_SESSION['authenticated'] = false;
1131 api_statuses_update('json');
1135 * Test the api_statuses_update() function with a parent status.
1139 public function testApiStatusesUpdateWithParent()
1141 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1145 * Test the api_statuses_update() function with a media_ids parameter.
1149 public function testApiStatusesUpdateWithMediaIds()
1151 $this->markTestIncomplete();
1155 * Test the api_statuses_update() function with the throttle limit reached.
1159 public function testApiStatusesUpdateWithDayThrottleReached()
1161 $this->markTestIncomplete();
1165 * Test the api_media_upload() function.
1166 * @runInSeparateProcess
1167 * @preserveGlobalState disabled
1169 public function testApiMediaUpload()
1171 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1176 * Test the api_media_upload() function without an authenticated user.
1180 public function testApiMediaUploadWithoutAuthenticatedUser()
1182 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1183 BasicAuth::setCurrentUserID();
1184 $_SESSION['authenticated'] = false;
1189 * Test the api_media_upload() function with an invalid uploaded media.
1193 public function testApiMediaUploadWithMedia()
1195 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1199 'tmp_name' => 'tmp_name'
1206 * Test the api_media_upload() function with an valid uploaded media.
1210 public function testApiMediaUploadWithValidMedia()
1218 'tmp_name' => $this->getTempImage(),
1219 'name' => 'spacer.png',
1220 'type' => 'image/png'
1224 DI::args()->setArgc(2);
1226 $result = api_media_upload();
1227 self::assertEquals('image/png', $result['media']['image']['image_type']);
1228 self::assertEquals(1, $result['media']['image']['w']);
1229 self::assertEquals(1, $result['media']['image']['h']);
1230 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1234 * Test the api_status_show() function.
1236 public function testApiStatusShowWithJson()
1238 $result = api_status_show('json', 1);
1239 self::assertStatus($result['status']);
1243 * Test the api_status_show() function with an XML result.
1245 public function testApiStatusShowWithXml()
1247 $result = api_status_show('xml', 1);
1248 self::assertXml($result, 'statuses');
1252 * Test the api_get_last_status() function
1254 public function testApiGetLastStatus()
1256 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1258 self::assertNotNull($item);
1262 * Test the api_users_show() function.
1266 public function testApiUsersShow()
1268 $result = api_users_show('json');
1269 // We can't use assertSelfUser() here because the user object is missing some properties.
1270 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1271 self::assertEquals('DFRN', $result['user']['location']);
1272 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1273 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1274 self::assertEquals('dfrn', $result['user']['network']);
1275 self::assertTrue($result['user']['verified']);
1279 * Test the api_users_show() function with an XML result.
1283 public function testApiUsersShowWithXml()
1285 $result = api_users_show('xml');
1286 self::assertXml($result, 'statuses');
1290 * Test the api_users_search() function.
1294 public function testApiUsersSearch()
1296 $_GET['q'] = 'othercontact';
1297 $result = api_users_search('json');
1298 self::assertOtherUser($result['users'][0]);
1302 * Test the api_users_search() function with an XML result.
1306 public function testApiUsersSearchWithXml()
1308 $_GET['q'] = 'othercontact';
1309 $result = api_users_search('xml');
1310 self::assertXml($result, 'users');
1314 * Test the api_users_search() function without a GET q parameter.
1318 public function testApiUsersSearchWithoutQuery()
1320 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1321 api_users_search('json');
1325 * Test the api_users_lookup() function.
1329 public function testApiUsersLookup()
1331 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1332 api_users_lookup('json');
1336 * Test the api_users_lookup() function with an user ID.
1340 public function testApiUsersLookupWithUserId()
1342 $_REQUEST['user_id'] = $this->otherUser['id'];
1343 $result = api_users_lookup('json');
1344 self::assertOtherUser($result['users'][0]);
1348 * Test the api_search() function.
1352 public function testApiSearch()
1354 $_REQUEST['q'] = 'reply';
1355 $_REQUEST['max_id'] = 10;
1356 $result = api_search('json');
1357 foreach ($result['status'] as $status) {
1358 self::assertStatus($status);
1359 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1364 * Test the api_search() function a count parameter.
1368 public function testApiSearchWithCount()
1370 $_REQUEST['q'] = 'reply';
1371 $_REQUEST['count'] = 20;
1372 $result = api_search('json');
1373 foreach ($result['status'] as $status) {
1374 self::assertStatus($status);
1375 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1380 * Test the api_search() function with an rpp parameter.
1384 public function testApiSearchWithRpp()
1386 $_REQUEST['q'] = 'reply';
1387 $_REQUEST['rpp'] = 20;
1388 $result = api_search('json');
1389 foreach ($result['status'] as $status) {
1390 self::assertStatus($status);
1391 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1396 * Test the api_search() function with an q parameter contains hashtag.
1397 * @doesNotPerformAssertions
1399 public function testApiSearchWithHashtag()
1401 $_REQUEST['q'] = '%23friendica';
1402 $result = api_search('json');
1403 foreach ($result['status'] as $status) {
1404 self::assertStatus($status);
1405 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1410 * Test the api_search() function with an exclude_replies parameter.
1411 * @doesNotPerformAssertions
1413 public function testApiSearchWithExcludeReplies()
1415 $_REQUEST['max_id'] = 10;
1416 $_REQUEST['exclude_replies'] = true;
1417 $_REQUEST['q'] = 'friendica';
1418 $result = api_search('json');
1419 foreach ($result['status'] as $status) {
1420 self::assertStatus($status);
1425 * Test the api_search() function without an authenticated user.
1429 public function testApiSearchWithUnallowedUser()
1431 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1432 $_GET['screen_name'] = $this->selfUser['nick'];
1433 BasicAuth::setCurrentUserID();
1438 * Test the api_search() function without any GET query parameter.
1442 public function testApiSearchWithoutQuery()
1444 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1449 * Test the api_statuses_home_timeline() function.
1453 public function testApiStatusesHomeTimeline()
1455 $_REQUEST['max_id'] = 10;
1456 $_REQUEST['exclude_replies'] = true;
1457 $_REQUEST['conversation_id'] = 1;
1458 $result = api_statuses_home_timeline('json');
1459 self::assertNotEmpty($result['status']);
1460 foreach ($result['status'] as $status) {
1461 self::assertStatus($status);
1466 * Test the api_statuses_home_timeline() function with a negative page parameter.
1470 public function testApiStatusesHomeTimelineWithNegativePage()
1472 $_REQUEST['page'] = -2;
1473 $result = api_statuses_home_timeline('json');
1474 self::assertNotEmpty($result['status']);
1475 foreach ($result['status'] as $status) {
1476 self::assertStatus($status);
1481 * Test the api_statuses_home_timeline() with an unallowed user.
1485 public function testApiStatusesHomeTimelineWithUnallowedUser()
1487 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1488 $_GET['screen_name'] = $this->selfUser['nick'];
1489 BasicAuth::setCurrentUserID();
1490 api_statuses_home_timeline('json');
1494 * Test the api_statuses_home_timeline() function with an RSS result.
1498 public function testApiStatusesHomeTimelineWithRss()
1500 $result = api_statuses_home_timeline('rss');
1501 self::assertXml($result, 'statuses');
1505 * Test the api_statuses_public_timeline() function.
1509 public function testApiStatusesPublicTimeline()
1511 $_REQUEST['max_id'] = 10;
1512 $_REQUEST['conversation_id'] = 1;
1513 $result = api_statuses_public_timeline('json');
1514 self::assertNotEmpty($result['status']);
1515 foreach ($result['status'] as $status) {
1516 self::assertStatus($status);
1521 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1525 public function testApiStatusesPublicTimelineWithExcludeReplies()
1527 $_REQUEST['max_id'] = 10;
1528 $_REQUEST['exclude_replies'] = true;
1529 $result = api_statuses_public_timeline('json');
1530 self::assertNotEmpty($result['status']);
1531 foreach ($result['status'] as $status) {
1532 self::assertStatus($status);
1537 * Test the api_statuses_public_timeline() function with a negative page parameter.
1541 public function testApiStatusesPublicTimelineWithNegativePage()
1543 $_REQUEST['page'] = -2;
1544 $result = api_statuses_public_timeline('json');
1545 self::assertNotEmpty($result['status']);
1546 foreach ($result['status'] as $status) {
1547 self::assertStatus($status);
1552 * Test the api_statuses_public_timeline() function with an unallowed user.
1556 public function testApiStatusesPublicTimelineWithUnallowedUser()
1558 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
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 $_GET['screen_name'] = $this->selfUser['nick'];
1614 BasicAuth::setCurrentUserID();
1615 api_statuses_networkpublic_timeline('json');
1619 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1623 public function testApiStatusesNetworkpublicTimelineWithRss()
1625 $result = api_statuses_networkpublic_timeline('rss');
1626 self::assertXml($result, 'statuses');
1630 * Test the api_statuses_show() function.
1634 public function testApiStatusesShow()
1636 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1637 api_statuses_show('json');
1641 * Test the api_statuses_show() function with an ID.
1645 public function testApiStatusesShowWithId()
1647 DI::args()->setArgv(['', '', '', 1]);
1648 $result = api_statuses_show('json');
1649 self::assertStatus($result['status']);
1653 * Test the api_statuses_show() function with the conversation parameter.
1657 public function testApiStatusesShowWithConversation()
1659 DI::args()->setArgv(['', '', '', 1]);
1660 $_REQUEST['conversation'] = 1;
1661 $result = api_statuses_show('json');
1662 self::assertNotEmpty($result['status']);
1663 foreach ($result['status'] as $status) {
1664 self::assertStatus($status);
1669 * Test the api_statuses_show() function with an unallowed user.
1673 public function testApiStatusesShowWithUnallowedUser()
1675 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1676 $_GET['screen_name'] = $this->selfUser['nick'];
1677 BasicAuth::setCurrentUserID();
1678 api_statuses_show('json');
1682 * Test the api_conversation_show() function.
1686 public function testApiConversationShow()
1688 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1689 api_conversation_show('json');
1693 * Test the api_conversation_show() function with an ID.
1697 public function testApiConversationShowWithId()
1699 DI::args()->setArgv(['', '', '', 1]);
1700 $_REQUEST['max_id'] = 10;
1701 $_REQUEST['page'] = -2;
1702 $result = api_conversation_show('json');
1703 self::assertNotEmpty($result['status']);
1704 foreach ($result['status'] as $status) {
1705 self::assertStatus($status);
1710 * Test the api_conversation_show() function with an unallowed user.
1714 public function testApiConversationShowWithUnallowedUser()
1716 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1717 $_GET['screen_name'] = $this->selfUser['nick'];
1718 BasicAuth::setCurrentUserID();
1719 api_conversation_show('json');
1723 * Test the api_statuses_repeat() function.
1727 public function testApiStatusesRepeat()
1729 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1730 api_statuses_repeat('json');
1734 * Test the api_statuses_repeat() function without an authenticated user.
1738 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1740 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1741 BasicAuth::setCurrentUserID();
1742 $_SESSION['authenticated'] = false;
1743 api_statuses_repeat('json');
1747 * Test the api_statuses_repeat() function with an ID.
1751 public function testApiStatusesRepeatWithId()
1753 DI::args()->setArgv(['', '', '', 1]);
1754 $result = api_statuses_repeat('json');
1755 self::assertStatus($result['status']);
1757 // Also test with a shared status
1758 DI::args()->setArgv(['', '', '', 5]);
1759 $result = api_statuses_repeat('json');
1760 self::assertStatus($result['status']);
1764 * Test the api_statuses_destroy() function.
1768 public function testApiStatusesDestroy()
1770 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1771 api_statuses_destroy('json');
1775 * Test the api_statuses_destroy() function without an authenticated user.
1779 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1781 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1782 BasicAuth::setCurrentUserID();
1783 $_SESSION['authenticated'] = false;
1784 api_statuses_destroy('json');
1788 * Test the api_statuses_destroy() function with an ID.
1792 public function testApiStatusesDestroyWithId()
1794 DI::args()->setArgv(['', '', '', 1]);
1795 $result = api_statuses_destroy('json');
1796 self::assertStatus($result['status']);
1800 * Test the api_statuses_mentions() function.
1804 public function testApiStatusesMentions()
1806 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1807 $_REQUEST['max_id'] = 10;
1808 $result = api_statuses_mentions('json');
1809 self::assertEmpty($result['status']);
1810 // We should test with mentions in the database.
1814 * Test the api_statuses_mentions() function with a negative page parameter.
1818 public function testApiStatusesMentionsWithNegativePage()
1820 $_REQUEST['page'] = -2;
1821 $result = api_statuses_mentions('json');
1822 self::assertEmpty($result['status']);
1826 * Test the api_statuses_mentions() function with an unallowed user.
1830 public function testApiStatusesMentionsWithUnallowedUser()
1832 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1833 $_GET['screen_name'] = $this->selfUser['nick'];
1834 BasicAuth::setCurrentUserID();
1835 api_statuses_mentions('json');
1839 * Test the api_statuses_mentions() function with an RSS result.
1843 public function testApiStatusesMentionsWithRss()
1845 $result = api_statuses_mentions('rss');
1846 self::assertXml($result, 'statuses');
1850 * Test the api_statuses_user_timeline() function.
1854 public function testApiStatusesUserTimeline()
1856 $_REQUEST['max_id'] = 10;
1857 $_REQUEST['exclude_replies'] = true;
1858 $_REQUEST['conversation_id'] = 1;
1859 $result = api_statuses_user_timeline('json');
1860 self::assertNotEmpty($result['status']);
1861 foreach ($result['status'] as $status) {
1862 self::assertStatus($status);
1867 * Test the api_statuses_user_timeline() function with a negative page parameter.
1871 public function testApiStatusesUserTimelineWithNegativePage()
1873 $_REQUEST['page'] = -2;
1874 $result = api_statuses_user_timeline('json');
1875 self::assertNotEmpty($result['status']);
1876 foreach ($result['status'] as $status) {
1877 self::assertStatus($status);
1882 * Test the api_statuses_user_timeline() function with an RSS result.
1886 public function testApiStatusesUserTimelineWithRss()
1888 $result = api_statuses_user_timeline('rss');
1889 self::assertXml($result, 'statuses');
1893 * Test the api_statuses_user_timeline() function with an unallowed user.
1897 public function testApiStatusesUserTimelineWithUnallowedUser()
1899 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1900 $_GET['screen_name'] = $this->selfUser['nick'];
1901 BasicAuth::setCurrentUserID();
1902 api_statuses_user_timeline('json');
1906 * Test the api_favorites_create_destroy() function.
1910 public function testApiFavoritesCreateDestroy()
1912 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1913 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1914 api_favorites_create_destroy('json');
1918 * Test the api_favorites_create_destroy() function with an invalid ID.
1922 public function testApiFavoritesCreateDestroyWithInvalidId()
1924 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1925 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1926 api_favorites_create_destroy('json');
1930 * Test the api_favorites_create_destroy() function with an invalid action.
1934 public function testApiFavoritesCreateDestroyWithInvalidAction()
1936 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1937 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1938 $_REQUEST['id'] = 1;
1939 api_favorites_create_destroy('json');
1943 * Test the api_favorites_create_destroy() function with the create action.
1947 public function testApiFavoritesCreateDestroyWithCreateAction()
1949 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1950 $_REQUEST['id'] = 3;
1951 $result = api_favorites_create_destroy('json');
1952 self::assertStatus($result['status']);
1956 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1960 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1962 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1963 $_REQUEST['id'] = 3;
1964 $result = api_favorites_create_destroy('rss');
1965 self::assertXml($result, 'status');
1969 * Test the api_favorites_create_destroy() function with the destroy action.
1973 public function testApiFavoritesCreateDestroyWithDestroyAction()
1975 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1976 $_REQUEST['id'] = 3;
1977 $result = api_favorites_create_destroy('json');
1978 self::assertStatus($result['status']);
1982 * Test the api_favorites_create_destroy() function without an authenticated user.
1986 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1988 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1989 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1990 BasicAuth::setCurrentUserID();
1991 $_SESSION['authenticated'] = false;
1992 api_favorites_create_destroy('json');
1996 * Test the api_favorites() function.
2000 public function testApiFavorites()
2002 $_REQUEST['page'] = -1;
2003 $_REQUEST['max_id'] = 10;
2004 $result = api_favorites('json');
2005 foreach ($result['status'] as $status) {
2006 self::assertStatus($status);
2011 * Test the api_favorites() function with an RSS result.
2015 public function testApiFavoritesWithRss()
2017 $result = api_favorites('rss');
2018 self::assertXml($result, 'statuses');
2022 * Test the api_favorites() function with an unallowed user.
2026 public function testApiFavoritesWithUnallowedUser()
2028 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2029 $_GET['screen_name'] = $this->selfUser['nick'];
2030 BasicAuth::setCurrentUserID();
2031 api_favorites('json');
2035 * Test the api_format_messages() function.
2039 public function testApiFormatMessages()
2041 $result = api_format_messages(
2042 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2043 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2044 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2046 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2047 self::assertEquals(1, $result['id']);
2048 self::assertEquals(2, $result['recipient_id']);
2049 self::assertEquals(3, $result['sender_id']);
2050 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2051 self::assertEquals('sender_name', $result['sender_screen_name']);
2055 * Test the api_format_messages() function with HTML.
2059 public function testApiFormatMessagesWithHtmlText()
2061 $_GET['getText'] = 'html';
2062 $result = api_format_messages(
2063 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2064 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2065 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2067 self::assertEquals('item_title', $result['title']);
2068 self::assertEquals('<strong>item_body</strong>', $result['text']);
2072 * Test the api_format_messages() function with plain text.
2076 public function testApiFormatMessagesWithPlainText()
2078 $_GET['getText'] = 'plain';
2079 $result = api_format_messages(
2080 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2081 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2082 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2084 self::assertEquals('item_title', $result['title']);
2085 self::assertEquals('item_body', $result['text']);
2089 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2093 public function testApiFormatMessagesWithoutUserObjects()
2095 $_GET['getUserObjects'] = 'false';
2096 $result = api_format_messages(
2097 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2098 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2099 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2101 self::assertTrue(!isset($result['sender']));
2102 self::assertTrue(!isset($result['recipient']));
2106 * Test the api_convert_item() function.
2110 public function testApiConvertItem()
2112 $result = api_convert_item(
2114 'network' => 'feed',
2115 'title' => 'item_title',
2117 // We need a long string to test that it is correctly cut
2118 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2119 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2120 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2121 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2122 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2123 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2124 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2125 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2126 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2127 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2128 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2129 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2130 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2131 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2132 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2133 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2134 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2135 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2136 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2137 'repellat officia illum quos impedit quam iste esse unde qui ' .
2138 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2139 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2140 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2141 'plink' => 'item_plink'
2144 self::assertStringStartsWith('item_title', $result['text']);
2145 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2149 * Test the api_convert_item() function with an empty item body.
2153 public function testApiConvertItemWithoutBody()
2155 $result = api_convert_item(
2157 'network' => 'feed',
2158 'title' => 'item_title',
2161 'plink' => 'item_plink'
2164 self::assertEquals("item_title", $result['text']);
2165 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2169 * Test the api_convert_item() function with the title in the body.
2173 public function testApiConvertItemWithTitleInBody()
2175 $result = api_convert_item(
2177 'title' => 'item_title',
2178 'body' => 'item_title item_body',
2182 self::assertEquals('item_title item_body', $result['text']);
2183 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2187 * Test the api_get_attachments() function.
2191 public function testApiGetAttachments()
2194 self::assertEmpty(api_get_attachments($body, 0));
2198 * Test the api_get_attachments() function with an img tag.
2202 public function testApiGetAttachmentsWithImage()
2204 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2205 self::assertIsArray(api_get_attachments($body, 0));
2209 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2213 public function testApiGetAttachmentsWithImageAndAndStatus()
2215 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2216 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2217 self::assertIsArray(api_get_attachments($body, 0));
2221 * Test the api_get_entitities() function.
2225 public function testApiGetEntitities()
2228 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2232 * Test the api_get_entitities() function with the include_entities parameter.
2236 public function testApiGetEntititiesWithIncludeEntities()
2238 $_REQUEST['include_entities'] = 'true';
2240 $result = api_get_entitities($text, 'bbcode', 0);
2241 self::assertIsArray($result['hashtags']);
2242 self::assertIsArray($result['symbols']);
2243 self::assertIsArray($result['urls']);
2244 self::assertIsArray($result['user_mentions']);
2248 * Test the api_format_items_embeded_images() function.
2252 public function testApiFormatItemsEmbededImages()
2255 'text ' . DI::baseUrl() . '/display/item_guid',
2256 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2261 * Test the api_contactlink_to_array() function.
2265 public function testApiContactlinkToArray()
2272 api_contactlink_to_array('text')
2277 * Test the api_contactlink_to_array() function with an URL.
2281 public function testApiContactlinkToArrayWithUrl()
2285 'name' => ['link_text'],
2288 api_contactlink_to_array('text <a href="url">link_text</a>')
2293 * Test the api_format_items_activities() function.
2297 public function testApiFormatItemsActivities()
2299 $item = ['uid' => 0, 'uri' => ''];
2300 $result = api_format_items_activities($item);
2301 self::assertArrayHasKey('like', $result);
2302 self::assertArrayHasKey('dislike', $result);
2303 self::assertArrayHasKey('attendyes', $result);
2304 self::assertArrayHasKey('attendno', $result);
2305 self::assertArrayHasKey('attendmaybe', $result);
2309 * Test the api_format_items_activities() function with an XML result.
2313 public function testApiFormatItemsActivitiesWithXml()
2315 $item = ['uid' => 0, 'uri' => ''];
2316 $result = api_format_items_activities($item, 'xml');
2317 self::assertArrayHasKey('friendica:like', $result);
2318 self::assertArrayHasKey('friendica:dislike', $result);
2319 self::assertArrayHasKey('friendica:attendyes', $result);
2320 self::assertArrayHasKey('friendica:attendno', $result);
2321 self::assertArrayHasKey('friendica:attendmaybe', $result);
2325 * Test the api_format_items() function.
2326 * @doesNotPerformAssertions
2328 public function testApiFormatItems()
2332 'item_network' => 'item_network',
2338 'author-network' => Protocol::DFRN,
2339 'author-link' => 'http://localhost/profile/othercontact',
2343 $result = api_format_items($items, ['id' => 0], true);
2344 foreach ($result as $status) {
2345 self::assertStatus($status);
2350 * Test the api_format_items() function with an XML result.
2351 * @doesNotPerformAssertions
2353 public function testApiFormatItemsWithXml()
2361 'author-network' => Protocol::DFRN,
2362 'author-link' => 'http://localhost/profile/othercontact',
2366 $result = api_format_items($items, ['id' => 0], true, 'xml');
2367 foreach ($result as $status) {
2368 self::assertStatus($status);
2373 * Test the api_lists_list() function.
2377 public function testApiListsList()
2379 $result = api_lists_list('json');
2380 self::assertEquals(['lists_list' => []], $result);
2384 * Test the api_lists_ownerships() function.
2388 public function testApiListsOwnerships()
2390 $result = api_lists_ownerships('json');
2391 foreach ($result['lists']['lists'] as $list) {
2392 self::assertList($list);
2397 * Test the api_lists_ownerships() function without an authenticated user.
2401 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2403 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2404 BasicAuth::setCurrentUserID();
2405 $_SESSION['authenticated'] = false;
2406 api_lists_ownerships('json');
2410 * Test the api_lists_statuses() function.
2414 public function testApiListsStatuses()
2416 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2417 api_lists_statuses('json');
2421 * Test the api_lists_statuses() function with a list ID.
2422 * @doesNotPerformAssertions
2424 public function testApiListsStatusesWithListId()
2426 $_REQUEST['list_id'] = 1;
2427 $_REQUEST['page'] = -1;
2428 $_REQUEST['max_id'] = 10;
2429 $result = api_lists_statuses('json');
2430 foreach ($result['status'] as $status) {
2431 self::assertStatus($status);
2436 * Test the api_lists_statuses() function with a list ID and a RSS result.
2440 public function testApiListsStatusesWithListIdAndRss()
2442 $_REQUEST['list_id'] = 1;
2443 $result = api_lists_statuses('rss');
2444 self::assertXml($result, 'statuses');
2448 * Test the api_lists_statuses() function with an unallowed user.
2452 public function testApiListsStatusesWithUnallowedUser()
2454 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2455 $_GET['screen_name'] = $this->selfUser['nick'];
2456 BasicAuth::setCurrentUserID();
2457 api_lists_statuses('json');
2461 * Test the api_statuses_f() function.
2465 public function testApiStatusesFWithFriends()
2468 $result = api_statuses_f('friends');
2469 self::assertArrayHasKey('user', $result);
2473 * Test the api_statuses_f() function.
2477 public function testApiStatusesFWithFollowers()
2479 $result = api_statuses_f('followers');
2480 self::assertArrayHasKey('user', $result);
2484 * Test the api_statuses_f() function.
2488 public function testApiStatusesFWithBlocks()
2490 $result = api_statuses_f('blocks');
2491 self::assertArrayHasKey('user', $result);
2495 * Test the api_statuses_f() function.
2499 public function testApiStatusesFWithIncoming()
2501 $result = api_statuses_f('incoming');
2502 self::assertArrayHasKey('user', $result);
2506 * Test the api_statuses_f() function an undefined cursor GET variable.
2510 public function testApiStatusesFWithUndefinedCursor()
2512 $_GET['cursor'] = 'undefined';
2513 self::assertFalse(api_statuses_f('friends'));
2517 * Test the api_statuses_friends() function.
2521 public function testApiStatusesFriends()
2523 $result = api_statuses_friends('json');
2524 self::assertArrayHasKey('user', $result);
2528 * Test the api_statuses_friends() function an undefined cursor GET variable.
2532 public function testApiStatusesFriendsWithUndefinedCursor()
2534 $_GET['cursor'] = 'undefined';
2535 self::assertFalse(api_statuses_friends('json'));
2539 * Test the api_statuses_followers() function.
2543 public function testApiStatusesFollowers()
2545 $result = api_statuses_followers('json');
2546 self::assertArrayHasKey('user', $result);
2550 * Test the api_statuses_followers() function an undefined cursor GET variable.
2554 public function testApiStatusesFollowersWithUndefinedCursor()
2556 $_GET['cursor'] = 'undefined';
2557 self::assertFalse(api_statuses_followers('json'));
2561 * Test the api_blocks_list() function.
2565 public function testApiBlocksList()
2567 $result = api_blocks_list('json');
2568 self::assertArrayHasKey('user', $result);
2572 * Test the api_blocks_list() function an undefined cursor GET variable.
2576 public function testApiBlocksListWithUndefinedCursor()
2578 $_GET['cursor'] = 'undefined';
2579 self::assertFalse(api_blocks_list('json'));
2583 * Test the api_friendships_incoming() function.
2587 public function testApiFriendshipsIncoming()
2589 $result = api_friendships_incoming('json');
2590 self::assertArrayHasKey('id', $result);
2594 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2598 public function testApiFriendshipsIncomingWithUndefinedCursor()
2600 $_GET['cursor'] = 'undefined';
2601 self::assertFalse(api_friendships_incoming('json'));
2605 * Test the api_statusnet_config() function.
2609 public function testApiStatusnetConfig()
2612 $result = api_statusnet_config('json');
2613 self::assertEquals('localhost', $result['config']['site']['server']);
2614 self::assertEquals('default', $result['config']['site']['theme']);
2615 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2616 self::assertTrue($result['config']['site']['fancy']);
2617 self::assertEquals('en', $result['config']['site']['language']);
2618 self::assertEquals('UTC', $result['config']['site']['timezone']);
2619 self::assertEquals(200000, $result['config']['site']['textlimit']);
2620 self::assertEquals('false', $result['config']['site']['private']);
2621 self::assertEquals('false', $result['config']['site']['ssl']);
2622 self::assertEquals(30, $result['config']['site']['shorturllength']);
2627 * Test the api_direct_messages_new() function.
2631 public function testApiDirectMessagesNew()
2633 $result = api_direct_messages_new('json');
2634 self::assertNull($result);
2638 * Test the api_direct_messages_new() function without an authenticated user.
2642 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2644 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2645 BasicAuth::setCurrentUserID();
2646 $_SESSION['authenticated'] = false;
2647 api_direct_messages_new('json');
2651 * Test the api_direct_messages_new() function with an user ID.
2655 public function testApiDirectMessagesNewWithUserId()
2657 $_POST['text'] = 'message_text';
2658 $_POST['user_id'] = $this->otherUser['id'];
2659 $result = api_direct_messages_new('json');
2660 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2664 * Test the api_direct_messages_new() function with a screen name.
2668 public function testApiDirectMessagesNewWithScreenName()
2670 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2671 $_POST['text'] = 'message_text';
2672 $_POST['screen_name'] = $this->friendUser['nick'];
2673 $result = api_direct_messages_new('json');
2674 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2675 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2676 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2680 * Test the api_direct_messages_new() function with a title.
2684 public function testApiDirectMessagesNewWithTitle()
2686 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2687 $_POST['text'] = 'message_text';
2688 $_POST['screen_name'] = $this->friendUser['nick'];
2689 $_REQUEST['title'] = 'message_title';
2690 $result = api_direct_messages_new('json');
2691 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2692 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2693 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2694 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2698 * Test the api_direct_messages_new() function with an RSS result.
2702 public function testApiDirectMessagesNewWithRss()
2704 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2705 $_POST['text'] = 'message_text';
2706 $_POST['screen_name'] = $this->friendUser['nick'];
2707 $result = api_direct_messages_new('rss');
2708 self::assertXml($result, 'direct-messages');
2712 * Test the api_direct_messages_destroy() function.
2716 public function testApiDirectMessagesDestroy()
2718 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2719 api_direct_messages_destroy('json');
2723 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2727 public function testApiDirectMessagesDestroyWithVerbose()
2729 $_GET['friendica_verbose'] = 'true';
2730 $result = api_direct_messages_destroy('json');
2734 'result' => 'error',
2735 'message' => 'message id or parenturi not specified'
2743 * Test the api_direct_messages_destroy() function without an authenticated user.
2747 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2749 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2750 BasicAuth::setCurrentUserID();
2751 $_SESSION['authenticated'] = false;
2752 api_direct_messages_destroy('json');
2756 * Test the api_direct_messages_destroy() function with a non-zero ID.
2760 public function testApiDirectMessagesDestroyWithId()
2762 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2763 $_REQUEST['id'] = 1;
2764 api_direct_messages_destroy('json');
2768 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2772 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2774 $_REQUEST['id'] = 1;
2775 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2776 $_GET['friendica_verbose'] = 'true';
2777 $result = api_direct_messages_destroy('json');
2781 'result' => 'error',
2782 'message' => 'message id not in database'
2790 * Test the api_direct_messages_destroy() function with a non-zero ID.
2794 public function testApiDirectMessagesDestroyWithCorrectId()
2796 $this->markTestIncomplete('We need to add a dataset for this.');
2800 * Test the api_direct_messages_box() function.
2804 public function testApiDirectMessagesBoxWithSentbox()
2806 $_REQUEST['page'] = -1;
2807 $_REQUEST['max_id'] = 10;
2808 $result = api_direct_messages_box('json', 'sentbox', 'false');
2809 self::assertArrayHasKey('direct_message', $result);
2813 * Test the api_direct_messages_box() function.
2817 public function testApiDirectMessagesBoxWithConversation()
2819 $result = api_direct_messages_box('json', 'conversation', 'false');
2820 self::assertArrayHasKey('direct_message', $result);
2824 * Test the api_direct_messages_box() function.
2828 public function testApiDirectMessagesBoxWithAll()
2830 $result = api_direct_messages_box('json', 'all', 'false');
2831 self::assertArrayHasKey('direct_message', $result);
2835 * Test the api_direct_messages_box() function.
2839 public function testApiDirectMessagesBoxWithInbox()
2841 $result = api_direct_messages_box('json', 'inbox', 'false');
2842 self::assertArrayHasKey('direct_message', $result);
2846 * Test the api_direct_messages_box() function.
2850 public function testApiDirectMessagesBoxWithVerbose()
2852 $result = api_direct_messages_box('json', 'sentbox', 'true');
2856 'result' => 'error',
2857 'message' => 'no mails available'
2865 * Test the api_direct_messages_box() function with a RSS result.
2869 public function testApiDirectMessagesBoxWithRss()
2871 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2872 self::assertXml($result, 'direct-messages');
2876 * Test the api_direct_messages_box() function without an authenticated user.
2880 public function testApiDirectMessagesBoxWithUnallowedUser()
2882 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2883 $_GET['screen_name'] = $this->selfUser['nick'];
2884 BasicAuth::setCurrentUserID();
2885 api_direct_messages_box('json', 'sentbox', 'false');
2889 * Test the api_direct_messages_sentbox() function.
2893 public function testApiDirectMessagesSentbox()
2895 $result = api_direct_messages_sentbox('json');
2896 self::assertArrayHasKey('direct_message', $result);
2900 * Test the api_direct_messages_inbox() function.
2904 public function testApiDirectMessagesInbox()
2906 $result = api_direct_messages_inbox('json');
2907 self::assertArrayHasKey('direct_message', $result);
2911 * Test the api_direct_messages_all() function.
2915 public function testApiDirectMessagesAll()
2917 $result = api_direct_messages_all('json');
2918 self::assertArrayHasKey('direct_message', $result);
2922 * Test the api_direct_messages_conversation() function.
2926 public function testApiDirectMessagesConversation()
2928 $result = api_direct_messages_conversation('json');
2929 self::assertArrayHasKey('direct_message', $result);
2933 * Test the api_oauth_request_token() function.
2937 public function testApiOauthRequestToken()
2939 $this->markTestIncomplete('exit() kills phpunit as well');
2943 * Test the api_oauth_access_token() function.
2947 public function testApiOauthAccessToken()
2949 $this->markTestIncomplete('exit() kills phpunit as well');
2953 * Test the api_fr_photos_list() function.
2957 public function testApiFrPhotosList()
2959 $result = api_fr_photos_list('json');
2960 self::assertArrayHasKey('photo', $result);
2964 * Test the api_fr_photos_list() function without an authenticated user.
2968 public function testApiFrPhotosListWithoutAuthenticatedUser()
2970 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2971 BasicAuth::setCurrentUserID();
2972 $_SESSION['authenticated'] = false;
2973 api_fr_photos_list('json');
2977 * Test the api_fr_photo_create_update() function.
2979 public function testApiFrPhotoCreateUpdate()
2981 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2982 api_fr_photo_create_update('json');
2986 * Test the api_fr_photo_create_update() function without an authenticated user.
2990 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
2992 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2993 BasicAuth::setCurrentUserID();
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 BasicAuth::setCurrentUserID();
3050 $_SESSION['authenticated'] = false;
3051 api_fr_photo_detail('json');
3055 * Test the api_fr_photo_detail() function with a photo ID.
3059 public function testApiFrPhotoDetailWithPhotoId()
3061 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3062 $_REQUEST['photo_id'] = 1;
3063 api_fr_photo_detail('json');
3067 * Test the api_fr_photo_detail() function with a correct photo ID.
3071 public function testApiFrPhotoDetailCorrectPhotoId()
3073 $this->markTestIncomplete('We need to create a dataset for this.');
3077 * Test the api_account_update_profile_image() function.
3081 public function testApiAccountUpdateProfileImage()
3083 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3084 api_account_update_profile_image('json');
3088 * Test the api_account_update_profile_image() function without an authenticated user.
3092 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3094 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3095 BasicAuth::setCurrentUserID();
3096 $_SESSION['authenticated'] = false;
3097 api_account_update_profile_image('json');
3101 * Test the api_account_update_profile_image() function with an uploaded file.
3105 public function testApiAccountUpdateProfileImageWithUpload()
3107 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3108 $this->markTestIncomplete();
3113 * Test the api_account_update_profile() function.
3117 public function testApiAccountUpdateProfile()
3119 $_POST['name'] = 'new_name';
3120 $_POST['description'] = 'new_description';
3121 $result = api_account_update_profile('json');
3122 // We can't use assertSelfUser() here because the user object is missing some properties.
3123 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3124 self::assertEquals('DFRN', $result['user']['location']);
3125 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3126 self::assertEquals('dfrn', $result['user']['network']);
3127 self::assertEquals('new_name', $result['user']['name']);
3128 self::assertEquals('new_description', $result['user']['description']);
3132 * Test the check_acl_input() function.
3136 public function testCheckAclInput()
3138 $result = check_acl_input('<aclstring>');
3139 // Where does this result come from?
3140 self::assertEquals(1, $result);
3144 * Test the check_acl_input() function with an empty ACL string.
3148 public function testCheckAclInputWithEmptyAclString()
3150 $result = check_acl_input(' ');
3151 self::assertFalse($result);
3155 * Test the save_media_to_database() function.
3159 public function testSaveMediaToDatabase()
3161 $this->markTestIncomplete();
3165 * Test the post_photo_item() function.
3169 public function testPostPhotoItem()
3171 $this->markTestIncomplete();
3175 * Test the prepare_photo_data() function.
3179 public function testPreparePhotoData()
3181 $this->markTestIncomplete();
3185 * Test the api_share_as_retweet() function with a valid item.
3189 public function testApiShareAsRetweetWithValidItem()
3191 $this->markTestIncomplete();
3195 * Test the api_in_reply_to() function.
3199 public function testApiInReplyTo()
3201 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3202 self::assertArrayHasKey('status_id', $result);
3203 self::assertArrayHasKey('user_id', $result);
3204 self::assertArrayHasKey('status_id_str', $result);
3205 self::assertArrayHasKey('user_id_str', $result);
3206 self::assertArrayHasKey('screen_name', $result);
3210 * Test the api_in_reply_to() function with a valid item.
3214 public function testApiInReplyToWithValidItem()
3216 $this->markTestIncomplete();
3220 * Test the api_clean_plain_items() function.
3224 public function testApiCleanPlainItems()
3226 $_REQUEST['include_entities'] = 'true';
3227 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3228 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3232 * Test the api_best_nickname() function.
3236 public function testApiBestNickname()
3239 $result = api_best_nickname($contacts);
3240 self::assertNull($result);
3244 * Test the api_best_nickname() function with contacts.
3248 public function testApiBestNicknameWithContacts()
3250 $this->markTestIncomplete();
3254 * Test the api_friendica_group_show() function.
3258 public function testApiFriendicaGroupShow()
3260 $this->markTestIncomplete();
3264 * Test the api_friendica_group_delete() function.
3268 public function testApiFriendicaGroupDelete()
3270 $this->markTestIncomplete();
3274 * Test the api_lists_destroy() function.
3278 public function testApiListsDestroy()
3280 $this->markTestIncomplete();
3284 * Test the group_create() function.
3288 public function testGroupCreate()
3290 $this->markTestIncomplete();
3294 * Test the api_friendica_group_create() function.
3298 public function testApiFriendicaGroupCreate()
3300 $this->markTestIncomplete();
3304 * Test the api_lists_create() function.
3308 public function testApiListsCreate()
3310 $this->markTestIncomplete();
3314 * Test the api_friendica_group_update() function.
3318 public function testApiFriendicaGroupUpdate()
3320 $this->markTestIncomplete();
3324 * Test the api_lists_update() function.
3328 public function testApiListsUpdate()
3330 $this->markTestIncomplete();
3334 * Test the api_friendica_activity() function.
3338 public function testApiFriendicaActivity()
3340 $this->markTestIncomplete();
3344 * Test the api_friendica_notification_seen() function.
3348 public function testApiFriendicaNotificationSeen()
3350 $this->markTestIncomplete();
3354 * Test the api_friendica_direct_messages_setseen() function.
3358 public function testApiFriendicaDirectMessagesSetseen()
3360 $this->markTestIncomplete();
3364 * Test the api_friendica_direct_messages_search() function.
3368 public function testApiFriendicaDirectMessagesSearch()
3370 $this->markTestIncomplete();