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()
55 /** @var IConfig $config */
56 $this->config = $this->dice->create(IConfig::class);
58 $this->config->set('system', 'url', 'http://localhost');
59 $this->config->set('system', 'hostname', 'localhost');
60 $this->config->set('system', 'worker_dont_fork', true);
63 $this->config->set('config', 'hostname', 'localhost');
64 $this->config->set('system', 'throttle_limit_day', 100);
65 $this->config->set('system', 'throttle_limit_week', 100);
66 $this->config->set('system', 'throttle_limit_month', 100);
67 $this->config->set('system', 'theme', 'system_theme');
71 $this->app = DI::app();
74 $this->app->argv = ['home'];
76 // User data that the test database is populated with
79 'name' => 'Self contact',
80 'nick' => 'selfcontact',
81 'nurl' => 'http://localhost/profile/selfcontact'
85 'name' => 'Friend contact',
86 'nick' => 'friendcontact',
87 'nurl' => 'http://localhost/profile/friendcontact'
91 'name' => 'othercontact',
92 'nick' => 'othercontact',
93 'nurl' => 'http://localhost/profile/othercontact'
96 // User ID that we know is not in the database
97 $this->wrongUserId = 666;
99 DI::session()->start();
101 // Most API require login so we force the session
104 'authenticated' => true,
105 'uid' => $this->selfUser['id']
114 * Assert that an user array contains expected keys.
116 * @param array $user User array
120 private function assertSelfUser(array $user)
122 $this->assertEquals($this->selfUser['id'], $user['uid']);
123 $this->assertEquals($this->selfUser['id'], $user['cid']);
124 $this->assertEquals(1, $user['self']);
125 $this->assertEquals('DFRN', $user['location']);
126 $this->assertEquals($this->selfUser['name'], $user['name']);
127 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
128 $this->assertEquals('dfrn', $user['network']);
129 $this->assertTrue($user['verified']);
133 * Assert that an user array contains expected keys.
135 * @param array $user User array
139 private function assertOtherUser(array $user)
141 $this->assertEquals($this->otherUser['id'], $user['id']);
142 $this->assertEquals($this->otherUser['id'], $user['id_str']);
143 $this->assertEquals(0, $user['self']);
144 $this->assertEquals($this->otherUser['name'], $user['name']);
145 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
146 $this->assertFalse($user['verified']);
150 * Assert that a status array contains expected keys.
152 * @param array $status Status array
156 private function assertStatus(array $status)
158 $this->assertInternalType('string', $status['text']);
159 $this->assertInternalType('int', $status['id']);
160 // We could probably do more checks here.
164 * Assert that a list array contains expected keys.
166 * @param array $list List array
170 private function assertList(array $list)
172 $this->assertInternalType('string', $list['name']);
173 $this->assertInternalType('int', $list['id']);
174 $this->assertInternalType('string', $list['id_str']);
175 $this->assertContains($list['mode'], ['public', 'private']);
176 // We could probably do more checks here.
180 * Assert that the string is XML and contain the root element.
182 * @param string $result XML string
183 * @param string $root_element Root element name
187 private function assertXml($result, $root_element)
189 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
190 $this->assertContains('<' . $root_element, $result);
191 // We could probably do more checks here.
195 * Get the path to a temporary empty PNG image.
197 * @return string Path
199 private function getTempImage()
201 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
205 // Empty 1x1 px PNG image
206 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
214 * Test the api_user() function.
218 public function testApiUser()
220 $this->assertEquals($this->selfUser['id'], api_user());
224 * Test the api_user() function with an unallowed user.
228 public function testApiUserWithUnallowedUser()
230 $_SESSION = ['allow_api' => false];
231 $this->assertEquals(false, api_user());
235 * Test the api_source() function.
239 public function testApiSource()
241 $this->assertEquals('api', api_source());
245 * Test the api_source() function with a Twidere user agent.
249 public function testApiSourceWithTwidere()
251 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
252 $this->assertEquals('Twidere', api_source());
256 * Test the api_source() function with a GET parameter.
260 public function testApiSourceWithGet()
262 $_GET['source'] = 'source_name';
263 $this->assertEquals('source_name', api_source());
267 * Test the api_date() function.
271 public function testApiDate()
273 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
277 * Test the api_register_func() function.
281 public function testApiRegisterFunc()
293 $this->assertTrue($API['api_path']['auth']);
294 $this->assertEquals('method', $API['api_path']['method']);
295 $this->assertTrue(is_callable($API['api_path']['func']));
299 * Test the api_login() function without any login.
302 * @runInSeparateProcess
303 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
305 public function testApiLoginWithoutLogin()
307 api_login($this->app);
311 * Test the api_login() function with a bad login.
314 * @runInSeparateProcess
315 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
317 public function testApiLoginWithBadLogin()
319 $_SERVER['PHP_AUTH_USER'] = 'user@server';
320 api_login($this->app);
324 * Test the api_login() function with oAuth.
328 public function testApiLoginWithOauth()
330 $this->markTestIncomplete('Can we test this easily?');
334 * Test the api_login() function with authentication provided by an addon.
338 public function testApiLoginWithAddonAuth()
340 $this->markTestIncomplete('Can we test this easily?');
344 * Test the api_login() function with a correct login.
347 * @runInSeparateProcess
349 public function testApiLoginWithCorrectLogin()
351 $_SERVER['PHP_AUTH_USER'] = 'Test user';
352 $_SERVER['PHP_AUTH_PW'] = 'password';
353 api_login($this->app);
357 * Test the api_login() function with a remote user.
360 * @runInSeparateProcess
361 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
363 public function testApiLoginWithRemoteUser()
365 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
366 api_login($this->app);
370 * Test the api_check_method() function.
374 public function testApiCheckMethod()
376 $this->assertFalse(api_check_method('method'));
380 * Test the api_check_method() function with a correct method.
384 public function testApiCheckMethodWithCorrectMethod()
386 $_SERVER['REQUEST_METHOD'] = 'method';
387 $this->assertTrue(api_check_method('method'));
391 * Test the api_check_method() function with a wildcard.
395 public function testApiCheckMethodWithWildcard()
397 $this->assertTrue(api_check_method('*'));
401 * Test the api_call() function.
404 * @runInSeparateProcess
406 public function testApiCall()
410 'method' => 'method',
411 'func' => function () {
412 return ['data' => ['some_data']];
415 $_SERVER['REQUEST_METHOD'] = 'method';
416 $_SERVER['QUERY_STRING'] = 'q=api_path';
417 $_GET['callback'] = 'callback_name';
419 $args = DI::args()->determine($_SERVER, $_GET);
422 'callback_name(["some_data"])',
423 api_call($this->app, $args)
428 * Test the api_call() function with the profiled enabled.
431 * @runInSeparateProcess
433 public function testApiCallWithProfiler()
437 'method' => 'method',
438 'func' => function () {
439 return ['data' => ['some_data']];
443 $_SERVER['REQUEST_METHOD'] = 'method';
444 $_SERVER['QUERY_STRING'] = 'q=api_path';
446 $args = DI::args()->determine($_SERVER, $_GET);
448 $this->config->set('system', 'profiler', true);
449 $this->config->set('rendertime', 'callstack', true);
450 $this->app->callstack = [
451 'database' => ['some_function' => 200],
452 'database_write' => ['some_function' => 200],
453 'cache' => ['some_function' => 200],
454 'cache_write' => ['some_function' => 200],
455 'network' => ['some_function' => 200]
460 api_call($this->app, $args)
465 * Test the api_call() function without any result.
468 * @runInSeparateProcess
470 public function testApiCallWithNoResult()
474 'method' => 'method',
475 'func' => function () {
479 $_SERVER['REQUEST_METHOD'] = 'method';
480 $_SERVER['QUERY_STRING'] = 'q=api_path';
482 $args = DI::args()->determine($_SERVER, $_GET);
485 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
486 api_call($this->app, $args)
491 * Test the api_call() function with an unimplemented API.
494 * @runInSeparateProcess
496 public function testApiCallWithUninplementedApi()
499 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
505 * Test the api_call() function with a JSON result.
508 * @runInSeparateProcess
510 public function testApiCallWithJson()
514 'method' => 'method',
515 'func' => function () {
516 return ['data' => ['some_data']];
519 $_SERVER['REQUEST_METHOD'] = 'method';
520 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
522 $args = DI::args()->determine($_SERVER, $_GET);
526 api_call($this->app, $args)
531 * Test the api_call() function with an XML result.
534 * @runInSeparateProcess
536 public function testApiCallWithXml()
540 'method' => 'method',
541 'func' => function () {
545 $_SERVER['REQUEST_METHOD'] = 'method';
546 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
548 $args = DI::args()->determine($_SERVER, $_GET);
552 api_call($this->app, $args)
557 * Test the api_call() function with an RSS result.
560 * @runInSeparateProcess
562 public function testApiCallWithRss()
566 'method' => 'method',
567 'func' => function () {
571 $_SERVER['REQUEST_METHOD'] = 'method';
572 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
574 $args = DI::args()->determine($_SERVER, $_GET);
577 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
579 api_call($this->app, $args)
584 * Test the api_call() function with an Atom result.
587 * @runInSeparateProcess
589 public function testApiCallWithAtom()
593 'method' => 'method',
594 'func' => function () {
598 $_SERVER['REQUEST_METHOD'] = 'method';
599 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
601 $args = DI::args()->determine($_SERVER, $_GET);
604 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
606 api_call($this->app, $args)
611 * Test the api_call() function with an unallowed method.
614 * @runInSeparateProcess
616 public function testApiCallWithWrongMethod()
619 $API['api_path'] = ['method' => 'method'];
621 $_SERVER['QUERY_STRING'] = 'q=api_path';
623 $args = DI::args()->determine($_SERVER, $_GET);
626 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
627 api_call($this->app, $args)
632 * Test the api_call() function with an unauthorized user.
635 * @runInSeparateProcess
637 public function testApiCallWithWrongAuth()
641 'method' => 'method',
644 $_SESSION['authenticated'] = false;
645 $_SERVER['REQUEST_METHOD'] = 'method';
646 $_SERVER['QUERY_STRING'] = 'q=api_path';
648 $args = DI::args()->determine($_SERVER, $_GET);
651 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
652 api_call($this->app, $args)
657 * Test the api_error() function with a JSON result.
660 * @runInSeparateProcess
662 public function testApiErrorWithJson()
665 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
666 api_error('json', new HTTPException\OKException('error_message'), DI::args())
671 * Test the api_error() function with an XML result.
674 * @runInSeparateProcess
676 public function testApiErrorWithXml()
679 '<?xml version="1.0"?>' . "\n" .
680 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
681 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
682 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
683 ' <error>error_message</error>' . "\n" .
684 ' <code>200 OK</code>' . "\n" .
685 ' <request/>' . "\n" .
687 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
692 * Test the api_error() function with an RSS result.
695 * @runInSeparateProcess
697 public function testApiErrorWithRss()
700 '<?xml version="1.0"?>' . "\n" .
701 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
702 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
703 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
704 ' <error>error_message</error>' . "\n" .
705 ' <code>200 OK</code>' . "\n" .
706 ' <request/>' . "\n" .
708 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
713 * Test the api_error() function with an Atom result.
716 * @runInSeparateProcess
718 public function testApiErrorWithAtom()
721 '<?xml version="1.0"?>' . "\n" .
722 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
723 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
724 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
725 ' <error>error_message</error>' . "\n" .
726 ' <code>200 OK</code>' . "\n" .
727 ' <request/>' . "\n" .
729 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
734 * Test the api_rss_extra() function.
738 public function testApiRssExtra()
740 $user_info = ['url' => 'user_url', 'lang' => 'en'];
741 $result = api_rss_extra($this->app, [], $user_info);
742 $this->assertEquals($user_info, $result['$user']);
743 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
744 $this->assertArrayHasKey('self', $result['$rss']);
745 $this->assertArrayHasKey('base', $result['$rss']);
746 $this->assertArrayHasKey('updated', $result['$rss']);
747 $this->assertArrayHasKey('atom_updated', $result['$rss']);
748 $this->assertArrayHasKey('language', $result['$rss']);
749 $this->assertArrayHasKey('logo', $result['$rss']);
753 * Test the api_rss_extra() function without any user info.
757 public function testApiRssExtraWithoutUserInfo()
759 $result = api_rss_extra($this->app, [], null);
760 $this->assertInternalType('array', $result['$user']);
761 $this->assertArrayHasKey('alternate', $result['$rss']);
762 $this->assertArrayHasKey('self', $result['$rss']);
763 $this->assertArrayHasKey('base', $result['$rss']);
764 $this->assertArrayHasKey('updated', $result['$rss']);
765 $this->assertArrayHasKey('atom_updated', $result['$rss']);
766 $this->assertArrayHasKey('language', $result['$rss']);
767 $this->assertArrayHasKey('logo', $result['$rss']);
771 * Test the api_unique_id_to_nurl() function.
775 public function testApiUniqueIdToNurl()
777 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
781 * Test the api_unique_id_to_nurl() function with a correct ID.
785 public function testApiUniqueIdToNurlWithCorrectId()
787 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
791 * Test the api_get_user() function.
795 public function testApiGetUser()
797 $user = api_get_user($this->app);
798 $this->assertSelfUser($user);
799 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
800 $this->assertEquals('6fdbe8', $user['profile_link_color']);
801 $this->assertEquals('ededed', $user['profile_background_color']);
805 * Test the api_get_user() function with a Frio schema.
809 public function testApiGetUserWithFrioSchema()
811 $pConfig = $this->dice->create(IPConfig::class);
812 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
813 $user = api_get_user($this->app);
814 $this->assertSelfUser($user);
815 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
816 $this->assertEquals('6fdbe8', $user['profile_link_color']);
817 $this->assertEquals('ededed', $user['profile_background_color']);
821 * Test the api_get_user() function with an empty Frio schema.
825 public function testApiGetUserWithEmptyFrioSchema()
827 $pConfig = $this->dice->create(IPConfig::class);
828 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
829 $user = api_get_user($this->app);
830 $this->assertSelfUser($user);
831 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
832 $this->assertEquals('6fdbe8', $user['profile_link_color']);
833 $this->assertEquals('ededed', $user['profile_background_color']);
837 * Test the api_get_user() function with a custom Frio schema.
841 public function testApiGetUserWithCustomFrioSchema()
843 $pConfig = $this->dice->create(IPConfig::class);
844 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
845 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
846 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
847 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
848 $user = api_get_user($this->app);
849 $this->assertSelfUser($user);
850 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
851 $this->assertEquals('123456', $user['profile_link_color']);
852 $this->assertEquals('123456', $user['profile_background_color']);
856 * Test the api_get_user() function with an user that is not allowed to use the API.
859 * @runInSeparateProcess
861 public function testApiGetUserWithoutApiUser()
863 $_SERVER['PHP_AUTH_USER'] = 'Test user';
864 $_SERVER['PHP_AUTH_PW'] = 'password';
865 $_SESSION['allow_api'] = false;
866 $this->assertFalse(api_get_user($this->app));
870 * Test the api_get_user() function with an user ID in a GET parameter.
874 public function testApiGetUserWithGetId()
876 $_GET['user_id'] = $this->otherUser['id'];
877 $this->assertOtherUser(api_get_user($this->app));
881 * Test the api_get_user() function with a wrong user ID in a GET parameter.
884 * @expectedException Friendica\Network\HTTPException\BadRequestException
886 public function testApiGetUserWithWrongGetId()
888 $_GET['user_id'] = $this->wrongUserId;
889 $this->assertOtherUser(api_get_user($this->app));
893 * Test the api_get_user() function with an user name in a GET parameter.
897 public function testApiGetUserWithGetName()
899 $_GET['screen_name'] = $this->selfUser['nick'];
900 $this->assertSelfUser(api_get_user($this->app));
904 * Test the api_get_user() function with a profile URL in a GET parameter.
908 public function testApiGetUserWithGetUrl()
910 $_GET['profileurl'] = $this->selfUser['nurl'];
911 $this->assertSelfUser(api_get_user($this->app));
915 * Test the api_get_user() function with an user ID in the API path.
919 public function testApiGetUserWithNumericCalledApi()
922 $called_api = ['api_path'];
923 $this->app->argv[1] = $this->otherUser['id'] . '.json';
924 $this->assertOtherUser(api_get_user($this->app));
928 * Test the api_get_user() function with the $called_api global variable.
932 public function testApiGetUserWithCalledApi()
935 $called_api = ['api', 'api_path'];
936 $this->assertSelfUser(api_get_user($this->app));
940 * Test the api_get_user() function with a valid user.
944 public function testApiGetUserWithCorrectUser()
946 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
950 * Test the api_get_user() function with a wrong user ID.
953 * @expectedException Friendica\Network\HTTPException\BadRequestException
955 public function testApiGetUserWithWrongUser()
957 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
961 * Test the api_get_user() function with a 0 user ID.
965 public function testApiGetUserWithZeroUser()
967 $this->assertSelfUser(api_get_user($this->app, 0));
971 * Test the api_item_get_user() function.
975 public function testApiItemGetUser()
977 $users = api_item_get_user($this->app, []);
978 $this->assertSelfUser($users[0]);
982 * Test the api_item_get_user() function with a different item parent.
986 public function testApiItemGetUserWithDifferentParent()
988 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
989 $this->assertSelfUser($users[0]);
990 $this->assertEquals($users[0], $users[1]);
994 * Test the api_walk_recursive() function.
998 public function testApiWalkRecursive()
1001 $this->assertEquals(
1006 // Should we test this with a callback that actually does something?
1014 * Test the api_walk_recursive() function with an array.
1018 public function testApiWalkRecursiveWithArray()
1020 $array = [['item1'], ['item2']];
1021 $this->assertEquals(
1026 // Should we test this with a callback that actually does something?
1034 * Test the api_reformat_xml() function.
1038 public function testApiReformatXml()
1042 $this->assertTrue(api_reformat_xml($item, $key));
1043 $this->assertEquals('true', $item);
1047 * Test the api_reformat_xml() function with a statusnet_api key.
1051 public function testApiReformatXmlWithStatusnetKey()
1054 $key = 'statusnet_api';
1055 $this->assertTrue(api_reformat_xml($item, $key));
1056 $this->assertEquals('statusnet:api', $key);
1060 * Test the api_reformat_xml() function with a friendica_api key.
1064 public function testApiReformatXmlWithFriendicaKey()
1067 $key = 'friendica_api';
1068 $this->assertTrue(api_reformat_xml($item, $key));
1069 $this->assertEquals('friendica:api', $key);
1073 * Test the api_create_xml() function.
1077 public function testApiCreateXml()
1079 $this->assertEquals(
1080 '<?xml version="1.0"?>' . "\n" .
1081 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1082 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1083 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1084 ' <data>some_data</data>' . "\n" .
1085 '</root_element>' . "\n",
1086 api_create_xml(['data' => ['some_data']], 'root_element')
1091 * Test the api_create_xml() function without any XML namespace.
1095 public function testApiCreateXmlWithoutNamespaces()
1097 $this->assertEquals(
1098 '<?xml version="1.0"?>' . "\n" .
1100 ' <data>some_data</data>' . "\n" .
1102 api_create_xml(['data' => ['some_data']], 'ok')
1107 * Test the api_format_data() function.
1111 public function testApiFormatData()
1113 $data = ['some_data'];
1114 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1118 * Test the api_format_data() function with an XML result.
1122 public function testApiFormatDataWithXml()
1124 $this->assertEquals(
1125 '<?xml version="1.0"?>' . "\n" .
1126 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1127 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1128 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1129 ' <data>some_data</data>' . "\n" .
1130 '</root_element>' . "\n",
1131 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1136 * Test the api_account_verify_credentials() function.
1140 public function testApiAccountVerifyCredentials()
1142 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1146 * Test the api_account_verify_credentials() function without an authenticated user.
1149 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1151 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1153 $_SESSION['authenticated'] = false;
1154 api_account_verify_credentials('json');
1158 * Test the requestdata() function.
1162 public function testRequestdata()
1164 $this->assertNull(requestdata('variable_name'));
1168 * Test the requestdata() function with a POST parameter.
1172 public function testRequestdataWithPost()
1174 $_POST['variable_name'] = 'variable_value';
1175 $this->assertEquals('variable_value', requestdata('variable_name'));
1179 * Test the requestdata() function with a GET parameter.
1183 public function testRequestdataWithGet()
1185 $_GET['variable_name'] = 'variable_value';
1186 $this->assertEquals('variable_value', requestdata('variable_name'));
1190 * Test the api_statuses_mediap() function.
1194 public function testApiStatusesMediap()
1196 $this->app->argc = 2;
1204 'tmp_name' => $this->getTempImage(),
1205 'name' => 'spacer.png',
1206 'type' => 'image/png'
1209 $_GET['status'] = '<b>Status content</b>';
1211 $result = api_statuses_mediap('json');
1212 $this->assertStatus($result['status']);
1216 * Test the api_statuses_mediap() function without an authenticated user.
1219 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1221 public function testApiStatusesMediapWithoutAuthenticatedUser()
1223 $_SESSION['authenticated'] = false;
1224 api_statuses_mediap('json');
1228 * Test the api_statuses_update() function.
1232 public function testApiStatusesUpdate()
1234 $_GET['status'] = 'Status content #friendica';
1235 $_GET['in_reply_to_status_id'] = -1;
1244 'tmp_name' => $this->getTempImage(),
1245 'name' => 'spacer.png',
1246 'type' => 'image/png'
1250 $result = api_statuses_update('json');
1251 $this->assertStatus($result['status']);
1255 * Test the api_statuses_update() function with an HTML status.
1259 public function testApiStatusesUpdateWithHtml()
1261 $_GET['htmlstatus'] = '<b>Status content</b>';
1263 $result = api_statuses_update('json');
1264 $this->assertStatus($result['status']);
1268 * Test the api_statuses_update() function without an authenticated user.
1271 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1273 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1275 $_SESSION['authenticated'] = false;
1276 api_statuses_update('json');
1280 * Test the api_statuses_update() function with a parent status.
1284 public function testApiStatusesUpdateWithParent()
1286 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1290 * Test the api_statuses_update() function with a media_ids parameter.
1294 public function testApiStatusesUpdateWithMediaIds()
1296 $this->markTestIncomplete();
1300 * Test the api_statuses_update() function with the throttle limit reached.
1304 public function testApiStatusesUpdateWithDayThrottleReached()
1306 $this->markTestIncomplete();
1310 * Test the api_media_upload() function.
1313 * @expectedException Friendica\Network\HTTPException\BadRequestException
1315 public function testApiMediaUpload()
1321 * Test the api_media_upload() function without an authenticated user.
1324 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1326 public function testApiMediaUploadWithoutAuthenticatedUser()
1328 $_SESSION['authenticated'] = false;
1333 * Test the api_media_upload() function with an invalid uploaded media.
1336 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1338 public function testApiMediaUploadWithMedia()
1343 'tmp_name' => 'tmp_name'
1350 * Test the api_media_upload() function with an valid uploaded media.
1354 public function testApiMediaUploadWithValidMedia()
1362 'tmp_name' => $this->getTempImage(),
1363 'name' => 'spacer.png',
1364 'type' => 'image/png'
1370 $result = api_media_upload();
1371 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1372 $this->assertEquals(1, $result['media']['image']['w']);
1373 $this->assertEquals(1, $result['media']['image']['h']);
1374 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1378 * Test the api_status_show() function.
1380 public function testApiStatusShowWithJson()
1382 $result = api_status_show('json', 1);
1383 $this->assertStatus($result['status']);
1387 * Test the api_status_show() function with an XML result.
1389 public function testApiStatusShowWithXml()
1391 $result = api_status_show('xml', 1);
1392 $this->assertXml($result, 'statuses');
1396 * Test the api_get_last_status() function
1398 public function testApiGetLastStatus()
1400 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1402 $this->assertNotNull($item);
1406 * Test the api_users_show() function.
1410 public function testApiUsersShow()
1412 $result = api_users_show('json');
1413 // We can't use assertSelfUser() here because the user object is missing some properties.
1414 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1415 $this->assertEquals('DFRN', $result['user']['location']);
1416 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1417 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1418 $this->assertEquals('dfrn', $result['user']['network']);
1419 $this->assertTrue($result['user']['verified']);
1423 * Test the api_users_show() function with an XML result.
1427 public function testApiUsersShowWithXml()
1429 $result = api_users_show('xml');
1430 $this->assertXml($result, 'statuses');
1434 * Test the api_users_search() function.
1438 public function testApiUsersSearch()
1440 $_GET['q'] = 'othercontact';
1441 $result = api_users_search('json');
1442 $this->assertOtherUser($result['users'][0]);
1446 * Test the api_users_search() function with an XML result.
1450 public function testApiUsersSearchWithXml()
1452 $_GET['q'] = 'othercontact';
1453 $result = api_users_search('xml');
1454 $this->assertXml($result, 'users');
1458 * Test the api_users_search() function without a GET q parameter.
1461 * @expectedException Friendica\Network\HTTPException\BadRequestException
1463 public function testApiUsersSearchWithoutQuery()
1465 api_users_search('json');
1469 * Test the api_users_lookup() function.
1472 * @expectedException Friendica\Network\HTTPException\NotFoundException
1474 public function testApiUsersLookup()
1476 api_users_lookup('json');
1480 * Test the api_users_lookup() function with an user ID.
1484 public function testApiUsersLookupWithUserId()
1486 $_REQUEST['user_id'] = $this->otherUser['id'];
1487 $result = api_users_lookup('json');
1488 $this->assertOtherUser($result['users'][0]);
1492 * Test the api_search() function.
1496 public function testApiSearch()
1498 $_REQUEST['q'] = 'reply';
1499 $_REQUEST['max_id'] = 10;
1500 $result = api_search('json');
1501 foreach ($result['status'] as $status) {
1502 $this->assertStatus($status);
1503 $this->assertContains('reply', $status['text'], null, true);
1508 * Test the api_search() function a count parameter.
1512 public function testApiSearchWithCount()
1514 $_REQUEST['q'] = 'reply';
1515 $_REQUEST['count'] = 20;
1516 $result = api_search('json');
1517 foreach ($result['status'] as $status) {
1518 $this->assertStatus($status);
1519 $this->assertContains('reply', $status['text'], null, true);
1524 * Test the api_search() function with an rpp parameter.
1528 public function testApiSearchWithRpp()
1530 $_REQUEST['q'] = 'reply';
1531 $_REQUEST['rpp'] = 20;
1532 $result = api_search('json');
1533 foreach ($result['status'] as $status) {
1534 $this->assertStatus($status);
1535 $this->assertContains('reply', $status['text'], null, true);
1540 * Test the api_search() function with an q parameter contains hashtag.
1544 public function testApiSearchWithHashtag()
1546 $_REQUEST['q'] = '%23friendica';
1547 $result = api_search('json');
1548 foreach ($result['status'] as $status) {
1549 $this->assertStatus($status);
1550 $this->assertContains('#friendica', $status['text'], null, true);
1555 * Test the api_search() function with an exclude_replies parameter.
1559 public function testApiSearchWithExcludeReplies()
1561 $_REQUEST['max_id'] = 10;
1562 $_REQUEST['exclude_replies'] = true;
1563 $_REQUEST['q'] = 'friendica';
1564 $result = api_search('json');
1565 foreach ($result['status'] as $status) {
1566 $this->assertStatus($status);
1571 * Test the api_search() function without an authenticated user.
1574 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1576 public function testApiSearchWithUnallowedUser()
1578 $_SESSION['allow_api'] = false;
1579 $_GET['screen_name'] = $this->selfUser['nick'];
1584 * Test the api_search() function without any GET query parameter.
1587 * @expectedException Friendica\Network\HTTPException\BadRequestException
1589 public function testApiSearchWithoutQuery()
1595 * Test the api_statuses_home_timeline() function.
1599 public function testApiStatusesHomeTimeline()
1601 $_REQUEST['max_id'] = 10;
1602 $_REQUEST['exclude_replies'] = true;
1603 $_REQUEST['conversation_id'] = 1;
1604 $result = api_statuses_home_timeline('json');
1605 $this->assertNotEmpty($result['status']);
1606 foreach ($result['status'] as $status) {
1607 $this->assertStatus($status);
1612 * Test the api_statuses_home_timeline() function with a negative page parameter.
1616 public function testApiStatusesHomeTimelineWithNegativePage()
1618 $_REQUEST['page'] = -2;
1619 $result = api_statuses_home_timeline('json');
1620 $this->assertNotEmpty($result['status']);
1621 foreach ($result['status'] as $status) {
1622 $this->assertStatus($status);
1627 * Test the api_statuses_home_timeline() with an unallowed user.
1630 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1632 public function testApiStatusesHomeTimelineWithUnallowedUser()
1634 $_SESSION['allow_api'] = false;
1635 $_GET['screen_name'] = $this->selfUser['nick'];
1636 api_statuses_home_timeline('json');
1640 * Test the api_statuses_home_timeline() function with an RSS result.
1644 public function testApiStatusesHomeTimelineWithRss()
1646 $result = api_statuses_home_timeline('rss');
1647 $this->assertXml($result, 'statuses');
1651 * Test the api_statuses_public_timeline() function.
1655 public function testApiStatusesPublicTimeline()
1657 $_REQUEST['max_id'] = 10;
1658 $_REQUEST['conversation_id'] = 1;
1659 $result = api_statuses_public_timeline('json');
1660 $this->assertNotEmpty($result['status']);
1661 foreach ($result['status'] as $status) {
1662 $this->assertStatus($status);
1667 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1671 public function testApiStatusesPublicTimelineWithExcludeReplies()
1673 $_REQUEST['max_id'] = 10;
1674 $_REQUEST['exclude_replies'] = true;
1675 $result = api_statuses_public_timeline('json');
1676 $this->assertNotEmpty($result['status']);
1677 foreach ($result['status'] as $status) {
1678 $this->assertStatus($status);
1683 * Test the api_statuses_public_timeline() function with a negative page parameter.
1687 public function testApiStatusesPublicTimelineWithNegativePage()
1689 $_REQUEST['page'] = -2;
1690 $result = api_statuses_public_timeline('json');
1691 $this->assertNotEmpty($result['status']);
1692 foreach ($result['status'] as $status) {
1693 $this->assertStatus($status);
1698 * Test the api_statuses_public_timeline() function with an unallowed user.
1701 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1703 public function testApiStatusesPublicTimelineWithUnallowedUser()
1705 $_SESSION['allow_api'] = false;
1706 $_GET['screen_name'] = $this->selfUser['nick'];
1707 api_statuses_public_timeline('json');
1711 * Test the api_statuses_public_timeline() function with an RSS result.
1715 public function testApiStatusesPublicTimelineWithRss()
1717 $result = api_statuses_public_timeline('rss');
1718 $this->assertXml($result, 'statuses');
1722 * Test the api_statuses_networkpublic_timeline() function.
1726 public function testApiStatusesNetworkpublicTimeline()
1728 $_REQUEST['max_id'] = 10;
1729 $result = api_statuses_networkpublic_timeline('json');
1730 $this->assertNotEmpty($result['status']);
1731 foreach ($result['status'] as $status) {
1732 $this->assertStatus($status);
1737 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1741 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1743 $_REQUEST['page'] = -2;
1744 $result = api_statuses_networkpublic_timeline('json');
1745 $this->assertNotEmpty($result['status']);
1746 foreach ($result['status'] as $status) {
1747 $this->assertStatus($status);
1752 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1755 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1757 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1759 $_SESSION['allow_api'] = false;
1760 $_GET['screen_name'] = $this->selfUser['nick'];
1761 api_statuses_networkpublic_timeline('json');
1765 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1769 public function testApiStatusesNetworkpublicTimelineWithRss()
1771 $result = api_statuses_networkpublic_timeline('rss');
1772 $this->assertXml($result, 'statuses');
1776 * Test the api_statuses_show() function.
1779 * @expectedException Friendica\Network\HTTPException\BadRequestException
1781 public function testApiStatusesShow()
1783 api_statuses_show('json');
1787 * Test the api_statuses_show() function with an ID.
1791 public function testApiStatusesShowWithId()
1793 $this->app->argv[3] = 1;
1794 $result = api_statuses_show('json');
1795 $this->assertStatus($result['status']);
1799 * Test the api_statuses_show() function with the conversation parameter.
1803 public function testApiStatusesShowWithConversation()
1805 $this->app->argv[3] = 1;
1806 $_REQUEST['conversation'] = 1;
1807 $result = api_statuses_show('json');
1808 $this->assertNotEmpty($result['status']);
1809 foreach ($result['status'] as $status) {
1810 $this->assertStatus($status);
1815 * Test the api_statuses_show() function with an unallowed user.
1818 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1820 public function testApiStatusesShowWithUnallowedUser()
1822 $_SESSION['allow_api'] = false;
1823 $_GET['screen_name'] = $this->selfUser['nick'];
1824 api_statuses_show('json');
1828 * Test the api_conversation_show() function.
1831 * @expectedException Friendica\Network\HTTPException\BadRequestException
1833 public function testApiConversationShow()
1835 api_conversation_show('json');
1839 * Test the api_conversation_show() function with an ID.
1843 public function testApiConversationShowWithId()
1845 $this->app->argv[3] = 1;
1846 $_REQUEST['max_id'] = 10;
1847 $_REQUEST['page'] = -2;
1848 $result = api_conversation_show('json');
1849 $this->assertNotEmpty($result['status']);
1850 foreach ($result['status'] as $status) {
1851 $this->assertStatus($status);
1856 * Test the api_conversation_show() function with an unallowed user.
1859 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1861 public function testApiConversationShowWithUnallowedUser()
1863 $_SESSION['allow_api'] = false;
1864 $_GET['screen_name'] = $this->selfUser['nick'];
1865 api_conversation_show('json');
1869 * Test the api_statuses_repeat() function.
1872 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1874 public function testApiStatusesRepeat()
1876 api_statuses_repeat('json');
1880 * Test the api_statuses_repeat() function without an authenticated user.
1883 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1885 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1887 $_SESSION['authenticated'] = false;
1888 api_statuses_repeat('json');
1892 * Test the api_statuses_repeat() function with an ID.
1896 public function testApiStatusesRepeatWithId()
1898 $this->app->argv[3] = 1;
1899 $result = api_statuses_repeat('json');
1900 $this->assertStatus($result['status']);
1902 // Also test with a shared status
1903 $this->app->argv[3] = 5;
1904 $result = api_statuses_repeat('json');
1905 $this->assertStatus($result['status']);
1909 * Test the api_statuses_destroy() function.
1912 * @expectedException Friendica\Network\HTTPException\BadRequestException
1914 public function testApiStatusesDestroy()
1916 api_statuses_destroy('json');
1920 * Test the api_statuses_destroy() function without an authenticated user.
1923 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1925 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1927 $_SESSION['authenticated'] = false;
1928 api_statuses_destroy('json');
1932 * Test the api_statuses_destroy() function with an ID.
1936 public function testApiStatusesDestroyWithId()
1938 $this->app->argv[3] = 1;
1939 $result = api_statuses_destroy('json');
1940 $this->assertStatus($result['status']);
1944 * Test the api_statuses_mentions() function.
1948 public function testApiStatusesMentions()
1950 $this->app->user = ['nickname' => $this->selfUser['nick']];
1951 $_REQUEST['max_id'] = 10;
1952 $result = api_statuses_mentions('json');
1953 $this->assertEmpty($result['status']);
1954 // We should test with mentions in the database.
1958 * Test the api_statuses_mentions() function with a negative page parameter.
1962 public function testApiStatusesMentionsWithNegativePage()
1964 $_REQUEST['page'] = -2;
1965 $result = api_statuses_mentions('json');
1966 $this->assertEmpty($result['status']);
1970 * Test the api_statuses_mentions() function with an unallowed user.
1973 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1975 public function testApiStatusesMentionsWithUnallowedUser()
1977 $_SESSION['allow_api'] = false;
1978 $_GET['screen_name'] = $this->selfUser['nick'];
1979 api_statuses_mentions('json');
1983 * Test the api_statuses_mentions() function with an RSS result.
1987 public function testApiStatusesMentionsWithRss()
1989 $result = api_statuses_mentions('rss');
1990 $this->assertXml($result, 'statuses');
1994 * Test the api_statuses_user_timeline() function.
1998 public function testApiStatusesUserTimeline()
2000 $_REQUEST['max_id'] = 10;
2001 $_REQUEST['exclude_replies'] = true;
2002 $_REQUEST['conversation_id'] = 1;
2003 $result = api_statuses_user_timeline('json');
2004 $this->assertNotEmpty($result['status']);
2005 foreach ($result['status'] as $status) {
2006 $this->assertStatus($status);
2011 * Test the api_statuses_user_timeline() function with a negative page parameter.
2015 public function testApiStatusesUserTimelineWithNegativePage()
2017 $_REQUEST['page'] = -2;
2018 $result = api_statuses_user_timeline('json');
2019 $this->assertNotEmpty($result['status']);
2020 foreach ($result['status'] as $status) {
2021 $this->assertStatus($status);
2026 * Test the api_statuses_user_timeline() function with an RSS result.
2030 public function testApiStatusesUserTimelineWithRss()
2032 $result = api_statuses_user_timeline('rss');
2033 $this->assertXml($result, 'statuses');
2037 * Test the api_statuses_user_timeline() function with an unallowed user.
2040 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2042 public function testApiStatusesUserTimelineWithUnallowedUser()
2044 $_SESSION['allow_api'] = false;
2045 $_GET['screen_name'] = $this->selfUser['nick'];
2046 api_statuses_user_timeline('json');
2050 * Test the api_favorites_create_destroy() function.
2053 * @expectedException Friendica\Network\HTTPException\BadRequestException
2055 public function testApiFavoritesCreateDestroy()
2057 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2058 $this->app->argc = count($this->app->argv);
2059 api_favorites_create_destroy('json');
2063 * Test the api_favorites_create_destroy() function with an invalid ID.
2066 * @expectedException Friendica\Network\HTTPException\BadRequestException
2068 public function testApiFavoritesCreateDestroyWithInvalidId()
2070 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2071 $this->app->argc = count($this->app->argv);
2072 api_favorites_create_destroy('json');
2076 * Test the api_favorites_create_destroy() function with an invalid action.
2079 * @expectedException Friendica\Network\HTTPException\BadRequestException
2081 public function testApiFavoritesCreateDestroyWithInvalidAction()
2083 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2084 $this->app->argc = count($this->app->argv);
2085 $_REQUEST['id'] = 1;
2086 api_favorites_create_destroy('json');
2090 * Test the api_favorites_create_destroy() function with the create action.
2094 public function testApiFavoritesCreateDestroyWithCreateAction()
2096 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2097 $this->app->argc = count($this->app->argv);
2098 $_REQUEST['id'] = 3;
2099 $result = api_favorites_create_destroy('json');
2100 $this->assertStatus($result['status']);
2104 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2108 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2110 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2111 $this->app->argc = count($this->app->argv);
2112 $_REQUEST['id'] = 3;
2113 $result = api_favorites_create_destroy('rss');
2114 $this->assertXml($result, 'status');
2118 * Test the api_favorites_create_destroy() function with the destroy action.
2122 public function testApiFavoritesCreateDestroyWithDestroyAction()
2124 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2125 $this->app->argc = count($this->app->argv);
2126 $_REQUEST['id'] = 3;
2127 $result = api_favorites_create_destroy('json');
2128 $this->assertStatus($result['status']);
2132 * Test the api_favorites_create_destroy() function without an authenticated user.
2135 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2137 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2139 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2140 $this->app->argc = count($this->app->argv);
2141 $_SESSION['authenticated'] = false;
2142 api_favorites_create_destroy('json');
2146 * Test the api_favorites() function.
2150 public function testApiFavorites()
2152 $_REQUEST['page'] = -1;
2153 $_REQUEST['max_id'] = 10;
2154 $result = api_favorites('json');
2155 foreach ($result['status'] as $status) {
2156 $this->assertStatus($status);
2161 * Test the api_favorites() function with an RSS result.
2165 public function testApiFavoritesWithRss()
2167 $result = api_favorites('rss');
2168 $this->assertXml($result, 'statuses');
2172 * Test the api_favorites() function with an unallowed user.
2175 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2177 public function testApiFavoritesWithUnallowedUser()
2179 $_SESSION['allow_api'] = false;
2180 $_GET['screen_name'] = $this->selfUser['nick'];
2181 api_favorites('json');
2185 * Test the api_format_messages() function.
2189 public function testApiFormatMessages()
2191 $result = api_format_messages(
2192 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2193 ['id' => 2, 'screen_name' => 'recipient_name'],
2194 ['id' => 3, 'screen_name' => 'sender_name']
2196 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2197 $this->assertEquals(1, $result['id']);
2198 $this->assertEquals(2, $result['recipient_id']);
2199 $this->assertEquals(3, $result['sender_id']);
2200 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2201 $this->assertEquals('sender_name', $result['sender_screen_name']);
2205 * Test the api_format_messages() function with HTML.
2209 public function testApiFormatMessagesWithHtmlText()
2211 $_GET['getText'] = 'html';
2212 $result = api_format_messages(
2213 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2214 ['id' => 2, 'screen_name' => 'recipient_name'],
2215 ['id' => 3, 'screen_name' => 'sender_name']
2217 $this->assertEquals('item_title', $result['title']);
2218 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2222 * Test the api_format_messages() function with plain text.
2226 public function testApiFormatMessagesWithPlainText()
2228 $_GET['getText'] = 'plain';
2229 $result = api_format_messages(
2230 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2231 ['id' => 2, 'screen_name' => 'recipient_name'],
2232 ['id' => 3, 'screen_name' => 'sender_name']
2234 $this->assertEquals('item_title', $result['title']);
2235 $this->assertEquals('item_body', $result['text']);
2239 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2243 public function testApiFormatMessagesWithoutUserObjects()
2245 $_GET['getUserObjects'] = 'false';
2246 $result = api_format_messages(
2247 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2248 ['id' => 2, 'screen_name' => 'recipient_name'],
2249 ['id' => 3, 'screen_name' => 'sender_name']
2251 $this->assertTrue(!isset($result['sender']));
2252 $this->assertTrue(!isset($result['recipient']));
2256 * Test the api_convert_item() function.
2260 public function testApiConvertItem()
2262 $result = api_convert_item(
2264 'network' => 'feed',
2265 'title' => 'item_title',
2266 // We need a long string to test that it is correctly cut
2267 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2268 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2269 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2270 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2271 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2272 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2273 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2274 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2275 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2276 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2277 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2278 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2279 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2280 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2281 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2282 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2283 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2284 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2285 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2286 'repellat officia illum quos impedit quam iste esse unde qui ' .
2287 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2288 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2289 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2290 'plink' => 'item_plink'
2293 $this->assertStringStartsWith('item_title', $result['text']);
2294 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2298 * Test the api_convert_item() function with an empty item body.
2302 public function testApiConvertItemWithoutBody()
2304 $result = api_convert_item(
2306 'network' => 'feed',
2307 'title' => 'item_title',
2309 'plink' => 'item_plink'
2312 $this->assertEquals('item_title', $result['text']);
2313 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2317 * Test the api_convert_item() function with the title in the body.
2321 public function testApiConvertItemWithTitleInBody()
2323 $result = api_convert_item(
2325 'title' => 'item_title',
2326 'body' => 'item_title item_body'
2329 $this->assertEquals('item_title item_body', $result['text']);
2330 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2334 * Test the api_get_attachments() function.
2338 public function testApiGetAttachments()
2341 $this->assertEmpty(api_get_attachments($body));
2345 * Test the api_get_attachments() function with an img tag.
2349 public function testApiGetAttachmentsWithImage()
2351 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2352 $this->assertInternalType('array', api_get_attachments($body));
2356 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2360 public function testApiGetAttachmentsWithImageAndAndStatus()
2362 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2363 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2364 $this->assertInternalType('array', api_get_attachments($body));
2368 * Test the api_get_entitities() function.
2372 public function testApiGetEntitities()
2375 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2379 * Test the api_get_entitities() function with the include_entities parameter.
2383 public function testApiGetEntititiesWithIncludeEntities()
2385 $_REQUEST['include_entities'] = 'true';
2387 $result = api_get_entitities($text, 'bbcode');
2388 $this->assertInternalType('array', $result['hashtags']);
2389 $this->assertInternalType('array', $result['symbols']);
2390 $this->assertInternalType('array', $result['urls']);
2391 $this->assertInternalType('array', $result['user_mentions']);
2395 * Test the api_format_items_embeded_images() function.
2399 public function testApiFormatItemsEmbededImages()
2401 $this->assertEquals(
2402 'text ' . DI::baseUrl() . '/display/item_guid',
2403 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2408 * Test the api_contactlink_to_array() function.
2412 public function testApiContactlinkToArray()
2414 $this->assertEquals(
2419 api_contactlink_to_array('text')
2424 * Test the api_contactlink_to_array() function with an URL.
2428 public function testApiContactlinkToArrayWithUrl()
2430 $this->assertEquals(
2432 'name' => ['link_text'],
2435 api_contactlink_to_array('text <a href="url">link_text</a>')
2440 * Test the api_format_items_activities() function.
2444 public function testApiFormatItemsActivities()
2446 $item = ['uid' => 0, 'uri' => ''];
2447 $result = api_format_items_activities($item);
2448 $this->assertArrayHasKey('like', $result);
2449 $this->assertArrayHasKey('dislike', $result);
2450 $this->assertArrayHasKey('attendyes', $result);
2451 $this->assertArrayHasKey('attendno', $result);
2452 $this->assertArrayHasKey('attendmaybe', $result);
2456 * Test the api_format_items_activities() function with an XML result.
2460 public function testApiFormatItemsActivitiesWithXml()
2462 $item = ['uid' => 0, 'uri' => ''];
2463 $result = api_format_items_activities($item, 'xml');
2464 $this->assertArrayHasKey('friendica:like', $result);
2465 $this->assertArrayHasKey('friendica:dislike', $result);
2466 $this->assertArrayHasKey('friendica:attendyes', $result);
2467 $this->assertArrayHasKey('friendica:attendno', $result);
2468 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2472 * Test the api_format_items() function.
2476 public function testApiFormatItems()
2480 'item_network' => 'item_network',
2486 'author-network' => Protocol::DFRN,
2487 'author-link' => 'http://localhost/profile/othercontact',
2491 $result = api_format_items($items, ['id' => 0], true);
2492 foreach ($result as $status) {
2493 $this->assertStatus($status);
2498 * Test the api_format_items() function with an XML result.
2502 public function testApiFormatItemsWithXml()
2510 'author-network' => Protocol::DFRN,
2511 'author-link' => 'http://localhost/profile/othercontact',
2515 $result = api_format_items($items, ['id' => 0], true, 'xml');
2516 foreach ($result as $status) {
2517 $this->assertStatus($status);
2522 * Test the api_format_items() function.
2526 public function testApiAccountRateLimitStatus()
2528 $result = api_account_rate_limit_status('json');
2529 $this->assertEquals(150, $result['hash']['remaining_hits']);
2530 $this->assertEquals(150, $result['hash']['hourly_limit']);
2531 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2535 * Test the api_format_items() function with an XML result.
2539 public function testApiAccountRateLimitStatusWithXml()
2541 $result = api_account_rate_limit_status('xml');
2542 $this->assertXml($result, 'hash');
2546 * Test the api_help_test() function.
2550 public function testApiHelpTest()
2552 $result = api_help_test('json');
2553 $this->assertEquals(['ok' => 'ok'], $result);
2557 * Test the api_help_test() function with an XML result.
2561 public function testApiHelpTestWithXml()
2563 $result = api_help_test('xml');
2564 $this->assertXml($result, 'ok');
2568 * Test the api_lists_list() function.
2572 public function testApiListsList()
2574 $result = api_lists_list('json');
2575 $this->assertEquals(['lists_list' => []], $result);
2579 * Test the api_lists_ownerships() function.
2583 public function testApiListsOwnerships()
2585 $result = api_lists_ownerships('json');
2586 foreach ($result['lists']['lists'] as $list) {
2587 $this->assertList($list);
2592 * Test the api_lists_ownerships() function without an authenticated user.
2595 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2597 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2599 $_SESSION['authenticated'] = false;
2600 api_lists_ownerships('json');
2604 * Test the api_lists_statuses() function.
2606 * @expectedException Friendica\Network\HTTPException\BadRequestException
2609 public function testApiListsStatuses()
2611 api_lists_statuses('json');
2615 * Test the api_lists_statuses() function with a list ID.
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 $this->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 $this->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 $this->assertArrayHasKey('user', $result);
2668 * Test the api_statuses_f() function.
2672 public function testApiStatusesFWithFollowers()
2674 $result = api_statuses_f('followers');
2675 $this->assertArrayHasKey('user', $result);
2679 * Test the api_statuses_f() function.
2683 public function testApiStatusesFWithBlocks()
2685 $result = api_statuses_f('blocks');
2686 $this->assertArrayHasKey('user', $result);
2690 * Test the api_statuses_f() function.
2694 public function testApiStatusesFWithIncoming()
2696 $result = api_statuses_f('incoming');
2697 $this->assertArrayHasKey('user', $result);
2701 * Test the api_statuses_f() function an undefined cursor GET variable.
2705 public function testApiStatusesFWithUndefinedCursor()
2707 $_GET['cursor'] = 'undefined';
2708 $this->assertFalse(api_statuses_f('friends'));
2712 * Test the api_statuses_friends() function.
2716 public function testApiStatusesFriends()
2718 $result = api_statuses_friends('json');
2719 $this->assertArrayHasKey('user', $result);
2723 * Test the api_statuses_friends() function an undefined cursor GET variable.
2727 public function testApiStatusesFriendsWithUndefinedCursor()
2729 $_GET['cursor'] = 'undefined';
2730 $this->assertFalse(api_statuses_friends('json'));
2734 * Test the api_statuses_followers() function.
2738 public function testApiStatusesFollowers()
2740 $result = api_statuses_followers('json');
2741 $this->assertArrayHasKey('user', $result);
2745 * Test the api_statuses_followers() function an undefined cursor GET variable.
2749 public function testApiStatusesFollowersWithUndefinedCursor()
2751 $_GET['cursor'] = 'undefined';
2752 $this->assertFalse(api_statuses_followers('json'));
2756 * Test the api_blocks_list() function.
2760 public function testApiBlocksList()
2762 $result = api_blocks_list('json');
2763 $this->assertArrayHasKey('user', $result);
2767 * Test the api_blocks_list() function an undefined cursor GET variable.
2771 public function testApiBlocksListWithUndefinedCursor()
2773 $_GET['cursor'] = 'undefined';
2774 $this->assertFalse(api_blocks_list('json'));
2778 * Test the api_friendships_incoming() function.
2782 public function testApiFriendshipsIncoming()
2784 $result = api_friendships_incoming('json');
2785 $this->assertArrayHasKey('id', $result);
2789 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2793 public function testApiFriendshipsIncomingWithUndefinedCursor()
2795 $_GET['cursor'] = 'undefined';
2796 $this->assertFalse(api_friendships_incoming('json'));
2800 * Test the api_statusnet_config() function.
2804 public function testApiStatusnetConfig()
2806 $result = api_statusnet_config('json');
2807 $this->assertEquals('localhost', $result['config']['site']['server']);
2808 $this->assertEquals('default', $result['config']['site']['theme']);
2809 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2810 $this->assertTrue($result['config']['site']['fancy']);
2811 $this->assertEquals('en', $result['config']['site']['language']);
2812 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2813 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2814 $this->assertEquals('false', $result['config']['site']['private']);
2815 $this->assertEquals('false', $result['config']['site']['ssl']);
2816 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2820 * Test the api_statusnet_version() function.
2824 public function testApiStatusnetVersion()
2826 $result = api_statusnet_version('json');
2827 $this->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 $this->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 $this->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 $this->assertContains('message_text', $result['direct_message']['text']);
2878 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2879 $this->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 $this->assertContains('message_text', $result['direct_message']['text']);
2895 $this->assertContains('message_title', $result['direct_message']['text']);
2896 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2897 $this->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 $this->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');
2934 $this->assertEquals(
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');
2980 $this->assertEquals(
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 $this->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 $this->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 $this->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 $this->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');
3055 $this->assertEquals(
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 $this->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 $this->assertArrayHasKey('direct_message', $result);
3102 * Test the api_direct_messages_inbox() function.
3106 public function testApiDirectMessagesInbox()
3108 $result = api_direct_messages_inbox('json');
3109 $this->assertArrayHasKey('direct_message', $result);
3113 * Test the api_direct_messages_all() function.
3117 public function testApiDirectMessagesAll()
3119 $result = api_direct_messages_all('json');
3120 $this->assertArrayHasKey('direct_message', $result);
3124 * Test the api_direct_messages_conversation() function.
3128 public function testApiDirectMessagesConversation()
3130 $result = api_direct_messages_conversation('json');
3131 $this->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 $this->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.
3272 * @expectedException Friendica\Network\HTTPException\BadRequestException
3274 public function testApiFrPhotoCreateUpdate()
3276 api_fr_photo_create_update('json');
3280 * Test the api_fr_photo_create_update() function without an authenticated user.
3283 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3285 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3287 $_SESSION['authenticated'] = false;
3288 api_fr_photo_create_update('json');
3292 * Test the api_fr_photo_create_update() function with an album name.
3295 * @expectedException Friendica\Network\HTTPException\BadRequestException
3297 public function testApiFrPhotoCreateUpdateWithAlbum()
3299 $_REQUEST['album'] = 'album_name';
3300 api_fr_photo_create_update('json');
3304 * Test the api_fr_photo_create_update() function with the update mode.
3308 public function testApiFrPhotoCreateUpdateWithUpdate()
3310 $this->markTestIncomplete('We need to create a dataset for this');
3314 * Test the api_fr_photo_create_update() function with an uploaded file.
3318 public function testApiFrPhotoCreateUpdateWithFile()
3320 $this->markTestIncomplete();
3324 * Test the api_fr_photo_delete() function.
3327 * @expectedException Friendica\Network\HTTPException\BadRequestException
3329 public function testApiFrPhotoDelete()
3331 api_fr_photo_delete('json');
3335 * Test the api_fr_photo_delete() function without an authenticated user.
3338 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3340 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3342 $_SESSION['authenticated'] = false;
3343 api_fr_photo_delete('json');
3347 * Test the api_fr_photo_delete() function with a photo ID.
3350 * @expectedException Friendica\Network\HTTPException\BadRequestException
3352 public function testApiFrPhotoDeleteWithPhotoId()
3354 $_REQUEST['photo_id'] = 1;
3355 api_fr_photo_delete('json');
3359 * Test the api_fr_photo_delete() function with a correct photo ID.
3363 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3365 $this->markTestIncomplete('We need to create a dataset for this.');
3369 * Test the api_fr_photo_detail() function.
3372 * @expectedException Friendica\Network\HTTPException\BadRequestException
3374 public function testApiFrPhotoDetail()
3376 api_fr_photo_detail('json');
3380 * Test the api_fr_photo_detail() function without an authenticated user.
3383 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3385 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3387 $_SESSION['authenticated'] = false;
3388 api_fr_photo_detail('json');
3392 * Test the api_fr_photo_detail() function with a photo ID.
3395 * @expectedException Friendica\Network\HTTPException\NotFoundException
3397 public function testApiFrPhotoDetailWithPhotoId()
3399 $_REQUEST['photo_id'] = 1;
3400 api_fr_photo_detail('json');
3404 * Test the api_fr_photo_detail() function with a correct photo ID.
3408 public function testApiFrPhotoDetailCorrectPhotoId()
3410 $this->markTestIncomplete('We need to create a dataset for this.');
3414 * Test the api_account_update_profile_image() function.
3417 * @expectedException Friendica\Network\HTTPException\BadRequestException
3419 public function testApiAccountUpdateProfileImage()
3421 api_account_update_profile_image('json');
3425 * Test the api_account_update_profile_image() function without an authenticated user.
3428 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3430 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3432 $_SESSION['authenticated'] = false;
3433 api_account_update_profile_image('json');
3437 * Test the api_account_update_profile_image() function with an uploaded file.
3440 * @expectedException Friendica\Network\HTTPException\BadRequestException
3442 public function testApiAccountUpdateProfileImageWithUpload()
3444 $this->markTestIncomplete();
3449 * Test the api_account_update_profile() function.
3453 public function testApiAccountUpdateProfile()
3455 $_POST['name'] = 'new_name';
3456 $_POST['description'] = 'new_description';
3457 $result = api_account_update_profile('json');
3458 // We can't use assertSelfUser() here because the user object is missing some properties.
3459 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3460 $this->assertEquals('DFRN', $result['user']['location']);
3461 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3462 $this->assertEquals('dfrn', $result['user']['network']);
3463 $this->assertEquals('new_name', $result['user']['name']);
3464 $this->assertEquals('new_description', $result['user']['description']);
3468 * Test the check_acl_input() function.
3472 public function testCheckAclInput()
3474 $result = check_acl_input('<aclstring>');
3475 // Where does this result come from?
3476 $this->assertEquals(1, $result);
3480 * Test the check_acl_input() function with an empty ACL string.
3484 public function testCheckAclInputWithEmptyAclString()
3486 $result = check_acl_input(' ');
3487 $this->assertFalse($result);
3491 * Test the save_media_to_database() function.
3495 public function testSaveMediaToDatabase()
3497 $this->markTestIncomplete();
3501 * Test the post_photo_item() function.
3505 public function testPostPhotoItem()
3507 $this->markTestIncomplete();
3511 * Test the prepare_photo_data() function.
3515 public function testPreparePhotoData()
3517 $this->markTestIncomplete();
3521 * Test the api_friendica_remoteauth() function.
3524 * @expectedException Friendica\Network\HTTPException\BadRequestException
3526 public function testApiFriendicaRemoteauth()
3528 api_friendica_remoteauth();
3532 * Test the api_friendica_remoteauth() function with an URL.
3535 * @expectedException Friendica\Network\HTTPException\BadRequestException
3537 public function testApiFriendicaRemoteauthWithUrl()
3539 $_GET['url'] = 'url';
3540 $_GET['c_url'] = 'url';
3541 api_friendica_remoteauth();
3545 * Test the api_friendica_remoteauth() function with a correct URL.
3549 public function testApiFriendicaRemoteauthWithCorrectUrl()
3551 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3552 $_GET['url'] = 'url';
3553 $_GET['c_url'] = $this->selfUser['nurl'];
3554 api_friendica_remoteauth();
3558 * Test the api_share_as_retweet() function.
3562 public function testApiShareAsRetweet()
3564 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3565 $result = api_share_as_retweet($item);
3566 $this->assertFalse($result);
3570 * Test the api_share_as_retweet() function with a valid item.
3574 public function testApiShareAsRetweetWithValidItem()
3576 $this->markTestIncomplete();
3580 * Test the api_in_reply_to() function.
3584 public function testApiInReplyTo()
3586 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3587 $this->assertArrayHasKey('status_id', $result);
3588 $this->assertArrayHasKey('user_id', $result);
3589 $this->assertArrayHasKey('status_id_str', $result);
3590 $this->assertArrayHasKey('user_id_str', $result);
3591 $this->assertArrayHasKey('screen_name', $result);
3595 * Test the api_in_reply_to() function with a valid item.
3599 public function testApiInReplyToWithValidItem()
3601 $this->markTestIncomplete();
3605 * Test the api_clean_plain_items() function.
3609 public function testApiCleanPlainItems()
3611 $_REQUEST['include_entities'] = 'true';
3612 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3613 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3617 * Test the api_best_nickname() function.
3621 public function testApiBestNickname()
3624 $result = api_best_nickname($contacts);
3625 $this->assertNull($result);
3629 * Test the api_best_nickname() function with contacts.
3633 public function testApiBestNicknameWithContacts()
3635 $this->markTestIncomplete();
3639 * Test the api_friendica_group_show() function.
3643 public function testApiFriendicaGroupShow()
3645 $this->markTestIncomplete();
3649 * Test the api_friendica_group_delete() function.
3653 public function testApiFriendicaGroupDelete()
3655 $this->markTestIncomplete();
3659 * Test the api_lists_destroy() function.
3663 public function testApiListsDestroy()
3665 $this->markTestIncomplete();
3669 * Test the group_create() function.
3673 public function testGroupCreate()
3675 $this->markTestIncomplete();
3679 * Test the api_friendica_group_create() function.
3683 public function testApiFriendicaGroupCreate()
3685 $this->markTestIncomplete();
3689 * Test the api_lists_create() function.
3693 public function testApiListsCreate()
3695 $this->markTestIncomplete();
3699 * Test the api_friendica_group_update() function.
3703 public function testApiFriendicaGroupUpdate()
3705 $this->markTestIncomplete();
3709 * Test the api_lists_update() function.
3713 public function testApiListsUpdate()
3715 $this->markTestIncomplete();
3719 * Test the api_friendica_activity() function.
3723 public function testApiFriendicaActivity()
3725 $this->markTestIncomplete();
3729 * Test the api_friendica_notification() function.
3732 * @expectedException Friendica\Network\HTTPException\BadRequestException
3734 public function testApiFriendicaNotification()
3736 api_friendica_notification('json');
3740 * Test the api_friendica_notification() function without an authenticated user.
3743 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3745 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3747 $_SESSION['authenticated'] = false;
3748 api_friendica_notification('json');
3752 * Test the api_friendica_notification() function with empty result
3756 public function testApiFriendicaNotificationWithEmptyResult()
3758 $this->app->argv = ['api', 'friendica', 'notification'];
3759 $this->app->argc = count($this->app->argv);
3760 $_SESSION['uid'] = 41;
3761 $result = api_friendica_notification('json');
3762 $this->assertEquals(['note' => false], $result);
3766 * Test the api_friendica_notification() function with an XML result.
3770 public function testApiFriendicaNotificationWithXmlResult()
3772 $this->app->argv = ['api', 'friendica', 'notification'];
3773 $this->app->argc = count($this->app->argv);
3774 $result = api_friendica_notification('xml');
3775 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3777 <?xml version="1.0"?>
3779 <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="0" 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"/>
3782 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3786 * Test the api_friendica_notification() function with an JSON result.
3790 public function testApiFriendicaNotificationWithJsonResult()
3792 $this->app->argv = ['api', 'friendica', 'notification'];
3793 $this->app->argc = count($this->app->argv);
3794 $result = json_encode(api_friendica_notification('json'));
3795 $this->assertJson($result);
3799 * Test the api_friendica_notification_seen() function.
3803 public function testApiFriendicaNotificationSeen()
3805 $this->markTestIncomplete();
3809 * Test the api_friendica_direct_messages_setseen() function.
3813 public function testApiFriendicaDirectMessagesSetseen()
3815 $this->markTestIncomplete();
3819 * Test the api_friendica_direct_messages_search() function.
3823 public function testApiFriendicaDirectMessagesSearch()
3825 $this->markTestIncomplete();
3829 * Test the api_saved_searches_list() function.
3833 public function testApiSavedSearchesList()
3835 $result = api_saved_searches_list('json');
3836 $this->assertEquals(1, $result['terms'][0]['id']);
3837 $this->assertEquals(1, $result['terms'][0]['id_str']);
3838 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3839 $this->assertEquals('Saved search', $result['terms'][0]['query']);