6 namespace Friendica\Test\legacy;
9 use Friendica\Core\Config\IConfig;
10 use Friendica\Core\PConfig\IPConfig;
11 use Friendica\Core\Protocol;
13 use Friendica\Network\HTTPException;
14 use Friendica\Test\FixtureTest;
15 use Friendica\Util\Temporal;
16 use Monolog\Handler\TestHandler;
18 require_once __DIR__ . '/../../include/api.php';
21 * Tests for the API functions.
23 * Functions that use header() need to be tested in a separate process.
24 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
26 class ApiTest extends FixtureTest
29 * @var TestHandler Can handle log-outputs
36 protected $friendUser;
40 protected $wrongUserId;
49 * Create variables used by tests.
51 protected function setUp()
53 global $API, $called_api;
59 /** @var IConfig $config */
60 $this->config = $this->dice->create(IConfig::class);
62 $this->config->set('system', 'url', 'http://localhost');
63 $this->config->set('system', 'hostname', 'localhost');
64 $this->config->set('system', 'worker_dont_fork', true);
67 $this->config->set('config', 'hostname', 'localhost');
68 $this->config->set('system', 'throttle_limit_day', 100);
69 $this->config->set('system', 'throttle_limit_week', 100);
70 $this->config->set('system', 'throttle_limit_month', 100);
71 $this->config->set('system', 'theme', 'system_theme');
75 $this->app = DI::app();
78 $this->app->argv = [''];
80 // User data that the test database is populated with
83 'name' => 'Self contact',
84 'nick' => 'selfcontact',
85 'nurl' => 'http://localhost/profile/selfcontact'
89 'name' => 'Friend contact',
90 'nick' => 'friendcontact',
91 'nurl' => 'http://localhost/profile/friendcontact'
95 'name' => 'othercontact',
96 'nick' => 'othercontact',
97 'nurl' => 'http://localhost/profile/othercontact'
100 // User ID that we know is not in the database
101 $this->wrongUserId = 666;
103 DI::session()->start();
105 // Most API require login so we force the session
108 'authenticated' => true,
109 'uid' => $this->selfUser['id']
118 * Assert that an user array contains expected keys.
120 * @param array $user User array
124 private function assertSelfUser(array $user)
126 self::assertEquals($this->selfUser['id'], $user['uid']);
127 self::assertEquals($this->selfUser['id'], $user['cid']);
128 self::assertEquals(1, $user['self']);
129 self::assertEquals('DFRN', $user['location']);
130 self::assertEquals($this->selfUser['name'], $user['name']);
131 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
132 self::assertEquals('dfrn', $user['network']);
133 self::assertTrue($user['verified']);
137 * Assert that an user array contains expected keys.
139 * @param array $user User array
143 private function assertOtherUser(array $user)
145 self::assertEquals($this->otherUser['id'], $user['id']);
146 self::assertEquals($this->otherUser['id'], $user['id_str']);
147 self::assertEquals(0, $user['self']);
148 self::assertEquals($this->otherUser['name'], $user['name']);
149 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
150 self::assertFalse($user['verified']);
154 * Assert that a status array contains expected keys.
156 * @param array $status Status array
160 private function assertStatus(array $status)
162 self::assertInternalType('string', $status['text']);
163 self::assertInternalType('int', $status['id']);
164 // We could probably do more checks here.
168 * Assert that a list array contains expected keys.
170 * @param array $list List array
174 private function assertList(array $list)
176 self::assertInternalType('string', $list['name']);
177 self::assertInternalType('int', $list['id']);
178 self::assertInternalType('string', $list['id_str']);
179 self::assertContains($list['mode'], ['public', 'private']);
180 // We could probably do more checks here.
184 * Assert that the string is XML and contain the root element.
186 * @param string $result XML string
187 * @param string $root_element Root element name
191 private function assertXml($result, $root_element)
193 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
194 self::assertContains('<' . $root_element, $result);
195 // We could probably do more checks here.
199 * Get the path to a temporary empty PNG image.
201 * @return string Path
203 private function getTempImage()
205 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
209 // Empty 1x1 px PNG image
210 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
218 * Test the api_user() function.
222 public function testApiUser()
224 self::assertEquals($this->selfUser['id'], api_user());
228 * Test the api_user() function with an unallowed user.
232 public function testApiUserWithUnallowedUser()
234 $_SESSION = ['allow_api' => false];
235 self::assertEquals(false, api_user());
239 * Test the api_source() function.
243 public function testApiSource()
245 self::assertEquals('api', api_source());
249 * Test the api_source() function with a Twidere user agent.
253 public function testApiSourceWithTwidere()
255 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
256 self::assertEquals('Twidere', api_source());
260 * Test the api_source() function with a GET parameter.
264 public function testApiSourceWithGet()
266 $_GET['source'] = 'source_name';
267 self::assertEquals('source_name', api_source());
271 * Test the api_date() function.
275 public function testApiDate()
277 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
281 * Test the api_register_func() function.
285 public function testApiRegisterFunc()
297 self::assertTrue($API['api_path']['auth']);
298 self::assertEquals('method', $API['api_path']['method']);
299 self::assertTrue(is_callable($API['api_path']['func']));
303 * Test the api_login() function without any login.
306 * @runInSeparateProcess
307 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
309 public function testApiLoginWithoutLogin()
311 api_login($this->app);
315 * Test the api_login() function with a bad login.
318 * @runInSeparateProcess
319 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
321 public function testApiLoginWithBadLogin()
323 $_SERVER['PHP_AUTH_USER'] = 'user@server';
324 api_login($this->app);
328 * Test the api_login() function with oAuth.
332 public function testApiLoginWithOauth()
334 $this->markTestIncomplete('Can we test this easily?');
338 * Test the api_login() function with authentication provided by an addon.
342 public function testApiLoginWithAddonAuth()
344 $this->markTestIncomplete('Can we test this easily?');
348 * Test the api_login() function with a correct login.
351 * @runInSeparateProcess
353 public function testApiLoginWithCorrectLogin()
355 $_SERVER['PHP_AUTH_USER'] = 'Test user';
356 $_SERVER['PHP_AUTH_PW'] = 'password';
357 api_login($this->app);
361 * Test the api_login() function with a remote user.
364 * @runInSeparateProcess
365 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
367 public function testApiLoginWithRemoteUser()
369 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
370 api_login($this->app);
374 * Test the api_check_method() function.
378 public function testApiCheckMethod()
380 self::assertFalse(api_check_method('method'));
384 * Test the api_check_method() function with a correct method.
388 public function testApiCheckMethodWithCorrectMethod()
390 $_SERVER['REQUEST_METHOD'] = 'method';
391 self::assertTrue(api_check_method('method'));
395 * Test the api_check_method() function with a wildcard.
399 public function testApiCheckMethodWithWildcard()
401 self::assertTrue(api_check_method('*'));
405 * Test the api_call() function.
408 * @runInSeparateProcess
410 public function testApiCall()
414 'method' => 'method',
415 'func' => function () {
416 return ['data' => ['some_data']];
419 $_SERVER['REQUEST_METHOD'] = 'method';
420 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
421 $_GET['callback'] = 'callback_name';
423 $args = DI::args()->determine($_SERVER, $_GET);
426 'callback_name(["some_data"])',
427 api_call($this->app, $args)
432 * Test the api_call() function with the profiled enabled.
435 * @runInSeparateProcess
437 public function testApiCallWithProfiler()
441 'method' => 'method',
442 'func' => function () {
443 return ['data' => ['some_data']];
447 $_SERVER['REQUEST_METHOD'] = 'method';
448 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
450 $args = DI::args()->determine($_SERVER, $_GET);
452 $this->config->set('system', 'profiler', true);
453 $this->config->set('rendertime', 'callstack', true);
454 $this->app->callstack = [
455 'database' => ['some_function' => 200],
456 'database_write' => ['some_function' => 200],
457 'cache' => ['some_function' => 200],
458 'cache_write' => ['some_function' => 200],
459 'network' => ['some_function' => 200]
464 api_call($this->app, $args)
469 * Test the api_call() function without any result.
472 * @runInSeparateProcess
474 public function testApiCallWithNoResult()
478 'method' => 'method',
479 'func' => function () {
483 $_SERVER['REQUEST_METHOD'] = 'method';
484 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
486 $args = DI::args()->determine($_SERVER, $_GET);
489 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
490 api_call($this->app, $args)
495 * Test the api_call() function with an unimplemented API.
498 * @runInSeparateProcess
500 public function testApiCallWithUninplementedApi()
503 '{"status":{"error":"Not Found","code":"404 Not Found","request":""}}',
509 * Test the api_call() function with a JSON result.
512 * @runInSeparateProcess
514 public function testApiCallWithJson()
518 'method' => 'method',
519 'func' => function () {
520 return ['data' => ['some_data']];
523 $_SERVER['REQUEST_METHOD'] = 'method';
524 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
526 $args = DI::args()->determine($_SERVER, $_GET);
530 api_call($this->app, $args)
535 * Test the api_call() function with an XML result.
538 * @runInSeparateProcess
540 public function testApiCallWithXml()
544 'method' => 'method',
545 'func' => function () {
549 $_SERVER['REQUEST_METHOD'] = 'method';
550 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
552 $args = DI::args()->determine($_SERVER, $_GET);
556 api_call($this->app, $args)
561 * Test the api_call() function with an RSS result.
564 * @runInSeparateProcess
566 public function testApiCallWithRss()
570 'method' => 'method',
571 'func' => function () {
575 $_SERVER['REQUEST_METHOD'] = 'method';
576 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
578 $args = DI::args()->determine($_SERVER, $_GET);
581 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
583 api_call($this->app, $args)
588 * Test the api_call() function with an Atom result.
591 * @runInSeparateProcess
593 public function testApiCallWithAtom()
597 'method' => 'method',
598 'func' => function () {
602 $_SERVER['REQUEST_METHOD'] = 'method';
603 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
605 $args = DI::args()->determine($_SERVER, $_GET);
608 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
610 api_call($this->app, $args)
615 * Test the api_call() function with an unallowed method.
618 * @runInSeparateProcess
620 public function testApiCallWithWrongMethod()
623 $API['api_path'] = ['method' => 'method'];
625 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
627 $args = DI::args()->determine($_SERVER, $_GET);
630 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
631 api_call($this->app, $args)
636 * Test the api_call() function with an unauthorized user.
639 * @runInSeparateProcess
641 public function testApiCallWithWrongAuth()
645 'method' => 'method',
648 $_SESSION['authenticated'] = false;
649 $_SERVER['REQUEST_METHOD'] = 'method';
650 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
652 $args = DI::args()->determine($_SERVER, $_GET);
655 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
656 api_call($this->app, $args)
661 * Test the api_error() function with a JSON result.
664 * @runInSeparateProcess
666 public function testApiErrorWithJson()
669 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
670 api_error('json', new HTTPException\OKException('error_message'), DI::args())
675 * Test the api_error() function with an XML result.
678 * @runInSeparateProcess
680 public function testApiErrorWithXml()
683 '<?xml version="1.0"?>' . "\n" .
684 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
685 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
686 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
687 ' <error>error_message</error>' . "\n" .
688 ' <code>200 OK</code>' . "\n" .
689 ' <request/>' . "\n" .
691 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
696 * Test the api_error() function with an RSS result.
699 * @runInSeparateProcess
701 public function testApiErrorWithRss()
704 '<?xml version="1.0"?>' . "\n" .
705 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
706 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
707 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
708 ' <error>error_message</error>' . "\n" .
709 ' <code>200 OK</code>' . "\n" .
710 ' <request/>' . "\n" .
712 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
717 * Test the api_error() function with an Atom result.
720 * @runInSeparateProcess
722 public function testApiErrorWithAtom()
725 '<?xml version="1.0"?>' . "\n" .
726 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
727 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
728 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
729 ' <error>error_message</error>' . "\n" .
730 ' <code>200 OK</code>' . "\n" .
731 ' <request/>' . "\n" .
733 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
738 * Test the api_rss_extra() function.
742 public function testApiRssExtra()
744 $user_info = ['url' => 'user_url', 'lang' => 'en'];
745 $result = api_rss_extra($this->app, [], $user_info);
746 self::assertEquals($user_info, $result['$user']);
747 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
748 self::assertArrayHasKey('self', $result['$rss']);
749 self::assertArrayHasKey('base', $result['$rss']);
750 self::assertArrayHasKey('updated', $result['$rss']);
751 self::assertArrayHasKey('atom_updated', $result['$rss']);
752 self::assertArrayHasKey('language', $result['$rss']);
753 self::assertArrayHasKey('logo', $result['$rss']);
757 * Test the api_rss_extra() function without any user info.
761 public function testApiRssExtraWithoutUserInfo()
763 $result = api_rss_extra($this->app, [], null);
764 self::assertInternalType('array', $result['$user']);
765 self::assertArrayHasKey('alternate', $result['$rss']);
766 self::assertArrayHasKey('self', $result['$rss']);
767 self::assertArrayHasKey('base', $result['$rss']);
768 self::assertArrayHasKey('updated', $result['$rss']);
769 self::assertArrayHasKey('atom_updated', $result['$rss']);
770 self::assertArrayHasKey('language', $result['$rss']);
771 self::assertArrayHasKey('logo', $result['$rss']);
775 * Test the api_unique_id_to_nurl() function.
779 public function testApiUniqueIdToNurl()
781 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
785 * Test the api_unique_id_to_nurl() function with a correct ID.
789 public function testApiUniqueIdToNurlWithCorrectId()
791 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
795 * Test the api_get_user() function.
799 public function testApiGetUser()
801 $user = api_get_user($this->app);
802 self::assertSelfUser($user);
803 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
804 self::assertEquals('6fdbe8', $user['profile_link_color']);
805 self::assertEquals('ededed', $user['profile_background_color']);
809 * Test the api_get_user() function with a Frio schema.
813 public function testApiGetUserWithFrioSchema()
815 $pConfig = $this->dice->create(IPConfig::class);
816 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
817 $user = api_get_user($this->app);
818 self::assertSelfUser($user);
819 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
820 self::assertEquals('6fdbe8', $user['profile_link_color']);
821 self::assertEquals('ededed', $user['profile_background_color']);
825 * Test the api_get_user() function with an empty Frio schema.
829 public function testApiGetUserWithEmptyFrioSchema()
831 $pConfig = $this->dice->create(IPConfig::class);
832 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
833 $user = api_get_user($this->app);
834 self::assertSelfUser($user);
835 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
836 self::assertEquals('6fdbe8', $user['profile_link_color']);
837 self::assertEquals('ededed', $user['profile_background_color']);
841 * Test the api_get_user() function with a custom Frio schema.
845 public function testApiGetUserWithCustomFrioSchema()
847 $pConfig = $this->dice->create(IPConfig::class);
848 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
849 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
850 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
851 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
852 $user = api_get_user($this->app);
853 self::assertSelfUser($user);
854 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
855 self::assertEquals('123456', $user['profile_link_color']);
856 self::assertEquals('123456', $user['profile_background_color']);
860 * Test the api_get_user() function with an user that is not allowed to use the API.
863 * @runInSeparateProcess
865 public function testApiGetUserWithoutApiUser()
867 $_SERVER['PHP_AUTH_USER'] = 'Test user';
868 $_SERVER['PHP_AUTH_PW'] = 'password';
869 $_SESSION['allow_api'] = false;
870 self::assertFalse(api_get_user($this->app));
874 * Test the api_get_user() function with an user ID in a GET parameter.
878 public function testApiGetUserWithGetId()
880 $_GET['user_id'] = $this->otherUser['id'];
881 self::assertOtherUser(api_get_user($this->app));
885 * Test the api_get_user() function with a wrong user ID in a GET parameter.
888 * @expectedException Friendica\Network\HTTPException\BadRequestException
890 public function testApiGetUserWithWrongGetId()
892 $_GET['user_id'] = $this->wrongUserId;
893 self::assertOtherUser(api_get_user($this->app));
897 * Test the api_get_user() function with an user name in a GET parameter.
901 public function testApiGetUserWithGetName()
903 $_GET['screen_name'] = $this->selfUser['nick'];
904 self::assertSelfUser(api_get_user($this->app));
908 * Test the api_get_user() function with a profile URL in a GET parameter.
912 public function testApiGetUserWithGetUrl()
914 $_GET['profileurl'] = $this->selfUser['nurl'];
915 self::assertSelfUser(api_get_user($this->app));
919 * Test the api_get_user() function with an user ID in the API path.
923 public function testApiGetUserWithNumericCalledApi()
926 $called_api = ['api_path'];
927 $this->app->argv[1] = $this->otherUser['id'] . '.json';
928 self::assertOtherUser(api_get_user($this->app));
932 * Test the api_get_user() function with the $called_api global variable.
936 public function testApiGetUserWithCalledApi()
939 $called_api = ['api', 'api_path'];
940 self::assertSelfUser(api_get_user($this->app));
944 * Test the api_get_user() function with a valid user.
948 public function testApiGetUserWithCorrectUser()
950 self::assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
954 * Test the api_get_user() function with a wrong user ID.
957 * @expectedException Friendica\Network\HTTPException\BadRequestException
959 public function testApiGetUserWithWrongUser()
961 self::assertOtherUser(api_get_user($this->app, $this->wrongUserId));
965 * Test the api_get_user() function with a 0 user ID.
969 public function testApiGetUserWithZeroUser()
971 self::assertSelfUser(api_get_user($this->app, 0));
975 * Test the api_item_get_user() function.
979 public function testApiItemGetUser()
981 $users = api_item_get_user($this->app, []);
982 self::assertSelfUser($users[0]);
986 * Test the api_item_get_user() function with a different item parent.
990 public function testApiItemGetUserWithDifferentParent()
992 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
993 self::assertSelfUser($users[0]);
994 self::assertEquals($users[0], $users[1]);
998 * Test the api_walk_recursive() function.
1002 public function testApiWalkRecursive()
1010 // Should we test this with a callback that actually does something?
1018 * Test the api_walk_recursive() function with an array.
1022 public function testApiWalkRecursiveWithArray()
1024 $array = [['item1'], ['item2']];
1030 // Should we test this with a callback that actually does something?
1038 * Test the api_reformat_xml() function.
1042 public function testApiReformatXml()
1046 self::assertTrue(api_reformat_xml($item, $key));
1047 self::assertEquals('true', $item);
1051 * Test the api_reformat_xml() function with a statusnet_api key.
1055 public function testApiReformatXmlWithStatusnetKey()
1058 $key = 'statusnet_api';
1059 self::assertTrue(api_reformat_xml($item, $key));
1060 self::assertEquals('statusnet:api', $key);
1064 * Test the api_reformat_xml() function with a friendica_api key.
1068 public function testApiReformatXmlWithFriendicaKey()
1071 $key = 'friendica_api';
1072 self::assertTrue(api_reformat_xml($item, $key));
1073 self::assertEquals('friendica:api', $key);
1077 * Test the api_create_xml() function.
1081 public function testApiCreateXml()
1084 '<?xml version="1.0"?>' . "\n" .
1085 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1086 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1087 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1088 ' <data>some_data</data>' . "\n" .
1089 '</root_element>' . "\n",
1090 api_create_xml(['data' => ['some_data']], 'root_element')
1095 * Test the api_create_xml() function without any XML namespace.
1099 public function testApiCreateXmlWithoutNamespaces()
1102 '<?xml version="1.0"?>' . "\n" .
1104 ' <data>some_data</data>' . "\n" .
1106 api_create_xml(['data' => ['some_data']], 'ok')
1111 * Test the api_format_data() function.
1115 public function testApiFormatData()
1117 $data = ['some_data'];
1118 self::assertEquals($data, api_format_data('root_element', 'json', $data));
1122 * Test the api_format_data() function with an XML result.
1126 public function testApiFormatDataWithXml()
1129 '<?xml version="1.0"?>' . "\n" .
1130 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1131 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1132 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1133 ' <data>some_data</data>' . "\n" .
1134 '</root_element>' . "\n",
1135 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1140 * Test the api_account_verify_credentials() function.
1144 public function testApiAccountVerifyCredentials()
1146 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1150 * Test the api_account_verify_credentials() function without an authenticated user.
1153 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1155 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1157 $_SESSION['authenticated'] = false;
1158 api_account_verify_credentials('json');
1162 * Test the requestdata() function.
1166 public function testRequestdata()
1168 self::assertNull(requestdata('variable_name'));
1172 * Test the requestdata() function with a POST parameter.
1176 public function testRequestdataWithPost()
1178 $_POST['variable_name'] = 'variable_value';
1179 self::assertEquals('variable_value', requestdata('variable_name'));
1183 * Test the requestdata() function with a GET parameter.
1187 public function testRequestdataWithGet()
1189 $_GET['variable_name'] = 'variable_value';
1190 self::assertEquals('variable_value', requestdata('variable_name'));
1194 * Test the api_statuses_mediap() function.
1198 public function testApiStatusesMediap()
1200 $this->app->argc = 2;
1208 'tmp_name' => $this->getTempImage(),
1209 'name' => 'spacer.png',
1210 'type' => 'image/png'
1213 $_GET['status'] = '<b>Status content</b>';
1215 $result = api_statuses_mediap('json');
1216 self::assertStatus($result['status']);
1220 * Test the api_statuses_mediap() function without an authenticated user.
1223 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1225 public function testApiStatusesMediapWithoutAuthenticatedUser()
1227 $_SESSION['authenticated'] = false;
1228 api_statuses_mediap('json');
1232 * Test the api_statuses_update() function.
1236 public function testApiStatusesUpdate()
1238 $_GET['status'] = 'Status content #friendica';
1239 $_GET['in_reply_to_status_id'] = -1;
1248 'tmp_name' => $this->getTempImage(),
1249 'name' => 'spacer.png',
1250 'type' => 'image/png'
1254 $result = api_statuses_update('json');
1255 self::assertStatus($result['status']);
1259 * Test the api_statuses_update() function with an HTML status.
1263 public function testApiStatusesUpdateWithHtml()
1265 $_GET['htmlstatus'] = '<b>Status content</b>';
1267 $result = api_statuses_update('json');
1268 self::assertStatus($result['status']);
1272 * Test the api_statuses_update() function without an authenticated user.
1275 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1277 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1279 $_SESSION['authenticated'] = false;
1280 api_statuses_update('json');
1284 * Test the api_statuses_update() function with a parent status.
1288 public function testApiStatusesUpdateWithParent()
1290 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1294 * Test the api_statuses_update() function with a media_ids parameter.
1298 public function testApiStatusesUpdateWithMediaIds()
1300 $this->markTestIncomplete();
1304 * Test the api_statuses_update() function with the throttle limit reached.
1308 public function testApiStatusesUpdateWithDayThrottleReached()
1310 $this->markTestIncomplete();
1314 * Test the api_media_upload() function.
1317 * @expectedException Friendica\Network\HTTPException\BadRequestException
1319 public function testApiMediaUpload()
1325 * Test the api_media_upload() function without an authenticated user.
1328 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1330 public function testApiMediaUploadWithoutAuthenticatedUser()
1332 $_SESSION['authenticated'] = false;
1337 * Test the api_media_upload() function with an invalid uploaded media.
1340 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1342 public function testApiMediaUploadWithMedia()
1347 'tmp_name' => 'tmp_name'
1354 * Test the api_media_upload() function with an valid uploaded media.
1358 public function testApiMediaUploadWithValidMedia()
1366 'tmp_name' => $this->getTempImage(),
1367 'name' => 'spacer.png',
1368 'type' => 'image/png'
1374 $result = api_media_upload();
1375 self::assertEquals('image/png', $result['media']['image']['image_type']);
1376 self::assertEquals(1, $result['media']['image']['w']);
1377 self::assertEquals(1, $result['media']['image']['h']);
1378 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1382 * Test the api_status_show() function.
1384 public function testApiStatusShowWithJson()
1386 $result = api_status_show('json', 1);
1387 self::assertStatus($result['status']);
1391 * Test the api_status_show() function with an XML result.
1393 public function testApiStatusShowWithXml()
1395 $result = api_status_show('xml', 1);
1396 self::assertXml($result, 'statuses');
1400 * Test the api_get_last_status() function
1402 public function testApiGetLastStatus()
1404 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1406 self::assertNotNull($item);
1410 * Test the api_users_show() function.
1414 public function testApiUsersShow()
1416 $result = api_users_show('json');
1417 // We can't use assertSelfUser() here because the user object is missing some properties.
1418 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1419 self::assertEquals('DFRN', $result['user']['location']);
1420 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1421 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1422 self::assertEquals('dfrn', $result['user']['network']);
1423 self::assertTrue($result['user']['verified']);
1427 * Test the api_users_show() function with an XML result.
1431 public function testApiUsersShowWithXml()
1433 $result = api_users_show('xml');
1434 self::assertXml($result, 'statuses');
1438 * Test the api_users_search() function.
1442 public function testApiUsersSearch()
1444 $_GET['q'] = 'othercontact';
1445 $result = api_users_search('json');
1446 self::assertOtherUser($result['users'][0]);
1450 * Test the api_users_search() function with an XML result.
1454 public function testApiUsersSearchWithXml()
1456 $_GET['q'] = 'othercontact';
1457 $result = api_users_search('xml');
1458 self::assertXml($result, 'users');
1462 * Test the api_users_search() function without a GET q parameter.
1465 * @expectedException Friendica\Network\HTTPException\BadRequestException
1467 public function testApiUsersSearchWithoutQuery()
1469 api_users_search('json');
1473 * Test the api_users_lookup() function.
1476 * @expectedException Friendica\Network\HTTPException\NotFoundException
1478 public function testApiUsersLookup()
1480 api_users_lookup('json');
1484 * Test the api_users_lookup() function with an user ID.
1488 public function testApiUsersLookupWithUserId()
1490 $_REQUEST['user_id'] = $this->otherUser['id'];
1491 $result = api_users_lookup('json');
1492 self::assertOtherUser($result['users'][0]);
1496 * Test the api_search() function.
1500 public function testApiSearch()
1502 $_REQUEST['q'] = 'reply';
1503 $_REQUEST['max_id'] = 10;
1504 $result = api_search('json');
1505 foreach ($result['status'] as $status) {
1506 self::assertStatus($status);
1507 self::assertContains('reply', $status['text'], null, true);
1512 * Test the api_search() function a count parameter.
1516 public function testApiSearchWithCount()
1518 $_REQUEST['q'] = 'reply';
1519 $_REQUEST['count'] = 20;
1520 $result = api_search('json');
1521 foreach ($result['status'] as $status) {
1522 self::assertStatus($status);
1523 self::assertContains('reply', $status['text'], null, true);
1528 * Test the api_search() function with an rpp parameter.
1532 public function testApiSearchWithRpp()
1534 $_REQUEST['q'] = 'reply';
1535 $_REQUEST['rpp'] = 20;
1536 $result = api_search('json');
1537 foreach ($result['status'] as $status) {
1538 self::assertStatus($status);
1539 self::assertContains('reply', $status['text'], null, true);
1544 * Test the api_search() function with an q parameter contains hashtag.
1548 public function testApiSearchWithHashtag()
1550 $_REQUEST['q'] = '%23friendica';
1551 $result = api_search('json');
1552 foreach ($result['status'] as $status) {
1553 self::assertStatus($status);
1554 self::assertContains('#friendica', $status['text'], null, true);
1559 * Test the api_search() function with an exclude_replies parameter.
1563 public function testApiSearchWithExcludeReplies()
1565 $_REQUEST['max_id'] = 10;
1566 $_REQUEST['exclude_replies'] = true;
1567 $_REQUEST['q'] = 'friendica';
1568 $result = api_search('json');
1569 foreach ($result['status'] as $status) {
1570 self::assertStatus($status);
1575 * Test the api_search() function without an authenticated user.
1578 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1580 public function testApiSearchWithUnallowedUser()
1582 $_SESSION['allow_api'] = false;
1583 $_GET['screen_name'] = $this->selfUser['nick'];
1588 * Test the api_search() function without any GET query parameter.
1591 * @expectedException Friendica\Network\HTTPException\BadRequestException
1593 public function testApiSearchWithoutQuery()
1599 * Test the api_statuses_home_timeline() function.
1603 public function testApiStatusesHomeTimeline()
1605 $_REQUEST['max_id'] = 10;
1606 $_REQUEST['exclude_replies'] = true;
1607 $_REQUEST['conversation_id'] = 1;
1608 $result = api_statuses_home_timeline('json');
1609 self::assertNotEmpty($result['status']);
1610 foreach ($result['status'] as $status) {
1611 self::assertStatus($status);
1616 * Test the api_statuses_home_timeline() function with a negative page parameter.
1620 public function testApiStatusesHomeTimelineWithNegativePage()
1622 $_REQUEST['page'] = -2;
1623 $result = api_statuses_home_timeline('json');
1624 self::assertNotEmpty($result['status']);
1625 foreach ($result['status'] as $status) {
1626 self::assertStatus($status);
1631 * Test the api_statuses_home_timeline() with an unallowed user.
1634 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1636 public function testApiStatusesHomeTimelineWithUnallowedUser()
1638 $_SESSION['allow_api'] = false;
1639 $_GET['screen_name'] = $this->selfUser['nick'];
1640 api_statuses_home_timeline('json');
1644 * Test the api_statuses_home_timeline() function with an RSS result.
1648 public function testApiStatusesHomeTimelineWithRss()
1650 $result = api_statuses_home_timeline('rss');
1651 self::assertXml($result, 'statuses');
1655 * Test the api_statuses_public_timeline() function.
1659 public function testApiStatusesPublicTimeline()
1661 $_REQUEST['max_id'] = 10;
1662 $_REQUEST['conversation_id'] = 1;
1663 $result = api_statuses_public_timeline('json');
1664 self::assertNotEmpty($result['status']);
1665 foreach ($result['status'] as $status) {
1666 self::assertStatus($status);
1671 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1675 public function testApiStatusesPublicTimelineWithExcludeReplies()
1677 $_REQUEST['max_id'] = 10;
1678 $_REQUEST['exclude_replies'] = true;
1679 $result = api_statuses_public_timeline('json');
1680 self::assertNotEmpty($result['status']);
1681 foreach ($result['status'] as $status) {
1682 self::assertStatus($status);
1687 * Test the api_statuses_public_timeline() function with a negative page parameter.
1691 public function testApiStatusesPublicTimelineWithNegativePage()
1693 $_REQUEST['page'] = -2;
1694 $result = api_statuses_public_timeline('json');
1695 self::assertNotEmpty($result['status']);
1696 foreach ($result['status'] as $status) {
1697 self::assertStatus($status);
1702 * Test the api_statuses_public_timeline() function with an unallowed user.
1705 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1707 public function testApiStatusesPublicTimelineWithUnallowedUser()
1709 $_SESSION['allow_api'] = false;
1710 $_GET['screen_name'] = $this->selfUser['nick'];
1711 api_statuses_public_timeline('json');
1715 * Test the api_statuses_public_timeline() function with an RSS result.
1719 public function testApiStatusesPublicTimelineWithRss()
1721 $result = api_statuses_public_timeline('rss');
1722 self::assertXml($result, 'statuses');
1726 * Test the api_statuses_networkpublic_timeline() function.
1730 public function testApiStatusesNetworkpublicTimeline()
1732 $_REQUEST['max_id'] = 10;
1733 $result = api_statuses_networkpublic_timeline('json');
1734 self::assertNotEmpty($result['status']);
1735 foreach ($result['status'] as $status) {
1736 self::assertStatus($status);
1741 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1745 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1747 $_REQUEST['page'] = -2;
1748 $result = api_statuses_networkpublic_timeline('json');
1749 self::assertNotEmpty($result['status']);
1750 foreach ($result['status'] as $status) {
1751 self::assertStatus($status);
1756 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1759 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1761 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1763 $_SESSION['allow_api'] = false;
1764 $_GET['screen_name'] = $this->selfUser['nick'];
1765 api_statuses_networkpublic_timeline('json');
1769 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1773 public function testApiStatusesNetworkpublicTimelineWithRss()
1775 $result = api_statuses_networkpublic_timeline('rss');
1776 self::assertXml($result, 'statuses');
1780 * Test the api_statuses_show() function.
1783 * @expectedException Friendica\Network\HTTPException\BadRequestException
1785 public function testApiStatusesShow()
1787 api_statuses_show('json');
1791 * Test the api_statuses_show() function with an ID.
1795 public function testApiStatusesShowWithId()
1797 $this->app->argv[3] = 1;
1798 $result = api_statuses_show('json');
1799 self::assertStatus($result['status']);
1803 * Test the api_statuses_show() function with the conversation parameter.
1807 public function testApiStatusesShowWithConversation()
1809 $this->app->argv[3] = 1;
1810 $_REQUEST['conversation'] = 1;
1811 $result = api_statuses_show('json');
1812 self::assertNotEmpty($result['status']);
1813 foreach ($result['status'] as $status) {
1814 self::assertStatus($status);
1819 * Test the api_statuses_show() function with an unallowed user.
1822 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1824 public function testApiStatusesShowWithUnallowedUser()
1826 $_SESSION['allow_api'] = false;
1827 $_GET['screen_name'] = $this->selfUser['nick'];
1828 api_statuses_show('json');
1832 * Test the api_conversation_show() function.
1835 * @expectedException Friendica\Network\HTTPException\BadRequestException
1837 public function testApiConversationShow()
1839 api_conversation_show('json');
1843 * Test the api_conversation_show() function with an ID.
1847 public function testApiConversationShowWithId()
1849 $this->app->argv[3] = 1;
1850 $_REQUEST['max_id'] = 10;
1851 $_REQUEST['page'] = -2;
1852 $result = api_conversation_show('json');
1853 self::assertNotEmpty($result['status']);
1854 foreach ($result['status'] as $status) {
1855 self::assertStatus($status);
1860 * Test the api_conversation_show() function with an unallowed user.
1863 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1865 public function testApiConversationShowWithUnallowedUser()
1867 $_SESSION['allow_api'] = false;
1868 $_GET['screen_name'] = $this->selfUser['nick'];
1869 api_conversation_show('json');
1873 * Test the api_statuses_repeat() function.
1876 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1878 public function testApiStatusesRepeat()
1880 api_statuses_repeat('json');
1884 * Test the api_statuses_repeat() function without an authenticated user.
1887 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1889 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1891 $_SESSION['authenticated'] = false;
1892 api_statuses_repeat('json');
1896 * Test the api_statuses_repeat() function with an ID.
1900 public function testApiStatusesRepeatWithId()
1902 $this->app->argv[3] = 1;
1903 $result = api_statuses_repeat('json');
1904 self::assertStatus($result['status']);
1906 // Also test with a shared status
1907 $this->app->argv[3] = 5;
1908 $result = api_statuses_repeat('json');
1909 self::assertStatus($result['status']);
1913 * Test the api_statuses_destroy() function.
1916 * @expectedException Friendica\Network\HTTPException\BadRequestException
1918 public function testApiStatusesDestroy()
1920 api_statuses_destroy('json');
1924 * Test the api_statuses_destroy() function without an authenticated user.
1927 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1929 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1931 $_SESSION['authenticated'] = false;
1932 api_statuses_destroy('json');
1936 * Test the api_statuses_destroy() function with an ID.
1940 public function testApiStatusesDestroyWithId()
1942 $this->app->argv[3] = 1;
1943 $result = api_statuses_destroy('json');
1944 self::assertStatus($result['status']);
1948 * Test the api_statuses_mentions() function.
1952 public function testApiStatusesMentions()
1954 $this->app->user = ['nickname' => $this->selfUser['nick']];
1955 $_REQUEST['max_id'] = 10;
1956 $result = api_statuses_mentions('json');
1957 self::assertEmpty($result['status']);
1958 // We should test with mentions in the database.
1962 * Test the api_statuses_mentions() function with a negative page parameter.
1966 public function testApiStatusesMentionsWithNegativePage()
1968 $_REQUEST['page'] = -2;
1969 $result = api_statuses_mentions('json');
1970 self::assertEmpty($result['status']);
1974 * Test the api_statuses_mentions() function with an unallowed user.
1977 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1979 public function testApiStatusesMentionsWithUnallowedUser()
1981 $_SESSION['allow_api'] = false;
1982 $_GET['screen_name'] = $this->selfUser['nick'];
1983 api_statuses_mentions('json');
1987 * Test the api_statuses_mentions() function with an RSS result.
1991 public function testApiStatusesMentionsWithRss()
1993 $result = api_statuses_mentions('rss');
1994 self::assertXml($result, 'statuses');
1998 * Test the api_statuses_user_timeline() function.
2002 public function testApiStatusesUserTimeline()
2004 $_REQUEST['max_id'] = 10;
2005 $_REQUEST['exclude_replies'] = true;
2006 $_REQUEST['conversation_id'] = 1;
2007 $result = api_statuses_user_timeline('json');
2008 self::assertNotEmpty($result['status']);
2009 foreach ($result['status'] as $status) {
2010 self::assertStatus($status);
2015 * Test the api_statuses_user_timeline() function with a negative page parameter.
2019 public function testApiStatusesUserTimelineWithNegativePage()
2021 $_REQUEST['page'] = -2;
2022 $result = api_statuses_user_timeline('json');
2023 self::assertNotEmpty($result['status']);
2024 foreach ($result['status'] as $status) {
2025 self::assertStatus($status);
2030 * Test the api_statuses_user_timeline() function with an RSS result.
2034 public function testApiStatusesUserTimelineWithRss()
2036 $result = api_statuses_user_timeline('rss');
2037 self::assertXml($result, 'statuses');
2041 * Test the api_statuses_user_timeline() function with an unallowed user.
2044 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2046 public function testApiStatusesUserTimelineWithUnallowedUser()
2048 $_SESSION['allow_api'] = false;
2049 $_GET['screen_name'] = $this->selfUser['nick'];
2050 api_statuses_user_timeline('json');
2054 * Test the api_favorites_create_destroy() function.
2057 * @expectedException Friendica\Network\HTTPException\BadRequestException
2059 public function testApiFavoritesCreateDestroy()
2061 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2062 $this->app->argc = count($this->app->argv);
2063 api_favorites_create_destroy('json');
2067 * Test the api_favorites_create_destroy() function with an invalid ID.
2070 * @expectedException Friendica\Network\HTTPException\BadRequestException
2072 public function testApiFavoritesCreateDestroyWithInvalidId()
2074 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2075 $this->app->argc = count($this->app->argv);
2076 api_favorites_create_destroy('json');
2080 * Test the api_favorites_create_destroy() function with an invalid action.
2083 * @expectedException Friendica\Network\HTTPException\BadRequestException
2085 public function testApiFavoritesCreateDestroyWithInvalidAction()
2087 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2088 $this->app->argc = count($this->app->argv);
2089 $_REQUEST['id'] = 1;
2090 api_favorites_create_destroy('json');
2094 * Test the api_favorites_create_destroy() function with the create action.
2098 public function testApiFavoritesCreateDestroyWithCreateAction()
2100 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2101 $this->app->argc = count($this->app->argv);
2102 $_REQUEST['id'] = 3;
2103 $result = api_favorites_create_destroy('json');
2104 self::assertStatus($result['status']);
2108 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2112 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2114 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2115 $this->app->argc = count($this->app->argv);
2116 $_REQUEST['id'] = 3;
2117 $result = api_favorites_create_destroy('rss');
2118 self::assertXml($result, 'status');
2122 * Test the api_favorites_create_destroy() function with the destroy action.
2126 public function testApiFavoritesCreateDestroyWithDestroyAction()
2128 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2129 $this->app->argc = count($this->app->argv);
2130 $_REQUEST['id'] = 3;
2131 $result = api_favorites_create_destroy('json');
2132 self::assertStatus($result['status']);
2136 * Test the api_favorites_create_destroy() function without an authenticated user.
2139 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2141 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2143 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2144 $this->app->argc = count($this->app->argv);
2145 $_SESSION['authenticated'] = false;
2146 api_favorites_create_destroy('json');
2150 * Test the api_favorites() function.
2154 public function testApiFavorites()
2156 $_REQUEST['page'] = -1;
2157 $_REQUEST['max_id'] = 10;
2158 $result = api_favorites('json');
2159 foreach ($result['status'] as $status) {
2160 self::assertStatus($status);
2165 * Test the api_favorites() function with an RSS result.
2169 public function testApiFavoritesWithRss()
2171 $result = api_favorites('rss');
2172 self::assertXml($result, 'statuses');
2176 * Test the api_favorites() function with an unallowed user.
2179 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2181 public function testApiFavoritesWithUnallowedUser()
2183 $_SESSION['allow_api'] = false;
2184 $_GET['screen_name'] = $this->selfUser['nick'];
2185 api_favorites('json');
2189 * Test the api_format_messages() function.
2193 public function testApiFormatMessages()
2195 $result = api_format_messages(
2196 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2197 ['id' => 2, 'screen_name' => 'recipient_name'],
2198 ['id' => 3, 'screen_name' => 'sender_name']
2200 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2201 self::assertEquals(1, $result['id']);
2202 self::assertEquals(2, $result['recipient_id']);
2203 self::assertEquals(3, $result['sender_id']);
2204 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2205 self::assertEquals('sender_name', $result['sender_screen_name']);
2209 * Test the api_format_messages() function with HTML.
2213 public function testApiFormatMessagesWithHtmlText()
2215 $_GET['getText'] = 'html';
2216 $result = api_format_messages(
2217 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2218 ['id' => 2, 'screen_name' => 'recipient_name'],
2219 ['id' => 3, 'screen_name' => 'sender_name']
2221 self::assertEquals('item_title', $result['title']);
2222 self::assertEquals('<strong>item_body</strong>', $result['text']);
2226 * Test the api_format_messages() function with plain text.
2230 public function testApiFormatMessagesWithPlainText()
2232 $_GET['getText'] = 'plain';
2233 $result = api_format_messages(
2234 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2235 ['id' => 2, 'screen_name' => 'recipient_name'],
2236 ['id' => 3, 'screen_name' => 'sender_name']
2238 self::assertEquals('item_title', $result['title']);
2239 self::assertEquals('item_body', $result['text']);
2243 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2247 public function testApiFormatMessagesWithoutUserObjects()
2249 $_GET['getUserObjects'] = 'false';
2250 $result = api_format_messages(
2251 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2252 ['id' => 2, 'screen_name' => 'recipient_name'],
2253 ['id' => 3, 'screen_name' => 'sender_name']
2255 self::assertTrue(!isset($result['sender']));
2256 self::assertTrue(!isset($result['recipient']));
2260 * Test the api_convert_item() function.
2264 public function testApiConvertItem()
2266 $result = api_convert_item(
2268 'network' => 'feed',
2269 'title' => 'item_title',
2270 // We need a long string to test that it is correctly cut
2271 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2272 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2273 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2274 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2275 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2276 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2277 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2278 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2279 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2280 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2281 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2282 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2283 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2284 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2285 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2286 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2287 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2288 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2289 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2290 'repellat officia illum quos impedit quam iste esse unde qui ' .
2291 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2292 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2293 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2294 'plink' => 'item_plink'
2297 self::assertStringStartsWith('item_title', $result['text']);
2298 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2302 * Test the api_convert_item() function with an empty item body.
2306 public function testApiConvertItemWithoutBody()
2308 $result = api_convert_item(
2310 'network' => 'feed',
2311 'title' => 'item_title',
2313 'plink' => 'item_plink'
2316 self::assertEquals('item_title', $result['text']);
2317 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2321 * Test the api_convert_item() function with the title in the body.
2325 public function testApiConvertItemWithTitleInBody()
2327 $result = api_convert_item(
2329 'title' => 'item_title',
2330 'body' => 'item_title item_body'
2333 self::assertEquals('item_title item_body', $result['text']);
2334 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2338 * Test the api_get_attachments() function.
2342 public function testApiGetAttachments()
2345 self::assertEmpty(api_get_attachments($body));
2349 * Test the api_get_attachments() function with an img tag.
2353 public function testApiGetAttachmentsWithImage()
2355 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2356 self::assertInternalType('array', api_get_attachments($body));
2360 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2364 public function testApiGetAttachmentsWithImageAndAndStatus()
2366 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2367 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2368 self::assertInternalType('array', api_get_attachments($body));
2372 * Test the api_get_entitities() function.
2376 public function testApiGetEntitities()
2379 self::assertInternalType('array', api_get_entitities($text, 'bbcode'));
2383 * Test the api_get_entitities() function with the include_entities parameter.
2387 public function testApiGetEntititiesWithIncludeEntities()
2389 $_REQUEST['include_entities'] = 'true';
2391 $result = api_get_entitities($text, 'bbcode');
2392 self::assertInternalType('array', $result['hashtags']);
2393 self::assertInternalType('array', $result['symbols']);
2394 self::assertInternalType('array', $result['urls']);
2395 self::assertInternalType('array', $result['user_mentions']);
2399 * Test the api_format_items_embeded_images() function.
2403 public function testApiFormatItemsEmbededImages()
2406 'text ' . DI::baseUrl() . '/display/item_guid',
2407 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2412 * Test the api_contactlink_to_array() function.
2416 public function testApiContactlinkToArray()
2423 api_contactlink_to_array('text')
2428 * Test the api_contactlink_to_array() function with an URL.
2432 public function testApiContactlinkToArrayWithUrl()
2436 'name' => ['link_text'],
2439 api_contactlink_to_array('text <a href="url">link_text</a>')
2444 * Test the api_format_items_activities() function.
2448 public function testApiFormatItemsActivities()
2450 $item = ['uid' => 0, 'uri' => ''];
2451 $result = api_format_items_activities($item);
2452 self::assertArrayHasKey('like', $result);
2453 self::assertArrayHasKey('dislike', $result);
2454 self::assertArrayHasKey('attendyes', $result);
2455 self::assertArrayHasKey('attendno', $result);
2456 self::assertArrayHasKey('attendmaybe', $result);
2460 * Test the api_format_items_activities() function with an XML result.
2464 public function testApiFormatItemsActivitiesWithXml()
2466 $item = ['uid' => 0, 'uri' => ''];
2467 $result = api_format_items_activities($item, 'xml');
2468 self::assertArrayHasKey('friendica:like', $result);
2469 self::assertArrayHasKey('friendica:dislike', $result);
2470 self::assertArrayHasKey('friendica:attendyes', $result);
2471 self::assertArrayHasKey('friendica:attendno', $result);
2472 self::assertArrayHasKey('friendica:attendmaybe', $result);
2476 * Test the api_format_items() function.
2480 public function testApiFormatItems()
2484 'item_network' => 'item_network',
2490 'author-network' => Protocol::DFRN,
2491 'author-link' => 'http://localhost/profile/othercontact',
2495 $result = api_format_items($items, ['id' => 0], true);
2496 foreach ($result as $status) {
2497 self::assertStatus($status);
2502 * Test the api_format_items() function with an XML result.
2506 public function testApiFormatItemsWithXml()
2514 'author-network' => Protocol::DFRN,
2515 'author-link' => 'http://localhost/profile/othercontact',
2519 $result = api_format_items($items, ['id' => 0], true, 'xml');
2520 foreach ($result as $status) {
2521 self::assertStatus($status);
2526 * Test the api_format_items() function.
2530 public function testApiAccountRateLimitStatus()
2532 $result = api_account_rate_limit_status('json');
2533 self::assertEquals(150, $result['hash']['remaining_hits']);
2534 self::assertEquals(150, $result['hash']['hourly_limit']);
2535 self::assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2539 * Test the api_format_items() function with an XML result.
2543 public function testApiAccountRateLimitStatusWithXml()
2545 $result = api_account_rate_limit_status('xml');
2546 self::assertXml($result, 'hash');
2550 * Test the api_help_test() function.
2554 public function testApiHelpTest()
2556 $result = api_help_test('json');
2557 self::assertEquals(['ok' => 'ok'], $result);
2561 * Test the api_help_test() function with an XML result.
2565 public function testApiHelpTestWithXml()
2567 $result = api_help_test('xml');
2568 self::assertXml($result, 'ok');
2572 * Test the api_lists_list() function.
2576 public function testApiListsList()
2578 $result = api_lists_list('json');
2579 self::assertEquals(['lists_list' => []], $result);
2583 * Test the api_lists_ownerships() function.
2587 public function testApiListsOwnerships()
2589 $result = api_lists_ownerships('json');
2590 foreach ($result['lists']['lists'] as $list) {
2591 self::assertList($list);
2596 * Test the api_lists_ownerships() function without an authenticated user.
2599 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2601 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2603 $_SESSION['authenticated'] = false;
2604 api_lists_ownerships('json');
2608 * Test the api_lists_statuses() function.
2610 * @expectedException Friendica\Network\HTTPException\BadRequestException
2613 public function testApiListsStatuses()
2615 api_lists_statuses('json');
2619 * Test the api_lists_statuses() function with a list ID.
2623 public function testApiListsStatusesWithListId()
2625 $_REQUEST['list_id'] = 1;
2626 $_REQUEST['page'] = -1;
2627 $_REQUEST['max_id'] = 10;
2628 $result = api_lists_statuses('json');
2629 foreach ($result['status'] as $status) {
2630 self::assertStatus($status);
2635 * Test the api_lists_statuses() function with a list ID and a RSS result.
2639 public function testApiListsStatusesWithListIdAndRss()
2641 $_REQUEST['list_id'] = 1;
2642 $result = api_lists_statuses('rss');
2643 self::assertXml($result, 'statuses');
2647 * Test the api_lists_statuses() function with an unallowed user.
2650 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2652 public function testApiListsStatusesWithUnallowedUser()
2654 $_SESSION['allow_api'] = false;
2655 $_GET['screen_name'] = $this->selfUser['nick'];
2656 api_lists_statuses('json');
2660 * Test the api_statuses_f() function.
2664 public function testApiStatusesFWithFriends()
2667 $result = api_statuses_f('friends');
2668 self::assertArrayHasKey('user', $result);
2672 * Test the api_statuses_f() function.
2676 public function testApiStatusesFWithFollowers()
2678 $result = api_statuses_f('followers');
2679 self::assertArrayHasKey('user', $result);
2683 * Test the api_statuses_f() function.
2687 public function testApiStatusesFWithBlocks()
2689 $result = api_statuses_f('blocks');
2690 self::assertArrayHasKey('user', $result);
2694 * Test the api_statuses_f() function.
2698 public function testApiStatusesFWithIncoming()
2700 $result = api_statuses_f('incoming');
2701 self::assertArrayHasKey('user', $result);
2705 * Test the api_statuses_f() function an undefined cursor GET variable.
2709 public function testApiStatusesFWithUndefinedCursor()
2711 $_GET['cursor'] = 'undefined';
2712 self::assertFalse(api_statuses_f('friends'));
2716 * Test the api_statuses_friends() function.
2720 public function testApiStatusesFriends()
2722 $result = api_statuses_friends('json');
2723 self::assertArrayHasKey('user', $result);
2727 * Test the api_statuses_friends() function an undefined cursor GET variable.
2731 public function testApiStatusesFriendsWithUndefinedCursor()
2733 $_GET['cursor'] = 'undefined';
2734 self::assertFalse(api_statuses_friends('json'));
2738 * Test the api_statuses_followers() function.
2742 public function testApiStatusesFollowers()
2744 $result = api_statuses_followers('json');
2745 self::assertArrayHasKey('user', $result);
2749 * Test the api_statuses_followers() function an undefined cursor GET variable.
2753 public function testApiStatusesFollowersWithUndefinedCursor()
2755 $_GET['cursor'] = 'undefined';
2756 self::assertFalse(api_statuses_followers('json'));
2760 * Test the api_blocks_list() function.
2764 public function testApiBlocksList()
2766 $result = api_blocks_list('json');
2767 self::assertArrayHasKey('user', $result);
2771 * Test the api_blocks_list() function an undefined cursor GET variable.
2775 public function testApiBlocksListWithUndefinedCursor()
2777 $_GET['cursor'] = 'undefined';
2778 self::assertFalse(api_blocks_list('json'));
2782 * Test the api_friendships_incoming() function.
2786 public function testApiFriendshipsIncoming()
2788 $result = api_friendships_incoming('json');
2789 self::assertArrayHasKey('id', $result);
2793 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2797 public function testApiFriendshipsIncomingWithUndefinedCursor()
2799 $_GET['cursor'] = 'undefined';
2800 self::assertFalse(api_friendships_incoming('json'));
2804 * Test the api_statusnet_config() function.
2808 public function testApiStatusnetConfig()
2810 $result = api_statusnet_config('json');
2811 self::assertEquals('localhost', $result['config']['site']['server']);
2812 self::assertEquals('default', $result['config']['site']['theme']);
2813 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2814 self::assertTrue($result['config']['site']['fancy']);
2815 self::assertEquals('en', $result['config']['site']['language']);
2816 self::assertEquals('UTC', $result['config']['site']['timezone']);
2817 self::assertEquals(200000, $result['config']['site']['textlimit']);
2818 self::assertEquals('false', $result['config']['site']['private']);
2819 self::assertEquals('false', $result['config']['site']['ssl']);
2820 self::assertEquals(30, $result['config']['site']['shorturllength']);
2824 * Test the api_statusnet_version() function.
2828 public function testApiStatusnetVersion()
2830 $result = api_statusnet_version('json');
2831 self::assertEquals('0.9.7', $result['version']);
2835 * Test the api_direct_messages_new() function.
2839 public function testApiDirectMessagesNew()
2841 $result = api_direct_messages_new('json');
2842 self::assertNull($result);
2846 * Test the api_direct_messages_new() function without an authenticated user.
2849 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2851 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2853 $_SESSION['authenticated'] = false;
2854 api_direct_messages_new('json');
2858 * Test the api_direct_messages_new() function with an user ID.
2862 public function testApiDirectMessagesNewWithUserId()
2864 $_POST['text'] = 'message_text';
2865 $_POST['user_id'] = $this->otherUser['id'];
2866 $result = api_direct_messages_new('json');
2867 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2871 * Test the api_direct_messages_new() function with a screen name.
2875 public function testApiDirectMessagesNewWithScreenName()
2877 $this->app->user = ['nickname' => $this->selfUser['nick']];
2878 $_POST['text'] = 'message_text';
2879 $_POST['screen_name'] = $this->friendUser['nick'];
2880 $result = api_direct_messages_new('json');
2881 self::assertContains('message_text', $result['direct_message']['text']);
2882 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2883 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2887 * Test the api_direct_messages_new() function with a title.
2891 public function testApiDirectMessagesNewWithTitle()
2893 $this->app->user = ['nickname' => $this->selfUser['nick']];
2894 $_POST['text'] = 'message_text';
2895 $_POST['screen_name'] = $this->friendUser['nick'];
2896 $_REQUEST['title'] = 'message_title';
2897 $result = api_direct_messages_new('json');
2898 self::assertContains('message_text', $result['direct_message']['text']);
2899 self::assertContains('message_title', $result['direct_message']['text']);
2900 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2901 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2905 * Test the api_direct_messages_new() function with an RSS result.
2909 public function testApiDirectMessagesNewWithRss()
2911 $this->app->user = ['nickname' => $this->selfUser['nick']];
2912 $_POST['text'] = 'message_text';
2913 $_POST['screen_name'] = $this->friendUser['nick'];
2914 $result = api_direct_messages_new('rss');
2915 self::assertXml($result, 'direct-messages');
2919 * Test the api_direct_messages_destroy() function.
2922 * @expectedException Friendica\Network\HTTPException\BadRequestException
2924 public function testApiDirectMessagesDestroy()
2926 api_direct_messages_destroy('json');
2930 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2934 public function testApiDirectMessagesDestroyWithVerbose()
2936 $_GET['friendica_verbose'] = 'true';
2937 $result = api_direct_messages_destroy('json');
2941 'result' => 'error',
2942 'message' => 'message id or parenturi not specified'
2950 * Test the api_direct_messages_destroy() function without an authenticated user.
2953 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2955 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2957 $_SESSION['authenticated'] = false;
2958 api_direct_messages_destroy('json');
2962 * Test the api_direct_messages_destroy() function with a non-zero ID.
2965 * @expectedException Friendica\Network\HTTPException\BadRequestException
2967 public function testApiDirectMessagesDestroyWithId()
2969 $_REQUEST['id'] = 1;
2970 api_direct_messages_destroy('json');
2974 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2978 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2980 $_REQUEST['id'] = 1;
2981 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2982 $_GET['friendica_verbose'] = 'true';
2983 $result = api_direct_messages_destroy('json');
2987 'result' => 'error',
2988 'message' => 'message id not in database'
2996 * Test the api_direct_messages_destroy() function with a non-zero ID.
3000 public function testApiDirectMessagesDestroyWithCorrectId()
3002 $this->markTestIncomplete('We need to add a dataset for this.');
3006 * Test the api_direct_messages_box() function.
3010 public function testApiDirectMessagesBoxWithSentbox()
3012 $_REQUEST['page'] = -1;
3013 $_REQUEST['max_id'] = 10;
3014 $result = api_direct_messages_box('json', 'sentbox', 'false');
3015 self::assertArrayHasKey('direct_message', $result);
3019 * Test the api_direct_messages_box() function.
3023 public function testApiDirectMessagesBoxWithConversation()
3025 $result = api_direct_messages_box('json', 'conversation', 'false');
3026 self::assertArrayHasKey('direct_message', $result);
3030 * Test the api_direct_messages_box() function.
3034 public function testApiDirectMessagesBoxWithAll()
3036 $result = api_direct_messages_box('json', 'all', 'false');
3037 self::assertArrayHasKey('direct_message', $result);
3041 * Test the api_direct_messages_box() function.
3045 public function testApiDirectMessagesBoxWithInbox()
3047 $result = api_direct_messages_box('json', 'inbox', 'false');
3048 self::assertArrayHasKey('direct_message', $result);
3052 * Test the api_direct_messages_box() function.
3056 public function testApiDirectMessagesBoxWithVerbose()
3058 $result = api_direct_messages_box('json', 'sentbox', 'true');
3062 'result' => 'error',
3063 'message' => 'no mails available'
3071 * Test the api_direct_messages_box() function with a RSS result.
3075 public function testApiDirectMessagesBoxWithRss()
3077 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3078 self::assertXml($result, 'direct-messages');
3082 * Test the api_direct_messages_box() function without an authenticated user.
3085 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3087 public function testApiDirectMessagesBoxWithUnallowedUser()
3089 $_SESSION['allow_api'] = false;
3090 $_GET['screen_name'] = $this->selfUser['nick'];
3091 api_direct_messages_box('json', 'sentbox', 'false');
3095 * Test the api_direct_messages_sentbox() function.
3099 public function testApiDirectMessagesSentbox()
3101 $result = api_direct_messages_sentbox('json');
3102 self::assertArrayHasKey('direct_message', $result);
3106 * Test the api_direct_messages_inbox() function.
3110 public function testApiDirectMessagesInbox()
3112 $result = api_direct_messages_inbox('json');
3113 self::assertArrayHasKey('direct_message', $result);
3117 * Test the api_direct_messages_all() function.
3121 public function testApiDirectMessagesAll()
3123 $result = api_direct_messages_all('json');
3124 self::assertArrayHasKey('direct_message', $result);
3128 * Test the api_direct_messages_conversation() function.
3132 public function testApiDirectMessagesConversation()
3134 $result = api_direct_messages_conversation('json');
3135 self::assertArrayHasKey('direct_message', $result);
3139 * Test the api_oauth_request_token() function.
3143 public function testApiOauthRequestToken()
3145 $this->markTestIncomplete('exit() kills phpunit as well');
3149 * Test the api_oauth_access_token() function.
3153 public function testApiOauthAccessToken()
3155 $this->markTestIncomplete('exit() kills phpunit as well');
3159 * Test the api_fr_photoalbum_delete() function.
3162 * @expectedException Friendica\Network\HTTPException\BadRequestException
3164 public function testApiFrPhotoalbumDelete()
3166 api_fr_photoalbum_delete('json');
3170 * Test the api_fr_photoalbum_delete() function with an album name.
3173 * @expectedException Friendica\Network\HTTPException\BadRequestException
3175 public function testApiFrPhotoalbumDeleteWithAlbum()
3177 $_REQUEST['album'] = 'album_name';
3178 api_fr_photoalbum_delete('json');
3182 * Test the api_fr_photoalbum_delete() function with an album name.
3186 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3188 $this->markTestIncomplete('We need to add a dataset for this.');
3192 * Test the api_fr_photoalbum_delete() function.
3195 * @expectedException Friendica\Network\HTTPException\BadRequestException
3197 public function testApiFrPhotoalbumUpdate()
3199 api_fr_photoalbum_update('json');
3203 * Test the api_fr_photoalbum_delete() function with an album name.
3206 * @expectedException Friendica\Network\HTTPException\BadRequestException
3208 public function testApiFrPhotoalbumUpdateWithAlbum()
3210 $_REQUEST['album'] = 'album_name';
3211 api_fr_photoalbum_update('json');
3215 * Test the api_fr_photoalbum_delete() function with an album name.
3218 * @expectedException Friendica\Network\HTTPException\BadRequestException
3220 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3222 $_REQUEST['album'] = 'album_name';
3223 $_REQUEST['album_new'] = 'album_name';
3224 api_fr_photoalbum_update('json');
3228 * Test the api_fr_photoalbum_update() function without an authenticated user.
3231 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3233 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3235 $_SESSION['authenticated'] = false;
3236 api_fr_photoalbum_update('json');
3240 * Test the api_fr_photoalbum_delete() function with an album name.
3244 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3246 $this->markTestIncomplete('We need to add a dataset for this.');
3250 * Test the api_fr_photos_list() function.
3254 public function testApiFrPhotosList()
3256 $result = api_fr_photos_list('json');
3257 self::assertArrayHasKey('photo', $result);
3261 * Test the api_fr_photos_list() function without an authenticated user.
3264 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3266 public function testApiFrPhotosListWithoutAuthenticatedUser()
3268 $_SESSION['authenticated'] = false;
3269 api_fr_photos_list('json');
3273 * Test the api_fr_photo_create_update() function.
3276 * @expectedException Friendica\Network\HTTPException\BadRequestException
3278 public function testApiFrPhotoCreateUpdate()
3280 api_fr_photo_create_update('json');
3284 * Test the api_fr_photo_create_update() function without an authenticated user.
3287 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3289 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3291 $_SESSION['authenticated'] = false;
3292 api_fr_photo_create_update('json');
3296 * Test the api_fr_photo_create_update() function with an album name.
3299 * @expectedException Friendica\Network\HTTPException\BadRequestException
3301 public function testApiFrPhotoCreateUpdateWithAlbum()
3303 $_REQUEST['album'] = 'album_name';
3304 api_fr_photo_create_update('json');
3308 * Test the api_fr_photo_create_update() function with the update mode.
3312 public function testApiFrPhotoCreateUpdateWithUpdate()
3314 $this->markTestIncomplete('We need to create a dataset for this');
3318 * Test the api_fr_photo_create_update() function with an uploaded file.
3322 public function testApiFrPhotoCreateUpdateWithFile()
3324 $this->markTestIncomplete();
3328 * Test the api_fr_photo_delete() function.
3331 * @expectedException Friendica\Network\HTTPException\BadRequestException
3333 public function testApiFrPhotoDelete()
3335 api_fr_photo_delete('json');
3339 * Test the api_fr_photo_delete() function without an authenticated user.
3342 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3344 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3346 $_SESSION['authenticated'] = false;
3347 api_fr_photo_delete('json');
3351 * Test the api_fr_photo_delete() function with a photo ID.
3354 * @expectedException Friendica\Network\HTTPException\BadRequestException
3356 public function testApiFrPhotoDeleteWithPhotoId()
3358 $_REQUEST['photo_id'] = 1;
3359 api_fr_photo_delete('json');
3363 * Test the api_fr_photo_delete() function with a correct photo ID.
3367 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3369 $this->markTestIncomplete('We need to create a dataset for this.');
3373 * Test the api_fr_photo_detail() function.
3376 * @expectedException Friendica\Network\HTTPException\BadRequestException
3378 public function testApiFrPhotoDetail()
3380 api_fr_photo_detail('json');
3384 * Test the api_fr_photo_detail() function without an authenticated user.
3387 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3389 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3391 $_SESSION['authenticated'] = false;
3392 api_fr_photo_detail('json');
3396 * Test the api_fr_photo_detail() function with a photo ID.
3399 * @expectedException Friendica\Network\HTTPException\NotFoundException
3401 public function testApiFrPhotoDetailWithPhotoId()
3403 $_REQUEST['photo_id'] = 1;
3404 api_fr_photo_detail('json');
3408 * Test the api_fr_photo_detail() function with a correct photo ID.
3412 public function testApiFrPhotoDetailCorrectPhotoId()
3414 $this->markTestIncomplete('We need to create a dataset for this.');
3418 * Test the api_account_update_profile_image() function.
3421 * @expectedException Friendica\Network\HTTPException\BadRequestException
3423 public function testApiAccountUpdateProfileImage()
3425 api_account_update_profile_image('json');
3429 * Test the api_account_update_profile_image() function without an authenticated user.
3432 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3434 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3436 $_SESSION['authenticated'] = false;
3437 api_account_update_profile_image('json');
3441 * Test the api_account_update_profile_image() function with an uploaded file.
3444 * @expectedException Friendica\Network\HTTPException\BadRequestException
3446 public function testApiAccountUpdateProfileImageWithUpload()
3448 $this->markTestIncomplete();
3453 * Test the api_account_update_profile() function.
3457 public function testApiAccountUpdateProfile()
3459 $_POST['name'] = 'new_name';
3460 $_POST['description'] = 'new_description';
3461 $result = api_account_update_profile('json');
3462 // We can't use assertSelfUser() here because the user object is missing some properties.
3463 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3464 self::assertEquals('DFRN', $result['user']['location']);
3465 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3466 self::assertEquals('dfrn', $result['user']['network']);
3467 self::assertEquals('new_name', $result['user']['name']);
3468 self::assertEquals('new_description', $result['user']['description']);
3472 * Test the check_acl_input() function.
3476 public function testCheckAclInput()
3478 $result = check_acl_input('<aclstring>');
3479 // Where does this result come from?
3480 self::assertEquals(1, $result);
3484 * Test the check_acl_input() function with an empty ACL string.
3488 public function testCheckAclInputWithEmptyAclString()
3490 $result = check_acl_input(' ');
3491 self::assertFalse($result);
3495 * Test the save_media_to_database() function.
3499 public function testSaveMediaToDatabase()
3501 $this->markTestIncomplete();
3505 * Test the post_photo_item() function.
3509 public function testPostPhotoItem()
3511 $this->markTestIncomplete();
3515 * Test the prepare_photo_data() function.
3519 public function testPreparePhotoData()
3521 $this->markTestIncomplete();
3525 * Test the api_friendica_remoteauth() function.
3528 * @expectedException Friendica\Network\HTTPException\BadRequestException
3530 public function testApiFriendicaRemoteauth()
3532 api_friendica_remoteauth();
3536 * Test the api_friendica_remoteauth() function with an URL.
3539 * @expectedException Friendica\Network\HTTPException\BadRequestException
3541 public function testApiFriendicaRemoteauthWithUrl()
3543 $_GET['url'] = 'url';
3544 $_GET['c_url'] = 'url';
3545 api_friendica_remoteauth();
3549 * Test the api_friendica_remoteauth() function with a correct URL.
3553 public function testApiFriendicaRemoteauthWithCorrectUrl()
3555 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3556 $_GET['url'] = 'url';
3557 $_GET['c_url'] = $this->selfUser['nurl'];
3558 api_friendica_remoteauth();
3562 * Test the api_share_as_retweet() function.
3566 public function testApiShareAsRetweet()
3568 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3569 $result = api_share_as_retweet($item);
3570 self::assertFalse($result);
3574 * Test the api_share_as_retweet() function with a valid item.
3578 public function testApiShareAsRetweetWithValidItem()
3580 $this->markTestIncomplete();
3584 * Test the api_in_reply_to() function.
3588 public function testApiInReplyTo()
3590 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3591 self::assertArrayHasKey('status_id', $result);
3592 self::assertArrayHasKey('user_id', $result);
3593 self::assertArrayHasKey('status_id_str', $result);
3594 self::assertArrayHasKey('user_id_str', $result);
3595 self::assertArrayHasKey('screen_name', $result);
3599 * Test the api_in_reply_to() function with a valid item.
3603 public function testApiInReplyToWithValidItem()
3605 $this->markTestIncomplete();
3609 * Test the api_clean_plain_items() function.
3613 public function testApiCleanPlainItems()
3615 $_REQUEST['include_entities'] = 'true';
3616 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3617 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3621 * Test the api_best_nickname() function.
3625 public function testApiBestNickname()
3628 $result = api_best_nickname($contacts);
3629 self::assertNull($result);
3633 * Test the api_best_nickname() function with contacts.
3637 public function testApiBestNicknameWithContacts()
3639 $this->markTestIncomplete();
3643 * Test the api_friendica_group_show() function.
3647 public function testApiFriendicaGroupShow()
3649 $this->markTestIncomplete();
3653 * Test the api_friendica_group_delete() function.
3657 public function testApiFriendicaGroupDelete()
3659 $this->markTestIncomplete();
3663 * Test the api_lists_destroy() function.
3667 public function testApiListsDestroy()
3669 $this->markTestIncomplete();
3673 * Test the group_create() function.
3677 public function testGroupCreate()
3679 $this->markTestIncomplete();
3683 * Test the api_friendica_group_create() function.
3687 public function testApiFriendicaGroupCreate()
3689 $this->markTestIncomplete();
3693 * Test the api_lists_create() function.
3697 public function testApiListsCreate()
3699 $this->markTestIncomplete();
3703 * Test the api_friendica_group_update() function.
3707 public function testApiFriendicaGroupUpdate()
3709 $this->markTestIncomplete();
3713 * Test the api_lists_update() function.
3717 public function testApiListsUpdate()
3719 $this->markTestIncomplete();
3723 * Test the api_friendica_activity() function.
3727 public function testApiFriendicaActivity()
3729 $this->markTestIncomplete();
3733 * Test the api_friendica_notification() function.
3736 * @expectedException Friendica\Network\HTTPException\BadRequestException
3738 public function testApiFriendicaNotification()
3740 api_friendica_notification('json');
3744 * Test the api_friendica_notification() function without an authenticated user.
3747 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3749 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3751 $_SESSION['authenticated'] = false;
3752 api_friendica_notification('json');
3756 * Test the api_friendica_notification() function with empty result
3760 public function testApiFriendicaNotificationWithEmptyResult()
3762 $this->app->argv = ['api', 'friendica', 'notification'];
3763 $this->app->argc = count($this->app->argv);
3764 $_SESSION['uid'] = 41;
3765 $result = api_friendica_notification('json');
3766 self::assertEquals(['note' => false], $result);
3770 * Test the api_friendica_notification() function with an XML result.
3774 public function testApiFriendicaNotificationWithXmlResult()
3776 $this->app->argv = ['api', 'friendica', 'notification'];
3777 $this->app->argc = count($this->app->argv);
3778 $result = api_friendica_notification('xml');
3779 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3781 <?xml version="1.0"?>
3783 <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" uri-id="" link="http://localhost/notification/1" iid="4" parent="" parent-uri-id="" seen="0" verb="" otype="item" name_cache="Reply to" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
3786 self::assertXmlStringEqualsXmlString($assertXml, $result);
3790 * Test the api_friendica_notification() function with an JSON result.
3794 public function testApiFriendicaNotificationWithJsonResult()
3796 $this->app->argv = ['api', 'friendica', 'notification'];
3797 $this->app->argc = count($this->app->argv);
3798 $result = json_encode(api_friendica_notification('json'));
3799 self::assertJson($result);
3803 * Test the api_friendica_notification_seen() function.
3807 public function testApiFriendicaNotificationSeen()
3809 $this->markTestIncomplete();
3813 * Test the api_friendica_direct_messages_setseen() function.
3817 public function testApiFriendicaDirectMessagesSetseen()
3819 $this->markTestIncomplete();
3823 * Test the api_friendica_direct_messages_search() function.
3827 public function testApiFriendicaDirectMessagesSearch()
3829 $this->markTestIncomplete();
3833 * Test the api_saved_searches_list() function.
3837 public function testApiSavedSearchesList()
3839 $result = api_saved_searches_list('json');
3840 self::assertEquals(1, $result['terms'][0]['id']);
3841 self::assertEquals(1, $result['terms'][0]['id_str']);
3842 self::assertEquals('Saved search', $result['terms'][0]['name']);
3843 self::assertEquals('Saved search', $result['terms'][0]['query']);