6 namespace Friendica\Test\legacy;
9 use Friendica\Core\Config\Capability\IManageConfigValues;
10 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
11 use Friendica\Core\Protocol;
13 use Friendica\Module\Api\ApiResponse;
14 use Friendica\Module\BaseApi;
15 use Friendica\Network\HTTPException;
16 use Friendica\Security\BasicAuth;
17 use Friendica\Test\FixtureTest;
18 use Friendica\Util\Arrays;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Temporal;
21 use Monolog\Handler\TestHandler;
23 require_once __DIR__ . '/../../include/api.php';
26 * Tests for the API functions.
28 * Functions that use header() need to be tested in a separate process.
29 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31 * @backupGlobals enabled
33 class ApiTest extends FixtureTest
36 * @var TestHandler Can handle log-outputs
43 protected $friendUser;
47 protected $wrongUserId;
52 /** @var IManageConfigValues */
56 * Create variables used by tests.
58 protected function setUp() : void
60 global $API, $called_api;
66 /** @var IManageConfigValues $config */
67 $this->config = $this->dice->create(IManageConfigValues::class);
69 $this->config->set('system', 'url', 'http://localhost');
70 $this->config->set('system', 'hostname', 'localhost');
71 $this->config->set('system', 'worker_dont_fork', true);
74 $this->config->set('config', 'hostname', 'localhost');
75 $this->config->set('system', 'throttle_limit_day', 100);
76 $this->config->set('system', 'throttle_limit_week', 100);
77 $this->config->set('system', 'throttle_limit_month', 100);
78 $this->config->set('system', 'theme', 'system_theme');
82 $this->app = DI::app();
84 DI::args()->setArgc(1);
86 // User data that the test database is populated with
89 'name' => 'Self contact',
90 'nick' => 'selfcontact',
91 'nurl' => 'http://localhost/profile/selfcontact'
95 'name' => 'Friend contact',
96 'nick' => 'friendcontact',
97 'nurl' => 'http://localhost/profile/friendcontact'
101 'name' => 'othercontact',
102 'nick' => 'othercontact',
103 'nurl' => 'http://localhost/profile/othercontact'
106 // User ID that we know is not in the database
107 $this->wrongUserId = 666;
109 DI::session()->start();
111 // Most API require login so we force the session
114 'authenticated' => true,
115 'uid' => $this->selfUser['id']
120 * Assert that an user array contains expected keys.
122 * @param array $user User array
126 private function assertSelfUser(array $user)
128 self::assertEquals($this->selfUser['id'], $user['uid']);
129 self::assertEquals($this->selfUser['id'], $user['cid']);
130 self::assertEquals(1, $user['self']);
131 self::assertEquals('DFRN', $user['location']);
132 self::assertEquals($this->selfUser['name'], $user['name']);
133 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
134 self::assertEquals('dfrn', $user['network']);
135 self::assertTrue($user['verified']);
139 * Assert that an user array contains expected keys.
141 * @param array $user User array
145 private function assertOtherUser(array $user = [])
147 self::assertEquals($this->otherUser['id'], $user['id']);
148 self::assertEquals($this->otherUser['id'], $user['id_str']);
149 self::assertEquals(0, $user['self']);
150 self::assertEquals($this->otherUser['name'], $user['name']);
151 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
152 self::assertFalse($user['verified']);
156 * Assert that a status array contains expected keys.
158 * @param array $status Status array
162 private function assertStatus(array $status = [])
164 self::assertIsString($status['text'] ?? '');
165 self::assertIsInt($status['id'] ?? '');
166 // We could probably do more checks here.
170 * Assert that a list array contains expected keys.
172 * @param array $list List array
176 private function assertList(array $list = [])
178 self::assertIsString($list['name']);
179 self::assertIsInt($list['id']);
180 self::assertIsString('string', $list['id_str']);
181 self::assertContains($list['mode'], ['public', 'private']);
182 // We could probably do more checks here.
186 * Assert that the string is XML and contain the root element.
188 * @param string $result XML string
189 * @param string $root_element Root element name
193 private function assertXml($result = '', $root_element = '')
195 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
196 self::assertStringContainsString('<' . $root_element, $result);
197 // We could probably do more checks here.
201 * Get the path to a temporary empty PNG image.
203 * @return string Path
205 private function getTempImage()
207 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
211 // Empty 1x1 px PNG image
212 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
220 * Test the api_user() function.
224 public function testApiUser()
226 self::assertEquals($this->selfUser['id'], api_user());
230 * Test the api_user() function with an unallowed user.
234 public function testApiUserWithUnallowedUser()
236 $_SESSION = ['allow_api' => false];
237 self::assertEquals(false, api_user());
241 * Test the api_source() function.
245 public function testApiSource()
247 self::assertEquals('api', api_source());
251 * Test the api_source() function with a Twidere user agent.
255 public function testApiSourceWithTwidere()
257 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
258 self::assertEquals('Twidere', api_source());
262 * Test the api_source() function with a GET parameter.
266 public function testApiSourceWithGet()
268 $_GET['source'] = 'source_name';
269 self::assertEquals('source_name', api_source());
273 * Test the api_date() function.
277 public function testApiDate()
279 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
283 * Test the api_register_func() function.
287 public function testApiRegisterFunc()
299 self::assertTrue($API['api_path']['auth']);
300 self::assertEquals('method', $API['api_path']['method']);
301 self::assertTrue(is_callable($API['api_path']['func']));
305 * Test the BasicAuth::getCurrentUserID() function without any login.
307 * @runInSeparateProcess
308 * @preserveGlobalState disabled
309 * @preserveGlobalState disabled
311 public function testApiLoginWithoutLogin()
313 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314 BasicAuth::getCurrentUserID(true);
318 * Test the BasicAuth::getCurrentUserID() function with a bad login.
320 * @runInSeparateProcess
321 * @preserveGlobalState disabled
322 * @preserveGlobalState disabled
324 public function testApiLoginWithBadLogin()
326 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
327 $_SERVER['PHP_AUTH_USER'] = 'user@server';
328 BasicAuth::getCurrentUserID(true);
332 * Test the BasicAuth::getCurrentUserID() function with oAuth.
336 public function testApiLoginWithOauth()
338 $this->markTestIncomplete('Can we test this easily?');
342 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
346 public function testApiLoginWithAddonAuth()
348 $this->markTestIncomplete('Can we test this easily?');
352 * Test the BasicAuth::getCurrentUserID() function with a correct login.
354 * @runInSeparateProcess
355 * @preserveGlobalState disabled
356 * @doesNotPerformAssertions
358 public function testApiLoginWithCorrectLogin()
360 $_SERVER['PHP_AUTH_USER'] = 'Test user';
361 $_SERVER['PHP_AUTH_PW'] = 'password';
362 BasicAuth::getCurrentUserID(true);
366 * Test the BasicAuth::getCurrentUserID() function with a remote user.
368 * @runInSeparateProcess
369 * @preserveGlobalState disabled
371 public function testApiLoginWithRemoteUser()
373 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
374 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
375 BasicAuth::getCurrentUserID(true);
379 * Test the api_check_method() function.
383 public function testApiCheckMethod()
385 self::assertFalse(api_check_method('method'));
389 * Test the api_check_method() function with a correct method.
393 public function testApiCheckMethodWithCorrectMethod()
395 $_SERVER['REQUEST_METHOD'] = 'method';
396 self::assertTrue(api_check_method('method'));
400 * Test the api_check_method() function with a wildcard.
404 public function testApiCheckMethodWithWildcard()
406 self::assertTrue(api_check_method('*'));
410 * Test the api_call() function.
412 * @runInSeparateProcess
413 * @preserveGlobalState disabled
415 public function testApiCall()
419 'method' => 'method',
420 'func' => function () {
421 return ['data' => ['some_data']];
424 $_SERVER['REQUEST_METHOD'] = 'method';
425 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
426 $_GET['callback'] = 'callback_name';
428 $args = DI::args()->determine($_SERVER, $_GET);
431 'callback_name(["some_data"])',
432 api_call($this->app, $args)
437 * Test the api_call() function with the profiled enabled.
439 * @runInSeparateProcess
440 * @preserveGlobalState disabled
442 public function testApiCallWithProfiler()
446 'method' => 'method',
447 'func' => function () {
448 return ['data' => ['some_data']];
452 $_SERVER['REQUEST_METHOD'] = 'method';
453 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
455 $args = DI::args()->determine($_SERVER, $_GET);
457 $this->config->set('system', 'profiler', true);
458 $this->config->set('rendertime', 'callstack', true);
459 $this->app->callstack = [
460 'database' => ['some_function' => 200],
461 'database_write' => ['some_function' => 200],
462 'cache' => ['some_function' => 200],
463 'cache_write' => ['some_function' => 200],
464 'network' => ['some_function' => 200]
469 api_call($this->app, $args)
474 * Test the api_call() function without any result.
476 * @runInSeparateProcess
477 * @preserveGlobalState disabled
479 public function testApiCallWithNoResult()
481 // @todo How to test the new API?
485 'method' => 'method',
486 'func' => function () {
490 $_SERVER['REQUEST_METHOD'] = 'method';
491 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
493 $args = DI::args()->determine($_SERVER, $_GET);
496 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
497 api_call($this->app, $args)
503 * Test the api_call() function with an unimplemented API.
505 * @runInSeparateProcess
506 * @preserveGlobalState disabled
508 public function testApiCallWithUninplementedApi()
510 // @todo How to test the new API?
513 '{"status":{"error":"Not Found","code":"404 Not Found","request":""}}',
520 * Test the api_call() function with a JSON result.
522 * @runInSeparateProcess
523 * @preserveGlobalState disabled
525 public function testApiCallWithJson()
529 'method' => 'method',
530 'func' => function () {
531 return ['data' => ['some_data']];
534 $_SERVER['REQUEST_METHOD'] = 'method';
535 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
537 $args = DI::args()->determine($_SERVER, $_GET);
541 api_call($this->app, $args)
546 * Test the api_call() function with an XML result.
548 * @runInSeparateProcess
549 * @preserveGlobalState disabled
551 public function testApiCallWithXml()
555 'method' => 'method',
556 'func' => function () {
560 $_SERVER['REQUEST_METHOD'] = 'method';
561 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
563 $args = DI::args()->determine($_SERVER, $_GET);
567 api_call($this->app, $args)
572 * Test the api_call() function with an RSS result.
574 * @runInSeparateProcess
575 * @preserveGlobalState disabled
577 public function testApiCallWithRss()
581 'method' => 'method',
582 'func' => function () {
586 $_SERVER['REQUEST_METHOD'] = 'method';
587 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
589 $args = DI::args()->determine($_SERVER, $_GET);
592 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
594 api_call($this->app, $args)
599 * Test the api_call() function with an Atom result.
601 * @runInSeparateProcess
602 * @preserveGlobalState disabled
604 public function testApiCallWithAtom()
608 'method' => 'method',
609 'func' => function () {
613 $_SERVER['REQUEST_METHOD'] = 'method';
614 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
616 $args = DI::args()->determine($_SERVER, $_GET);
619 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
621 api_call($this->app, $args)
626 * Test the api_call() function with an unauthorized user.
628 * @runInSeparateProcess
629 * @preserveGlobalState disabled
631 public function testApiCallWithWrongAuth()
633 // @todo How to test the new API?
637 'method' => 'method',
640 $_SESSION['authenticated'] = false;
641 $_SERVER['REQUEST_METHOD'] = 'method';
642 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
644 $args = DI::args()->determine($_SERVER, $_GET);
647 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
648 api_call($this->app, $args)
655 * Test the api_rss_extra() function.
659 public function testApiRssExtra()
661 $user_info = ['url' => 'user_url', 'lang' => 'en'];
662 $result = api_rss_extra($this->app, [], $user_info);
663 self::assertEquals($user_info, $result['$user']);
664 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
665 self::assertArrayHasKey('self', $result['$rss']);
666 self::assertArrayHasKey('base', $result['$rss']);
667 self::assertArrayHasKey('updated', $result['$rss']);
668 self::assertArrayHasKey('atom_updated', $result['$rss']);
669 self::assertArrayHasKey('language', $result['$rss']);
670 self::assertArrayHasKey('logo', $result['$rss']);
674 * Test the api_rss_extra() function without any user info.
678 public function testApiRssExtraWithoutUserInfo()
680 $result = api_rss_extra($this->app, [], null);
681 self::assertIsArray($result['$user']);
682 self::assertArrayHasKey('alternate', $result['$rss']);
683 self::assertArrayHasKey('self', $result['$rss']);
684 self::assertArrayHasKey('base', $result['$rss']);
685 self::assertArrayHasKey('updated', $result['$rss']);
686 self::assertArrayHasKey('atom_updated', $result['$rss']);
687 self::assertArrayHasKey('language', $result['$rss']);
688 self::assertArrayHasKey('logo', $result['$rss']);
692 * Test the api_unique_id_to_nurl() function.
696 public function testApiUniqueIdToNurl()
698 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
702 * Test the api_unique_id_to_nurl() function with a correct ID.
706 public function testApiUniqueIdToNurlWithCorrectId()
708 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
712 * Test the api_get_user() function.
716 public function testApiGetUser()
718 $user = api_get_user();
719 self::assertSelfUser($user);
720 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
721 self::assertEquals('6fdbe8', $user['profile_link_color']);
722 self::assertEquals('ededed', $user['profile_background_color']);
726 * Test the api_get_user() function with a Frio schema.
730 public function testApiGetUserWithFrioSchema()
732 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
733 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
734 $user = api_get_user();
735 self::assertSelfUser($user);
736 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
737 self::assertEquals('6fdbe8', $user['profile_link_color']);
738 self::assertEquals('ededed', $user['profile_background_color']);
742 * Test the api_get_user() function with an empty Frio schema.
746 public function testApiGetUserWithEmptyFrioSchema()
748 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
749 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
750 $user = api_get_user();
751 self::assertSelfUser($user);
752 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
753 self::assertEquals('6fdbe8', $user['profile_link_color']);
754 self::assertEquals('ededed', $user['profile_background_color']);
758 * Test the api_get_user() function with a custom Frio schema.
762 public function testApiGetUserWithCustomFrioSchema()
764 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
765 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
766 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
767 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
768 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
769 $user = api_get_user();
770 self::assertSelfUser($user);
771 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
772 self::assertEquals('123456', $user['profile_link_color']);
773 self::assertEquals('123456', $user['profile_background_color']);
777 * Test the api_get_user() function with an user that is not allowed to use the API.
779 * @runInSeparateProcess
780 * @preserveGlobalState disabled
782 public function testApiGetUserWithoutApiUser()
784 $_SERVER['PHP_AUTH_USER'] = 'Test user';
785 $_SERVER['PHP_AUTH_PW'] = 'password';
786 $_SESSION['allow_api'] = false;
787 self::assertFalse(api_get_user());
791 * Test the api_get_user() function with an user ID in a GET parameter.
795 public function testApiGetUserWithGetId()
797 $_GET['user_id'] = $this->otherUser['id'];
798 self::assertOtherUser(api_get_user());
802 * Test the api_get_user() function with a wrong user ID in a GET parameter.
806 public function testApiGetUserWithWrongGetId()
808 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
809 $_GET['user_id'] = $this->wrongUserId;
810 self::assertOtherUser(api_get_user());
814 * Test the api_get_user() function with an user name in a GET parameter.
818 public function testApiGetUserWithGetName()
820 $_GET['screen_name'] = $this->selfUser['nick'];
821 self::assertSelfUser(api_get_user());
825 * Test the api_get_user() function with a profile URL in a GET parameter.
829 public function testApiGetUserWithGetUrl()
831 $_GET['profileurl'] = $this->selfUser['nurl'];
832 self::assertSelfUser(api_get_user());
836 * Test the api_get_user() function with an user ID in the API path.
840 public function testApiGetUserWithNumericCalledApi()
843 $called_api = ['api_path'];
844 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
845 self::assertOtherUser(api_get_user());
849 * Test the api_get_user() function with the $called_api global variable.
853 public function testApiGetUserWithCalledApi()
856 $called_api = ['api', 'api_path'];
857 self::assertSelfUser(api_get_user());
861 * Test the api_get_user() function with a valid user.
865 public function testApiGetUserWithCorrectUser()
867 self::assertOtherUser(api_get_user($this->otherUser['id']));
871 * Test the api_get_user() function with a wrong user ID.
875 public function testApiGetUserWithWrongUser()
877 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
878 self::assertOtherUser(api_get_user($this->wrongUserId));
882 * Test the api_get_user() function with a 0 user ID.
886 public function testApiGetUserWithZeroUser()
888 self::assertSelfUser(api_get_user(0));
892 * Test the api_item_get_user() function.
896 public function testApiItemGetUser()
898 $users = api_item_get_user($this->app, []);
899 self::assertSelfUser($users[0]);
903 * Test the api_item_get_user() function with a different item parent.
907 public function testApiItemGetUserWithDifferentParent()
909 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
910 self::assertSelfUser($users[0]);
911 self::assertEquals($users[0], $users[1]);
915 * Test the Arrays::walkRecursive() function.
919 public function testApiWalkRecursive()
924 Arrays::walkRecursive(
927 // Should we test this with a callback that actually does something?
935 * Test the Arrays::walkRecursive() function with an array.
939 public function testApiWalkRecursiveWithArray()
941 $array = [['item1'], ['item2']];
944 Arrays::walkRecursive(
947 // Should we test this with a callback that actually does something?
955 * Test the BaseApi::reformatXML() function.
959 public function testApiReformatXml()
963 self::assertTrue(ApiResponse::reformatXML($item, $key));
964 self::assertEquals('true', $item);
968 * Test the BaseApi::reformatXML() function with a statusnet_api key.
972 public function testApiReformatXmlWithStatusnetKey()
975 $key = 'statusnet_api';
976 self::assertTrue(ApiResponse::reformatXML($item, $key));
977 self::assertEquals('statusnet:api', $key);
981 * Test the BaseApi::reformatXML() function with a friendica_api key.
985 public function testApiReformatXmlWithFriendicaKey()
988 $key = 'friendica_api';
989 self::assertTrue(ApiResponse::reformatXML($item, $key));
990 self::assertEquals('friendica:api', $key);
994 * Test the BaseApi::createXML() function.
998 public function testApiCreateXml()
1001 '<?xml version="1.0"?>' . "\n" .
1002 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1003 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1004 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1005 ' <data>some_data</data>' . "\n" .
1006 '</root_element>' . "\n",
1007 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
1012 * Test the BaseApi::createXML() function without any XML namespace.
1016 public function testApiCreateXmlWithoutNamespaces()
1019 '<?xml version="1.0"?>' . "\n" .
1021 ' <data>some_data</data>' . "\n" .
1023 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
1028 * Test the BaseApi::formatData() function.
1032 public function testApiFormatData()
1034 $data = ['some_data'];
1035 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
1039 * Test the BaseApi::formatData() function with an XML result.
1043 public function testApiFormatDataWithXml()
1046 '<?xml version="1.0"?>' . "\n" .
1047 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1048 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1049 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1050 ' <data>some_data</data>' . "\n" .
1051 '</root_element>' . "\n",
1052 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
1057 * Test the api_account_verify_credentials() function.
1061 public function testApiAccountVerifyCredentials()
1063 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1067 * Test the api_account_verify_credentials() function without an authenticated user.
1071 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1073 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1074 $_SESSION['authenticated'] = false;
1075 api_account_verify_credentials('json');
1079 * Test the requestdata() function.
1083 public function testRequestdata()
1085 self::assertNull(requestdata('variable_name'));
1089 * Test the requestdata() function with a POST parameter.
1093 public function testRequestdataWithPost()
1095 $_POST['variable_name'] = 'variable_value';
1096 self::assertEquals('variable_value', requestdata('variable_name'));
1100 * Test the requestdata() function with a GET parameter.
1104 public function testRequestdataWithGet()
1106 $_GET['variable_name'] = 'variable_value';
1107 self::assertEquals('variable_value', requestdata('variable_name'));
1111 * Test the api_statuses_mediap() function.
1115 public function testApiStatusesMediap()
1117 DI::args()->setArgc(2);
1125 'tmp_name' => $this->getTempImage(),
1126 'name' => 'spacer.png',
1127 'type' => 'image/png'
1130 $_GET['status'] = '<b>Status content</b>';
1132 $result = api_statuses_mediap('json');
1133 self::assertStatus($result['status']);
1137 * Test the api_statuses_mediap() function without an authenticated user.
1141 public function testApiStatusesMediapWithoutAuthenticatedUser()
1143 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1144 $_SESSION['authenticated'] = false;
1145 api_statuses_mediap('json');
1149 * Test the api_statuses_update() function.
1153 public function testApiStatusesUpdate()
1155 $_GET['status'] = 'Status content #friendica';
1156 $_GET['in_reply_to_status_id'] = -1;
1165 'tmp_name' => $this->getTempImage(),
1166 'name' => 'spacer.png',
1167 'type' => 'image/png'
1171 $result = api_statuses_update('json');
1172 self::assertStatus($result['status']);
1176 * Test the api_statuses_update() function with an HTML status.
1180 public function testApiStatusesUpdateWithHtml()
1182 $_GET['htmlstatus'] = '<b>Status content</b>';
1184 $result = api_statuses_update('json');
1185 self::assertStatus($result['status']);
1189 * Test the api_statuses_update() function without an authenticated user.
1193 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1195 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1196 $_SESSION['authenticated'] = false;
1197 api_statuses_update('json');
1201 * Test the api_statuses_update() function with a parent status.
1205 public function testApiStatusesUpdateWithParent()
1207 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1211 * Test the api_statuses_update() function with a media_ids parameter.
1215 public function testApiStatusesUpdateWithMediaIds()
1217 $this->markTestIncomplete();
1221 * Test the api_statuses_update() function with the throttle limit reached.
1225 public function testApiStatusesUpdateWithDayThrottleReached()
1227 $this->markTestIncomplete();
1231 * Test the api_media_upload() function.
1232 * @runInSeparateProcess
1233 * @preserveGlobalState disabled
1235 public function testApiMediaUpload()
1237 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1242 * Test the api_media_upload() function without an authenticated user.
1246 public function testApiMediaUploadWithoutAuthenticatedUser()
1248 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1249 $_SESSION['authenticated'] = false;
1254 * Test the api_media_upload() function with an invalid uploaded media.
1258 public function testApiMediaUploadWithMedia()
1260 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1264 'tmp_name' => 'tmp_name'
1271 * Test the api_media_upload() function with an valid uploaded media.
1275 public function testApiMediaUploadWithValidMedia()
1283 'tmp_name' => $this->getTempImage(),
1284 'name' => 'spacer.png',
1285 'type' => 'image/png'
1289 DI::args()->setArgc(2);
1291 $result = api_media_upload();
1292 self::assertEquals('image/png', $result['media']['image']['image_type']);
1293 self::assertEquals(1, $result['media']['image']['w']);
1294 self::assertEquals(1, $result['media']['image']['h']);
1295 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1299 * Test the api_status_show() function.
1301 public function testApiStatusShowWithJson()
1303 $result = api_status_show('json', 1);
1304 self::assertStatus($result['status']);
1308 * Test the api_status_show() function with an XML result.
1310 public function testApiStatusShowWithXml()
1312 $result = api_status_show('xml', 1);
1313 self::assertXml($result, 'statuses');
1317 * Test the api_get_last_status() function
1319 public function testApiGetLastStatus()
1321 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1323 self::assertNotNull($item);
1327 * Test the api_users_show() function.
1331 public function testApiUsersShow()
1333 $result = api_users_show('json');
1334 // We can't use assertSelfUser() here because the user object is missing some properties.
1335 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1336 self::assertEquals('DFRN', $result['user']['location']);
1337 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1338 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1339 self::assertEquals('dfrn', $result['user']['network']);
1340 self::assertTrue($result['user']['verified']);
1344 * Test the api_users_show() function with an XML result.
1348 public function testApiUsersShowWithXml()
1350 $result = api_users_show('xml');
1351 self::assertXml($result, 'statuses');
1355 * Test the api_users_search() function.
1359 public function testApiUsersSearch()
1361 $_GET['q'] = 'othercontact';
1362 $result = api_users_search('json');
1363 self::assertOtherUser($result['users'][0]);
1367 * Test the api_users_search() function with an XML result.
1371 public function testApiUsersSearchWithXml()
1373 $_GET['q'] = 'othercontact';
1374 $result = api_users_search('xml');
1375 self::assertXml($result, 'users');
1379 * Test the api_users_search() function without a GET q parameter.
1383 public function testApiUsersSearchWithoutQuery()
1385 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1386 api_users_search('json');
1390 * Test the api_users_lookup() function.
1394 public function testApiUsersLookup()
1396 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1397 api_users_lookup('json');
1401 * Test the api_users_lookup() function with an user ID.
1405 public function testApiUsersLookupWithUserId()
1407 $_REQUEST['user_id'] = $this->otherUser['id'];
1408 $result = api_users_lookup('json');
1409 self::assertOtherUser($result['users'][0]);
1413 * Test the api_search() function.
1417 public function testApiSearch()
1419 $_REQUEST['q'] = 'reply';
1420 $_REQUEST['max_id'] = 10;
1421 $result = api_search('json');
1422 foreach ($result['status'] as $status) {
1423 self::assertStatus($status);
1424 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1429 * Test the api_search() function a count parameter.
1433 public function testApiSearchWithCount()
1435 $_REQUEST['q'] = 'reply';
1436 $_REQUEST['count'] = 20;
1437 $result = api_search('json');
1438 foreach ($result['status'] as $status) {
1439 self::assertStatus($status);
1440 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1445 * Test the api_search() function with an rpp parameter.
1449 public function testApiSearchWithRpp()
1451 $_REQUEST['q'] = 'reply';
1452 $_REQUEST['rpp'] = 20;
1453 $result = api_search('json');
1454 foreach ($result['status'] as $status) {
1455 self::assertStatus($status);
1456 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1461 * Test the api_search() function with an q parameter contains hashtag.
1462 * @doesNotPerformAssertions
1464 public function testApiSearchWithHashtag()
1466 $_REQUEST['q'] = '%23friendica';
1467 $result = api_search('json');
1468 foreach ($result['status'] as $status) {
1469 self::assertStatus($status);
1470 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1475 * Test the api_search() function with an exclude_replies parameter.
1476 * @doesNotPerformAssertions
1478 public function testApiSearchWithExcludeReplies()
1480 $_REQUEST['max_id'] = 10;
1481 $_REQUEST['exclude_replies'] = true;
1482 $_REQUEST['q'] = 'friendica';
1483 $result = api_search('json');
1484 foreach ($result['status'] as $status) {
1485 self::assertStatus($status);
1490 * Test the api_search() function without an authenticated user.
1494 public function testApiSearchWithUnallowedUser()
1496 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1497 $_SESSION['allow_api'] = false;
1498 $_GET['screen_name'] = $this->selfUser['nick'];
1503 * Test the api_search() function without any GET query parameter.
1507 public function testApiSearchWithoutQuery()
1509 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1514 * Test the api_statuses_home_timeline() function.
1518 public function testApiStatusesHomeTimeline()
1520 $_REQUEST['max_id'] = 10;
1521 $_REQUEST['exclude_replies'] = true;
1522 $_REQUEST['conversation_id'] = 1;
1523 $result = api_statuses_home_timeline('json');
1524 self::assertNotEmpty($result['status']);
1525 foreach ($result['status'] as $status) {
1526 self::assertStatus($status);
1531 * Test the api_statuses_home_timeline() function with a negative page parameter.
1535 public function testApiStatusesHomeTimelineWithNegativePage()
1537 $_REQUEST['page'] = -2;
1538 $result = api_statuses_home_timeline('json');
1539 self::assertNotEmpty($result['status']);
1540 foreach ($result['status'] as $status) {
1541 self::assertStatus($status);
1546 * Test the api_statuses_home_timeline() with an unallowed user.
1550 public function testApiStatusesHomeTimelineWithUnallowedUser()
1552 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1553 $_SESSION['allow_api'] = false;
1554 $_GET['screen_name'] = $this->selfUser['nick'];
1555 api_statuses_home_timeline('json');
1559 * Test the api_statuses_home_timeline() function with an RSS result.
1563 public function testApiStatusesHomeTimelineWithRss()
1565 $result = api_statuses_home_timeline('rss');
1566 self::assertXml($result, 'statuses');
1570 * Test the api_statuses_public_timeline() function.
1574 public function testApiStatusesPublicTimeline()
1576 $_REQUEST['max_id'] = 10;
1577 $_REQUEST['conversation_id'] = 1;
1578 $result = api_statuses_public_timeline('json');
1579 self::assertNotEmpty($result['status']);
1580 foreach ($result['status'] as $status) {
1581 self::assertStatus($status);
1586 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1590 public function testApiStatusesPublicTimelineWithExcludeReplies()
1592 $_REQUEST['max_id'] = 10;
1593 $_REQUEST['exclude_replies'] = true;
1594 $result = api_statuses_public_timeline('json');
1595 self::assertNotEmpty($result['status']);
1596 foreach ($result['status'] as $status) {
1597 self::assertStatus($status);
1602 * Test the api_statuses_public_timeline() function with a negative page parameter.
1606 public function testApiStatusesPublicTimelineWithNegativePage()
1608 $_REQUEST['page'] = -2;
1609 $result = api_statuses_public_timeline('json');
1610 self::assertNotEmpty($result['status']);
1611 foreach ($result['status'] as $status) {
1612 self::assertStatus($status);
1617 * Test the api_statuses_public_timeline() function with an unallowed user.
1621 public function testApiStatusesPublicTimelineWithUnallowedUser()
1623 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1624 $_SESSION['allow_api'] = false;
1625 $_GET['screen_name'] = $this->selfUser['nick'];
1626 api_statuses_public_timeline('json');
1630 * Test the api_statuses_public_timeline() function with an RSS result.
1634 public function testApiStatusesPublicTimelineWithRss()
1636 $result = api_statuses_public_timeline('rss');
1637 self::assertXml($result, 'statuses');
1641 * Test the api_statuses_networkpublic_timeline() function.
1645 public function testApiStatusesNetworkpublicTimeline()
1647 $_REQUEST['max_id'] = 10;
1648 $result = api_statuses_networkpublic_timeline('json');
1649 self::assertNotEmpty($result['status']);
1650 foreach ($result['status'] as $status) {
1651 self::assertStatus($status);
1656 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1660 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1662 $_REQUEST['page'] = -2;
1663 $result = api_statuses_networkpublic_timeline('json');
1664 self::assertNotEmpty($result['status']);
1665 foreach ($result['status'] as $status) {
1666 self::assertStatus($status);
1671 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1675 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1677 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1678 $_SESSION['allow_api'] = false;
1679 $_GET['screen_name'] = $this->selfUser['nick'];
1680 api_statuses_networkpublic_timeline('json');
1684 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1688 public function testApiStatusesNetworkpublicTimelineWithRss()
1690 $result = api_statuses_networkpublic_timeline('rss');
1691 self::assertXml($result, 'statuses');
1695 * Test the api_statuses_show() function.
1699 public function testApiStatusesShow()
1701 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1702 api_statuses_show('json');
1706 * Test the api_statuses_show() function with an ID.
1710 public function testApiStatusesShowWithId()
1712 DI::args()->setArgv(['', '', '', 1]);
1713 $result = api_statuses_show('json');
1714 self::assertStatus($result['status']);
1718 * Test the api_statuses_show() function with the conversation parameter.
1722 public function testApiStatusesShowWithConversation()
1724 DI::args()->setArgv(['', '', '', 1]);
1725 $_REQUEST['conversation'] = 1;
1726 $result = api_statuses_show('json');
1727 self::assertNotEmpty($result['status']);
1728 foreach ($result['status'] as $status) {
1729 self::assertStatus($status);
1734 * Test the api_statuses_show() function with an unallowed user.
1738 public function testApiStatusesShowWithUnallowedUser()
1740 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1741 $_SESSION['allow_api'] = false;
1742 $_GET['screen_name'] = $this->selfUser['nick'];
1743 api_statuses_show('json');
1747 * Test the api_conversation_show() function.
1751 public function testApiConversationShow()
1753 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1754 api_conversation_show('json');
1758 * Test the api_conversation_show() function with an ID.
1762 public function testApiConversationShowWithId()
1764 DI::args()->setArgv(['', '', '', 1]);
1765 $_REQUEST['max_id'] = 10;
1766 $_REQUEST['page'] = -2;
1767 $result = api_conversation_show('json');
1768 self::assertNotEmpty($result['status']);
1769 foreach ($result['status'] as $status) {
1770 self::assertStatus($status);
1775 * Test the api_conversation_show() function with an unallowed user.
1779 public function testApiConversationShowWithUnallowedUser()
1781 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1782 $_SESSION['allow_api'] = false;
1783 $_GET['screen_name'] = $this->selfUser['nick'];
1784 api_conversation_show('json');
1788 * Test the api_statuses_repeat() function.
1792 public function testApiStatusesRepeat()
1794 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1795 api_statuses_repeat('json');
1799 * Test the api_statuses_repeat() function without an authenticated user.
1803 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1805 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1806 $_SESSION['authenticated'] = false;
1807 api_statuses_repeat('json');
1811 * Test the api_statuses_repeat() function with an ID.
1815 public function testApiStatusesRepeatWithId()
1817 DI::args()->setArgv(['', '', '', 1]);
1818 $result = api_statuses_repeat('json');
1819 self::assertStatus($result['status']);
1821 // Also test with a shared status
1822 DI::args()->setArgv(['', '', '', 5]);
1823 $result = api_statuses_repeat('json');
1824 self::assertStatus($result['status']);
1828 * Test the api_statuses_destroy() function.
1832 public function testApiStatusesDestroy()
1834 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1835 api_statuses_destroy('json');
1839 * Test the api_statuses_destroy() function without an authenticated user.
1843 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1845 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1846 $_SESSION['authenticated'] = false;
1847 api_statuses_destroy('json');
1851 * Test the api_statuses_destroy() function with an ID.
1855 public function testApiStatusesDestroyWithId()
1857 DI::args()->setArgv(['', '', '', 1]);
1858 $result = api_statuses_destroy('json');
1859 self::assertStatus($result['status']);
1863 * Test the api_statuses_mentions() function.
1867 public function testApiStatusesMentions()
1869 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1870 $_REQUEST['max_id'] = 10;
1871 $result = api_statuses_mentions('json');
1872 self::assertEmpty($result['status']);
1873 // We should test with mentions in the database.
1877 * Test the api_statuses_mentions() function with a negative page parameter.
1881 public function testApiStatusesMentionsWithNegativePage()
1883 $_REQUEST['page'] = -2;
1884 $result = api_statuses_mentions('json');
1885 self::assertEmpty($result['status']);
1889 * Test the api_statuses_mentions() function with an unallowed user.
1893 public function testApiStatusesMentionsWithUnallowedUser()
1895 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1896 $_SESSION['allow_api'] = false;
1897 $_GET['screen_name'] = $this->selfUser['nick'];
1898 api_statuses_mentions('json');
1902 * Test the api_statuses_mentions() function with an RSS result.
1906 public function testApiStatusesMentionsWithRss()
1908 $result = api_statuses_mentions('rss');
1909 self::assertXml($result, 'statuses');
1913 * Test the api_statuses_user_timeline() function.
1917 public function testApiStatusesUserTimeline()
1919 $_REQUEST['max_id'] = 10;
1920 $_REQUEST['exclude_replies'] = true;
1921 $_REQUEST['conversation_id'] = 1;
1922 $result = api_statuses_user_timeline('json');
1923 self::assertNotEmpty($result['status']);
1924 foreach ($result['status'] as $status) {
1925 self::assertStatus($status);
1930 * Test the api_statuses_user_timeline() function with a negative page parameter.
1934 public function testApiStatusesUserTimelineWithNegativePage()
1936 $_REQUEST['page'] = -2;
1937 $result = api_statuses_user_timeline('json');
1938 self::assertNotEmpty($result['status']);
1939 foreach ($result['status'] as $status) {
1940 self::assertStatus($status);
1945 * Test the api_statuses_user_timeline() function with an RSS result.
1949 public function testApiStatusesUserTimelineWithRss()
1951 $result = api_statuses_user_timeline('rss');
1952 self::assertXml($result, 'statuses');
1956 * Test the api_statuses_user_timeline() function with an unallowed user.
1960 public function testApiStatusesUserTimelineWithUnallowedUser()
1962 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1963 $_SESSION['allow_api'] = false;
1964 $_GET['screen_name'] = $this->selfUser['nick'];
1965 api_statuses_user_timeline('json');
1969 * Test the api_favorites_create_destroy() function.
1973 public function testApiFavoritesCreateDestroy()
1975 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1976 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1977 api_favorites_create_destroy('json');
1981 * Test the api_favorites_create_destroy() function with an invalid ID.
1985 public function testApiFavoritesCreateDestroyWithInvalidId()
1987 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1988 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1989 api_favorites_create_destroy('json');
1993 * Test the api_favorites_create_destroy() function with an invalid action.
1997 public function testApiFavoritesCreateDestroyWithInvalidAction()
1999 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2000 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
2001 $_REQUEST['id'] = 1;
2002 api_favorites_create_destroy('json');
2006 * Test the api_favorites_create_destroy() function with the create action.
2010 public function testApiFavoritesCreateDestroyWithCreateAction()
2012 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2013 $_REQUEST['id'] = 3;
2014 $result = api_favorites_create_destroy('json');
2015 self::assertStatus($result['status']);
2019 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2023 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2025 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
2026 $_REQUEST['id'] = 3;
2027 $result = api_favorites_create_destroy('rss');
2028 self::assertXml($result, 'status');
2032 * Test the api_favorites_create_destroy() function with the destroy action.
2036 public function testApiFavoritesCreateDestroyWithDestroyAction()
2038 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
2039 $_REQUEST['id'] = 3;
2040 $result = api_favorites_create_destroy('json');
2041 self::assertStatus($result['status']);
2045 * Test the api_favorites_create_destroy() function without an authenticated user.
2049 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2051 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2052 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2053 $_SESSION['authenticated'] = false;
2054 api_favorites_create_destroy('json');
2058 * Test the api_favorites() function.
2062 public function testApiFavorites()
2064 $_REQUEST['page'] = -1;
2065 $_REQUEST['max_id'] = 10;
2066 $result = api_favorites('json');
2067 foreach ($result['status'] as $status) {
2068 self::assertStatus($status);
2073 * Test the api_favorites() function with an RSS result.
2077 public function testApiFavoritesWithRss()
2079 $result = api_favorites('rss');
2080 self::assertXml($result, 'statuses');
2084 * Test the api_favorites() function with an unallowed user.
2088 public function testApiFavoritesWithUnallowedUser()
2090 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2091 $_SESSION['allow_api'] = false;
2092 $_GET['screen_name'] = $this->selfUser['nick'];
2093 api_favorites('json');
2097 * Test the api_format_messages() function.
2101 public function testApiFormatMessages()
2103 $result = api_format_messages(
2104 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2105 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2106 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2108 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2109 self::assertEquals(1, $result['id']);
2110 self::assertEquals(2, $result['recipient_id']);
2111 self::assertEquals(3, $result['sender_id']);
2112 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2113 self::assertEquals('sender_name', $result['sender_screen_name']);
2117 * Test the api_format_messages() function with HTML.
2121 public function testApiFormatMessagesWithHtmlText()
2123 $_GET['getText'] = 'html';
2124 $result = api_format_messages(
2125 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2126 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2127 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2129 self::assertEquals('item_title', $result['title']);
2130 self::assertEquals('<strong>item_body</strong>', $result['text']);
2134 * Test the api_format_messages() function with plain text.
2138 public function testApiFormatMessagesWithPlainText()
2140 $_GET['getText'] = 'plain';
2141 $result = api_format_messages(
2142 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2143 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2144 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2146 self::assertEquals('item_title', $result['title']);
2147 self::assertEquals('item_body', $result['text']);
2151 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2155 public function testApiFormatMessagesWithoutUserObjects()
2157 $_GET['getUserObjects'] = 'false';
2158 $result = api_format_messages(
2159 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2160 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2161 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2163 self::assertTrue(!isset($result['sender']));
2164 self::assertTrue(!isset($result['recipient']));
2168 * Test the api_convert_item() function.
2172 public function testApiConvertItem()
2174 $result = api_convert_item(
2176 'network' => 'feed',
2177 'title' => 'item_title',
2179 // We need a long string to test that it is correctly cut
2180 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2181 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2182 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2183 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2184 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2185 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2186 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2187 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2188 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2189 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2190 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2191 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2192 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2193 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2194 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2195 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2196 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2197 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2198 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2199 'repellat officia illum quos impedit quam iste esse unde qui ' .
2200 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2201 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2202 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2203 'plink' => 'item_plink'
2206 self::assertStringStartsWith('item_title', $result['text']);
2207 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2211 * Test the api_convert_item() function with an empty item body.
2215 public function testApiConvertItemWithoutBody()
2217 $result = api_convert_item(
2219 'network' => 'feed',
2220 'title' => 'item_title',
2223 'plink' => 'item_plink'
2226 self::assertEquals("item_title", $result['text']);
2227 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2231 * Test the api_convert_item() function with the title in the body.
2235 public function testApiConvertItemWithTitleInBody()
2237 $result = api_convert_item(
2239 'title' => 'item_title',
2240 'body' => 'item_title item_body',
2244 self::assertEquals('item_title item_body', $result['text']);
2245 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2249 * Test the api_get_attachments() function.
2253 public function testApiGetAttachments()
2256 self::assertEmpty(api_get_attachments($body, 0));
2260 * Test the api_get_attachments() function with an img tag.
2264 public function testApiGetAttachmentsWithImage()
2266 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2267 self::assertIsArray(api_get_attachments($body, 0));
2271 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2275 public function testApiGetAttachmentsWithImageAndAndStatus()
2277 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2278 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2279 self::assertIsArray(api_get_attachments($body, 0));
2283 * Test the api_get_entitities() function.
2287 public function testApiGetEntitities()
2290 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2294 * Test the api_get_entitities() function with the include_entities parameter.
2298 public function testApiGetEntititiesWithIncludeEntities()
2300 $_REQUEST['include_entities'] = 'true';
2302 $result = api_get_entitities($text, 'bbcode', 0);
2303 self::assertIsArray($result['hashtags']);
2304 self::assertIsArray($result['symbols']);
2305 self::assertIsArray($result['urls']);
2306 self::assertIsArray($result['user_mentions']);
2310 * Test the api_format_items_embeded_images() function.
2314 public function testApiFormatItemsEmbededImages()
2317 'text ' . DI::baseUrl() . '/display/item_guid',
2318 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2323 * Test the api_contactlink_to_array() function.
2327 public function testApiContactlinkToArray()
2334 api_contactlink_to_array('text')
2339 * Test the api_contactlink_to_array() function with an URL.
2343 public function testApiContactlinkToArrayWithUrl()
2347 'name' => ['link_text'],
2350 api_contactlink_to_array('text <a href="url">link_text</a>')
2355 * Test the api_format_items_activities() function.
2359 public function testApiFormatItemsActivities()
2361 $item = ['uid' => 0, 'uri' => ''];
2362 $result = api_format_items_activities($item);
2363 self::assertArrayHasKey('like', $result);
2364 self::assertArrayHasKey('dislike', $result);
2365 self::assertArrayHasKey('attendyes', $result);
2366 self::assertArrayHasKey('attendno', $result);
2367 self::assertArrayHasKey('attendmaybe', $result);
2371 * Test the api_format_items_activities() function with an XML result.
2375 public function testApiFormatItemsActivitiesWithXml()
2377 $item = ['uid' => 0, 'uri' => ''];
2378 $result = api_format_items_activities($item, 'xml');
2379 self::assertArrayHasKey('friendica:like', $result);
2380 self::assertArrayHasKey('friendica:dislike', $result);
2381 self::assertArrayHasKey('friendica:attendyes', $result);
2382 self::assertArrayHasKey('friendica:attendno', $result);
2383 self::assertArrayHasKey('friendica:attendmaybe', $result);
2387 * Test the api_format_items() function.
2388 * @doesNotPerformAssertions
2390 public function testApiFormatItems()
2394 'item_network' => 'item_network',
2400 'author-network' => Protocol::DFRN,
2401 'author-link' => 'http://localhost/profile/othercontact',
2405 $result = api_format_items($items, ['id' => 0], true);
2406 foreach ($result as $status) {
2407 self::assertStatus($status);
2412 * Test the api_format_items() function with an XML result.
2413 * @doesNotPerformAssertions
2415 public function testApiFormatItemsWithXml()
2423 'author-network' => Protocol::DFRN,
2424 'author-link' => 'http://localhost/profile/othercontact',
2428 $result = api_format_items($items, ['id' => 0], true, 'xml');
2429 foreach ($result as $status) {
2430 self::assertStatus($status);
2435 * Test the api_lists_list() function.
2439 public function testApiListsList()
2441 $result = api_lists_list('json');
2442 self::assertEquals(['lists_list' => []], $result);
2446 * Test the api_lists_ownerships() function.
2450 public function testApiListsOwnerships()
2452 $result = api_lists_ownerships('json');
2453 foreach ($result['lists']['lists'] as $list) {
2454 self::assertList($list);
2459 * Test the api_lists_ownerships() function without an authenticated user.
2463 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2465 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2466 $_SESSION['authenticated'] = false;
2467 api_lists_ownerships('json');
2471 * Test the api_lists_statuses() function.
2475 public function testApiListsStatuses()
2477 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2478 api_lists_statuses('json');
2482 * Test the api_lists_statuses() function with a list ID.
2483 * @doesNotPerformAssertions
2485 public function testApiListsStatusesWithListId()
2487 $_REQUEST['list_id'] = 1;
2488 $_REQUEST['page'] = -1;
2489 $_REQUEST['max_id'] = 10;
2490 $result = api_lists_statuses('json');
2491 foreach ($result['status'] as $status) {
2492 self::assertStatus($status);
2497 * Test the api_lists_statuses() function with a list ID and a RSS result.
2501 public function testApiListsStatusesWithListIdAndRss()
2503 $_REQUEST['list_id'] = 1;
2504 $result = api_lists_statuses('rss');
2505 self::assertXml($result, 'statuses');
2509 * Test the api_lists_statuses() function with an unallowed user.
2513 public function testApiListsStatusesWithUnallowedUser()
2515 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2516 $_SESSION['allow_api'] = false;
2517 $_GET['screen_name'] = $this->selfUser['nick'];
2518 api_lists_statuses('json');
2522 * Test the api_statuses_f() function.
2526 public function testApiStatusesFWithFriends()
2529 $result = api_statuses_f('friends');
2530 self::assertArrayHasKey('user', $result);
2534 * Test the api_statuses_f() function.
2538 public function testApiStatusesFWithFollowers()
2540 $result = api_statuses_f('followers');
2541 self::assertArrayHasKey('user', $result);
2545 * Test the api_statuses_f() function.
2549 public function testApiStatusesFWithBlocks()
2551 $result = api_statuses_f('blocks');
2552 self::assertArrayHasKey('user', $result);
2556 * Test the api_statuses_f() function.
2560 public function testApiStatusesFWithIncoming()
2562 $result = api_statuses_f('incoming');
2563 self::assertArrayHasKey('user', $result);
2567 * Test the api_statuses_f() function an undefined cursor GET variable.
2571 public function testApiStatusesFWithUndefinedCursor()
2573 $_GET['cursor'] = 'undefined';
2574 self::assertFalse(api_statuses_f('friends'));
2578 * Test the api_statuses_friends() function.
2582 public function testApiStatusesFriends()
2584 $result = api_statuses_friends('json');
2585 self::assertArrayHasKey('user', $result);
2589 * Test the api_statuses_friends() function an undefined cursor GET variable.
2593 public function testApiStatusesFriendsWithUndefinedCursor()
2595 $_GET['cursor'] = 'undefined';
2596 self::assertFalse(api_statuses_friends('json'));
2600 * Test the api_statuses_followers() function.
2604 public function testApiStatusesFollowers()
2606 $result = api_statuses_followers('json');
2607 self::assertArrayHasKey('user', $result);
2611 * Test the api_statuses_followers() function an undefined cursor GET variable.
2615 public function testApiStatusesFollowersWithUndefinedCursor()
2617 $_GET['cursor'] = 'undefined';
2618 self::assertFalse(api_statuses_followers('json'));
2622 * Test the api_blocks_list() function.
2626 public function testApiBlocksList()
2628 $result = api_blocks_list('json');
2629 self::assertArrayHasKey('user', $result);
2633 * Test the api_blocks_list() function an undefined cursor GET variable.
2637 public function testApiBlocksListWithUndefinedCursor()
2639 $_GET['cursor'] = 'undefined';
2640 self::assertFalse(api_blocks_list('json'));
2644 * Test the api_friendships_incoming() function.
2648 public function testApiFriendshipsIncoming()
2650 $result = api_friendships_incoming('json');
2651 self::assertArrayHasKey('id', $result);
2655 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2659 public function testApiFriendshipsIncomingWithUndefinedCursor()
2661 $_GET['cursor'] = 'undefined';
2662 self::assertFalse(api_friendships_incoming('json'));
2666 * Test the api_statusnet_config() function.
2670 public function testApiStatusnetConfig()
2672 $result = api_statusnet_config('json');
2673 self::assertEquals('localhost', $result['config']['site']['server']);
2674 self::assertEquals('default', $result['config']['site']['theme']);
2675 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2676 self::assertTrue($result['config']['site']['fancy']);
2677 self::assertEquals('en', $result['config']['site']['language']);
2678 self::assertEquals('UTC', $result['config']['site']['timezone']);
2679 self::assertEquals(200000, $result['config']['site']['textlimit']);
2680 self::assertEquals('false', $result['config']['site']['private']);
2681 self::assertEquals('false', $result['config']['site']['ssl']);
2682 self::assertEquals(30, $result['config']['site']['shorturllength']);
2686 * Test the api_direct_messages_new() function.
2690 public function testApiDirectMessagesNew()
2692 $result = api_direct_messages_new('json');
2693 self::assertNull($result);
2697 * Test the api_direct_messages_new() function without an authenticated user.
2701 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2703 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2704 $_SESSION['authenticated'] = false;
2705 api_direct_messages_new('json');
2709 * Test the api_direct_messages_new() function with an user ID.
2713 public function testApiDirectMessagesNewWithUserId()
2715 $_POST['text'] = 'message_text';
2716 $_POST['user_id'] = $this->otherUser['id'];
2717 $result = api_direct_messages_new('json');
2718 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2722 * Test the api_direct_messages_new() function with a screen name.
2726 public function testApiDirectMessagesNewWithScreenName()
2728 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2729 $_POST['text'] = 'message_text';
2730 $_POST['screen_name'] = $this->friendUser['nick'];
2731 $result = api_direct_messages_new('json');
2732 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2733 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2734 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2738 * Test the api_direct_messages_new() function with a title.
2742 public function testApiDirectMessagesNewWithTitle()
2744 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2745 $_POST['text'] = 'message_text';
2746 $_POST['screen_name'] = $this->friendUser['nick'];
2747 $_REQUEST['title'] = 'message_title';
2748 $result = api_direct_messages_new('json');
2749 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2750 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2751 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2752 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2756 * Test the api_direct_messages_new() function with an RSS result.
2760 public function testApiDirectMessagesNewWithRss()
2762 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2763 $_POST['text'] = 'message_text';
2764 $_POST['screen_name'] = $this->friendUser['nick'];
2765 $result = api_direct_messages_new('rss');
2766 self::assertXml($result, 'direct-messages');
2770 * Test the api_direct_messages_destroy() function.
2774 public function testApiDirectMessagesDestroy()
2776 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2777 api_direct_messages_destroy('json');
2781 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2785 public function testApiDirectMessagesDestroyWithVerbose()
2787 $_GET['friendica_verbose'] = 'true';
2788 $result = api_direct_messages_destroy('json');
2792 'result' => 'error',
2793 'message' => 'message id or parenturi not specified'
2801 * Test the api_direct_messages_destroy() function without an authenticated user.
2805 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2807 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2808 $_SESSION['authenticated'] = false;
2809 api_direct_messages_destroy('json');
2813 * Test the api_direct_messages_destroy() function with a non-zero ID.
2817 public function testApiDirectMessagesDestroyWithId()
2819 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2820 $_REQUEST['id'] = 1;
2821 api_direct_messages_destroy('json');
2825 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2829 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2831 $_REQUEST['id'] = 1;
2832 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2833 $_GET['friendica_verbose'] = 'true';
2834 $result = api_direct_messages_destroy('json');
2838 'result' => 'error',
2839 'message' => 'message id not in database'
2847 * Test the api_direct_messages_destroy() function with a non-zero ID.
2851 public function testApiDirectMessagesDestroyWithCorrectId()
2853 $this->markTestIncomplete('We need to add a dataset for this.');
2857 * Test the api_direct_messages_box() function.
2861 public function testApiDirectMessagesBoxWithSentbox()
2863 $_REQUEST['page'] = -1;
2864 $_REQUEST['max_id'] = 10;
2865 $result = api_direct_messages_box('json', 'sentbox', 'false');
2866 self::assertArrayHasKey('direct_message', $result);
2870 * Test the api_direct_messages_box() function.
2874 public function testApiDirectMessagesBoxWithConversation()
2876 $result = api_direct_messages_box('json', 'conversation', 'false');
2877 self::assertArrayHasKey('direct_message', $result);
2881 * Test the api_direct_messages_box() function.
2885 public function testApiDirectMessagesBoxWithAll()
2887 $result = api_direct_messages_box('json', 'all', 'false');
2888 self::assertArrayHasKey('direct_message', $result);
2892 * Test the api_direct_messages_box() function.
2896 public function testApiDirectMessagesBoxWithInbox()
2898 $result = api_direct_messages_box('json', 'inbox', 'false');
2899 self::assertArrayHasKey('direct_message', $result);
2903 * Test the api_direct_messages_box() function.
2907 public function testApiDirectMessagesBoxWithVerbose()
2909 $result = api_direct_messages_box('json', 'sentbox', 'true');
2913 'result' => 'error',
2914 'message' => 'no mails available'
2922 * Test the api_direct_messages_box() function with a RSS result.
2926 public function testApiDirectMessagesBoxWithRss()
2928 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2929 self::assertXml($result, 'direct-messages');
2933 * Test the api_direct_messages_box() function without an authenticated user.
2937 public function testApiDirectMessagesBoxWithUnallowedUser()
2939 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2940 $_SESSION['allow_api'] = false;
2941 $_GET['screen_name'] = $this->selfUser['nick'];
2942 api_direct_messages_box('json', 'sentbox', 'false');
2946 * Test the api_direct_messages_sentbox() function.
2950 public function testApiDirectMessagesSentbox()
2952 $result = api_direct_messages_sentbox('json');
2953 self::assertArrayHasKey('direct_message', $result);
2957 * Test the api_direct_messages_inbox() function.
2961 public function testApiDirectMessagesInbox()
2963 $result = api_direct_messages_inbox('json');
2964 self::assertArrayHasKey('direct_message', $result);
2968 * Test the api_direct_messages_all() function.
2972 public function testApiDirectMessagesAll()
2974 $result = api_direct_messages_all('json');
2975 self::assertArrayHasKey('direct_message', $result);
2979 * Test the api_direct_messages_conversation() function.
2983 public function testApiDirectMessagesConversation()
2985 $result = api_direct_messages_conversation('json');
2986 self::assertArrayHasKey('direct_message', $result);
2990 * Test the api_oauth_request_token() function.
2994 public function testApiOauthRequestToken()
2996 $this->markTestIncomplete('exit() kills phpunit as well');
3000 * Test the api_oauth_access_token() function.
3004 public function testApiOauthAccessToken()
3006 $this->markTestIncomplete('exit() kills phpunit as well');
3010 * Test the api_fr_photos_list() function.
3014 public function testApiFrPhotosList()
3016 $result = api_fr_photos_list('json');
3017 self::assertArrayHasKey('photo', $result);
3021 * Test the api_fr_photos_list() function without an authenticated user.
3025 public function testApiFrPhotosListWithoutAuthenticatedUser()
3027 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3028 $_SESSION['authenticated'] = false;
3029 api_fr_photos_list('json');
3033 * Test the api_fr_photo_create_update() function.
3035 public function testApiFrPhotoCreateUpdate()
3037 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3038 api_fr_photo_create_update('json');
3042 * Test the api_fr_photo_create_update() function without an authenticated user.
3046 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3048 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3049 $_SESSION['authenticated'] = false;
3050 api_fr_photo_create_update('json');
3054 * Test the api_fr_photo_create_update() function with an album name.
3058 public function testApiFrPhotoCreateUpdateWithAlbum()
3060 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3061 $_REQUEST['album'] = 'album_name';
3062 api_fr_photo_create_update('json');
3066 * Test the api_fr_photo_create_update() function with the update mode.
3070 public function testApiFrPhotoCreateUpdateWithUpdate()
3072 $this->markTestIncomplete('We need to create a dataset for this');
3076 * Test the api_fr_photo_create_update() function with an uploaded file.
3080 public function testApiFrPhotoCreateUpdateWithFile()
3082 $this->markTestIncomplete();
3086 * Test the api_fr_photo_detail() function.
3090 public function testApiFrPhotoDetail()
3092 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3093 api_fr_photo_detail('json');
3097 * Test the api_fr_photo_detail() function without an authenticated user.
3101 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3103 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3104 $_SESSION['authenticated'] = false;
3105 api_fr_photo_detail('json');
3109 * Test the api_fr_photo_detail() function with a photo ID.
3113 public function testApiFrPhotoDetailWithPhotoId()
3115 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3116 $_REQUEST['photo_id'] = 1;
3117 api_fr_photo_detail('json');
3121 * Test the api_fr_photo_detail() function with a correct photo ID.
3125 public function testApiFrPhotoDetailCorrectPhotoId()
3127 $this->markTestIncomplete('We need to create a dataset for this.');
3131 * Test the api_account_update_profile_image() function.
3135 public function testApiAccountUpdateProfileImage()
3137 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3138 api_account_update_profile_image('json');
3142 * Test the api_account_update_profile_image() function without an authenticated user.
3146 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3148 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3149 $_SESSION['authenticated'] = false;
3150 api_account_update_profile_image('json');
3154 * Test the api_account_update_profile_image() function with an uploaded file.
3158 public function testApiAccountUpdateProfileImageWithUpload()
3160 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3161 $this->markTestIncomplete();
3166 * Test the api_account_update_profile() function.
3170 public function testApiAccountUpdateProfile()
3172 $_POST['name'] = 'new_name';
3173 $_POST['description'] = 'new_description';
3174 $result = api_account_update_profile('json');
3175 // We can't use assertSelfUser() here because the user object is missing some properties.
3176 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3177 self::assertEquals('DFRN', $result['user']['location']);
3178 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3179 self::assertEquals('dfrn', $result['user']['network']);
3180 self::assertEquals('new_name', $result['user']['name']);
3181 self::assertEquals('new_description', $result['user']['description']);
3185 * Test the check_acl_input() function.
3189 public function testCheckAclInput()
3191 $result = check_acl_input('<aclstring>');
3192 // Where does this result come from?
3193 self::assertEquals(1, $result);
3197 * Test the check_acl_input() function with an empty ACL string.
3201 public function testCheckAclInputWithEmptyAclString()
3203 $result = check_acl_input(' ');
3204 self::assertFalse($result);
3208 * Test the save_media_to_database() function.
3212 public function testSaveMediaToDatabase()
3214 $this->markTestIncomplete();
3218 * Test the post_photo_item() function.
3222 public function testPostPhotoItem()
3224 $this->markTestIncomplete();
3228 * Test the prepare_photo_data() function.
3232 public function testPreparePhotoData()
3234 $this->markTestIncomplete();
3238 * Test the api_share_as_retweet() function with a valid item.
3242 public function testApiShareAsRetweetWithValidItem()
3244 $this->markTestIncomplete();
3248 * Test the api_in_reply_to() function.
3252 public function testApiInReplyTo()
3254 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3255 self::assertArrayHasKey('status_id', $result);
3256 self::assertArrayHasKey('user_id', $result);
3257 self::assertArrayHasKey('status_id_str', $result);
3258 self::assertArrayHasKey('user_id_str', $result);
3259 self::assertArrayHasKey('screen_name', $result);
3263 * Test the api_in_reply_to() function with a valid item.
3267 public function testApiInReplyToWithValidItem()
3269 $this->markTestIncomplete();
3273 * Test the api_clean_plain_items() function.
3277 public function testApiCleanPlainItems()
3279 $_REQUEST['include_entities'] = 'true';
3280 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3281 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3285 * Test the api_best_nickname() function.
3289 public function testApiBestNickname()
3292 $result = api_best_nickname($contacts);
3293 self::assertNull($result);
3297 * Test the api_best_nickname() function with contacts.
3301 public function testApiBestNicknameWithContacts()
3303 $this->markTestIncomplete();
3307 * Test the api_friendica_group_show() function.
3311 public function testApiFriendicaGroupShow()
3313 $this->markTestIncomplete();
3317 * Test the api_friendica_group_delete() function.
3321 public function testApiFriendicaGroupDelete()
3323 $this->markTestIncomplete();
3327 * Test the api_lists_destroy() function.
3331 public function testApiListsDestroy()
3333 $this->markTestIncomplete();
3337 * Test the group_create() function.
3341 public function testGroupCreate()
3343 $this->markTestIncomplete();
3347 * Test the api_friendica_group_create() function.
3351 public function testApiFriendicaGroupCreate()
3353 $this->markTestIncomplete();
3357 * Test the api_lists_create() function.
3361 public function testApiListsCreate()
3363 $this->markTestIncomplete();
3367 * Test the api_friendica_group_update() function.
3371 public function testApiFriendicaGroupUpdate()
3373 $this->markTestIncomplete();
3377 * Test the api_lists_update() function.
3381 public function testApiListsUpdate()
3383 $this->markTestIncomplete();
3387 * Test the api_friendica_activity() function.
3391 public function testApiFriendicaActivity()
3393 $this->markTestIncomplete();
3397 * Test the api_friendica_notification_seen() function.
3401 public function testApiFriendicaNotificationSeen()
3403 $this->markTestIncomplete();
3407 * Test the api_friendica_direct_messages_setseen() function.
3411 public function testApiFriendicaDirectMessagesSetseen()
3413 $this->markTestIncomplete();
3417 * Test the api_friendica_direct_messages_search() function.
3421 public function testApiFriendicaDirectMessagesSearch()
3423 $this->markTestIncomplete();