6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\Config\Cache;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\System;
14 use Friendica\Factory;
15 use Friendica\Network\HTTPException;
16 use Friendica\Util\BasePath;
17 use Monolog\Handler\TestHandler;
19 require_once __DIR__ . '/../../include/api.php';
22 * Tests for the API functions.
24 * Functions that use header() need to be tested in a separate process.
25 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
27 class ApiTest extends DatabaseTest
30 * @var TestHandler Can handle log-outputs
35 * Create variables used by tests.
37 public function setUp()
39 $basePath = BasePath::create(dirname(__DIR__) . '/../');
40 $configLoader = new Cache\ConfigCacheLoader($basePath);
41 $configCache = Factory\ConfigFactory::createCache($configLoader);
42 $profiler = Factory\ProfilerFactory::create($configCache);
43 Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
44 $config = Factory\ConfigFactory::createConfig($configCache);
45 Factory\ConfigFactory::createPConfig($configCache);
46 $logger = Factory\LoggerFactory::create('test', $config);
47 $this->app = new App($basePath, $config, $logger, $profiler, false);
51 // User data that the test database is populated with
54 'name' => 'Self contact',
55 'nick' => 'selfcontact',
56 'nurl' => 'http://localhost/profile/selfcontact'
60 'name' => 'Friend contact',
61 'nick' => 'friendcontact',
62 'nurl' => 'http://localhost/profile/friendcontact'
66 'name' => 'othercontact',
67 'nick' => 'othercontact',
68 'nurl' => 'http://localhost/profile/othercontact'
71 // User ID that we know is not in the database
72 $this->wrongUserId = 666;
74 // Most API require login so we force the session
77 'authenticated' => true,
78 'uid' => $this->selfUser['id']
81 Config::set('system', 'url', 'http://localhost');
82 Config::set('system', 'hostname', 'localhost');
83 Config::set('system', 'worker_dont_fork', true);
86 Config::set('config', 'hostname', 'localhost');
87 Config::set('system', 'throttle_limit_day', 100);
88 Config::set('system', 'throttle_limit_week', 100);
89 Config::set('system', 'throttle_limit_month', 100);
90 Config::set('system', 'theme', 'system_theme');
94 * Cleanup variables used by tests.
96 protected function tearDown()
100 $this->app->argc = 1;
101 $this->app->argv = ['home'];
105 * Assert that an user array contains expected keys.
106 * @param array $user User array
109 private function assertSelfUser(array $user)
111 $this->assertEquals($this->selfUser['id'], $user['uid']);
112 $this->assertEquals($this->selfUser['id'], $user['cid']);
113 $this->assertEquals(1, $user['self']);
114 $this->assertEquals('DFRN', $user['location']);
115 $this->assertEquals($this->selfUser['name'], $user['name']);
116 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
117 $this->assertEquals('dfrn', $user['network']);
118 $this->assertTrue($user['verified']);
122 * Assert that an user array contains expected keys.
123 * @param array $user User array
126 private function assertOtherUser(array $user)
128 $this->assertEquals($this->otherUser['id'], $user['id']);
129 $this->assertEquals($this->otherUser['id'], $user['id_str']);
130 $this->assertEquals(0, $user['self']);
131 $this->assertEquals($this->otherUser['name'], $user['name']);
132 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
133 $this->assertFalse($user['verified']);
137 * Assert that a status array contains expected keys.
138 * @param array $status Status array
141 private function assertStatus(array $status)
143 $this->assertInternalType('string', $status['text']);
144 $this->assertInternalType('int', $status['id']);
145 // We could probably do more checks here.
149 * Assert that a list array contains expected keys.
150 * @param array $list List array
153 private function assertList(array $list)
155 $this->assertInternalType('string', $list['name']);
156 $this->assertInternalType('int', $list['id']);
157 $this->assertInternalType('string', $list['id_str']);
158 $this->assertContains($list['mode'], ['public', 'private']);
159 // We could probably do more checks here.
163 * Assert that the string is XML and contain the root element.
164 * @param string $result XML string
165 * @param string $root_element Root element name
168 private function assertXml($result, $root_element)
170 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
171 $this->assertContains('<'.$root_element, $result);
172 // We could probably do more checks here.
176 * Get the path to a temporary empty PNG image.
177 * @return string Path
179 private function getTempImage()
181 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
185 // Empty 1x1 px PNG image
186 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
194 * Test the api_user() function.
197 public function testApiUser()
199 $this->assertEquals($this->selfUser['id'], api_user());
203 * Test the api_user() function with an unallowed user.
206 public function testApiUserWithUnallowedUser()
208 $_SESSION = ['allow_api' => false];
209 $this->assertEquals(false, api_user());
213 * Test the api_source() function.
216 public function testApiSource()
218 $this->assertEquals('api', api_source());
222 * Test the api_source() function with a Twidere user agent.
225 public function testApiSourceWithTwidere()
227 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
228 $this->assertEquals('Twidere', api_source());
232 * Test the api_source() function with a GET parameter.
235 public function testApiSourceWithGet()
237 $_GET['source'] = 'source_name';
238 $this->assertEquals('source_name', api_source());
242 * Test the api_date() function.
245 public function testApiDate()
247 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
251 * Test the api_register_func() function.
254 public function testApiRegisterFunc()
266 $this->assertTrue($API['api_path']['auth']);
267 $this->assertEquals('method', $API['api_path']['method']);
268 $this->assertTrue(is_callable($API['api_path']['func']));
272 * Test the api_login() function without any login.
274 * @runInSeparateProcess
275 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
277 public function testApiLoginWithoutLogin()
279 api_login($this->app);
283 * Test the api_login() function with a bad login.
285 * @runInSeparateProcess
286 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
288 public function testApiLoginWithBadLogin()
290 $_SERVER['PHP_AUTH_USER'] = 'user@server';
291 api_login($this->app);
295 * Test the api_login() function with oAuth.
298 public function testApiLoginWithOauth()
300 $this->markTestIncomplete('Can we test this easily?');
304 * Test the api_login() function with authentication provided by an addon.
307 public function testApiLoginWithAddonAuth()
309 $this->markTestIncomplete('Can we test this easily?');
313 * Test the api_login() function with a correct login.
315 * @runInSeparateProcess
317 public function testApiLoginWithCorrectLogin()
319 $_SERVER['PHP_AUTH_USER'] = 'Test user';
320 $_SERVER['PHP_AUTH_PW'] = 'password';
321 api_login($this->app);
325 * Test the api_login() function with a remote user.
327 * @runInSeparateProcess
328 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
330 public function testApiLoginWithRemoteUser()
332 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
333 api_login($this->app);
337 * Test the api_check_method() function.
340 public function testApiCheckMethod()
342 $this->assertFalse(api_check_method('method'));
346 * Test the api_check_method() function with a correct method.
349 public function testApiCheckMethodWithCorrectMethod()
351 $_SERVER['REQUEST_METHOD'] = 'method';
352 $this->assertTrue(api_check_method('method'));
356 * Test the api_check_method() function with a wildcard.
359 public function testApiCheckMethodWithWildcard()
361 $this->assertTrue(api_check_method('*'));
365 * Test the api_call() function.
367 * @runInSeparateProcess
369 public function testApiCall()
373 'method' => 'method',
374 'func' => function () {
375 return ['data' => ['some_data']];
378 $_SERVER['REQUEST_METHOD'] = 'method';
379 $_GET['callback'] = 'callback_name';
381 $this->app->query_string = 'api_path';
383 'callback_name(["some_data"])',
389 * Test the api_call() function with the profiled enabled.
391 * @runInSeparateProcess
393 public function testApiCallWithProfiler()
397 'method' => 'method',
398 'func' => function () {
399 return ['data' => ['some_data']];
402 $_SERVER['REQUEST_METHOD'] = 'method';
403 Config::set('system', 'profiler', true);
404 Config::set('rendertime', 'callstack', true);
405 $this->app->callstack = [
406 'database' => ['some_function' => 200],
407 'database_write' => ['some_function' => 200],
408 'cache' => ['some_function' => 200],
409 'cache_write' => ['some_function' => 200],
410 'network' => ['some_function' => 200]
413 $this->app->query_string = 'api_path';
421 * Test the api_call() function without any result.
423 * @runInSeparateProcess
425 public function testApiCallWithNoResult()
429 'method' => 'method',
430 'func' => function () {
434 $_SERVER['REQUEST_METHOD'] = 'method';
436 $this->app->query_string = 'api_path';
438 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
444 * Test the api_call() function with an unimplemented API.
446 * @runInSeparateProcess
448 public function testApiCallWithUninplementedApi()
451 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
457 * Test the api_call() function with a JSON result.
459 * @runInSeparateProcess
461 public function testApiCallWithJson()
465 'method' => 'method',
466 'func' => function () {
467 return ['data' => ['some_data']];
470 $_SERVER['REQUEST_METHOD'] = 'method';
472 $this->app->query_string = 'api_path.json';
480 * Test the api_call() function with an XML result.
482 * @runInSeparateProcess
484 public function testApiCallWithXml()
488 'method' => 'method',
489 'func' => function () {
493 $_SERVER['REQUEST_METHOD'] = 'method';
495 $this->app->query_string = 'api_path.xml';
503 * Test the api_call() function with an RSS result.
505 * @runInSeparateProcess
507 public function testApiCallWithRss()
511 'method' => 'method',
512 'func' => function () {
516 $_SERVER['REQUEST_METHOD'] = 'method';
518 $this->app->query_string = 'api_path.rss';
520 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
527 * Test the api_call() function with an Atom result.
529 * @runInSeparateProcess
531 public function testApiCallWithAtom()
535 'method' => 'method',
536 'func' => function () {
540 $_SERVER['REQUEST_METHOD'] = 'method';
542 $this->app->query_string = 'api_path.atom';
544 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
551 * Test the api_call() function with an unallowed method.
553 * @runInSeparateProcess
555 public function testApiCallWithWrongMethod()
558 $API['api_path'] = ['method' => 'method'];
560 $this->app->query_string = 'api_path';
562 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
568 * Test the api_call() function with an unauthorized user.
570 * @runInSeparateProcess
572 public function testApiCallWithWrongAuth()
576 'method' => 'method',
579 $_SERVER['REQUEST_METHOD'] = 'method';
580 $_SESSION['authenticated'] = false;
582 $this->app->query_string = 'api_path';
584 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
590 * Test the api_error() function with a JSON result.
592 * @runInSeparateProcess
594 public function testApiErrorWithJson()
597 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
598 api_error('json', new HTTPException('error_message'))
603 * Test the api_error() function with an XML result.
605 * @runInSeparateProcess
607 public function testApiErrorWithXml()
610 '<?xml version="1.0"?>'."\n".
611 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
612 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
613 'xmlns:georss="http://www.georss.org/georss">'."\n".
614 ' <error>error_message</error>'."\n".
615 ' <code>200 Friendica\Network\HTTP</code>'."\n".
618 api_error('xml', new HTTPException('error_message'))
623 * Test the api_error() function with an RSS result.
625 * @runInSeparateProcess
627 public function testApiErrorWithRss()
630 '<?xml version="1.0"?>'."\n".
631 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
632 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
633 'xmlns:georss="http://www.georss.org/georss">'."\n".
634 ' <error>error_message</error>'."\n".
635 ' <code>200 Friendica\Network\HTTP</code>'."\n".
638 api_error('rss', new HTTPException('error_message'))
643 * Test the api_error() function with an Atom result.
645 * @runInSeparateProcess
647 public function testApiErrorWithAtom()
650 '<?xml version="1.0"?>'."\n".
651 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
652 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
653 'xmlns:georss="http://www.georss.org/georss">'."\n".
654 ' <error>error_message</error>'."\n".
655 ' <code>200 Friendica\Network\HTTP</code>'."\n".
658 api_error('atom', new HTTPException('error_message'))
663 * Test the api_rss_extra() function.
666 public function testApiRssExtra()
668 $user_info = ['url' => 'user_url', 'lang' => 'en'];
669 $result = api_rss_extra($this->app, [], $user_info);
670 $this->assertEquals($user_info, $result['$user']);
671 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
672 $this->assertArrayHasKey('self', $result['$rss']);
673 $this->assertArrayHasKey('base', $result['$rss']);
674 $this->assertArrayHasKey('updated', $result['$rss']);
675 $this->assertArrayHasKey('atom_updated', $result['$rss']);
676 $this->assertArrayHasKey('language', $result['$rss']);
677 $this->assertArrayHasKey('logo', $result['$rss']);
681 * Test the api_rss_extra() function without any user info.
683 * @runInSeparateProcess
685 public function testApiRssExtraWithoutUserInfo()
687 $result = api_rss_extra($this->app, [], null);
688 $this->assertInternalType('array', $result['$user']);
689 $this->assertArrayHasKey('alternate', $result['$rss']);
690 $this->assertArrayHasKey('self', $result['$rss']);
691 $this->assertArrayHasKey('base', $result['$rss']);
692 $this->assertArrayHasKey('updated', $result['$rss']);
693 $this->assertArrayHasKey('atom_updated', $result['$rss']);
694 $this->assertArrayHasKey('language', $result['$rss']);
695 $this->assertArrayHasKey('logo', $result['$rss']);
699 * Test the api_unique_id_to_nurl() function.
702 public function testApiUniqueIdToNurl()
704 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
708 * Test the api_unique_id_to_nurl() function with a correct ID.
711 public function testApiUniqueIdToNurlWithCorrectId()
713 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
717 * Test the api_get_user() function.
719 * @runInSeparateProcess
721 public function testApiGetUser()
723 $user = api_get_user($this->app);
724 $this->assertSelfUser($user);
725 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
726 $this->assertEquals('6fdbe8', $user['profile_link_color']);
727 $this->assertEquals('ededed', $user['profile_background_color']);
731 * Test the api_get_user() function with a Frio schema.
733 * @runInSeparateProcess
735 public function testApiGetUserWithFrioSchema()
737 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
738 $user = api_get_user($this->app);
739 $this->assertSelfUser($user);
740 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
741 $this->assertEquals('6fdbe8', $user['profile_link_color']);
742 $this->assertEquals('ededed', $user['profile_background_color']);
746 * Test the api_get_user() function with a custom Frio schema.
748 * @runInSeparateProcess
750 public function testApiGetUserWithCustomFrioSchema()
752 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
753 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
754 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
755 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
756 $user = api_get_user($this->app);
757 $this->assertSelfUser($user);
758 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
759 $this->assertEquals('123456', $user['profile_link_color']);
760 $this->assertEquals('123456', $user['profile_background_color']);
764 * Test the api_get_user() function with an empty Frio schema.
766 * @runInSeparateProcess
768 public function testApiGetUserWithEmptyFrioSchema()
770 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
771 $user = api_get_user($this->app);
772 $this->assertSelfUser($user);
773 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
774 $this->assertEquals('6fdbe8', $user['profile_link_color']);
775 $this->assertEquals('ededed', $user['profile_background_color']);
779 * Test the api_get_user() function with an user that is not allowed to use the API.
781 * @runInSeparateProcess
783 public function testApiGetUserWithoutApiUser()
785 $_SERVER['PHP_AUTH_USER'] = 'Test user';
786 $_SERVER['PHP_AUTH_PW'] = 'password';
787 $_SESSION['allow_api'] = false;
788 $this->assertFalse(api_get_user($this->app));
792 * Test the api_get_user() function with an user ID in a GET parameter.
794 * @runInSeparateProcess
796 public function testApiGetUserWithGetId()
798 $_GET['user_id'] = $this->otherUser['id'];
799 $this->assertOtherUser(api_get_user($this->app));
803 * Test the api_get_user() function with a wrong user ID in a GET parameter.
805 * @runInSeparateProcess
806 * @expectedException Friendica\Network\HTTPException\BadRequestException
808 public function testApiGetUserWithWrongGetId()
810 $_GET['user_id'] = $this->wrongUserId;
811 $this->assertOtherUser(api_get_user($this->app));
815 * Test the api_get_user() function with an user name in a GET parameter.
817 * @runInSeparateProcess
819 public function testApiGetUserWithGetName()
821 $_GET['screen_name'] = $this->selfUser['nick'];
822 $this->assertSelfUser(api_get_user($this->app));
826 * Test the api_get_user() function with a profile URL in a GET parameter.
828 * @runInSeparateProcess
830 public function testApiGetUserWithGetUrl()
832 $_GET['profileurl'] = $this->selfUser['nurl'];
833 $this->assertSelfUser(api_get_user($this->app));
837 * Test the api_get_user() function with an user ID in the API path.
839 * @runInSeparateProcess
841 public function testApiGetUserWithNumericCalledApi()
844 $called_api = ['api_path'];
845 $this->app->argv[1] = $this->otherUser['id'].'.json';
846 $this->assertOtherUser(api_get_user($this->app));
850 * Test the api_get_user() function with the $called_api global variable.
852 * @runInSeparateProcess
854 public function testApiGetUserWithCalledApi()
857 $called_api = ['api', 'api_path'];
858 $this->assertSelfUser(api_get_user($this->app));
862 * Test the api_get_user() function with a valid user.
864 * @runInSeparateProcess
866 public function testApiGetUserWithCorrectUser()
868 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
872 * Test the api_get_user() function with a wrong user ID.
874 * @runInSeparateProcess
875 * @expectedException Friendica\Network\HTTPException\BadRequestException
877 public function testApiGetUserWithWrongUser()
879 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
883 * Test the api_get_user() function with a 0 user ID.
885 * @runInSeparateProcess
887 public function testApiGetUserWithZeroUser()
889 $this->assertSelfUser(api_get_user($this->app, 0));
893 * Test the api_item_get_user() function.
895 * @runInSeparateProcess
897 public function testApiItemGetUser()
899 $users = api_item_get_user($this->app, []);
900 $this->assertSelfUser($users[0]);
904 * Test the api_item_get_user() function with a different item parent.
907 public function testApiItemGetUserWithDifferentParent()
909 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
910 $this->assertSelfUser($users[0]);
911 $this->assertEquals($users[0], $users[1]);
915 * Test the api_walk_recursive() function.
918 public function testApiWalkRecursive()
926 // Should we test this with a callback that actually does something?
934 * Test the api_walk_recursive() function with an array.
937 public function testApiWalkRecursiveWithArray()
939 $array = [['item1'], ['item2']];
945 // Should we test this with a callback that actually does something?
953 * Test the api_reformat_xml() function.
956 public function testApiReformatXml()
960 $this->assertTrue(api_reformat_xml($item, $key));
961 $this->assertEquals('true', $item);
965 * Test the api_reformat_xml() function with a statusnet_api key.
968 public function testApiReformatXmlWithStatusnetKey()
971 $key = 'statusnet_api';
972 $this->assertTrue(api_reformat_xml($item, $key));
973 $this->assertEquals('statusnet:api', $key);
977 * Test the api_reformat_xml() function with a friendica_api key.
980 public function testApiReformatXmlWithFriendicaKey()
983 $key = 'friendica_api';
984 $this->assertTrue(api_reformat_xml($item, $key));
985 $this->assertEquals('friendica:api', $key);
989 * Test the api_create_xml() function.
992 public function testApiCreateXml()
995 '<?xml version="1.0"?>'."\n".
996 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
997 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
998 'xmlns:georss="http://www.georss.org/georss">'."\n".
999 ' <data>some_data</data>'."\n".
1000 '</root_element>'."\n",
1001 api_create_xml(['data' => ['some_data']], 'root_element')
1006 * Test the api_create_xml() function without any XML namespace.
1009 public function testApiCreateXmlWithoutNamespaces()
1011 $this->assertEquals(
1012 '<?xml version="1.0"?>'."\n".
1014 ' <data>some_data</data>'."\n".
1016 api_create_xml(['data' => ['some_data']], 'ok')
1021 * Test the api_format_data() function.
1024 public function testApiFormatData()
1026 $data = ['some_data'];
1027 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1031 * Test the api_format_data() function with an XML result.
1034 public function testApiFormatDataWithXml()
1036 $this->assertEquals(
1037 '<?xml version="1.0"?>'."\n".
1038 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1039 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1040 'xmlns:georss="http://www.georss.org/georss">'."\n".
1041 ' <data>some_data</data>'."\n".
1042 '</root_element>'."\n",
1043 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1048 * Test the api_account_verify_credentials() function.
1051 public function testApiAccountVerifyCredentials()
1053 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1057 * Test the api_account_verify_credentials() function without an authenticated user.
1059 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1061 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1063 $_SESSION['authenticated'] = false;
1064 api_account_verify_credentials('json');
1068 * Test the requestdata() function.
1071 public function testRequestdata()
1073 $this->assertNull(requestdata('variable_name'));
1077 * Test the requestdata() function with a POST parameter.
1080 public function testRequestdataWithPost()
1082 $_POST['variable_name'] = 'variable_value';
1083 $this->assertEquals('variable_value', requestdata('variable_name'));
1087 * Test the requestdata() function with a GET parameter.
1090 public function testRequestdataWithGet()
1092 $_GET['variable_name'] = 'variable_value';
1093 $this->assertEquals('variable_value', requestdata('variable_name'));
1097 * Test the api_statuses_mediap() function.
1100 public function testApiStatusesMediap()
1102 $this->app->argc = 2;
1110 'tmp_name' => $this->getTempImage(),
1111 'name' => 'spacer.png',
1112 'type' => 'image/png'
1115 $_GET['status'] = '<b>Status content</b>';
1117 $result = api_statuses_mediap('json');
1118 $this->assertStatus($result['status']);
1122 * Test the api_statuses_mediap() function without an authenticated user.
1124 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1126 public function testApiStatusesMediapWithoutAuthenticatedUser()
1128 $_SESSION['authenticated'] = false;
1129 api_statuses_mediap('json');
1133 * Test the api_statuses_update() function.
1136 public function testApiStatusesUpdate()
1138 $_GET['status'] = 'Status content #friendica';
1139 $_GET['in_reply_to_status_id'] = -1;
1148 'tmp_name' => $this->getTempImage(),
1149 'name' => 'spacer.png',
1150 'type' => 'image/png'
1154 $result = api_statuses_update('json');
1155 $this->assertStatus($result['status']);
1159 * Test the api_statuses_update() function with an HTML status.
1162 public function testApiStatusesUpdateWithHtml()
1164 $_GET['htmlstatus'] = '<b>Status content</b>';
1166 $result = api_statuses_update('json');
1167 $this->assertStatus($result['status']);
1171 * Test the api_statuses_update() function without an authenticated user.
1173 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1175 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1177 $_SESSION['authenticated'] = false;
1178 api_statuses_update('json');
1182 * Test the api_statuses_update() function with a parent status.
1185 public function testApiStatusesUpdateWithParent()
1187 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1191 * Test the api_statuses_update() function with a media_ids parameter.
1194 public function testApiStatusesUpdateWithMediaIds()
1196 $this->markTestIncomplete();
1200 * Test the api_statuses_update() function with the throttle limit reached.
1203 public function testApiStatusesUpdateWithDayThrottleReached()
1205 $this->markTestIncomplete();
1209 * Test the api_media_upload() function.
1211 * @expectedException Friendica\Network\HTTPException\BadRequestException
1213 public function testApiMediaUpload()
1219 * Test the api_media_upload() function without an authenticated user.
1221 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1223 public function testApiMediaUploadWithoutAuthenticatedUser()
1225 $_SESSION['authenticated'] = false;
1230 * Test the api_media_upload() function with an invalid uploaded media.
1232 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1234 public function testApiMediaUploadWithMedia()
1239 'tmp_name' => 'tmp_name'
1246 * Test the api_media_upload() function with an valid uploaded media.
1249 public function testApiMediaUploadWithValidMedia()
1257 'tmp_name' => $this->getTempImage(),
1258 'name' => 'spacer.png',
1259 'type' => 'image/png'
1265 $result = api_media_upload();
1266 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1267 $this->assertEquals(1, $result['media']['image']['w']);
1268 $this->assertEquals(1, $result['media']['image']['h']);
1269 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1273 * Test the api_status_show() function.
1276 public function testApiStatusShow()
1278 $result = api_status_show('json');
1279 $this->assertStatus($result['status']);
1283 * Test the api_status_show() function with an XML result.
1286 public function testApiStatusShowWithXml()
1288 $result = api_status_show('xml');
1289 $this->assertXml($result, 'statuses');
1293 * Test the api_status_show() function with a raw result.
1296 public function testApiStatusShowWithRaw()
1298 $this->assertStatus(api_status_show('raw'));
1302 * Test the api_users_show() function.
1305 public function testApiUsersShow()
1307 $result = api_users_show('json');
1308 // We can't use assertSelfUser() here because the user object is missing some properties.
1309 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1310 $this->assertEquals('DFRN', $result['user']['location']);
1311 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1312 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1313 $this->assertEquals('dfrn', $result['user']['network']);
1314 $this->assertTrue($result['user']['verified']);
1318 * Test the api_users_show() function with an XML result.
1321 public function testApiUsersShowWithXml()
1323 $result = api_users_show('xml');
1324 $this->assertXml($result, 'statuses');
1328 * Test the api_users_search() function.
1331 public function testApiUsersSearch()
1333 $_GET['q'] = 'othercontact';
1334 $result = api_users_search('json');
1335 $this->assertOtherUser($result['users'][0]);
1339 * Test the api_users_search() function with an XML result.
1342 public function testApiUsersSearchWithXml()
1344 $_GET['q'] = 'othercontact';
1345 $result = api_users_search('xml');
1346 $this->assertXml($result, 'users');
1350 * Test the api_users_search() function without a GET q parameter.
1352 * @expectedException Friendica\Network\HTTPException\BadRequestException
1354 public function testApiUsersSearchWithoutQuery()
1356 api_users_search('json');
1360 * Test the api_users_lookup() function.
1362 * @expectedException Friendica\Network\HTTPException\NotFoundException
1364 public function testApiUsersLookup()
1366 api_users_lookup('json');
1370 * Test the api_users_lookup() function with an user ID.
1373 public function testApiUsersLookupWithUserId()
1375 $_REQUEST['user_id'] = $this->otherUser['id'];
1376 $result = api_users_lookup('json');
1377 $this->assertOtherUser($result['users'][0]);
1381 * Test the api_search() function.
1384 public function testApiSearch()
1386 $_REQUEST['q'] = 'reply';
1387 $_REQUEST['max_id'] = 10;
1388 $result = api_search('json');
1389 foreach ($result['status'] as $status) {
1390 $this->assertStatus($status);
1391 $this->assertContains('reply', $status['text'], null, true);
1396 * Test the api_search() function a count parameter.
1399 public function testApiSearchWithCount()
1401 $_REQUEST['q'] = 'reply';
1402 $_REQUEST['count'] = 20;
1403 $result = api_search('json');
1404 foreach ($result['status'] as $status) {
1405 $this->assertStatus($status);
1406 $this->assertContains('reply', $status['text'], null, true);
1411 * Test the api_search() function with an rpp parameter.
1414 public function testApiSearchWithRpp()
1416 $_REQUEST['q'] = 'reply';
1417 $_REQUEST['rpp'] = 20;
1418 $result = api_search('json');
1419 foreach ($result['status'] as $status) {
1420 $this->assertStatus($status);
1421 $this->assertContains('reply', $status['text'], null, true);
1426 * Test the api_search() function with an q parameter contains hashtag.
1429 public function testApiSearchWithHashtag()
1431 $_REQUEST['q'] = '%23friendica';
1432 $result = api_search('json');
1433 foreach ($result['status'] as $status) {
1434 $this->assertStatus($status);
1435 $this->assertContains('#friendica', $status['text'], null, true);
1440 * Test the api_search() function with an exclude_replies parameter.
1443 public function testApiSearchWithExcludeReplies()
1445 $_REQUEST['max_id'] = 10;
1446 $_REQUEST['exclude_replies'] = true;
1447 $_REQUEST['q'] = 'friendica';
1448 $result = api_search('json');
1449 foreach ($result['status'] as $status) {
1450 $this->assertStatus($status);
1455 * Test the api_search() function without an authenticated user.
1457 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1459 public function testApiSearchWithUnallowedUser()
1461 $_SESSION['allow_api'] = false;
1462 $_GET['screen_name'] = $this->selfUser['nick'];
1467 * Test the api_search() function without any GET query parameter.
1469 * @expectedException Friendica\Network\HTTPException\BadRequestException
1471 public function testApiSearchWithoutQuery()
1477 * Test the api_statuses_home_timeline() function.
1480 public function testApiStatusesHomeTimeline()
1482 $_REQUEST['max_id'] = 10;
1483 $_REQUEST['exclude_replies'] = true;
1484 $_REQUEST['conversation_id'] = 1;
1485 $result = api_statuses_home_timeline('json');
1486 $this->assertNotEmpty($result['status']);
1487 foreach ($result['status'] as $status) {
1488 $this->assertStatus($status);
1493 * Test the api_statuses_home_timeline() function with a negative page parameter.
1496 public function testApiStatusesHomeTimelineWithNegativePage()
1498 $_REQUEST['page'] = -2;
1499 $result = api_statuses_home_timeline('json');
1500 $this->assertNotEmpty($result['status']);
1501 foreach ($result['status'] as $status) {
1502 $this->assertStatus($status);
1507 * Test the api_statuses_home_timeline() with an unallowed user.
1509 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1511 public function testApiStatusesHomeTimelineWithUnallowedUser()
1513 $_SESSION['allow_api'] = false;
1514 $_GET['screen_name'] = $this->selfUser['nick'];
1515 api_statuses_home_timeline('json');
1519 * Test the api_statuses_home_timeline() function with an RSS result.
1522 public function testApiStatusesHomeTimelineWithRss()
1524 $result = api_statuses_home_timeline('rss');
1525 $this->assertXml($result, 'statuses');
1529 * Test the api_statuses_public_timeline() function.
1532 public function testApiStatusesPublicTimeline()
1534 $_REQUEST['max_id'] = 10;
1535 $_REQUEST['conversation_id'] = 1;
1536 $result = api_statuses_public_timeline('json');
1537 $this->assertNotEmpty($result['status']);
1538 foreach ($result['status'] as $status) {
1539 $this->assertStatus($status);
1544 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1547 public function testApiStatusesPublicTimelineWithExcludeReplies()
1549 $_REQUEST['max_id'] = 10;
1550 $_REQUEST['exclude_replies'] = true;
1551 $result = api_statuses_public_timeline('json');
1552 $this->assertNotEmpty($result['status']);
1553 foreach ($result['status'] as $status) {
1554 $this->assertStatus($status);
1559 * Test the api_statuses_public_timeline() function with a negative page parameter.
1562 public function testApiStatusesPublicTimelineWithNegativePage()
1564 $_REQUEST['page'] = -2;
1565 $result = api_statuses_public_timeline('json');
1566 $this->assertNotEmpty($result['status']);
1567 foreach ($result['status'] as $status) {
1568 $this->assertStatus($status);
1573 * Test the api_statuses_public_timeline() function with an unallowed user.
1575 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1577 public function testApiStatusesPublicTimelineWithUnallowedUser()
1579 $_SESSION['allow_api'] = false;
1580 $_GET['screen_name'] = $this->selfUser['nick'];
1581 api_statuses_public_timeline('json');
1585 * Test the api_statuses_public_timeline() function with an RSS result.
1588 public function testApiStatusesPublicTimelineWithRss()
1590 $result = api_statuses_public_timeline('rss');
1591 $this->assertXml($result, 'statuses');
1595 * Test the api_statuses_networkpublic_timeline() function.
1598 public function testApiStatusesNetworkpublicTimeline()
1600 $_REQUEST['max_id'] = 10;
1601 $result = api_statuses_networkpublic_timeline('json');
1602 $this->assertNotEmpty($result['status']);
1603 foreach ($result['status'] as $status) {
1604 $this->assertStatus($status);
1609 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1612 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1614 $_REQUEST['page'] = -2;
1615 $result = api_statuses_networkpublic_timeline('json');
1616 $this->assertNotEmpty($result['status']);
1617 foreach ($result['status'] as $status) {
1618 $this->assertStatus($status);
1623 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1625 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1627 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1629 $_SESSION['allow_api'] = false;
1630 $_GET['screen_name'] = $this->selfUser['nick'];
1631 api_statuses_networkpublic_timeline('json');
1635 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1638 public function testApiStatusesNetworkpublicTimelineWithRss()
1640 $result = api_statuses_networkpublic_timeline('rss');
1641 $this->assertXml($result, 'statuses');
1645 * Test the api_statuses_show() function.
1647 * @expectedException Friendica\Network\HTTPException\BadRequestException
1649 public function testApiStatusesShow()
1651 api_statuses_show('json');
1655 * Test the api_statuses_show() function with an ID.
1658 public function testApiStatusesShowWithId()
1660 $this->app->argv[3] = 1;
1661 $result = api_statuses_show('json');
1662 $this->assertStatus($result['status']);
1666 * Test the api_statuses_show() function with the conversation parameter.
1669 public function testApiStatusesShowWithConversation()
1671 $this->app->argv[3] = 1;
1672 $_REQUEST['conversation'] = 1;
1673 $result = api_statuses_show('json');
1674 $this->assertNotEmpty($result['status']);
1675 foreach ($result['status'] as $status) {
1676 $this->assertStatus($status);
1681 * Test the api_statuses_show() function with an unallowed user.
1683 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1685 public function testApiStatusesShowWithUnallowedUser()
1687 $_SESSION['allow_api'] = false;
1688 $_GET['screen_name'] = $this->selfUser['nick'];
1689 api_statuses_show('json');
1693 * Test the api_conversation_show() function.
1695 * @expectedException Friendica\Network\HTTPException\BadRequestException
1697 public function testApiConversationShow()
1699 api_conversation_show('json');
1703 * Test the api_conversation_show() function with an ID.
1706 public function testApiConversationShowWithId()
1708 $this->app->argv[3] = 1;
1709 $_REQUEST['max_id'] = 10;
1710 $_REQUEST['page'] = -2;
1711 $result = api_conversation_show('json');
1712 $this->assertNotEmpty($result['status']);
1713 foreach ($result['status'] as $status) {
1714 $this->assertStatus($status);
1719 * Test the api_conversation_show() function with an unallowed user.
1721 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1723 public function testApiConversationShowWithUnallowedUser()
1725 $_SESSION['allow_api'] = false;
1726 $_GET['screen_name'] = $this->selfUser['nick'];
1727 api_conversation_show('json');
1731 * Test the api_statuses_repeat() function.
1733 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1735 public function testApiStatusesRepeat()
1737 api_statuses_repeat('json');
1741 * Test the api_statuses_repeat() function without an authenticated user.
1743 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1745 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1747 $_SESSION['authenticated'] = false;
1748 api_statuses_repeat('json');
1752 * Test the api_statuses_repeat() function with an ID.
1755 public function testApiStatusesRepeatWithId()
1757 $this->app->argv[3] = 1;
1758 $result = api_statuses_repeat('json');
1759 $this->assertStatus($result['status']);
1761 // Also test with a shared status
1762 $this->app->argv[3] = 5;
1763 $result = api_statuses_repeat('json');
1764 $this->assertStatus($result['status']);
1768 * Test the api_statuses_destroy() function.
1770 * @expectedException Friendica\Network\HTTPException\BadRequestException
1772 public function testApiStatusesDestroy()
1774 api_statuses_destroy('json');
1778 * Test the api_statuses_destroy() function without an authenticated user.
1780 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1782 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1784 $_SESSION['authenticated'] = false;
1785 api_statuses_destroy('json');
1789 * Test the api_statuses_destroy() function with an ID.
1792 public function testApiStatusesDestroyWithId()
1794 $this->app->argv[3] = 1;
1795 $result = api_statuses_destroy('json');
1796 $this->assertStatus($result['status']);
1800 * Test the api_statuses_mentions() function.
1803 public function testApiStatusesMentions()
1805 $this->app->user = ['nickname' => $this->selfUser['nick']];
1806 $_REQUEST['max_id'] = 10;
1807 $result = api_statuses_mentions('json');
1808 $this->assertEmpty($result['status']);
1809 // We should test with mentions in the database.
1813 * Test the api_statuses_mentions() function with a negative page parameter.
1816 public function testApiStatusesMentionsWithNegativePage()
1818 $_REQUEST['page'] = -2;
1819 $result = api_statuses_mentions('json');
1820 $this->assertEmpty($result['status']);
1824 * Test the api_statuses_mentions() function with an unallowed user.
1826 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1828 public function testApiStatusesMentionsWithUnallowedUser()
1830 $_SESSION['allow_api'] = false;
1831 $_GET['screen_name'] = $this->selfUser['nick'];
1832 api_statuses_mentions('json');
1836 * Test the api_statuses_mentions() function with an RSS result.
1839 public function testApiStatusesMentionsWithRss()
1841 $result = api_statuses_mentions('rss');
1842 $this->assertXml($result, 'statuses');
1846 * Test the api_statuses_user_timeline() function.
1849 public function testApiStatusesUserTimeline()
1851 $_REQUEST['max_id'] = 10;
1852 $_REQUEST['exclude_replies'] = true;
1853 $_REQUEST['conversation_id'] = 1;
1854 $result = api_statuses_user_timeline('json');
1855 $this->assertNotEmpty($result['status']);
1856 foreach ($result['status'] as $status) {
1857 $this->assertStatus($status);
1862 * Test the api_statuses_user_timeline() function with a negative page parameter.
1865 public function testApiStatusesUserTimelineWithNegativePage()
1867 $_REQUEST['page'] = -2;
1868 $result = api_statuses_user_timeline('json');
1869 $this->assertNotEmpty($result['status']);
1870 foreach ($result['status'] as $status) {
1871 $this->assertStatus($status);
1876 * Test the api_statuses_user_timeline() function with an RSS result.
1879 public function testApiStatusesUserTimelineWithRss()
1881 $result = api_statuses_user_timeline('rss');
1882 $this->assertXml($result, 'statuses');
1886 * Test the api_statuses_user_timeline() function with an unallowed user.
1888 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1890 public function testApiStatusesUserTimelineWithUnallowedUser()
1892 $_SESSION['allow_api'] = false;
1893 $_GET['screen_name'] = $this->selfUser['nick'];
1894 api_statuses_user_timeline('json');
1898 * Test the api_favorites_create_destroy() function.
1900 * @expectedException Friendica\Network\HTTPException\BadRequestException
1902 public function testApiFavoritesCreateDestroy()
1904 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1905 $this->app->argc = count($this->app->argv);
1906 api_favorites_create_destroy('json');
1910 * Test the api_favorites_create_destroy() function with an invalid ID.
1912 * @expectedException Friendica\Network\HTTPException\BadRequestException
1914 public function testApiFavoritesCreateDestroyWithInvalidId()
1916 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1917 $this->app->argc = count($this->app->argv);
1918 api_favorites_create_destroy('json');
1922 * Test the api_favorites_create_destroy() function with an invalid action.
1924 * @expectedException Friendica\Network\HTTPException\BadRequestException
1926 public function testApiFavoritesCreateDestroyWithInvalidAction()
1928 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1929 $this->app->argc = count($this->app->argv);
1930 $_REQUEST['id'] = 1;
1931 api_favorites_create_destroy('json');
1935 * Test the api_favorites_create_destroy() function with the create action.
1938 public function testApiFavoritesCreateDestroyWithCreateAction()
1940 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1941 $this->app->argc = count($this->app->argv);
1942 $_REQUEST['id'] = 3;
1943 $result = api_favorites_create_destroy('json');
1944 $this->assertStatus($result['status']);
1948 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1951 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1953 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1954 $this->app->argc = count($this->app->argv);
1955 $_REQUEST['id'] = 3;
1956 $result = api_favorites_create_destroy('rss');
1957 $this->assertXml($result, 'status');
1961 * Test the api_favorites_create_destroy() function with the destroy action.
1964 public function testApiFavoritesCreateDestroyWithDestroyAction()
1966 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1967 $this->app->argc = count($this->app->argv);
1968 $_REQUEST['id'] = 3;
1969 $result = api_favorites_create_destroy('json');
1970 $this->assertStatus($result['status']);
1974 * Test the api_favorites_create_destroy() function without an authenticated user.
1976 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1978 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1980 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1981 $this->app->argc = count($this->app->argv);
1982 $_SESSION['authenticated'] = false;
1983 api_favorites_create_destroy('json');
1987 * Test the api_favorites() function.
1990 public function testApiFavorites()
1992 $_REQUEST['page'] = -1;
1993 $_REQUEST['max_id'] = 10;
1994 $result = api_favorites('json');
1995 foreach ($result['status'] as $status) {
1996 $this->assertStatus($status);
2001 * Test the api_favorites() function with an RSS result.
2004 public function testApiFavoritesWithRss()
2006 $result = api_favorites('rss');
2007 $this->assertXml($result, 'statuses');
2011 * Test the api_favorites() function with an unallowed user.
2013 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2015 public function testApiFavoritesWithUnallowedUser()
2017 $_SESSION['allow_api'] = false;
2018 $_GET['screen_name'] = $this->selfUser['nick'];
2019 api_favorites('json');
2023 * Test the api_format_messages() function.
2026 public function testApiFormatMessages()
2028 $result = api_format_messages(
2029 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2030 ['id' => 2, 'screen_name' => 'recipient_name'],
2031 ['id' => 3, 'screen_name' => 'sender_name']
2033 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2034 $this->assertEquals(1, $result['id']);
2035 $this->assertEquals(2, $result['recipient_id']);
2036 $this->assertEquals(3, $result['sender_id']);
2037 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2038 $this->assertEquals('sender_name', $result['sender_screen_name']);
2042 * Test the api_format_messages() function with HTML.
2045 public function testApiFormatMessagesWithHtmlText()
2047 $_GET['getText'] = 'html';
2048 $result = api_format_messages(
2049 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2050 ['id' => 2, 'screen_name' => 'recipient_name'],
2051 ['id' => 3, 'screen_name' => 'sender_name']
2053 $this->assertEquals('item_title', $result['title']);
2054 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2058 * Test the api_format_messages() function with plain text.
2061 public function testApiFormatMessagesWithPlainText()
2063 $_GET['getText'] = 'plain';
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('item_body', $result['text']);
2074 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2077 public function testApiFormatMessagesWithoutUserObjects()
2079 $_GET['getUserObjects'] = 'false';
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->assertTrue(!isset($result['sender']));
2086 $this->assertTrue(!isset($result['recipient']));
2090 * Test the api_convert_item() function.
2093 public function testApiConvertItem()
2095 $result = api_convert_item(
2097 'network' => 'feed',
2098 'title' => 'item_title',
2099 // We need a long string to test that it is correctly cut
2100 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2101 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2102 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2103 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2104 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2105 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2106 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2107 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2108 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2109 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2110 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2111 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2112 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2113 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2114 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2115 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2116 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2117 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2118 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2119 'repellat officia illum quos impedit quam iste esse unde qui '.
2120 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2121 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2122 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2123 'plink' => 'item_plink'
2126 $this->assertStringStartsWith('item_title', $result['text']);
2127 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2131 * Test the api_convert_item() function with an empty item body.
2134 public function testApiConvertItemWithoutBody()
2136 $result = api_convert_item(
2138 'network' => 'feed',
2139 'title' => 'item_title',
2141 'plink' => 'item_plink'
2144 $this->assertEquals('item_title', $result['text']);
2145 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2149 * Test the api_convert_item() function with the title in the body.
2152 public function testApiConvertItemWithTitleInBody()
2154 $result = api_convert_item(
2156 'title' => 'item_title',
2157 'body' => 'item_title item_body'
2160 $this->assertEquals('item_title item_body', $result['text']);
2161 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2165 * Test the api_get_attachments() function.
2168 public function testApiGetAttachments()
2171 $this->assertEmpty(api_get_attachments($body));
2175 * Test the api_get_attachments() function with an img tag.
2178 public function testApiGetAttachmentsWithImage()
2180 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2181 $this->assertInternalType('array', api_get_attachments($body));
2185 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2188 public function testApiGetAttachmentsWithImageAndAndStatus()
2190 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2191 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2192 $this->assertInternalType('array', api_get_attachments($body));
2196 * Test the api_get_entitities() function.
2199 public function testApiGetEntitities()
2202 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2206 * Test the api_get_entitities() function with the include_entities parameter.
2209 public function testApiGetEntititiesWithIncludeEntities()
2211 $_REQUEST['include_entities'] = 'true';
2213 $result = api_get_entitities($text, 'bbcode');
2214 $this->assertInternalType('array', $result['hashtags']);
2215 $this->assertInternalType('array', $result['symbols']);
2216 $this->assertInternalType('array', $result['urls']);
2217 $this->assertInternalType('array', $result['user_mentions']);
2221 * Test the api_format_items_embeded_images() function.
2224 public function testApiFormatItemsEmbededImages()
2226 $this->assertEquals(
2227 'text ' . System::baseUrl() . '/display/item_guid',
2228 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2233 * Test the api_contactlink_to_array() function.
2236 public function testApiContactlinkToArray()
2238 $this->assertEquals(
2243 api_contactlink_to_array('text')
2248 * Test the api_contactlink_to_array() function with an URL.
2251 public function testApiContactlinkToArrayWithUrl()
2253 $this->assertEquals(
2255 'name' => ['link_text'],
2258 api_contactlink_to_array('text <a href="url">link_text</a>')
2263 * Test the api_format_items_activities() function.
2266 public function testApiFormatItemsActivities()
2268 $item = ['uid' => 0, 'uri' => ''];
2269 $result = api_format_items_activities($item);
2270 $this->assertArrayHasKey('like', $result);
2271 $this->assertArrayHasKey('dislike', $result);
2272 $this->assertArrayHasKey('attendyes', $result);
2273 $this->assertArrayHasKey('attendno', $result);
2274 $this->assertArrayHasKey('attendmaybe', $result);
2278 * Test the api_format_items_activities() function with an XML result.
2281 public function testApiFormatItemsActivitiesWithXml()
2283 $item = ['uid' => 0, 'uri' => ''];
2284 $result = api_format_items_activities($item, 'xml');
2285 $this->assertArrayHasKey('friendica:like', $result);
2286 $this->assertArrayHasKey('friendica:dislike', $result);
2287 $this->assertArrayHasKey('friendica:attendyes', $result);
2288 $this->assertArrayHasKey('friendica:attendno', $result);
2289 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2293 * Test the api_format_items_profiles() function.
2296 public function testApiFormatItemsProfiles()
2299 'id' => 'profile_id',
2300 'profile-name' => 'profile_name',
2301 'is-default' => true,
2302 'hide-friends' => true,
2303 'photo' => 'profile_photo',
2304 'thumb' => 'profile_thumb',
2306 'net-publish' => true,
2307 'pdesc' => 'description',
2308 'dob' => 'date_of_birth',
2309 'address' => 'address',
2310 'locality' => 'city',
2311 'region' => 'region',
2312 'postal-code' => 'postal_code',
2313 'country-name' => 'country',
2314 'hometown' => 'hometown',
2315 'gender' => 'gender',
2316 'marital' => 'marital',
2317 'with' => 'marital_with',
2318 'howlong' => 'marital_since',
2319 'sexual' => 'sexual',
2320 'politic' => 'politic',
2321 'religion' => 'religion',
2322 'pub_keywords' => 'public_keywords',
2323 'prv_keywords' => 'private_keywords',
2326 'dislikes' => 'dislikes',
2332 'interest' => 'interest',
2333 'romance' => 'romance',
2335 'education' => 'education',
2336 'contact' => 'social_networks',
2337 'homepage' => 'homepage'
2339 $result = api_format_items_profiles($profile_row);
2340 $this->assertEquals(
2342 'profile_id' => 'profile_id',
2343 'profile_name' => 'profile_name',
2344 'is_default' => true,
2345 'hide_friends' => true,
2346 'profile_photo' => 'profile_photo',
2347 'profile_thumb' => 'profile_thumb',
2349 'net_publish' => true,
2350 'description' => 'description',
2351 'date_of_birth' => 'date_of_birth',
2352 'address' => 'address',
2354 'region' => 'region',
2355 'postal_code' => 'postal_code',
2356 'country' => 'country',
2357 'hometown' => 'hometown',
2358 'gender' => 'gender',
2359 'marital' => 'marital',
2360 'marital_with' => 'marital_with',
2361 'marital_since' => 'marital_since',
2362 'sexual' => 'sexual',
2363 'politic' => 'politic',
2364 'religion' => 'religion',
2365 'public_keywords' => 'public_keywords',
2366 'private_keywords' => 'private_keywords',
2369 'dislikes' => 'dislikes',
2375 'interest' => 'interest',
2376 'romance' => 'romance',
2378 'education' => 'education',
2379 'social_networks' => 'social_networks',
2380 'homepage' => 'homepage',
2388 * Test the api_format_items() function.
2391 public function testApiFormatItems()
2395 'item_network' => 'item_network',
2401 'author-network' => Protocol::DFRN,
2402 'author-link' => 'http://localhost/profile/othercontact',
2406 $result = api_format_items($items, ['id' => 0], true);
2407 foreach ($result as $status) {
2408 $this->assertStatus($status);
2413 * Test the api_format_items() function with an XML result.
2416 public function testApiFormatItemsWithXml()
2424 'author-network' => Protocol::DFRN,
2425 'author-link' => 'http://localhost/profile/othercontact',
2429 $result = api_format_items($items, ['id' => 0], true, 'xml');
2430 foreach ($result as $status) {
2431 $this->assertStatus($status);
2436 * Test the api_format_items() function.
2439 public function testApiAccountRateLimitStatus()
2441 $result = api_account_rate_limit_status('json');
2442 $this->assertEquals(150, $result['hash']['remaining_hits']);
2443 $this->assertEquals(150, $result['hash']['hourly_limit']);
2444 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2448 * Test the api_format_items() function with an XML result.
2451 public function testApiAccountRateLimitStatusWithXml()
2453 $result = api_account_rate_limit_status('xml');
2454 $this->assertXml($result, 'hash');
2458 * Test the api_help_test() function.
2461 public function testApiHelpTest()
2463 $result = api_help_test('json');
2464 $this->assertEquals(['ok' => 'ok'], $result);
2468 * Test the api_help_test() function with an XML result.
2471 public function testApiHelpTestWithXml()
2473 $result = api_help_test('xml');
2474 $this->assertXml($result, 'ok');
2478 * Test the api_lists_list() function.
2481 public function testApiListsList()
2483 $result = api_lists_list('json');
2484 $this->assertEquals(['lists_list' => []], $result);
2488 * Test the api_lists_ownerships() function.
2491 public function testApiListsOwnerships()
2493 $result = api_lists_ownerships('json');
2494 foreach ($result['lists']['lists'] as $list) {
2495 $this->assertList($list);
2500 * Test the api_lists_ownerships() function without an authenticated user.
2502 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2504 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2506 $_SESSION['authenticated'] = false;
2507 api_lists_ownerships('json');
2511 * Test the api_lists_statuses() function.
2512 * @expectedException Friendica\Network\HTTPException\BadRequestException
2515 public function testApiListsStatuses()
2517 api_lists_statuses('json');
2521 * Test the api_lists_statuses() function with a list ID.
2524 public function testApiListsStatusesWithListId()
2526 $_REQUEST['list_id'] = 1;
2527 $_REQUEST['page'] = -1;
2528 $_REQUEST['max_id'] = 10;
2529 $result = api_lists_statuses('json');
2530 foreach ($result['status'] as $status) {
2531 $this->assertStatus($status);
2536 * Test the api_lists_statuses() function with a list ID and a RSS result.
2539 public function testApiListsStatusesWithListIdAndRss()
2541 $_REQUEST['list_id'] = 1;
2542 $result = api_lists_statuses('rss');
2543 $this->assertXml($result, 'statuses');
2547 * Test the api_lists_statuses() function with an unallowed user.
2549 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2551 public function testApiListsStatusesWithUnallowedUser()
2553 $_SESSION['allow_api'] = false;
2554 $_GET['screen_name'] = $this->selfUser['nick'];
2555 api_lists_statuses('json');
2559 * Test the api_statuses_f() function.
2562 public function testApiStatusesFWithFriends()
2565 $result = api_statuses_f('friends');
2566 $this->assertArrayHasKey('user', $result);
2570 * Test the api_statuses_f() function.
2573 public function testApiStatusesFWithFollowers()
2575 $result = api_statuses_f('followers');
2576 $this->assertArrayHasKey('user', $result);
2580 * Test the api_statuses_f() function.
2583 public function testApiStatusesFWithBlocks()
2585 $result = api_statuses_f('blocks');
2586 $this->assertArrayHasKey('user', $result);
2590 * Test the api_statuses_f() function.
2593 public function testApiStatusesFWithIncoming()
2595 $result = api_statuses_f('incoming');
2596 $this->assertArrayHasKey('user', $result);
2600 * Test the api_statuses_f() function an undefined cursor GET variable.
2603 public function testApiStatusesFWithUndefinedCursor()
2605 $_GET['cursor'] = 'undefined';
2606 $this->assertFalse(api_statuses_f('friends'));
2610 * Test the api_statuses_friends() function.
2613 public function testApiStatusesFriends()
2615 $result = api_statuses_friends('json');
2616 $this->assertArrayHasKey('user', $result);
2620 * Test the api_statuses_friends() function an undefined cursor GET variable.
2623 public function testApiStatusesFriendsWithUndefinedCursor()
2625 $_GET['cursor'] = 'undefined';
2626 $this->assertFalse(api_statuses_friends('json'));
2630 * Test the api_statuses_followers() function.
2633 public function testApiStatusesFollowers()
2635 $result = api_statuses_followers('json');
2636 $this->assertArrayHasKey('user', $result);
2640 * Test the api_statuses_followers() function an undefined cursor GET variable.
2643 public function testApiStatusesFollowersWithUndefinedCursor()
2645 $_GET['cursor'] = 'undefined';
2646 $this->assertFalse(api_statuses_followers('json'));
2650 * Test the api_blocks_list() function.
2653 public function testApiBlocksList()
2655 $result = api_blocks_list('json');
2656 $this->assertArrayHasKey('user', $result);
2660 * Test the api_blocks_list() function an undefined cursor GET variable.
2663 public function testApiBlocksListWithUndefinedCursor()
2665 $_GET['cursor'] = 'undefined';
2666 $this->assertFalse(api_blocks_list('json'));
2670 * Test the api_friendships_incoming() function.
2673 public function testApiFriendshipsIncoming()
2675 $result = api_friendships_incoming('json');
2676 $this->assertArrayHasKey('id', $result);
2680 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2683 public function testApiFriendshipsIncomingWithUndefinedCursor()
2685 $_GET['cursor'] = 'undefined';
2686 $this->assertFalse(api_friendships_incoming('json'));
2690 * Test the api_statusnet_config() function.
2693 public function testApiStatusnetConfig()
2695 $result = api_statusnet_config('json');
2696 $this->assertEquals('localhost', $result['config']['site']['server']);
2697 $this->assertEquals('default', $result['config']['site']['theme']);
2698 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2699 $this->assertTrue($result['config']['site']['fancy']);
2700 $this->assertEquals('en', $result['config']['site']['language']);
2701 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2702 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2703 $this->assertEquals('false', $result['config']['site']['private']);
2704 $this->assertEquals('false', $result['config']['site']['ssl']);
2705 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2709 * Test the api_statusnet_version() function.
2712 public function testApiStatusnetVersion()
2714 $result = api_statusnet_version('json');
2715 $this->assertEquals('0.9.7', $result['version']);
2719 * Test the api_ff_ids() function.
2722 public function testApiFfIds()
2724 $result = api_ff_ids('json');
2725 $this->assertNull($result);
2729 * Test the api_ff_ids() function with a result.
2732 public function testApiFfIdsWithResult()
2734 $this->markTestIncomplete();
2738 * Test the api_ff_ids() function without an authenticated user.
2740 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2742 public function testApiFfIdsWithoutAuthenticatedUser()
2744 $_SESSION['authenticated'] = false;
2749 * Test the api_friends_ids() function.
2752 public function testApiFriendsIds()
2754 $result = api_friends_ids('json');
2755 $this->assertNull($result);
2759 * Test the api_followers_ids() function.
2762 public function testApiFollowersIds()
2764 $result = api_followers_ids('json');
2765 $this->assertNull($result);
2769 * Test the api_direct_messages_new() function.
2772 public function testApiDirectMessagesNew()
2774 $result = api_direct_messages_new('json');
2775 $this->assertNull($result);
2779 * Test the api_direct_messages_new() function without an authenticated user.
2781 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2783 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2785 $_SESSION['authenticated'] = false;
2786 api_direct_messages_new('json');
2790 * Test the api_direct_messages_new() function with an user ID.
2793 public function testApiDirectMessagesNewWithUserId()
2795 $_POST['text'] = 'message_text';
2796 $_POST['user_id'] = $this->otherUser['id'];
2797 $result = api_direct_messages_new('json');
2798 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2802 * Test the api_direct_messages_new() function with a screen name.
2805 public function testApiDirectMessagesNewWithScreenName()
2807 $_POST['text'] = 'message_text';
2808 $_POST['screen_name'] = $this->friendUser['nick'];
2809 $result = api_direct_messages_new('json');
2810 $this->assertEquals(1, $result['direct_message']['id']);
2811 $this->assertContains('message_text', $result['direct_message']['text']);
2812 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2813 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2817 * Test the api_direct_messages_new() function with a title.
2820 public function testApiDirectMessagesNewWithTitle()
2822 $_POST['text'] = 'message_text';
2823 $_POST['screen_name'] = $this->friendUser['nick'];
2824 $_REQUEST['title'] = 'message_title';
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->assertContains('message_title', $result['direct_message']['text']);
2829 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2830 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2834 * Test the api_direct_messages_new() function with an RSS result.
2837 public function testApiDirectMessagesNewWithRss()
2839 $_POST['text'] = 'message_text';
2840 $_POST['screen_name'] = $this->friendUser['nick'];
2841 $result = api_direct_messages_new('rss');
2842 $this->assertXml($result, 'direct-messages');
2846 * Test the api_direct_messages_destroy() function.
2848 * @expectedException Friendica\Network\HTTPException\BadRequestException
2850 public function testApiDirectMessagesDestroy()
2852 api_direct_messages_destroy('json');
2856 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2859 public function testApiDirectMessagesDestroyWithVerbose()
2861 $_GET['friendica_verbose'] = 'true';
2862 $result = api_direct_messages_destroy('json');
2863 $this->assertEquals(
2866 'result' => 'error',
2867 'message' => 'message id or parenturi not specified'
2875 * Test the api_direct_messages_destroy() function without an authenticated user.
2877 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2879 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2881 $_SESSION['authenticated'] = false;
2882 api_direct_messages_destroy('json');
2886 * Test the api_direct_messages_destroy() function with a non-zero ID.
2888 * @expectedException Friendica\Network\HTTPException\BadRequestException
2890 public function testApiDirectMessagesDestroyWithId()
2892 $_REQUEST['id'] = 1;
2893 api_direct_messages_destroy('json');
2897 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2900 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2902 $_REQUEST['id'] = 1;
2903 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2904 $_GET['friendica_verbose'] = 'true';
2905 $result = api_direct_messages_destroy('json');
2906 $this->assertEquals(
2909 'result' => 'error',
2910 'message' => 'message id not in database'
2918 * Test the api_direct_messages_destroy() function with a non-zero ID.
2921 public function testApiDirectMessagesDestroyWithCorrectId()
2923 $this->markTestIncomplete('We need to add a dataset for this.');
2927 * Test the api_direct_messages_box() function.
2930 public function testApiDirectMessagesBoxWithSentbox()
2932 $_REQUEST['page'] = -1;
2933 $_REQUEST['max_id'] = 10;
2934 $result = api_direct_messages_box('json', 'sentbox', 'false');
2935 $this->assertArrayHasKey('direct_message', $result);
2939 * Test the api_direct_messages_box() function.
2942 public function testApiDirectMessagesBoxWithConversation()
2944 $result = api_direct_messages_box('json', 'conversation', 'false');
2945 $this->assertArrayHasKey('direct_message', $result);
2949 * Test the api_direct_messages_box() function.
2952 public function testApiDirectMessagesBoxWithAll()
2954 $result = api_direct_messages_box('json', 'all', 'false');
2955 $this->assertArrayHasKey('direct_message', $result);
2959 * Test the api_direct_messages_box() function.
2962 public function testApiDirectMessagesBoxWithInbox()
2964 $result = api_direct_messages_box('json', 'inbox', 'false');
2965 $this->assertArrayHasKey('direct_message', $result);
2969 * Test the api_direct_messages_box() function.
2972 public function testApiDirectMessagesBoxWithVerbose()
2974 $result = api_direct_messages_box('json', 'sentbox', 'true');
2975 $this->assertEquals(
2978 'result' => 'error',
2979 'message' => 'no mails available'
2987 * Test the api_direct_messages_box() function with a RSS result.
2990 public function testApiDirectMessagesBoxWithRss()
2992 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2993 $this->assertXml($result, 'direct-messages');
2997 * Test the api_direct_messages_box() function without an authenticated user.
2999 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3001 public function testApiDirectMessagesBoxWithUnallowedUser()
3003 $_SESSION['allow_api'] = false;
3004 $_GET['screen_name'] = $this->selfUser['nick'];
3005 api_direct_messages_box('json', 'sentbox', 'false');
3009 * Test the api_direct_messages_sentbox() function.
3012 public function testApiDirectMessagesSentbox()
3014 $result = api_direct_messages_sentbox('json');
3015 $this->assertArrayHasKey('direct_message', $result);
3019 * Test the api_direct_messages_inbox() function.
3022 public function testApiDirectMessagesInbox()
3024 $result = api_direct_messages_inbox('json');
3025 $this->assertArrayHasKey('direct_message', $result);
3029 * Test the api_direct_messages_all() function.
3032 public function testApiDirectMessagesAll()
3034 $result = api_direct_messages_all('json');
3035 $this->assertArrayHasKey('direct_message', $result);
3039 * Test the api_direct_messages_conversation() function.
3042 public function testApiDirectMessagesConversation()
3044 $result = api_direct_messages_conversation('json');
3045 $this->assertArrayHasKey('direct_message', $result);
3049 * Test the api_oauth_request_token() function.
3052 public function testApiOauthRequestToken()
3054 $this->markTestIncomplete('killme() kills phpunit as well');
3058 * Test the api_oauth_access_token() function.
3061 public function testApiOauthAccessToken()
3063 $this->markTestIncomplete('killme() kills phpunit as well');
3067 * Test the api_fr_photoalbum_delete() function.
3069 * @expectedException Friendica\Network\HTTPException\BadRequestException
3071 public function testApiFrPhotoalbumDelete()
3073 api_fr_photoalbum_delete('json');
3077 * Test the api_fr_photoalbum_delete() function with an album name.
3079 * @expectedException Friendica\Network\HTTPException\BadRequestException
3081 public function testApiFrPhotoalbumDeleteWithAlbum()
3083 $_REQUEST['album'] = 'album_name';
3084 api_fr_photoalbum_delete('json');
3088 * Test the api_fr_photoalbum_delete() function with an album name.
3091 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3093 $this->markTestIncomplete('We need to add a dataset for this.');
3097 * Test the api_fr_photoalbum_delete() function.
3099 * @expectedException Friendica\Network\HTTPException\BadRequestException
3101 public function testApiFrPhotoalbumUpdate()
3103 api_fr_photoalbum_update('json');
3107 * Test the api_fr_photoalbum_delete() function with an album name.
3109 * @expectedException Friendica\Network\HTTPException\BadRequestException
3111 public function testApiFrPhotoalbumUpdateWithAlbum()
3113 $_REQUEST['album'] = 'album_name';
3114 api_fr_photoalbum_update('json');
3118 * Test the api_fr_photoalbum_delete() function with an album name.
3120 * @expectedException Friendica\Network\HTTPException\BadRequestException
3122 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3124 $_REQUEST['album'] = 'album_name';
3125 $_REQUEST['album_new'] = 'album_name';
3126 api_fr_photoalbum_update('json');
3130 * Test the api_fr_photoalbum_update() function without an authenticated user.
3132 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3134 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3136 $_SESSION['authenticated'] = false;
3137 api_fr_photoalbum_update('json');
3141 * Test the api_fr_photoalbum_delete() function with an album name.
3144 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3146 $this->markTestIncomplete('We need to add a dataset for this.');
3150 * Test the api_fr_photos_list() function.
3153 public function testApiFrPhotosList()
3155 $result = api_fr_photos_list('json');
3156 $this->assertArrayHasKey('photo', $result);
3160 * Test the api_fr_photos_list() function without an authenticated user.
3162 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3164 public function testApiFrPhotosListWithoutAuthenticatedUser()
3166 $_SESSION['authenticated'] = false;
3167 api_fr_photos_list('json');
3171 * Test the api_fr_photo_create_update() function.
3173 * @expectedException Friendica\Network\HTTPException\BadRequestException
3175 public function testApiFrPhotoCreateUpdate()
3177 api_fr_photo_create_update('json');
3181 * Test the api_fr_photo_create_update() function without an authenticated user.
3183 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3185 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3187 $_SESSION['authenticated'] = false;
3188 api_fr_photo_create_update('json');
3192 * Test the api_fr_photo_create_update() function with an album name.
3194 * @expectedException Friendica\Network\HTTPException\BadRequestException
3196 public function testApiFrPhotoCreateUpdateWithAlbum()
3198 $_REQUEST['album'] = 'album_name';
3199 api_fr_photo_create_update('json');
3203 * Test the api_fr_photo_create_update() function with the update mode.
3206 public function testApiFrPhotoCreateUpdateWithUpdate()
3208 $this->markTestIncomplete('We need to create a dataset for this');
3212 * Test the api_fr_photo_create_update() function with an uploaded file.
3215 public function testApiFrPhotoCreateUpdateWithFile()
3217 $this->markTestIncomplete();
3221 * Test the api_fr_photo_delete() function.
3223 * @expectedException Friendica\Network\HTTPException\BadRequestException
3225 public function testApiFrPhotoDelete()
3227 api_fr_photo_delete('json');
3231 * Test the api_fr_photo_delete() function without an authenticated user.
3233 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3235 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3237 $_SESSION['authenticated'] = false;
3238 api_fr_photo_delete('json');
3242 * Test the api_fr_photo_delete() function with a photo ID.
3244 * @expectedException Friendica\Network\HTTPException\BadRequestException
3246 public function testApiFrPhotoDeleteWithPhotoId()
3248 $_REQUEST['photo_id'] = 1;
3249 api_fr_photo_delete('json');
3253 * Test the api_fr_photo_delete() function with a correct photo ID.
3256 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3258 $this->markTestIncomplete('We need to create a dataset for this.');
3262 * Test the api_fr_photo_detail() function.
3264 * @expectedException Friendica\Network\HTTPException\BadRequestException
3266 public function testApiFrPhotoDetail()
3268 api_fr_photo_detail('json');
3272 * Test the api_fr_photo_detail() function without an authenticated user.
3274 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3276 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3278 $_SESSION['authenticated'] = false;
3279 api_fr_photo_detail('json');
3283 * Test the api_fr_photo_detail() function with a photo ID.
3285 * @expectedException Friendica\Network\HTTPException\NotFoundException
3287 public function testApiFrPhotoDetailWithPhotoId()
3289 $_REQUEST['photo_id'] = 1;
3290 api_fr_photo_detail('json');
3294 * Test the api_fr_photo_detail() function with a correct photo ID.
3297 public function testApiFrPhotoDetailCorrectPhotoId()
3299 $this->markTestIncomplete('We need to create a dataset for this.');
3303 * Test the api_account_update_profile_image() function.
3305 * @expectedException Friendica\Network\HTTPException\BadRequestException
3307 public function testApiAccountUpdateProfileImage()
3309 api_account_update_profile_image('json');
3313 * Test the api_account_update_profile_image() function without an authenticated user.
3315 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3317 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3319 $_SESSION['authenticated'] = false;
3320 api_account_update_profile_image('json');
3324 * Test the api_account_update_profile_image() function with an uploaded file.
3326 * @expectedException Friendica\Network\HTTPException\BadRequestException
3328 public function testApiAccountUpdateProfileImageWithUpload()
3330 $this->markTestIncomplete();
3335 * Test the api_account_update_profile() function.
3338 public function testApiAccountUpdateProfile()
3340 $_POST['name'] = 'new_name';
3341 $_POST['description'] = 'new_description';
3342 $result = api_account_update_profile('json');
3343 // We can't use assertSelfUser() here because the user object is missing some properties.
3344 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3345 $this->assertEquals('DFRN', $result['user']['location']);
3346 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3347 $this->assertEquals('dfrn', $result['user']['network']);
3348 $this->assertEquals('new_name', $result['user']['name']);
3349 $this->assertEquals('new_description', $result['user']['description']);
3353 * Test the check_acl_input() function.
3356 public function testCheckAclInput()
3358 $result = check_acl_input('<aclstring>');
3359 // Where does this result come from?
3360 $this->assertEquals(1, $result);
3364 * Test the check_acl_input() function with an empty ACL string.
3367 public function testCheckAclInputWithEmptyAclString()
3369 $result = check_acl_input(' ');
3370 $this->assertFalse($result);
3374 * Test the save_media_to_database() function.
3377 public function testSaveMediaToDatabase()
3379 $this->markTestIncomplete();
3383 * Test the post_photo_item() function.
3386 public function testPostPhotoItem()
3388 $this->markTestIncomplete();
3392 * Test the prepare_photo_data() function.
3395 public function testPreparePhotoData()
3397 $this->markTestIncomplete();
3401 * Test the api_friendica_remoteauth() function.
3403 * @expectedException Friendica\Network\HTTPException\BadRequestException
3405 public function testApiFriendicaRemoteauth()
3407 api_friendica_remoteauth();
3411 * Test the api_friendica_remoteauth() function with an URL.
3413 * @expectedException Friendica\Network\HTTPException\BadRequestException
3415 public function testApiFriendicaRemoteauthWithUrl()
3417 $_GET['url'] = 'url';
3418 $_GET['c_url'] = 'url';
3419 api_friendica_remoteauth();
3423 * Test the api_friendica_remoteauth() function with a correct URL.
3426 public function testApiFriendicaRemoteauthWithCorrectUrl()
3428 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3429 $_GET['url'] = 'url';
3430 $_GET['c_url'] = $this->selfUser['nurl'];
3431 api_friendica_remoteauth();
3435 * Test the api_share_as_retweet() function.
3438 public function testApiShareAsRetweet()
3440 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3441 $result = api_share_as_retweet($item);
3442 $this->assertFalse($result);
3446 * Test the api_share_as_retweet() function with a valid item.
3449 public function testApiShareAsRetweetWithValidItem()
3451 $this->markTestIncomplete();
3455 * Test the api_get_nick() function.
3458 public function testApiGetNick()
3460 $result = api_get_nick($this->otherUser['nurl']);
3461 $this->assertEquals('othercontact', $result);
3465 * Test the api_get_nick() function with a wrong URL.
3468 public function testApiGetNickWithWrongUrl()
3470 $result = api_get_nick('wrong_url');
3471 $this->assertFalse($result);
3475 * Test the api_in_reply_to() function.
3478 public function testApiInReplyTo()
3480 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3481 $this->assertArrayHasKey('status_id', $result);
3482 $this->assertArrayHasKey('user_id', $result);
3483 $this->assertArrayHasKey('status_id_str', $result);
3484 $this->assertArrayHasKey('user_id_str', $result);
3485 $this->assertArrayHasKey('screen_name', $result);
3489 * Test the api_in_reply_to() function with a valid item.
3492 public function testApiInReplyToWithValidItem()
3494 $this->markTestIncomplete();
3498 * Test the api_clean_plain_items() function.
3501 public function testApiCleanPlainItems()
3503 $_REQUEST['include_entities'] = 'true';
3504 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3505 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3509 * Test the api_clean_attachments() function.
3512 public function testApiCleanAttachments()
3514 $this->markTestIncomplete();
3518 * Test the api_best_nickname() function.
3521 public function testApiBestNickname()
3524 $result = api_best_nickname($contacts);
3525 $this->assertNull($result);
3529 * Test the api_best_nickname() function with contacts.
3532 public function testApiBestNicknameWithContacts()
3534 $this->markTestIncomplete();
3538 * Test the api_friendica_group_show() function.
3541 public function testApiFriendicaGroupShow()
3543 $this->markTestIncomplete();
3547 * Test the api_friendica_group_delete() function.
3550 public function testApiFriendicaGroupDelete()
3552 $this->markTestIncomplete();
3556 * Test the api_lists_destroy() function.
3559 public function testApiListsDestroy()
3561 $this->markTestIncomplete();
3565 * Test the group_create() function.
3568 public function testGroupCreate()
3570 $this->markTestIncomplete();
3574 * Test the api_friendica_group_create() function.
3577 public function testApiFriendicaGroupCreate()
3579 $this->markTestIncomplete();
3583 * Test the api_lists_create() function.
3586 public function testApiListsCreate()
3588 $this->markTestIncomplete();
3592 * Test the api_friendica_group_update() function.
3595 public function testApiFriendicaGroupUpdate()
3597 $this->markTestIncomplete();
3601 * Test the api_lists_update() function.
3604 public function testApiListsUpdate()
3606 $this->markTestIncomplete();
3610 * Test the api_friendica_activity() function.
3613 public function testApiFriendicaActivity()
3615 $this->markTestIncomplete();
3619 * Test the api_friendica_notification() function.
3621 * @expectedException Friendica\Network\HTTPException\BadRequestException
3623 public function testApiFriendicaNotification()
3625 api_friendica_notification('json');
3629 * Test the api_friendica_notification() function without an authenticated user.
3631 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3633 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3635 $_SESSION['authenticated'] = false;
3636 api_friendica_notification('json');
3640 * Test the api_friendica_notification() function with an argument count.
3643 public function testApiFriendicaNotificationWithArgumentCount()
3645 $this->app->argv = ['api', 'friendica', 'notification'];
3646 $this->app->argc = count($this->app->argv);
3647 $result = api_friendica_notification('json');
3648 $this->assertEquals(['note' => false], $result);
3652 * Test the api_friendica_notification() function with an XML result.
3655 public function testApiFriendicaNotificationWithXmlResult()
3657 $this->app->argv = ['api', 'friendica', 'notification'];
3658 $this->app->argc = count($this->app->argv);
3659 $result = api_friendica_notification('xml');
3660 $this->assertXml($result, 'notes');
3664 * Test the api_friendica_notification_seen() function.
3667 public function testApiFriendicaNotificationSeen()
3669 $this->markTestIncomplete();
3673 * Test the api_friendica_direct_messages_setseen() function.
3676 public function testApiFriendicaDirectMessagesSetseen()
3678 $this->markTestIncomplete();
3682 * Test the api_friendica_direct_messages_search() function.
3685 public function testApiFriendicaDirectMessagesSearch()
3687 $this->markTestIncomplete();
3691 * Test the api_friendica_profile_show() function.
3694 public function testApiFriendicaProfileShow()
3696 $result = api_friendica_profile_show('json');
3697 // We can't use assertSelfUser() here because the user object is missing some properties.
3698 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3699 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3700 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3701 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3702 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3703 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3704 $this->assertFalse($result['$result']['multi_profiles']);
3708 * Test the api_friendica_profile_show() function with a profile ID.
3711 public function testApiFriendicaProfileShowWithProfileId()
3713 $this->markTestIncomplete('We need to add a dataset for this.');
3717 * Test the api_friendica_profile_show() function with a wrong profile ID.
3719 * @expectedException Friendica\Network\HTTPException\BadRequestException
3721 public function testApiFriendicaProfileShowWithWrongProfileId()
3723 $_REQUEST['profile_id'] = 666;
3724 api_friendica_profile_show('json');
3728 * Test the api_friendica_profile_show() function without an authenticated user.
3730 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3732 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3734 $_SESSION['authenticated'] = false;
3735 api_friendica_profile_show('json');
3739 * Test the api_saved_searches_list() function.
3742 public function testApiSavedSearchesList()
3744 $result = api_saved_searches_list('json');
3745 $this->assertEquals(1, $result['terms'][0]['id']);
3746 $this->assertEquals(1, $result['terms'][0]['id_str']);
3747 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3748 $this->assertEquals('Saved search', $result['terms'][0]['query']);