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 * @backupGlobals enabled
28 class ApiTest extends FixtureTest
31 * @var TestHandler Can handle log-outputs
38 protected $friendUser;
42 protected $wrongUserId;
51 * Create variables used by tests.
53 protected function setUp() : void
55 global $API, $called_api;
61 /** @var IConfig $config */
62 $this->config = $this->dice->create(IConfig::class);
64 $this->config->set('system', 'url', 'http://localhost');
65 $this->config->set('system', 'hostname', 'localhost');
66 $this->config->set('system', 'worker_dont_fork', true);
69 $this->config->set('config', 'hostname', 'localhost');
70 $this->config->set('system', 'throttle_limit_day', 100);
71 $this->config->set('system', 'throttle_limit_week', 100);
72 $this->config->set('system', 'throttle_limit_month', 100);
73 $this->config->set('system', 'theme', 'system_theme');
77 $this->app = DI::app();
80 $this->app->argv = [''];
82 // User data that the test database is populated with
85 'name' => 'Self contact',
86 'nick' => 'selfcontact',
87 'nurl' => 'http://localhost/profile/selfcontact'
91 'name' => 'Friend contact',
92 'nick' => 'friendcontact',
93 'nurl' => 'http://localhost/profile/friendcontact'
97 'name' => 'othercontact',
98 'nick' => 'othercontact',
99 'nurl' => 'http://localhost/profile/othercontact'
102 // User ID that we know is not in the database
103 $this->wrongUserId = 666;
105 DI::session()->start();
107 // Most API require login so we force the session
110 'authenticated' => true,
111 'uid' => $this->selfUser['id']
116 * Assert that an user array contains expected keys.
118 * @param array $user User array
122 private function assertSelfUser(array $user)
124 self::assertEquals($this->selfUser['id'], $user['uid']);
125 self::assertEquals($this->selfUser['id'], $user['cid']);
126 self::assertEquals(1, $user['self']);
127 self::assertEquals('DFRN', $user['location']);
128 self::assertEquals($this->selfUser['name'], $user['name']);
129 self::assertEquals($this->selfUser['nick'], $user['screen_name']);
130 self::assertEquals('dfrn', $user['network']);
131 self::assertTrue($user['verified']);
135 * Assert that an user array contains expected keys.
137 * @param array $user User array
141 private function assertOtherUser(array $user = [])
143 self::assertEquals($this->otherUser['id'], $user['id']);
144 self::assertEquals($this->otherUser['id'], $user['id_str']);
145 self::assertEquals(0, $user['self']);
146 self::assertEquals($this->otherUser['name'], $user['name']);
147 self::assertEquals($this->otherUser['nick'], $user['screen_name']);
148 self::assertFalse($user['verified']);
152 * Assert that a status array contains expected keys.
154 * @param array $status Status array
158 private function assertStatus(array $status = [])
160 self::assertInternalType('string', $status['text'] ?? '');
161 self::assertInternalType('int', $status['id'] ?? '');
162 // We could probably do more checks here.
166 * Assert that a list array contains expected keys.
168 * @param array $list List array
172 private function assertList(array $list = [])
174 self::assertInternalType('string', $list['name']);
175 self::assertInternalType('int', $list['id']);
176 self::assertInternalType('string', $list['id_str']);
177 self::assertContains($list['mode'], ['public', 'private']);
178 // We could probably do more checks here.
182 * Assert that the string is XML and contain the root element.
184 * @param string $result XML string
185 * @param string $root_element Root element name
189 private function assertXml($result = '', $root_element = '')
191 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
192 self::assertContains('<' . $root_element, $result);
193 // We could probably do more checks here.
197 * Get the path to a temporary empty PNG image.
199 * @return string Path
201 private function getTempImage()
203 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
207 // Empty 1x1 px PNG image
208 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
216 * Test the api_user() function.
220 public function testApiUser()
222 self::assertEquals($this->selfUser['id'], api_user());
226 * Test the api_user() function with an unallowed user.
230 public function testApiUserWithUnallowedUser()
232 $_SESSION = ['allow_api' => false];
233 self::assertEquals(false, api_user());
237 * Test the api_source() function.
241 public function testApiSource()
243 self::assertEquals('api', api_source());
247 * Test the api_source() function with a Twidere user agent.
251 public function testApiSourceWithTwidere()
253 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
254 self::assertEquals('Twidere', api_source());
258 * Test the api_source() function with a GET parameter.
262 public function testApiSourceWithGet()
264 $_GET['source'] = 'source_name';
265 self::assertEquals('source_name', api_source());
269 * Test the api_date() function.
273 public function testApiDate()
275 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
279 * Test the api_register_func() function.
283 public function testApiRegisterFunc()
295 self::assertTrue($API['api_path']['auth']);
296 self::assertEquals('method', $API['api_path']['method']);
297 self::assertTrue(is_callable($API['api_path']['func']));
301 * Test the api_login() function without any login.
303 * @runInSeparateProcess
304 * @preserveGlobalState disabled
305 * @preserveGlobalState disabled
306 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
308 public function testApiLoginWithoutLogin()
310 api_login($this->app);
314 * Test the api_login() function with a bad login.
316 * @runInSeparateProcess
317 * @preserveGlobalState disabled
318 * @preserveGlobalState disabled
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.
350 * @runInSeparateProcess
351 * @preserveGlobalState disabled
352 * @doesNotPerformAssertions
354 public function testApiLoginWithCorrectLogin()
356 $_SERVER['PHP_AUTH_USER'] = 'Test user';
357 $_SERVER['PHP_AUTH_PW'] = 'password';
358 api_login($this->app);
362 * Test the api_login() function with a remote user.
364 * @runInSeparateProcess
365 * @preserveGlobalState disabled
366 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
368 public function testApiLoginWithRemoteUser()
370 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
371 api_login($this->app);
375 * Test the api_check_method() function.
379 public function testApiCheckMethod()
381 self::assertFalse(api_check_method('method'));
385 * Test the api_check_method() function with a correct method.
389 public function testApiCheckMethodWithCorrectMethod()
391 $_SERVER['REQUEST_METHOD'] = 'method';
392 self::assertTrue(api_check_method('method'));
396 * Test the api_check_method() function with a wildcard.
400 public function testApiCheckMethodWithWildcard()
402 self::assertTrue(api_check_method('*'));
406 * Test the api_call() function.
408 * @runInSeparateProcess
409 * @preserveGlobalState disabled
411 public function testApiCall()
415 'method' => 'method',
416 'func' => function () {
417 return ['data' => ['some_data']];
420 $_SERVER['REQUEST_METHOD'] = 'method';
421 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
422 $_GET['callback'] = 'callback_name';
424 $args = DI::args()->determine($_SERVER, $_GET);
427 'callback_name(["some_data"])',
428 api_call($this->app, $args)
433 * Test the api_call() function with the profiled enabled.
435 * @runInSeparateProcess
436 * @preserveGlobalState disabled
438 public function testApiCallWithProfiler()
442 'method' => 'method',
443 'func' => function () {
444 return ['data' => ['some_data']];
448 $_SERVER['REQUEST_METHOD'] = 'method';
449 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
451 $args = DI::args()->determine($_SERVER, $_GET);
453 $this->config->set('system', 'profiler', true);
454 $this->config->set('rendertime', 'callstack', true);
455 $this->app->callstack = [
456 'database' => ['some_function' => 200],
457 'database_write' => ['some_function' => 200],
458 'cache' => ['some_function' => 200],
459 'cache_write' => ['some_function' => 200],
460 'network' => ['some_function' => 200]
465 api_call($this->app, $args)
470 * Test the api_call() function without any result.
472 * @runInSeparateProcess
473 * @preserveGlobalState disabled
475 public function testApiCallWithNoResult()
479 'method' => 'method',
480 'func' => function () {
484 $_SERVER['REQUEST_METHOD'] = 'method';
485 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
487 $args = DI::args()->determine($_SERVER, $_GET);
490 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
491 api_call($this->app, $args)
496 * Test the api_call() function with an unimplemented API.
498 * @runInSeparateProcess
499 * @preserveGlobalState disabled
501 public function testApiCallWithUninplementedApi()
504 '{"status":{"error":"Not Found","code":"404 Not Found","request":""}}',
510 * Test the api_call() function with a JSON result.
512 * @runInSeparateProcess
513 * @preserveGlobalState disabled
515 public function testApiCallWithJson()
519 'method' => 'method',
520 'func' => function () {
521 return ['data' => ['some_data']];
524 $_SERVER['REQUEST_METHOD'] = 'method';
525 $_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
527 $args = DI::args()->determine($_SERVER, $_GET);
531 api_call($this->app, $args)
536 * Test the api_call() function with an XML result.
538 * @runInSeparateProcess
539 * @preserveGlobalState disabled
541 public function testApiCallWithXml()
545 'method' => 'method',
546 'func' => function () {
550 $_SERVER['REQUEST_METHOD'] = 'method';
551 $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
553 $args = DI::args()->determine($_SERVER, $_GET);
557 api_call($this->app, $args)
562 * Test the api_call() function with an RSS result.
564 * @runInSeparateProcess
565 * @preserveGlobalState disabled
567 public function testApiCallWithRss()
571 'method' => 'method',
572 'func' => function () {
576 $_SERVER['REQUEST_METHOD'] = 'method';
577 $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
579 $args = DI::args()->determine($_SERVER, $_GET);
582 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
584 api_call($this->app, $args)
589 * Test the api_call() function with an Atom result.
591 * @runInSeparateProcess
592 * @preserveGlobalState disabled
594 public function testApiCallWithAtom()
598 'method' => 'method',
599 'func' => function () {
603 $_SERVER['REQUEST_METHOD'] = 'method';
604 $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
606 $args = DI::args()->determine($_SERVER, $_GET);
609 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
611 api_call($this->app, $args)
616 * Test the api_call() function with an unallowed method.
618 * @runInSeparateProcess
619 * @preserveGlobalState disabled
621 public function testApiCallWithWrongMethod()
624 $API['api_path'] = ['method' => 'method'];
626 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
628 $args = DI::args()->determine($_SERVER, $_GET);
631 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
632 api_call($this->app, $args)
637 * Test the api_call() function with an unauthorized user.
639 * @runInSeparateProcess
640 * @preserveGlobalState disabled
642 public function testApiCallWithWrongAuth()
646 'method' => 'method',
649 $_SESSION['authenticated'] = false;
650 $_SERVER['REQUEST_METHOD'] = 'method';
651 $_SERVER['QUERY_STRING'] = 'pagename=api_path';
653 $args = DI::args()->determine($_SERVER, $_GET);
656 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
657 api_call($this->app, $args)
662 * Test the api_error() function with a JSON result.
664 * @runInSeparateProcess
665 * @preserveGlobalState disabled
667 public function testApiErrorWithJson()
670 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
671 api_error('json', new HTTPException\OKException('error_message'), DI::args())
676 * Test the api_error() function with an XML result.
678 * @runInSeparateProcess
679 * @preserveGlobalState disabled
681 public function testApiErrorWithXml()
684 '<?xml version="1.0"?>' . "\n" .
685 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
686 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
687 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
688 ' <error>error_message</error>' . "\n" .
689 ' <code>200 OK</code>' . "\n" .
690 ' <request/>' . "\n" .
692 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
697 * Test the api_error() function with an RSS result.
699 * @runInSeparateProcess
700 * @preserveGlobalState disabled
702 public function testApiErrorWithRss()
705 '<?xml version="1.0"?>' . "\n" .
706 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
707 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
708 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
709 ' <error>error_message</error>' . "\n" .
710 ' <code>200 OK</code>' . "\n" .
711 ' <request/>' . "\n" .
713 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
718 * Test the api_error() function with an Atom result.
720 * @runInSeparateProcess
721 * @preserveGlobalState disabled
723 public function testApiErrorWithAtom()
726 '<?xml version="1.0"?>' . "\n" .
727 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
728 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
729 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
730 ' <error>error_message</error>' . "\n" .
731 ' <code>200 OK</code>' . "\n" .
732 ' <request/>' . "\n" .
734 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
739 * Test the api_rss_extra() function.
743 public function testApiRssExtra()
745 $user_info = ['url' => 'user_url', 'lang' => 'en'];
746 $result = api_rss_extra($this->app, [], $user_info);
747 self::assertEquals($user_info, $result['$user']);
748 self::assertEquals($user_info['url'], $result['$rss']['alternate']);
749 self::assertArrayHasKey('self', $result['$rss']);
750 self::assertArrayHasKey('base', $result['$rss']);
751 self::assertArrayHasKey('updated', $result['$rss']);
752 self::assertArrayHasKey('atom_updated', $result['$rss']);
753 self::assertArrayHasKey('language', $result['$rss']);
754 self::assertArrayHasKey('logo', $result['$rss']);
758 * Test the api_rss_extra() function without any user info.
762 public function testApiRssExtraWithoutUserInfo()
764 $result = api_rss_extra($this->app, [], null);
765 self::assertInternalType('array', $result['$user']);
766 self::assertArrayHasKey('alternate', $result['$rss']);
767 self::assertArrayHasKey('self', $result['$rss']);
768 self::assertArrayHasKey('base', $result['$rss']);
769 self::assertArrayHasKey('updated', $result['$rss']);
770 self::assertArrayHasKey('atom_updated', $result['$rss']);
771 self::assertArrayHasKey('language', $result['$rss']);
772 self::assertArrayHasKey('logo', $result['$rss']);
776 * Test the api_unique_id_to_nurl() function.
780 public function testApiUniqueIdToNurl()
782 self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
786 * Test the api_unique_id_to_nurl() function with a correct ID.
790 public function testApiUniqueIdToNurlWithCorrectId()
792 self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
796 * Test the api_get_user() function.
800 public function testApiGetUser()
802 $user = api_get_user($this->app);
803 self::assertSelfUser($user);
804 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
805 self::assertEquals('6fdbe8', $user['profile_link_color']);
806 self::assertEquals('ededed', $user['profile_background_color']);
810 * Test the api_get_user() function with a Frio schema.
814 public function testApiGetUserWithFrioSchema()
816 $pConfig = $this->dice->create(IPConfig::class);
817 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
818 $user = api_get_user($this->app);
819 self::assertSelfUser($user);
820 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
821 self::assertEquals('6fdbe8', $user['profile_link_color']);
822 self::assertEquals('ededed', $user['profile_background_color']);
826 * Test the api_get_user() function with an empty Frio schema.
830 public function testApiGetUserWithEmptyFrioSchema()
832 $pConfig = $this->dice->create(IPConfig::class);
833 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
834 $user = api_get_user($this->app);
835 self::assertSelfUser($user);
836 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
837 self::assertEquals('6fdbe8', $user['profile_link_color']);
838 self::assertEquals('ededed', $user['profile_background_color']);
842 * Test the api_get_user() function with a custom Frio schema.
846 public function testApiGetUserWithCustomFrioSchema()
848 $pConfig = $this->dice->create(IPConfig::class);
849 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
850 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
851 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
852 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
853 $user = api_get_user($this->app);
854 self::assertSelfUser($user);
855 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
856 self::assertEquals('123456', $user['profile_link_color']);
857 self::assertEquals('123456', $user['profile_background_color']);
861 * Test the api_get_user() function with an user that is not allowed to use the API.
863 * @runInSeparateProcess
864 * @preserveGlobalState disabled
866 public function testApiGetUserWithoutApiUser()
868 $_SERVER['PHP_AUTH_USER'] = 'Test user';
869 $_SERVER['PHP_AUTH_PW'] = 'password';
870 $_SESSION['allow_api'] = false;
871 self::assertFalse(api_get_user($this->app));
875 * Test the api_get_user() function with an user ID in a GET parameter.
879 public function testApiGetUserWithGetId()
881 $_GET['user_id'] = $this->otherUser['id'];
882 self::assertOtherUser(api_get_user($this->app));
886 * Test the api_get_user() function with a wrong user ID in a GET parameter.
889 * @expectedException Friendica\Network\HTTPException\BadRequestException
891 public function testApiGetUserWithWrongGetId()
893 $_GET['user_id'] = $this->wrongUserId;
894 self::assertOtherUser(api_get_user($this->app));
898 * Test the api_get_user() function with an user name in a GET parameter.
902 public function testApiGetUserWithGetName()
904 $_GET['screen_name'] = $this->selfUser['nick'];
905 self::assertSelfUser(api_get_user($this->app));
909 * Test the api_get_user() function with a profile URL in a GET parameter.
913 public function testApiGetUserWithGetUrl()
915 $_GET['profileurl'] = $this->selfUser['nurl'];
916 self::assertSelfUser(api_get_user($this->app));
920 * Test the api_get_user() function with an user ID in the API path.
924 public function testApiGetUserWithNumericCalledApi()
927 $called_api = ['api_path'];
928 $this->app->argv[1] = $this->otherUser['id'] . '.json';
929 self::assertOtherUser(api_get_user($this->app));
933 * Test the api_get_user() function with the $called_api global variable.
937 public function testApiGetUserWithCalledApi()
940 $called_api = ['api', 'api_path'];
941 self::assertSelfUser(api_get_user($this->app));
945 * Test the api_get_user() function with a valid user.
949 public function testApiGetUserWithCorrectUser()
951 self::assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
955 * Test the api_get_user() function with a wrong user ID.
958 * @expectedException Friendica\Network\HTTPException\BadRequestException
960 public function testApiGetUserWithWrongUser()
962 self::assertOtherUser(api_get_user($this->app, $this->wrongUserId));
966 * Test the api_get_user() function with a 0 user ID.
970 public function testApiGetUserWithZeroUser()
972 self::assertSelfUser(api_get_user($this->app, 0));
976 * Test the api_item_get_user() function.
980 public function testApiItemGetUser()
982 $users = api_item_get_user($this->app, []);
983 self::assertSelfUser($users[0]);
987 * Test the api_item_get_user() function with a different item parent.
991 public function testApiItemGetUserWithDifferentParent()
993 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
994 self::assertSelfUser($users[0]);
995 self::assertEquals($users[0], $users[1]);
999 * Test the api_walk_recursive() function.
1003 public function testApiWalkRecursive()
1011 // Should we test this with a callback that actually does something?
1019 * Test the api_walk_recursive() function with an array.
1023 public function testApiWalkRecursiveWithArray()
1025 $array = [['item1'], ['item2']];
1031 // Should we test this with a callback that actually does something?
1039 * Test the api_reformat_xml() function.
1043 public function testApiReformatXml()
1047 self::assertTrue(api_reformat_xml($item, $key));
1048 self::assertEquals('true', $item);
1052 * Test the api_reformat_xml() function with a statusnet_api key.
1056 public function testApiReformatXmlWithStatusnetKey()
1059 $key = 'statusnet_api';
1060 self::assertTrue(api_reformat_xml($item, $key));
1061 self::assertEquals('statusnet:api', $key);
1065 * Test the api_reformat_xml() function with a friendica_api key.
1069 public function testApiReformatXmlWithFriendicaKey()
1072 $key = 'friendica_api';
1073 self::assertTrue(api_reformat_xml($item, $key));
1074 self::assertEquals('friendica:api', $key);
1078 * Test the api_create_xml() function.
1082 public function testApiCreateXml()
1085 '<?xml version="1.0"?>' . "\n" .
1086 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1087 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1088 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1089 ' <data>some_data</data>' . "\n" .
1090 '</root_element>' . "\n",
1091 api_create_xml(['data' => ['some_data']], 'root_element')
1096 * Test the api_create_xml() function without any XML namespace.
1100 public function testApiCreateXmlWithoutNamespaces()
1103 '<?xml version="1.0"?>' . "\n" .
1105 ' <data>some_data</data>' . "\n" .
1107 api_create_xml(['data' => ['some_data']], 'ok')
1112 * Test the api_format_data() function.
1116 public function testApiFormatData()
1118 $data = ['some_data'];
1119 self::assertEquals($data, api_format_data('root_element', 'json', $data));
1123 * Test the api_format_data() function with an XML result.
1127 public function testApiFormatDataWithXml()
1130 '<?xml version="1.0"?>' . "\n" .
1131 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1132 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1133 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1134 ' <data>some_data</data>' . "\n" .
1135 '</root_element>' . "\n",
1136 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1141 * Test the api_account_verify_credentials() function.
1145 public function testApiAccountVerifyCredentials()
1147 self::assertArrayHasKey('user', api_account_verify_credentials('json'));
1151 * Test the api_account_verify_credentials() function without an authenticated user.
1154 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1156 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1158 $_SESSION['authenticated'] = false;
1159 api_account_verify_credentials('json');
1163 * Test the requestdata() function.
1167 public function testRequestdata()
1169 self::assertNull(requestdata('variable_name'));
1173 * Test the requestdata() function with a POST parameter.
1177 public function testRequestdataWithPost()
1179 $_POST['variable_name'] = 'variable_value';
1180 self::assertEquals('variable_value', requestdata('variable_name'));
1184 * Test the requestdata() function with a GET parameter.
1188 public function testRequestdataWithGet()
1190 $_GET['variable_name'] = 'variable_value';
1191 self::assertEquals('variable_value', requestdata('variable_name'));
1195 * Test the api_statuses_mediap() function.
1199 public function testApiStatusesMediap()
1201 $this->app->argc = 2;
1209 'tmp_name' => $this->getTempImage(),
1210 'name' => 'spacer.png',
1211 'type' => 'image/png'
1214 $_GET['status'] = '<b>Status content</b>';
1216 $result = api_statuses_mediap('json');
1217 self::assertStatus($result['status']);
1221 * Test the api_statuses_mediap() function without an authenticated user.
1224 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1226 public function testApiStatusesMediapWithoutAuthenticatedUser()
1228 $_SESSION['authenticated'] = false;
1229 api_statuses_mediap('json');
1233 * Test the api_statuses_update() function.
1237 public function testApiStatusesUpdate()
1239 $_GET['status'] = 'Status content #friendica';
1240 $_GET['in_reply_to_status_id'] = -1;
1249 'tmp_name' => $this->getTempImage(),
1250 'name' => 'spacer.png',
1251 'type' => 'image/png'
1255 $result = api_statuses_update('json');
1256 self::assertStatus($result['status']);
1260 * Test the api_statuses_update() function with an HTML status.
1264 public function testApiStatusesUpdateWithHtml()
1266 $_GET['htmlstatus'] = '<b>Status content</b>';
1268 $result = api_statuses_update('json');
1269 self::assertStatus($result['status']);
1273 * Test the api_statuses_update() function without an authenticated user.
1276 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1278 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1280 $_SESSION['authenticated'] = false;
1281 api_statuses_update('json');
1285 * Test the api_statuses_update() function with a parent status.
1289 public function testApiStatusesUpdateWithParent()
1291 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1295 * Test the api_statuses_update() function with a media_ids parameter.
1299 public function testApiStatusesUpdateWithMediaIds()
1301 $this->markTestIncomplete();
1305 * Test the api_statuses_update() function with the throttle limit reached.
1309 public function testApiStatusesUpdateWithDayThrottleReached()
1311 $this->markTestIncomplete();
1315 * Test the api_media_upload() function.
1316 * @runInSeparateProcess
1317 * @preserveGlobalState disabled
1318 * @expectedException Friendica\Network\HTTPException\BadRequestException
1320 public function testApiMediaUpload()
1326 * Test the api_media_upload() function without an authenticated user.
1329 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1331 public function testApiMediaUploadWithoutAuthenticatedUser()
1333 $_SESSION['authenticated'] = false;
1338 * Test the api_media_upload() function with an invalid uploaded media.
1341 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1343 public function testApiMediaUploadWithMedia()
1348 'tmp_name' => 'tmp_name'
1355 * Test the api_media_upload() function with an valid uploaded media.
1359 public function testApiMediaUploadWithValidMedia()
1367 'tmp_name' => $this->getTempImage(),
1368 'name' => 'spacer.png',
1369 'type' => 'image/png'
1375 $result = api_media_upload();
1376 self::assertEquals('image/png', $result['media']['image']['image_type']);
1377 self::assertEquals(1, $result['media']['image']['w']);
1378 self::assertEquals(1, $result['media']['image']['h']);
1379 self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
1383 * Test the api_status_show() function.
1385 public function testApiStatusShowWithJson()
1387 $result = api_status_show('json', 1);
1388 self::assertStatus($result['status']);
1392 * Test the api_status_show() function with an XML result.
1394 public function testApiStatusShowWithXml()
1396 $result = api_status_show('xml', 1);
1397 self::assertXml($result, 'statuses');
1401 * Test the api_get_last_status() function
1403 public function testApiGetLastStatus()
1405 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1407 self::assertNotNull($item);
1411 * Test the api_users_show() function.
1415 public function testApiUsersShow()
1417 $result = api_users_show('json');
1418 // We can't use assertSelfUser() here because the user object is missing some properties.
1419 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
1420 self::assertEquals('DFRN', $result['user']['location']);
1421 self::assertEquals($this->selfUser['name'], $result['user']['name']);
1422 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1423 self::assertEquals('dfrn', $result['user']['network']);
1424 self::assertTrue($result['user']['verified']);
1428 * Test the api_users_show() function with an XML result.
1432 public function testApiUsersShowWithXml()
1434 $result = api_users_show('xml');
1435 self::assertXml($result, 'statuses');
1439 * Test the api_users_search() function.
1443 public function testApiUsersSearch()
1445 $_GET['q'] = 'othercontact';
1446 $result = api_users_search('json');
1447 self::assertOtherUser($result['users'][0]);
1451 * Test the api_users_search() function with an XML result.
1455 public function testApiUsersSearchWithXml()
1457 $_GET['q'] = 'othercontact';
1458 $result = api_users_search('xml');
1459 self::assertXml($result, 'users');
1463 * Test the api_users_search() function without a GET q parameter.
1466 * @expectedException Friendica\Network\HTTPException\BadRequestException
1468 public function testApiUsersSearchWithoutQuery()
1470 api_users_search('json');
1474 * Test the api_users_lookup() function.
1477 * @expectedException Friendica\Network\HTTPException\NotFoundException
1479 public function testApiUsersLookup()
1481 api_users_lookup('json');
1485 * Test the api_users_lookup() function with an user ID.
1489 public function testApiUsersLookupWithUserId()
1491 $_REQUEST['user_id'] = $this->otherUser['id'];
1492 $result = api_users_lookup('json');
1493 self::assertOtherUser($result['users'][0]);
1497 * Test the api_search() function.
1501 public function testApiSearch()
1503 $_REQUEST['q'] = 'reply';
1504 $_REQUEST['max_id'] = 10;
1505 $result = api_search('json');
1506 foreach ($result['status'] as $status) {
1507 self::assertStatus($status);
1508 self::assertContains('reply', $status['text'], '', true);
1513 * Test the api_search() function a count parameter.
1517 public function testApiSearchWithCount()
1519 $_REQUEST['q'] = 'reply';
1520 $_REQUEST['count'] = 20;
1521 $result = api_search('json');
1522 foreach ($result['status'] as $status) {
1523 self::assertStatus($status);
1524 self::assertContains('reply', $status['text'], '', true);
1529 * Test the api_search() function with an rpp parameter.
1533 public function testApiSearchWithRpp()
1535 $_REQUEST['q'] = 'reply';
1536 $_REQUEST['rpp'] = 20;
1537 $result = api_search('json');
1538 foreach ($result['status'] as $status) {
1539 self::assertStatus($status);
1540 self::assertContains('reply', $status['text'], '', true);
1545 * Test the api_search() function with an q parameter contains hashtag.
1546 * @doesNotPerformAssertions
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'], '', true);
1559 * Test the api_search() function with an exclude_replies parameter.
1560 * @doesNotPerformAssertions
1562 public function testApiSearchWithExcludeReplies()
1564 $_REQUEST['max_id'] = 10;
1565 $_REQUEST['exclude_replies'] = true;
1566 $_REQUEST['q'] = 'friendica';
1567 $result = api_search('json');
1568 foreach ($result['status'] as $status) {
1569 self::assertStatus($status);
1574 * Test the api_search() function without an authenticated user.
1577 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1579 public function testApiSearchWithUnallowedUser()
1581 $_SESSION['allow_api'] = false;
1582 $_GET['screen_name'] = $this->selfUser['nick'];
1587 * Test the api_search() function without any GET query parameter.
1590 * @expectedException Friendica\Network\HTTPException\BadRequestException
1592 public function testApiSearchWithoutQuery()
1598 * Test the api_statuses_home_timeline() function.
1602 public function testApiStatusesHomeTimeline()
1604 $_REQUEST['max_id'] = 10;
1605 $_REQUEST['exclude_replies'] = true;
1606 $_REQUEST['conversation_id'] = 1;
1607 $result = api_statuses_home_timeline('json');
1608 self::assertNotEmpty($result['status']);
1609 foreach ($result['status'] as $status) {
1610 self::assertStatus($status);
1615 * Test the api_statuses_home_timeline() function with a negative page parameter.
1619 public function testApiStatusesHomeTimelineWithNegativePage()
1621 $_REQUEST['page'] = -2;
1622 $result = api_statuses_home_timeline('json');
1623 self::assertNotEmpty($result['status']);
1624 foreach ($result['status'] as $status) {
1625 self::assertStatus($status);
1630 * Test the api_statuses_home_timeline() with an unallowed user.
1633 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1635 public function testApiStatusesHomeTimelineWithUnallowedUser()
1637 $_SESSION['allow_api'] = false;
1638 $_GET['screen_name'] = $this->selfUser['nick'];
1639 api_statuses_home_timeline('json');
1643 * Test the api_statuses_home_timeline() function with an RSS result.
1647 public function testApiStatusesHomeTimelineWithRss()
1649 $result = api_statuses_home_timeline('rss');
1650 self::assertXml($result, 'statuses');
1654 * Test the api_statuses_public_timeline() function.
1658 public function testApiStatusesPublicTimeline()
1660 $_REQUEST['max_id'] = 10;
1661 $_REQUEST['conversation_id'] = 1;
1662 $result = api_statuses_public_timeline('json');
1663 self::assertNotEmpty($result['status']);
1664 foreach ($result['status'] as $status) {
1665 self::assertStatus($status);
1670 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1674 public function testApiStatusesPublicTimelineWithExcludeReplies()
1676 $_REQUEST['max_id'] = 10;
1677 $_REQUEST['exclude_replies'] = true;
1678 $result = api_statuses_public_timeline('json');
1679 self::assertNotEmpty($result['status']);
1680 foreach ($result['status'] as $status) {
1681 self::assertStatus($status);
1686 * Test the api_statuses_public_timeline() function with a negative page parameter.
1690 public function testApiStatusesPublicTimelineWithNegativePage()
1692 $_REQUEST['page'] = -2;
1693 $result = api_statuses_public_timeline('json');
1694 self::assertNotEmpty($result['status']);
1695 foreach ($result['status'] as $status) {
1696 self::assertStatus($status);
1701 * Test the api_statuses_public_timeline() function with an unallowed user.
1704 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1706 public function testApiStatusesPublicTimelineWithUnallowedUser()
1708 $_SESSION['allow_api'] = false;
1709 $_GET['screen_name'] = $this->selfUser['nick'];
1710 api_statuses_public_timeline('json');
1714 * Test the api_statuses_public_timeline() function with an RSS result.
1718 public function testApiStatusesPublicTimelineWithRss()
1720 $result = api_statuses_public_timeline('rss');
1721 self::assertXml($result, 'statuses');
1725 * Test the api_statuses_networkpublic_timeline() function.
1729 public function testApiStatusesNetworkpublicTimeline()
1731 $_REQUEST['max_id'] = 10;
1732 $result = api_statuses_networkpublic_timeline('json');
1733 self::assertNotEmpty($result['status']);
1734 foreach ($result['status'] as $status) {
1735 self::assertStatus($status);
1740 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1744 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1746 $_REQUEST['page'] = -2;
1747 $result = api_statuses_networkpublic_timeline('json');
1748 self::assertNotEmpty($result['status']);
1749 foreach ($result['status'] as $status) {
1750 self::assertStatus($status);
1755 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1758 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1760 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1762 $_SESSION['allow_api'] = false;
1763 $_GET['screen_name'] = $this->selfUser['nick'];
1764 api_statuses_networkpublic_timeline('json');
1768 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1772 public function testApiStatusesNetworkpublicTimelineWithRss()
1774 $result = api_statuses_networkpublic_timeline('rss');
1775 self::assertXml($result, 'statuses');
1779 * Test the api_statuses_show() function.
1782 * @expectedException Friendica\Network\HTTPException\BadRequestException
1784 public function testApiStatusesShow()
1786 api_statuses_show('json');
1790 * Test the api_statuses_show() function with an ID.
1794 public function testApiStatusesShowWithId()
1796 $this->app->argv[3] = 1;
1797 $result = api_statuses_show('json');
1798 self::assertStatus($result['status']);
1802 * Test the api_statuses_show() function with the conversation parameter.
1806 public function testApiStatusesShowWithConversation()
1808 $this->app->argv[3] = 1;
1809 $_REQUEST['conversation'] = 1;
1810 $result = api_statuses_show('json');
1811 self::assertNotEmpty($result['status']);
1812 foreach ($result['status'] as $status) {
1813 self::assertStatus($status);
1818 * Test the api_statuses_show() function with an unallowed user.
1821 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1823 public function testApiStatusesShowWithUnallowedUser()
1825 $_SESSION['allow_api'] = false;
1826 $_GET['screen_name'] = $this->selfUser['nick'];
1827 api_statuses_show('json');
1831 * Test the api_conversation_show() function.
1834 * @expectedException Friendica\Network\HTTPException\BadRequestException
1836 public function testApiConversationShow()
1838 api_conversation_show('json');
1842 * Test the api_conversation_show() function with an ID.
1846 public function testApiConversationShowWithId()
1848 $this->app->argv[3] = 1;
1849 $_REQUEST['max_id'] = 10;
1850 $_REQUEST['page'] = -2;
1851 $result = api_conversation_show('json');
1852 self::assertNotEmpty($result['status']);
1853 foreach ($result['status'] as $status) {
1854 self::assertStatus($status);
1859 * Test the api_conversation_show() function with an unallowed user.
1862 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1864 public function testApiConversationShowWithUnallowedUser()
1866 $_SESSION['allow_api'] = false;
1867 $_GET['screen_name'] = $this->selfUser['nick'];
1868 api_conversation_show('json');
1872 * Test the api_statuses_repeat() function.
1875 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1877 public function testApiStatusesRepeat()
1879 api_statuses_repeat('json');
1883 * Test the api_statuses_repeat() function without an authenticated user.
1886 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1888 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1890 $_SESSION['authenticated'] = false;
1891 api_statuses_repeat('json');
1895 * Test the api_statuses_repeat() function with an ID.
1899 public function testApiStatusesRepeatWithId()
1901 $this->app->argv[3] = 1;
1902 $result = api_statuses_repeat('json');
1903 self::assertStatus($result['status']);
1905 // Also test with a shared status
1906 $this->app->argv[3] = 5;
1907 $result = api_statuses_repeat('json');
1908 self::assertStatus($result['status']);
1912 * Test the api_statuses_destroy() function.
1915 * @expectedException Friendica\Network\HTTPException\BadRequestException
1917 public function testApiStatusesDestroy()
1919 api_statuses_destroy('json');
1923 * Test the api_statuses_destroy() function without an authenticated user.
1926 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1928 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1930 $_SESSION['authenticated'] = false;
1931 api_statuses_destroy('json');
1935 * Test the api_statuses_destroy() function with an ID.
1939 public function testApiStatusesDestroyWithId()
1941 $this->app->argv[3] = 1;
1942 $result = api_statuses_destroy('json');
1943 self::assertStatus($result['status']);
1947 * Test the api_statuses_mentions() function.
1951 public function testApiStatusesMentions()
1953 $this->app->user = ['nickname' => $this->selfUser['nick']];
1954 $_REQUEST['max_id'] = 10;
1955 $result = api_statuses_mentions('json');
1956 self::assertEmpty($result['status']);
1957 // We should test with mentions in the database.
1961 * Test the api_statuses_mentions() function with a negative page parameter.
1965 public function testApiStatusesMentionsWithNegativePage()
1967 $_REQUEST['page'] = -2;
1968 $result = api_statuses_mentions('json');
1969 self::assertEmpty($result['status']);
1973 * Test the api_statuses_mentions() function with an unallowed user.
1976 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1978 public function testApiStatusesMentionsWithUnallowedUser()
1980 $_SESSION['allow_api'] = false;
1981 $_GET['screen_name'] = $this->selfUser['nick'];
1982 api_statuses_mentions('json');
1986 * Test the api_statuses_mentions() function with an RSS result.
1990 public function testApiStatusesMentionsWithRss()
1992 $result = api_statuses_mentions('rss');
1993 self::assertXml($result, 'statuses');
1997 * Test the api_statuses_user_timeline() function.
2001 public function testApiStatusesUserTimeline()
2003 $_REQUEST['max_id'] = 10;
2004 $_REQUEST['exclude_replies'] = true;
2005 $_REQUEST['conversation_id'] = 1;
2006 $result = api_statuses_user_timeline('json');
2007 self::assertNotEmpty($result['status']);
2008 foreach ($result['status'] as $status) {
2009 self::assertStatus($status);
2014 * Test the api_statuses_user_timeline() function with a negative page parameter.
2018 public function testApiStatusesUserTimelineWithNegativePage()
2020 $_REQUEST['page'] = -2;
2021 $result = api_statuses_user_timeline('json');
2022 self::assertNotEmpty($result['status']);
2023 foreach ($result['status'] as $status) {
2024 self::assertStatus($status);
2029 * Test the api_statuses_user_timeline() function with an RSS result.
2033 public function testApiStatusesUserTimelineWithRss()
2035 $result = api_statuses_user_timeline('rss');
2036 self::assertXml($result, 'statuses');
2040 * Test the api_statuses_user_timeline() function with an unallowed user.
2043 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2045 public function testApiStatusesUserTimelineWithUnallowedUser()
2047 $_SESSION['allow_api'] = false;
2048 $_GET['screen_name'] = $this->selfUser['nick'];
2049 api_statuses_user_timeline('json');
2053 * Test the api_favorites_create_destroy() function.
2056 * @expectedException Friendica\Network\HTTPException\BadRequestException
2058 public function testApiFavoritesCreateDestroy()
2060 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2061 $this->app->argc = count($this->app->argv);
2062 api_favorites_create_destroy('json');
2066 * Test the api_favorites_create_destroy() function with an invalid ID.
2069 * @expectedException Friendica\Network\HTTPException\BadRequestException
2071 public function testApiFavoritesCreateDestroyWithInvalidId()
2073 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2074 $this->app->argc = count($this->app->argv);
2075 api_favorites_create_destroy('json');
2079 * Test the api_favorites_create_destroy() function with an invalid action.
2082 * @expectedException Friendica\Network\HTTPException\BadRequestException
2084 public function testApiFavoritesCreateDestroyWithInvalidAction()
2086 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2087 $this->app->argc = count($this->app->argv);
2088 $_REQUEST['id'] = 1;
2089 api_favorites_create_destroy('json');
2093 * Test the api_favorites_create_destroy() function with the create action.
2097 public function testApiFavoritesCreateDestroyWithCreateAction()
2099 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2100 $this->app->argc = count($this->app->argv);
2101 $_REQUEST['id'] = 3;
2102 $result = api_favorites_create_destroy('json');
2103 self::assertStatus($result['status']);
2107 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2111 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2113 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2114 $this->app->argc = count($this->app->argv);
2115 $_REQUEST['id'] = 3;
2116 $result = api_favorites_create_destroy('rss');
2117 self::assertXml($result, 'status');
2121 * Test the api_favorites_create_destroy() function with the destroy action.
2125 public function testApiFavoritesCreateDestroyWithDestroyAction()
2127 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2128 $this->app->argc = count($this->app->argv);
2129 $_REQUEST['id'] = 3;
2130 $result = api_favorites_create_destroy('json');
2131 self::assertStatus($result['status']);
2135 * Test the api_favorites_create_destroy() function without an authenticated user.
2138 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2140 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2142 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2143 $this->app->argc = count($this->app->argv);
2144 $_SESSION['authenticated'] = false;
2145 api_favorites_create_destroy('json');
2149 * Test the api_favorites() function.
2153 public function testApiFavorites()
2155 $_REQUEST['page'] = -1;
2156 $_REQUEST['max_id'] = 10;
2157 $result = api_favorites('json');
2158 foreach ($result['status'] as $status) {
2159 self::assertStatus($status);
2164 * Test the api_favorites() function with an RSS result.
2168 public function testApiFavoritesWithRss()
2170 $result = api_favorites('rss');
2171 self::assertXml($result, 'statuses');
2175 * Test the api_favorites() function with an unallowed user.
2178 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2180 public function testApiFavoritesWithUnallowedUser()
2182 $_SESSION['allow_api'] = false;
2183 $_GET['screen_name'] = $this->selfUser['nick'];
2184 api_favorites('json');
2188 * Test the api_format_messages() function.
2192 public function testApiFormatMessages()
2194 $result = api_format_messages(
2195 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2196 ['id' => 2, 'screen_name' => 'recipient_name'],
2197 ['id' => 3, 'screen_name' => 'sender_name']
2199 self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2200 self::assertEquals(1, $result['id']);
2201 self::assertEquals(2, $result['recipient_id']);
2202 self::assertEquals(3, $result['sender_id']);
2203 self::assertEquals('recipient_name', $result['recipient_screen_name']);
2204 self::assertEquals('sender_name', $result['sender_screen_name']);
2208 * Test the api_format_messages() function with HTML.
2212 public function testApiFormatMessagesWithHtmlText()
2214 $_GET['getText'] = 'html';
2215 $result = api_format_messages(
2216 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2217 ['id' => 2, 'screen_name' => 'recipient_name'],
2218 ['id' => 3, 'screen_name' => 'sender_name']
2220 self::assertEquals('item_title', $result['title']);
2221 self::assertEquals('<strong>item_body</strong>', $result['text']);
2225 * Test the api_format_messages() function with plain text.
2229 public function testApiFormatMessagesWithPlainText()
2231 $_GET['getText'] = 'plain';
2232 $result = api_format_messages(
2233 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2234 ['id' => 2, 'screen_name' => 'recipient_name'],
2235 ['id' => 3, 'screen_name' => 'sender_name']
2237 self::assertEquals('item_title', $result['title']);
2238 self::assertEquals('item_body', $result['text']);
2242 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2246 public function testApiFormatMessagesWithoutUserObjects()
2248 $_GET['getUserObjects'] = 'false';
2249 $result = api_format_messages(
2250 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2251 ['id' => 2, 'screen_name' => 'recipient_name'],
2252 ['id' => 3, 'screen_name' => 'sender_name']
2254 self::assertTrue(!isset($result['sender']));
2255 self::assertTrue(!isset($result['recipient']));
2259 * Test the api_convert_item() function.
2263 public function testApiConvertItem()
2265 $result = api_convert_item(
2267 'network' => 'feed',
2268 'title' => 'item_title',
2269 // We need a long string to test that it is correctly cut
2270 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2271 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2272 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2273 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2274 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2275 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2276 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2277 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2278 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2279 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2280 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2281 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2282 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2283 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2284 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2285 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2286 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2287 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2288 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2289 'repellat officia illum quos impedit quam iste esse unde qui ' .
2290 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2291 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2292 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2293 'plink' => 'item_plink'
2296 self::assertStringStartsWith('item_title', $result['text']);
2297 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2301 * Test the api_convert_item() function with an empty item body.
2305 public function testApiConvertItemWithoutBody()
2307 $result = api_convert_item(
2309 'network' => 'feed',
2310 'title' => 'item_title',
2312 'plink' => 'item_plink'
2315 self::assertEquals('item_title', $result['text']);
2316 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2320 * Test the api_convert_item() function with the title in the body.
2324 public function testApiConvertItemWithTitleInBody()
2326 $result = api_convert_item(
2328 'title' => 'item_title',
2329 'body' => 'item_title item_body'
2332 self::assertEquals('item_title item_body', $result['text']);
2333 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2337 * Test the api_get_attachments() function.
2341 public function testApiGetAttachments()
2344 self::assertEmpty(api_get_attachments($body));
2348 * Test the api_get_attachments() function with an img tag.
2352 public function testApiGetAttachmentsWithImage()
2354 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2355 self::assertInternalType('array', api_get_attachments($body));
2359 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2363 public function testApiGetAttachmentsWithImageAndAndStatus()
2365 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2366 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2367 self::assertInternalType('array', api_get_attachments($body));
2371 * Test the api_get_entitities() function.
2375 public function testApiGetEntitities()
2378 self::assertInternalType('array', api_get_entitities($text, 'bbcode'));
2382 * Test the api_get_entitities() function with the include_entities parameter.
2386 public function testApiGetEntititiesWithIncludeEntities()
2388 $_REQUEST['include_entities'] = 'true';
2390 $result = api_get_entitities($text, 'bbcode');
2391 self::assertInternalType('array', $result['hashtags']);
2392 self::assertInternalType('array', $result['symbols']);
2393 self::assertInternalType('array', $result['urls']);
2394 self::assertInternalType('array', $result['user_mentions']);
2398 * Test the api_format_items_embeded_images() function.
2402 public function testApiFormatItemsEmbededImages()
2405 'text ' . DI::baseUrl() . '/display/item_guid',
2406 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2411 * Test the api_contactlink_to_array() function.
2415 public function testApiContactlinkToArray()
2422 api_contactlink_to_array('text')
2427 * Test the api_contactlink_to_array() function with an URL.
2431 public function testApiContactlinkToArrayWithUrl()
2435 'name' => ['link_text'],
2438 api_contactlink_to_array('text <a href="url">link_text</a>')
2443 * Test the api_format_items_activities() function.
2447 public function testApiFormatItemsActivities()
2449 $item = ['uid' => 0, 'uri' => ''];
2450 $result = api_format_items_activities($item);
2451 self::assertArrayHasKey('like', $result);
2452 self::assertArrayHasKey('dislike', $result);
2453 self::assertArrayHasKey('attendyes', $result);
2454 self::assertArrayHasKey('attendno', $result);
2455 self::assertArrayHasKey('attendmaybe', $result);
2459 * Test the api_format_items_activities() function with an XML result.
2463 public function testApiFormatItemsActivitiesWithXml()
2465 $item = ['uid' => 0, 'uri' => ''];
2466 $result = api_format_items_activities($item, 'xml');
2467 self::assertArrayHasKey('friendica:like', $result);
2468 self::assertArrayHasKey('friendica:dislike', $result);
2469 self::assertArrayHasKey('friendica:attendyes', $result);
2470 self::assertArrayHasKey('friendica:attendno', $result);
2471 self::assertArrayHasKey('friendica:attendmaybe', $result);
2475 * Test the api_format_items() function.
2476 * @doesNotPerformAssertions
2478 public function testApiFormatItems()
2482 'item_network' => 'item_network',
2488 'author-network' => Protocol::DFRN,
2489 'author-link' => 'http://localhost/profile/othercontact',
2493 $result = api_format_items($items, ['id' => 0], true);
2494 foreach ($result as $status) {
2495 self::assertStatus($status);
2500 * Test the api_format_items() function with an XML result.
2501 * @doesNotPerformAssertions
2503 public function testApiFormatItemsWithXml()
2511 'author-network' => Protocol::DFRN,
2512 'author-link' => 'http://localhost/profile/othercontact',
2516 $result = api_format_items($items, ['id' => 0], true, 'xml');
2517 foreach ($result as $status) {
2518 self::assertStatus($status);
2523 * Test the api_format_items() function.
2527 public function testApiAccountRateLimitStatus()
2529 $result = api_account_rate_limit_status('json');
2530 self::assertEquals(150, $result['hash']['remaining_hits']);
2531 self::assertEquals(150, $result['hash']['hourly_limit']);
2532 self::assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2536 * Test the api_format_items() function with an XML result.
2540 public function testApiAccountRateLimitStatusWithXml()
2542 $result = api_account_rate_limit_status('xml');
2543 self::assertXml($result, 'hash');
2547 * Test the api_help_test() function.
2551 public function testApiHelpTest()
2553 $result = api_help_test('json');
2554 self::assertEquals(['ok' => 'ok'], $result);
2558 * Test the api_help_test() function with an XML result.
2562 public function testApiHelpTestWithXml()
2564 $result = api_help_test('xml');
2565 self::assertXml($result, 'ok');
2569 * Test the api_lists_list() function.
2573 public function testApiListsList()
2575 $result = api_lists_list('json');
2576 self::assertEquals(['lists_list' => []], $result);
2580 * Test the api_lists_ownerships() function.
2584 public function testApiListsOwnerships()
2586 $result = api_lists_ownerships('json');
2587 foreach ($result['lists']['lists'] as $list) {
2588 self::assertList($list);
2593 * Test the api_lists_ownerships() function without an authenticated user.
2596 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2598 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2600 $_SESSION['authenticated'] = false;
2601 api_lists_ownerships('json');
2605 * Test the api_lists_statuses() function.
2607 * @expectedException Friendica\Network\HTTPException\BadRequestException
2610 public function testApiListsStatuses()
2612 api_lists_statuses('json');
2616 * Test the api_lists_statuses() function with a list ID.
2617 * @doesNotPerformAssertions
2619 public function testApiListsStatusesWithListId()
2621 $_REQUEST['list_id'] = 1;
2622 $_REQUEST['page'] = -1;
2623 $_REQUEST['max_id'] = 10;
2624 $result = api_lists_statuses('json');
2625 foreach ($result['status'] as $status) {
2626 self::assertStatus($status);
2631 * Test the api_lists_statuses() function with a list ID and a RSS result.
2635 public function testApiListsStatusesWithListIdAndRss()
2637 $_REQUEST['list_id'] = 1;
2638 $result = api_lists_statuses('rss');
2639 self::assertXml($result, 'statuses');
2643 * Test the api_lists_statuses() function with an unallowed user.
2646 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2648 public function testApiListsStatusesWithUnallowedUser()
2650 $_SESSION['allow_api'] = false;
2651 $_GET['screen_name'] = $this->selfUser['nick'];
2652 api_lists_statuses('json');
2656 * Test the api_statuses_f() function.
2660 public function testApiStatusesFWithFriends()
2663 $result = api_statuses_f('friends');
2664 self::assertArrayHasKey('user', $result);
2668 * Test the api_statuses_f() function.
2672 public function testApiStatusesFWithFollowers()
2674 $result = api_statuses_f('followers');
2675 self::assertArrayHasKey('user', $result);
2679 * Test the api_statuses_f() function.
2683 public function testApiStatusesFWithBlocks()
2685 $result = api_statuses_f('blocks');
2686 self::assertArrayHasKey('user', $result);
2690 * Test the api_statuses_f() function.
2694 public function testApiStatusesFWithIncoming()
2696 $result = api_statuses_f('incoming');
2697 self::assertArrayHasKey('user', $result);
2701 * Test the api_statuses_f() function an undefined cursor GET variable.
2705 public function testApiStatusesFWithUndefinedCursor()
2707 $_GET['cursor'] = 'undefined';
2708 self::assertFalse(api_statuses_f('friends'));
2712 * Test the api_statuses_friends() function.
2716 public function testApiStatusesFriends()
2718 $result = api_statuses_friends('json');
2719 self::assertArrayHasKey('user', $result);
2723 * Test the api_statuses_friends() function an undefined cursor GET variable.
2727 public function testApiStatusesFriendsWithUndefinedCursor()
2729 $_GET['cursor'] = 'undefined';
2730 self::assertFalse(api_statuses_friends('json'));
2734 * Test the api_statuses_followers() function.
2738 public function testApiStatusesFollowers()
2740 $result = api_statuses_followers('json');
2741 self::assertArrayHasKey('user', $result);
2745 * Test the api_statuses_followers() function an undefined cursor GET variable.
2749 public function testApiStatusesFollowersWithUndefinedCursor()
2751 $_GET['cursor'] = 'undefined';
2752 self::assertFalse(api_statuses_followers('json'));
2756 * Test the api_blocks_list() function.
2760 public function testApiBlocksList()
2762 $result = api_blocks_list('json');
2763 self::assertArrayHasKey('user', $result);
2767 * Test the api_blocks_list() function an undefined cursor GET variable.
2771 public function testApiBlocksListWithUndefinedCursor()
2773 $_GET['cursor'] = 'undefined';
2774 self::assertFalse(api_blocks_list('json'));
2778 * Test the api_friendships_incoming() function.
2782 public function testApiFriendshipsIncoming()
2784 $result = api_friendships_incoming('json');
2785 self::assertArrayHasKey('id', $result);
2789 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2793 public function testApiFriendshipsIncomingWithUndefinedCursor()
2795 $_GET['cursor'] = 'undefined';
2796 self::assertFalse(api_friendships_incoming('json'));
2800 * Test the api_statusnet_config() function.
2804 public function testApiStatusnetConfig()
2806 $result = api_statusnet_config('json');
2807 self::assertEquals('localhost', $result['config']['site']['server']);
2808 self::assertEquals('default', $result['config']['site']['theme']);
2809 self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2810 self::assertTrue($result['config']['site']['fancy']);
2811 self::assertEquals('en', $result['config']['site']['language']);
2812 self::assertEquals('UTC', $result['config']['site']['timezone']);
2813 self::assertEquals(200000, $result['config']['site']['textlimit']);
2814 self::assertEquals('false', $result['config']['site']['private']);
2815 self::assertEquals('false', $result['config']['site']['ssl']);
2816 self::assertEquals(30, $result['config']['site']['shorturllength']);
2820 * Test the api_statusnet_version() function.
2824 public function testApiStatusnetVersion()
2826 $result = api_statusnet_version('json');
2827 self::assertEquals('0.9.7', $result['version']);
2831 * Test the api_direct_messages_new() function.
2835 public function testApiDirectMessagesNew()
2837 $result = api_direct_messages_new('json');
2838 self::assertNull($result);
2842 * Test the api_direct_messages_new() function without an authenticated user.
2845 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2847 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2849 $_SESSION['authenticated'] = false;
2850 api_direct_messages_new('json');
2854 * Test the api_direct_messages_new() function with an user ID.
2858 public function testApiDirectMessagesNewWithUserId()
2860 $_POST['text'] = 'message_text';
2861 $_POST['user_id'] = $this->otherUser['id'];
2862 $result = api_direct_messages_new('json');
2863 self::assertEquals(['direct_message' => ['error' => -1]], $result);
2867 * Test the api_direct_messages_new() function with a screen name.
2871 public function testApiDirectMessagesNewWithScreenName()
2873 $this->app->user = ['nickname' => $this->selfUser['nick']];
2874 $_POST['text'] = 'message_text';
2875 $_POST['screen_name'] = $this->friendUser['nick'];
2876 $result = api_direct_messages_new('json');
2877 self::assertContains('message_text', $result['direct_message']['text']);
2878 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2879 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2883 * Test the api_direct_messages_new() function with a title.
2887 public function testApiDirectMessagesNewWithTitle()
2889 $this->app->user = ['nickname' => $this->selfUser['nick']];
2890 $_POST['text'] = 'message_text';
2891 $_POST['screen_name'] = $this->friendUser['nick'];
2892 $_REQUEST['title'] = 'message_title';
2893 $result = api_direct_messages_new('json');
2894 self::assertContains('message_text', $result['direct_message']['text']);
2895 self::assertContains('message_title', $result['direct_message']['text']);
2896 self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2897 self::assertEquals(1, $result['direct_message']['friendica_seen']);
2901 * Test the api_direct_messages_new() function with an RSS result.
2905 public function testApiDirectMessagesNewWithRss()
2907 $this->app->user = ['nickname' => $this->selfUser['nick']];
2908 $_POST['text'] = 'message_text';
2909 $_POST['screen_name'] = $this->friendUser['nick'];
2910 $result = api_direct_messages_new('rss');
2911 self::assertXml($result, 'direct-messages');
2915 * Test the api_direct_messages_destroy() function.
2918 * @expectedException Friendica\Network\HTTPException\BadRequestException
2920 public function testApiDirectMessagesDestroy()
2922 api_direct_messages_destroy('json');
2926 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2930 public function testApiDirectMessagesDestroyWithVerbose()
2932 $_GET['friendica_verbose'] = 'true';
2933 $result = api_direct_messages_destroy('json');
2937 'result' => 'error',
2938 'message' => 'message id or parenturi not specified'
2946 * Test the api_direct_messages_destroy() function without an authenticated user.
2949 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2951 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2953 $_SESSION['authenticated'] = false;
2954 api_direct_messages_destroy('json');
2958 * Test the api_direct_messages_destroy() function with a non-zero ID.
2961 * @expectedException Friendica\Network\HTTPException\BadRequestException
2963 public function testApiDirectMessagesDestroyWithId()
2965 $_REQUEST['id'] = 1;
2966 api_direct_messages_destroy('json');
2970 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2974 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2976 $_REQUEST['id'] = 1;
2977 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2978 $_GET['friendica_verbose'] = 'true';
2979 $result = api_direct_messages_destroy('json');
2983 'result' => 'error',
2984 'message' => 'message id not in database'
2992 * Test the api_direct_messages_destroy() function with a non-zero ID.
2996 public function testApiDirectMessagesDestroyWithCorrectId()
2998 $this->markTestIncomplete('We need to add a dataset for this.');
3002 * Test the api_direct_messages_box() function.
3006 public function testApiDirectMessagesBoxWithSentbox()
3008 $_REQUEST['page'] = -1;
3009 $_REQUEST['max_id'] = 10;
3010 $result = api_direct_messages_box('json', 'sentbox', 'false');
3011 self::assertArrayHasKey('direct_message', $result);
3015 * Test the api_direct_messages_box() function.
3019 public function testApiDirectMessagesBoxWithConversation()
3021 $result = api_direct_messages_box('json', 'conversation', 'false');
3022 self::assertArrayHasKey('direct_message', $result);
3026 * Test the api_direct_messages_box() function.
3030 public function testApiDirectMessagesBoxWithAll()
3032 $result = api_direct_messages_box('json', 'all', 'false');
3033 self::assertArrayHasKey('direct_message', $result);
3037 * Test the api_direct_messages_box() function.
3041 public function testApiDirectMessagesBoxWithInbox()
3043 $result = api_direct_messages_box('json', 'inbox', 'false');
3044 self::assertArrayHasKey('direct_message', $result);
3048 * Test the api_direct_messages_box() function.
3052 public function testApiDirectMessagesBoxWithVerbose()
3054 $result = api_direct_messages_box('json', 'sentbox', 'true');
3058 'result' => 'error',
3059 'message' => 'no mails available'
3067 * Test the api_direct_messages_box() function with a RSS result.
3071 public function testApiDirectMessagesBoxWithRss()
3073 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3074 self::assertXml($result, 'direct-messages');
3078 * Test the api_direct_messages_box() function without an authenticated user.
3081 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3083 public function testApiDirectMessagesBoxWithUnallowedUser()
3085 $_SESSION['allow_api'] = false;
3086 $_GET['screen_name'] = $this->selfUser['nick'];
3087 api_direct_messages_box('json', 'sentbox', 'false');
3091 * Test the api_direct_messages_sentbox() function.
3095 public function testApiDirectMessagesSentbox()
3097 $result = api_direct_messages_sentbox('json');
3098 self::assertArrayHasKey('direct_message', $result);
3102 * Test the api_direct_messages_inbox() function.
3106 public function testApiDirectMessagesInbox()
3108 $result = api_direct_messages_inbox('json');
3109 self::assertArrayHasKey('direct_message', $result);
3113 * Test the api_direct_messages_all() function.
3117 public function testApiDirectMessagesAll()
3119 $result = api_direct_messages_all('json');
3120 self::assertArrayHasKey('direct_message', $result);
3124 * Test the api_direct_messages_conversation() function.
3128 public function testApiDirectMessagesConversation()
3130 $result = api_direct_messages_conversation('json');
3131 self::assertArrayHasKey('direct_message', $result);
3135 * Test the api_oauth_request_token() function.
3139 public function testApiOauthRequestToken()
3141 $this->markTestIncomplete('exit() kills phpunit as well');
3145 * Test the api_oauth_access_token() function.
3149 public function testApiOauthAccessToken()
3151 $this->markTestIncomplete('exit() kills phpunit as well');
3155 * Test the api_fr_photoalbum_delete() function.
3158 * @expectedException Friendica\Network\HTTPException\BadRequestException
3160 public function testApiFrPhotoalbumDelete()
3162 api_fr_photoalbum_delete('json');
3166 * Test the api_fr_photoalbum_delete() function with an album name.
3169 * @expectedException Friendica\Network\HTTPException\BadRequestException
3171 public function testApiFrPhotoalbumDeleteWithAlbum()
3173 $_REQUEST['album'] = 'album_name';
3174 api_fr_photoalbum_delete('json');
3178 * Test the api_fr_photoalbum_delete() function with an album name.
3182 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3184 $this->markTestIncomplete('We need to add a dataset for this.');
3188 * Test the api_fr_photoalbum_delete() function.
3191 * @expectedException Friendica\Network\HTTPException\BadRequestException
3193 public function testApiFrPhotoalbumUpdate()
3195 api_fr_photoalbum_update('json');
3199 * Test the api_fr_photoalbum_delete() function with an album name.
3202 * @expectedException Friendica\Network\HTTPException\BadRequestException
3204 public function testApiFrPhotoalbumUpdateWithAlbum()
3206 $_REQUEST['album'] = 'album_name';
3207 api_fr_photoalbum_update('json');
3211 * Test the api_fr_photoalbum_delete() function with an album name.
3214 * @expectedException Friendica\Network\HTTPException\BadRequestException
3216 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3218 $_REQUEST['album'] = 'album_name';
3219 $_REQUEST['album_new'] = 'album_name';
3220 api_fr_photoalbum_update('json');
3224 * Test the api_fr_photoalbum_update() function without an authenticated user.
3227 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3229 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3231 $_SESSION['authenticated'] = false;
3232 api_fr_photoalbum_update('json');
3236 * Test the api_fr_photoalbum_delete() function with an album name.
3240 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3242 $this->markTestIncomplete('We need to add a dataset for this.');
3246 * Test the api_fr_photos_list() function.
3250 public function testApiFrPhotosList()
3252 $result = api_fr_photos_list('json');
3253 self::assertArrayHasKey('photo', $result);
3257 * Test the api_fr_photos_list() function without an authenticated user.
3260 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3262 public function testApiFrPhotosListWithoutAuthenticatedUser()
3264 $_SESSION['authenticated'] = false;
3265 api_fr_photos_list('json');
3269 * Test the api_fr_photo_create_update() function.
3270 * @expectedException Friendica\Network\HTTPException\BadRequestException
3272 public function testApiFrPhotoCreateUpdate()
3274 api_fr_photo_create_update('json');
3278 * Test the api_fr_photo_create_update() function without an authenticated user.
3281 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3283 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3285 $_SESSION['authenticated'] = false;
3286 api_fr_photo_create_update('json');
3290 * Test the api_fr_photo_create_update() function with an album name.
3293 * @expectedException Friendica\Network\HTTPException\BadRequestException
3295 public function testApiFrPhotoCreateUpdateWithAlbum()
3297 $_REQUEST['album'] = 'album_name';
3298 api_fr_photo_create_update('json');
3302 * Test the api_fr_photo_create_update() function with the update mode.
3306 public function testApiFrPhotoCreateUpdateWithUpdate()
3308 $this->markTestIncomplete('We need to create a dataset for this');
3312 * Test the api_fr_photo_create_update() function with an uploaded file.
3316 public function testApiFrPhotoCreateUpdateWithFile()
3318 $this->markTestIncomplete();
3322 * Test the api_fr_photo_delete() function.
3325 * @expectedException Friendica\Network\HTTPException\BadRequestException
3327 public function testApiFrPhotoDelete()
3329 api_fr_photo_delete('json');
3333 * Test the api_fr_photo_delete() function without an authenticated user.
3336 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3338 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3340 $_SESSION['authenticated'] = false;
3341 api_fr_photo_delete('json');
3345 * Test the api_fr_photo_delete() function with a photo ID.
3348 * @expectedException Friendica\Network\HTTPException\BadRequestException
3350 public function testApiFrPhotoDeleteWithPhotoId()
3352 $_REQUEST['photo_id'] = 1;
3353 api_fr_photo_delete('json');
3357 * Test the api_fr_photo_delete() function with a correct photo ID.
3361 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3363 $this->markTestIncomplete('We need to create a dataset for this.');
3367 * Test the api_fr_photo_detail() function.
3370 * @expectedException Friendica\Network\HTTPException\BadRequestException
3372 public function testApiFrPhotoDetail()
3374 api_fr_photo_detail('json');
3378 * Test the api_fr_photo_detail() function without an authenticated user.
3381 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3383 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3385 $_SESSION['authenticated'] = false;
3386 api_fr_photo_detail('json');
3390 * Test the api_fr_photo_detail() function with a photo ID.
3393 * @expectedException Friendica\Network\HTTPException\NotFoundException
3395 public function testApiFrPhotoDetailWithPhotoId()
3397 $_REQUEST['photo_id'] = 1;
3398 api_fr_photo_detail('json');
3402 * Test the api_fr_photo_detail() function with a correct photo ID.
3406 public function testApiFrPhotoDetailCorrectPhotoId()
3408 $this->markTestIncomplete('We need to create a dataset for this.');
3412 * Test the api_account_update_profile_image() function.
3415 * @expectedException Friendica\Network\HTTPException\BadRequestException
3417 public function testApiAccountUpdateProfileImage()
3419 api_account_update_profile_image('json');
3423 * Test the api_account_update_profile_image() function without an authenticated user.
3426 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3428 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3430 $_SESSION['authenticated'] = false;
3431 api_account_update_profile_image('json');
3435 * Test the api_account_update_profile_image() function with an uploaded file.
3438 * @expectedException Friendica\Network\HTTPException\BadRequestException
3440 public function testApiAccountUpdateProfileImageWithUpload()
3442 $this->markTestIncomplete();
3447 * Test the api_account_update_profile() function.
3451 public function testApiAccountUpdateProfile()
3453 $_POST['name'] = 'new_name';
3454 $_POST['description'] = 'new_description';
3455 $result = api_account_update_profile('json');
3456 // We can't use assertSelfUser() here because the user object is missing some properties.
3457 self::assertEquals($this->selfUser['id'], $result['user']['cid']);
3458 self::assertEquals('DFRN', $result['user']['location']);
3459 self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3460 self::assertEquals('dfrn', $result['user']['network']);
3461 self::assertEquals('new_name', $result['user']['name']);
3462 self::assertEquals('new_description', $result['user']['description']);
3466 * Test the check_acl_input() function.
3470 public function testCheckAclInput()
3472 $result = check_acl_input('<aclstring>');
3473 // Where does this result come from?
3474 self::assertEquals(1, $result);
3478 * Test the check_acl_input() function with an empty ACL string.
3482 public function testCheckAclInputWithEmptyAclString()
3484 $result = check_acl_input(' ');
3485 self::assertFalse($result);
3489 * Test the save_media_to_database() function.
3493 public function testSaveMediaToDatabase()
3495 $this->markTestIncomplete();
3499 * Test the post_photo_item() function.
3503 public function testPostPhotoItem()
3505 $this->markTestIncomplete();
3509 * Test the prepare_photo_data() function.
3513 public function testPreparePhotoData()
3515 $this->markTestIncomplete();
3519 * Test the api_friendica_remoteauth() function.
3522 * @expectedException Friendica\Network\HTTPException\BadRequestException
3524 public function testApiFriendicaRemoteauth()
3526 api_friendica_remoteauth();
3530 * Test the api_friendica_remoteauth() function with an URL.
3533 * @expectedException Friendica\Network\HTTPException\BadRequestException
3535 public function testApiFriendicaRemoteauthWithUrl()
3537 $_GET['url'] = 'url';
3538 $_GET['c_url'] = 'url';
3539 api_friendica_remoteauth();
3543 * Test the api_friendica_remoteauth() function with a correct URL.
3547 public function testApiFriendicaRemoteauthWithCorrectUrl()
3549 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3550 $_GET['url'] = 'url';
3551 $_GET['c_url'] = $this->selfUser['nurl'];
3552 api_friendica_remoteauth();
3556 * Test the api_share_as_retweet() function.
3560 public function testApiShareAsRetweet()
3562 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3563 $result = api_share_as_retweet($item);
3564 self::assertFalse($result);
3568 * Test the api_share_as_retweet() function with a valid item.
3572 public function testApiShareAsRetweetWithValidItem()
3574 $this->markTestIncomplete();
3578 * Test the api_in_reply_to() function.
3582 public function testApiInReplyTo()
3584 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3585 self::assertArrayHasKey('status_id', $result);
3586 self::assertArrayHasKey('user_id', $result);
3587 self::assertArrayHasKey('status_id_str', $result);
3588 self::assertArrayHasKey('user_id_str', $result);
3589 self::assertArrayHasKey('screen_name', $result);
3593 * Test the api_in_reply_to() function with a valid item.
3597 public function testApiInReplyToWithValidItem()
3599 $this->markTestIncomplete();
3603 * Test the api_clean_plain_items() function.
3607 public function testApiCleanPlainItems()
3609 $_REQUEST['include_entities'] = 'true';
3610 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3611 self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3615 * Test the api_best_nickname() function.
3619 public function testApiBestNickname()
3622 $result = api_best_nickname($contacts);
3623 self::assertNull($result);
3627 * Test the api_best_nickname() function with contacts.
3631 public function testApiBestNicknameWithContacts()
3633 $this->markTestIncomplete();
3637 * Test the api_friendica_group_show() function.
3641 public function testApiFriendicaGroupShow()
3643 $this->markTestIncomplete();
3647 * Test the api_friendica_group_delete() function.
3651 public function testApiFriendicaGroupDelete()
3653 $this->markTestIncomplete();
3657 * Test the api_lists_destroy() function.
3661 public function testApiListsDestroy()
3663 $this->markTestIncomplete();
3667 * Test the group_create() function.
3671 public function testGroupCreate()
3673 $this->markTestIncomplete();
3677 * Test the api_friendica_group_create() function.
3681 public function testApiFriendicaGroupCreate()
3683 $this->markTestIncomplete();
3687 * Test the api_lists_create() function.
3691 public function testApiListsCreate()
3693 $this->markTestIncomplete();
3697 * Test the api_friendica_group_update() function.
3701 public function testApiFriendicaGroupUpdate()
3703 $this->markTestIncomplete();
3707 * Test the api_lists_update() function.
3711 public function testApiListsUpdate()
3713 $this->markTestIncomplete();
3717 * Test the api_friendica_activity() function.
3721 public function testApiFriendicaActivity()
3723 $this->markTestIncomplete();
3727 * Test the api_friendica_notification() function.
3730 * @expectedException Friendica\Network\HTTPException\BadRequestException
3732 public function testApiFriendicaNotification()
3734 api_friendica_notification('json');
3738 * Test the api_friendica_notification() function without an authenticated user.
3741 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3743 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3745 $_SESSION['authenticated'] = false;
3746 api_friendica_notification('json');
3750 * Test the api_friendica_notification() function with empty result
3754 public function testApiFriendicaNotificationWithEmptyResult()
3756 $this->app->argv = ['api', 'friendica', 'notification'];
3757 $this->app->argc = count($this->app->argv);
3758 $_SESSION['uid'] = 41;
3759 $result = api_friendica_notification('json');
3760 self::assertEquals(['note' => false], $result);
3764 * Test the api_friendica_notification() function with an XML result.
3768 public function testApiFriendicaNotificationWithXmlResult()
3770 $this->app->argv = ['api', 'friendica', 'notification'];
3771 $this->app->argc = count($this->app->argv);
3772 $result = api_friendica_notification('xml');
3773 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3775 <?xml version="1.0"?>
3777 <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"/>
3780 self::assertXmlStringEqualsXmlString($assertXml, $result);
3784 * Test the api_friendica_notification() function with an JSON result.
3788 public function testApiFriendicaNotificationWithJsonResult()
3790 $this->app->argv = ['api', 'friendica', 'notification'];
3791 $this->app->argc = count($this->app->argv);
3792 $result = json_encode(api_friendica_notification('json'));
3793 self::assertJson($result);
3797 * Test the api_friendica_notification_seen() function.
3801 public function testApiFriendicaNotificationSeen()
3803 $this->markTestIncomplete();
3807 * Test the api_friendica_direct_messages_setseen() function.
3811 public function testApiFriendicaDirectMessagesSetseen()
3813 $this->markTestIncomplete();
3817 * Test the api_friendica_direct_messages_search() function.
3821 public function testApiFriendicaDirectMessagesSearch()
3823 $this->markTestIncomplete();
3827 * Test the api_saved_searches_list() function.
3831 public function testApiSavedSearchesList()
3833 $result = api_saved_searches_list('json');
3834 self::assertEquals(1, $result['terms'][0]['id']);
3835 self::assertEquals(1, $result['terms'][0]['id_str']);
3836 self::assertEquals('Saved search', $result['terms'][0]['name']);
3837 self::assertEquals('Saved search', $result['terms'][0]['query']);