6 namespace Friendica\Test\legacy;
9 use Friendica\Core\Config\Capability\IManageConfigValues;
10 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
11 use Friendica\Core\Protocol;
13 use Friendica\Module\Api\ApiResponse;
14 use Friendica\Module\BaseApi;
15 use Friendica\Network\HTTPException;
16 use Friendica\Security\BasicAuth;
17 use Friendica\Test\FixtureTest;
18 use Friendica\Util\Arrays;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Temporal;
21 use Monolog\Handler\TestHandler;
23 require_once __DIR__ . '/../../include/api.php';
26 * Tests for the API functions.
28 * Functions that use header() need to be tested in a separate process.
29 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31 * @backupGlobals enabled
33 class ApiTest extends FixtureTest
36 * @var TestHandler Can handle log-outputs
43 protected $friendUser;
47 protected $wrongUserId;
52 /** @var IManageConfigValues */
56 * Create variables used by tests.
58 protected function setUp() : void
60 global $API, $called_api;
66 /** @var IManageConfigValues $config */
67 $this->config = $this->dice->create(IManageConfigValues::class);
69 $this->config->set('system', 'url', 'http://localhost');
70 $this->config->set('system', 'hostname', 'localhost');
71 $this->config->set('system', 'worker_dont_fork', true);
74 $this->config->set('config', 'hostname', 'localhost');
75 $this->config->set('system', 'throttle_limit_day', 100);
76 $this->config->set('system', 'throttle_limit_week', 100);
77 $this->config->set('system', 'throttle_limit_month', 100);
78 $this->config->set('system', 'theme', 'system_theme');
82 $this->app = DI::app();
84 DI::args()->setArgc(1);
86 // User data that the test database is populated with
89 'name' => 'Self contact',
90 'nick' => 'selfcontact',
91 'nurl' => 'http://localhost/profile/selfcontact'
95 'name' => 'Friend contact',
96 'nick' => 'friendcontact',
97 'nurl' => 'http://localhost/profile/friendcontact'
101 'name' => 'othercontact',
102 'nick' => 'othercontact',
103 'nurl' => 'http://localhost/profile/othercontact'
106 // User ID that we know is not in the database
107 $this->wrongUserId = 666;
109 DI::session()->start();
111 // Most API require login so we force the session
114 'authenticated' => true,
115 'uid' => $this->selfUser['id']
117 BasicAuth::setCurrentUserID($this->selfUser['id']);
121 * Assert that an user array contains expected keys.
123 * @param array $user User array
127 private function assertSelfUser(array $user)
129 self::assertEquals($this->selfUser['id'], $user['uid']);
130 self::assertEquals($this->selfUser['id'], $user['cid']);
131 self::assertEquals(1, $user['self']);
132 self::assertEquals('DFRN', $user['location']);
133 self::assertEquals($this->selfUser['name'], $user['name']);
134 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
135 self::assertEquals('dfrn', $user['network']);
136 self::assertTrue($user['verified']);
140 * Assert that an user array contains expected keys.
142 * @param array $user User array
146 private function assertOtherUser(array $user = [])
148 self::assertEquals($this->otherUser['id'], $user['id']);
149 self::assertEquals($this->otherUser['id'], $user['id_str']);
150 self::assertEquals(0, $user['self']);
151 self::assertEquals($this->otherUser['name'], $user['name']);
152 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
153 self::assertFalse($user['verified']);
157 * Assert that a status array contains expected keys.
159 * @param array $status Status array
163 private function assertStatus(array $status = [])
165 self::assertIsString($status['text'] ?? '');
166 self::assertIsInt($status['id'] ?? '');
167 // We could probably do more checks here.
171 * Assert that a list array contains expected keys.
173 * @param array $list List array
177 private function assertList(array $list = [])
179 self::assertIsString($list['name']);
180 self::assertIsInt($list['id']);
181 self::assertIsString('string', $list['id_str']);
182 self::assertContains($list['mode'], ['public', 'private']);
183 // We could probably do more checks here.
187 * Assert that the string is XML and contain the root element.
189 * @param string $result XML string
190 * @param string $root_element Root element name
194 private function assertXml($result = '', $root_element = '')
196 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
197 self::assertStringContainsString('<' . $root_element, $result);
198 // We could probably do more checks here.
202 * Get the path to a temporary empty PNG image.
204 * @return string Path
206 private function getTempImage()
208 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
212 // Empty 1x1 px PNG image
213 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
221 * Test the api_user() function.
225 public function testApiUser()
227 self::assertEquals($this->selfUser['id'], api_user());
231 * Test the api_user() function with an unallowed user.
235 public function testApiUserWithUnallowedUser()
237 $_SESSION = ['allow_api' => false];
238 self::assertEquals(false, api_user());
242 * Test the api_source() function.
246 public function testApiSource()
248 self::assertEquals('api', api_source());
252 * Test the api_source() function with a Twidere user agent.
256 public function testApiSourceWithTwidere()
258 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
259 self::assertEquals('Twidere', api_source());
263 * Test the api_source() function with a GET parameter.
267 public function testApiSourceWithGet()
269 $_GET['source'] = 'source_name';
270 self::assertEquals('source_name', api_source());
274 * Test the api_date() function.
278 public function testApiDate()
280 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
284 * Test the api_register_func() function.
288 public function testApiRegisterFunc()
300 self::assertTrue($API['api_path']['auth']);
301 self::assertEquals('method', $API['api_path']['method']);
302 self::assertTrue(is_callable($API['api_path']['func']));
306 * Test the BasicAuth::getCurrentUserID() function without any login.
308 * @runInSeparateProcess
309 * @preserveGlobalState disabled
310 * @preserveGlobalState disabled
312 public function testApiLoginWithoutLogin()
314 BasicAuth::setCurrentUserID();
315 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
316 BasicAuth::getCurrentUserID(true);
320 * Test the BasicAuth::getCurrentUserID() function with a bad login.
322 * @runInSeparateProcess
323 * @preserveGlobalState disabled
324 * @preserveGlobalState disabled
326 public function testApiLoginWithBadLogin()
328 BasicAuth::setCurrentUserID();
329 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
330 $_SERVER['PHP_AUTH_USER'] = 'user@server';
331 BasicAuth::getCurrentUserID(true);
335 * Test the BasicAuth::getCurrentUserID() function with oAuth.
339 public function testApiLoginWithOauth()
341 $this->markTestIncomplete('Can we test this easily?');
345 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
349 public function testApiLoginWithAddonAuth()
351 $this->markTestIncomplete('Can we test this easily?');
355 * Test the BasicAuth::getCurrentUserID() function with a correct login.
357 * @runInSeparateProcess
358 * @preserveGlobalState disabled
359 * @doesNotPerformAssertions
361 public function testApiLoginWithCorrectLogin()
363 BasicAuth::setCurrentUserID();
364 $_SERVER['PHP_AUTH_USER'] = 'Test user';
365 $_SERVER['PHP_AUTH_PW'] = 'password';
366 BasicAuth::getCurrentUserID(true);
370 * Test the BasicAuth::getCurrentUserID() function with a remote user.
372 * @runInSeparateProcess
373 * @preserveGlobalState disabled
375 public function testApiLoginWithRemoteUser()
377 BasicAuth::setCurrentUserID();
378 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
379 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
380 BasicAuth::getCurrentUserID(true);
384 * Test the api_check_method() function.
388 public function testApiCheckMethod()
390 self::assertFalse(api_check_method('method'));
394 * Test the api_check_method() function with a correct method.
398 public function testApiCheckMethodWithCorrectMethod()
400 $_SERVER['REQUEST_METHOD'] = 'method';
401 self::assertTrue(api_check_method('method'));
405 * Test the api_check_method() function with a wildcard.
409 public function testApiCheckMethodWithWildcard()
411 self::assertTrue(api_check_method('*'));
415 * Test the api_call() function.
417 * @runInSeparateProcess
418 * @preserveGlobalState disabled
420 public function testApiCall()
424 'method' => 'method',
425 'func' => function () {
426 return ['data' => ['some_data']];
429 $_SERVER['REQUEST_METHOD'] = 'method';
430 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
431 $_GET['callback'] = 'callback_name';
433 $args = DI::args()->determine($_SERVER, $_GET);
436 'callback_name(["some_data"])',
437 api_call($this->app, $args)
442 * Test the api_call() function with the profiled enabled.
444 * @runInSeparateProcess
445 * @preserveGlobalState disabled
447 public function testApiCallWithProfiler()
451 'method' => 'method',
452 'func' => function () {
453 return ['data' => ['some_data']];
457 $_SERVER['REQUEST_METHOD'] = 'method';
458 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
460 $args = DI::args()->determine($_SERVER, $_GET);
462 $this->config->set('system', 'profiler', true);
463 $this->config->set('rendertime', 'callstack', true);
464 $this->app->callstack = [
465 'database' => ['some_function' => 200],
466 'database_write' => ['some_function' => 200],
467 'cache' => ['some_function' => 200],
468 'cache_write' => ['some_function' => 200],
469 'network' => ['some_function' => 200]
474 api_call($this->app, $args)
479 * Test the api_call() function with a JSON result.
481 * @runInSeparateProcess
482 * @preserveGlobalState disabled
484 public function testApiCallWithJson()
488 'method' => 'method',
489 'func' => function () {
490 return ['data' => ['some_data']];
493 $_SERVER['REQUEST_METHOD'] = 'method';
494 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
496 $args = DI::args()->determine($_SERVER, $_GET);
500 api_call($this->app, $args)
505 * Test the api_call() function with an XML result.
507 * @runInSeparateProcess
508 * @preserveGlobalState disabled
510 public function testApiCallWithXml()
514 'method' => 'method',
515 'func' => function () {
519 $_SERVER['REQUEST_METHOD'] = 'method';
520 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
522 $args = DI::args()->determine($_SERVER, $_GET);
526 api_call($this->app, $args)
531 * Test the api_call() function with an RSS result.
533 * @runInSeparateProcess
534 * @preserveGlobalState disabled
536 public function testApiCallWithRss()
540 'method' => 'method',
541 'func' => function () {
545 $_SERVER['REQUEST_METHOD'] = 'method';
546 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
548 $args = DI::args()->determine($_SERVER, $_GET);
551 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
553 api_call($this->app, $args)
558 * Test the api_call() function with an Atom result.
560 * @runInSeparateProcess
561 * @preserveGlobalState disabled
563 public function testApiCallWithAtom()
567 'method' => 'method',
568 'func' => function () {
572 $_SERVER['REQUEST_METHOD'] = 'method';
573 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
575 $args = DI::args()->determine($_SERVER, $_GET);
578 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
580 api_call($this->app, $args)
585 * Test the api_rss_extra() function.
589 public function testApiRssExtra()
591 $user_info = ['url' => 'user_url', 'lang' => 'en'];
592 $result = api_rss_extra([], $user_info);
593 self::assertEquals($user_info, $result['$user']);
594 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
595 self::assertArrayHasKey('self', $result['$rss']);
596 self::assertArrayHasKey('base', $result['$rss']);
597 self::assertArrayHasKey('updated', $result['$rss']);
598 self::assertArrayHasKey('atom_updated', $result['$rss']);
599 self::assertArrayHasKey('language', $result['$rss']);
600 self::assertArrayHasKey('logo', $result['$rss']);
604 * Test the api_rss_extra() function without any user info.
608 public function testApiRssExtraWithoutUserInfo()
610 $result = api_rss_extra([], null);
611 self::assertIsArray($result['$user']);
612 self::assertArrayHasKey('alternate', $result['$rss']);
613 self::assertArrayHasKey('self', $result['$rss']);
614 self::assertArrayHasKey('base', $result['$rss']);
615 self::assertArrayHasKey('updated', $result['$rss']);
616 self::assertArrayHasKey('atom_updated', $result['$rss']);
617 self::assertArrayHasKey('language', $result['$rss']);
618 self::assertArrayHasKey('logo', $result['$rss']);
622 * Test the api_unique_id_to_nurl() function.
626 public function testApiUniqueIdToNurl()
628 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
632 * Test the api_unique_id_to_nurl() function with a correct ID.
636 public function testApiUniqueIdToNurlWithCorrectId()
638 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
642 * Test the api_get_user() function.
646 public function testApiGetUser()
648 $user = api_get_user();
649 self::assertSelfUser($user);
650 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
651 // self::assertEquals('6fdbe8', $user['profile_link_color']);
652 // self::assertEquals('ededed', $user['profile_background_color']);
656 * Test the api_get_user() function with a Frio schema.
660 public function testApiGetUserWithFrioSchema()
662 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
663 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
664 $user = api_get_user();
665 self::assertSelfUser($user);
666 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
667 // self::assertEquals('6fdbe8', $user['profile_link_color']);
668 // self::assertEquals('ededed', $user['profile_background_color']);
672 * Test the api_get_user() function with an empty Frio schema.
676 public function testApiGetUserWithEmptyFrioSchema()
678 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
679 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
680 $user = api_get_user();
681 self::assertSelfUser($user);
682 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
683 // self::assertEquals('6fdbe8', $user['profile_link_color']);
684 // self::assertEquals('ededed', $user['profile_background_color']);
688 * Test the api_get_user() function with a custom Frio schema.
692 public function testApiGetUserWithCustomFrioSchema()
694 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
695 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
696 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
697 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
698 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
699 $user = api_get_user();
700 self::assertSelfUser($user);
701 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
702 // self::assertEquals('123456', $user['profile_link_color']);
703 // self::assertEquals('123456', $user['profile_background_color']);
707 * Test the api_get_user() function with an user that is not allowed to use the API.
709 * @runInSeparateProcess
710 * @preserveGlobalState disabled
712 public function testApiGetUserWithoutApiUser()
714 $_SERVER['PHP_AUTH_USER'] = 'Test user';
715 $_SERVER['PHP_AUTH_PW'] = 'password';
716 $_SESSION['allow_api'] = false;
717 BasicAuth::setCurrentUserID();
718 self::assertFalse(api_get_user());
722 * Test the api_get_user() function with an user ID in a GET parameter.
726 public function testApiGetUserWithGetId()
728 $_GET['user_id'] = $this->otherUser['id'];
729 self::assertOtherUser(api_get_user());
733 * Test the api_get_user() function with a wrong user ID in a GET parameter.
737 public function testApiGetUserWithWrongGetId()
739 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
740 $_GET['user_id'] = $this->wrongUserId;
741 self::assertOtherUser(api_get_user());
745 * Test the api_get_user() function with an user name in a GET parameter.
749 public function testApiGetUserWithGetName()
751 $_GET['screen_name'] = $this->selfUser['nick'];
752 self::assertSelfUser(api_get_user());
756 * Test the api_get_user() function with a profile URL in a GET parameter.
760 public function testApiGetUserWithGetUrl()
762 $_GET['profileurl'] = $this->selfUser['nurl'];
763 self::assertSelfUser(api_get_user());
767 * Test the api_get_user() function with an user ID in the API path.
771 public function testApiGetUserWithNumericCalledApi()
774 $called_api = ['api_path'];
775 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
776 self::assertOtherUser(api_get_user());
780 * Test the api_get_user() function with the $called_api global variable.
784 public function testApiGetUserWithCalledApi()
787 $called_api = ['api', 'api_path'];
788 self::assertSelfUser(api_get_user());
792 * Test the api_get_user() function with a valid user.
796 public function testApiGetUserWithCorrectUser()
798 self::assertOtherUser(api_get_user($this->otherUser['id']));
802 * Test the api_get_user() function with a wrong user ID.
806 public function testApiGetUserWithWrongUser()
808 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
809 self::assertOtherUser(api_get_user($this->wrongUserId));
813 * Test the api_get_user() function with a 0 user ID.
817 public function testApiGetUserWithZeroUser()
819 self::assertSelfUser(api_get_user(0));
823 * Test the api_item_get_user() function.
827 public function testApiItemGetUser()
829 $users = api_item_get_user($this->app, []);
830 self::assertSelfUser($users[0]);
834 * Test the api_item_get_user() function with a different item parent.
838 public function testApiItemGetUserWithDifferentParent()
840 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
841 self::assertSelfUser($users[0]);
842 self::assertEquals($users[0], $users[1]);
846 * Test the Arrays::walkRecursive() function.
850 public function testApiWalkRecursive()
855 Arrays::walkRecursive(
858 // Should we test this with a callback that actually does something?
866 * Test the Arrays::walkRecursive() function with an array.
870 public function testApiWalkRecursiveWithArray()
872 $array = [['item1'], ['item2']];
875 Arrays::walkRecursive(
878 // Should we test this with a callback that actually does something?
886 * Test the BaseApi::reformatXML() function.
890 public function testApiReformatXml()
894 self::assertTrue(ApiResponse::reformatXML($item, $key));
895 self::assertEquals('true', $item);
899 * Test the BaseApi::reformatXML() function with a statusnet_api key.
903 public function testApiReformatXmlWithStatusnetKey()
906 $key = 'statusnet_api';
907 self::assertTrue(ApiResponse::reformatXML($item, $key));
908 self::assertEquals('statusnet:api', $key);
912 * Test the BaseApi::reformatXML() function with a friendica_api key.
916 public function testApiReformatXmlWithFriendicaKey()
919 $key = 'friendica_api';
920 self::assertTrue(ApiResponse::reformatXML($item, $key));
921 self::assertEquals('friendica:api', $key);
925 * Test the BaseApi::createXML() function.
929 public function testApiCreateXml()
932 '<?xml version="1.0"?>' . "\n" .
933 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
934 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
935 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
936 ' <data>some_data</data>' . "\n" .
937 '</root_element>' . "\n",
938 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
943 * Test the BaseApi::createXML() function without any XML namespace.
947 public function testApiCreateXmlWithoutNamespaces()
950 '<?xml version="1.0"?>' . "\n" .
952 ' <data>some_data</data>' . "\n" .
954 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
959 * Test the BaseApi::formatData() function.
963 public function testApiFormatData()
965 $data = ['some_data'];
966 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
970 * Test the BaseApi::formatData() function with an XML result.
974 public function testApiFormatDataWithXml()
977 '<?xml version="1.0"?>' . "\n" .
978 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
979 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
980 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
981 ' <data>some_data</data>' . "\n" .
982 '</root_element>' . "\n",
983 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
988 * Test the api_account_verify_credentials() function.
992 public function testApiAccountVerifyCredentials()
994 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
998 * Test the api_account_verify_credentials() function without an authenticated user.
1002 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1004 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1005 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 $_SESSION['allow_api'] = false;
1433 $_GET['screen_name'] = $this->selfUser['nick'];
1434 BasicAuth::setCurrentUserID();
1439 * Test the api_search() function without any GET query parameter.
1443 public function testApiSearchWithoutQuery()
1445 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1450 * Test the api_statuses_home_timeline() function.
1454 public function testApiStatusesHomeTimeline()
1456 $_REQUEST['max_id'] = 10;
1457 $_REQUEST['exclude_replies'] = true;
1458 $_REQUEST['conversation_id'] = 1;
1459 $result = api_statuses_home_timeline('json');
1460 self::assertNotEmpty($result['status']);
1461 foreach ($result['status'] as $status) {
1462 self::assertStatus($status);
1467 * Test the api_statuses_home_timeline() function with a negative page parameter.
1471 public function testApiStatusesHomeTimelineWithNegativePage()
1473 $_REQUEST['page'] = -2;
1474 $result = api_statuses_home_timeline('json');
1475 self::assertNotEmpty($result['status']);
1476 foreach ($result['status'] as $status) {
1477 self::assertStatus($status);
1482 * Test the api_statuses_home_timeline() with an unallowed user.
1486 public function testApiStatusesHomeTimelineWithUnallowedUser()
1488 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1489 $_SESSION['allow_api'] = false;
1490 $_GET['screen_name'] = $this->selfUser['nick'];
1491 BasicAuth::setCurrentUserID();
1492 api_statuses_home_timeline('json');
1496 * Test the api_statuses_home_timeline() function with an RSS result.
1500 public function testApiStatusesHomeTimelineWithRss()
1502 $result = api_statuses_home_timeline('rss');
1503 self::assertXml($result, 'statuses');
1507 * Test the api_statuses_public_timeline() function.
1511 public function testApiStatusesPublicTimeline()
1513 $_REQUEST['max_id'] = 10;
1514 $_REQUEST['conversation_id'] = 1;
1515 $result = api_statuses_public_timeline('json');
1516 self::assertNotEmpty($result['status']);
1517 foreach ($result['status'] as $status) {
1518 self::assertStatus($status);
1523 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1527 public function testApiStatusesPublicTimelineWithExcludeReplies()
1529 $_REQUEST['max_id'] = 10;
1530 $_REQUEST['exclude_replies'] = true;
1531 $result = api_statuses_public_timeline('json');
1532 self::assertNotEmpty($result['status']);
1533 foreach ($result['status'] as $status) {
1534 self::assertStatus($status);
1539 * Test the api_statuses_public_timeline() function with a negative page parameter.
1543 public function testApiStatusesPublicTimelineWithNegativePage()
1545 $_REQUEST['page'] = -2;
1546 $result = api_statuses_public_timeline('json');
1547 self::assertNotEmpty($result['status']);
1548 foreach ($result['status'] as $status) {
1549 self::assertStatus($status);
1554 * Test the api_statuses_public_timeline() function with an unallowed user.
1558 public function testApiStatusesPublicTimelineWithUnallowedUser()
1560 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1561 $_SESSION['allow_api'] = false;
1562 $_GET['screen_name'] = $this->selfUser['nick'];
1563 BasicAuth::setCurrentUserID();
1564 api_statuses_public_timeline('json');
1568 * Test the api_statuses_public_timeline() function with an RSS result.
1572 public function testApiStatusesPublicTimelineWithRss()
1574 $result = api_statuses_public_timeline('rss');
1575 self::assertXml($result, 'statuses');
1579 * Test the api_statuses_networkpublic_timeline() function.
1583 public function testApiStatusesNetworkpublicTimeline()
1585 $_REQUEST['max_id'] = 10;
1586 $result = api_statuses_networkpublic_timeline('json');
1587 self::assertNotEmpty($result['status']);
1588 foreach ($result['status'] as $status) {
1589 self::assertStatus($status);
1594 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1598 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1600 $_REQUEST['page'] = -2;
1601 $result = api_statuses_networkpublic_timeline('json');
1602 self::assertNotEmpty($result['status']);
1603 foreach ($result['status'] as $status) {
1604 self::assertStatus($status);
1609 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1613 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1615 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1616 $_SESSION['allow_api'] = false;
1617 $_GET['screen_name'] = $this->selfUser['nick'];
1618 BasicAuth::setCurrentUserID();
1619 api_statuses_networkpublic_timeline('json');
1623 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1627 public function testApiStatusesNetworkpublicTimelineWithRss()
1629 $result = api_statuses_networkpublic_timeline('rss');
1630 self::assertXml($result, 'statuses');
1634 * Test the api_statuses_show() function.
1638 public function testApiStatusesShow()
1640 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1641 api_statuses_show('json');
1645 * Test the api_statuses_show() function with an ID.
1649 public function testApiStatusesShowWithId()
1651 DI::args()->setArgv(['', '', '', 1]);
1652 $result = api_statuses_show('json');
1653 self::assertStatus($result['status']);
1657 * Test the api_statuses_show() function with the conversation parameter.
1661 public function testApiStatusesShowWithConversation()
1663 DI::args()->setArgv(['', '', '', 1]);
1664 $_REQUEST['conversation'] = 1;
1665 $result = api_statuses_show('json');
1666 self::assertNotEmpty($result['status']);
1667 foreach ($result['status'] as $status) {
1668 self::assertStatus($status);
1673 * Test the api_statuses_show() function with an unallowed user.
1677 public function testApiStatusesShowWithUnallowedUser()
1679 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1680 $_SESSION['allow_api'] = false;
1681 $_GET['screen_name'] = $this->selfUser['nick'];
1682 BasicAuth::setCurrentUserID();
1683 api_statuses_show('json');
1687 * Test the api_conversation_show() function.
1691 public function testApiConversationShow()
1693 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1694 api_conversation_show('json');
1698 * Test the api_conversation_show() function with an ID.
1702 public function testApiConversationShowWithId()
1704 DI::args()->setArgv(['', '', '', 1]);
1705 $_REQUEST['max_id'] = 10;
1706 $_REQUEST['page'] = -2;
1707 $result = api_conversation_show('json');
1708 self::assertNotEmpty($result['status']);
1709 foreach ($result['status'] as $status) {
1710 self::assertStatus($status);
1715 * Test the api_conversation_show() function with an unallowed user.
1719 public function testApiConversationShowWithUnallowedUser()
1721 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1722 $_SESSION['allow_api'] = false;
1723 $_GET['screen_name'] = $this->selfUser['nick'];
1724 BasicAuth::setCurrentUserID();
1725 api_conversation_show('json');
1729 * Test the api_statuses_repeat() function.
1733 public function testApiStatusesRepeat()
1735 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1736 api_statuses_repeat('json');
1740 * Test the api_statuses_repeat() function without an authenticated user.
1744 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1746 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1747 BasicAuth::setCurrentUserID();
1748 $_SESSION['authenticated'] = false;
1749 api_statuses_repeat('json');
1753 * Test the api_statuses_repeat() function with an ID.
1757 public function testApiStatusesRepeatWithId()
1759 DI::args()->setArgv(['', '', '', 1]);
1760 $result = api_statuses_repeat('json');
1761 self::assertStatus($result['status']);
1763 // Also test with a shared status
1764 DI::args()->setArgv(['', '', '', 5]);
1765 $result = api_statuses_repeat('json');
1766 self::assertStatus($result['status']);
1770 * Test the api_statuses_destroy() function.
1774 public function testApiStatusesDestroy()
1776 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1777 api_statuses_destroy('json');
1781 * Test the api_statuses_destroy() function without an authenticated user.
1785 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1787 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1788 BasicAuth::setCurrentUserID();
1789 $_SESSION['authenticated'] = false;
1790 api_statuses_destroy('json');
1794 * Test the api_statuses_destroy() function with an ID.
1798 public function testApiStatusesDestroyWithId()
1800 DI::args()->setArgv(['', '', '', 1]);
1801 $result = api_statuses_destroy('json');
1802 self::assertStatus($result['status']);
1806 * Test the api_statuses_mentions() function.
1810 public function testApiStatusesMentions()
1812 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1813 $_REQUEST['max_id'] = 10;
1814 $result = api_statuses_mentions('json');
1815 self::assertEmpty($result['status']);
1816 // We should test with mentions in the database.
1820 * Test the api_statuses_mentions() function with a negative page parameter.
1824 public function testApiStatusesMentionsWithNegativePage()
1826 $_REQUEST['page'] = -2;
1827 $result = api_statuses_mentions('json');
1828 self::assertEmpty($result['status']);
1832 * Test the api_statuses_mentions() function with an unallowed user.
1836 public function testApiStatusesMentionsWithUnallowedUser()
1838 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1839 $_SESSION['allow_api'] = false;
1840 $_GET['screen_name'] = $this->selfUser['nick'];
1841 BasicAuth::setCurrentUserID();
1842 api_statuses_mentions('json');
1846 * Test the api_statuses_mentions() function with an RSS result.
1850 public function testApiStatusesMentionsWithRss()
1852 $result = api_statuses_mentions('rss');
1853 self::assertXml($result, 'statuses');
1857 * Test the api_statuses_user_timeline() function.
1861 public function testApiStatusesUserTimeline()
1863 $_REQUEST['max_id'] = 10;
1864 $_REQUEST['exclude_replies'] = true;
1865 $_REQUEST['conversation_id'] = 1;
1866 $result = api_statuses_user_timeline('json');
1867 self::assertNotEmpty($result['status']);
1868 foreach ($result['status'] as $status) {
1869 self::assertStatus($status);
1874 * Test the api_statuses_user_timeline() function with a negative page parameter.
1878 public function testApiStatusesUserTimelineWithNegativePage()
1880 $_REQUEST['page'] = -2;
1881 $result = api_statuses_user_timeline('json');
1882 self::assertNotEmpty($result['status']);
1883 foreach ($result['status'] as $status) {
1884 self::assertStatus($status);
1889 * Test the api_statuses_user_timeline() function with an RSS result.
1893 public function testApiStatusesUserTimelineWithRss()
1895 $result = api_statuses_user_timeline('rss');
1896 self::assertXml($result, 'statuses');
1900 * Test the api_statuses_user_timeline() function with an unallowed user.
1904 public function testApiStatusesUserTimelineWithUnallowedUser()
1906 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1907 $_SESSION['allow_api'] = false;
1908 $_GET['screen_name'] = $this->selfUser['nick'];
1909 BasicAuth::setCurrentUserID();
1910 api_statuses_user_timeline('json');
1914 * Test the api_favorites_create_destroy() function.
1918 public function testApiFavoritesCreateDestroy()
1920 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1921 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1922 api_favorites_create_destroy('json');
1926 * Test the api_favorites_create_destroy() function with an invalid ID.
1930 public function testApiFavoritesCreateDestroyWithInvalidId()
1932 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1933 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1934 api_favorites_create_destroy('json');
1938 * Test the api_favorites_create_destroy() function with an invalid action.
1942 public function testApiFavoritesCreateDestroyWithInvalidAction()
1944 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1945 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1946 $_REQUEST['id'] = 1;
1947 api_favorites_create_destroy('json');
1951 * Test the api_favorites_create_destroy() function with the create action.
1955 public function testApiFavoritesCreateDestroyWithCreateAction()
1957 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1958 $_REQUEST['id'] = 3;
1959 $result = api_favorites_create_destroy('json');
1960 self::assertStatus($result['status']);
1964 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1968 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1970 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1971 $_REQUEST['id'] = 3;
1972 $result = api_favorites_create_destroy('rss');
1973 self::assertXml($result, 'status');
1977 * Test the api_favorites_create_destroy() function with the destroy action.
1981 public function testApiFavoritesCreateDestroyWithDestroyAction()
1983 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1984 $_REQUEST['id'] = 3;
1985 $result = api_favorites_create_destroy('json');
1986 self::assertStatus($result['status']);
1990 * Test the api_favorites_create_destroy() function without an authenticated user.
1994 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1996 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1997 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1998 BasicAuth::setCurrentUserID();
1999 $_SESSION['authenticated'] = false;
2000 api_favorites_create_destroy('json');
2004 * Test the api_favorites() function.
2008 public function testApiFavorites()
2010 $_REQUEST['page'] = -1;
2011 $_REQUEST['max_id'] = 10;
2012 $result = api_favorites('json');
2013 foreach ($result['status'] as $status) {
2014 self::assertStatus($status);
2019 * Test the api_favorites() function with an RSS result.
2023 public function testApiFavoritesWithRss()
2025 $result = api_favorites('rss');
2026 self::assertXml($result, 'statuses');
2030 * Test the api_favorites() function with an unallowed user.
2034 public function testApiFavoritesWithUnallowedUser()
2036 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2037 $_SESSION['allow_api'] = false;
2038 $_GET['screen_name'] = $this->selfUser['nick'];
2039 BasicAuth::setCurrentUserID();
2040 api_favorites('json');
2044 * Test the api_format_messages() function.
2048 public function testApiFormatMessages()
2050 $result = api_format_messages(
2051 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2052 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2053 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2055 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2056 self::assertEquals(1, $result['id']);
2057 self::assertEquals(2, $result['recipient_id']);
2058 self::assertEquals(3, $result['sender_id']);
2059 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2060 self::assertEquals('sender_name', $result['sender_screen_name']);
2064 * Test the api_format_messages() function with HTML.
2068 public function testApiFormatMessagesWithHtmlText()
2070 $_GET['getText'] = 'html';
2071 $result = api_format_messages(
2072 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2073 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2074 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2076 self::assertEquals('item_title', $result['title']);
2077 self::assertEquals('<strong>item_body</strong>', $result['text']);
2081 * Test the api_format_messages() function with plain text.
2085 public function testApiFormatMessagesWithPlainText()
2087 $_GET['getText'] = 'plain';
2088 $result = api_format_messages(
2089 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2090 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2091 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2093 self::assertEquals('item_title', $result['title']);
2094 self::assertEquals('item_body', $result['text']);
2098 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2102 public function testApiFormatMessagesWithoutUserObjects()
2104 $_GET['getUserObjects'] = 'false';
2105 $result = api_format_messages(
2106 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2107 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2108 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2110 self::assertTrue(!isset($result['sender']));
2111 self::assertTrue(!isset($result['recipient']));
2115 * Test the api_convert_item() function.
2119 public function testApiConvertItem()
2121 $result = api_convert_item(
2123 'network' => 'feed',
2124 'title' => 'item_title',
2126 // We need a long string to test that it is correctly cut
2127 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2128 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2129 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2130 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2131 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2132 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2133 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2134 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2135 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2136 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2137 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2138 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2139 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2140 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2141 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2142 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2143 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2144 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2145 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2146 'repellat officia illum quos impedit quam iste esse unde qui ' .
2147 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2148 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2149 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2150 'plink' => 'item_plink'
2153 self::assertStringStartsWith('item_title', $result['text']);
2154 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2158 * Test the api_convert_item() function with an empty item body.
2162 public function testApiConvertItemWithoutBody()
2164 $result = api_convert_item(
2166 'network' => 'feed',
2167 'title' => 'item_title',
2170 'plink' => 'item_plink'
2173 self::assertEquals("item_title", $result['text']);
2174 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2178 * Test the api_convert_item() function with the title in the body.
2182 public function testApiConvertItemWithTitleInBody()
2184 $result = api_convert_item(
2186 'title' => 'item_title',
2187 'body' => 'item_title item_body',
2191 self::assertEquals('item_title item_body', $result['text']);
2192 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2196 * Test the api_get_attachments() function.
2200 public function testApiGetAttachments()
2203 self::assertEmpty(api_get_attachments($body, 0));
2207 * Test the api_get_attachments() function with an img tag.
2211 public function testApiGetAttachmentsWithImage()
2213 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2214 self::assertIsArray(api_get_attachments($body, 0));
2218 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2222 public function testApiGetAttachmentsWithImageAndAndStatus()
2224 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2225 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2226 self::assertIsArray(api_get_attachments($body, 0));
2230 * Test the api_get_entitities() function.
2234 public function testApiGetEntitities()
2237 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2241 * Test the api_get_entitities() function with the include_entities parameter.
2245 public function testApiGetEntititiesWithIncludeEntities()
2247 $_REQUEST['include_entities'] = 'true';
2249 $result = api_get_entitities($text, 'bbcode', 0);
2250 self::assertIsArray($result['hashtags']);
2251 self::assertIsArray($result['symbols']);
2252 self::assertIsArray($result['urls']);
2253 self::assertIsArray($result['user_mentions']);
2257 * Test the api_format_items_embeded_images() function.
2261 public function testApiFormatItemsEmbededImages()
2264 'text ' . DI::baseUrl() . '/display/item_guid',
2265 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2270 * Test the api_contactlink_to_array() function.
2274 public function testApiContactlinkToArray()
2281 api_contactlink_to_array('text')
2286 * Test the api_contactlink_to_array() function with an URL.
2290 public function testApiContactlinkToArrayWithUrl()
2294 'name' => ['link_text'],
2297 api_contactlink_to_array('text <a href="url">link_text</a>')
2302 * Test the api_format_items_activities() function.
2306 public function testApiFormatItemsActivities()
2308 $item = ['uid' => 0, 'uri' => ''];
2309 $result = api_format_items_activities($item);
2310 self::assertArrayHasKey('like', $result);
2311 self::assertArrayHasKey('dislike', $result);
2312 self::assertArrayHasKey('attendyes', $result);
2313 self::assertArrayHasKey('attendno', $result);
2314 self::assertArrayHasKey('attendmaybe', $result);
2318 * Test the api_format_items_activities() function with an XML result.
2322 public function testApiFormatItemsActivitiesWithXml()
2324 $item = ['uid' => 0, 'uri' => ''];
2325 $result = api_format_items_activities($item, 'xml');
2326 self::assertArrayHasKey('friendica:like', $result);
2327 self::assertArrayHasKey('friendica:dislike', $result);
2328 self::assertArrayHasKey('friendica:attendyes', $result);
2329 self::assertArrayHasKey('friendica:attendno', $result);
2330 self::assertArrayHasKey('friendica:attendmaybe', $result);
2334 * Test the api_format_items() function.
2335 * @doesNotPerformAssertions
2337 public function testApiFormatItems()
2341 'item_network' => 'item_network',
2347 'author-network' => Protocol::DFRN,
2348 'author-link' => 'http://localhost/profile/othercontact',
2352 $result = api_format_items($items, ['id' => 0], true);
2353 foreach ($result as $status) {
2354 self::assertStatus($status);
2359 * Test the api_format_items() function with an XML result.
2360 * @doesNotPerformAssertions
2362 public function testApiFormatItemsWithXml()
2370 'author-network' => Protocol::DFRN,
2371 'author-link' => 'http://localhost/profile/othercontact',
2375 $result = api_format_items($items, ['id' => 0], true, 'xml');
2376 foreach ($result as $status) {
2377 self::assertStatus($status);
2382 * Test the api_lists_list() function.
2386 public function testApiListsList()
2388 $result = api_lists_list('json');
2389 self::assertEquals(['lists_list' => []], $result);
2393 * Test the api_lists_ownerships() function.
2397 public function testApiListsOwnerships()
2399 $result = api_lists_ownerships('json');
2400 foreach ($result['lists']['lists'] as $list) {
2401 self::assertList($list);
2406 * Test the api_lists_ownerships() function without an authenticated user.
2410 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2412 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2413 BasicAuth::setCurrentUserID();
2414 $_SESSION['authenticated'] = false;
2415 api_lists_ownerships('json');
2419 * Test the api_lists_statuses() function.
2423 public function testApiListsStatuses()
2425 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2426 api_lists_statuses('json');
2430 * Test the api_lists_statuses() function with a list ID.
2431 * @doesNotPerformAssertions
2433 public function testApiListsStatusesWithListId()
2435 $_REQUEST['list_id'] = 1;
2436 $_REQUEST['page'] = -1;
2437 $_REQUEST['max_id'] = 10;
2438 $result = api_lists_statuses('json');
2439 foreach ($result['status'] as $status) {
2440 self::assertStatus($status);
2445 * Test the api_lists_statuses() function with a list ID and a RSS result.
2449 public function testApiListsStatusesWithListIdAndRss()
2451 $_REQUEST['list_id'] = 1;
2452 $result = api_lists_statuses('rss');
2453 self::assertXml($result, 'statuses');
2457 * Test the api_lists_statuses() function with an unallowed user.
2461 public function testApiListsStatusesWithUnallowedUser()
2463 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2464 $_SESSION['allow_api'] = false;
2465 $_GET['screen_name'] = $this->selfUser['nick'];
2466 BasicAuth::setCurrentUserID();
2467 api_lists_statuses('json');
2471 * Test the api_statuses_f() function.
2475 public function testApiStatusesFWithFriends()
2478 $result = api_statuses_f('friends');
2479 self::assertArrayHasKey('user', $result);
2483 * Test the api_statuses_f() function.
2487 public function testApiStatusesFWithFollowers()
2489 $result = api_statuses_f('followers');
2490 self::assertArrayHasKey('user', $result);
2494 * Test the api_statuses_f() function.
2498 public function testApiStatusesFWithBlocks()
2500 $result = api_statuses_f('blocks');
2501 self::assertArrayHasKey('user', $result);
2505 * Test the api_statuses_f() function.
2509 public function testApiStatusesFWithIncoming()
2511 $result = api_statuses_f('incoming');
2512 self::assertArrayHasKey('user', $result);
2516 * Test the api_statuses_f() function an undefined cursor GET variable.
2520 public function testApiStatusesFWithUndefinedCursor()
2522 $_GET['cursor'] = 'undefined';
2523 self::assertFalse(api_statuses_f('friends'));
2527 * Test the api_statuses_friends() function.
2531 public function testApiStatusesFriends()
2533 $result = api_statuses_friends('json');
2534 self::assertArrayHasKey('user', $result);
2538 * Test the api_statuses_friends() function an undefined cursor GET variable.
2542 public function testApiStatusesFriendsWithUndefinedCursor()
2544 $_GET['cursor'] = 'undefined';
2545 self::assertFalse(api_statuses_friends('json'));
2549 * Test the api_statuses_followers() function.
2553 public function testApiStatusesFollowers()
2555 $result = api_statuses_followers('json');
2556 self::assertArrayHasKey('user', $result);
2560 * Test the api_statuses_followers() function an undefined cursor GET variable.
2564 public function testApiStatusesFollowersWithUndefinedCursor()
2566 $_GET['cursor'] = 'undefined';
2567 self::assertFalse(api_statuses_followers('json'));
2571 * Test the api_blocks_list() function.
2575 public function testApiBlocksList()
2577 $result = api_blocks_list('json');
2578 self::assertArrayHasKey('user', $result);
2582 * Test the api_blocks_list() function an undefined cursor GET variable.
2586 public function testApiBlocksListWithUndefinedCursor()
2588 $_GET['cursor'] = 'undefined';
2589 self::assertFalse(api_blocks_list('json'));
2593 * Test the api_friendships_incoming() function.
2597 public function testApiFriendshipsIncoming()
2599 $result = api_friendships_incoming('json');
2600 self::assertArrayHasKey('id', $result);
2604 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2608 public function testApiFriendshipsIncomingWithUndefinedCursor()
2610 $_GET['cursor'] = 'undefined';
2611 self::assertFalse(api_friendships_incoming('json'));
2615 * Test the api_statusnet_config() function.
2619 public function testApiStatusnetConfig()
2622 $result = api_statusnet_config('json');
2623 self::assertEquals('localhost', $result['config']['site']['server']);
2624 self::assertEquals('default', $result['config']['site']['theme']);
2625 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2626 self::assertTrue($result['config']['site']['fancy']);
2627 self::assertEquals('en', $result['config']['site']['language']);
2628 self::assertEquals('UTC', $result['config']['site']['timezone']);
2629 self::assertEquals(200000, $result['config']['site']['textlimit']);
2630 self::assertEquals('false', $result['config']['site']['private']);
2631 self::assertEquals('false', $result['config']['site']['ssl']);
2632 self::assertEquals(30, $result['config']['site']['shorturllength']);
2637 * Test the api_direct_messages_new() function.
2641 public function testApiDirectMessagesNew()
2643 $result = api_direct_messages_new('json');
2644 self::assertNull($result);
2648 * Test the api_direct_messages_new() function without an authenticated user.
2652 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2654 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2655 BasicAuth::setCurrentUserID();
2656 $_SESSION['authenticated'] = false;
2657 api_direct_messages_new('json');
2661 * Test the api_direct_messages_new() function with an user ID.
2665 public function testApiDirectMessagesNewWithUserId()
2667 $_POST['text'] = 'message_text';
2668 $_POST['user_id'] = $this->otherUser['id'];
2669 $result = api_direct_messages_new('json');
2670 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2674 * Test the api_direct_messages_new() function with a screen name.
2678 public function testApiDirectMessagesNewWithScreenName()
2680 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2681 $_POST['text'] = 'message_text';
2682 $_POST['screen_name'] = $this->friendUser['nick'];
2683 $result = api_direct_messages_new('json');
2684 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2685 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2686 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2690 * Test the api_direct_messages_new() function with a title.
2694 public function testApiDirectMessagesNewWithTitle()
2696 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2697 $_POST['text'] = 'message_text';
2698 $_POST['screen_name'] = $this->friendUser['nick'];
2699 $_REQUEST['title'] = 'message_title';
2700 $result = api_direct_messages_new('json');
2701 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2702 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2703 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2704 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2708 * Test the api_direct_messages_new() function with an RSS result.
2712 public function testApiDirectMessagesNewWithRss()
2714 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2715 $_POST['text'] = 'message_text';
2716 $_POST['screen_name'] = $this->friendUser['nick'];
2717 $result = api_direct_messages_new('rss');
2718 self::assertXml($result, 'direct-messages');
2722 * Test the api_direct_messages_destroy() function.
2726 public function testApiDirectMessagesDestroy()
2728 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2729 api_direct_messages_destroy('json');
2733 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2737 public function testApiDirectMessagesDestroyWithVerbose()
2739 $_GET['friendica_verbose'] = 'true';
2740 $result = api_direct_messages_destroy('json');
2744 'result' => 'error',
2745 'message' => 'message id or parenturi not specified'
2753 * Test the api_direct_messages_destroy() function without an authenticated user.
2757 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2759 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2760 BasicAuth::setCurrentUserID();
2761 $_SESSION['authenticated'] = false;
2762 api_direct_messages_destroy('json');
2766 * Test the api_direct_messages_destroy() function with a non-zero ID.
2770 public function testApiDirectMessagesDestroyWithId()
2772 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2773 $_REQUEST['id'] = 1;
2774 api_direct_messages_destroy('json');
2778 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2782 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2784 $_REQUEST['id'] = 1;
2785 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2786 $_GET['friendica_verbose'] = 'true';
2787 $result = api_direct_messages_destroy('json');
2791 'result' => 'error',
2792 'message' => 'message id not in database'
2800 * Test the api_direct_messages_destroy() function with a non-zero ID.
2804 public function testApiDirectMessagesDestroyWithCorrectId()
2806 $this->markTestIncomplete('We need to add a dataset for this.');
2810 * Test the api_direct_messages_box() function.
2814 public function testApiDirectMessagesBoxWithSentbox()
2816 $_REQUEST['page'] = -1;
2817 $_REQUEST['max_id'] = 10;
2818 $result = api_direct_messages_box('json', 'sentbox', 'false');
2819 self::assertArrayHasKey('direct_message', $result);
2823 * Test the api_direct_messages_box() function.
2827 public function testApiDirectMessagesBoxWithConversation()
2829 $result = api_direct_messages_box('json', 'conversation', 'false');
2830 self::assertArrayHasKey('direct_message', $result);
2834 * Test the api_direct_messages_box() function.
2838 public function testApiDirectMessagesBoxWithAll()
2840 $result = api_direct_messages_box('json', 'all', 'false');
2841 self::assertArrayHasKey('direct_message', $result);
2845 * Test the api_direct_messages_box() function.
2849 public function testApiDirectMessagesBoxWithInbox()
2851 $result = api_direct_messages_box('json', 'inbox', 'false');
2852 self::assertArrayHasKey('direct_message', $result);
2856 * Test the api_direct_messages_box() function.
2860 public function testApiDirectMessagesBoxWithVerbose()
2862 $result = api_direct_messages_box('json', 'sentbox', 'true');
2866 'result' => 'error',
2867 'message' => 'no mails available'
2875 * Test the api_direct_messages_box() function with a RSS result.
2879 public function testApiDirectMessagesBoxWithRss()
2881 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2882 self::assertXml($result, 'direct-messages');
2886 * Test the api_direct_messages_box() function without an authenticated user.
2890 public function testApiDirectMessagesBoxWithUnallowedUser()
2892 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2893 $_SESSION['allow_api'] = false;
2894 $_GET['screen_name'] = $this->selfUser['nick'];
2895 BasicAuth::setCurrentUserID();
2896 api_direct_messages_box('json', 'sentbox', 'false');
2900 * Test the api_direct_messages_sentbox() function.
2904 public function testApiDirectMessagesSentbox()
2906 $result = api_direct_messages_sentbox('json');
2907 self::assertArrayHasKey('direct_message', $result);
2911 * Test the api_direct_messages_inbox() function.
2915 public function testApiDirectMessagesInbox()
2917 $result = api_direct_messages_inbox('json');
2918 self::assertArrayHasKey('direct_message', $result);
2922 * Test the api_direct_messages_all() function.
2926 public function testApiDirectMessagesAll()
2928 $result = api_direct_messages_all('json');
2929 self::assertArrayHasKey('direct_message', $result);
2933 * Test the api_direct_messages_conversation() function.
2937 public function testApiDirectMessagesConversation()
2939 $result = api_direct_messages_conversation('json');
2940 self::assertArrayHasKey('direct_message', $result);
2944 * Test the api_oauth_request_token() function.
2948 public function testApiOauthRequestToken()
2950 $this->markTestIncomplete('exit() kills phpunit as well');
2954 * Test the api_oauth_access_token() function.
2958 public function testApiOauthAccessToken()
2960 $this->markTestIncomplete('exit() kills phpunit as well');
2964 * Test the api_fr_photos_list() function.
2968 public function testApiFrPhotosList()
2970 $result = api_fr_photos_list('json');
2971 self::assertArrayHasKey('photo', $result);
2975 * Test the api_fr_photos_list() function without an authenticated user.
2979 public function testApiFrPhotosListWithoutAuthenticatedUser()
2981 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2982 BasicAuth::setCurrentUserID();
2983 $_SESSION['authenticated'] = false;
2984 api_fr_photos_list('json');
2988 * Test the api_fr_photo_create_update() function.
2990 public function testApiFrPhotoCreateUpdate()
2992 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2993 api_fr_photo_create_update('json');
2997 * Test the api_fr_photo_create_update() function without an authenticated user.
3001 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3003 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3004 BasicAuth::setCurrentUserID();
3005 $_SESSION['authenticated'] = false;
3006 api_fr_photo_create_update('json');
3010 * Test the api_fr_photo_create_update() function with an album name.
3014 public function testApiFrPhotoCreateUpdateWithAlbum()
3016 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3017 $_REQUEST['album'] = 'album_name';
3018 api_fr_photo_create_update('json');
3022 * Test the api_fr_photo_create_update() function with the update mode.
3026 public function testApiFrPhotoCreateUpdateWithUpdate()
3028 $this->markTestIncomplete('We need to create a dataset for this');
3032 * Test the api_fr_photo_create_update() function with an uploaded file.
3036 public function testApiFrPhotoCreateUpdateWithFile()
3038 $this->markTestIncomplete();
3042 * Test the api_fr_photo_detail() function.
3046 public function testApiFrPhotoDetail()
3048 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3049 api_fr_photo_detail('json');
3053 * Test the api_fr_photo_detail() function without an authenticated user.
3057 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3059 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3060 BasicAuth::setCurrentUserID();
3061 $_SESSION['authenticated'] = false;
3062 api_fr_photo_detail('json');
3066 * Test the api_fr_photo_detail() function with a photo ID.
3070 public function testApiFrPhotoDetailWithPhotoId()
3072 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3073 $_REQUEST['photo_id'] = 1;
3074 api_fr_photo_detail('json');
3078 * Test the api_fr_photo_detail() function with a correct photo ID.
3082 public function testApiFrPhotoDetailCorrectPhotoId()
3084 $this->markTestIncomplete('We need to create a dataset for this.');
3088 * Test the api_account_update_profile_image() function.
3092 public function testApiAccountUpdateProfileImage()
3094 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3095 api_account_update_profile_image('json');
3099 * Test the api_account_update_profile_image() function without an authenticated user.
3103 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3105 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3106 BasicAuth::setCurrentUserID();
3107 $_SESSION['authenticated'] = false;
3108 api_account_update_profile_image('json');
3112 * Test the api_account_update_profile_image() function with an uploaded file.
3116 public function testApiAccountUpdateProfileImageWithUpload()
3118 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3119 $this->markTestIncomplete();
3124 * Test the api_account_update_profile() function.
3128 public function testApiAccountUpdateProfile()
3130 $_POST['name'] = 'new_name';
3131 $_POST['description'] = 'new_description';
3132 $result = api_account_update_profile('json');
3133 // We can't use assertSelfUser() here because the user object is missing some properties.
3134 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3135 self::assertEquals('DFRN', $result['user']['location']);
3136 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3137 self::assertEquals('dfrn', $result['user']['network']);
3138 self::assertEquals('new_name', $result['user']['name']);
3139 self::assertEquals('new_description', $result['user']['description']);
3143 * Test the check_acl_input() function.
3147 public function testCheckAclInput()
3149 $result = check_acl_input('<aclstring>');
3150 // Where does this result come from?
3151 self::assertEquals(1, $result);
3155 * Test the check_acl_input() function with an empty ACL string.
3159 public function testCheckAclInputWithEmptyAclString()
3161 $result = check_acl_input(' ');
3162 self::assertFalse($result);
3166 * Test the save_media_to_database() function.
3170 public function testSaveMediaToDatabase()
3172 $this->markTestIncomplete();
3176 * Test the post_photo_item() function.
3180 public function testPostPhotoItem()
3182 $this->markTestIncomplete();
3186 * Test the prepare_photo_data() function.
3190 public function testPreparePhotoData()
3192 $this->markTestIncomplete();
3196 * Test the api_share_as_retweet() function with a valid item.
3200 public function testApiShareAsRetweetWithValidItem()
3202 $this->markTestIncomplete();
3206 * Test the api_in_reply_to() function.
3210 public function testApiInReplyTo()
3212 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3213 self::assertArrayHasKey('status_id', $result);
3214 self::assertArrayHasKey('user_id', $result);
3215 self::assertArrayHasKey('status_id_str', $result);
3216 self::assertArrayHasKey('user_id_str', $result);
3217 self::assertArrayHasKey('screen_name', $result);
3221 * Test the api_in_reply_to() function with a valid item.
3225 public function testApiInReplyToWithValidItem()
3227 $this->markTestIncomplete();
3231 * Test the api_clean_plain_items() function.
3235 public function testApiCleanPlainItems()
3237 $_REQUEST['include_entities'] = 'true';
3238 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3239 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3243 * Test the api_best_nickname() function.
3247 public function testApiBestNickname()
3250 $result = api_best_nickname($contacts);
3251 self::assertNull($result);
3255 * Test the api_best_nickname() function with contacts.
3259 public function testApiBestNicknameWithContacts()
3261 $this->markTestIncomplete();
3265 * Test the api_friendica_group_show() function.
3269 public function testApiFriendicaGroupShow()
3271 $this->markTestIncomplete();
3275 * Test the api_friendica_group_delete() function.
3279 public function testApiFriendicaGroupDelete()
3281 $this->markTestIncomplete();
3285 * Test the api_lists_destroy() function.
3289 public function testApiListsDestroy()
3291 $this->markTestIncomplete();
3295 * Test the group_create() function.
3299 public function testGroupCreate()
3301 $this->markTestIncomplete();
3305 * Test the api_friendica_group_create() function.
3309 public function testApiFriendicaGroupCreate()
3311 $this->markTestIncomplete();
3315 * Test the api_lists_create() function.
3319 public function testApiListsCreate()
3321 $this->markTestIncomplete();
3325 * Test the api_friendica_group_update() function.
3329 public function testApiFriendicaGroupUpdate()
3331 $this->markTestIncomplete();
3335 * Test the api_lists_update() function.
3339 public function testApiListsUpdate()
3341 $this->markTestIncomplete();
3345 * Test the api_friendica_activity() function.
3349 public function testApiFriendicaActivity()
3351 $this->markTestIncomplete();
3355 * Test the api_friendica_notification_seen() function.
3359 public function testApiFriendicaNotificationSeen()
3361 $this->markTestIncomplete();
3365 * Test the api_friendica_direct_messages_setseen() function.
3369 public function testApiFriendicaDirectMessagesSetseen()
3371 $this->markTestIncomplete();
3375 * Test the api_friendica_direct_messages_search() function.
3379 public function testApiFriendicaDirectMessagesSearch()
3381 $this->markTestIncomplete();