6 namespace Friendica\Test\legacy;
9 use Friendica\App\Router;
10 use Friendica\Core\Config\Capability\IManageConfigValues;
11 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
12 use Friendica\Core\Protocol;
14 use Friendica\Model\Post;
15 use Friendica\Module\Api\ApiResponse;
16 use Friendica\Module\Api\Twitter\Media\Upload;
17 use Friendica\Module\BaseApi;
18 use Friendica\Network\HTTPException;
19 use Friendica\Security\BasicAuth;
20 use Friendica\Test\FixtureTest;
21 use Friendica\Util\Arrays;
22 use Friendica\Util\DateTimeFormat;
23 use Friendica\Util\Temporal;
24 use Monolog\Handler\TestHandler;
26 require_once __DIR__ . '/../../include/api.php';
29 * Tests for the API functions.
31 * Functions that use header() need to be tested in a separate process.
32 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
34 * @backupGlobals enabled
36 class ApiTest extends FixtureTest
39 * @var TestHandler Can handle log-outputs
46 protected $friendUser;
50 protected $wrongUserId;
55 /** @var IManageConfigValues */
59 * Create variables used by tests.
61 protected function setUp() : void
63 global $API, $called_api;
69 /** @var IManageConfigValues $config */
70 $this->config = $this->dice->create(IManageConfigValues::class);
72 $this->config->set('system', 'url', 'http://localhost');
73 $this->config->set('system', 'hostname', 'localhost');
74 $this->config->set('system', 'worker_dont_fork', true);
77 $this->config->set('config', 'hostname', 'localhost');
78 $this->config->set('system', 'throttle_limit_day', 100);
79 $this->config->set('system', 'throttle_limit_week', 100);
80 $this->config->set('system', 'throttle_limit_month', 100);
81 $this->config->set('system', 'theme', 'system_theme');
85 $this->app = DI::app();
87 DI::args()->setArgc(1);
89 // User data that the test database is populated with
92 'name' => 'Self contact',
93 'nick' => 'selfcontact',
94 'nurl' => 'http://localhost/profile/selfcontact'
98 'name' => 'Friend contact',
99 'nick' => 'friendcontact',
100 'nurl' => 'http://localhost/profile/friendcontact'
104 'name' => 'othercontact',
105 'nick' => 'othercontact',
106 'nurl' => 'http://localhost/profile/othercontact'
109 // User ID that we know is not in the database
110 $this->wrongUserId = 666;
112 DI::session()->start();
114 // Most API require login so we force the session
116 'authenticated' => true,
117 'uid' => $this->selfUser['id']
119 BasicAuth::setCurrentUserID($this->selfUser['id']);
123 * Assert that an user array contains expected keys.
125 * @param array $user User array
129 private function assertSelfUser(array $user)
131 self::assertEquals($this->selfUser['id'], $user['uid']);
132 self::assertEquals($this->selfUser['id'], $user['cid']);
133 self::assertEquals(1, $user['self']);
134 self::assertEquals('DFRN', $user['location']);
135 self::assertEquals($this->selfUser['name'], $user['name']);
136 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
137 self::assertEquals('dfrn', $user['network']);
138 self::assertTrue($user['verified']);
142 * Assert that an user array contains expected keys.
144 * @param array $user User array
148 private function assertOtherUser(array $user = [])
150 self::assertEquals($this->otherUser['id'], $user['id']);
151 self::assertEquals($this->otherUser['id'], $user['id_str']);
152 self::assertEquals($this->otherUser['name'], $user['name']);
153 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
154 self::assertFalse($user['verified']);
158 * Assert that a status array contains expected keys.
160 * @param array $status Status array
164 private function assertStatus(array $status = [])
166 self::assertIsString($status['text'] ?? '');
167 self::assertIsInt($status['id'] ?? '');
168 // We could probably do more checks here.
172 * Assert that a list array contains expected keys.
174 * @param array $list List array
178 private function assertList(array $list = [])
180 self::assertIsString($list['name']);
181 self::assertIsInt($list['id']);
182 self::assertIsString('string', $list['id_str']);
183 self::assertContains($list['mode'], ['public', 'private']);
184 // We could probably do more checks here.
188 * Assert that the string is XML and contain the root element.
190 * @param string $result XML string
191 * @param string $root_element Root element name
195 private function assertXml($result = '', $root_element = '')
197 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
198 self::assertStringContainsString('<' . $root_element, $result);
199 // We could probably do more checks here.
203 * Get the path to a temporary empty PNG image.
205 * @return string Path
207 private function getTempImage()
209 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
213 // Empty 1x1 px PNG image
214 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
222 * Test the api_user() function.
226 public function testApiUser()
228 self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
232 * Test the api_user() function with an unallowed user.
236 public function testApiUserWithUnallowedUser()
238 // self::assertEquals(false, api_user());
242 * Test the api_source() function.
246 public function testApiSource()
248 self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
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', BasicAuth::getCurrentApplicationToken()['name']);
263 * Test the api_source() function with a GET parameter.
267 public function testApiSourceWithGet()
269 $_REQUEST['source'] = 'source_name';
270 self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
274 * Test the api_date() function.
278 public function testApiDate()
280 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
284 * Test the api_register_func() function.
288 public function testApiRegisterFunc()
300 self::assertTrue(is_callable($API['api_path']['func']));
304 * Test the BasicAuth::getCurrentUserID() function without any login.
306 * @runInSeparateProcess
307 * @preserveGlobalState disabled
308 * @preserveGlobalState disabled
310 public function testApiLoginWithoutLogin()
312 BasicAuth::setCurrentUserID();
313 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314 BasicAuth::getCurrentUserID(true);
318 * Test the BasicAuth::getCurrentUserID() function with a bad login.
320 * @runInSeparateProcess
321 * @preserveGlobalState disabled
322 * @preserveGlobalState disabled
324 public function testApiLoginWithBadLogin()
326 BasicAuth::setCurrentUserID();
327 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
328 $_SERVER['PHP_AUTH_USER'] = 'user@server';
329 BasicAuth::getCurrentUserID(true);
333 * Test the BasicAuth::getCurrentUserID() function with oAuth.
337 public function testApiLoginWithOauth()
339 $this->markTestIncomplete('Can we test this easily?');
343 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
347 public function testApiLoginWithAddonAuth()
349 $this->markTestIncomplete('Can we test this easily?');
353 * Test the BasicAuth::getCurrentUserID() function with a correct login.
355 * @runInSeparateProcess
356 * @preserveGlobalState disabled
357 * @doesNotPerformAssertions
359 public function testApiLoginWithCorrectLogin()
361 BasicAuth::setCurrentUserID();
362 $_SERVER['PHP_AUTH_USER'] = 'Test user';
363 $_SERVER['PHP_AUTH_PW'] = 'password';
364 BasicAuth::getCurrentUserID(true);
368 * Test the BasicAuth::getCurrentUserID() function with a remote user.
370 * @runInSeparateProcess
371 * @preserveGlobalState disabled
373 public function testApiLoginWithRemoteUser()
375 BasicAuth::setCurrentUserID();
376 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
377 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
378 BasicAuth::getCurrentUserID(true);
382 * Test the api_call() function.
384 * @runInSeparateProcess
385 * @preserveGlobalState disabled
387 public function testApiCall()
391 'method' => 'method',
392 'func' => function () {
393 return ['data' => ['some_data']];
396 $_SERVER['REQUEST_METHOD'] = 'method';
397 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
398 $_GET['callback'] = 'callback_name';
401 'callback_name(["some_data"])',
402 api_call('api_path', 'json')
407 * Test the api_call() function with the profiled enabled.
409 * @runInSeparateProcess
410 * @preserveGlobalState disabled
412 public function testApiCallWithProfiler()
416 'method' => 'method',
417 'func' => function () {
418 return ['data' => ['some_data']];
422 $_SERVER['REQUEST_METHOD'] = 'method';
423 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
425 $this->config->set('system', 'profiler', true);
426 $this->config->set('rendertime', 'callstack', true);
427 $this->app->callstack = [
428 'database' => ['some_function' => 200],
429 'database_write' => ['some_function' => 200],
430 'cache' => ['some_function' => 200],
431 'cache_write' => ['some_function' => 200],
432 'network' => ['some_function' => 200]
437 api_call('api_path', 'json')
442 * Test the api_call() function with a JSON result.
444 * @runInSeparateProcess
445 * @preserveGlobalState disabled
447 public function testApiCallWithJson()
451 'method' => 'method',
452 'func' => function () {
453 return ['data' => ['some_data']];
456 $_SERVER['REQUEST_METHOD'] = 'method';
457 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
461 api_call('api_path.json', 'json')
466 * Test the api_call() function with an XML result.
468 * @runInSeparateProcess
469 * @preserveGlobalState disabled
471 public function testApiCallWithXml()
475 'method' => 'method',
476 'func' => function () {
480 $_SERVER['REQUEST_METHOD'] = 'method';
481 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
483 $args = DI::args()->determine($_SERVER, $_GET);
487 api_call('api_path.xml', 'xml')
492 * Test the api_call() function with an RSS result.
494 * @runInSeparateProcess
495 * @preserveGlobalState disabled
497 public function testApiCallWithRss()
501 'method' => 'method',
502 'func' => function () {
506 $_SERVER['REQUEST_METHOD'] = 'method';
507 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
510 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
512 api_call('api_path.rss', 'rss')
517 * Test the api_call() function with an Atom result.
519 * @runInSeparateProcess
520 * @preserveGlobalState disabled
522 public function testApiCallWithAtom()
526 'method' => 'method',
527 'func' => function () {
531 $_SERVER['REQUEST_METHOD'] = 'method';
532 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
535 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
537 api_call('api_path.atom', 'atom')
542 * Test the api_rss_extra() function.
546 public function testApiRssExtra()
549 $user_info = ['url' => 'user_url', 'lang' => 'en'];
550 $result = api_rss_extra([], $user_info);
551 self::assertEquals($user_info, $result['$user']);
552 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
553 self::assertArrayHasKey('self', $result['$rss']);
554 self::assertArrayHasKey('base', $result['$rss']);
555 self::assertArrayHasKey('updated', $result['$rss']);
556 self::assertArrayHasKey('atom_updated', $result['$rss']);
557 self::assertArrayHasKey('language', $result['$rss']);
558 self::assertArrayHasKey('logo', $result['$rss']);
563 * Test the api_rss_extra() function without any user info.
567 public function testApiRssExtraWithoutUserInfo()
570 $result = api_rss_extra([], null);
571 self::assertIsArray($result['$user']);
572 self::assertArrayHasKey('alternate', $result['$rss']);
573 self::assertArrayHasKey('self', $result['$rss']);
574 self::assertArrayHasKey('base', $result['$rss']);
575 self::assertArrayHasKey('updated', $result['$rss']);
576 self::assertArrayHasKey('atom_updated', $result['$rss']);
577 self::assertArrayHasKey('language', $result['$rss']);
578 self::assertArrayHasKey('logo', $result['$rss']);
583 * Test the api_get_user() function.
587 public function testApiGetUser()
589 // $user = api_get_user();
590 // self::assertSelfUser($user);
591 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
592 // self::assertEquals('6fdbe8', $user['profile_link_color']);
593 // self::assertEquals('ededed', $user['profile_background_color']);
597 * Test the api_get_user() function with a Frio schema.
601 public function testApiGetUserWithFrioSchema()
603 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
604 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
605 // $user = api_get_user();
606 // self::assertSelfUser($user);
607 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
608 // self::assertEquals('6fdbe8', $user['profile_link_color']);
609 // self::assertEquals('ededed', $user['profile_background_color']);
613 * Test the api_get_user() function with an empty Frio schema.
617 public function testApiGetUserWithEmptyFrioSchema()
619 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
620 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
621 // $user = api_get_user();
622 // self::assertSelfUser($user);
623 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
624 // self::assertEquals('6fdbe8', $user['profile_link_color']);
625 // self::assertEquals('ededed', $user['profile_background_color']);
629 * Test the api_get_user() function with a custom Frio schema.
633 public function testApiGetUserWithCustomFrioSchema()
635 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
636 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
637 // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
638 // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
639 // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
640 // $user = api_get_user();
641 // self::assertSelfUser($user);
642 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
643 // self::assertEquals('123456', $user['profile_link_color']);
644 // self::assertEquals('123456', $user['profile_background_color']);
648 * Test the api_get_user() function with an user that is not allowed to use the API.
650 * @runInSeparateProcess
651 * @preserveGlobalState disabled
653 public function testApiGetUserWithoutApiUser()
655 // api_get_user() with empty parameters is not used anymore
657 $_SERVER['PHP_AUTH_USER'] = 'Test user';
658 $_SERVER['PHP_AUTH_PW'] = 'password';
659 BasicAuth::setCurrentUserID();
660 self::assertFalse(api_get_user());
665 * Test the api_get_user() function with an user ID in a GET parameter.
669 public function testApiGetUserWithGetId()
671 // self::assertOtherUser(api_get_user());
675 * Test the api_get_user() function with a wrong user ID in a GET parameter.
679 public function testApiGetUserWithWrongGetId()
681 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
682 // self::assertOtherUser(api_get_user());
686 * Test the api_get_user() function with an user name in a GET parameter.
690 public function testApiGetUserWithGetName()
692 // self::assertSelfUser(api_get_user());
696 * Test the api_get_user() function with a profile URL in a GET parameter.
700 public function testApiGetUserWithGetUrl()
702 // self::assertSelfUser(api_get_user());
706 * Test the api_get_user() function with an user ID in the API path.
710 public function testApiGetUserWithNumericCalledApi()
712 // global $called_api;
713 // $called_api = ['api_path'];
714 // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
715 // self::assertOtherUser(api_get_user());
719 * Test the api_get_user() function with the $called_api global variable.
723 public function testApiGetUserWithCalledApi()
725 // global $called_api;
726 // $called_api = ['api', 'api_path'];
727 // self::assertSelfUser(api_get_user());
731 * Test the Arrays::walkRecursive() function.
735 public function testApiWalkRecursive()
740 Arrays::walkRecursive(
743 // Should we test this with a callback that actually does something?
751 * Test the Arrays::walkRecursive() function with an array.
755 public function testApiWalkRecursiveWithArray()
757 $array = [['item1'], ['item2']];
760 Arrays::walkRecursive(
763 // Should we test this with a callback that actually does something?
771 * Test the BaseApi::reformatXML() function.
775 public function testApiReformatXml()
779 self::assertTrue(ApiResponse::reformatXML($item, $key));
780 self::assertEquals('true', $item);
784 * Test the BaseApi::reformatXML() function with a statusnet_api key.
788 public function testApiReformatXmlWithStatusnetKey()
791 $key = 'statusnet_api';
792 self::assertTrue(ApiResponse::reformatXML($item, $key));
793 self::assertEquals('statusnet:api', $key);
797 * Test the BaseApi::reformatXML() function with a friendica_api key.
801 public function testApiReformatXmlWithFriendicaKey()
804 $key = 'friendica_api';
805 self::assertTrue(ApiResponse::reformatXML($item, $key));
806 self::assertEquals('friendica:api', $key);
810 * Test the BaseApi::createXML() function.
814 public function testApiCreateXml()
817 '<?xml version="1.0"?>' . "\n" .
818 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
819 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
820 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
821 ' <data>some_data</data>' . "\n" .
822 '</root_element>' . "\n",
823 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
828 * Test the BaseApi::createXML() function without any XML namespace.
832 public function testApiCreateXmlWithoutNamespaces()
835 '<?xml version="1.0"?>' . "\n" .
837 ' <data>some_data</data>' . "\n" .
839 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
844 * Test the BaseApi::formatData() function.
848 public function testApiFormatData()
850 $data = ['some_data'];
851 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
855 * Test the BaseApi::formatData() function with an XML result.
859 public function testApiFormatDataWithXml()
862 '<?xml version="1.0"?>' . "\n" .
863 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
864 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
865 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
866 ' <data>some_data</data>' . "\n" .
867 '</root_element>' . "\n",
868 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
873 * Test the api_statuses_mediap() function.
877 public function testApiStatusesMediap()
880 DI::args()->setArgc(2);
888 'tmp_name' => $this->getTempImage(),
889 'name' => 'spacer.png',
890 'type' => 'image/png'
893 $_GET['status'] = '<b>Status content</b>';
895 $result = api_statuses_mediap('json');
896 self::assertStatus($result['status']);
901 * Test the api_statuses_mediap() function without an authenticated user.
905 public function testApiStatusesMediapWithoutAuthenticatedUser()
907 // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
908 // BasicAuth::setCurrentUserID();
909 // $_SESSION['authenticated'] = false;
910 // api_statuses_mediap('json');
914 * Test the api_statuses_update() function.
918 public function testApiStatusesUpdate()
921 $_REQUEST['status'] = 'Status content #friendica';
922 $_REQUEST['in_reply_to_status_id'] = -1;
923 $_REQUEST['lat'] = 48;
924 $_REQUEST['long'] = 7;
931 'tmp_name' => $this->getTempImage(),
932 'name' => 'spacer.png',
933 'type' => 'image/png'
937 $result = api_statuses_update('json');
938 self::assertStatus($result['status']);
943 * Test the api_statuses_update() function with an HTML status.
947 public function testApiStatusesUpdateWithHtml()
950 $_REQUEST['htmlstatus'] = '<b>Status content</b>';
952 $result = api_statuses_update('json');
953 self::assertStatus($result['status']);
958 * Test the api_statuses_update() function without an authenticated user.
962 public function testApiStatusesUpdateWithoutAuthenticatedUser()
965 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
966 BasicAuth::setCurrentUserID();
967 $_SESSION['authenticated'] = false;
968 api_statuses_update('json');
973 * Test the api_statuses_update() function with a parent status.
977 public function testApiStatusesUpdateWithParent()
979 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
983 * Test the api_statuses_update() function with a media_ids parameter.
987 public function testApiStatusesUpdateWithMediaIds()
989 $this->markTestIncomplete();
993 * Test the api_statuses_update() function with the throttle limit reached.
997 public function testApiStatusesUpdateWithDayThrottleReached()
999 $this->markTestIncomplete();
1003 * Test the \Friendica\Module\Api\Twitter\Media\Upload module.
1004 * @runInSeparateProcess
1005 * @preserveGlobalState disabled
1007 public function testApiMediaUpload()
1009 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1010 $_SERVER['REQUEST_METHOD'] = Router::POST;
1011 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1015 * Test the \Friendica\Module\Api\Twitter\Media\Upload module without an authenticated user.
1019 public function testApiMediaUploadWithoutAuthenticatedUser()
1021 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1022 BasicAuth::setCurrentUserID();
1023 $_SESSION['authenticated'] = false;
1024 $_SERVER['REQUEST_METHOD'] = Router::POST;
1025 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1029 * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an invalid uploaded media.
1033 public function testApiMediaUploadWithMedia()
1035 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1039 'tmp_name' => 'tmp_name'
1042 $_SERVER['REQUEST_METHOD'] = Router::POST;
1043 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1047 * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an valid uploaded media.
1051 public function testApiMediaUploadWithValidMedia()
1059 'tmp_name' => $this->getTempImage(),
1060 'name' => 'spacer.png',
1061 'type' => 'image/png'
1065 $_SERVER['REQUEST_METHOD'] = Router::POST;
1067 $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1068 $media = json_decode($response->getBody(), true);
1070 self::assertEquals('image/png', $media['image']['image_type']);
1071 self::assertEquals(1, $media['image']['w']);
1072 self::assertEquals(1, $media['image']['h']);
1073 self::assertNotEmpty($media['image']['friendica_preview_url']);
1077 * Test the api_statuses_repeat() function.
1081 public function testApiStatusesRepeat()
1083 // $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1084 // api_statuses_repeat('json');
1088 * Test the api_statuses_repeat() function without an authenticated user.
1092 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1094 // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1095 // BasicAuth::setCurrentUserID();
1096 // $_SESSION['authenticated'] = false;
1097 // api_statuses_repeat('json');
1101 * Test the api_statuses_repeat() function with an ID.
1105 public function testApiStatusesRepeatWithId()
1107 // DI::args()->setArgv(['', '', '', 1]);
1108 // $result = api_statuses_repeat('json');
1109 // self::assertStatus($result['status']);
1111 // Also test with a shared status
1112 // DI::args()->setArgv(['', '', '', 5]);
1113 // $result = api_statuses_repeat('json');
1114 // self::assertStatus($result['status']);
1118 * Test the api_favorites_create_destroy() function.
1122 public function testApiFavoritesCreateDestroy()
1124 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1125 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1126 // api_favorites_create_destroy('json');
1130 * Test the api_favorites_create_destroy() function with an invalid ID.
1134 public function testApiFavoritesCreateDestroyWithInvalidId()
1136 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1137 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1138 // api_favorites_create_destroy('json');
1142 * Test the api_favorites_create_destroy() function with an invalid action.
1146 public function testApiFavoritesCreateDestroyWithInvalidAction()
1148 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1149 // DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1150 // $_REQUEST['id'] = 1;
1151 // api_favorites_create_destroy('json');
1155 * Test the api_favorites_create_destroy() function with the create action.
1159 public function testApiFavoritesCreateDestroyWithCreateAction()
1161 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1162 // $_REQUEST['id'] = 3;
1163 // $result = api_favorites_create_destroy('json');
1164 // self::assertStatus($result['status']);
1168 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1172 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1174 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1175 // $_REQUEST['id'] = 3;
1176 // $result = api_favorites_create_destroy('rss');
1177 // self::assertXml($result, 'status');
1181 * Test the api_favorites_create_destroy() function with the destroy action.
1185 public function testApiFavoritesCreateDestroyWithDestroyAction()
1187 // DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1188 // $_REQUEST['id'] = 3;
1189 // $result = api_favorites_create_destroy('json');
1190 // self::assertStatus($result['status']);
1194 * Test the api_favorites_create_destroy() function without an authenticated user.
1198 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1201 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1202 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1203 BasicAuth::setCurrentUserID();
1204 $_SESSION['authenticated'] = false;
1205 api_favorites_create_destroy('json');
1212 * Test the api_format_messages() function.
1216 public function testApiFormatMessages()
1218 $result = api_format_messages(
1219 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1220 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1221 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
1223 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
1224 self::assertEquals(1, $result['id']);
1225 self::assertEquals(2, $result['recipient_id']);
1226 self::assertEquals(3, $result['sender_id']);
1227 self::assertEquals('recipient_name', $result['recipient_screen_name']);
1228 self::assertEquals('sender_name', $result['sender_screen_name']);
1232 * Test the api_format_messages() function with HTML.
1236 public function testApiFormatMessagesWithHtmlText()
1238 $_GET['getText'] = 'html';
1239 $result = api_format_messages(
1240 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1241 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1242 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1244 self::assertEquals('item_title', $result['title']);
1245 self::assertEquals('<strong>item_body</strong>', $result['text']);
1249 * Test the api_format_messages() function with plain text.
1253 public function testApiFormatMessagesWithPlainText()
1255 $_GET['getText'] = 'plain';
1256 $result = api_format_messages(
1257 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1258 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1259 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1261 self::assertEquals('item_title', $result['title']);
1262 self::assertEquals('item_body', $result['text']);
1266 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
1270 public function testApiFormatMessagesWithoutUserObjects()
1272 $_GET['getUserObjects'] = 'false';
1273 $result = api_format_messages(
1274 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1275 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1276 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1278 self::assertTrue(!isset($result['sender']));
1279 self::assertTrue(!isset($result['recipient']));
1283 * Test the api_convert_item() function.
1287 public function testApiConvertItem()
1290 $result = api_convert_item(
1292 'network' => 'feed',
1293 'title' => 'item_title',
1295 // We need a long string to test that it is correctly cut
1296 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
1297 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
1298 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
1299 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
1300 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
1301 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
1302 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
1303 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
1304 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
1305 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
1306 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
1307 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
1308 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
1309 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
1310 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
1311 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
1312 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
1313 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
1314 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
1315 'repellat officia illum quos impedit quam iste esse unde qui ' .
1316 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
1317 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
1318 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
1319 'plink' => 'item_plink'
1322 self::assertStringStartsWith('item_title', $result['text']);
1323 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
1328 * Test the api_convert_item() function with an empty item body.
1332 public function testApiConvertItemWithoutBody()
1335 $result = api_convert_item(
1337 'network' => 'feed',
1338 'title' => 'item_title',
1341 'plink' => 'item_plink'
1344 self::assertEquals("item_title", $result['text']);
1345 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
1350 * Test the api_convert_item() function with the title in the body.
1354 public function testApiConvertItemWithTitleInBody()
1357 $result = api_convert_item(
1359 'title' => 'item_title',
1360 'body' => 'item_title item_body',
1364 self::assertEquals('item_title item_body', $result['text']);
1365 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
1370 * Test the api_get_attachments() function.
1374 public function testApiGetAttachments()
1377 // self::assertEmpty(api_get_attachments($body, 0));
1381 * Test the api_get_attachments() function with an img tag.
1385 public function testApiGetAttachmentsWithImage()
1387 // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
1388 // self::assertIsArray(api_get_attachments($body, 0));
1392 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
1396 public function testApiGetAttachmentsWithImageAndAndStatus()
1398 // $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
1399 // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
1400 // self::assertIsArray(api_get_attachments($body, 0));
1404 * Test the api_get_entitities() function.
1408 public function testApiGetEntitities()
1411 // self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
1415 * Test the api_get_entitities() function with the include_entities parameter.
1419 public function testApiGetEntititiesWithIncludeEntities()
1422 $_REQUEST['include_entities'] = 'true';
1424 $result = api_get_entitities($text, 'bbcode', 0);
1425 self::assertIsArray($result['hashtags']);
1426 self::assertIsArray($result['symbols']);
1427 self::assertIsArray($result['urls']);
1428 self::assertIsArray($result['user_mentions']);
1433 * Test the api_format_items_embeded_images() function.
1437 public function testApiFormatItemsEmbededImages()
1441 'text ' . DI::baseUrl() . '/display/item_guid',
1442 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
1448 * Test the api_format_items_activities() function.
1452 public function testApiFormatItemsActivities()
1454 $item = ['uid' => 0, 'uri-id' => 1];
1455 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
1456 self::assertArrayHasKey('like', $result);
1457 self::assertArrayHasKey('dislike', $result);
1458 self::assertArrayHasKey('attendyes', $result);
1459 self::assertArrayHasKey('attendno', $result);
1460 self::assertArrayHasKey('attendmaybe', $result);
1464 * Test the api_format_items_activities() function with an XML result.
1468 public function testApiFormatItemsActivitiesWithXml()
1470 $item = ['uid' => 0, 'uri-id' => 1];
1471 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
1472 self::assertArrayHasKey('friendica:like', $result);
1473 self::assertArrayHasKey('friendica:dislike', $result);
1474 self::assertArrayHasKey('friendica:attendyes', $result);
1475 self::assertArrayHasKey('friendica:attendno', $result);
1476 self::assertArrayHasKey('friendica:attendmaybe', $result);
1480 * Test the api_format_items() function.
1481 * @doesNotPerformAssertions
1483 public function testApiFormatItems()
1486 $items = Post::selectToArray([], ['uid' => 42]);
1487 foreach ($items as $item) {
1488 $status = api_format_item($item);
1489 self::assertStatus($status);
1495 * Test the api_format_items() function with an XML result.
1496 * @doesNotPerformAssertions
1498 public function testApiFormatItemsWithXml()
1501 $items = Post::selectToArray([], ['uid' => 42]);
1502 foreach ($items as $item) {
1503 $status = api_format_item($item, 'xml');
1504 self::assertStatus($status);
1510 * Test the api_lists_list() function.
1514 public function testApiListsList()
1516 $result = api_lists_list('json');
1517 self::assertEquals(['lists_list' => []], $result);
1521 * Test the api_lists_ownerships() function.
1525 public function testApiListsOwnerships()
1527 $result = api_lists_ownerships('json');
1528 foreach ($result['lists']['lists'] as $list) {
1529 self::assertList($list);
1534 * Test the api_lists_ownerships() function without an authenticated user.
1538 public function testApiListsOwnershipsWithoutAuthenticatedUser()
1540 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1541 BasicAuth::setCurrentUserID();
1542 $_SESSION['authenticated'] = false;
1543 api_lists_ownerships('json');
1547 * Test the api_statuses_f() function.
1551 public function testApiStatusesFWithIncoming()
1553 // $result = api_statuses_f('incoming');
1554 // self::assertArrayHasKey('user', $result);
1559 * Test the api_direct_messages_new() function.
1563 public function testApiDirectMessagesNew()
1565 $result = api_direct_messages_new('json');
1566 self::assertNull($result);
1570 * Test the api_direct_messages_new() function without an authenticated user.
1574 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
1576 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1577 BasicAuth::setCurrentUserID();
1578 $_SESSION['authenticated'] = false;
1579 api_direct_messages_new('json');
1583 * Test the api_direct_messages_new() function with an user ID.
1587 public function testApiDirectMessagesNewWithUserId()
1589 $_POST['text'] = 'message_text';
1590 $_REQUEST['user_id'] = $this->otherUser['id'];
1591 $result = api_direct_messages_new('json');
1592 self::assertEquals(['direct_message' => ['error' => -1]], $result);
1596 * Test the api_direct_messages_new() function with a screen name.
1600 public function testApiDirectMessagesNewWithScreenName()
1602 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1603 $_POST['text'] = 'message_text';
1604 $_REQUEST['user_id'] = $this->friendUser['id'];
1605 $result = api_direct_messages_new('json');
1606 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1607 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1608 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1612 * Test the api_direct_messages_new() function with a title.
1616 public function testApiDirectMessagesNewWithTitle()
1618 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1619 $_POST['text'] = 'message_text';
1620 $_REQUEST['user_id'] = $this->friendUser['id'];
1621 $_REQUEST['title'] = 'message_title';
1622 $result = api_direct_messages_new('json');
1623 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1624 self::assertStringContainsString('message_title', $result['direct_message']['text']);
1625 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1626 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1630 * Test the api_direct_messages_new() function with an RSS result.
1634 public function testApiDirectMessagesNewWithRss()
1636 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1637 $_POST['text'] = 'message_text';
1638 $_REQUEST['user_id'] = $this->friendUser['id'];
1639 $result = api_direct_messages_new('rss');
1640 self::assertXml($result, 'direct-messages');
1644 * Test the api_direct_messages_destroy() function.
1648 public function testApiDirectMessagesDestroy()
1650 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1651 api_direct_messages_destroy('json');
1655 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
1659 public function testApiDirectMessagesDestroyWithVerbose()
1661 $_GET['friendica_verbose'] = 'true';
1662 $result = api_direct_messages_destroy('json');
1666 'result' => 'error',
1667 'message' => 'message id or parenturi not specified'
1675 * Test the api_direct_messages_destroy() function without an authenticated user.
1679 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
1681 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1682 BasicAuth::setCurrentUserID();
1683 $_SESSION['authenticated'] = false;
1684 api_direct_messages_destroy('json');
1688 * Test the api_direct_messages_destroy() function with a non-zero ID.
1692 public function testApiDirectMessagesDestroyWithId()
1694 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1695 $_REQUEST['id'] = 1;
1696 api_direct_messages_destroy('json');
1700 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
1704 public function testApiDirectMessagesDestroyWithIdAndVerbose()
1706 $_REQUEST['id'] = 1;
1707 $_REQUEST['friendica_parenturi'] = 'parent_uri';
1708 $_GET['friendica_verbose'] = 'true';
1709 $result = api_direct_messages_destroy('json');
1713 'result' => 'error',
1714 'message' => 'message id not in database'
1722 * Test the api_direct_messages_destroy() function with a non-zero ID.
1726 public function testApiDirectMessagesDestroyWithCorrectId()
1728 $this->markTestIncomplete('We need to add a dataset for this.');
1732 * Test the api_direct_messages_box() function.
1736 public function testApiDirectMessagesBoxWithSentbox()
1738 $_REQUEST['page'] = -1;
1739 $_REQUEST['max_id'] = 10;
1740 $result = api_direct_messages_box('json', 'sentbox', 'false');
1741 self::assertArrayHasKey('direct_message', $result);
1745 * Test the api_direct_messages_box() function.
1749 public function testApiDirectMessagesBoxWithConversation()
1751 $result = api_direct_messages_box('json', 'conversation', 'false');
1752 self::assertArrayHasKey('direct_message', $result);
1756 * Test the api_direct_messages_box() function.
1760 public function testApiDirectMessagesBoxWithAll()
1762 $result = api_direct_messages_box('json', 'all', 'false');
1763 self::assertArrayHasKey('direct_message', $result);
1767 * Test the api_direct_messages_box() function.
1771 public function testApiDirectMessagesBoxWithInbox()
1773 $result = api_direct_messages_box('json', 'inbox', 'false');
1774 self::assertArrayHasKey('direct_message', $result);
1778 * Test the api_direct_messages_box() function.
1782 public function testApiDirectMessagesBoxWithVerbose()
1784 $result = api_direct_messages_box('json', 'sentbox', 'true');
1788 'result' => 'error',
1789 'message' => 'no mails available'
1797 * Test the api_direct_messages_box() function with a RSS result.
1801 public function testApiDirectMessagesBoxWithRss()
1803 $result = api_direct_messages_box('rss', 'sentbox', 'false');
1804 self::assertXml($result, 'direct-messages');
1808 * Test the api_direct_messages_box() function without an authenticated user.
1812 public function testApiDirectMessagesBoxWithUnallowedUser()
1814 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1815 BasicAuth::setCurrentUserID();
1816 api_direct_messages_box('json', 'sentbox', 'false');
1820 * Test the api_direct_messages_sentbox() function.
1824 public function testApiDirectMessagesSentbox()
1826 $result = api_direct_messages_sentbox('json');
1827 self::assertArrayHasKey('direct_message', $result);
1831 * Test the api_direct_messages_inbox() function.
1835 public function testApiDirectMessagesInbox()
1837 $result = api_direct_messages_inbox('json');
1838 self::assertArrayHasKey('direct_message', $result);
1842 * Test the api_direct_messages_all() function.
1846 public function testApiDirectMessagesAll()
1848 $result = api_direct_messages_all('json');
1849 self::assertArrayHasKey('direct_message', $result);
1853 * Test the api_direct_messages_conversation() function.
1857 public function testApiDirectMessagesConversation()
1859 $result = api_direct_messages_conversation('json');
1860 self::assertArrayHasKey('direct_message', $result);
1864 * Test the api_oauth_request_token() function.
1868 public function testApiOauthRequestToken()
1870 $this->markTestIncomplete('exit() kills phpunit as well');
1874 * Test the api_oauth_access_token() function.
1878 public function testApiOauthAccessToken()
1880 $this->markTestIncomplete('exit() kills phpunit as well');
1884 * Test the api_fr_photos_list() function.
1888 public function testApiFrPhotosList()
1890 $result = api_fr_photos_list('json');
1891 self::assertArrayHasKey('photo', $result);
1895 * Test the api_fr_photos_list() function without an authenticated user.
1899 public function testApiFrPhotosListWithoutAuthenticatedUser()
1901 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1902 BasicAuth::setCurrentUserID();
1903 $_SESSION['authenticated'] = false;
1904 api_fr_photos_list('json');
1908 * Test the api_fr_photo_create_update() function.
1910 public function testApiFrPhotoCreateUpdate()
1912 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1913 api_fr_photo_create_update('json');
1917 * Test the api_fr_photo_create_update() function without an authenticated user.
1921 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
1923 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1924 BasicAuth::setCurrentUserID();
1925 $_SESSION['authenticated'] = false;
1926 api_fr_photo_create_update('json');
1930 * Test the api_fr_photo_create_update() function with an album name.
1934 public function testApiFrPhotoCreateUpdateWithAlbum()
1936 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1937 $_REQUEST['album'] = 'album_name';
1938 api_fr_photo_create_update('json');
1942 * Test the api_fr_photo_create_update() function with the update mode.
1946 public function testApiFrPhotoCreateUpdateWithUpdate()
1948 $this->markTestIncomplete('We need to create a dataset for this');
1952 * Test the api_fr_photo_create_update() function with an uploaded file.
1956 public function testApiFrPhotoCreateUpdateWithFile()
1958 $this->markTestIncomplete();
1962 * Test the api_fr_photo_detail() function.
1966 public function testApiFrPhotoDetail()
1968 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1969 api_fr_photo_detail('json');
1973 * Test the api_fr_photo_detail() function without an authenticated user.
1977 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
1979 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1980 BasicAuth::setCurrentUserID();
1981 $_SESSION['authenticated'] = false;
1982 api_fr_photo_detail('json');
1986 * Test the api_fr_photo_detail() function with a photo ID.
1990 public function testApiFrPhotoDetailWithPhotoId()
1992 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1993 $_REQUEST['photo_id'] = 1;
1994 api_fr_photo_detail('json');
1998 * Test the api_fr_photo_detail() function with a correct photo ID.
2002 public function testApiFrPhotoDetailCorrectPhotoId()
2004 $this->markTestIncomplete('We need to create a dataset for this.');
2008 * Test the api_account_update_profile_image() function.
2012 public function testApiAccountUpdateProfileImage()
2014 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2015 api_account_update_profile_image('json');
2019 * Test the api_account_update_profile_image() function without an authenticated user.
2023 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
2025 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2026 BasicAuth::setCurrentUserID();
2027 $_SESSION['authenticated'] = false;
2028 api_account_update_profile_image('json');
2032 * Test the api_account_update_profile_image() function with an uploaded file.
2036 public function testApiAccountUpdateProfileImageWithUpload()
2038 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2039 $this->markTestIncomplete();
2043 * Test the check_acl_input() function.
2047 public function testCheckAclInput()
2049 $result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
2050 // Where does this result come from?
2051 self::assertEquals(1, $result);
2055 * Test the check_acl_input() function with an empty ACL string.
2059 public function testCheckAclInputWithEmptyAclString()
2061 $result = check_acl_input(' ', BaseApi::getCurrentUserID());
2062 self::assertFalse($result);
2066 * Test the save_media_to_database() function.
2070 public function testSaveMediaToDatabase()
2072 $this->markTestIncomplete();
2076 * Test the post_photo_item() function.
2080 public function testPostPhotoItem()
2082 $this->markTestIncomplete();
2086 * Test the prepare_photo_data() function.
2090 public function testPreparePhotoData()
2092 $this->markTestIncomplete();
2096 * Test the api_share_as_retweet() function with a valid item.
2100 public function testApiShareAsRetweetWithValidItem()
2102 $this->markTestIncomplete();
2106 * Test the api_in_reply_to() function with a valid item.
2110 public function testApiInReplyToWithValidItem()
2112 $this->markTestIncomplete();
2116 * Test the api_clean_plain_items() function.
2120 public function testApiCleanPlainItems()
2122 $_REQUEST['include_entities'] = 'true';
2123 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
2124 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
2128 * Test the api_best_nickname() function with contacts.
2132 public function testApiBestNicknameWithContacts()
2134 $this->markTestIncomplete();
2138 * Test the api_friendica_group_show() function.
2142 public function testApiFriendicaGroupShow()
2144 $this->markTestIncomplete();
2148 * Test the api_friendica_group_delete() function.
2152 public function testApiFriendicaGroupDelete()
2154 $this->markTestIncomplete();
2158 * Test the api_lists_destroy() function.
2162 public function testApiListsDestroy()
2164 $this->markTestIncomplete();
2168 * Test the group_create() function.
2172 public function testGroupCreate()
2174 $this->markTestIncomplete();
2178 * Test the api_friendica_group_create() function.
2182 public function testApiFriendicaGroupCreate()
2184 $this->markTestIncomplete();
2188 * Test the api_lists_create() function.
2192 public function testApiListsCreate()
2194 $this->markTestIncomplete();
2198 * Test the api_friendica_group_update() function.
2202 public function testApiFriendicaGroupUpdate()
2204 $this->markTestIncomplete();
2208 * Test the api_lists_update() function.
2212 public function testApiListsUpdate()
2214 $this->markTestIncomplete();
2218 * Test the api_friendica_activity() function.
2222 public function testApiFriendicaActivity()
2224 $this->markTestIncomplete();
2228 * Test the api_friendica_notification_seen() function.
2232 public function testApiFriendicaNotificationSeen()
2234 $this->markTestIncomplete();
2238 * Test the api_friendica_direct_messages_setseen() function.
2242 public function testApiFriendicaDirectMessagesSetseen()
2244 $this->markTestIncomplete();
2248 * Test the api_friendica_direct_messages_search() function.
2252 public function testApiFriendicaDirectMessagesSearch()
2254 $this->markTestIncomplete();