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'], BaseApi::getCurrentUserID());
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 // api_get_user() with empty parameters is not used anymore
716 $_SERVER['PHP_AUTH_USER'] = 'Test user';
717 $_SERVER['PHP_AUTH_PW'] = 'password';
718 $_SESSION['allow_api'] = false;
719 BasicAuth::setCurrentUserID();
720 self::assertFalse(api_get_user());
725 * Test the api_get_user() function with an user ID in a GET parameter.
729 public function testApiGetUserWithGetId()
731 // $_GET['user_id'] = $this->otherUser['id'];
732 // self::assertOtherUser(api_get_user());
736 * Test the api_get_user() function with a wrong user ID in a GET parameter.
740 public function testApiGetUserWithWrongGetId()
742 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
743 // $_GET['user_id'] = $this->wrongUserId;
744 // self::assertOtherUser(api_get_user());
748 * Test the api_get_user() function with an user name in a GET parameter.
752 public function testApiGetUserWithGetName()
754 // $_GET['screen_name'] = $this->selfUser['nick'];
755 // self::assertSelfUser(api_get_user());
759 * Test the api_get_user() function with a profile URL in a GET parameter.
763 public function testApiGetUserWithGetUrl()
765 // $_GET['profileurl'] = $this->selfUser['nurl'];
766 // self::assertSelfUser(api_get_user());
770 * Test the api_get_user() function with an user ID in the API path.
774 public function testApiGetUserWithNumericCalledApi()
776 // global $called_api;
777 // $called_api = ['api_path'];
778 // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
779 // self::assertOtherUser(api_get_user());
783 * Test the api_get_user() function with the $called_api global variable.
787 public function testApiGetUserWithCalledApi()
789 // global $called_api;
790 // $called_api = ['api', 'api_path'];
791 // self::assertSelfUser(api_get_user());
795 * Test the api_get_user() function with a valid user.
799 public function testApiGetUserWithCorrectUser()
801 self::assertOtherUser(api_get_user($this->otherUser['id']));
805 * Test the api_get_user() function with a wrong user ID.
809 public function testApiGetUserWithWrongUser()
811 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
812 self::assertOtherUser(api_get_user($this->wrongUserId));
816 * Test the api_get_user() function with a 0 user ID.
820 public function testApiGetUserWithZeroUser()
822 self::assertSelfUser(api_get_user(0));
826 * Test the api_item_get_user() function.
830 public function testApiItemGetUser()
832 $users = api_item_get_user($this->app, []);
833 self::assertSelfUser($users[0]);
837 * Test the api_item_get_user() function with a different item parent.
841 public function testApiItemGetUserWithDifferentParent()
843 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
844 self::assertSelfUser($users[0]);
845 self::assertEquals($users[0], $users[1]);
849 * Test the Arrays::walkRecursive() function.
853 public function testApiWalkRecursive()
858 Arrays::walkRecursive(
861 // Should we test this with a callback that actually does something?
869 * Test the Arrays::walkRecursive() function with an array.
873 public function testApiWalkRecursiveWithArray()
875 $array = [['item1'], ['item2']];
878 Arrays::walkRecursive(
881 // Should we test this with a callback that actually does something?
889 * Test the BaseApi::reformatXML() function.
893 public function testApiReformatXml()
897 self::assertTrue(ApiResponse::reformatXML($item, $key));
898 self::assertEquals('true', $item);
902 * Test the BaseApi::reformatXML() function with a statusnet_api key.
906 public function testApiReformatXmlWithStatusnetKey()
909 $key = 'statusnet_api';
910 self::assertTrue(ApiResponse::reformatXML($item, $key));
911 self::assertEquals('statusnet:api', $key);
915 * Test the BaseApi::reformatXML() function with a friendica_api key.
919 public function testApiReformatXmlWithFriendicaKey()
922 $key = 'friendica_api';
923 self::assertTrue(ApiResponse::reformatXML($item, $key));
924 self::assertEquals('friendica:api', $key);
928 * Test the BaseApi::createXML() function.
932 public function testApiCreateXml()
935 '<?xml version="1.0"?>' . "\n" .
936 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
937 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
938 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
939 ' <data>some_data</data>' . "\n" .
940 '</root_element>' . "\n",
941 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
946 * Test the BaseApi::createXML() function without any XML namespace.
950 public function testApiCreateXmlWithoutNamespaces()
953 '<?xml version="1.0"?>' . "\n" .
955 ' <data>some_data</data>' . "\n" .
957 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
962 * Test the BaseApi::formatData() function.
966 public function testApiFormatData()
968 $data = ['some_data'];
969 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
973 * Test the BaseApi::formatData() function with an XML result.
977 public function testApiFormatDataWithXml()
980 '<?xml version="1.0"?>' . "\n" .
981 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
982 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
983 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
984 ' <data>some_data</data>' . "\n" .
985 '</root_element>' . "\n",
986 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
991 * Test the api_account_verify_credentials() function.
995 public function testApiAccountVerifyCredentials()
997 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1001 * Test the api_account_verify_credentials() function without an authenticated user.
1005 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1007 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1008 BasicAuth::setCurrentUserID();
1009 $_SESSION['authenticated'] = false;
1010 api_account_verify_credentials('json');
1014 * Test the requestdata() function.
1018 public function testRequestdata()
1020 self::assertNull(requestdata('variable_name'));
1024 * Test the requestdata() function with a POST parameter.
1028 public function testRequestdataWithPost()
1030 $_POST['variable_name'] = 'variable_value';
1031 self::assertEquals('variable_value', requestdata('variable_name'));
1035 * Test the requestdata() function with a GET parameter.
1039 public function testRequestdataWithGet()
1041 $_GET['variable_name'] = 'variable_value';
1042 self::assertEquals('variable_value', requestdata('variable_name'));
1046 * Test the api_statuses_mediap() function.
1050 public function testApiStatusesMediap()
1052 DI::args()->setArgc(2);
1060 'tmp_name' => $this->getTempImage(),
1061 'name' => 'spacer.png',
1062 'type' => 'image/png'
1065 $_GET['status'] = '<b>Status content</b>';
1067 $result = api_statuses_mediap('json');
1068 self::assertStatus($result['status']);
1072 * Test the api_statuses_mediap() function without an authenticated user.
1076 public function testApiStatusesMediapWithoutAuthenticatedUser()
1078 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1079 BasicAuth::setCurrentUserID();
1080 $_SESSION['authenticated'] = false;
1081 api_statuses_mediap('json');
1085 * Test the api_statuses_update() function.
1089 public function testApiStatusesUpdate()
1091 $_GET['status'] = 'Status content #friendica';
1092 $_GET['in_reply_to_status_id'] = -1;
1101 'tmp_name' => $this->getTempImage(),
1102 'name' => 'spacer.png',
1103 'type' => 'image/png'
1107 $result = api_statuses_update('json');
1108 self::assertStatus($result['status']);
1112 * Test the api_statuses_update() function with an HTML status.
1116 public function testApiStatusesUpdateWithHtml()
1118 $_GET['htmlstatus'] = '<b>Status content</b>';
1120 $result = api_statuses_update('json');
1121 self::assertStatus($result['status']);
1125 * Test the api_statuses_update() function without an authenticated user.
1129 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1131 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1132 BasicAuth::setCurrentUserID();
1133 $_SESSION['authenticated'] = false;
1134 api_statuses_update('json');
1138 * Test the api_statuses_update() function with a parent status.
1142 public function testApiStatusesUpdateWithParent()
1144 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1148 * Test the api_statuses_update() function with a media_ids parameter.
1152 public function testApiStatusesUpdateWithMediaIds()
1154 $this->markTestIncomplete();
1158 * Test the api_statuses_update() function with the throttle limit reached.
1162 public function testApiStatusesUpdateWithDayThrottleReached()
1164 $this->markTestIncomplete();
1168 * Test the api_media_upload() function.
1169 * @runInSeparateProcess
1170 * @preserveGlobalState disabled
1172 public function testApiMediaUpload()
1174 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1179 * Test the api_media_upload() function without an authenticated user.
1183 public function testApiMediaUploadWithoutAuthenticatedUser()
1185 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1186 BasicAuth::setCurrentUserID();
1187 $_SESSION['authenticated'] = false;
1192 * Test the api_media_upload() function with an invalid uploaded media.
1196 public function testApiMediaUploadWithMedia()
1198 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1202 'tmp_name' => 'tmp_name'
1209 * Test the api_media_upload() function with an valid uploaded media.
1213 public function testApiMediaUploadWithValidMedia()
1221 'tmp_name' => $this->getTempImage(),
1222 'name' => 'spacer.png',
1223 'type' => 'image/png'
1227 DI::args()->setArgc(2);
1229 $result = api_media_upload();
1230 self::assertEquals('image/png', $result['media']['image']['image_type']);
1231 self::assertEquals(1, $result['media']['image']['w']);
1232 self::assertEquals(1, $result['media']['image']['h']);
1233 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1237 * Test the api_status_show() function.
1239 public function testApiStatusShowWithJson()
1241 $result = api_status_show('json', 1);
1242 self::assertStatus($result['status']);
1246 * Test the api_status_show() function with an XML result.
1248 public function testApiStatusShowWithXml()
1250 $result = api_status_show('xml', 1);
1251 self::assertXml($result, 'statuses');
1255 * Test the api_get_last_status() function
1257 public function testApiGetLastStatus()
1259 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1261 self::assertNotNull($item);
1265 * Test the api_users_show() function.
1269 public function testApiUsersShow()
1271 $result = api_users_show('json');
1272 // We can't use assertSelfUser() here because the user object is missing some properties.
1273 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1274 self::assertEquals('DFRN', $result['user']['location']);
1275 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1276 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1277 self::assertEquals('dfrn', $result['user']['network']);
1278 self::assertTrue($result['user']['verified']);
1282 * Test the api_users_show() function with an XML result.
1286 public function testApiUsersShowWithXml()
1288 $result = api_users_show('xml');
1289 self::assertXml($result, 'statuses');
1293 * Test the api_users_search() function.
1297 public function testApiUsersSearch()
1299 $_GET['q'] = 'othercontact';
1300 $result = api_users_search('json');
1301 self::assertOtherUser($result['users'][0]);
1305 * Test the api_users_search() function with an XML result.
1309 public function testApiUsersSearchWithXml()
1311 $_GET['q'] = 'othercontact';
1312 $result = api_users_search('xml');
1313 self::assertXml($result, 'users');
1317 * Test the api_users_search() function without a GET q parameter.
1321 public function testApiUsersSearchWithoutQuery()
1323 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1324 api_users_search('json');
1328 * Test the api_users_lookup() function.
1332 public function testApiUsersLookup()
1334 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1335 api_users_lookup('json');
1339 * Test the api_users_lookup() function with an user ID.
1343 public function testApiUsersLookupWithUserId()
1345 $_REQUEST['user_id'] = $this->otherUser['id'];
1346 $result = api_users_lookup('json');
1347 self::assertOtherUser($result['users'][0]);
1351 * Test the api_search() function.
1355 public function testApiSearch()
1357 $_REQUEST['q'] = 'reply';
1358 $_REQUEST['max_id'] = 10;
1359 $result = api_search('json');
1360 foreach ($result['status'] as $status) {
1361 self::assertStatus($status);
1362 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1367 * Test the api_search() function a count parameter.
1371 public function testApiSearchWithCount()
1373 $_REQUEST['q'] = 'reply';
1374 $_REQUEST['count'] = 20;
1375 $result = api_search('json');
1376 foreach ($result['status'] as $status) {
1377 self::assertStatus($status);
1378 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1383 * Test the api_search() function with an rpp parameter.
1387 public function testApiSearchWithRpp()
1389 $_REQUEST['q'] = 'reply';
1390 $_REQUEST['rpp'] = 20;
1391 $result = api_search('json');
1392 foreach ($result['status'] as $status) {
1393 self::assertStatus($status);
1394 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1399 * Test the api_search() function with an q parameter contains hashtag.
1400 * @doesNotPerformAssertions
1402 public function testApiSearchWithHashtag()
1404 $_REQUEST['q'] = '%23friendica';
1405 $result = api_search('json');
1406 foreach ($result['status'] as $status) {
1407 self::assertStatus($status);
1408 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1413 * Test the api_search() function with an exclude_replies parameter.
1414 * @doesNotPerformAssertions
1416 public function testApiSearchWithExcludeReplies()
1418 $_REQUEST['max_id'] = 10;
1419 $_REQUEST['exclude_replies'] = true;
1420 $_REQUEST['q'] = 'friendica';
1421 $result = api_search('json');
1422 foreach ($result['status'] as $status) {
1423 self::assertStatus($status);
1428 * Test the api_search() function without an authenticated user.
1432 public function testApiSearchWithUnallowedUser()
1434 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1435 $_SESSION['allow_api'] = false;
1436 $_GET['screen_name'] = $this->selfUser['nick'];
1437 BasicAuth::setCurrentUserID();
1442 * Test the api_search() function without any GET query parameter.
1446 public function testApiSearchWithoutQuery()
1448 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1453 * Test the api_statuses_home_timeline() function.
1457 public function testApiStatusesHomeTimeline()
1459 $_REQUEST['max_id'] = 10;
1460 $_REQUEST['exclude_replies'] = true;
1461 $_REQUEST['conversation_id'] = 1;
1462 $result = api_statuses_home_timeline('json');
1463 self::assertNotEmpty($result['status']);
1464 foreach ($result['status'] as $status) {
1465 self::assertStatus($status);
1470 * Test the api_statuses_home_timeline() function with a negative page parameter.
1474 public function testApiStatusesHomeTimelineWithNegativePage()
1476 $_REQUEST['page'] = -2;
1477 $result = api_statuses_home_timeline('json');
1478 self::assertNotEmpty($result['status']);
1479 foreach ($result['status'] as $status) {
1480 self::assertStatus($status);
1485 * Test the api_statuses_home_timeline() with an unallowed user.
1489 public function testApiStatusesHomeTimelineWithUnallowedUser()
1491 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1492 $_SESSION['allow_api'] = false;
1493 $_GET['screen_name'] = $this->selfUser['nick'];
1494 BasicAuth::setCurrentUserID();
1495 api_statuses_home_timeline('json');
1499 * Test the api_statuses_home_timeline() function with an RSS result.
1503 public function testApiStatusesHomeTimelineWithRss()
1505 $result = api_statuses_home_timeline('rss');
1506 self::assertXml($result, 'statuses');
1510 * Test the api_statuses_public_timeline() function.
1514 public function testApiStatusesPublicTimeline()
1516 $_REQUEST['max_id'] = 10;
1517 $_REQUEST['conversation_id'] = 1;
1518 $result = api_statuses_public_timeline('json');
1519 self::assertNotEmpty($result['status']);
1520 foreach ($result['status'] as $status) {
1521 self::assertStatus($status);
1526 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1530 public function testApiStatusesPublicTimelineWithExcludeReplies()
1532 $_REQUEST['max_id'] = 10;
1533 $_REQUEST['exclude_replies'] = true;
1534 $result = api_statuses_public_timeline('json');
1535 self::assertNotEmpty($result['status']);
1536 foreach ($result['status'] as $status) {
1537 self::assertStatus($status);
1542 * Test the api_statuses_public_timeline() function with a negative page parameter.
1546 public function testApiStatusesPublicTimelineWithNegativePage()
1548 $_REQUEST['page'] = -2;
1549 $result = api_statuses_public_timeline('json');
1550 self::assertNotEmpty($result['status']);
1551 foreach ($result['status'] as $status) {
1552 self::assertStatus($status);
1557 * Test the api_statuses_public_timeline() function with an unallowed user.
1561 public function testApiStatusesPublicTimelineWithUnallowedUser()
1563 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1564 $_SESSION['allow_api'] = false;
1565 $_GET['screen_name'] = $this->selfUser['nick'];
1566 BasicAuth::setCurrentUserID();
1567 api_statuses_public_timeline('json');
1571 * Test the api_statuses_public_timeline() function with an RSS result.
1575 public function testApiStatusesPublicTimelineWithRss()
1577 $result = api_statuses_public_timeline('rss');
1578 self::assertXml($result, 'statuses');
1582 * Test the api_statuses_networkpublic_timeline() function.
1586 public function testApiStatusesNetworkpublicTimeline()
1588 $_REQUEST['max_id'] = 10;
1589 $result = api_statuses_networkpublic_timeline('json');
1590 self::assertNotEmpty($result['status']);
1591 foreach ($result['status'] as $status) {
1592 self::assertStatus($status);
1597 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1601 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1603 $_REQUEST['page'] = -2;
1604 $result = api_statuses_networkpublic_timeline('json');
1605 self::assertNotEmpty($result['status']);
1606 foreach ($result['status'] as $status) {
1607 self::assertStatus($status);
1612 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1616 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1618 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1619 $_SESSION['allow_api'] = false;
1620 $_GET['screen_name'] = $this->selfUser['nick'];
1621 BasicAuth::setCurrentUserID();
1622 api_statuses_networkpublic_timeline('json');
1626 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1630 public function testApiStatusesNetworkpublicTimelineWithRss()
1632 $result = api_statuses_networkpublic_timeline('rss');
1633 self::assertXml($result, 'statuses');
1637 * Test the api_statuses_show() function.
1641 public function testApiStatusesShow()
1643 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1644 api_statuses_show('json');
1648 * Test the api_statuses_show() function with an ID.
1652 public function testApiStatusesShowWithId()
1654 DI::args()->setArgv(['', '', '', 1]);
1655 $result = api_statuses_show('json');
1656 self::assertStatus($result['status']);
1660 * Test the api_statuses_show() function with the conversation parameter.
1664 public function testApiStatusesShowWithConversation()
1666 DI::args()->setArgv(['', '', '', 1]);
1667 $_REQUEST['conversation'] = 1;
1668 $result = api_statuses_show('json');
1669 self::assertNotEmpty($result['status']);
1670 foreach ($result['status'] as $status) {
1671 self::assertStatus($status);
1676 * Test the api_statuses_show() function with an unallowed user.
1680 public function testApiStatusesShowWithUnallowedUser()
1682 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1683 $_SESSION['allow_api'] = false;
1684 $_GET['screen_name'] = $this->selfUser['nick'];
1685 BasicAuth::setCurrentUserID();
1686 api_statuses_show('json');
1690 * Test the api_conversation_show() function.
1694 public function testApiConversationShow()
1696 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1697 api_conversation_show('json');
1701 * Test the api_conversation_show() function with an ID.
1705 public function testApiConversationShowWithId()
1707 DI::args()->setArgv(['', '', '', 1]);
1708 $_REQUEST['max_id'] = 10;
1709 $_REQUEST['page'] = -2;
1710 $result = api_conversation_show('json');
1711 self::assertNotEmpty($result['status']);
1712 foreach ($result['status'] as $status) {
1713 self::assertStatus($status);
1718 * Test the api_conversation_show() function with an unallowed user.
1722 public function testApiConversationShowWithUnallowedUser()
1724 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1725 $_SESSION['allow_api'] = false;
1726 $_GET['screen_name'] = $this->selfUser['nick'];
1727 BasicAuth::setCurrentUserID();
1728 api_conversation_show('json');
1732 * Test the api_statuses_repeat() function.
1736 public function testApiStatusesRepeat()
1738 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1739 api_statuses_repeat('json');
1743 * Test the api_statuses_repeat() function without an authenticated user.
1747 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1749 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1750 BasicAuth::setCurrentUserID();
1751 $_SESSION['authenticated'] = false;
1752 api_statuses_repeat('json');
1756 * Test the api_statuses_repeat() function with an ID.
1760 public function testApiStatusesRepeatWithId()
1762 DI::args()->setArgv(['', '', '', 1]);
1763 $result = api_statuses_repeat('json');
1764 self::assertStatus($result['status']);
1766 // Also test with a shared status
1767 DI::args()->setArgv(['', '', '', 5]);
1768 $result = api_statuses_repeat('json');
1769 self::assertStatus($result['status']);
1773 * Test the api_statuses_destroy() function.
1777 public function testApiStatusesDestroy()
1779 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1780 api_statuses_destroy('json');
1784 * Test the api_statuses_destroy() function without an authenticated user.
1788 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1790 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1791 BasicAuth::setCurrentUserID();
1792 $_SESSION['authenticated'] = false;
1793 api_statuses_destroy('json');
1797 * Test the api_statuses_destroy() function with an ID.
1801 public function testApiStatusesDestroyWithId()
1803 DI::args()->setArgv(['', '', '', 1]);
1804 $result = api_statuses_destroy('json');
1805 self::assertStatus($result['status']);
1809 * Test the api_statuses_mentions() function.
1813 public function testApiStatusesMentions()
1815 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1816 $_REQUEST['max_id'] = 10;
1817 $result = api_statuses_mentions('json');
1818 self::assertEmpty($result['status']);
1819 // We should test with mentions in the database.
1823 * Test the api_statuses_mentions() function with a negative page parameter.
1827 public function testApiStatusesMentionsWithNegativePage()
1829 $_REQUEST['page'] = -2;
1830 $result = api_statuses_mentions('json');
1831 self::assertEmpty($result['status']);
1835 * Test the api_statuses_mentions() function with an unallowed user.
1839 public function testApiStatusesMentionsWithUnallowedUser()
1841 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1842 $_SESSION['allow_api'] = false;
1843 $_GET['screen_name'] = $this->selfUser['nick'];
1844 BasicAuth::setCurrentUserID();
1845 api_statuses_mentions('json');
1849 * Test the api_statuses_mentions() function with an RSS result.
1853 public function testApiStatusesMentionsWithRss()
1855 $result = api_statuses_mentions('rss');
1856 self::assertXml($result, 'statuses');
1860 * Test the api_statuses_user_timeline() function.
1864 public function testApiStatusesUserTimeline()
1866 $_REQUEST['max_id'] = 10;
1867 $_REQUEST['exclude_replies'] = true;
1868 $_REQUEST['conversation_id'] = 1;
1869 $result = api_statuses_user_timeline('json');
1870 self::assertNotEmpty($result['status']);
1871 foreach ($result['status'] as $status) {
1872 self::assertStatus($status);
1877 * Test the api_statuses_user_timeline() function with a negative page parameter.
1881 public function testApiStatusesUserTimelineWithNegativePage()
1883 $_REQUEST['page'] = -2;
1884 $result = api_statuses_user_timeline('json');
1885 self::assertNotEmpty($result['status']);
1886 foreach ($result['status'] as $status) {
1887 self::assertStatus($status);
1892 * Test the api_statuses_user_timeline() function with an RSS result.
1896 public function testApiStatusesUserTimelineWithRss()
1898 $result = api_statuses_user_timeline('rss');
1899 self::assertXml($result, 'statuses');
1903 * Test the api_statuses_user_timeline() function with an unallowed user.
1907 public function testApiStatusesUserTimelineWithUnallowedUser()
1909 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1910 $_SESSION['allow_api'] = false;
1911 $_GET['screen_name'] = $this->selfUser['nick'];
1912 BasicAuth::setCurrentUserID();
1913 api_statuses_user_timeline('json');
1917 * Test the api_favorites_create_destroy() function.
1921 public function testApiFavoritesCreateDestroy()
1923 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1924 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1925 api_favorites_create_destroy('json');
1929 * Test the api_favorites_create_destroy() function with an invalid ID.
1933 public function testApiFavoritesCreateDestroyWithInvalidId()
1935 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1936 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1937 api_favorites_create_destroy('json');
1941 * Test the api_favorites_create_destroy() function with an invalid action.
1945 public function testApiFavoritesCreateDestroyWithInvalidAction()
1947 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1948 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1949 $_REQUEST['id'] = 1;
1950 api_favorites_create_destroy('json');
1954 * Test the api_favorites_create_destroy() function with the create action.
1958 public function testApiFavoritesCreateDestroyWithCreateAction()
1960 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1961 $_REQUEST['id'] = 3;
1962 $result = api_favorites_create_destroy('json');
1963 self::assertStatus($result['status']);
1967 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1971 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1973 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1974 $_REQUEST['id'] = 3;
1975 $result = api_favorites_create_destroy('rss');
1976 self::assertXml($result, 'status');
1980 * Test the api_favorites_create_destroy() function with the destroy action.
1984 public function testApiFavoritesCreateDestroyWithDestroyAction()
1986 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1987 $_REQUEST['id'] = 3;
1988 $result = api_favorites_create_destroy('json');
1989 self::assertStatus($result['status']);
1993 * Test the api_favorites_create_destroy() function without an authenticated user.
1997 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1999 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2000 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2001 BasicAuth::setCurrentUserID();
2002 $_SESSION['authenticated'] = false;
2003 api_favorites_create_destroy('json');
2007 * Test the api_favorites() function.
2011 public function testApiFavorites()
2013 $_REQUEST['page'] = -1;
2014 $_REQUEST['max_id'] = 10;
2015 $result = api_favorites('json');
2016 foreach ($result['status'] as $status) {
2017 self::assertStatus($status);
2022 * Test the api_favorites() function with an RSS result.
2026 public function testApiFavoritesWithRss()
2028 $result = api_favorites('rss');
2029 self::assertXml($result, 'statuses');
2033 * Test the api_favorites() function with an unallowed user.
2037 public function testApiFavoritesWithUnallowedUser()
2039 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2040 $_SESSION['allow_api'] = false;
2041 $_GET['screen_name'] = $this->selfUser['nick'];
2042 BasicAuth::setCurrentUserID();
2043 api_favorites('json');
2047 * Test the api_format_messages() function.
2051 public function testApiFormatMessages()
2053 $result = api_format_messages(
2054 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2055 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2056 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2058 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2059 self::assertEquals(1, $result['id']);
2060 self::assertEquals(2, $result['recipient_id']);
2061 self::assertEquals(3, $result['sender_id']);
2062 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2063 self::assertEquals('sender_name', $result['sender_screen_name']);
2067 * Test the api_format_messages() function with HTML.
2071 public function testApiFormatMessagesWithHtmlText()
2073 $_GET['getText'] = 'html';
2074 $result = api_format_messages(
2075 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2076 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2077 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2079 self::assertEquals('item_title', $result['title']);
2080 self::assertEquals('<strong>item_body</strong>', $result['text']);
2084 * Test the api_format_messages() function with plain text.
2088 public function testApiFormatMessagesWithPlainText()
2090 $_GET['getText'] = 'plain';
2091 $result = api_format_messages(
2092 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2093 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2094 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2096 self::assertEquals('item_title', $result['title']);
2097 self::assertEquals('item_body', $result['text']);
2101 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2105 public function testApiFormatMessagesWithoutUserObjects()
2107 $_GET['getUserObjects'] = 'false';
2108 $result = api_format_messages(
2109 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2110 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2111 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2113 self::assertTrue(!isset($result['sender']));
2114 self::assertTrue(!isset($result['recipient']));
2118 * Test the api_convert_item() function.
2122 public function testApiConvertItem()
2124 $result = api_convert_item(
2126 'network' => 'feed',
2127 'title' => 'item_title',
2129 // We need a long string to test that it is correctly cut
2130 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2131 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2132 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2133 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2134 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2135 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2136 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2137 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2138 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2139 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2140 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2141 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2142 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2143 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2144 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2145 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2146 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2147 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2148 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2149 'repellat officia illum quos impedit quam iste esse unde qui ' .
2150 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2151 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2152 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2153 'plink' => 'item_plink'
2156 self::assertStringStartsWith('item_title', $result['text']);
2157 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2161 * Test the api_convert_item() function with an empty item body.
2165 public function testApiConvertItemWithoutBody()
2167 $result = api_convert_item(
2169 'network' => 'feed',
2170 'title' => 'item_title',
2173 'plink' => 'item_plink'
2176 self::assertEquals("item_title", $result['text']);
2177 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2181 * Test the api_convert_item() function with the title in the body.
2185 public function testApiConvertItemWithTitleInBody()
2187 $result = api_convert_item(
2189 'title' => 'item_title',
2190 'body' => 'item_title item_body',
2194 self::assertEquals('item_title item_body', $result['text']);
2195 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2199 * Test the api_get_attachments() function.
2203 public function testApiGetAttachments()
2206 self::assertEmpty(api_get_attachments($body, 0));
2210 * Test the api_get_attachments() function with an img tag.
2214 public function testApiGetAttachmentsWithImage()
2216 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2217 self::assertIsArray(api_get_attachments($body, 0));
2221 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2225 public function testApiGetAttachmentsWithImageAndAndStatus()
2227 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2228 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2229 self::assertIsArray(api_get_attachments($body, 0));
2233 * Test the api_get_entitities() function.
2237 public function testApiGetEntitities()
2240 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2244 * Test the api_get_entitities() function with the include_entities parameter.
2248 public function testApiGetEntititiesWithIncludeEntities()
2250 $_REQUEST['include_entities'] = 'true';
2252 $result = api_get_entitities($text, 'bbcode', 0);
2253 self::assertIsArray($result['hashtags']);
2254 self::assertIsArray($result['symbols']);
2255 self::assertIsArray($result['urls']);
2256 self::assertIsArray($result['user_mentions']);
2260 * Test the api_format_items_embeded_images() function.
2264 public function testApiFormatItemsEmbededImages()
2267 'text ' . DI::baseUrl() . '/display/item_guid',
2268 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2273 * Test the api_contactlink_to_array() function.
2277 public function testApiContactlinkToArray()
2284 api_contactlink_to_array('text')
2289 * Test the api_contactlink_to_array() function with an URL.
2293 public function testApiContactlinkToArrayWithUrl()
2297 'name' => ['link_text'],
2300 api_contactlink_to_array('text <a href="url">link_text</a>')
2305 * Test the api_format_items_activities() function.
2309 public function testApiFormatItemsActivities()
2311 $item = ['uid' => 0, 'uri' => ''];
2312 $result = api_format_items_activities($item);
2313 self::assertArrayHasKey('like', $result);
2314 self::assertArrayHasKey('dislike', $result);
2315 self::assertArrayHasKey('attendyes', $result);
2316 self::assertArrayHasKey('attendno', $result);
2317 self::assertArrayHasKey('attendmaybe', $result);
2321 * Test the api_format_items_activities() function with an XML result.
2325 public function testApiFormatItemsActivitiesWithXml()
2327 $item = ['uid' => 0, 'uri' => ''];
2328 $result = api_format_items_activities($item, 'xml');
2329 self::assertArrayHasKey('friendica:like', $result);
2330 self::assertArrayHasKey('friendica:dislike', $result);
2331 self::assertArrayHasKey('friendica:attendyes', $result);
2332 self::assertArrayHasKey('friendica:attendno', $result);
2333 self::assertArrayHasKey('friendica:attendmaybe', $result);
2337 * Test the api_format_items() function.
2338 * @doesNotPerformAssertions
2340 public function testApiFormatItems()
2344 'item_network' => 'item_network',
2350 'author-network' => Protocol::DFRN,
2351 'author-link' => 'http://localhost/profile/othercontact',
2355 $result = api_format_items($items, ['id' => 0], true);
2356 foreach ($result as $status) {
2357 self::assertStatus($status);
2362 * Test the api_format_items() function with an XML result.
2363 * @doesNotPerformAssertions
2365 public function testApiFormatItemsWithXml()
2373 'author-network' => Protocol::DFRN,
2374 'author-link' => 'http://localhost/profile/othercontact',
2378 $result = api_format_items($items, ['id' => 0], true, 'xml');
2379 foreach ($result as $status) {
2380 self::assertStatus($status);
2385 * Test the api_lists_list() function.
2389 public function testApiListsList()
2391 $result = api_lists_list('json');
2392 self::assertEquals(['lists_list' => []], $result);
2396 * Test the api_lists_ownerships() function.
2400 public function testApiListsOwnerships()
2402 $result = api_lists_ownerships('json');
2403 foreach ($result['lists']['lists'] as $list) {
2404 self::assertList($list);
2409 * Test the api_lists_ownerships() function without an authenticated user.
2413 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2415 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2416 BasicAuth::setCurrentUserID();
2417 $_SESSION['authenticated'] = false;
2418 api_lists_ownerships('json');
2422 * Test the api_lists_statuses() function.
2426 public function testApiListsStatuses()
2428 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2429 api_lists_statuses('json');
2433 * Test the api_lists_statuses() function with a list ID.
2434 * @doesNotPerformAssertions
2436 public function testApiListsStatusesWithListId()
2438 $_REQUEST['list_id'] = 1;
2439 $_REQUEST['page'] = -1;
2440 $_REQUEST['max_id'] = 10;
2441 $result = api_lists_statuses('json');
2442 foreach ($result['status'] as $status) {
2443 self::assertStatus($status);
2448 * Test the api_lists_statuses() function with a list ID and a RSS result.
2452 public function testApiListsStatusesWithListIdAndRss()
2454 $_REQUEST['list_id'] = 1;
2455 $result = api_lists_statuses('rss');
2456 self::assertXml($result, 'statuses');
2460 * Test the api_lists_statuses() function with an unallowed user.
2464 public function testApiListsStatusesWithUnallowedUser()
2466 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2467 $_SESSION['allow_api'] = false;
2468 $_GET['screen_name'] = $this->selfUser['nick'];
2469 BasicAuth::setCurrentUserID();
2470 api_lists_statuses('json');
2474 * Test the api_statuses_f() function.
2478 public function testApiStatusesFWithFriends()
2481 $result = api_statuses_f('friends');
2482 self::assertArrayHasKey('user', $result);
2486 * Test the api_statuses_f() function.
2490 public function testApiStatusesFWithFollowers()
2492 $result = api_statuses_f('followers');
2493 self::assertArrayHasKey('user', $result);
2497 * Test the api_statuses_f() function.
2501 public function testApiStatusesFWithBlocks()
2503 $result = api_statuses_f('blocks');
2504 self::assertArrayHasKey('user', $result);
2508 * Test the api_statuses_f() function.
2512 public function testApiStatusesFWithIncoming()
2514 $result = api_statuses_f('incoming');
2515 self::assertArrayHasKey('user', $result);
2519 * Test the api_statuses_f() function an undefined cursor GET variable.
2523 public function testApiStatusesFWithUndefinedCursor()
2525 $_GET['cursor'] = 'undefined';
2526 self::assertFalse(api_statuses_f('friends'));
2530 * Test the api_statuses_friends() function.
2534 public function testApiStatusesFriends()
2536 $result = api_statuses_friends('json');
2537 self::assertArrayHasKey('user', $result);
2541 * Test the api_statuses_friends() function an undefined cursor GET variable.
2545 public function testApiStatusesFriendsWithUndefinedCursor()
2547 $_GET['cursor'] = 'undefined';
2548 self::assertFalse(api_statuses_friends('json'));
2552 * Test the api_statuses_followers() function.
2556 public function testApiStatusesFollowers()
2558 $result = api_statuses_followers('json');
2559 self::assertArrayHasKey('user', $result);
2563 * Test the api_statuses_followers() function an undefined cursor GET variable.
2567 public function testApiStatusesFollowersWithUndefinedCursor()
2569 $_GET['cursor'] = 'undefined';
2570 self::assertFalse(api_statuses_followers('json'));
2574 * Test the api_blocks_list() function.
2578 public function testApiBlocksList()
2580 $result = api_blocks_list('json');
2581 self::assertArrayHasKey('user', $result);
2585 * Test the api_blocks_list() function an undefined cursor GET variable.
2589 public function testApiBlocksListWithUndefinedCursor()
2591 $_GET['cursor'] = 'undefined';
2592 self::assertFalse(api_blocks_list('json'));
2596 * Test the api_friendships_incoming() function.
2600 public function testApiFriendshipsIncoming()
2602 $result = api_friendships_incoming('json');
2603 self::assertArrayHasKey('id', $result);
2607 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2611 public function testApiFriendshipsIncomingWithUndefinedCursor()
2613 $_GET['cursor'] = 'undefined';
2614 self::assertFalse(api_friendships_incoming('json'));
2618 * Test the api_statusnet_config() function.
2622 public function testApiStatusnetConfig()
2625 $result = api_statusnet_config('json');
2626 self::assertEquals('localhost', $result['config']['site']['server']);
2627 self::assertEquals('default', $result['config']['site']['theme']);
2628 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2629 self::assertTrue($result['config']['site']['fancy']);
2630 self::assertEquals('en', $result['config']['site']['language']);
2631 self::assertEquals('UTC', $result['config']['site']['timezone']);
2632 self::assertEquals(200000, $result['config']['site']['textlimit']);
2633 self::assertEquals('false', $result['config']['site']['private']);
2634 self::assertEquals('false', $result['config']['site']['ssl']);
2635 self::assertEquals(30, $result['config']['site']['shorturllength']);
2640 * Test the api_direct_messages_new() function.
2644 public function testApiDirectMessagesNew()
2646 $result = api_direct_messages_new('json');
2647 self::assertNull($result);
2651 * Test the api_direct_messages_new() function without an authenticated user.
2655 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2657 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2658 BasicAuth::setCurrentUserID();
2659 $_SESSION['authenticated'] = false;
2660 api_direct_messages_new('json');
2664 * Test the api_direct_messages_new() function with an user ID.
2668 public function testApiDirectMessagesNewWithUserId()
2670 $_POST['text'] = 'message_text';
2671 $_POST['user_id'] = $this->otherUser['id'];
2672 $result = api_direct_messages_new('json');
2673 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2677 * Test the api_direct_messages_new() function with a screen name.
2681 public function testApiDirectMessagesNewWithScreenName()
2683 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2684 $_POST['text'] = 'message_text';
2685 $_POST['screen_name'] = $this->friendUser['nick'];
2686 $result = api_direct_messages_new('json');
2687 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2688 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2689 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2693 * Test the api_direct_messages_new() function with a title.
2697 public function testApiDirectMessagesNewWithTitle()
2699 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2700 $_POST['text'] = 'message_text';
2701 $_POST['screen_name'] = $this->friendUser['nick'];
2702 $_REQUEST['title'] = 'message_title';
2703 $result = api_direct_messages_new('json');
2704 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2705 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2706 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2707 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2711 * Test the api_direct_messages_new() function with an RSS result.
2715 public function testApiDirectMessagesNewWithRss()
2717 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2718 $_POST['text'] = 'message_text';
2719 $_POST['screen_name'] = $this->friendUser['nick'];
2720 $result = api_direct_messages_new('rss');
2721 self::assertXml($result, 'direct-messages');
2725 * Test the api_direct_messages_destroy() function.
2729 public function testApiDirectMessagesDestroy()
2731 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2732 api_direct_messages_destroy('json');
2736 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2740 public function testApiDirectMessagesDestroyWithVerbose()
2742 $_GET['friendica_verbose'] = 'true';
2743 $result = api_direct_messages_destroy('json');
2747 'result' => 'error',
2748 'message' => 'message id or parenturi not specified'
2756 * Test the api_direct_messages_destroy() function without an authenticated user.
2760 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2762 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2763 BasicAuth::setCurrentUserID();
2764 $_SESSION['authenticated'] = false;
2765 api_direct_messages_destroy('json');
2769 * Test the api_direct_messages_destroy() function with a non-zero ID.
2773 public function testApiDirectMessagesDestroyWithId()
2775 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2776 $_REQUEST['id'] = 1;
2777 api_direct_messages_destroy('json');
2781 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2785 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2787 $_REQUEST['id'] = 1;
2788 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2789 $_GET['friendica_verbose'] = 'true';
2790 $result = api_direct_messages_destroy('json');
2794 'result' => 'error',
2795 'message' => 'message id not in database'
2803 * Test the api_direct_messages_destroy() function with a non-zero ID.
2807 public function testApiDirectMessagesDestroyWithCorrectId()
2809 $this->markTestIncomplete('We need to add a dataset for this.');
2813 * Test the api_direct_messages_box() function.
2817 public function testApiDirectMessagesBoxWithSentbox()
2819 $_REQUEST['page'] = -1;
2820 $_REQUEST['max_id'] = 10;
2821 $result = api_direct_messages_box('json', 'sentbox', 'false');
2822 self::assertArrayHasKey('direct_message', $result);
2826 * Test the api_direct_messages_box() function.
2830 public function testApiDirectMessagesBoxWithConversation()
2832 $result = api_direct_messages_box('json', 'conversation', 'false');
2833 self::assertArrayHasKey('direct_message', $result);
2837 * Test the api_direct_messages_box() function.
2841 public function testApiDirectMessagesBoxWithAll()
2843 $result = api_direct_messages_box('json', 'all', 'false');
2844 self::assertArrayHasKey('direct_message', $result);
2848 * Test the api_direct_messages_box() function.
2852 public function testApiDirectMessagesBoxWithInbox()
2854 $result = api_direct_messages_box('json', 'inbox', 'false');
2855 self::assertArrayHasKey('direct_message', $result);
2859 * Test the api_direct_messages_box() function.
2863 public function testApiDirectMessagesBoxWithVerbose()
2865 $result = api_direct_messages_box('json', 'sentbox', 'true');
2869 'result' => 'error',
2870 'message' => 'no mails available'
2878 * Test the api_direct_messages_box() function with a RSS result.
2882 public function testApiDirectMessagesBoxWithRss()
2884 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2885 self::assertXml($result, 'direct-messages');
2889 * Test the api_direct_messages_box() function without an authenticated user.
2893 public function testApiDirectMessagesBoxWithUnallowedUser()
2895 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2896 $_SESSION['allow_api'] = false;
2897 $_GET['screen_name'] = $this->selfUser['nick'];
2898 BasicAuth::setCurrentUserID();
2899 api_direct_messages_box('json', 'sentbox', 'false');
2903 * Test the api_direct_messages_sentbox() function.
2907 public function testApiDirectMessagesSentbox()
2909 $result = api_direct_messages_sentbox('json');
2910 self::assertArrayHasKey('direct_message', $result);
2914 * Test the api_direct_messages_inbox() function.
2918 public function testApiDirectMessagesInbox()
2920 $result = api_direct_messages_inbox('json');
2921 self::assertArrayHasKey('direct_message', $result);
2925 * Test the api_direct_messages_all() function.
2929 public function testApiDirectMessagesAll()
2931 $result = api_direct_messages_all('json');
2932 self::assertArrayHasKey('direct_message', $result);
2936 * Test the api_direct_messages_conversation() function.
2940 public function testApiDirectMessagesConversation()
2942 $result = api_direct_messages_conversation('json');
2943 self::assertArrayHasKey('direct_message', $result);
2947 * Test the api_oauth_request_token() function.
2951 public function testApiOauthRequestToken()
2953 $this->markTestIncomplete('exit() kills phpunit as well');
2957 * Test the api_oauth_access_token() function.
2961 public function testApiOauthAccessToken()
2963 $this->markTestIncomplete('exit() kills phpunit as well');
2967 * Test the api_fr_photos_list() function.
2971 public function testApiFrPhotosList()
2973 $result = api_fr_photos_list('json');
2974 self::assertArrayHasKey('photo', $result);
2978 * Test the api_fr_photos_list() function without an authenticated user.
2982 public function testApiFrPhotosListWithoutAuthenticatedUser()
2984 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2985 BasicAuth::setCurrentUserID();
2986 $_SESSION['authenticated'] = false;
2987 api_fr_photos_list('json');
2991 * Test the api_fr_photo_create_update() function.
2993 public function testApiFrPhotoCreateUpdate()
2995 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2996 api_fr_photo_create_update('json');
3000 * Test the api_fr_photo_create_update() function without an authenticated user.
3004 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3006 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3007 BasicAuth::setCurrentUserID();
3008 $_SESSION['authenticated'] = false;
3009 api_fr_photo_create_update('json');
3013 * Test the api_fr_photo_create_update() function with an album name.
3017 public function testApiFrPhotoCreateUpdateWithAlbum()
3019 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3020 $_REQUEST['album'] = 'album_name';
3021 api_fr_photo_create_update('json');
3025 * Test the api_fr_photo_create_update() function with the update mode.
3029 public function testApiFrPhotoCreateUpdateWithUpdate()
3031 $this->markTestIncomplete('We need to create a dataset for this');
3035 * Test the api_fr_photo_create_update() function with an uploaded file.
3039 public function testApiFrPhotoCreateUpdateWithFile()
3041 $this->markTestIncomplete();
3045 * Test the api_fr_photo_detail() function.
3049 public function testApiFrPhotoDetail()
3051 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3052 api_fr_photo_detail('json');
3056 * Test the api_fr_photo_detail() function without an authenticated user.
3060 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3062 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3063 BasicAuth::setCurrentUserID();
3064 $_SESSION['authenticated'] = false;
3065 api_fr_photo_detail('json');
3069 * Test the api_fr_photo_detail() function with a photo ID.
3073 public function testApiFrPhotoDetailWithPhotoId()
3075 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3076 $_REQUEST['photo_id'] = 1;
3077 api_fr_photo_detail('json');
3081 * Test the api_fr_photo_detail() function with a correct photo ID.
3085 public function testApiFrPhotoDetailCorrectPhotoId()
3087 $this->markTestIncomplete('We need to create a dataset for this.');
3091 * Test the api_account_update_profile_image() function.
3095 public function testApiAccountUpdateProfileImage()
3097 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3098 api_account_update_profile_image('json');
3102 * Test the api_account_update_profile_image() function without an authenticated user.
3106 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3108 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3109 BasicAuth::setCurrentUserID();
3110 $_SESSION['authenticated'] = false;
3111 api_account_update_profile_image('json');
3115 * Test the api_account_update_profile_image() function with an uploaded file.
3119 public function testApiAccountUpdateProfileImageWithUpload()
3121 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3122 $this->markTestIncomplete();
3127 * Test the api_account_update_profile() function.
3131 public function testApiAccountUpdateProfile()
3133 $_POST['name'] = 'new_name';
3134 $_POST['description'] = 'new_description';
3135 $result = api_account_update_profile('json');
3136 // We can't use assertSelfUser() here because the user object is missing some properties.
3137 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3138 self::assertEquals('DFRN', $result['user']['location']);
3139 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3140 self::assertEquals('dfrn', $result['user']['network']);
3141 self::assertEquals('new_name', $result['user']['name']);
3142 self::assertEquals('new_description', $result['user']['description']);
3146 * Test the check_acl_input() function.
3150 public function testCheckAclInput()
3152 $result = check_acl_input('<aclstring>');
3153 // Where does this result come from?
3154 self::assertEquals(1, $result);
3158 * Test the check_acl_input() function with an empty ACL string.
3162 public function testCheckAclInputWithEmptyAclString()
3164 $result = check_acl_input(' ');
3165 self::assertFalse($result);
3169 * Test the save_media_to_database() function.
3173 public function testSaveMediaToDatabase()
3175 $this->markTestIncomplete();
3179 * Test the post_photo_item() function.
3183 public function testPostPhotoItem()
3185 $this->markTestIncomplete();
3189 * Test the prepare_photo_data() function.
3193 public function testPreparePhotoData()
3195 $this->markTestIncomplete();
3199 * Test the api_share_as_retweet() function with a valid item.
3203 public function testApiShareAsRetweetWithValidItem()
3205 $this->markTestIncomplete();
3209 * Test the api_in_reply_to() function.
3213 public function testApiInReplyTo()
3215 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3216 self::assertArrayHasKey('status_id', $result);
3217 self::assertArrayHasKey('user_id', $result);
3218 self::assertArrayHasKey('status_id_str', $result);
3219 self::assertArrayHasKey('user_id_str', $result);
3220 self::assertArrayHasKey('screen_name', $result);
3224 * Test the api_in_reply_to() function with a valid item.
3228 public function testApiInReplyToWithValidItem()
3230 $this->markTestIncomplete();
3234 * Test the api_clean_plain_items() function.
3238 public function testApiCleanPlainItems()
3240 $_REQUEST['include_entities'] = 'true';
3241 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3242 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3246 * Test the api_best_nickname() function.
3250 public function testApiBestNickname()
3253 $result = api_best_nickname($contacts);
3254 self::assertNull($result);
3258 * Test the api_best_nickname() function with contacts.
3262 public function testApiBestNicknameWithContacts()
3264 $this->markTestIncomplete();
3268 * Test the api_friendica_group_show() function.
3272 public function testApiFriendicaGroupShow()
3274 $this->markTestIncomplete();
3278 * Test the api_friendica_group_delete() function.
3282 public function testApiFriendicaGroupDelete()
3284 $this->markTestIncomplete();
3288 * Test the api_lists_destroy() function.
3292 public function testApiListsDestroy()
3294 $this->markTestIncomplete();
3298 * Test the group_create() function.
3302 public function testGroupCreate()
3304 $this->markTestIncomplete();
3308 * Test the api_friendica_group_create() function.
3312 public function testApiFriendicaGroupCreate()
3314 $this->markTestIncomplete();
3318 * Test the api_lists_create() function.
3322 public function testApiListsCreate()
3324 $this->markTestIncomplete();
3328 * Test the api_friendica_group_update() function.
3332 public function testApiFriendicaGroupUpdate()
3334 $this->markTestIncomplete();
3338 * Test the api_lists_update() function.
3342 public function testApiListsUpdate()
3344 $this->markTestIncomplete();
3348 * Test the api_friendica_activity() function.
3352 public function testApiFriendicaActivity()
3354 $this->markTestIncomplete();
3358 * Test the api_friendica_notification_seen() function.
3362 public function testApiFriendicaNotificationSeen()
3364 $this->markTestIncomplete();
3368 * Test the api_friendica_direct_messages_setseen() function.
3372 public function testApiFriendicaDirectMessagesSetseen()
3374 $this->markTestIncomplete();
3378 * Test the api_friendica_direct_messages_search() function.
3382 public function testApiFriendicaDirectMessagesSearch()
3384 $this->markTestIncomplete();