6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\Config\Cache\PConfigCache;
11 use Friendica\Core\L10n\L10n;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\System;
15 use Friendica\Factory;
16 use Friendica\Network\HTTPException;
17 use Friendica\Util\BaseURL;
18 use Monolog\Handler\TestHandler;
20 require_once __DIR__ . '/../../include/api.php';
23 * Tests for the API functions.
25 * Functions that use header() need to be tested in a separate process.
26 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
28 class ApiTest extends DatabaseTest
31 * @var TestHandler Can handle log-outputs
41 protected $friendUser;
45 protected $wrongUserId;
48 * Create variables used by tests.
50 public function setUp()
52 $configModel = new \Friendica\Model\Config\Config(self::$dba);
53 $configFactory = new Factory\ConfigFactory();
54 $config = $configFactory->createConfig(self::$configCache, $configModel);
55 $pconfigModel = new \Friendica\Model\Config\PConfig(self::$dba);
56 $configFactory->createPConfig(self::$configCache, new PConfigCache(), $pconfigModel);
57 $loggerFactory = new Factory\LoggerFactory();
58 $logger = $loggerFactory->create('test', self::$dba, $config, self::$profiler);
59 $baseUrl = new BaseURL($config, $_SERVER);
60 $router = new App\Router();
61 $l10n = new L10n($config,
64 $this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, $l10n, false);
68 // User data that the test database is populated with
71 'name' => 'Self contact',
72 'nick' => 'selfcontact',
73 'nurl' => 'http://localhost/profile/selfcontact'
77 'name' => 'Friend contact',
78 'nick' => 'friendcontact',
79 'nurl' => 'http://localhost/profile/friendcontact'
83 'name' => 'othercontact',
84 'nick' => 'othercontact',
85 'nurl' => 'http://localhost/profile/othercontact'
88 // User ID that we know is not in the database
89 $this->wrongUserId = 666;
91 // Most API require login so we force the session
94 'authenticated' => true,
95 'uid' => $this->selfUser['id']
98 Config::set('system', 'url', 'http://localhost');
99 Config::set('system', 'hostname', 'localhost');
100 Config::set('system', 'worker_dont_fork', true);
103 Config::set('config', 'hostname', 'localhost');
104 Config::set('system', 'throttle_limit_day', 100);
105 Config::set('system', 'throttle_limit_week', 100);
106 Config::set('system', 'throttle_limit_month', 100);
107 Config::set('system', 'theme', 'system_theme');
111 * Cleanup variables used by tests.
113 protected function tearDown()
117 $this->app->argc = 1;
118 $this->app->argv = ['home'];
122 * Assert that an user array contains expected keys.
123 * @param array $user User array
126 private function assertSelfUser(array $user)
128 $this->assertEquals($this->selfUser['id'], $user['uid']);
129 $this->assertEquals($this->selfUser['id'], $user['cid']);
130 $this->assertEquals(1, $user['self']);
131 $this->assertEquals('DFRN', $user['location']);
132 $this->assertEquals($this->selfUser['name'], $user['name']);
133 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
134 $this->assertEquals('dfrn', $user['network']);
135 $this->assertTrue($user['verified']);
139 * Assert that an user array contains expected keys.
140 * @param array $user User array
143 private function assertOtherUser(array $user)
145 $this->assertEquals($this->otherUser['id'], $user['id']);
146 $this->assertEquals($this->otherUser['id'], $user['id_str']);
147 $this->assertEquals(0, $user['self']);
148 $this->assertEquals($this->otherUser['name'], $user['name']);
149 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
150 $this->assertFalse($user['verified']);
154 * Assert that a status array contains expected keys.
155 * @param array $status Status array
158 private function assertStatus(array $status)
160 $this->assertInternalType('string', $status['text']);
161 $this->assertInternalType('int', $status['id']);
162 // We could probably do more checks here.
166 * Assert that a list array contains expected keys.
167 * @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.
181 * @param string $result XML string
182 * @param string $root_element Root element name
185 private function assertXml($result, $root_element)
187 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
188 $this->assertContains('<'.$root_element, $result);
189 // We could probably do more checks here.
193 * Get the path to a temporary empty PNG image.
194 * @return string Path
196 private function getTempImage()
198 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
202 // Empty 1x1 px PNG image
203 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
211 * Test the api_user() function.
214 public function testApiUser()
216 $this->assertEquals($this->selfUser['id'], api_user());
220 * Test the api_user() function with an unallowed user.
223 public function testApiUserWithUnallowedUser()
225 $_SESSION = ['allow_api' => false];
226 $this->assertEquals(false, api_user());
230 * Test the api_source() function.
233 public function testApiSource()
235 $this->assertEquals('api', api_source());
239 * Test the api_source() function with a Twidere user agent.
242 public function testApiSourceWithTwidere()
244 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
245 $this->assertEquals('Twidere', api_source());
249 * Test the api_source() function with a GET parameter.
252 public function testApiSourceWithGet()
254 $_GET['source'] = 'source_name';
255 $this->assertEquals('source_name', api_source());
259 * Test the api_date() function.
262 public function testApiDate()
264 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
268 * Test the api_register_func() function.
271 public function testApiRegisterFunc()
283 $this->assertTrue($API['api_path']['auth']);
284 $this->assertEquals('method', $API['api_path']['method']);
285 $this->assertTrue(is_callable($API['api_path']['func']));
289 * Test the api_login() function without any login.
291 * @runInSeparateProcess
292 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
294 public function testApiLoginWithoutLogin()
296 api_login($this->app);
300 * Test the api_login() function with a bad login.
302 * @runInSeparateProcess
303 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
305 public function testApiLoginWithBadLogin()
307 $_SERVER['PHP_AUTH_USER'] = 'user@server';
308 api_login($this->app);
312 * Test the api_login() function with oAuth.
315 public function testApiLoginWithOauth()
317 $this->markTestIncomplete('Can we test this easily?');
321 * Test the api_login() function with authentication provided by an addon.
324 public function testApiLoginWithAddonAuth()
326 $this->markTestIncomplete('Can we test this easily?');
330 * Test the api_login() function with a correct login.
332 * @runInSeparateProcess
334 public function testApiLoginWithCorrectLogin()
336 $_SERVER['PHP_AUTH_USER'] = 'Test user';
337 $_SERVER['PHP_AUTH_PW'] = 'password';
338 api_login($this->app);
342 * Test the api_login() function with a remote user.
344 * @runInSeparateProcess
345 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
347 public function testApiLoginWithRemoteUser()
349 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
350 api_login($this->app);
354 * Test the api_check_method() function.
357 public function testApiCheckMethod()
359 $this->assertFalse(api_check_method('method'));
363 * Test the api_check_method() function with a correct method.
366 public function testApiCheckMethodWithCorrectMethod()
368 $_SERVER['REQUEST_METHOD'] = 'method';
369 $this->assertTrue(api_check_method('method'));
373 * Test the api_check_method() function with a wildcard.
376 public function testApiCheckMethodWithWildcard()
378 $this->assertTrue(api_check_method('*'));
382 * Test the api_call() function.
384 * @runInSeparateProcess
386 public function testApiCall()
390 'method' => 'method',
391 'func' => function () {
392 return ['data' => ['some_data']];
395 $_SERVER['REQUEST_METHOD'] = 'method';
396 $_GET['callback'] = 'callback_name';
398 $this->app->query_string = 'api_path';
400 'callback_name(["some_data"])',
406 * Test the api_call() function with the profiled enabled.
408 * @runInSeparateProcess
410 public function testApiCallWithProfiler()
414 'method' => 'method',
415 'func' => function () {
416 return ['data' => ['some_data']];
419 $_SERVER['REQUEST_METHOD'] = 'method';
420 Config::set('system', 'profiler', true);
421 Config::set('rendertime', 'callstack', true);
422 $this->app->callstack = [
423 'database' => ['some_function' => 200],
424 'database_write' => ['some_function' => 200],
425 'cache' => ['some_function' => 200],
426 'cache_write' => ['some_function' => 200],
427 'network' => ['some_function' => 200]
430 $this->app->query_string = 'api_path';
438 * Test the api_call() function without any result.
440 * @runInSeparateProcess
442 public function testApiCallWithNoResult()
446 'method' => 'method',
447 'func' => function () {
451 $_SERVER['REQUEST_METHOD'] = 'method';
453 $this->app->query_string = 'api_path';
455 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
461 * Test the api_call() function with an unimplemented API.
463 * @runInSeparateProcess
465 public function testApiCallWithUninplementedApi()
468 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
474 * Test the api_call() function with a JSON result.
476 * @runInSeparateProcess
478 public function testApiCallWithJson()
482 'method' => 'method',
483 'func' => function () {
484 return ['data' => ['some_data']];
487 $_SERVER['REQUEST_METHOD'] = 'method';
489 $this->app->query_string = 'api_path.json';
497 * Test the api_call() function with an XML result.
499 * @runInSeparateProcess
501 public function testApiCallWithXml()
505 'method' => 'method',
506 'func' => function () {
510 $_SERVER['REQUEST_METHOD'] = 'method';
512 $this->app->query_string = 'api_path.xml';
520 * Test the api_call() function with an RSS result.
522 * @runInSeparateProcess
524 public function testApiCallWithRss()
528 'method' => 'method',
529 'func' => function () {
533 $_SERVER['REQUEST_METHOD'] = 'method';
535 $this->app->query_string = 'api_path.rss';
537 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
544 * Test the api_call() function with an Atom result.
546 * @runInSeparateProcess
548 public function testApiCallWithAtom()
552 'method' => 'method',
553 'func' => function () {
557 $_SERVER['REQUEST_METHOD'] = 'method';
559 $this->app->query_string = 'api_path.atom';
561 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
568 * Test the api_call() function with an unallowed method.
570 * @runInSeparateProcess
572 public function testApiCallWithWrongMethod()
575 $API['api_path'] = ['method' => 'method'];
577 $this->app->query_string = 'api_path';
579 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
585 * Test the api_call() function with an unauthorized user.
587 * @runInSeparateProcess
589 public function testApiCallWithWrongAuth()
593 'method' => 'method',
596 $_SERVER['REQUEST_METHOD'] = 'method';
597 $_SESSION['authenticated'] = false;
599 $this->app->query_string = 'api_path';
601 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
607 * Test the api_error() function with a JSON result.
609 * @runInSeparateProcess
611 public function testApiErrorWithJson()
614 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
615 api_error('json', new HTTPException\OKException('error_message'))
620 * Test the api_error() function with an XML result.
622 * @runInSeparateProcess
624 public function testApiErrorWithXml()
627 '<?xml version="1.0"?>'."\n".
628 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
629 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
630 'xmlns:georss="http://www.georss.org/georss">'."\n".
631 ' <error>error_message</error>'."\n".
632 ' <code>200 OK</code>'."\n".
635 api_error('xml', new HTTPException\OKException('error_message'))
640 * Test the api_error() function with an RSS result.
642 * @runInSeparateProcess
644 public function testApiErrorWithRss()
647 '<?xml version="1.0"?>'."\n".
648 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
649 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
650 'xmlns:georss="http://www.georss.org/georss">'."\n".
651 ' <error>error_message</error>'."\n".
652 ' <code>200 OK</code>'."\n".
655 api_error('rss', new HTTPException\OKException('error_message'))
660 * Test the api_error() function with an Atom result.
662 * @runInSeparateProcess
664 public function testApiErrorWithAtom()
667 '<?xml version="1.0"?>'."\n".
668 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
669 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
670 'xmlns:georss="http://www.georss.org/georss">'."\n".
671 ' <error>error_message</error>'."\n".
672 ' <code>200 OK</code>'."\n".
675 api_error('atom', new HTTPException\OKException('error_message'))
680 * Test the api_rss_extra() function.
683 public function testApiRssExtra()
685 $user_info = ['url' => 'user_url', 'lang' => 'en'];
686 $result = api_rss_extra($this->app, [], $user_info);
687 $this->assertEquals($user_info, $result['$user']);
688 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
689 $this->assertArrayHasKey('self', $result['$rss']);
690 $this->assertArrayHasKey('base', $result['$rss']);
691 $this->assertArrayHasKey('updated', $result['$rss']);
692 $this->assertArrayHasKey('atom_updated', $result['$rss']);
693 $this->assertArrayHasKey('language', $result['$rss']);
694 $this->assertArrayHasKey('logo', $result['$rss']);
698 * Test the api_rss_extra() function without any user info.
700 * @runInSeparateProcess
702 public function testApiRssExtraWithoutUserInfo()
704 $result = api_rss_extra($this->app, [], null);
705 $this->assertInternalType('array', $result['$user']);
706 $this->assertArrayHasKey('alternate', $result['$rss']);
707 $this->assertArrayHasKey('self', $result['$rss']);
708 $this->assertArrayHasKey('base', $result['$rss']);
709 $this->assertArrayHasKey('updated', $result['$rss']);
710 $this->assertArrayHasKey('atom_updated', $result['$rss']);
711 $this->assertArrayHasKey('language', $result['$rss']);
712 $this->assertArrayHasKey('logo', $result['$rss']);
716 * Test the api_unique_id_to_nurl() function.
719 public function testApiUniqueIdToNurl()
721 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
725 * Test the api_unique_id_to_nurl() function with a correct ID.
728 public function testApiUniqueIdToNurlWithCorrectId()
730 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
734 * Test the api_get_user() function.
736 * @runInSeparateProcess
738 public function testApiGetUser()
740 $user = api_get_user($this->app);
741 $this->assertSelfUser($user);
742 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
743 $this->assertEquals('6fdbe8', $user['profile_link_color']);
744 $this->assertEquals('ededed', $user['profile_background_color']);
748 * Test the api_get_user() function with a Frio schema.
750 * @runInSeparateProcess
752 public function testApiGetUserWithFrioSchema()
754 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
755 $user = api_get_user($this->app);
756 $this->assertSelfUser($user);
757 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
758 $this->assertEquals('6fdbe8', $user['profile_link_color']);
759 $this->assertEquals('ededed', $user['profile_background_color']);
763 * Test the api_get_user() function with a custom Frio schema.
765 * @runInSeparateProcess
767 public function testApiGetUserWithCustomFrioSchema()
769 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
770 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
771 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
772 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
773 $user = api_get_user($this->app);
774 $this->assertSelfUser($user);
775 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
776 $this->assertEquals('123456', $user['profile_link_color']);
777 $this->assertEquals('123456', $user['profile_background_color']);
781 * Test the api_get_user() function with an empty Frio schema.
783 * @runInSeparateProcess
785 public function testApiGetUserWithEmptyFrioSchema()
787 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
788 $user = api_get_user($this->app);
789 $this->assertSelfUser($user);
790 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
791 $this->assertEquals('6fdbe8', $user['profile_link_color']);
792 $this->assertEquals('ededed', $user['profile_background_color']);
796 * Test the api_get_user() function with an user that is not allowed to use the API.
798 * @runInSeparateProcess
800 public function testApiGetUserWithoutApiUser()
802 $_SERVER['PHP_AUTH_USER'] = 'Test user';
803 $_SERVER['PHP_AUTH_PW'] = 'password';
804 $_SESSION['allow_api'] = false;
805 $this->assertFalse(api_get_user($this->app));
809 * Test the api_get_user() function with an user ID in a GET parameter.
811 * @runInSeparateProcess
813 public function testApiGetUserWithGetId()
815 $_GET['user_id'] = $this->otherUser['id'];
816 $this->assertOtherUser(api_get_user($this->app));
820 * Test the api_get_user() function with a wrong user ID in a GET parameter.
822 * @runInSeparateProcess
823 * @expectedException Friendica\Network\HTTPException\BadRequestException
825 public function testApiGetUserWithWrongGetId()
827 $_GET['user_id'] = $this->wrongUserId;
828 $this->assertOtherUser(api_get_user($this->app));
832 * Test the api_get_user() function with an user name in a GET parameter.
834 * @runInSeparateProcess
836 public function testApiGetUserWithGetName()
838 $_GET['screen_name'] = $this->selfUser['nick'];
839 $this->assertSelfUser(api_get_user($this->app));
843 * Test the api_get_user() function with a profile URL in a GET parameter.
845 * @runInSeparateProcess
847 public function testApiGetUserWithGetUrl()
849 $_GET['profileurl'] = $this->selfUser['nurl'];
850 $this->assertSelfUser(api_get_user($this->app));
854 * Test the api_get_user() function with an user ID in the API path.
856 * @runInSeparateProcess
858 public function testApiGetUserWithNumericCalledApi()
861 $called_api = ['api_path'];
862 $this->app->argv[1] = $this->otherUser['id'].'.json';
863 $this->assertOtherUser(api_get_user($this->app));
867 * Test the api_get_user() function with the $called_api global variable.
869 * @runInSeparateProcess
871 public function testApiGetUserWithCalledApi()
874 $called_api = ['api', 'api_path'];
875 $this->assertSelfUser(api_get_user($this->app));
879 * Test the api_get_user() function with a valid user.
881 * @runInSeparateProcess
883 public function testApiGetUserWithCorrectUser()
885 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
889 * Test the api_get_user() function with a wrong user ID.
891 * @runInSeparateProcess
892 * @expectedException Friendica\Network\HTTPException\BadRequestException
894 public function testApiGetUserWithWrongUser()
896 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
900 * Test the api_get_user() function with a 0 user ID.
902 * @runInSeparateProcess
904 public function testApiGetUserWithZeroUser()
906 $this->assertSelfUser(api_get_user($this->app, 0));
910 * Test the api_item_get_user() function.
912 * @runInSeparateProcess
914 public function testApiItemGetUser()
916 $users = api_item_get_user($this->app, []);
917 $this->assertSelfUser($users[0]);
921 * Test the api_item_get_user() function with a different item parent.
924 public function testApiItemGetUserWithDifferentParent()
926 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
927 $this->assertSelfUser($users[0]);
928 $this->assertEquals($users[0], $users[1]);
932 * Test the api_walk_recursive() function.
935 public function testApiWalkRecursive()
943 // Should we test this with a callback that actually does something?
951 * Test the api_walk_recursive() function with an array.
954 public function testApiWalkRecursiveWithArray()
956 $array = [['item1'], ['item2']];
962 // Should we test this with a callback that actually does something?
970 * Test the api_reformat_xml() function.
973 public function testApiReformatXml()
977 $this->assertTrue(api_reformat_xml($item, $key));
978 $this->assertEquals('true', $item);
982 * Test the api_reformat_xml() function with a statusnet_api key.
985 public function testApiReformatXmlWithStatusnetKey()
988 $key = 'statusnet_api';
989 $this->assertTrue(api_reformat_xml($item, $key));
990 $this->assertEquals('statusnet:api', $key);
994 * Test the api_reformat_xml() function with a friendica_api key.
997 public function testApiReformatXmlWithFriendicaKey()
1000 $key = 'friendica_api';
1001 $this->assertTrue(api_reformat_xml($item, $key));
1002 $this->assertEquals('friendica:api', $key);
1006 * Test the api_create_xml() function.
1009 public function testApiCreateXml()
1011 $this->assertEquals(
1012 '<?xml version="1.0"?>'."\n".
1013 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1014 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1015 'xmlns:georss="http://www.georss.org/georss">'."\n".
1016 ' <data>some_data</data>'."\n".
1017 '</root_element>'."\n",
1018 api_create_xml(['data' => ['some_data']], 'root_element')
1023 * Test the api_create_xml() function without any XML namespace.
1026 public function testApiCreateXmlWithoutNamespaces()
1028 $this->assertEquals(
1029 '<?xml version="1.0"?>'."\n".
1031 ' <data>some_data</data>'."\n".
1033 api_create_xml(['data' => ['some_data']], 'ok')
1038 * Test the api_format_data() function.
1041 public function testApiFormatData()
1043 $data = ['some_data'];
1044 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1048 * Test the api_format_data() function with an XML result.
1051 public function testApiFormatDataWithXml()
1053 $this->assertEquals(
1054 '<?xml version="1.0"?>'."\n".
1055 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1056 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1057 'xmlns:georss="http://www.georss.org/georss">'."\n".
1058 ' <data>some_data</data>'."\n".
1059 '</root_element>'."\n",
1060 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1065 * Test the api_account_verify_credentials() function.
1068 public function testApiAccountVerifyCredentials()
1070 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1074 * Test the api_account_verify_credentials() function without an authenticated user.
1076 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1078 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1080 $_SESSION['authenticated'] = false;
1081 api_account_verify_credentials('json');
1085 * Test the requestdata() function.
1088 public function testRequestdata()
1090 $this->assertNull(requestdata('variable_name'));
1094 * Test the requestdata() function with a POST parameter.
1097 public function testRequestdataWithPost()
1099 $_POST['variable_name'] = 'variable_value';
1100 $this->assertEquals('variable_value', requestdata('variable_name'));
1104 * Test the requestdata() function with a GET parameter.
1107 public function testRequestdataWithGet()
1109 $_GET['variable_name'] = 'variable_value';
1110 $this->assertEquals('variable_value', requestdata('variable_name'));
1114 * Test the api_statuses_mediap() function.
1117 public function testApiStatusesMediap()
1119 $this->app->argc = 2;
1127 'tmp_name' => $this->getTempImage(),
1128 'name' => 'spacer.png',
1129 'type' => 'image/png'
1132 $_GET['status'] = '<b>Status content</b>';
1134 $result = api_statuses_mediap('json');
1135 $this->assertStatus($result['status']);
1139 * Test the api_statuses_mediap() function without an authenticated user.
1141 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1143 public function testApiStatusesMediapWithoutAuthenticatedUser()
1145 $_SESSION['authenticated'] = false;
1146 api_statuses_mediap('json');
1150 * Test the api_statuses_update() function.
1153 public function testApiStatusesUpdate()
1155 $_GET['status'] = 'Status content #friendica';
1156 $_GET['in_reply_to_status_id'] = -1;
1165 'tmp_name' => $this->getTempImage(),
1166 'name' => 'spacer.png',
1167 'type' => 'image/png'
1171 $result = api_statuses_update('json');
1172 $this->assertStatus($result['status']);
1176 * Test the api_statuses_update() function with an HTML status.
1179 public function testApiStatusesUpdateWithHtml()
1181 $_GET['htmlstatus'] = '<b>Status content</b>';
1183 $result = api_statuses_update('json');
1184 $this->assertStatus($result['status']);
1188 * Test the api_statuses_update() function without an authenticated user.
1190 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1192 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1194 $_SESSION['authenticated'] = false;
1195 api_statuses_update('json');
1199 * Test the api_statuses_update() function with a parent status.
1202 public function testApiStatusesUpdateWithParent()
1204 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1208 * Test the api_statuses_update() function with a media_ids parameter.
1211 public function testApiStatusesUpdateWithMediaIds()
1213 $this->markTestIncomplete();
1217 * Test the api_statuses_update() function with the throttle limit reached.
1220 public function testApiStatusesUpdateWithDayThrottleReached()
1222 $this->markTestIncomplete();
1226 * Test the api_media_upload() function.
1228 * @expectedException Friendica\Network\HTTPException\BadRequestException
1230 public function testApiMediaUpload()
1236 * Test the api_media_upload() function without an authenticated user.
1238 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1240 public function testApiMediaUploadWithoutAuthenticatedUser()
1242 $_SESSION['authenticated'] = false;
1247 * Test the api_media_upload() function with an invalid uploaded media.
1249 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1251 public function testApiMediaUploadWithMedia()
1256 'tmp_name' => 'tmp_name'
1263 * Test the api_media_upload() function with an valid uploaded media.
1266 public function testApiMediaUploadWithValidMedia()
1274 'tmp_name' => $this->getTempImage(),
1275 'name' => 'spacer.png',
1276 'type' => 'image/png'
1282 $result = api_media_upload();
1283 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1284 $this->assertEquals(1, $result['media']['image']['w']);
1285 $this->assertEquals(1, $result['media']['image']['h']);
1286 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1290 * Test the api_status_show() function.
1292 public function testApiStatusShowWithJson()
1294 $result = api_status_show('json', 1);
1295 $this->assertStatus($result['status']);
1299 * Test the api_status_show() function with an XML result.
1301 public function testApiStatusShowWithXml()
1303 $result = api_status_show('xml', 1);
1304 $this->assertXml($result, 'statuses');
1308 * Test the api_get_last_status() function
1310 public function testApiGetLastStatus()
1312 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1314 $this->assertNotNull($item);
1318 * Test the api_users_show() function.
1321 public function testApiUsersShow()
1323 $result = api_users_show('json');
1324 // We can't use assertSelfUser() here because the user object is missing some properties.
1325 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1326 $this->assertEquals('DFRN', $result['user']['location']);
1327 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1328 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1329 $this->assertEquals('dfrn', $result['user']['network']);
1330 $this->assertTrue($result['user']['verified']);
1334 * Test the api_users_show() function with an XML result.
1337 public function testApiUsersShowWithXml()
1339 $result = api_users_show('xml');
1340 $this->assertXml($result, 'statuses');
1344 * Test the api_users_search() function.
1347 public function testApiUsersSearch()
1349 $_GET['q'] = 'othercontact';
1350 $result = api_users_search('json');
1351 $this->assertOtherUser($result['users'][0]);
1355 * Test the api_users_search() function with an XML result.
1358 public function testApiUsersSearchWithXml()
1360 $_GET['q'] = 'othercontact';
1361 $result = api_users_search('xml');
1362 $this->assertXml($result, 'users');
1366 * Test the api_users_search() function without a GET q parameter.
1368 * @expectedException Friendica\Network\HTTPException\BadRequestException
1370 public function testApiUsersSearchWithoutQuery()
1372 api_users_search('json');
1376 * Test the api_users_lookup() function.
1378 * @expectedException Friendica\Network\HTTPException\NotFoundException
1380 public function testApiUsersLookup()
1382 api_users_lookup('json');
1386 * Test the api_users_lookup() function with an user ID.
1389 public function testApiUsersLookupWithUserId()
1391 $_REQUEST['user_id'] = $this->otherUser['id'];
1392 $result = api_users_lookup('json');
1393 $this->assertOtherUser($result['users'][0]);
1397 * Test the api_search() function.
1400 public function testApiSearch()
1402 $_REQUEST['q'] = 'reply';
1403 $_REQUEST['max_id'] = 10;
1404 $result = api_search('json');
1405 foreach ($result['status'] as $status) {
1406 $this->assertStatus($status);
1407 $this->assertContains('reply', $status['text'], null, true);
1412 * Test the api_search() function a count parameter.
1415 public function testApiSearchWithCount()
1417 $_REQUEST['q'] = 'reply';
1418 $_REQUEST['count'] = 20;
1419 $result = api_search('json');
1420 foreach ($result['status'] as $status) {
1421 $this->assertStatus($status);
1422 $this->assertContains('reply', $status['text'], null, true);
1427 * Test the api_search() function with an rpp parameter.
1430 public function testApiSearchWithRpp()
1432 $_REQUEST['q'] = 'reply';
1433 $_REQUEST['rpp'] = 20;
1434 $result = api_search('json');
1435 foreach ($result['status'] as $status) {
1436 $this->assertStatus($status);
1437 $this->assertContains('reply', $status['text'], null, true);
1442 * Test the api_search() function with an q parameter contains hashtag.
1445 public function testApiSearchWithHashtag()
1447 $_REQUEST['q'] = '%23friendica';
1448 $result = api_search('json');
1449 foreach ($result['status'] as $status) {
1450 $this->assertStatus($status);
1451 $this->assertContains('#friendica', $status['text'], null, true);
1456 * Test the api_search() function with an exclude_replies parameter.
1459 public function testApiSearchWithExcludeReplies()
1461 $_REQUEST['max_id'] = 10;
1462 $_REQUEST['exclude_replies'] = true;
1463 $_REQUEST['q'] = 'friendica';
1464 $result = api_search('json');
1465 foreach ($result['status'] as $status) {
1466 $this->assertStatus($status);
1471 * Test the api_search() function without an authenticated user.
1473 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1475 public function testApiSearchWithUnallowedUser()
1477 $_SESSION['allow_api'] = false;
1478 $_GET['screen_name'] = $this->selfUser['nick'];
1483 * Test the api_search() function without any GET query parameter.
1485 * @expectedException Friendica\Network\HTTPException\BadRequestException
1487 public function testApiSearchWithoutQuery()
1493 * Test the api_statuses_home_timeline() function.
1496 public function testApiStatusesHomeTimeline()
1498 $_REQUEST['max_id'] = 10;
1499 $_REQUEST['exclude_replies'] = true;
1500 $_REQUEST['conversation_id'] = 1;
1501 $result = api_statuses_home_timeline('json');
1502 $this->assertNotEmpty($result['status']);
1503 foreach ($result['status'] as $status) {
1504 $this->assertStatus($status);
1509 * Test the api_statuses_home_timeline() function with a negative page parameter.
1512 public function testApiStatusesHomeTimelineWithNegativePage()
1514 $_REQUEST['page'] = -2;
1515 $result = api_statuses_home_timeline('json');
1516 $this->assertNotEmpty($result['status']);
1517 foreach ($result['status'] as $status) {
1518 $this->assertStatus($status);
1523 * Test the api_statuses_home_timeline() with an unallowed user.
1525 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1527 public function testApiStatusesHomeTimelineWithUnallowedUser()
1529 $_SESSION['allow_api'] = false;
1530 $_GET['screen_name'] = $this->selfUser['nick'];
1531 api_statuses_home_timeline('json');
1535 * Test the api_statuses_home_timeline() function with an RSS result.
1538 public function testApiStatusesHomeTimelineWithRss()
1540 $result = api_statuses_home_timeline('rss');
1541 $this->assertXml($result, 'statuses');
1545 * Test the api_statuses_public_timeline() function.
1548 public function testApiStatusesPublicTimeline()
1550 $_REQUEST['max_id'] = 10;
1551 $_REQUEST['conversation_id'] = 1;
1552 $result = api_statuses_public_timeline('json');
1553 $this->assertNotEmpty($result['status']);
1554 foreach ($result['status'] as $status) {
1555 $this->assertStatus($status);
1560 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1563 public function testApiStatusesPublicTimelineWithExcludeReplies()
1565 $_REQUEST['max_id'] = 10;
1566 $_REQUEST['exclude_replies'] = true;
1567 $result = api_statuses_public_timeline('json');
1568 $this->assertNotEmpty($result['status']);
1569 foreach ($result['status'] as $status) {
1570 $this->assertStatus($status);
1575 * Test the api_statuses_public_timeline() function with a negative page parameter.
1578 public function testApiStatusesPublicTimelineWithNegativePage()
1580 $_REQUEST['page'] = -2;
1581 $result = api_statuses_public_timeline('json');
1582 $this->assertNotEmpty($result['status']);
1583 foreach ($result['status'] as $status) {
1584 $this->assertStatus($status);
1589 * Test the api_statuses_public_timeline() function with an unallowed user.
1591 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1593 public function testApiStatusesPublicTimelineWithUnallowedUser()
1595 $_SESSION['allow_api'] = false;
1596 $_GET['screen_name'] = $this->selfUser['nick'];
1597 api_statuses_public_timeline('json');
1601 * Test the api_statuses_public_timeline() function with an RSS result.
1604 public function testApiStatusesPublicTimelineWithRss()
1606 $result = api_statuses_public_timeline('rss');
1607 $this->assertXml($result, 'statuses');
1611 * Test the api_statuses_networkpublic_timeline() function.
1614 public function testApiStatusesNetworkpublicTimeline()
1616 $_REQUEST['max_id'] = 10;
1617 $result = api_statuses_networkpublic_timeline('json');
1618 $this->assertNotEmpty($result['status']);
1619 foreach ($result['status'] as $status) {
1620 $this->assertStatus($status);
1625 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1628 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1630 $_REQUEST['page'] = -2;
1631 $result = api_statuses_networkpublic_timeline('json');
1632 $this->assertNotEmpty($result['status']);
1633 foreach ($result['status'] as $status) {
1634 $this->assertStatus($status);
1639 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1641 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1643 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1645 $_SESSION['allow_api'] = false;
1646 $_GET['screen_name'] = $this->selfUser['nick'];
1647 api_statuses_networkpublic_timeline('json');
1651 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1654 public function testApiStatusesNetworkpublicTimelineWithRss()
1656 $result = api_statuses_networkpublic_timeline('rss');
1657 $this->assertXml($result, 'statuses');
1661 * Test the api_statuses_show() function.
1663 * @expectedException Friendica\Network\HTTPException\BadRequestException
1665 public function testApiStatusesShow()
1667 api_statuses_show('json');
1671 * Test the api_statuses_show() function with an ID.
1674 public function testApiStatusesShowWithId()
1676 $this->app->argv[3] = 1;
1677 $result = api_statuses_show('json');
1678 $this->assertStatus($result['status']);
1682 * Test the api_statuses_show() function with the conversation parameter.
1685 public function testApiStatusesShowWithConversation()
1687 $this->app->argv[3] = 1;
1688 $_REQUEST['conversation'] = 1;
1689 $result = api_statuses_show('json');
1690 $this->assertNotEmpty($result['status']);
1691 foreach ($result['status'] as $status) {
1692 $this->assertStatus($status);
1697 * Test the api_statuses_show() function with an unallowed user.
1699 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1701 public function testApiStatusesShowWithUnallowedUser()
1703 $_SESSION['allow_api'] = false;
1704 $_GET['screen_name'] = $this->selfUser['nick'];
1705 api_statuses_show('json');
1709 * Test the api_conversation_show() function.
1711 * @expectedException Friendica\Network\HTTPException\BadRequestException
1713 public function testApiConversationShow()
1715 api_conversation_show('json');
1719 * Test the api_conversation_show() function with an ID.
1722 public function testApiConversationShowWithId()
1724 $this->app->argv[3] = 1;
1725 $_REQUEST['max_id'] = 10;
1726 $_REQUEST['page'] = -2;
1727 $result = api_conversation_show('json');
1728 $this->assertNotEmpty($result['status']);
1729 foreach ($result['status'] as $status) {
1730 $this->assertStatus($status);
1735 * Test the api_conversation_show() function with an unallowed user.
1737 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1739 public function testApiConversationShowWithUnallowedUser()
1741 $_SESSION['allow_api'] = false;
1742 $_GET['screen_name'] = $this->selfUser['nick'];
1743 api_conversation_show('json');
1747 * Test the api_statuses_repeat() function.
1749 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1751 public function testApiStatusesRepeat()
1753 api_statuses_repeat('json');
1757 * Test the api_statuses_repeat() function without an authenticated user.
1759 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1761 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1763 $_SESSION['authenticated'] = false;
1764 api_statuses_repeat('json');
1768 * Test the api_statuses_repeat() function with an ID.
1771 public function testApiStatusesRepeatWithId()
1773 $this->app->argv[3] = 1;
1774 $result = api_statuses_repeat('json');
1775 $this->assertStatus($result['status']);
1777 // Also test with a shared status
1778 $this->app->argv[3] = 5;
1779 $result = api_statuses_repeat('json');
1780 $this->assertStatus($result['status']);
1784 * Test the api_statuses_destroy() function.
1786 * @expectedException Friendica\Network\HTTPException\BadRequestException
1788 public function testApiStatusesDestroy()
1790 api_statuses_destroy('json');
1794 * Test the api_statuses_destroy() function without an authenticated user.
1796 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1798 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1800 $_SESSION['authenticated'] = false;
1801 api_statuses_destroy('json');
1805 * Test the api_statuses_destroy() function with an ID.
1808 public function testApiStatusesDestroyWithId()
1810 $this->app->argv[3] = 1;
1811 $result = api_statuses_destroy('json');
1812 $this->assertStatus($result['status']);
1816 * Test the api_statuses_mentions() function.
1819 public function testApiStatusesMentions()
1821 $this->app->user = ['nickname' => $this->selfUser['nick']];
1822 $_REQUEST['max_id'] = 10;
1823 $result = api_statuses_mentions('json');
1824 $this->assertEmpty($result['status']);
1825 // We should test with mentions in the database.
1829 * Test the api_statuses_mentions() function with a negative page parameter.
1832 public function testApiStatusesMentionsWithNegativePage()
1834 $_REQUEST['page'] = -2;
1835 $result = api_statuses_mentions('json');
1836 $this->assertEmpty($result['status']);
1840 * Test the api_statuses_mentions() function with an unallowed user.
1842 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1844 public function testApiStatusesMentionsWithUnallowedUser()
1846 $_SESSION['allow_api'] = false;
1847 $_GET['screen_name'] = $this->selfUser['nick'];
1848 api_statuses_mentions('json');
1852 * Test the api_statuses_mentions() function with an RSS result.
1855 public function testApiStatusesMentionsWithRss()
1857 $result = api_statuses_mentions('rss');
1858 $this->assertXml($result, 'statuses');
1862 * Test the api_statuses_user_timeline() function.
1865 public function testApiStatusesUserTimeline()
1867 $_REQUEST['max_id'] = 10;
1868 $_REQUEST['exclude_replies'] = true;
1869 $_REQUEST['conversation_id'] = 1;
1870 $result = api_statuses_user_timeline('json');
1871 $this->assertNotEmpty($result['status']);
1872 foreach ($result['status'] as $status) {
1873 $this->assertStatus($status);
1878 * Test the api_statuses_user_timeline() function with a negative page parameter.
1881 public function testApiStatusesUserTimelineWithNegativePage()
1883 $_REQUEST['page'] = -2;
1884 $result = api_statuses_user_timeline('json');
1885 $this->assertNotEmpty($result['status']);
1886 foreach ($result['status'] as $status) {
1887 $this->assertStatus($status);
1892 * Test the api_statuses_user_timeline() function with an RSS result.
1895 public function testApiStatusesUserTimelineWithRss()
1897 $result = api_statuses_user_timeline('rss');
1898 $this->assertXml($result, 'statuses');
1902 * Test the api_statuses_user_timeline() function with an unallowed user.
1904 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1906 public function testApiStatusesUserTimelineWithUnallowedUser()
1908 $_SESSION['allow_api'] = false;
1909 $_GET['screen_name'] = $this->selfUser['nick'];
1910 api_statuses_user_timeline('json');
1914 * Test the api_favorites_create_destroy() function.
1916 * @expectedException Friendica\Network\HTTPException\BadRequestException
1918 public function testApiFavoritesCreateDestroy()
1920 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1921 $this->app->argc = count($this->app->argv);
1922 api_favorites_create_destroy('json');
1926 * Test the api_favorites_create_destroy() function with an invalid ID.
1928 * @expectedException Friendica\Network\HTTPException\BadRequestException
1930 public function testApiFavoritesCreateDestroyWithInvalidId()
1932 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1933 $this->app->argc = count($this->app->argv);
1934 api_favorites_create_destroy('json');
1938 * Test the api_favorites_create_destroy() function with an invalid action.
1940 * @expectedException Friendica\Network\HTTPException\BadRequestException
1942 public function testApiFavoritesCreateDestroyWithInvalidAction()
1944 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1945 $this->app->argc = count($this->app->argv);
1946 $_REQUEST['id'] = 1;
1947 api_favorites_create_destroy('json');
1951 * Test the api_favorites_create_destroy() function with the create action.
1954 public function testApiFavoritesCreateDestroyWithCreateAction()
1956 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1957 $this->app->argc = count($this->app->argv);
1958 $_REQUEST['id'] = 3;
1959 $result = api_favorites_create_destroy('json');
1960 $this->assertStatus($result['status']);
1964 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1967 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1969 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1970 $this->app->argc = count($this->app->argv);
1971 $_REQUEST['id'] = 3;
1972 $result = api_favorites_create_destroy('rss');
1973 $this->assertXml($result, 'status');
1977 * Test the api_favorites_create_destroy() function with the destroy action.
1980 public function testApiFavoritesCreateDestroyWithDestroyAction()
1982 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1983 $this->app->argc = count($this->app->argv);
1984 $_REQUEST['id'] = 3;
1985 $result = api_favorites_create_destroy('json');
1986 $this->assertStatus($result['status']);
1990 * Test the api_favorites_create_destroy() function without an authenticated user.
1992 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1994 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1996 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1997 $this->app->argc = count($this->app->argv);
1998 $_SESSION['authenticated'] = false;
1999 api_favorites_create_destroy('json');
2003 * Test the api_favorites() function.
2006 public function testApiFavorites()
2008 $_REQUEST['page'] = -1;
2009 $_REQUEST['max_id'] = 10;
2010 $result = api_favorites('json');
2011 foreach ($result['status'] as $status) {
2012 $this->assertStatus($status);
2017 * Test the api_favorites() function with an RSS result.
2020 public function testApiFavoritesWithRss()
2022 $result = api_favorites('rss');
2023 $this->assertXml($result, 'statuses');
2027 * Test the api_favorites() function with an unallowed user.
2029 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2031 public function testApiFavoritesWithUnallowedUser()
2033 $_SESSION['allow_api'] = false;
2034 $_GET['screen_name'] = $this->selfUser['nick'];
2035 api_favorites('json');
2039 * Test the api_format_messages() function.
2042 public function testApiFormatMessages()
2044 $result = api_format_messages(
2045 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2046 ['id' => 2, 'screen_name' => 'recipient_name'],
2047 ['id' => 3, 'screen_name' => 'sender_name']
2049 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2050 $this->assertEquals(1, $result['id']);
2051 $this->assertEquals(2, $result['recipient_id']);
2052 $this->assertEquals(3, $result['sender_id']);
2053 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2054 $this->assertEquals('sender_name', $result['sender_screen_name']);
2058 * Test the api_format_messages() function with HTML.
2061 public function testApiFormatMessagesWithHtmlText()
2063 $_GET['getText'] = 'html';
2064 $result = api_format_messages(
2065 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2066 ['id' => 2, 'screen_name' => 'recipient_name'],
2067 ['id' => 3, 'screen_name' => 'sender_name']
2069 $this->assertEquals('item_title', $result['title']);
2070 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2074 * Test the api_format_messages() function with plain text.
2077 public function testApiFormatMessagesWithPlainText()
2079 $_GET['getText'] = 'plain';
2080 $result = api_format_messages(
2081 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2082 ['id' => 2, 'screen_name' => 'recipient_name'],
2083 ['id' => 3, 'screen_name' => 'sender_name']
2085 $this->assertEquals('item_title', $result['title']);
2086 $this->assertEquals('item_body', $result['text']);
2090 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2093 public function testApiFormatMessagesWithoutUserObjects()
2095 $_GET['getUserObjects'] = 'false';
2096 $result = api_format_messages(
2097 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2098 ['id' => 2, 'screen_name' => 'recipient_name'],
2099 ['id' => 3, 'screen_name' => 'sender_name']
2101 $this->assertTrue(!isset($result['sender']));
2102 $this->assertTrue(!isset($result['recipient']));
2106 * Test the api_convert_item() function.
2109 public function testApiConvertItem()
2111 $result = api_convert_item(
2113 'network' => 'feed',
2114 'title' => 'item_title',
2115 // We need a long string to test that it is correctly cut
2116 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2117 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2118 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2119 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2120 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2121 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2122 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2123 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2124 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2125 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2126 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2127 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2128 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2129 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2130 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2131 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2132 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2133 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2134 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2135 'repellat officia illum quos impedit quam iste esse unde qui '.
2136 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2137 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2138 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2139 'plink' => 'item_plink'
2142 $this->assertStringStartsWith('item_title', $result['text']);
2143 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2147 * Test the api_convert_item() function with an empty item body.
2150 public function testApiConvertItemWithoutBody()
2152 $result = api_convert_item(
2154 'network' => 'feed',
2155 'title' => 'item_title',
2157 'plink' => 'item_plink'
2160 $this->assertEquals('item_title', $result['text']);
2161 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2165 * Test the api_convert_item() function with the title in the body.
2168 public function testApiConvertItemWithTitleInBody()
2170 $result = api_convert_item(
2172 'title' => 'item_title',
2173 'body' => 'item_title item_body'
2176 $this->assertEquals('item_title item_body', $result['text']);
2177 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2181 * Test the api_get_attachments() function.
2184 public function testApiGetAttachments()
2187 $this->assertEmpty(api_get_attachments($body));
2191 * Test the api_get_attachments() function with an img tag.
2194 public function testApiGetAttachmentsWithImage()
2196 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2197 $this->assertInternalType('array', api_get_attachments($body));
2201 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2204 public function testApiGetAttachmentsWithImageAndAndStatus()
2206 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2207 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2208 $this->assertInternalType('array', api_get_attachments($body));
2212 * Test the api_get_entitities() function.
2215 public function testApiGetEntitities()
2218 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2222 * Test the api_get_entitities() function with the include_entities parameter.
2225 public function testApiGetEntititiesWithIncludeEntities()
2227 $_REQUEST['include_entities'] = 'true';
2229 $result = api_get_entitities($text, 'bbcode');
2230 $this->assertInternalType('array', $result['hashtags']);
2231 $this->assertInternalType('array', $result['symbols']);
2232 $this->assertInternalType('array', $result['urls']);
2233 $this->assertInternalType('array', $result['user_mentions']);
2237 * Test the api_format_items_embeded_images() function.
2240 public function testApiFormatItemsEmbededImages()
2242 $this->assertEquals(
2243 'text ' . System::baseUrl() . '/display/item_guid',
2244 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2249 * Test the api_contactlink_to_array() function.
2252 public function testApiContactlinkToArray()
2254 $this->assertEquals(
2259 api_contactlink_to_array('text')
2264 * Test the api_contactlink_to_array() function with an URL.
2267 public function testApiContactlinkToArrayWithUrl()
2269 $this->assertEquals(
2271 'name' => ['link_text'],
2274 api_contactlink_to_array('text <a href="url">link_text</a>')
2279 * Test the api_format_items_activities() function.
2282 public function testApiFormatItemsActivities()
2284 $item = ['uid' => 0, 'uri' => ''];
2285 $result = api_format_items_activities($item);
2286 $this->assertArrayHasKey('like', $result);
2287 $this->assertArrayHasKey('dislike', $result);
2288 $this->assertArrayHasKey('attendyes', $result);
2289 $this->assertArrayHasKey('attendno', $result);
2290 $this->assertArrayHasKey('attendmaybe', $result);
2294 * Test the api_format_items_activities() function with an XML result.
2297 public function testApiFormatItemsActivitiesWithXml()
2299 $item = ['uid' => 0, 'uri' => ''];
2300 $result = api_format_items_activities($item, 'xml');
2301 $this->assertArrayHasKey('friendica:like', $result);
2302 $this->assertArrayHasKey('friendica:dislike', $result);
2303 $this->assertArrayHasKey('friendica:attendyes', $result);
2304 $this->assertArrayHasKey('friendica:attendno', $result);
2305 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2309 * Test the api_format_items_profiles() function.
2312 public function testApiFormatItemsProfiles()
2315 'id' => 'profile_id',
2316 'profile-name' => 'profile_name',
2317 'is-default' => true,
2318 'hide-friends' => true,
2319 'photo' => 'profile_photo',
2320 'thumb' => 'profile_thumb',
2322 'net-publish' => true,
2323 'pdesc' => 'description',
2324 'dob' => 'date_of_birth',
2325 'address' => 'address',
2326 'locality' => 'city',
2327 'region' => 'region',
2328 'postal-code' => 'postal_code',
2329 'country-name' => 'country',
2330 'hometown' => 'hometown',
2331 'gender' => 'gender',
2332 'marital' => 'marital',
2333 'with' => 'marital_with',
2334 'howlong' => 'marital_since',
2335 'sexual' => 'sexual',
2336 'politic' => 'politic',
2337 'religion' => 'religion',
2338 'pub_keywords' => 'public_keywords',
2339 'prv_keywords' => 'private_keywords',
2342 'dislikes' => 'dislikes',
2348 'interest' => 'interest',
2349 'romance' => 'romance',
2351 'education' => 'education',
2352 'contact' => 'social_networks',
2353 'homepage' => 'homepage'
2355 $result = api_format_items_profiles($profile_row);
2356 $this->assertEquals(
2358 'profile_id' => 'profile_id',
2359 'profile_name' => 'profile_name',
2360 'is_default' => true,
2361 'hide_friends' => true,
2362 'profile_photo' => 'profile_photo',
2363 'profile_thumb' => 'profile_thumb',
2365 'net_publish' => true,
2366 'description' => 'description',
2367 'date_of_birth' => 'date_of_birth',
2368 'address' => 'address',
2370 'region' => 'region',
2371 'postal_code' => 'postal_code',
2372 'country' => 'country',
2373 'hometown' => 'hometown',
2374 'gender' => 'gender',
2375 'marital' => 'marital',
2376 'marital_with' => 'marital_with',
2377 'marital_since' => 'marital_since',
2378 'sexual' => 'sexual',
2379 'politic' => 'politic',
2380 'religion' => 'religion',
2381 'public_keywords' => 'public_keywords',
2382 'private_keywords' => 'private_keywords',
2385 'dislikes' => 'dislikes',
2391 'interest' => 'interest',
2392 'romance' => 'romance',
2394 'education' => 'education',
2395 'social_networks' => 'social_networks',
2396 'homepage' => 'homepage',
2404 * Test the api_format_items() function.
2407 public function testApiFormatItems()
2411 'item_network' => 'item_network',
2417 'author-network' => Protocol::DFRN,
2418 'author-link' => 'http://localhost/profile/othercontact',
2422 $result = api_format_items($items, ['id' => 0], true);
2423 foreach ($result as $status) {
2424 $this->assertStatus($status);
2429 * Test the api_format_items() function with an XML result.
2432 public function testApiFormatItemsWithXml()
2440 'author-network' => Protocol::DFRN,
2441 'author-link' => 'http://localhost/profile/othercontact',
2445 $result = api_format_items($items, ['id' => 0], true, 'xml');
2446 foreach ($result as $status) {
2447 $this->assertStatus($status);
2452 * Test the api_format_items() function.
2455 public function testApiAccountRateLimitStatus()
2457 $result = api_account_rate_limit_status('json');
2458 $this->assertEquals(150, $result['hash']['remaining_hits']);
2459 $this->assertEquals(150, $result['hash']['hourly_limit']);
2460 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2464 * Test the api_format_items() function with an XML result.
2467 public function testApiAccountRateLimitStatusWithXml()
2469 $result = api_account_rate_limit_status('xml');
2470 $this->assertXml($result, 'hash');
2474 * Test the api_help_test() function.
2477 public function testApiHelpTest()
2479 $result = api_help_test('json');
2480 $this->assertEquals(['ok' => 'ok'], $result);
2484 * Test the api_help_test() function with an XML result.
2487 public function testApiHelpTestWithXml()
2489 $result = api_help_test('xml');
2490 $this->assertXml($result, 'ok');
2494 * Test the api_lists_list() function.
2497 public function testApiListsList()
2499 $result = api_lists_list('json');
2500 $this->assertEquals(['lists_list' => []], $result);
2504 * Test the api_lists_ownerships() function.
2507 public function testApiListsOwnerships()
2509 $result = api_lists_ownerships('json');
2510 foreach ($result['lists']['lists'] as $list) {
2511 $this->assertList($list);
2516 * Test the api_lists_ownerships() function without an authenticated user.
2518 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2520 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2522 $_SESSION['authenticated'] = false;
2523 api_lists_ownerships('json');
2527 * Test the api_lists_statuses() function.
2528 * @expectedException Friendica\Network\HTTPException\BadRequestException
2531 public function testApiListsStatuses()
2533 api_lists_statuses('json');
2537 * Test the api_lists_statuses() function with a list ID.
2540 public function testApiListsStatusesWithListId()
2542 $_REQUEST['list_id'] = 1;
2543 $_REQUEST['page'] = -1;
2544 $_REQUEST['max_id'] = 10;
2545 $result = api_lists_statuses('json');
2546 foreach ($result['status'] as $status) {
2547 $this->assertStatus($status);
2552 * Test the api_lists_statuses() function with a list ID and a RSS result.
2555 public function testApiListsStatusesWithListIdAndRss()
2557 $_REQUEST['list_id'] = 1;
2558 $result = api_lists_statuses('rss');
2559 $this->assertXml($result, 'statuses');
2563 * Test the api_lists_statuses() function with an unallowed user.
2565 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2567 public function testApiListsStatusesWithUnallowedUser()
2569 $_SESSION['allow_api'] = false;
2570 $_GET['screen_name'] = $this->selfUser['nick'];
2571 api_lists_statuses('json');
2575 * Test the api_statuses_f() function.
2578 public function testApiStatusesFWithFriends()
2581 $result = api_statuses_f('friends');
2582 $this->assertArrayHasKey('user', $result);
2586 * Test the api_statuses_f() function.
2589 public function testApiStatusesFWithFollowers()
2591 $result = api_statuses_f('followers');
2592 $this->assertArrayHasKey('user', $result);
2596 * Test the api_statuses_f() function.
2599 public function testApiStatusesFWithBlocks()
2601 $result = api_statuses_f('blocks');
2602 $this->assertArrayHasKey('user', $result);
2606 * Test the api_statuses_f() function.
2609 public function testApiStatusesFWithIncoming()
2611 $result = api_statuses_f('incoming');
2612 $this->assertArrayHasKey('user', $result);
2616 * Test the api_statuses_f() function an undefined cursor GET variable.
2619 public function testApiStatusesFWithUndefinedCursor()
2621 $_GET['cursor'] = 'undefined';
2622 $this->assertFalse(api_statuses_f('friends'));
2626 * Test the api_statuses_friends() function.
2629 public function testApiStatusesFriends()
2631 $result = api_statuses_friends('json');
2632 $this->assertArrayHasKey('user', $result);
2636 * Test the api_statuses_friends() function an undefined cursor GET variable.
2639 public function testApiStatusesFriendsWithUndefinedCursor()
2641 $_GET['cursor'] = 'undefined';
2642 $this->assertFalse(api_statuses_friends('json'));
2646 * Test the api_statuses_followers() function.
2649 public function testApiStatusesFollowers()
2651 $result = api_statuses_followers('json');
2652 $this->assertArrayHasKey('user', $result);
2656 * Test the api_statuses_followers() function an undefined cursor GET variable.
2659 public function testApiStatusesFollowersWithUndefinedCursor()
2661 $_GET['cursor'] = 'undefined';
2662 $this->assertFalse(api_statuses_followers('json'));
2666 * Test the api_blocks_list() function.
2669 public function testApiBlocksList()
2671 $result = api_blocks_list('json');
2672 $this->assertArrayHasKey('user', $result);
2676 * Test the api_blocks_list() function an undefined cursor GET variable.
2679 public function testApiBlocksListWithUndefinedCursor()
2681 $_GET['cursor'] = 'undefined';
2682 $this->assertFalse(api_blocks_list('json'));
2686 * Test the api_friendships_incoming() function.
2689 public function testApiFriendshipsIncoming()
2691 $result = api_friendships_incoming('json');
2692 $this->assertArrayHasKey('id', $result);
2696 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2699 public function testApiFriendshipsIncomingWithUndefinedCursor()
2701 $_GET['cursor'] = 'undefined';
2702 $this->assertFalse(api_friendships_incoming('json'));
2706 * Test the api_statusnet_config() function.
2709 public function testApiStatusnetConfig()
2711 $result = api_statusnet_config('json');
2712 $this->assertEquals('localhost', $result['config']['site']['server']);
2713 $this->assertEquals('default', $result['config']['site']['theme']);
2714 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2715 $this->assertTrue($result['config']['site']['fancy']);
2716 $this->assertEquals('en', $result['config']['site']['language']);
2717 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2718 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2719 $this->assertEquals('false', $result['config']['site']['private']);
2720 $this->assertEquals('false', $result['config']['site']['ssl']);
2721 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2725 * Test the api_statusnet_version() function.
2728 public function testApiStatusnetVersion()
2730 $result = api_statusnet_version('json');
2731 $this->assertEquals('0.9.7', $result['version']);
2735 * Test the api_ff_ids() function.
2738 public function testApiFfIds()
2740 $result = api_ff_ids('json');
2741 $this->assertNull($result);
2745 * Test the api_ff_ids() function with a result.
2748 public function testApiFfIdsWithResult()
2750 $this->markTestIncomplete();
2754 * Test the api_ff_ids() function without an authenticated user.
2756 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2758 public function testApiFfIdsWithoutAuthenticatedUser()
2760 $_SESSION['authenticated'] = false;
2765 * Test the api_friends_ids() function.
2768 public function testApiFriendsIds()
2770 $result = api_friends_ids('json');
2771 $this->assertNull($result);
2775 * Test the api_followers_ids() function.
2778 public function testApiFollowersIds()
2780 $result = api_followers_ids('json');
2781 $this->assertNull($result);
2785 * Test the api_direct_messages_new() function.
2788 public function testApiDirectMessagesNew()
2790 $result = api_direct_messages_new('json');
2791 $this->assertNull($result);
2795 * Test the api_direct_messages_new() function without an authenticated user.
2797 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2799 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2801 $_SESSION['authenticated'] = false;
2802 api_direct_messages_new('json');
2806 * Test the api_direct_messages_new() function with an user ID.
2809 public function testApiDirectMessagesNewWithUserId()
2811 $_POST['text'] = 'message_text';
2812 $_POST['user_id'] = $this->otherUser['id'];
2813 $result = api_direct_messages_new('json');
2814 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2818 * Test the api_direct_messages_new() function with a screen name.
2821 public function testApiDirectMessagesNewWithScreenName()
2823 $_POST['text'] = 'message_text';
2824 $_POST['screen_name'] = $this->friendUser['nick'];
2825 $result = api_direct_messages_new('json');
2826 $this->assertEquals(1, $result['direct_message']['id']);
2827 $this->assertContains('message_text', $result['direct_message']['text']);
2828 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2829 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2833 * Test the api_direct_messages_new() function with a title.
2836 public function testApiDirectMessagesNewWithTitle()
2838 $_POST['text'] = 'message_text';
2839 $_POST['screen_name'] = $this->friendUser['nick'];
2840 $_REQUEST['title'] = 'message_title';
2841 $result = api_direct_messages_new('json');
2842 $this->assertEquals(1, $result['direct_message']['id']);
2843 $this->assertContains('message_text', $result['direct_message']['text']);
2844 $this->assertContains('message_title', $result['direct_message']['text']);
2845 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2846 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2850 * Test the api_direct_messages_new() function with an RSS result.
2853 public function testApiDirectMessagesNewWithRss()
2855 $_POST['text'] = 'message_text';
2856 $_POST['screen_name'] = $this->friendUser['nick'];
2857 $result = api_direct_messages_new('rss');
2858 $this->assertXml($result, 'direct-messages');
2862 * Test the api_direct_messages_destroy() function.
2864 * @expectedException Friendica\Network\HTTPException\BadRequestException
2866 public function testApiDirectMessagesDestroy()
2868 api_direct_messages_destroy('json');
2872 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2875 public function testApiDirectMessagesDestroyWithVerbose()
2877 $_GET['friendica_verbose'] = 'true';
2878 $result = api_direct_messages_destroy('json');
2879 $this->assertEquals(
2882 'result' => 'error',
2883 'message' => 'message id or parenturi not specified'
2891 * Test the api_direct_messages_destroy() function without an authenticated user.
2893 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2895 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2897 $_SESSION['authenticated'] = false;
2898 api_direct_messages_destroy('json');
2902 * Test the api_direct_messages_destroy() function with a non-zero ID.
2904 * @expectedException Friendica\Network\HTTPException\BadRequestException
2906 public function testApiDirectMessagesDestroyWithId()
2908 $_REQUEST['id'] = 1;
2909 api_direct_messages_destroy('json');
2913 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2916 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2918 $_REQUEST['id'] = 1;
2919 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2920 $_GET['friendica_verbose'] = 'true';
2921 $result = api_direct_messages_destroy('json');
2922 $this->assertEquals(
2925 'result' => 'error',
2926 'message' => 'message id not in database'
2934 * Test the api_direct_messages_destroy() function with a non-zero ID.
2937 public function testApiDirectMessagesDestroyWithCorrectId()
2939 $this->markTestIncomplete('We need to add a dataset for this.');
2943 * Test the api_direct_messages_box() function.
2946 public function testApiDirectMessagesBoxWithSentbox()
2948 $_REQUEST['page'] = -1;
2949 $_REQUEST['max_id'] = 10;
2950 $result = api_direct_messages_box('json', 'sentbox', 'false');
2951 $this->assertArrayHasKey('direct_message', $result);
2955 * Test the api_direct_messages_box() function.
2958 public function testApiDirectMessagesBoxWithConversation()
2960 $result = api_direct_messages_box('json', 'conversation', 'false');
2961 $this->assertArrayHasKey('direct_message', $result);
2965 * Test the api_direct_messages_box() function.
2968 public function testApiDirectMessagesBoxWithAll()
2970 $result = api_direct_messages_box('json', 'all', 'false');
2971 $this->assertArrayHasKey('direct_message', $result);
2975 * Test the api_direct_messages_box() function.
2978 public function testApiDirectMessagesBoxWithInbox()
2980 $result = api_direct_messages_box('json', 'inbox', 'false');
2981 $this->assertArrayHasKey('direct_message', $result);
2985 * Test the api_direct_messages_box() function.
2988 public function testApiDirectMessagesBoxWithVerbose()
2990 $result = api_direct_messages_box('json', 'sentbox', 'true');
2991 $this->assertEquals(
2994 'result' => 'error',
2995 'message' => 'no mails available'
3003 * Test the api_direct_messages_box() function with a RSS result.
3006 public function testApiDirectMessagesBoxWithRss()
3008 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3009 $this->assertXml($result, 'direct-messages');
3013 * Test the api_direct_messages_box() function without an authenticated user.
3015 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3017 public function testApiDirectMessagesBoxWithUnallowedUser()
3019 $_SESSION['allow_api'] = false;
3020 $_GET['screen_name'] = $this->selfUser['nick'];
3021 api_direct_messages_box('json', 'sentbox', 'false');
3025 * Test the api_direct_messages_sentbox() function.
3028 public function testApiDirectMessagesSentbox()
3030 $result = api_direct_messages_sentbox('json');
3031 $this->assertArrayHasKey('direct_message', $result);
3035 * Test the api_direct_messages_inbox() function.
3038 public function testApiDirectMessagesInbox()
3040 $result = api_direct_messages_inbox('json');
3041 $this->assertArrayHasKey('direct_message', $result);
3045 * Test the api_direct_messages_all() function.
3048 public function testApiDirectMessagesAll()
3050 $result = api_direct_messages_all('json');
3051 $this->assertArrayHasKey('direct_message', $result);
3055 * Test the api_direct_messages_conversation() function.
3058 public function testApiDirectMessagesConversation()
3060 $result = api_direct_messages_conversation('json');
3061 $this->assertArrayHasKey('direct_message', $result);
3065 * Test the api_oauth_request_token() function.
3068 public function testApiOauthRequestToken()
3070 $this->markTestIncomplete('killme() kills phpunit as well');
3074 * Test the api_oauth_access_token() function.
3077 public function testApiOauthAccessToken()
3079 $this->markTestIncomplete('killme() kills phpunit as well');
3083 * Test the api_fr_photoalbum_delete() function.
3085 * @expectedException Friendica\Network\HTTPException\BadRequestException
3087 public function testApiFrPhotoalbumDelete()
3089 api_fr_photoalbum_delete('json');
3093 * Test the api_fr_photoalbum_delete() function with an album name.
3095 * @expectedException Friendica\Network\HTTPException\BadRequestException
3097 public function testApiFrPhotoalbumDeleteWithAlbum()
3099 $_REQUEST['album'] = 'album_name';
3100 api_fr_photoalbum_delete('json');
3104 * Test the api_fr_photoalbum_delete() function with an album name.
3107 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3109 $this->markTestIncomplete('We need to add a dataset for this.');
3113 * Test the api_fr_photoalbum_delete() function.
3115 * @expectedException Friendica\Network\HTTPException\BadRequestException
3117 public function testApiFrPhotoalbumUpdate()
3119 api_fr_photoalbum_update('json');
3123 * Test the api_fr_photoalbum_delete() function with an album name.
3125 * @expectedException Friendica\Network\HTTPException\BadRequestException
3127 public function testApiFrPhotoalbumUpdateWithAlbum()
3129 $_REQUEST['album'] = 'album_name';
3130 api_fr_photoalbum_update('json');
3134 * Test the api_fr_photoalbum_delete() function with an album name.
3136 * @expectedException Friendica\Network\HTTPException\BadRequestException
3138 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3140 $_REQUEST['album'] = 'album_name';
3141 $_REQUEST['album_new'] = 'album_name';
3142 api_fr_photoalbum_update('json');
3146 * Test the api_fr_photoalbum_update() function without an authenticated user.
3148 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3150 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3152 $_SESSION['authenticated'] = false;
3153 api_fr_photoalbum_update('json');
3157 * Test the api_fr_photoalbum_delete() function with an album name.
3160 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3162 $this->markTestIncomplete('We need to add a dataset for this.');
3166 * Test the api_fr_photos_list() function.
3169 public function testApiFrPhotosList()
3171 $result = api_fr_photos_list('json');
3172 $this->assertArrayHasKey('photo', $result);
3176 * Test the api_fr_photos_list() function without an authenticated user.
3178 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3180 public function testApiFrPhotosListWithoutAuthenticatedUser()
3182 $_SESSION['authenticated'] = false;
3183 api_fr_photos_list('json');
3187 * Test the api_fr_photo_create_update() function.
3189 * @expectedException Friendica\Network\HTTPException\BadRequestException
3191 public function testApiFrPhotoCreateUpdate()
3193 api_fr_photo_create_update('json');
3197 * Test the api_fr_photo_create_update() function without an authenticated user.
3199 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3201 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3203 $_SESSION['authenticated'] = false;
3204 api_fr_photo_create_update('json');
3208 * Test the api_fr_photo_create_update() function with an album name.
3210 * @expectedException Friendica\Network\HTTPException\BadRequestException
3212 public function testApiFrPhotoCreateUpdateWithAlbum()
3214 $_REQUEST['album'] = 'album_name';
3215 api_fr_photo_create_update('json');
3219 * Test the api_fr_photo_create_update() function with the update mode.
3222 public function testApiFrPhotoCreateUpdateWithUpdate()
3224 $this->markTestIncomplete('We need to create a dataset for this');
3228 * Test the api_fr_photo_create_update() function with an uploaded file.
3231 public function testApiFrPhotoCreateUpdateWithFile()
3233 $this->markTestIncomplete();
3237 * Test the api_fr_photo_delete() function.
3239 * @expectedException Friendica\Network\HTTPException\BadRequestException
3241 public function testApiFrPhotoDelete()
3243 api_fr_photo_delete('json');
3247 * Test the api_fr_photo_delete() function without an authenticated user.
3249 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3251 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3253 $_SESSION['authenticated'] = false;
3254 api_fr_photo_delete('json');
3258 * Test the api_fr_photo_delete() function with a photo ID.
3260 * @expectedException Friendica\Network\HTTPException\BadRequestException
3262 public function testApiFrPhotoDeleteWithPhotoId()
3264 $_REQUEST['photo_id'] = 1;
3265 api_fr_photo_delete('json');
3269 * Test the api_fr_photo_delete() function with a correct photo ID.
3272 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3274 $this->markTestIncomplete('We need to create a dataset for this.');
3278 * Test the api_fr_photo_detail() function.
3280 * @expectedException Friendica\Network\HTTPException\BadRequestException
3282 public function testApiFrPhotoDetail()
3284 api_fr_photo_detail('json');
3288 * Test the api_fr_photo_detail() function without an authenticated user.
3290 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3292 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3294 $_SESSION['authenticated'] = false;
3295 api_fr_photo_detail('json');
3299 * Test the api_fr_photo_detail() function with a photo ID.
3301 * @expectedException Friendica\Network\HTTPException\NotFoundException
3303 public function testApiFrPhotoDetailWithPhotoId()
3305 $_REQUEST['photo_id'] = 1;
3306 api_fr_photo_detail('json');
3310 * Test the api_fr_photo_detail() function with a correct photo ID.
3313 public function testApiFrPhotoDetailCorrectPhotoId()
3315 $this->markTestIncomplete('We need to create a dataset for this.');
3319 * Test the api_account_update_profile_image() function.
3321 * @expectedException Friendica\Network\HTTPException\BadRequestException
3323 public function testApiAccountUpdateProfileImage()
3325 api_account_update_profile_image('json');
3329 * Test the api_account_update_profile_image() function without an authenticated user.
3331 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3333 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3335 $_SESSION['authenticated'] = false;
3336 api_account_update_profile_image('json');
3340 * Test the api_account_update_profile_image() function with an uploaded file.
3342 * @expectedException Friendica\Network\HTTPException\BadRequestException
3344 public function testApiAccountUpdateProfileImageWithUpload()
3346 $this->markTestIncomplete();
3351 * Test the api_account_update_profile() function.
3354 public function testApiAccountUpdateProfile()
3356 $_POST['name'] = 'new_name';
3357 $_POST['description'] = 'new_description';
3358 $result = api_account_update_profile('json');
3359 // We can't use assertSelfUser() here because the user object is missing some properties.
3360 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3361 $this->assertEquals('DFRN', $result['user']['location']);
3362 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3363 $this->assertEquals('dfrn', $result['user']['network']);
3364 $this->assertEquals('new_name', $result['user']['name']);
3365 $this->assertEquals('new_description', $result['user']['description']);
3369 * Test the check_acl_input() function.
3372 public function testCheckAclInput()
3374 $result = check_acl_input('<aclstring>');
3375 // Where does this result come from?
3376 $this->assertEquals(1, $result);
3380 * Test the check_acl_input() function with an empty ACL string.
3383 public function testCheckAclInputWithEmptyAclString()
3385 $result = check_acl_input(' ');
3386 $this->assertFalse($result);
3390 * Test the save_media_to_database() function.
3393 public function testSaveMediaToDatabase()
3395 $this->markTestIncomplete();
3399 * Test the post_photo_item() function.
3402 public function testPostPhotoItem()
3404 $this->markTestIncomplete();
3408 * Test the prepare_photo_data() function.
3411 public function testPreparePhotoData()
3413 $this->markTestIncomplete();
3417 * Test the api_friendica_remoteauth() function.
3419 * @expectedException Friendica\Network\HTTPException\BadRequestException
3421 public function testApiFriendicaRemoteauth()
3423 api_friendica_remoteauth();
3427 * Test the api_friendica_remoteauth() function with an URL.
3429 * @expectedException Friendica\Network\HTTPException\BadRequestException
3431 public function testApiFriendicaRemoteauthWithUrl()
3433 $_GET['url'] = 'url';
3434 $_GET['c_url'] = 'url';
3435 api_friendica_remoteauth();
3439 * Test the api_friendica_remoteauth() function with a correct URL.
3442 public function testApiFriendicaRemoteauthWithCorrectUrl()
3444 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3445 $_GET['url'] = 'url';
3446 $_GET['c_url'] = $this->selfUser['nurl'];
3447 api_friendica_remoteauth();
3451 * Test the api_share_as_retweet() function.
3454 public function testApiShareAsRetweet()
3456 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3457 $result = api_share_as_retweet($item);
3458 $this->assertFalse($result);
3462 * Test the api_share_as_retweet() function with a valid item.
3465 public function testApiShareAsRetweetWithValidItem()
3467 $this->markTestIncomplete();
3471 * Test the api_get_nick() function.
3474 public function testApiGetNick()
3476 $result = api_get_nick($this->otherUser['nurl']);
3477 $this->assertEquals('othercontact', $result);
3481 * Test the api_get_nick() function with a wrong URL.
3484 public function testApiGetNickWithWrongUrl()
3486 $result = api_get_nick('wrong_url');
3487 $this->assertFalse($result);
3491 * Test the api_in_reply_to() function.
3494 public function testApiInReplyTo()
3496 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3497 $this->assertArrayHasKey('status_id', $result);
3498 $this->assertArrayHasKey('user_id', $result);
3499 $this->assertArrayHasKey('status_id_str', $result);
3500 $this->assertArrayHasKey('user_id_str', $result);
3501 $this->assertArrayHasKey('screen_name', $result);
3505 * Test the api_in_reply_to() function with a valid item.
3508 public function testApiInReplyToWithValidItem()
3510 $this->markTestIncomplete();
3514 * Test the api_clean_plain_items() function.
3517 public function testApiCleanPlainItems()
3519 $_REQUEST['include_entities'] = 'true';
3520 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3521 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3525 * Test the api_clean_attachments() function.
3528 public function testApiCleanAttachments()
3530 $this->markTestIncomplete();
3534 * Test the api_best_nickname() function.
3537 public function testApiBestNickname()
3540 $result = api_best_nickname($contacts);
3541 $this->assertNull($result);
3545 * Test the api_best_nickname() function with contacts.
3548 public function testApiBestNicknameWithContacts()
3550 $this->markTestIncomplete();
3554 * Test the api_friendica_group_show() function.
3557 public function testApiFriendicaGroupShow()
3559 $this->markTestIncomplete();
3563 * Test the api_friendica_group_delete() function.
3566 public function testApiFriendicaGroupDelete()
3568 $this->markTestIncomplete();
3572 * Test the api_lists_destroy() function.
3575 public function testApiListsDestroy()
3577 $this->markTestIncomplete();
3581 * Test the group_create() function.
3584 public function testGroupCreate()
3586 $this->markTestIncomplete();
3590 * Test the api_friendica_group_create() function.
3593 public function testApiFriendicaGroupCreate()
3595 $this->markTestIncomplete();
3599 * Test the api_lists_create() function.
3602 public function testApiListsCreate()
3604 $this->markTestIncomplete();
3608 * Test the api_friendica_group_update() function.
3611 public function testApiFriendicaGroupUpdate()
3613 $this->markTestIncomplete();
3617 * Test the api_lists_update() function.
3620 public function testApiListsUpdate()
3622 $this->markTestIncomplete();
3626 * Test the api_friendica_activity() function.
3629 public function testApiFriendicaActivity()
3631 $this->markTestIncomplete();
3635 * Test the api_friendica_notification() function.
3637 * @expectedException Friendica\Network\HTTPException\BadRequestException
3639 public function testApiFriendicaNotification()
3641 api_friendica_notification('json');
3645 * Test the api_friendica_notification() function without an authenticated user.
3647 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3649 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3651 $_SESSION['authenticated'] = false;
3652 api_friendica_notification('json');
3656 * Test the api_friendica_notification() function with an argument count.
3659 public function testApiFriendicaNotificationWithArgumentCount()
3661 $this->app->argv = ['api', 'friendica', 'notification'];
3662 $this->app->argc = count($this->app->argv);
3663 $result = api_friendica_notification('json');
3664 $this->assertEquals(['note' => false], $result);
3668 * Test the api_friendica_notification() function with an XML result.
3671 public function testApiFriendicaNotificationWithXmlResult()
3673 $this->app->argv = ['api', 'friendica', 'notification'];
3674 $this->app->argc = count($this->app->argv);
3675 $result = api_friendica_notification('xml');
3676 $this->assertXml($result, 'notes');
3680 * Test the api_friendica_notification_seen() function.
3683 public function testApiFriendicaNotificationSeen()
3685 $this->markTestIncomplete();
3689 * Test the api_friendica_direct_messages_setseen() function.
3692 public function testApiFriendicaDirectMessagesSetseen()
3694 $this->markTestIncomplete();
3698 * Test the api_friendica_direct_messages_search() function.
3701 public function testApiFriendicaDirectMessagesSearch()
3703 $this->markTestIncomplete();
3707 * Test the api_friendica_profile_show() function.
3710 public function testApiFriendicaProfileShow()
3712 $result = api_friendica_profile_show('json');
3713 // We can't use assertSelfUser() here because the user object is missing some properties.
3714 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3715 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3716 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3717 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3718 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3719 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3720 $this->assertFalse($result['$result']['multi_profiles']);
3724 * Test the api_friendica_profile_show() function with a profile ID.
3727 public function testApiFriendicaProfileShowWithProfileId()
3729 $this->markTestIncomplete('We need to add a dataset for this.');
3733 * Test the api_friendica_profile_show() function with a wrong profile ID.
3735 * @expectedException Friendica\Network\HTTPException\BadRequestException
3737 public function testApiFriendicaProfileShowWithWrongProfileId()
3739 $_REQUEST['profile_id'] = 666;
3740 api_friendica_profile_show('json');
3744 * Test the api_friendica_profile_show() function without an authenticated user.
3746 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3748 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3750 $_SESSION['authenticated'] = false;
3751 api_friendica_profile_show('json');
3755 * Test the api_saved_searches_list() function.
3758 public function testApiSavedSearchesList()
3760 $result = api_saved_searches_list('json');
3761 $this->assertEquals(1, $result['terms'][0]['id']);
3762 $this->assertEquals(1, $result['terms'][0]['id_str']);
3763 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3764 $this->assertEquals('Saved search', $result['terms'][0]['query']);