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\Model\Post;
14 use Friendica\Module\Api\ApiResponse;
15 use Friendica\Module\Api\Twitter\Media\Upload;
16 use Friendica\Module\BaseApi;
17 use Friendica\Network\HTTPException;
18 use Friendica\Security\BasicAuth;
19 use Friendica\Test\FixtureTest;
20 use Friendica\Util\Arrays;
21 use Friendica\Util\DateTimeFormat;
22 use Friendica\Util\Temporal;
23 use Monolog\Handler\TestHandler;
25 require_once __DIR__ . '/../../include/api.php';
28 * Tests for the API functions.
30 * Functions that use header() need to be tested in a separate process.
31 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
33 * @backupGlobals enabled
35 class ApiTest extends FixtureTest
38 * @var TestHandler Can handle log-outputs
45 protected $friendUser;
49 protected $wrongUserId;
54 /** @var IManageConfigValues */
58 * Create variables used by tests.
60 protected function setUp() : void
62 global $API, $called_api;
68 /** @var IManageConfigValues $config */
69 $this->config = $this->dice->create(IManageConfigValues::class);
71 $this->config->set('system', 'url', 'http://localhost');
72 $this->config->set('system', 'hostname', 'localhost');
73 $this->config->set('system', 'worker_dont_fork', true);
76 $this->config->set('config', 'hostname', 'localhost');
77 $this->config->set('system', 'throttle_limit_day', 100);
78 $this->config->set('system', 'throttle_limit_week', 100);
79 $this->config->set('system', 'throttle_limit_month', 100);
80 $this->config->set('system', 'theme', 'system_theme');
84 $this->app = DI::app();
86 DI::args()->setArgc(1);
88 // User data that the test database is populated with
91 'name' => 'Self contact',
92 'nick' => 'selfcontact',
93 'nurl' => 'http://localhost/profile/selfcontact'
97 'name' => 'Friend contact',
98 'nick' => 'friendcontact',
99 'nurl' => 'http://localhost/profile/friendcontact'
103 'name' => 'othercontact',
104 'nick' => 'othercontact',
105 'nurl' => 'http://localhost/profile/othercontact'
108 // User ID that we know is not in the database
109 $this->wrongUserId = 666;
111 DI::session()->start();
113 // Most API require login so we force the session
115 'authenticated' => true,
116 'uid' => $this->selfUser['id']
118 BasicAuth::setCurrentUserID($this->selfUser['id']);
122 * Assert that an user array contains expected keys.
124 * @param array $user User array
128 private function assertSelfUser(array $user)
130 self::assertEquals($this->selfUser['id'], $user['uid']);
131 self::assertEquals($this->selfUser['id'], $user['cid']);
132 self::assertEquals(1, $user['self']);
133 self::assertEquals('DFRN', $user['location']);
134 self::assertEquals($this->selfUser['name'], $user['name']);
135 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
136 self::assertEquals('dfrn', $user['network']);
137 self::assertTrue($user['verified']);
141 * Assert that an user array contains expected keys.
143 * @param array $user User array
147 private function assertOtherUser(array $user = [])
149 self::assertEquals($this->otherUser['id'], $user['id']);
150 self::assertEquals($this->otherUser['id'], $user['id_str']);
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 // self::assertEquals(false, api_user());
241 * Test the api_source() function.
245 public function testApiSource()
247 self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
251 * Test the api_source() function with a Twidere user agent.
255 public function testApiSourceWithTwidere()
257 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
258 self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
262 * Test the api_source() function with a GET parameter.
266 public function testApiSourceWithGet()
268 $_REQUEST['source'] = 'source_name';
269 self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
273 * Test the api_date() function.
277 public function testApiDate()
279 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
283 * Test the api_register_func() function.
287 public function testApiRegisterFunc()
299 self::assertTrue(is_callable($API['api_path']['func']));
303 * Test the BasicAuth::getCurrentUserID() function without any login.
305 * @runInSeparateProcess
306 * @preserveGlobalState disabled
307 * @preserveGlobalState disabled
309 public function testApiLoginWithoutLogin()
311 BasicAuth::setCurrentUserID();
312 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
313 BasicAuth::getCurrentUserID(true);
317 * Test the BasicAuth::getCurrentUserID() function with a bad login.
319 * @runInSeparateProcess
320 * @preserveGlobalState disabled
321 * @preserveGlobalState disabled
323 public function testApiLoginWithBadLogin()
325 BasicAuth::setCurrentUserID();
326 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
327 $_SERVER['PHP_AUTH_USER'] = 'user@server';
328 BasicAuth::getCurrentUserID(true);
332 * Test the BasicAuth::getCurrentUserID() function with oAuth.
336 public function testApiLoginWithOauth()
338 $this->markTestIncomplete('Can we test this easily?');
342 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
346 public function testApiLoginWithAddonAuth()
348 $this->markTestIncomplete('Can we test this easily?');
352 * Test the BasicAuth::getCurrentUserID() function with a correct login.
354 * @runInSeparateProcess
355 * @preserveGlobalState disabled
356 * @doesNotPerformAssertions
358 public function testApiLoginWithCorrectLogin()
360 BasicAuth::setCurrentUserID();
361 $_SERVER['PHP_AUTH_USER'] = 'Test user';
362 $_SERVER['PHP_AUTH_PW'] = 'password';
363 BasicAuth::getCurrentUserID(true);
367 * Test the BasicAuth::getCurrentUserID() function with a remote user.
369 * @runInSeparateProcess
370 * @preserveGlobalState disabled
372 public function testApiLoginWithRemoteUser()
374 BasicAuth::setCurrentUserID();
375 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
376 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
377 BasicAuth::getCurrentUserID(true);
381 * Test the api_call() function.
383 * @runInSeparateProcess
384 * @preserveGlobalState disabled
386 public function testApiCall()
390 'method' => 'method',
391 'func' => function () {
392 return ['data' => ['some_data']];
395 $_SERVER['REQUEST_METHOD'] = 'method';
396 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
397 $_GET['callback'] = 'callback_name';
400 'callback_name(["some_data"])',
401 api_call('api_path', 'json')
406 * Test the api_call() function with the profiled enabled.
408 * @runInSeparateProcess
409 * @preserveGlobalState disabled
411 public function testApiCallWithProfiler()
415 'method' => 'method',
416 'func' => function () {
417 return ['data' => ['some_data']];
421 $_SERVER['REQUEST_METHOD'] = 'method';
422 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
424 $this->config->set('system', 'profiler', true);
425 $this->config->set('rendertime', 'callstack', true);
426 $this->app->callstack = [
427 'database' => ['some_function' => 200],
428 'database_write' => ['some_function' => 200],
429 'cache' => ['some_function' => 200],
430 'cache_write' => ['some_function' => 200],
431 'network' => ['some_function' => 200]
436 api_call('api_path', 'json')
441 * Test the api_call() function with a JSON result.
443 * @runInSeparateProcess
444 * @preserveGlobalState disabled
446 public function testApiCallWithJson()
450 'method' => 'method',
451 'func' => function () {
452 return ['data' => ['some_data']];
455 $_SERVER['REQUEST_METHOD'] = 'method';
456 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
460 api_call('api_path.json', 'json')
465 * Test the api_call() function with an XML result.
467 * @runInSeparateProcess
468 * @preserveGlobalState disabled
470 public function testApiCallWithXml()
474 'method' => 'method',
475 'func' => function () {
479 $_SERVER['REQUEST_METHOD'] = 'method';
480 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
482 $args = DI::args()->determine($_SERVER, $_GET);
486 api_call('api_path.xml', 'xml')
491 * Test the api_call() function with an RSS result.
493 * @runInSeparateProcess
494 * @preserveGlobalState disabled
496 public function testApiCallWithRss()
500 'method' => 'method',
501 'func' => function () {
505 $_SERVER['REQUEST_METHOD'] = 'method';
506 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
509 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
511 api_call('api_path.rss', 'rss')
516 * Test the api_call() function with an Atom result.
518 * @runInSeparateProcess
519 * @preserveGlobalState disabled
521 public function testApiCallWithAtom()
525 'method' => 'method',
526 'func' => function () {
530 $_SERVER['REQUEST_METHOD'] = 'method';
531 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
534 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
536 api_call('api_path.atom', 'atom')
541 * Test the api_rss_extra() function.
545 public function testApiRssExtra()
548 $user_info = ['url' => 'user_url', 'lang' => 'en'];
549 $result = api_rss_extra([], $user_info);
550 self::assertEquals($user_info, $result['$user']);
551 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
552 self::assertArrayHasKey('self', $result['$rss']);
553 self::assertArrayHasKey('base', $result['$rss']);
554 self::assertArrayHasKey('updated', $result['$rss']);
555 self::assertArrayHasKey('atom_updated', $result['$rss']);
556 self::assertArrayHasKey('language', $result['$rss']);
557 self::assertArrayHasKey('logo', $result['$rss']);
562 * Test the api_rss_extra() function without any user info.
566 public function testApiRssExtraWithoutUserInfo()
569 $result = api_rss_extra([], null);
570 self::assertIsArray($result['$user']);
571 self::assertArrayHasKey('alternate', $result['$rss']);
572 self::assertArrayHasKey('self', $result['$rss']);
573 self::assertArrayHasKey('base', $result['$rss']);
574 self::assertArrayHasKey('updated', $result['$rss']);
575 self::assertArrayHasKey('atom_updated', $result['$rss']);
576 self::assertArrayHasKey('language', $result['$rss']);
577 self::assertArrayHasKey('logo', $result['$rss']);
582 * Test the api_get_user() function.
586 public function testApiGetUser()
588 // $user = api_get_user();
589 // self::assertSelfUser($user);
590 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
591 // self::assertEquals('6fdbe8', $user['profile_link_color']);
592 // self::assertEquals('ededed', $user['profile_background_color']);
596 * Test the api_get_user() function with a Frio schema.
600 public function testApiGetUserWithFrioSchema()
602 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
603 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
604 // $user = api_get_user();
605 // self::assertSelfUser($user);
606 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
607 // self::assertEquals('6fdbe8', $user['profile_link_color']);
608 // self::assertEquals('ededed', $user['profile_background_color']);
612 * Test the api_get_user() function with an empty Frio schema.
616 public function testApiGetUserWithEmptyFrioSchema()
618 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
619 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
620 // $user = api_get_user();
621 // self::assertSelfUser($user);
622 // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
623 // self::assertEquals('6fdbe8', $user['profile_link_color']);
624 // self::assertEquals('ededed', $user['profile_background_color']);
628 * Test the api_get_user() function with a custom Frio schema.
632 public function testApiGetUserWithCustomFrioSchema()
634 // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
635 // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
636 // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
637 // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
638 // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
639 // $user = api_get_user();
640 // self::assertSelfUser($user);
641 // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
642 // self::assertEquals('123456', $user['profile_link_color']);
643 // self::assertEquals('123456', $user['profile_background_color']);
647 * Test the api_get_user() function with an user that is not allowed to use the API.
649 * @runInSeparateProcess
650 * @preserveGlobalState disabled
652 public function testApiGetUserWithoutApiUser()
654 // api_get_user() with empty parameters is not used anymore
656 $_SERVER['PHP_AUTH_USER'] = 'Test user';
657 $_SERVER['PHP_AUTH_PW'] = 'password';
658 BasicAuth::setCurrentUserID();
659 self::assertFalse(api_get_user());
664 * Test the api_get_user() function with an user ID in a GET parameter.
668 public function testApiGetUserWithGetId()
670 // self::assertOtherUser(api_get_user());
674 * Test the api_get_user() function with a wrong user ID in a GET parameter.
678 public function testApiGetUserWithWrongGetId()
680 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
681 // self::assertOtherUser(api_get_user());
685 * Test the api_get_user() function with an user name in a GET parameter.
689 public function testApiGetUserWithGetName()
691 // self::assertSelfUser(api_get_user());
695 * Test the api_get_user() function with a profile URL in a GET parameter.
699 public function testApiGetUserWithGetUrl()
701 // self::assertSelfUser(api_get_user());
705 * Test the api_get_user() function with an user ID in the API path.
709 public function testApiGetUserWithNumericCalledApi()
711 // global $called_api;
712 // $called_api = ['api_path'];
713 // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
714 // self::assertOtherUser(api_get_user());
718 * Test the api_get_user() function with the $called_api global variable.
722 public function testApiGetUserWithCalledApi()
724 // global $called_api;
725 // $called_api = ['api', 'api_path'];
726 // self::assertSelfUser(api_get_user());
730 * Test the Arrays::walkRecursive() function.
734 public function testApiWalkRecursive()
739 Arrays::walkRecursive(
742 // Should we test this with a callback that actually does something?
750 * Test the Arrays::walkRecursive() function with an array.
754 public function testApiWalkRecursiveWithArray()
756 $array = [['item1'], ['item2']];
759 Arrays::walkRecursive(
762 // Should we test this with a callback that actually does something?
770 * Test the BaseApi::reformatXML() function.
774 public function testApiReformatXml()
778 self::assertTrue(ApiResponse::reformatXML($item, $key));
779 self::assertEquals('true', $item);
783 * Test the BaseApi::reformatXML() function with a statusnet_api key.
787 public function testApiReformatXmlWithStatusnetKey()
790 $key = 'statusnet_api';
791 self::assertTrue(ApiResponse::reformatXML($item, $key));
792 self::assertEquals('statusnet:api', $key);
796 * Test the BaseApi::reformatXML() function with a friendica_api key.
800 public function testApiReformatXmlWithFriendicaKey()
803 $key = 'friendica_api';
804 self::assertTrue(ApiResponse::reformatXML($item, $key));
805 self::assertEquals('friendica:api', $key);
809 * Test the BaseApi::createXML() function.
813 public function testApiCreateXml()
816 '<?xml version="1.0"?>' . "\n" .
817 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
818 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
819 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
820 ' <data>some_data</data>' . "\n" .
821 '</root_element>' . "\n",
822 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
827 * Test the BaseApi::createXML() function without any XML namespace.
831 public function testApiCreateXmlWithoutNamespaces()
834 '<?xml version="1.0"?>' . "\n" .
836 ' <data>some_data</data>' . "\n" .
838 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
843 * Test the BaseApi::formatData() function.
847 public function testApiFormatData()
849 $data = ['some_data'];
850 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
854 * Test the BaseApi::formatData() function with an XML result.
858 public function testApiFormatDataWithXml()
861 '<?xml version="1.0"?>' . "\n" .
862 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
863 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
864 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
865 ' <data>some_data</data>' . "\n" .
866 '</root_element>' . "\n",
867 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
872 * Test the api_statuses_mediap() function.
876 public function testApiStatusesMediap()
878 DI::args()->setArgc(2);
886 'tmp_name' => $this->getTempImage(),
887 'name' => 'spacer.png',
888 'type' => 'image/png'
891 $_GET['status'] = '<b>Status content</b>';
893 $result = api_statuses_mediap('json');
894 self::assertStatus($result['status']);
898 * Test the api_statuses_mediap() function without an authenticated user.
902 public function testApiStatusesMediapWithoutAuthenticatedUser()
904 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
905 BasicAuth::setCurrentUserID();
906 $_SESSION['authenticated'] = false;
907 api_statuses_mediap('json');
911 * Test the api_statuses_update() function.
915 public function testApiStatusesUpdate()
917 $_REQUEST['status'] = 'Status content #friendica';
918 $_REQUEST['in_reply_to_status_id'] = -1;
919 $_REQUEST['lat'] = 48;
920 $_REQUEST['long'] = 7;
927 'tmp_name' => $this->getTempImage(),
928 'name' => 'spacer.png',
929 'type' => 'image/png'
933 $result = api_statuses_update('json');
934 self::assertStatus($result['status']);
938 * Test the api_statuses_update() function with an HTML status.
942 public function testApiStatusesUpdateWithHtml()
944 $_REQUEST['htmlstatus'] = '<b>Status content</b>';
946 $result = api_statuses_update('json');
947 self::assertStatus($result['status']);
951 * Test the api_statuses_update() function without an authenticated user.
955 public function testApiStatusesUpdateWithoutAuthenticatedUser()
957 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
958 BasicAuth::setCurrentUserID();
959 $_SESSION['authenticated'] = false;
960 api_statuses_update('json');
964 * Test the api_statuses_update() function with a parent status.
968 public function testApiStatusesUpdateWithParent()
970 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
974 * Test the api_statuses_update() function with a media_ids parameter.
978 public function testApiStatusesUpdateWithMediaIds()
980 $this->markTestIncomplete();
984 * Test the api_statuses_update() function with the throttle limit reached.
988 public function testApiStatusesUpdateWithDayThrottleReached()
990 $this->markTestIncomplete();
994 * Test the \Friendica\Module\Api\Twitter\Media\Upload module.
995 * @runInSeparateProcess
996 * @preserveGlobalState disabled
998 public function testApiMediaUpload()
1000 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1001 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1005 * Test the \Friendica\Module\Api\Twitter\Media\Upload module without an authenticated user.
1009 public function testApiMediaUploadWithoutAuthenticatedUser()
1011 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1012 BasicAuth::setCurrentUserID();
1013 $_SESSION['authenticated'] = false;
1014 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1018 * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an invalid uploaded media.
1022 public function testApiMediaUploadWithMedia()
1024 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1028 'tmp_name' => 'tmp_name'
1031 (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1035 * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an valid uploaded media.
1039 public function testApiMediaUploadWithValidMedia()
1047 'tmp_name' => $this->getTempImage(),
1048 'name' => 'spacer.png',
1049 'type' => 'image/png'
1053 $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
1054 $media = json_decode($response->getBody(), true);
1056 self::assertEquals('image/png', $media['image']['image_type']);
1057 self::assertEquals(1, $media['image']['w']);
1058 self::assertEquals(1, $media['image']['h']);
1059 self::assertNotEmpty($media['image']['friendica_preview_url']);
1063 * Test the api_statuses_repeat() function.
1067 public function testApiStatusesRepeat()
1069 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1070 api_statuses_repeat('json');
1074 * Test the api_statuses_repeat() function without an authenticated user.
1078 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1080 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1081 BasicAuth::setCurrentUserID();
1082 $_SESSION['authenticated'] = false;
1083 api_statuses_repeat('json');
1087 * Test the api_statuses_repeat() function with an ID.
1091 public function testApiStatusesRepeatWithId()
1093 DI::args()->setArgv(['', '', '', 1]);
1094 $result = api_statuses_repeat('json');
1095 self::assertStatus($result['status']);
1097 // Also test with a shared status
1098 DI::args()->setArgv(['', '', '', 5]);
1099 $result = api_statuses_repeat('json');
1100 self::assertStatus($result['status']);
1104 * Test the api_favorites_create_destroy() function.
1108 public function testApiFavoritesCreateDestroy()
1110 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1111 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
1112 // api_favorites_create_destroy('json');
1116 * Test the api_favorites_create_destroy() function with an invalid ID.
1120 public function testApiFavoritesCreateDestroyWithInvalidId()
1122 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1123 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
1124 // api_favorites_create_destroy('json');
1128 * Test the api_favorites_create_destroy() function with an invalid action.
1132 public function testApiFavoritesCreateDestroyWithInvalidAction()
1134 // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1135 // DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
1136 // $_REQUEST['id'] = 1;
1137 // api_favorites_create_destroy('json');
1141 * Test the api_favorites_create_destroy() function with the create action.
1145 public function testApiFavoritesCreateDestroyWithCreateAction()
1147 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1148 // $_REQUEST['id'] = 3;
1149 // $result = api_favorites_create_destroy('json');
1150 // self::assertStatus($result['status']);
1154 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1158 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1160 // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
1161 // $_REQUEST['id'] = 3;
1162 // $result = api_favorites_create_destroy('rss');
1163 // self::assertXml($result, 'status');
1167 * Test the api_favorites_create_destroy() function with the destroy action.
1171 public function testApiFavoritesCreateDestroyWithDestroyAction()
1173 // DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
1174 // $_REQUEST['id'] = 3;
1175 // $result = api_favorites_create_destroy('json');
1176 // self::assertStatus($result['status']);
1180 * Test the api_favorites_create_destroy() function without an authenticated user.
1184 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1187 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1188 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
1189 BasicAuth::setCurrentUserID();
1190 $_SESSION['authenticated'] = false;
1191 api_favorites_create_destroy('json');
1198 * Test the api_format_messages() function.
1202 public function testApiFormatMessages()
1204 $result = api_format_messages(
1205 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1206 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1207 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
1209 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
1210 self::assertEquals(1, $result['id']);
1211 self::assertEquals(2, $result['recipient_id']);
1212 self::assertEquals(3, $result['sender_id']);
1213 self::assertEquals('recipient_name', $result['recipient_screen_name']);
1214 self::assertEquals('sender_name', $result['sender_screen_name']);
1218 * Test the api_format_messages() function with HTML.
1222 public function testApiFormatMessagesWithHtmlText()
1224 $_GET['getText'] = 'html';
1225 $result = api_format_messages(
1226 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1227 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1228 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1230 self::assertEquals('item_title', $result['title']);
1231 self::assertEquals('<strong>item_body</strong>', $result['text']);
1235 * Test the api_format_messages() function with plain text.
1239 public function testApiFormatMessagesWithPlainText()
1241 $_GET['getText'] = 'plain';
1242 $result = api_format_messages(
1243 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1244 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1245 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1247 self::assertEquals('item_title', $result['title']);
1248 self::assertEquals('item_body', $result['text']);
1252 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
1256 public function testApiFormatMessagesWithoutUserObjects()
1258 $_GET['getUserObjects'] = 'false';
1259 $result = api_format_messages(
1260 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1261 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
1262 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
1264 self::assertTrue(!isset($result['sender']));
1265 self::assertTrue(!isset($result['recipient']));
1269 * Test the api_convert_item() function.
1273 public function testApiConvertItem()
1276 $result = api_convert_item(
1278 'network' => 'feed',
1279 'title' => 'item_title',
1281 // We need a long string to test that it is correctly cut
1282 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
1283 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
1284 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
1285 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
1286 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
1287 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
1288 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
1289 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
1290 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
1291 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
1292 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
1293 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
1294 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
1295 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
1296 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
1297 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
1298 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
1299 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
1300 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
1301 'repellat officia illum quos impedit quam iste esse unde qui ' .
1302 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
1303 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
1304 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
1305 'plink' => 'item_plink'
1308 self::assertStringStartsWith('item_title', $result['text']);
1309 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
1314 * Test the api_convert_item() function with an empty item body.
1318 public function testApiConvertItemWithoutBody()
1321 $result = api_convert_item(
1323 'network' => 'feed',
1324 'title' => 'item_title',
1327 'plink' => 'item_plink'
1330 self::assertEquals("item_title", $result['text']);
1331 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
1336 * Test the api_convert_item() function with the title in the body.
1340 public function testApiConvertItemWithTitleInBody()
1343 $result = api_convert_item(
1345 'title' => 'item_title',
1346 'body' => 'item_title item_body',
1350 self::assertEquals('item_title item_body', $result['text']);
1351 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
1356 * Test the api_get_attachments() function.
1360 public function testApiGetAttachments()
1363 // self::assertEmpty(api_get_attachments($body, 0));
1367 * Test the api_get_attachments() function with an img tag.
1371 public function testApiGetAttachmentsWithImage()
1373 // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
1374 // self::assertIsArray(api_get_attachments($body, 0));
1378 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
1382 public function testApiGetAttachmentsWithImageAndAndStatus()
1384 // $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
1385 // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
1386 // self::assertIsArray(api_get_attachments($body, 0));
1390 * Test the api_get_entitities() function.
1394 public function testApiGetEntitities()
1397 // self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
1401 * Test the api_get_entitities() function with the include_entities parameter.
1405 public function testApiGetEntititiesWithIncludeEntities()
1408 $_REQUEST['include_entities'] = 'true';
1410 $result = api_get_entitities($text, 'bbcode', 0);
1411 self::assertIsArray($result['hashtags']);
1412 self::assertIsArray($result['symbols']);
1413 self::assertIsArray($result['urls']);
1414 self::assertIsArray($result['user_mentions']);
1419 * Test the api_format_items_embeded_images() function.
1423 public function testApiFormatItemsEmbededImages()
1427 'text ' . DI::baseUrl() . '/display/item_guid',
1428 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
1434 * Test the api_format_items_activities() function.
1438 public function testApiFormatItemsActivities()
1440 $item = ['uid' => 0, 'uri-id' => 1];
1441 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
1442 self::assertArrayHasKey('like', $result);
1443 self::assertArrayHasKey('dislike', $result);
1444 self::assertArrayHasKey('attendyes', $result);
1445 self::assertArrayHasKey('attendno', $result);
1446 self::assertArrayHasKey('attendmaybe', $result);
1450 * Test the api_format_items_activities() function with an XML result.
1454 public function testApiFormatItemsActivitiesWithXml()
1456 $item = ['uid' => 0, 'uri-id' => 1];
1457 $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
1458 self::assertArrayHasKey('friendica:like', $result);
1459 self::assertArrayHasKey('friendica:dislike', $result);
1460 self::assertArrayHasKey('friendica:attendyes', $result);
1461 self::assertArrayHasKey('friendica:attendno', $result);
1462 self::assertArrayHasKey('friendica:attendmaybe', $result);
1466 * Test the api_format_items() function.
1467 * @doesNotPerformAssertions
1469 public function testApiFormatItems()
1472 $items = Post::selectToArray([], ['uid' => 42]);
1473 foreach ($items as $item) {
1474 $status = api_format_item($item);
1475 self::assertStatus($status);
1481 * Test the api_format_items() function with an XML result.
1482 * @doesNotPerformAssertions
1484 public function testApiFormatItemsWithXml()
1487 $items = Post::selectToArray([], ['uid' => 42]);
1488 foreach ($items as $item) {
1489 $status = api_format_item($item, 'xml');
1490 self::assertStatus($status);
1496 * Test the api_lists_list() function.
1500 public function testApiListsList()
1502 $result = api_lists_list('json');
1503 self::assertEquals(['lists_list' => []], $result);
1507 * Test the api_lists_ownerships() function.
1511 public function testApiListsOwnerships()
1513 $result = api_lists_ownerships('json');
1514 foreach ($result['lists']['lists'] as $list) {
1515 self::assertList($list);
1520 * Test the api_lists_ownerships() function without an authenticated user.
1524 public function testApiListsOwnershipsWithoutAuthenticatedUser()
1526 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1527 BasicAuth::setCurrentUserID();
1528 $_SESSION['authenticated'] = false;
1529 api_lists_ownerships('json');
1533 * Test the api_statuses_f() function.
1537 public function testApiStatusesFWithIncoming()
1539 // $result = api_statuses_f('incoming');
1540 // self::assertArrayHasKey('user', $result);
1545 * Test the api_direct_messages_new() function.
1549 public function testApiDirectMessagesNew()
1551 $result = api_direct_messages_new('json');
1552 self::assertNull($result);
1556 * Test the api_direct_messages_new() function without an authenticated user.
1560 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
1562 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1563 BasicAuth::setCurrentUserID();
1564 $_SESSION['authenticated'] = false;
1565 api_direct_messages_new('json');
1569 * Test the api_direct_messages_new() function with an user ID.
1573 public function testApiDirectMessagesNewWithUserId()
1575 $_POST['text'] = 'message_text';
1576 $_REQUEST['user_id'] = $this->otherUser['id'];
1577 $result = api_direct_messages_new('json');
1578 self::assertEquals(['direct_message' => ['error' => -1]], $result);
1582 * Test the api_direct_messages_new() function with a screen name.
1586 public function testApiDirectMessagesNewWithScreenName()
1588 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1589 $_POST['text'] = 'message_text';
1590 $_REQUEST['user_id'] = $this->friendUser['id'];
1591 $result = api_direct_messages_new('json');
1592 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1593 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1594 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1598 * Test the api_direct_messages_new() function with a title.
1602 public function testApiDirectMessagesNewWithTitle()
1604 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1605 $_POST['text'] = 'message_text';
1606 $_REQUEST['user_id'] = $this->friendUser['id'];
1607 $_REQUEST['title'] = 'message_title';
1608 $result = api_direct_messages_new('json');
1609 self::assertStringContainsString('message_text', $result['direct_message']['text']);
1610 self::assertStringContainsString('message_title', $result['direct_message']['text']);
1611 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
1612 self::assertEquals(1, $result['direct_message']['friendica_seen']);
1616 * Test the api_direct_messages_new() function with an RSS result.
1620 public function testApiDirectMessagesNewWithRss()
1622 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1623 $_POST['text'] = 'message_text';
1624 $_REQUEST['user_id'] = $this->friendUser['id'];
1625 $result = api_direct_messages_new('rss');
1626 self::assertXml($result, 'direct-messages');
1630 * Test the api_direct_messages_destroy() function.
1634 public function testApiDirectMessagesDestroy()
1636 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1637 api_direct_messages_destroy('json');
1641 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
1645 public function testApiDirectMessagesDestroyWithVerbose()
1647 $_GET['friendica_verbose'] = 'true';
1648 $result = api_direct_messages_destroy('json');
1652 'result' => 'error',
1653 'message' => 'message id or parenturi not specified'
1661 * Test the api_direct_messages_destroy() function without an authenticated user.
1665 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
1667 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1668 BasicAuth::setCurrentUserID();
1669 $_SESSION['authenticated'] = false;
1670 api_direct_messages_destroy('json');
1674 * Test the api_direct_messages_destroy() function with a non-zero ID.
1678 public function testApiDirectMessagesDestroyWithId()
1680 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1681 $_REQUEST['id'] = 1;
1682 api_direct_messages_destroy('json');
1686 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
1690 public function testApiDirectMessagesDestroyWithIdAndVerbose()
1692 $_REQUEST['id'] = 1;
1693 $_REQUEST['friendica_parenturi'] = 'parent_uri';
1694 $_GET['friendica_verbose'] = 'true';
1695 $result = api_direct_messages_destroy('json');
1699 'result' => 'error',
1700 'message' => 'message id not in database'
1708 * Test the api_direct_messages_destroy() function with a non-zero ID.
1712 public function testApiDirectMessagesDestroyWithCorrectId()
1714 $this->markTestIncomplete('We need to add a dataset for this.');
1718 * Test the api_direct_messages_box() function.
1722 public function testApiDirectMessagesBoxWithSentbox()
1724 $_REQUEST['page'] = -1;
1725 $_REQUEST['max_id'] = 10;
1726 $result = api_direct_messages_box('json', 'sentbox', 'false');
1727 self::assertArrayHasKey('direct_message', $result);
1731 * Test the api_direct_messages_box() function.
1735 public function testApiDirectMessagesBoxWithConversation()
1737 $result = api_direct_messages_box('json', 'conversation', 'false');
1738 self::assertArrayHasKey('direct_message', $result);
1742 * Test the api_direct_messages_box() function.
1746 public function testApiDirectMessagesBoxWithAll()
1748 $result = api_direct_messages_box('json', 'all', 'false');
1749 self::assertArrayHasKey('direct_message', $result);
1753 * Test the api_direct_messages_box() function.
1757 public function testApiDirectMessagesBoxWithInbox()
1759 $result = api_direct_messages_box('json', 'inbox', 'false');
1760 self::assertArrayHasKey('direct_message', $result);
1764 * Test the api_direct_messages_box() function.
1768 public function testApiDirectMessagesBoxWithVerbose()
1770 $result = api_direct_messages_box('json', 'sentbox', 'true');
1774 'result' => 'error',
1775 'message' => 'no mails available'
1783 * Test the api_direct_messages_box() function with a RSS result.
1787 public function testApiDirectMessagesBoxWithRss()
1789 $result = api_direct_messages_box('rss', 'sentbox', 'false');
1790 self::assertXml($result, 'direct-messages');
1794 * Test the api_direct_messages_box() function without an authenticated user.
1798 public function testApiDirectMessagesBoxWithUnallowedUser()
1800 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1801 BasicAuth::setCurrentUserID();
1802 api_direct_messages_box('json', 'sentbox', 'false');
1806 * Test the api_direct_messages_sentbox() function.
1810 public function testApiDirectMessagesSentbox()
1812 $result = api_direct_messages_sentbox('json');
1813 self::assertArrayHasKey('direct_message', $result);
1817 * Test the api_direct_messages_inbox() function.
1821 public function testApiDirectMessagesInbox()
1823 $result = api_direct_messages_inbox('json');
1824 self::assertArrayHasKey('direct_message', $result);
1828 * Test the api_direct_messages_all() function.
1832 public function testApiDirectMessagesAll()
1834 $result = api_direct_messages_all('json');
1835 self::assertArrayHasKey('direct_message', $result);
1839 * Test the api_direct_messages_conversation() function.
1843 public function testApiDirectMessagesConversation()
1845 $result = api_direct_messages_conversation('json');
1846 self::assertArrayHasKey('direct_message', $result);
1850 * Test the api_oauth_request_token() function.
1854 public function testApiOauthRequestToken()
1856 $this->markTestIncomplete('exit() kills phpunit as well');
1860 * Test the api_oauth_access_token() function.
1864 public function testApiOauthAccessToken()
1866 $this->markTestIncomplete('exit() kills phpunit as well');
1870 * Test the api_fr_photos_list() function.
1874 public function testApiFrPhotosList()
1876 $result = api_fr_photos_list('json');
1877 self::assertArrayHasKey('photo', $result);
1881 * Test the api_fr_photos_list() function without an authenticated user.
1885 public function testApiFrPhotosListWithoutAuthenticatedUser()
1887 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1888 BasicAuth::setCurrentUserID();
1889 $_SESSION['authenticated'] = false;
1890 api_fr_photos_list('json');
1894 * Test the api_fr_photo_create_update() function.
1896 public function testApiFrPhotoCreateUpdate()
1898 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1899 api_fr_photo_create_update('json');
1903 * Test the api_fr_photo_create_update() function without an authenticated user.
1907 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
1909 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1910 BasicAuth::setCurrentUserID();
1911 $_SESSION['authenticated'] = false;
1912 api_fr_photo_create_update('json');
1916 * Test the api_fr_photo_create_update() function with an album name.
1920 public function testApiFrPhotoCreateUpdateWithAlbum()
1922 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1923 $_REQUEST['album'] = 'album_name';
1924 api_fr_photo_create_update('json');
1928 * Test the api_fr_photo_create_update() function with the update mode.
1932 public function testApiFrPhotoCreateUpdateWithUpdate()
1934 $this->markTestIncomplete('We need to create a dataset for this');
1938 * Test the api_fr_photo_create_update() function with an uploaded file.
1942 public function testApiFrPhotoCreateUpdateWithFile()
1944 $this->markTestIncomplete();
1948 * Test the api_fr_photo_detail() function.
1952 public function testApiFrPhotoDetail()
1954 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1955 api_fr_photo_detail('json');
1959 * Test the api_fr_photo_detail() function without an authenticated user.
1963 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
1965 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
1966 BasicAuth::setCurrentUserID();
1967 $_SESSION['authenticated'] = false;
1968 api_fr_photo_detail('json');
1972 * Test the api_fr_photo_detail() function with a photo ID.
1976 public function testApiFrPhotoDetailWithPhotoId()
1978 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1979 $_REQUEST['photo_id'] = 1;
1980 api_fr_photo_detail('json');
1984 * Test the api_fr_photo_detail() function with a correct photo ID.
1988 public function testApiFrPhotoDetailCorrectPhotoId()
1990 $this->markTestIncomplete('We need to create a dataset for this.');
1994 * Test the api_account_update_profile_image() function.
1998 public function testApiAccountUpdateProfileImage()
2000 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2001 api_account_update_profile_image('json');
2005 * Test the api_account_update_profile_image() function without an authenticated user.
2009 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
2011 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
2012 BasicAuth::setCurrentUserID();
2013 $_SESSION['authenticated'] = false;
2014 api_account_update_profile_image('json');
2018 * Test the api_account_update_profile_image() function with an uploaded file.
2022 public function testApiAccountUpdateProfileImageWithUpload()
2024 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2025 $this->markTestIncomplete();
2029 * Test the check_acl_input() function.
2033 public function testCheckAclInput()
2035 $result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
2036 // Where does this result come from?
2037 self::assertEquals(1, $result);
2041 * Test the check_acl_input() function with an empty ACL string.
2045 public function testCheckAclInputWithEmptyAclString()
2047 $result = check_acl_input(' ', BaseApi::getCurrentUserID());
2048 self::assertFalse($result);
2052 * Test the save_media_to_database() function.
2056 public function testSaveMediaToDatabase()
2058 $this->markTestIncomplete();
2062 * Test the post_photo_item() function.
2066 public function testPostPhotoItem()
2068 $this->markTestIncomplete();
2072 * Test the prepare_photo_data() function.
2076 public function testPreparePhotoData()
2078 $this->markTestIncomplete();
2082 * Test the api_share_as_retweet() function with a valid item.
2086 public function testApiShareAsRetweetWithValidItem()
2088 $this->markTestIncomplete();
2092 * Test the api_in_reply_to() function with a valid item.
2096 public function testApiInReplyToWithValidItem()
2098 $this->markTestIncomplete();
2102 * Test the api_clean_plain_items() function.
2106 public function testApiCleanPlainItems()
2108 $_REQUEST['include_entities'] = 'true';
2109 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
2110 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
2114 * Test the api_best_nickname() function with contacts.
2118 public function testApiBestNicknameWithContacts()
2120 $this->markTestIncomplete();
2124 * Test the api_friendica_group_show() function.
2128 public function testApiFriendicaGroupShow()
2130 $this->markTestIncomplete();
2134 * Test the api_friendica_group_delete() function.
2138 public function testApiFriendicaGroupDelete()
2140 $this->markTestIncomplete();
2144 * Test the api_lists_destroy() function.
2148 public function testApiListsDestroy()
2150 $this->markTestIncomplete();
2154 * Test the group_create() function.
2158 public function testGroupCreate()
2160 $this->markTestIncomplete();
2164 * Test the api_friendica_group_create() function.
2168 public function testApiFriendicaGroupCreate()
2170 $this->markTestIncomplete();
2174 * Test the api_lists_create() function.
2178 public function testApiListsCreate()
2180 $this->markTestIncomplete();
2184 * Test the api_friendica_group_update() function.
2188 public function testApiFriendicaGroupUpdate()
2190 $this->markTestIncomplete();
2194 * Test the api_lists_update() function.
2198 public function testApiListsUpdate()
2200 $this->markTestIncomplete();
2204 * Test the api_friendica_activity() function.
2208 public function testApiFriendicaActivity()
2210 $this->markTestIncomplete();
2214 * Test the api_friendica_notification_seen() function.
2218 public function testApiFriendicaNotificationSeen()
2220 $this->markTestIncomplete();
2224 * Test the api_friendica_direct_messages_setseen() function.
2228 public function testApiFriendicaDirectMessagesSetseen()
2230 $this->markTestIncomplete();
2234 * Test the api_friendica_direct_messages_search() function.
2238 public function testApiFriendicaDirectMessagesSearch()
2240 $this->markTestIncomplete();