6 namespace Friendica\Test\legacy;
9 use Friendica\Core\Config\Capability\IManageConfigValues;
10 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
11 use Friendica\Core\Protocol;
13 use Friendica\Module\Api\ApiResponse;
14 use Friendica\Module\BaseApi;
15 use Friendica\Network\HTTPException;
16 use Friendica\Security\BasicAuth;
17 use Friendica\Test\FixtureTest;
18 use Friendica\Util\Arrays;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Temporal;
21 use Monolog\Handler\TestHandler;
23 require_once __DIR__ . '/../../include/api.php';
26 * Tests for the API functions.
28 * Functions that use header() need to be tested in a separate process.
29 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31 * @backupGlobals enabled
33 class ApiTest extends FixtureTest
36 * @var TestHandler Can handle log-outputs
43 protected $friendUser;
47 protected $wrongUserId;
52 /** @var IManageConfigValues */
56 * Create variables used by tests.
58 protected function setUp() : void
60 global $API, $called_api;
66 /** @var IManageConfigValues $config */
67 $this->config = $this->dice->create(IManageConfigValues::class);
69 $this->config->set('system', 'url', 'http://localhost');
70 $this->config->set('system', 'hostname', 'localhost');
71 $this->config->set('system', 'worker_dont_fork', true);
74 $this->config->set('config', 'hostname', 'localhost');
75 $this->config->set('system', 'throttle_limit_day', 100);
76 $this->config->set('system', 'throttle_limit_week', 100);
77 $this->config->set('system', 'throttle_limit_month', 100);
78 $this->config->set('system', 'theme', 'system_theme');
82 $this->app = DI::app();
84 DI::args()->setArgc(1);
86 // User data that the test database is populated with
89 'name' => 'Self contact',
90 'nick' => 'selfcontact',
91 'nurl' => 'http://localhost/profile/selfcontact'
95 'name' => 'Friend contact',
96 'nick' => 'friendcontact',
97 'nurl' => 'http://localhost/profile/friendcontact'
101 'name' => 'othercontact',
102 'nick' => 'othercontact',
103 'nurl' => 'http://localhost/profile/othercontact'
106 // User ID that we know is not in the database
107 $this->wrongUserId = 666;
109 DI::session()->start();
111 // Most API require login so we force the session
114 'authenticated' => true,
115 'uid' => $this->selfUser['id']
120 * Assert that an user array contains expected keys.
122 * @param array $user User array
126 private function assertSelfUser(array $user)
128 self::assertEquals($this->selfUser['id'], $user['uid']);
129 self::assertEquals($this->selfUser['id'], $user['cid']);
130 self::assertEquals(1, $user['self']);
131 self::assertEquals('DFRN', $user['location']);
132 self::assertEquals($this->selfUser['name'], $user['name']);
133 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
134 self::assertEquals('dfrn', $user['network']);
135 self::assertTrue($user['verified']);
139 * Assert that an user array contains expected keys.
141 * @param array $user User array
145 private function assertOtherUser(array $user = [])
147 self::assertEquals($this->otherUser['id'], $user['id']);
148 self::assertEquals($this->otherUser['id'], $user['id_str']);
149 self::assertEquals(0, $user['self']);
150 self::assertEquals($this->otherUser['name'], $user['name']);
151 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
152 self::assertFalse($user['verified']);
156 * Assert that a status array contains expected keys.
158 * @param array $status Status array
162 private function assertStatus(array $status = [])
164 self::assertIsString($status['text'] ?? '');
165 self::assertIsInt($status['id'] ?? '');
166 // We could probably do more checks here.
170 * Assert that a list array contains expected keys.
172 * @param array $list List array
176 private function assertList(array $list = [])
178 self::assertIsString($list['name']);
179 self::assertIsInt($list['id']);
180 self::assertIsString('string', $list['id_str']);
181 self::assertContains($list['mode'], ['public', 'private']);
182 // We could probably do more checks here.
186 * Assert that the string is XML and contain the root element.
188 * @param string $result XML string
189 * @param string $root_element Root element name
193 private function assertXml($result = '', $root_element = '')
195 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
196 self::assertStringContainsString('<' . $root_element, $result);
197 // We could probably do more checks here.
201 * Get the path to a temporary empty PNG image.
203 * @return string Path
205 private function getTempImage()
207 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
211 // Empty 1x1 px PNG image
212 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
220 * Test the api_user() function.
224 public function testApiUser()
226 self::assertEquals($this->selfUser['id'], api_user());
230 * Test the api_user() function with an unallowed user.
234 public function testApiUserWithUnallowedUser()
236 $_SESSION = ['allow_api' => false];
237 self::assertEquals(false, api_user());
241 * Test the api_source() function.
245 public function testApiSource()
247 self::assertEquals('api', api_source());
251 * Test the api_source() function with a Twidere user agent.
255 public function testApiSourceWithTwidere()
257 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
258 self::assertEquals('Twidere', api_source());
262 * Test the api_source() function with a GET parameter.
266 public function testApiSourceWithGet()
268 $_GET['source'] = 'source_name';
269 self::assertEquals('source_name', api_source());
273 * Test the api_date() function.
277 public function testApiDate()
279 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
283 * Test the api_register_func() function.
287 public function testApiRegisterFunc()
299 self::assertTrue($API['api_path']['auth']);
300 self::assertEquals('method', $API['api_path']['method']);
301 self::assertTrue(is_callable($API['api_path']['func']));
305 * Test the BasicAuth::getCurrentUserID() function without any login.
307 * @runInSeparateProcess
308 * @preserveGlobalState disabled
309 * @preserveGlobalState disabled
311 public function testApiLoginWithoutLogin()
313 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
314 BasicAuth::getCurrentUserID(true);
318 * Test the BasicAuth::getCurrentUserID() function with a bad login.
320 * @runInSeparateProcess
321 * @preserveGlobalState disabled
322 * @preserveGlobalState disabled
324 public function testApiLoginWithBadLogin()
326 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
327 $_SERVER['PHP_AUTH_USER'] = 'user@server';
328 BasicAuth::getCurrentUserID(true);
332 * Test the BasicAuth::getCurrentUserID() function with oAuth.
336 public function testApiLoginWithOauth()
338 $this->markTestIncomplete('Can we test this easily?');
342 * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
346 public function testApiLoginWithAddonAuth()
348 $this->markTestIncomplete('Can we test this easily?');
352 * Test the BasicAuth::getCurrentUserID() function with a correct login.
354 * @runInSeparateProcess
355 * @preserveGlobalState disabled
356 * @doesNotPerformAssertions
358 public function testApiLoginWithCorrectLogin()
360 $_SERVER['PHP_AUTH_USER'] = 'Test user';
361 $_SERVER['PHP_AUTH_PW'] = 'password';
362 BasicAuth::getCurrentUserID(true);
366 * Test the BasicAuth::getCurrentUserID() function with a remote user.
368 * @runInSeparateProcess
369 * @preserveGlobalState disabled
371 public function testApiLoginWithRemoteUser()
373 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
374 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
375 BasicAuth::getCurrentUserID(true);
379 * Test the api_check_method() function.
383 public function testApiCheckMethod()
385 self::assertFalse(api_check_method('method'));
389 * Test the api_check_method() function with a correct method.
393 public function testApiCheckMethodWithCorrectMethod()
395 $_SERVER['REQUEST_METHOD'] = 'method';
396 self::assertTrue(api_check_method('method'));
400 * Test the api_check_method() function with a wildcard.
404 public function testApiCheckMethodWithWildcard()
406 self::assertTrue(api_check_method('*'));
410 * Test the api_call() function.
412 * @runInSeparateProcess
413 * @preserveGlobalState disabled
415 public function testApiCall()
419 'method' => 'method',
420 'func' => function () {
421 return ['data' => ['some_data']];
424 $_SERVER['REQUEST_METHOD'] = 'method';
425 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
426 $_GET['callback'] = 'callback_name';
428 $args = DI::args()->determine($_SERVER, $_GET);
431 'callback_name(["some_data"])',
432 api_call($this->app, $args)
437 * Test the api_call() function with the profiled enabled.
439 * @runInSeparateProcess
440 * @preserveGlobalState disabled
442 public function testApiCallWithProfiler()
446 'method' => 'method',
447 'func' => function () {
448 return ['data' => ['some_data']];
452 $_SERVER['REQUEST_METHOD'] = 'method';
453 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
455 $args = DI::args()->determine($_SERVER, $_GET);
457 $this->config->set('system', 'profiler', true);
458 $this->config->set('rendertime', 'callstack', true);
459 $this->app->callstack = [
460 'database' => ['some_function' => 200],
461 'database_write' => ['some_function' => 200],
462 'cache' => ['some_function' => 200],
463 'cache_write' => ['some_function' => 200],
464 'network' => ['some_function' => 200]
469 api_call($this->app, $args)
474 * Test the api_call() function without any result.
476 * @runInSeparateProcess
477 * @preserveGlobalState disabled
479 public function testApiCallWithNoResult()
481 // @todo How to test the new API?
485 'method' => 'method',
486 'func' => function () {
490 $_SERVER['REQUEST_METHOD'] = 'method';
491 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
493 $args = DI::args()->determine($_SERVER, $_GET);
496 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
497 api_call($this->app, $args)
503 * Test the api_call() function with an unimplemented API.
505 * @runInSeparateProcess
506 * @preserveGlobalState disabled
508 public function testApiCallWithUninplementedApi()
510 // @todo How to test the new API?
513 '{"status":{"error":"Not Found","code":"404 Not Found","request":""}}',
520 * Test the api_call() function with a JSON result.
522 * @runInSeparateProcess
523 * @preserveGlobalState disabled
525 public function testApiCallWithJson()
529 'method' => 'method',
530 'func' => function () {
531 return ['data' => ['some_data']];
534 $_SERVER['REQUEST_METHOD'] = 'method';
535 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
537 $args = DI::args()->determine($_SERVER, $_GET);
541 api_call($this->app, $args)
546 * Test the api_call() function with an XML result.
548 * @runInSeparateProcess
549 * @preserveGlobalState disabled
551 public function testApiCallWithXml()
555 'method' => 'method',
556 'func' => function () {
560 $_SERVER['REQUEST_METHOD'] = 'method';
561 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
563 $args = DI::args()->determine($_SERVER, $_GET);
567 api_call($this->app, $args)
572 * Test the api_call() function with an RSS result.
574 * @runInSeparateProcess
575 * @preserveGlobalState disabled
577 public function testApiCallWithRss()
581 'method' => 'method',
582 'func' => function () {
586 $_SERVER['REQUEST_METHOD'] = 'method';
587 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
589 $args = DI::args()->determine($_SERVER, $_GET);
592 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
594 api_call($this->app, $args)
599 * Test the api_call() function with an Atom result.
601 * @runInSeparateProcess
602 * @preserveGlobalState disabled
604 public function testApiCallWithAtom()
608 'method' => 'method',
609 'func' => function () {
613 $_SERVER['REQUEST_METHOD'] = 'method';
614 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
616 $args = DI::args()->determine($_SERVER, $_GET);
619 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
621 api_call($this->app, $args)
626 * Test the api_call() function with an unallowed method.
628 * @runInSeparateProcess
629 * @preserveGlobalState disabled
631 public function testApiCallWithWrongMethod()
633 // Shouldn't be needed anymore due to the router?
636 $API['api_path'] = ['method' => 'method'];
638 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
640 $args = DI::args()->determine($_SERVER, $_GET);
643 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
644 api_call($this->app, $args)
650 * Test the api_call() function with an unauthorized user.
652 * @runInSeparateProcess
653 * @preserveGlobalState disabled
655 public function testApiCallWithWrongAuth()
657 // @todo How to test the new API?
661 'method' => 'method',
664 $_SESSION['authenticated'] = false;
665 $_SERVER['REQUEST_METHOD'] = 'method';
666 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
668 $args = DI::args()->determine($_SERVER, $_GET);
671 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
672 api_call($this->app, $args)
678 * Test the api_error() function with a JSON result.
680 * @runInSeparateProcess
681 * @preserveGlobalState disabled
683 public function testApiErrorWithJson()
685 // @todo How to test the new API?
686 // self::assertEquals(
687 // '{"status":{"error":"error_message","code":"200 OK","request":""}}',
688 // api_error('json', new HTTPException\OKException('error_message'), DI::args())
693 * Test the api_error() function with an XML result.
695 * @runInSeparateProcess
696 * @preserveGlobalState disabled
698 public function testApiErrorWithXml()
700 // @todo How to test the new API?
703 '<?xml version="1.0"?>' . "\n" .
704 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
705 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
706 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
707 ' <error>error_message</error>' . "\n" .
708 ' <code>200 OK</code>' . "\n" .
709 ' <request/>' . "\n" .
711 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
717 * Test the api_error() function with an RSS result.
719 * @runInSeparateProcess
720 * @preserveGlobalState disabled
722 public function testApiErrorWithRss()
724 // @todo How to test the new API?
727 '<?xml version="1.0"?>' . "\n" .
728 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
729 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
730 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
731 ' <error>error_message</error>' . "\n" .
732 ' <code>200 OK</code>' . "\n" .
733 ' <request/>' . "\n" .
735 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
741 * Test the api_error() function with an Atom result.
743 * @runInSeparateProcess
744 * @preserveGlobalState disabled
746 public function testApiErrorWithAtom()
748 // @todo How to test the new API?
751 '<?xml version="1.0"?>' . "\n" .
752 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
753 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
754 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
755 ' <error>error_message</error>' . "\n" .
756 ' <code>200 OK</code>' . "\n" .
757 ' <request/>' . "\n" .
759 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
765 * Test the api_rss_extra() function.
769 public function testApiRssExtra()
771 $user_info = ['url' => 'user_url', 'lang' => 'en'];
772 $result = api_rss_extra($this->app, [], $user_info);
773 self::assertEquals($user_info, $result['$user']);
774 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
775 self::assertArrayHasKey('self', $result['$rss']);
776 self::assertArrayHasKey('base', $result['$rss']);
777 self::assertArrayHasKey('updated', $result['$rss']);
778 self::assertArrayHasKey('atom_updated', $result['$rss']);
779 self::assertArrayHasKey('language', $result['$rss']);
780 self::assertArrayHasKey('logo', $result['$rss']);
784 * Test the api_rss_extra() function without any user info.
788 public function testApiRssExtraWithoutUserInfo()
790 $result = api_rss_extra($this->app, [], null);
791 self::assertIsArray($result['$user']);
792 self::assertArrayHasKey('alternate', $result['$rss']);
793 self::assertArrayHasKey('self', $result['$rss']);
794 self::assertArrayHasKey('base', $result['$rss']);
795 self::assertArrayHasKey('updated', $result['$rss']);
796 self::assertArrayHasKey('atom_updated', $result['$rss']);
797 self::assertArrayHasKey('language', $result['$rss']);
798 self::assertArrayHasKey('logo', $result['$rss']);
802 * Test the api_unique_id_to_nurl() function.
806 public function testApiUniqueIdToNurl()
808 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
812 * Test the api_unique_id_to_nurl() function with a correct ID.
816 public function testApiUniqueIdToNurlWithCorrectId()
818 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
822 * Test the api_get_user() function.
826 public function testApiGetUser()
828 $user = api_get_user();
829 self::assertSelfUser($user);
830 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
831 self::assertEquals('6fdbe8', $user['profile_link_color']);
832 self::assertEquals('ededed', $user['profile_background_color']);
836 * Test the api_get_user() function with a Frio schema.
840 public function testApiGetUserWithFrioSchema()
842 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
843 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
844 $user = api_get_user();
845 self::assertSelfUser($user);
846 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
847 self::assertEquals('6fdbe8', $user['profile_link_color']);
848 self::assertEquals('ededed', $user['profile_background_color']);
852 * Test the api_get_user() function with an empty Frio schema.
856 public function testApiGetUserWithEmptyFrioSchema()
858 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
859 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
860 $user = api_get_user();
861 self::assertSelfUser($user);
862 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
863 self::assertEquals('6fdbe8', $user['profile_link_color']);
864 self::assertEquals('ededed', $user['profile_background_color']);
868 * Test the api_get_user() function with a custom Frio schema.
872 public function testApiGetUserWithCustomFrioSchema()
874 $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
875 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
876 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
877 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
878 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
879 $user = api_get_user();
880 self::assertSelfUser($user);
881 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
882 self::assertEquals('123456', $user['profile_link_color']);
883 self::assertEquals('123456', $user['profile_background_color']);
887 * Test the api_get_user() function with an user that is not allowed to use the API.
889 * @runInSeparateProcess
890 * @preserveGlobalState disabled
892 public function testApiGetUserWithoutApiUser()
894 $_SERVER['PHP_AUTH_USER'] = 'Test user';
895 $_SERVER['PHP_AUTH_PW'] = 'password';
896 $_SESSION['allow_api'] = false;
897 self::assertFalse(api_get_user());
901 * Test the api_get_user() function with an user ID in a GET parameter.
905 public function testApiGetUserWithGetId()
907 $_GET['user_id'] = $this->otherUser['id'];
908 self::assertOtherUser(api_get_user());
912 * Test the api_get_user() function with a wrong user ID in a GET parameter.
916 public function testApiGetUserWithWrongGetId()
918 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
919 $_GET['user_id'] = $this->wrongUserId;
920 self::assertOtherUser(api_get_user());
924 * Test the api_get_user() function with an user name in a GET parameter.
928 public function testApiGetUserWithGetName()
930 $_GET['screen_name'] = $this->selfUser['nick'];
931 self::assertSelfUser(api_get_user());
935 * Test the api_get_user() function with a profile URL in a GET parameter.
939 public function testApiGetUserWithGetUrl()
941 $_GET['profileurl'] = $this->selfUser['nurl'];
942 self::assertSelfUser(api_get_user());
946 * Test the api_get_user() function with an user ID in the API path.
950 public function testApiGetUserWithNumericCalledApi()
953 $called_api = ['api_path'];
954 DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
955 self::assertOtherUser(api_get_user());
959 * Test the api_get_user() function with the $called_api global variable.
963 public function testApiGetUserWithCalledApi()
966 $called_api = ['api', 'api_path'];
967 self::assertSelfUser(api_get_user());
971 * Test the api_get_user() function with a valid user.
975 public function testApiGetUserWithCorrectUser()
977 self::assertOtherUser(api_get_user($this->otherUser['id']));
981 * Test the api_get_user() function with a wrong user ID.
985 public function testApiGetUserWithWrongUser()
987 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
988 self::assertOtherUser(api_get_user($this->wrongUserId));
992 * Test the api_get_user() function with a 0 user ID.
996 public function testApiGetUserWithZeroUser()
998 self::assertSelfUser(api_get_user(0));
1002 * Test the api_item_get_user() function.
1006 public function testApiItemGetUser()
1008 $users = api_item_get_user($this->app, []);
1009 self::assertSelfUser($users[0]);
1013 * Test the api_item_get_user() function with a different item parent.
1017 public function testApiItemGetUserWithDifferentParent()
1019 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
1020 self::assertSelfUser($users[0]);
1021 self::assertEquals($users[0], $users[1]);
1025 * Test the Arrays::walkRecursive() function.
1029 public function testApiWalkRecursive()
1034 Arrays::walkRecursive(
1037 // Should we test this with a callback that actually does something?
1045 * Test the Arrays::walkRecursive() function with an array.
1049 public function testApiWalkRecursiveWithArray()
1051 $array = [['item1'], ['item2']];
1054 Arrays::walkRecursive(
1057 // Should we test this with a callback that actually does something?
1065 * Test the BaseApi::reformatXML() function.
1069 public function testApiReformatXml()
1073 self::assertTrue(ApiResponse::reformatXML($item, $key));
1074 self::assertEquals('true', $item);
1078 * Test the BaseApi::reformatXML() function with a statusnet_api key.
1082 public function testApiReformatXmlWithStatusnetKey()
1085 $key = 'statusnet_api';
1086 self::assertTrue(ApiResponse::reformatXML($item, $key));
1087 self::assertEquals('statusnet:api', $key);
1091 * Test the BaseApi::reformatXML() function with a friendica_api key.
1095 public function testApiReformatXmlWithFriendicaKey()
1098 $key = 'friendica_api';
1099 self::assertTrue(ApiResponse::reformatXML($item, $key));
1100 self::assertEquals('friendica:api', $key);
1104 * Test the BaseApi::createXML() function.
1108 public function testApiCreateXml()
1111 '<?xml version="1.0"?>' . "\n" .
1112 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1113 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1114 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1115 ' <data>some_data</data>' . "\n" .
1116 '</root_element>' . "\n",
1117 DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
1122 * Test the BaseApi::createXML() function without any XML namespace.
1126 public function testApiCreateXmlWithoutNamespaces()
1129 '<?xml version="1.0"?>' . "\n" .
1131 ' <data>some_data</data>' . "\n" .
1133 DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
1138 * Test the BaseApi::formatData() function.
1142 public function testApiFormatData()
1144 $data = ['some_data'];
1145 self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
1149 * Test the BaseApi::formatData() function with an XML result.
1153 public function testApiFormatDataWithXml()
1156 '<?xml version="1.0"?>' . "\n" .
1157 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1158 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1159 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1160 ' <data>some_data</data>' . "\n" .
1161 '</root_element>' . "\n",
1162 DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
1167 * Test the api_account_verify_credentials() function.
1171 public function testApiAccountVerifyCredentials()
1173 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1177 * Test the api_account_verify_credentials() function without an authenticated user.
1181 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1183 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1184 $_SESSION['authenticated'] = false;
1185 api_account_verify_credentials('json');
1189 * Test the requestdata() function.
1193 public function testRequestdata()
1195 self::assertNull(requestdata('variable_name'));
1199 * Test the requestdata() function with a POST parameter.
1203 public function testRequestdataWithPost()
1205 $_POST['variable_name'] = 'variable_value';
1206 self::assertEquals('variable_value', requestdata('variable_name'));
1210 * Test the requestdata() function with a GET parameter.
1214 public function testRequestdataWithGet()
1216 $_GET['variable_name'] = 'variable_value';
1217 self::assertEquals('variable_value', requestdata('variable_name'));
1221 * Test the api_statuses_mediap() function.
1225 public function testApiStatusesMediap()
1227 DI::args()->setArgc(2);
1235 'tmp_name' => $this->getTempImage(),
1236 'name' => 'spacer.png',
1237 'type' => 'image/png'
1240 $_GET['status'] = '<b>Status content</b>';
1242 $result = api_statuses_mediap('json');
1243 self::assertStatus($result['status']);
1247 * Test the api_statuses_mediap() function without an authenticated user.
1251 public function testApiStatusesMediapWithoutAuthenticatedUser()
1253 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1254 $_SESSION['authenticated'] = false;
1255 api_statuses_mediap('json');
1259 * Test the api_statuses_update() function.
1263 public function testApiStatusesUpdate()
1265 $_GET['status'] = 'Status content #friendica';
1266 $_GET['in_reply_to_status_id'] = -1;
1275 'tmp_name' => $this->getTempImage(),
1276 'name' => 'spacer.png',
1277 'type' => 'image/png'
1281 $result = api_statuses_update('json');
1282 self::assertStatus($result['status']);
1286 * Test the api_statuses_update() function with an HTML status.
1290 public function testApiStatusesUpdateWithHtml()
1292 $_GET['htmlstatus'] = '<b>Status content</b>';
1294 $result = api_statuses_update('json');
1295 self::assertStatus($result['status']);
1299 * Test the api_statuses_update() function without an authenticated user.
1303 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1305 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1306 $_SESSION['authenticated'] = false;
1307 api_statuses_update('json');
1311 * Test the api_statuses_update() function with a parent status.
1315 public function testApiStatusesUpdateWithParent()
1317 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1321 * Test the api_statuses_update() function with a media_ids parameter.
1325 public function testApiStatusesUpdateWithMediaIds()
1327 $this->markTestIncomplete();
1331 * Test the api_statuses_update() function with the throttle limit reached.
1335 public function testApiStatusesUpdateWithDayThrottleReached()
1337 $this->markTestIncomplete();
1341 * Test the api_media_upload() function.
1342 * @runInSeparateProcess
1343 * @preserveGlobalState disabled
1345 public function testApiMediaUpload()
1347 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1352 * Test the api_media_upload() function without an authenticated user.
1356 public function testApiMediaUploadWithoutAuthenticatedUser()
1358 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1359 $_SESSION['authenticated'] = false;
1364 * Test the api_media_upload() function with an invalid uploaded media.
1368 public function testApiMediaUploadWithMedia()
1370 $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
1374 'tmp_name' => 'tmp_name'
1381 * Test the api_media_upload() function with an valid uploaded media.
1385 public function testApiMediaUploadWithValidMedia()
1393 'tmp_name' => $this->getTempImage(),
1394 'name' => 'spacer.png',
1395 'type' => 'image/png'
1399 DI::args()->setArgc(2);
1401 $result = api_media_upload();
1402 self::assertEquals('image/png', $result['media']['image']['image_type']);
1403 self::assertEquals(1, $result['media']['image']['w']);
1404 self::assertEquals(1, $result['media']['image']['h']);
1405 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1409 * Test the api_status_show() function.
1411 public function testApiStatusShowWithJson()
1413 $result = api_status_show('json', 1);
1414 self::assertStatus($result['status']);
1418 * Test the api_status_show() function with an XML result.
1420 public function testApiStatusShowWithXml()
1422 $result = api_status_show('xml', 1);
1423 self::assertXml($result, 'statuses');
1427 * Test the api_get_last_status() function
1429 public function testApiGetLastStatus()
1431 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1433 self::assertNotNull($item);
1437 * Test the api_users_show() function.
1441 public function testApiUsersShow()
1443 $result = api_users_show('json');
1444 // We can't use assertSelfUser() here because the user object is missing some properties.
1445 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1446 self::assertEquals('DFRN', $result['user']['location']);
1447 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1448 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1449 self::assertEquals('dfrn', $result['user']['network']);
1450 self::assertTrue($result['user']['verified']);
1454 * Test the api_users_show() function with an XML result.
1458 public function testApiUsersShowWithXml()
1460 $result = api_users_show('xml');
1461 self::assertXml($result, 'statuses');
1465 * Test the api_users_search() function.
1469 public function testApiUsersSearch()
1471 $_GET['q'] = 'othercontact';
1472 $result = api_users_search('json');
1473 self::assertOtherUser($result['users'][0]);
1477 * Test the api_users_search() function with an XML result.
1481 public function testApiUsersSearchWithXml()
1483 $_GET['q'] = 'othercontact';
1484 $result = api_users_search('xml');
1485 self::assertXml($result, 'users');
1489 * Test the api_users_search() function without a GET q parameter.
1493 public function testApiUsersSearchWithoutQuery()
1495 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1496 api_users_search('json');
1500 * Test the api_users_lookup() function.
1504 public function testApiUsersLookup()
1506 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
1507 api_users_lookup('json');
1511 * Test the api_users_lookup() function with an user ID.
1515 public function testApiUsersLookupWithUserId()
1517 $_REQUEST['user_id'] = $this->otherUser['id'];
1518 $result = api_users_lookup('json');
1519 self::assertOtherUser($result['users'][0]);
1523 * Test the api_search() function.
1527 public function testApiSearch()
1529 $_REQUEST['q'] = 'reply';
1530 $_REQUEST['max_id'] = 10;
1531 $result = api_search('json');
1532 foreach ($result['status'] as $status) {
1533 self::assertStatus($status);
1534 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1539 * Test the api_search() function a count parameter.
1543 public function testApiSearchWithCount()
1545 $_REQUEST['q'] = 'reply';
1546 $_REQUEST['count'] = 20;
1547 $result = api_search('json');
1548 foreach ($result['status'] as $status) {
1549 self::assertStatus($status);
1550 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1555 * Test the api_search() function with an rpp parameter.
1559 public function testApiSearchWithRpp()
1561 $_REQUEST['q'] = 'reply';
1562 $_REQUEST['rpp'] = 20;
1563 $result = api_search('json');
1564 foreach ($result['status'] as $status) {
1565 self::assertStatus($status);
1566 self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
1571 * Test the api_search() function with an q parameter contains hashtag.
1572 * @doesNotPerformAssertions
1574 public function testApiSearchWithHashtag()
1576 $_REQUEST['q'] = '%23friendica';
1577 $result = api_search('json');
1578 foreach ($result['status'] as $status) {
1579 self::assertStatus($status);
1580 self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
1585 * Test the api_search() function with an exclude_replies parameter.
1586 * @doesNotPerformAssertions
1588 public function testApiSearchWithExcludeReplies()
1590 $_REQUEST['max_id'] = 10;
1591 $_REQUEST['exclude_replies'] = true;
1592 $_REQUEST['q'] = 'friendica';
1593 $result = api_search('json');
1594 foreach ($result['status'] as $status) {
1595 self::assertStatus($status);
1600 * Test the api_search() function without an authenticated user.
1604 public function testApiSearchWithUnallowedUser()
1606 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1607 $_SESSION['allow_api'] = false;
1608 $_GET['screen_name'] = $this->selfUser['nick'];
1613 * Test the api_search() function without any GET query parameter.
1617 public function testApiSearchWithoutQuery()
1619 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1624 * Test the api_statuses_home_timeline() function.
1628 public function testApiStatusesHomeTimeline()
1630 $_REQUEST['max_id'] = 10;
1631 $_REQUEST['exclude_replies'] = true;
1632 $_REQUEST['conversation_id'] = 1;
1633 $result = api_statuses_home_timeline('json');
1634 self::assertNotEmpty($result['status']);
1635 foreach ($result['status'] as $status) {
1636 self::assertStatus($status);
1641 * Test the api_statuses_home_timeline() function with a negative page parameter.
1645 public function testApiStatusesHomeTimelineWithNegativePage()
1647 $_REQUEST['page'] = -2;
1648 $result = api_statuses_home_timeline('json');
1649 self::assertNotEmpty($result['status']);
1650 foreach ($result['status'] as $status) {
1651 self::assertStatus($status);
1656 * Test the api_statuses_home_timeline() with an unallowed user.
1660 public function testApiStatusesHomeTimelineWithUnallowedUser()
1662 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1663 $_SESSION['allow_api'] = false;
1664 $_GET['screen_name'] = $this->selfUser['nick'];
1665 api_statuses_home_timeline('json');
1669 * Test the api_statuses_home_timeline() function with an RSS result.
1673 public function testApiStatusesHomeTimelineWithRss()
1675 $result = api_statuses_home_timeline('rss');
1676 self::assertXml($result, 'statuses');
1680 * Test the api_statuses_public_timeline() function.
1684 public function testApiStatusesPublicTimeline()
1686 $_REQUEST['max_id'] = 10;
1687 $_REQUEST['conversation_id'] = 1;
1688 $result = api_statuses_public_timeline('json');
1689 self::assertNotEmpty($result['status']);
1690 foreach ($result['status'] as $status) {
1691 self::assertStatus($status);
1696 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1700 public function testApiStatusesPublicTimelineWithExcludeReplies()
1702 $_REQUEST['max_id'] = 10;
1703 $_REQUEST['exclude_replies'] = true;
1704 $result = api_statuses_public_timeline('json');
1705 self::assertNotEmpty($result['status']);
1706 foreach ($result['status'] as $status) {
1707 self::assertStatus($status);
1712 * Test the api_statuses_public_timeline() function with a negative page parameter.
1716 public function testApiStatusesPublicTimelineWithNegativePage()
1718 $_REQUEST['page'] = -2;
1719 $result = api_statuses_public_timeline('json');
1720 self::assertNotEmpty($result['status']);
1721 foreach ($result['status'] as $status) {
1722 self::assertStatus($status);
1727 * Test the api_statuses_public_timeline() function with an unallowed user.
1731 public function testApiStatusesPublicTimelineWithUnallowedUser()
1733 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1734 $_SESSION['allow_api'] = false;
1735 $_GET['screen_name'] = $this->selfUser['nick'];
1736 api_statuses_public_timeline('json');
1740 * Test the api_statuses_public_timeline() function with an RSS result.
1744 public function testApiStatusesPublicTimelineWithRss()
1746 $result = api_statuses_public_timeline('rss');
1747 self::assertXml($result, 'statuses');
1751 * Test the api_statuses_networkpublic_timeline() function.
1755 public function testApiStatusesNetworkpublicTimeline()
1757 $_REQUEST['max_id'] = 10;
1758 $result = api_statuses_networkpublic_timeline('json');
1759 self::assertNotEmpty($result['status']);
1760 foreach ($result['status'] as $status) {
1761 self::assertStatus($status);
1766 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1770 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1772 $_REQUEST['page'] = -2;
1773 $result = api_statuses_networkpublic_timeline('json');
1774 self::assertNotEmpty($result['status']);
1775 foreach ($result['status'] as $status) {
1776 self::assertStatus($status);
1781 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1785 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1787 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1788 $_SESSION['allow_api'] = false;
1789 $_GET['screen_name'] = $this->selfUser['nick'];
1790 api_statuses_networkpublic_timeline('json');
1794 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1798 public function testApiStatusesNetworkpublicTimelineWithRss()
1800 $result = api_statuses_networkpublic_timeline('rss');
1801 self::assertXml($result, 'statuses');
1805 * Test the api_statuses_show() function.
1809 public function testApiStatusesShow()
1811 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1812 api_statuses_show('json');
1816 * Test the api_statuses_show() function with an ID.
1820 public function testApiStatusesShowWithId()
1822 DI::args()->setArgv(['', '', '', 1]);
1823 $result = api_statuses_show('json');
1824 self::assertStatus($result['status']);
1828 * Test the api_statuses_show() function with the conversation parameter.
1832 public function testApiStatusesShowWithConversation()
1834 DI::args()->setArgv(['', '', '', 1]);
1835 $_REQUEST['conversation'] = 1;
1836 $result = api_statuses_show('json');
1837 self::assertNotEmpty($result['status']);
1838 foreach ($result['status'] as $status) {
1839 self::assertStatus($status);
1844 * Test the api_statuses_show() function with an unallowed user.
1848 public function testApiStatusesShowWithUnallowedUser()
1850 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1851 $_SESSION['allow_api'] = false;
1852 $_GET['screen_name'] = $this->selfUser['nick'];
1853 api_statuses_show('json');
1857 * Test the api_conversation_show() function.
1861 public function testApiConversationShow()
1863 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1864 api_conversation_show('json');
1868 * Test the api_conversation_show() function with an ID.
1872 public function testApiConversationShowWithId()
1874 DI::args()->setArgv(['', '', '', 1]);
1875 $_REQUEST['max_id'] = 10;
1876 $_REQUEST['page'] = -2;
1877 $result = api_conversation_show('json');
1878 self::assertNotEmpty($result['status']);
1879 foreach ($result['status'] as $status) {
1880 self::assertStatus($status);
1885 * Test the api_conversation_show() function with an unallowed user.
1889 public function testApiConversationShowWithUnallowedUser()
1891 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1892 $_SESSION['allow_api'] = false;
1893 $_GET['screen_name'] = $this->selfUser['nick'];
1894 api_conversation_show('json');
1898 * Test the api_statuses_repeat() function.
1902 public function testApiStatusesRepeat()
1904 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1905 api_statuses_repeat('json');
1909 * Test the api_statuses_repeat() function without an authenticated user.
1913 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1915 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1916 $_SESSION['authenticated'] = false;
1917 api_statuses_repeat('json');
1921 * Test the api_statuses_repeat() function with an ID.
1925 public function testApiStatusesRepeatWithId()
1927 DI::args()->setArgv(['', '', '', 1]);
1928 $result = api_statuses_repeat('json');
1929 self::assertStatus($result['status']);
1931 // Also test with a shared status
1932 DI::args()->setArgv(['', '', '', 5]);
1933 $result = api_statuses_repeat('json');
1934 self::assertStatus($result['status']);
1938 * Test the api_statuses_destroy() function.
1942 public function testApiStatusesDestroy()
1944 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
1945 api_statuses_destroy('json');
1949 * Test the api_statuses_destroy() function without an authenticated user.
1953 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1955 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
1956 $_SESSION['authenticated'] = false;
1957 api_statuses_destroy('json');
1961 * Test the api_statuses_destroy() function with an ID.
1965 public function testApiStatusesDestroyWithId()
1967 DI::args()->setArgv(['', '', '', 1]);
1968 $result = api_statuses_destroy('json');
1969 self::assertStatus($result['status']);
1973 * Test the api_statuses_mentions() function.
1977 public function testApiStatusesMentions()
1979 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
1980 $_REQUEST['max_id'] = 10;
1981 $result = api_statuses_mentions('json');
1982 self::assertEmpty($result['status']);
1983 // We should test with mentions in the database.
1987 * Test the api_statuses_mentions() function with a negative page parameter.
1991 public function testApiStatusesMentionsWithNegativePage()
1993 $_REQUEST['page'] = -2;
1994 $result = api_statuses_mentions('json');
1995 self::assertEmpty($result['status']);
1999 * Test the api_statuses_mentions() function with an unallowed user.
2003 public function testApiStatusesMentionsWithUnallowedUser()
2005 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2006 $_SESSION['allow_api'] = false;
2007 $_GET['screen_name'] = $this->selfUser['nick'];
2008 api_statuses_mentions('json');
2012 * Test the api_statuses_mentions() function with an RSS result.
2016 public function testApiStatusesMentionsWithRss()
2018 $result = api_statuses_mentions('rss');
2019 self::assertXml($result, 'statuses');
2023 * Test the api_statuses_user_timeline() function.
2027 public function testApiStatusesUserTimeline()
2029 $_REQUEST['max_id'] = 10;
2030 $_REQUEST['exclude_replies'] = true;
2031 $_REQUEST['conversation_id'] = 1;
2032 $result = api_statuses_user_timeline('json');
2033 self::assertNotEmpty($result['status']);
2034 foreach ($result['status'] as $status) {
2035 self::assertStatus($status);
2040 * Test the api_statuses_user_timeline() function with a negative page parameter.
2044 public function testApiStatusesUserTimelineWithNegativePage()
2046 $_REQUEST['page'] = -2;
2047 $result = api_statuses_user_timeline('json');
2048 self::assertNotEmpty($result['status']);
2049 foreach ($result['status'] as $status) {
2050 self::assertStatus($status);
2055 * Test the api_statuses_user_timeline() function with an RSS result.
2059 public function testApiStatusesUserTimelineWithRss()
2061 $result = api_statuses_user_timeline('rss');
2062 self::assertXml($result, 'statuses');
2066 * Test the api_statuses_user_timeline() function with an unallowed user.
2070 public function testApiStatusesUserTimelineWithUnallowedUser()
2072 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2073 $_SESSION['allow_api'] = false;
2074 $_GET['screen_name'] = $this->selfUser['nick'];
2075 api_statuses_user_timeline('json');
2079 * Test the api_favorites_create_destroy() function.
2083 public function testApiFavoritesCreateDestroy()
2085 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2086 DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
2087 api_favorites_create_destroy('json');
2091 * Test the api_favorites_create_destroy() function with an invalid ID.
2095 public function testApiFavoritesCreateDestroyWithInvalidId()
2097 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2098 DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
2099 api_favorites_create_destroy('json');
2103 * Test the api_favorites_create_destroy() function with an invalid action.
2107 public function testApiFavoritesCreateDestroyWithInvalidAction()
2109 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2110 DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
2111 $_REQUEST['id'] = 1;
2112 api_favorites_create_destroy('json');
2116 * Test the api_favorites_create_destroy() function with the create action.
2120 public function testApiFavoritesCreateDestroyWithCreateAction()
2122 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2123 $_REQUEST['id'] = 3;
2124 $result = api_favorites_create_destroy('json');
2125 self::assertStatus($result['status']);
2129 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2133 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2135 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
2136 $_REQUEST['id'] = 3;
2137 $result = api_favorites_create_destroy('rss');
2138 self::assertXml($result, 'status');
2142 * Test the api_favorites_create_destroy() function with the destroy action.
2146 public function testApiFavoritesCreateDestroyWithDestroyAction()
2148 DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
2149 $_REQUEST['id'] = 3;
2150 $result = api_favorites_create_destroy('json');
2151 self::assertStatus($result['status']);
2155 * Test the api_favorites_create_destroy() function without an authenticated user.
2159 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2161 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2162 DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
2163 $_SESSION['authenticated'] = false;
2164 api_favorites_create_destroy('json');
2168 * Test the api_favorites() function.
2172 public function testApiFavorites()
2174 $_REQUEST['page'] = -1;
2175 $_REQUEST['max_id'] = 10;
2176 $result = api_favorites('json');
2177 foreach ($result['status'] as $status) {
2178 self::assertStatus($status);
2183 * Test the api_favorites() function with an RSS result.
2187 public function testApiFavoritesWithRss()
2189 $result = api_favorites('rss');
2190 self::assertXml($result, 'statuses');
2194 * Test the api_favorites() function with an unallowed user.
2198 public function testApiFavoritesWithUnallowedUser()
2200 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2201 $_SESSION['allow_api'] = false;
2202 $_GET['screen_name'] = $this->selfUser['nick'];
2203 api_favorites('json');
2207 * Test the api_format_messages() function.
2211 public function testApiFormatMessages()
2213 $result = api_format_messages(
2214 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2215 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2216 ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
2218 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2219 self::assertEquals(1, $result['id']);
2220 self::assertEquals(2, $result['recipient_id']);
2221 self::assertEquals(3, $result['sender_id']);
2222 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2223 self::assertEquals('sender_name', $result['sender_screen_name']);
2227 * Test the api_format_messages() function with HTML.
2231 public function testApiFormatMessagesWithHtmlText()
2233 $_GET['getText'] = 'html';
2234 $result = api_format_messages(
2235 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2236 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2237 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2239 self::assertEquals('item_title', $result['title']);
2240 self::assertEquals('<strong>item_body</strong>', $result['text']);
2244 * Test the api_format_messages() function with plain text.
2248 public function testApiFormatMessagesWithPlainText()
2250 $_GET['getText'] = 'plain';
2251 $result = api_format_messages(
2252 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2253 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2254 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2256 self::assertEquals('item_title', $result['title']);
2257 self::assertEquals('item_body', $result['text']);
2261 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2265 public function testApiFormatMessagesWithoutUserObjects()
2267 $_GET['getUserObjects'] = 'false';
2268 $result = api_format_messages(
2269 ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2270 ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
2271 ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
2273 self::assertTrue(!isset($result['sender']));
2274 self::assertTrue(!isset($result['recipient']));
2278 * Test the api_convert_item() function.
2282 public function testApiConvertItem()
2284 $result = api_convert_item(
2286 'network' => 'feed',
2287 'title' => 'item_title',
2289 // We need a long string to test that it is correctly cut
2290 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2291 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2292 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2293 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2294 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2295 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2296 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2297 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2298 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2299 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2300 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2301 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2302 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2303 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2304 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2305 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2306 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2307 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2308 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2309 'repellat officia illum quos impedit quam iste esse unde qui ' .
2310 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2311 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2312 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2313 'plink' => 'item_plink'
2316 self::assertStringStartsWith('item_title', $result['text']);
2317 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2321 * Test the api_convert_item() function with an empty item body.
2325 public function testApiConvertItemWithoutBody()
2327 $result = api_convert_item(
2329 'network' => 'feed',
2330 'title' => 'item_title',
2333 'plink' => 'item_plink'
2336 self::assertEquals("item_title", $result['text']);
2337 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2341 * Test the api_convert_item() function with the title in the body.
2345 public function testApiConvertItemWithTitleInBody()
2347 $result = api_convert_item(
2349 'title' => 'item_title',
2350 'body' => 'item_title item_body',
2354 self::assertEquals('item_title item_body', $result['text']);
2355 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2359 * Test the api_get_attachments() function.
2363 public function testApiGetAttachments()
2366 self::assertEmpty(api_get_attachments($body, 0));
2370 * Test the api_get_attachments() function with an img tag.
2374 public function testApiGetAttachmentsWithImage()
2376 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2377 self::assertIsArray(api_get_attachments($body, 0));
2381 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2385 public function testApiGetAttachmentsWithImageAndAndStatus()
2387 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2388 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2389 self::assertIsArray(api_get_attachments($body, 0));
2393 * Test the api_get_entitities() function.
2397 public function testApiGetEntitities()
2400 self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
2404 * Test the api_get_entitities() function with the include_entities parameter.
2408 public function testApiGetEntititiesWithIncludeEntities()
2410 $_REQUEST['include_entities'] = 'true';
2412 $result = api_get_entitities($text, 'bbcode', 0);
2413 self::assertIsArray($result['hashtags']);
2414 self::assertIsArray($result['symbols']);
2415 self::assertIsArray($result['urls']);
2416 self::assertIsArray($result['user_mentions']);
2420 * Test the api_format_items_embeded_images() function.
2424 public function testApiFormatItemsEmbededImages()
2427 'text ' . DI::baseUrl() . '/display/item_guid',
2428 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2433 * Test the api_contactlink_to_array() function.
2437 public function testApiContactlinkToArray()
2444 api_contactlink_to_array('text')
2449 * Test the api_contactlink_to_array() function with an URL.
2453 public function testApiContactlinkToArrayWithUrl()
2457 'name' => ['link_text'],
2460 api_contactlink_to_array('text <a href="url">link_text</a>')
2465 * Test the api_format_items_activities() function.
2469 public function testApiFormatItemsActivities()
2471 $item = ['uid' => 0, 'uri' => ''];
2472 $result = api_format_items_activities($item);
2473 self::assertArrayHasKey('like', $result);
2474 self::assertArrayHasKey('dislike', $result);
2475 self::assertArrayHasKey('attendyes', $result);
2476 self::assertArrayHasKey('attendno', $result);
2477 self::assertArrayHasKey('attendmaybe', $result);
2481 * Test the api_format_items_activities() function with an XML result.
2485 public function testApiFormatItemsActivitiesWithXml()
2487 $item = ['uid' => 0, 'uri' => ''];
2488 $result = api_format_items_activities($item, 'xml');
2489 self::assertArrayHasKey('friendica:like', $result);
2490 self::assertArrayHasKey('friendica:dislike', $result);
2491 self::assertArrayHasKey('friendica:attendyes', $result);
2492 self::assertArrayHasKey('friendica:attendno', $result);
2493 self::assertArrayHasKey('friendica:attendmaybe', $result);
2497 * Test the api_format_items() function.
2498 * @doesNotPerformAssertions
2500 public function testApiFormatItems()
2504 'item_network' => 'item_network',
2510 'author-network' => Protocol::DFRN,
2511 'author-link' => 'http://localhost/profile/othercontact',
2515 $result = api_format_items($items, ['id' => 0], true);
2516 foreach ($result as $status) {
2517 self::assertStatus($status);
2522 * Test the api_format_items() function with an XML result.
2523 * @doesNotPerformAssertions
2525 public function testApiFormatItemsWithXml()
2533 'author-network' => Protocol::DFRN,
2534 'author-link' => 'http://localhost/profile/othercontact',
2538 $result = api_format_items($items, ['id' => 0], true, 'xml');
2539 foreach ($result as $status) {
2540 self::assertStatus($status);
2545 * Test the api_format_items() function.
2549 public function testApiAccountRateLimitStatus()
2551 // @todo How to test the new API?
2552 // $result = api_account_rate_limit_status('json');
2553 // self::assertEquals(150, $result['hash']['remaining_hits']);
2554 // self::assertEquals(150, $result['hash']['hourly_limit']);
2555 // self::assertIsInt($result['hash']['reset_time_in_seconds']);
2559 * Test the api_format_items() function with an XML result.
2563 public function testApiAccountRateLimitStatusWithXml()
2565 // @todo How to test the new API?
2566 // $result = api_account_rate_limit_status('xml');
2567 // self::assertXml($result, 'hash');
2571 * Test the api_help_test() function.
2575 public function testApiHelpTest()
2577 // @todo How to test the new API?
2578 // $result = \Friendica\Module\Api\Friendica\Help\Test::rawcontent(['extension' => 'json']);
2579 // self::assertEquals(['ok' => 'ok'], $result);
2583 * Test the api_help_test() function with an XML result.
2587 public function testApiHelpTestWithXml()
2589 // @todo How to test the new API?
2590 // $result = api_help_test('xml');
2591 // self::assertXml($result, 'ok');
2595 * Test the api_lists_list() function.
2599 public function testApiListsList()
2601 $result = api_lists_list('json');
2602 self::assertEquals(['lists_list' => []], $result);
2606 * Test the api_lists_ownerships() function.
2610 public function testApiListsOwnerships()
2612 $result = api_lists_ownerships('json');
2613 foreach ($result['lists']['lists'] as $list) {
2614 self::assertList($list);
2619 * Test the api_lists_ownerships() function without an authenticated user.
2623 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2625 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2626 $_SESSION['authenticated'] = false;
2627 api_lists_ownerships('json');
2631 * Test the api_lists_statuses() function.
2635 public function testApiListsStatuses()
2637 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2638 api_lists_statuses('json');
2642 * Test the api_lists_statuses() function with a list ID.
2643 * @doesNotPerformAssertions
2645 public function testApiListsStatusesWithListId()
2647 $_REQUEST['list_id'] = 1;
2648 $_REQUEST['page'] = -1;
2649 $_REQUEST['max_id'] = 10;
2650 $result = api_lists_statuses('json');
2651 foreach ($result['status'] as $status) {
2652 self::assertStatus($status);
2657 * Test the api_lists_statuses() function with a list ID and a RSS result.
2661 public function testApiListsStatusesWithListIdAndRss()
2663 $_REQUEST['list_id'] = 1;
2664 $result = api_lists_statuses('rss');
2665 self::assertXml($result, 'statuses');
2669 * Test the api_lists_statuses() function with an unallowed user.
2673 public function testApiListsStatusesWithUnallowedUser()
2675 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2676 $_SESSION['allow_api'] = false;
2677 $_GET['screen_name'] = $this->selfUser['nick'];
2678 api_lists_statuses('json');
2682 * Test the api_statuses_f() function.
2686 public function testApiStatusesFWithFriends()
2689 $result = api_statuses_f('friends');
2690 self::assertArrayHasKey('user', $result);
2694 * Test the api_statuses_f() function.
2698 public function testApiStatusesFWithFollowers()
2700 $result = api_statuses_f('followers');
2701 self::assertArrayHasKey('user', $result);
2705 * Test the api_statuses_f() function.
2709 public function testApiStatusesFWithBlocks()
2711 $result = api_statuses_f('blocks');
2712 self::assertArrayHasKey('user', $result);
2716 * Test the api_statuses_f() function.
2720 public function testApiStatusesFWithIncoming()
2722 $result = api_statuses_f('incoming');
2723 self::assertArrayHasKey('user', $result);
2727 * Test the api_statuses_f() function an undefined cursor GET variable.
2731 public function testApiStatusesFWithUndefinedCursor()
2733 $_GET['cursor'] = 'undefined';
2734 self::assertFalse(api_statuses_f('friends'));
2738 * Test the api_statuses_friends() function.
2742 public function testApiStatusesFriends()
2744 $result = api_statuses_friends('json');
2745 self::assertArrayHasKey('user', $result);
2749 * Test the api_statuses_friends() function an undefined cursor GET variable.
2753 public function testApiStatusesFriendsWithUndefinedCursor()
2755 $_GET['cursor'] = 'undefined';
2756 self::assertFalse(api_statuses_friends('json'));
2760 * Test the api_statuses_followers() function.
2764 public function testApiStatusesFollowers()
2766 $result = api_statuses_followers('json');
2767 self::assertArrayHasKey('user', $result);
2771 * Test the api_statuses_followers() function an undefined cursor GET variable.
2775 public function testApiStatusesFollowersWithUndefinedCursor()
2777 $_GET['cursor'] = 'undefined';
2778 self::assertFalse(api_statuses_followers('json'));
2782 * Test the api_blocks_list() function.
2786 public function testApiBlocksList()
2788 $result = api_blocks_list('json');
2789 self::assertArrayHasKey('user', $result);
2793 * Test the api_blocks_list() function an undefined cursor GET variable.
2797 public function testApiBlocksListWithUndefinedCursor()
2799 $_GET['cursor'] = 'undefined';
2800 self::assertFalse(api_blocks_list('json'));
2804 * Test the api_friendships_incoming() function.
2808 public function testApiFriendshipsIncoming()
2810 $result = api_friendships_incoming('json');
2811 self::assertArrayHasKey('id', $result);
2815 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2819 public function testApiFriendshipsIncomingWithUndefinedCursor()
2821 $_GET['cursor'] = 'undefined';
2822 self::assertFalse(api_friendships_incoming('json'));
2826 * Test the api_statusnet_config() function.
2830 public function testApiStatusnetConfig()
2832 $result = api_statusnet_config('json');
2833 self::assertEquals('localhost', $result['config']['site']['server']);
2834 self::assertEquals('default', $result['config']['site']['theme']);
2835 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2836 self::assertTrue($result['config']['site']['fancy']);
2837 self::assertEquals('en', $result['config']['site']['language']);
2838 self::assertEquals('UTC', $result['config']['site']['timezone']);
2839 self::assertEquals(200000, $result['config']['site']['textlimit']);
2840 self::assertEquals('false', $result['config']['site']['private']);
2841 self::assertEquals('false', $result['config']['site']['ssl']);
2842 self::assertEquals(30, $result['config']['site']['shorturllength']);
2846 * Test the api_statusnet_version() function.
2850 public function testApiStatusnetVersion()
2852 // @todo How to test the new API?
2853 // $result = api_statusnet_version('json');
2854 // self::assertEquals('0.9.7', $result['version']);
2858 * Test the api_direct_messages_new() function.
2862 public function testApiDirectMessagesNew()
2864 $result = api_direct_messages_new('json');
2865 self::assertNull($result);
2869 * Test the api_direct_messages_new() function without an authenticated user.
2873 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2875 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2876 $_SESSION['authenticated'] = false;
2877 api_direct_messages_new('json');
2881 * Test the api_direct_messages_new() function with an user ID.
2885 public function testApiDirectMessagesNewWithUserId()
2887 $_POST['text'] = 'message_text';
2888 $_POST['user_id'] = $this->otherUser['id'];
2889 $result = api_direct_messages_new('json');
2890 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2894 * Test the api_direct_messages_new() function with a screen name.
2898 public function testApiDirectMessagesNewWithScreenName()
2900 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2901 $_POST['text'] = 'message_text';
2902 $_POST['screen_name'] = $this->friendUser['nick'];
2903 $result = api_direct_messages_new('json');
2904 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2905 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2906 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2910 * Test the api_direct_messages_new() function with a title.
2914 public function testApiDirectMessagesNewWithTitle()
2916 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2917 $_POST['text'] = 'message_text';
2918 $_POST['screen_name'] = $this->friendUser['nick'];
2919 $_REQUEST['title'] = 'message_title';
2920 $result = api_direct_messages_new('json');
2921 self::assertStringContainsString('message_text', $result['direct_message']['text']);
2922 self::assertStringContainsString('message_title', $result['direct_message']['text']);
2923 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2924 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2928 * Test the api_direct_messages_new() function with an RSS result.
2932 public function testApiDirectMessagesNewWithRss()
2934 $this->app->setLoggedInUserNickname($this->selfUser['nick']);
2935 $_POST['text'] = 'message_text';
2936 $_POST['screen_name'] = $this->friendUser['nick'];
2937 $result = api_direct_messages_new('rss');
2938 self::assertXml($result, 'direct-messages');
2942 * Test the api_direct_messages_destroy() function.
2946 public function testApiDirectMessagesDestroy()
2948 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2949 api_direct_messages_destroy('json');
2953 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2957 public function testApiDirectMessagesDestroyWithVerbose()
2959 $_GET['friendica_verbose'] = 'true';
2960 $result = api_direct_messages_destroy('json');
2964 'result' => 'error',
2965 'message' => 'message id or parenturi not specified'
2973 * Test the api_direct_messages_destroy() function without an authenticated user.
2977 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2979 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
2980 $_SESSION['authenticated'] = false;
2981 api_direct_messages_destroy('json');
2985 * Test the api_direct_messages_destroy() function with a non-zero ID.
2989 public function testApiDirectMessagesDestroyWithId()
2991 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
2992 $_REQUEST['id'] = 1;
2993 api_direct_messages_destroy('json');
2997 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3001 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3003 $_REQUEST['id'] = 1;
3004 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3005 $_GET['friendica_verbose'] = 'true';
3006 $result = api_direct_messages_destroy('json');
3010 'result' => 'error',
3011 'message' => 'message id not in database'
3019 * Test the api_direct_messages_destroy() function with a non-zero ID.
3023 public function testApiDirectMessagesDestroyWithCorrectId()
3025 $this->markTestIncomplete('We need to add a dataset for this.');
3029 * Test the api_direct_messages_box() function.
3033 public function testApiDirectMessagesBoxWithSentbox()
3035 $_REQUEST['page'] = -1;
3036 $_REQUEST['max_id'] = 10;
3037 $result = api_direct_messages_box('json', 'sentbox', 'false');
3038 self::assertArrayHasKey('direct_message', $result);
3042 * Test the api_direct_messages_box() function.
3046 public function testApiDirectMessagesBoxWithConversation()
3048 $result = api_direct_messages_box('json', 'conversation', 'false');
3049 self::assertArrayHasKey('direct_message', $result);
3053 * Test the api_direct_messages_box() function.
3057 public function testApiDirectMessagesBoxWithAll()
3059 $result = api_direct_messages_box('json', 'all', 'false');
3060 self::assertArrayHasKey('direct_message', $result);
3064 * Test the api_direct_messages_box() function.
3068 public function testApiDirectMessagesBoxWithInbox()
3070 $result = api_direct_messages_box('json', 'inbox', 'false');
3071 self::assertArrayHasKey('direct_message', $result);
3075 * Test the api_direct_messages_box() function.
3079 public function testApiDirectMessagesBoxWithVerbose()
3081 $result = api_direct_messages_box('json', 'sentbox', 'true');
3085 'result' => 'error',
3086 'message' => 'no mails available'
3094 * Test the api_direct_messages_box() function with a RSS result.
3098 public function testApiDirectMessagesBoxWithRss()
3100 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3101 self::assertXml($result, 'direct-messages');
3105 * Test the api_direct_messages_box() function without an authenticated user.
3109 public function testApiDirectMessagesBoxWithUnallowedUser()
3111 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3112 $_SESSION['allow_api'] = false;
3113 $_GET['screen_name'] = $this->selfUser['nick'];
3114 api_direct_messages_box('json', 'sentbox', 'false');
3118 * Test the api_direct_messages_sentbox() function.
3122 public function testApiDirectMessagesSentbox()
3124 $result = api_direct_messages_sentbox('json');
3125 self::assertArrayHasKey('direct_message', $result);
3129 * Test the api_direct_messages_inbox() function.
3133 public function testApiDirectMessagesInbox()
3135 $result = api_direct_messages_inbox('json');
3136 self::assertArrayHasKey('direct_message', $result);
3140 * Test the api_direct_messages_all() function.
3144 public function testApiDirectMessagesAll()
3146 $result = api_direct_messages_all('json');
3147 self::assertArrayHasKey('direct_message', $result);
3151 * Test the api_direct_messages_conversation() function.
3155 public function testApiDirectMessagesConversation()
3157 $result = api_direct_messages_conversation('json');
3158 self::assertArrayHasKey('direct_message', $result);
3162 * Test the api_oauth_request_token() function.
3166 public function testApiOauthRequestToken()
3168 $this->markTestIncomplete('exit() kills phpunit as well');
3172 * Test the api_oauth_access_token() function.
3176 public function testApiOauthAccessToken()
3178 $this->markTestIncomplete('exit() kills phpunit as well');
3182 * Test the api_fr_photos_list() function.
3186 public function testApiFrPhotosList()
3188 $result = api_fr_photos_list('json');
3189 self::assertArrayHasKey('photo', $result);
3193 * Test the api_fr_photos_list() function without an authenticated user.
3197 public function testApiFrPhotosListWithoutAuthenticatedUser()
3199 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3200 $_SESSION['authenticated'] = false;
3201 api_fr_photos_list('json');
3205 * Test the api_fr_photo_create_update() function.
3207 public function testApiFrPhotoCreateUpdate()
3209 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3210 api_fr_photo_create_update('json');
3214 * Test the api_fr_photo_create_update() function without an authenticated user.
3218 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3220 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3221 $_SESSION['authenticated'] = false;
3222 api_fr_photo_create_update('json');
3226 * Test the api_fr_photo_create_update() function with an album name.
3230 public function testApiFrPhotoCreateUpdateWithAlbum()
3232 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3233 $_REQUEST['album'] = 'album_name';
3234 api_fr_photo_create_update('json');
3238 * Test the api_fr_photo_create_update() function with the update mode.
3242 public function testApiFrPhotoCreateUpdateWithUpdate()
3244 $this->markTestIncomplete('We need to create a dataset for this');
3248 * Test the api_fr_photo_create_update() function with an uploaded file.
3252 public function testApiFrPhotoCreateUpdateWithFile()
3254 $this->markTestIncomplete();
3258 * Test the api_fr_photo_detail() function.
3262 public function testApiFrPhotoDetail()
3264 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3265 api_fr_photo_detail('json');
3269 * Test the api_fr_photo_detail() function without an authenticated user.
3273 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3275 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3276 $_SESSION['authenticated'] = false;
3277 api_fr_photo_detail('json');
3281 * Test the api_fr_photo_detail() function with a photo ID.
3285 public function testApiFrPhotoDetailWithPhotoId()
3287 $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
3288 $_REQUEST['photo_id'] = 1;
3289 api_fr_photo_detail('json');
3293 * Test the api_fr_photo_detail() function with a correct photo ID.
3297 public function testApiFrPhotoDetailCorrectPhotoId()
3299 $this->markTestIncomplete('We need to create a dataset for this.');
3303 * Test the api_account_update_profile_image() function.
3307 public function testApiAccountUpdateProfileImage()
3309 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3310 api_account_update_profile_image('json');
3314 * Test the api_account_update_profile_image() function without an authenticated user.
3318 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3320 $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
3321 $_SESSION['authenticated'] = false;
3322 api_account_update_profile_image('json');
3326 * Test the api_account_update_profile_image() function with an uploaded file.
3330 public function testApiAccountUpdateProfileImageWithUpload()
3332 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
3333 $this->markTestIncomplete();
3338 * Test the api_account_update_profile() function.
3342 public function testApiAccountUpdateProfile()
3344 $_POST['name'] = 'new_name';
3345 $_POST['description'] = 'new_description';
3346 $result = api_account_update_profile('json');
3347 // We can't use assertSelfUser() here because the user object is missing some properties.
3348 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3349 self::assertEquals('DFRN', $result['user']['location']);
3350 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3351 self::assertEquals('dfrn', $result['user']['network']);
3352 self::assertEquals('new_name', $result['user']['name']);
3353 self::assertEquals('new_description', $result['user']['description']);
3357 * Test the check_acl_input() function.
3361 public function testCheckAclInput()
3363 $result = check_acl_input('<aclstring>');
3364 // Where does this result come from?
3365 self::assertEquals(1, $result);
3369 * Test the check_acl_input() function with an empty ACL string.
3373 public function testCheckAclInputWithEmptyAclString()
3375 $result = check_acl_input(' ');
3376 self::assertFalse($result);
3380 * Test the save_media_to_database() function.
3384 public function testSaveMediaToDatabase()
3386 $this->markTestIncomplete();
3390 * Test the post_photo_item() function.
3394 public function testPostPhotoItem()
3396 $this->markTestIncomplete();
3400 * Test the prepare_photo_data() function.
3404 public function testPreparePhotoData()
3406 $this->markTestIncomplete();
3410 * Test the api_share_as_retweet() function with a valid item.
3414 public function testApiShareAsRetweetWithValidItem()
3416 $this->markTestIncomplete();
3420 * Test the api_in_reply_to() function.
3424 public function testApiInReplyTo()
3426 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3427 self::assertArrayHasKey('status_id', $result);
3428 self::assertArrayHasKey('user_id', $result);
3429 self::assertArrayHasKey('status_id_str', $result);
3430 self::assertArrayHasKey('user_id_str', $result);
3431 self::assertArrayHasKey('screen_name', $result);
3435 * Test the api_in_reply_to() function with a valid item.
3439 public function testApiInReplyToWithValidItem()
3441 $this->markTestIncomplete();
3445 * Test the api_clean_plain_items() function.
3449 public function testApiCleanPlainItems()
3451 $_REQUEST['include_entities'] = 'true';
3452 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3453 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3457 * Test the api_best_nickname() function.
3461 public function testApiBestNickname()
3464 $result = api_best_nickname($contacts);
3465 self::assertNull($result);
3469 * Test the api_best_nickname() function with contacts.
3473 public function testApiBestNicknameWithContacts()
3475 $this->markTestIncomplete();
3479 * Test the api_friendica_group_show() function.
3483 public function testApiFriendicaGroupShow()
3485 $this->markTestIncomplete();
3489 * Test the api_friendica_group_delete() function.
3493 public function testApiFriendicaGroupDelete()
3495 $this->markTestIncomplete();
3499 * Test the api_lists_destroy() function.
3503 public function testApiListsDestroy()
3505 $this->markTestIncomplete();
3509 * Test the group_create() function.
3513 public function testGroupCreate()
3515 $this->markTestIncomplete();
3519 * Test the api_friendica_group_create() function.
3523 public function testApiFriendicaGroupCreate()
3525 $this->markTestIncomplete();
3529 * Test the api_lists_create() function.
3533 public function testApiListsCreate()
3535 $this->markTestIncomplete();
3539 * Test the api_friendica_group_update() function.
3543 public function testApiFriendicaGroupUpdate()
3545 $this->markTestIncomplete();
3549 * Test the api_lists_update() function.
3553 public function testApiListsUpdate()
3555 $this->markTestIncomplete();
3559 * Test the api_friendica_activity() function.
3563 public function testApiFriendicaActivity()
3565 $this->markTestIncomplete();
3569 * Test the api_friendica_notification_seen() function.
3573 public function testApiFriendicaNotificationSeen()
3575 $this->markTestIncomplete();
3579 * Test the api_friendica_direct_messages_setseen() function.
3583 public function testApiFriendicaDirectMessagesSetseen()
3585 $this->markTestIncomplete();
3589 * Test the api_friendica_direct_messages_search() function.
3593 public function testApiFriendicaDirectMessagesSearch()
3595 $this->markTestIncomplete();
3599 * Test the api_saved_searches_list() function.
3603 public function testApiSavedSearchesList()
3605 // $result = api_saved_searches_list('json');
3606 // self::assertEquals(1, $result['terms'][0]['id']);
3607 // self::assertEquals(1, $result['terms'][0]['id_str']);
3608 // self::assertEquals('Saved search', $result['terms'][0]['name']);
3609 // self::assertEquals('Saved search', $result['terms'][0]['query']);