6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Factory;
14 use Friendica\Network\HTTPException;
15 use Friendica\Util\BasePath;
16 use Friendica\Util\Config\ConfigFileLoader;
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
40 protected $friendUser;
44 protected $wrongUserId;
47 * Create variables used by tests.
49 public function setUp()
51 $basePath = BasePath::create(dirname(__DIR__) . '/../');
52 $mode = new App\Mode($basePath);
53 $router = new App\Router();
54 $configLoader = new ConfigFileLoader($basePath, $mode);
55 $configCache = Factory\ConfigFactory::createCache($configLoader);
56 $profiler = Factory\ProfilerFactory::create($configCache);
57 Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
58 $config = Factory\ConfigFactory::createConfig($configCache);
59 Factory\ConfigFactory::createPConfig($configCache);
60 $logger = Factory\LoggerFactory::create('test', $config, $profiler);
61 $this->app = new App($config, $mode, $router, $logger, $profiler, false);
65 // User data that the test database is populated with
68 'name' => 'Self contact',
69 'nick' => 'selfcontact',
70 'nurl' => 'http://localhost/profile/selfcontact'
74 'name' => 'Friend contact',
75 'nick' => 'friendcontact',
76 'nurl' => 'http://localhost/profile/friendcontact'
80 'name' => 'othercontact',
81 'nick' => 'othercontact',
82 'nurl' => 'http://localhost/profile/othercontact'
85 // User ID that we know is not in the database
86 $this->wrongUserId = 666;
88 // Most API require login so we force the session
91 'authenticated' => true,
92 'uid' => $this->selfUser['id']
95 Config::set('system', 'url', 'http://localhost');
96 Config::set('system', 'hostname', 'localhost');
97 Config::set('system', 'worker_dont_fork', true);
100 Config::set('config', 'hostname', 'localhost');
101 Config::set('system', 'throttle_limit_day', 100);
102 Config::set('system', 'throttle_limit_week', 100);
103 Config::set('system', 'throttle_limit_month', 100);
104 Config::set('system', 'theme', 'system_theme');
108 * Cleanup variables used by tests.
110 protected function tearDown()
114 $this->app->argc = 1;
115 $this->app->argv = ['home'];
119 * Assert that an user array contains expected keys.
120 * @param array $user User array
123 private function assertSelfUser(array $user)
125 $this->assertEquals($this->selfUser['id'], $user['uid']);
126 $this->assertEquals($this->selfUser['id'], $user['cid']);
127 $this->assertEquals(1, $user['self']);
128 $this->assertEquals('DFRN', $user['location']);
129 $this->assertEquals($this->selfUser['name'], $user['name']);
130 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
131 $this->assertEquals('dfrn', $user['network']);
132 $this->assertTrue($user['verified']);
136 * Assert that an user array contains expected keys.
137 * @param array $user User array
140 private function assertOtherUser(array $user)
142 $this->assertEquals($this->otherUser['id'], $user['id']);
143 $this->assertEquals($this->otherUser['id'], $user['id_str']);
144 $this->assertEquals(0, $user['self']);
145 $this->assertEquals($this->otherUser['name'], $user['name']);
146 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
147 $this->assertFalse($user['verified']);
151 * Assert that a status array contains expected keys.
152 * @param array $status Status array
155 private function assertStatus(array $status)
157 $this->assertInternalType('string', $status['text']);
158 $this->assertInternalType('int', $status['id']);
159 // We could probably do more checks here.
163 * Assert that a list array contains expected keys.
164 * @param array $list List array
167 private function assertList(array $list)
169 $this->assertInternalType('string', $list['name']);
170 $this->assertInternalType('int', $list['id']);
171 $this->assertInternalType('string', $list['id_str']);
172 $this->assertContains($list['mode'], ['public', 'private']);
173 // We could probably do more checks here.
177 * Assert that the string is XML and contain the root element.
178 * @param string $result XML string
179 * @param string $root_element Root element name
182 private function assertXml($result, $root_element)
184 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
185 $this->assertContains('<'.$root_element, $result);
186 // We could probably do more checks here.
190 * Get the path to a temporary empty PNG image.
191 * @return string Path
193 private function getTempImage()
195 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
199 // Empty 1x1 px PNG image
200 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
208 * Test the api_user() function.
211 public function testApiUser()
213 $this->assertEquals($this->selfUser['id'], api_user());
217 * Test the api_user() function with an unallowed user.
220 public function testApiUserWithUnallowedUser()
222 $_SESSION = ['allow_api' => false];
223 $this->assertEquals(false, api_user());
227 * Test the api_source() function.
230 public function testApiSource()
232 $this->assertEquals('api', api_source());
236 * Test the api_source() function with a Twidere user agent.
239 public function testApiSourceWithTwidere()
241 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
242 $this->assertEquals('Twidere', api_source());
246 * Test the api_source() function with a GET parameter.
249 public function testApiSourceWithGet()
251 $_GET['source'] = 'source_name';
252 $this->assertEquals('source_name', api_source());
256 * Test the api_date() function.
259 public function testApiDate()
261 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
265 * Test the api_register_func() function.
268 public function testApiRegisterFunc()
280 $this->assertTrue($API['api_path']['auth']);
281 $this->assertEquals('method', $API['api_path']['method']);
282 $this->assertTrue(is_callable($API['api_path']['func']));
286 * Test the api_login() function without any login.
288 * @runInSeparateProcess
289 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
291 public function testApiLoginWithoutLogin()
293 api_login($this->app);
297 * Test the api_login() function with a bad login.
299 * @runInSeparateProcess
300 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
302 public function testApiLoginWithBadLogin()
304 $_SERVER['PHP_AUTH_USER'] = 'user@server';
305 api_login($this->app);
309 * Test the api_login() function with oAuth.
312 public function testApiLoginWithOauth()
314 $this->markTestIncomplete('Can we test this easily?');
318 * Test the api_login() function with authentication provided by an addon.
321 public function testApiLoginWithAddonAuth()
323 $this->markTestIncomplete('Can we test this easily?');
327 * Test the api_login() function with a correct login.
329 * @runInSeparateProcess
331 public function testApiLoginWithCorrectLogin()
333 $_SERVER['PHP_AUTH_USER'] = 'Test user';
334 $_SERVER['PHP_AUTH_PW'] = 'password';
335 api_login($this->app);
339 * Test the api_login() function with a remote user.
341 * @runInSeparateProcess
342 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
344 public function testApiLoginWithRemoteUser()
346 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
347 api_login($this->app);
351 * Test the api_check_method() function.
354 public function testApiCheckMethod()
356 $this->assertFalse(api_check_method('method'));
360 * Test the api_check_method() function with a correct method.
363 public function testApiCheckMethodWithCorrectMethod()
365 $_SERVER['REQUEST_METHOD'] = 'method';
366 $this->assertTrue(api_check_method('method'));
370 * Test the api_check_method() function with a wildcard.
373 public function testApiCheckMethodWithWildcard()
375 $this->assertTrue(api_check_method('*'));
379 * Test the api_call() function.
381 * @runInSeparateProcess
383 public function testApiCall()
387 'method' => 'method',
388 'func' => function () {
389 return ['data' => ['some_data']];
392 $_SERVER['REQUEST_METHOD'] = 'method';
393 $_GET['callback'] = 'callback_name';
395 $this->app->query_string = 'api_path';
397 'callback_name(["some_data"])',
403 * Test the api_call() function with the profiled enabled.
405 * @runInSeparateProcess
407 public function testApiCallWithProfiler()
411 'method' => 'method',
412 'func' => function () {
413 return ['data' => ['some_data']];
416 $_SERVER['REQUEST_METHOD'] = 'method';
417 Config::set('system', 'profiler', true);
418 Config::set('rendertime', 'callstack', true);
419 $this->app->callstack = [
420 'database' => ['some_function' => 200],
421 'database_write' => ['some_function' => 200],
422 'cache' => ['some_function' => 200],
423 'cache_write' => ['some_function' => 200],
424 'network' => ['some_function' => 200]
427 $this->app->query_string = 'api_path';
435 * Test the api_call() function without any result.
437 * @runInSeparateProcess
439 public function testApiCallWithNoResult()
443 'method' => 'method',
444 'func' => function () {
448 $_SERVER['REQUEST_METHOD'] = 'method';
450 $this->app->query_string = 'api_path';
452 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
458 * Test the api_call() function with an unimplemented API.
460 * @runInSeparateProcess
462 public function testApiCallWithUninplementedApi()
465 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
471 * Test the api_call() function with a JSON result.
473 * @runInSeparateProcess
475 public function testApiCallWithJson()
479 'method' => 'method',
480 'func' => function () {
481 return ['data' => ['some_data']];
484 $_SERVER['REQUEST_METHOD'] = 'method';
486 $this->app->query_string = 'api_path.json';
494 * Test the api_call() function with an XML result.
496 * @runInSeparateProcess
498 public function testApiCallWithXml()
502 'method' => 'method',
503 'func' => function () {
507 $_SERVER['REQUEST_METHOD'] = 'method';
509 $this->app->query_string = 'api_path.xml';
517 * Test the api_call() function with an RSS result.
519 * @runInSeparateProcess
521 public function testApiCallWithRss()
525 'method' => 'method',
526 'func' => function () {
530 $_SERVER['REQUEST_METHOD'] = 'method';
532 $this->app->query_string = 'api_path.rss';
534 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
541 * Test the api_call() function with an Atom result.
543 * @runInSeparateProcess
545 public function testApiCallWithAtom()
549 'method' => 'method',
550 'func' => function () {
554 $_SERVER['REQUEST_METHOD'] = 'method';
556 $this->app->query_string = 'api_path.atom';
558 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
565 * Test the api_call() function with an unallowed method.
567 * @runInSeparateProcess
569 public function testApiCallWithWrongMethod()
572 $API['api_path'] = ['method' => 'method'];
574 $this->app->query_string = 'api_path';
576 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
582 * Test the api_call() function with an unauthorized user.
584 * @runInSeparateProcess
586 public function testApiCallWithWrongAuth()
590 'method' => 'method',
593 $_SERVER['REQUEST_METHOD'] = 'method';
594 $_SESSION['authenticated'] = false;
596 $this->app->query_string = 'api_path';
598 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
604 * Test the api_error() function with a JSON result.
606 * @runInSeparateProcess
608 public function testApiErrorWithJson()
611 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
612 api_error('json', new HTTPException('error_message'))
617 * Test the api_error() function with an XML result.
619 * @runInSeparateProcess
621 public function testApiErrorWithXml()
624 '<?xml version="1.0"?>'."\n".
625 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
626 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
627 'xmlns:georss="http://www.georss.org/georss">'."\n".
628 ' <error>error_message</error>'."\n".
629 ' <code>200 Friendica\Network\HTTP</code>'."\n".
632 api_error('xml', new HTTPException('error_message'))
637 * Test the api_error() function with an RSS result.
639 * @runInSeparateProcess
641 public function testApiErrorWithRss()
644 '<?xml version="1.0"?>'."\n".
645 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
646 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
647 'xmlns:georss="http://www.georss.org/georss">'."\n".
648 ' <error>error_message</error>'."\n".
649 ' <code>200 Friendica\Network\HTTP</code>'."\n".
652 api_error('rss', new HTTPException('error_message'))
657 * Test the api_error() function with an Atom result.
659 * @runInSeparateProcess
661 public function testApiErrorWithAtom()
664 '<?xml version="1.0"?>'."\n".
665 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
666 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
667 'xmlns:georss="http://www.georss.org/georss">'."\n".
668 ' <error>error_message</error>'."\n".
669 ' <code>200 Friendica\Network\HTTP</code>'."\n".
672 api_error('atom', new HTTPException('error_message'))
677 * Test the api_rss_extra() function.
680 public function testApiRssExtra()
682 $user_info = ['url' => 'user_url', 'lang' => 'en'];
683 $result = api_rss_extra($this->app, [], $user_info);
684 $this->assertEquals($user_info, $result['$user']);
685 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
686 $this->assertArrayHasKey('self', $result['$rss']);
687 $this->assertArrayHasKey('base', $result['$rss']);
688 $this->assertArrayHasKey('updated', $result['$rss']);
689 $this->assertArrayHasKey('atom_updated', $result['$rss']);
690 $this->assertArrayHasKey('language', $result['$rss']);
691 $this->assertArrayHasKey('logo', $result['$rss']);
695 * Test the api_rss_extra() function without any user info.
697 * @runInSeparateProcess
699 public function testApiRssExtraWithoutUserInfo()
701 $result = api_rss_extra($this->app, [], null);
702 $this->assertInternalType('array', $result['$user']);
703 $this->assertArrayHasKey('alternate', $result['$rss']);
704 $this->assertArrayHasKey('self', $result['$rss']);
705 $this->assertArrayHasKey('base', $result['$rss']);
706 $this->assertArrayHasKey('updated', $result['$rss']);
707 $this->assertArrayHasKey('atom_updated', $result['$rss']);
708 $this->assertArrayHasKey('language', $result['$rss']);
709 $this->assertArrayHasKey('logo', $result['$rss']);
713 * Test the api_unique_id_to_nurl() function.
716 public function testApiUniqueIdToNurl()
718 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
722 * Test the api_unique_id_to_nurl() function with a correct ID.
725 public function testApiUniqueIdToNurlWithCorrectId()
727 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
731 * Test the api_get_user() function.
733 * @runInSeparateProcess
735 public function testApiGetUser()
737 $user = api_get_user($this->app);
738 $this->assertSelfUser($user);
739 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
740 $this->assertEquals('6fdbe8', $user['profile_link_color']);
741 $this->assertEquals('ededed', $user['profile_background_color']);
745 * Test the api_get_user() function with a Frio schema.
747 * @runInSeparateProcess
749 public function testApiGetUserWithFrioSchema()
751 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
752 $user = api_get_user($this->app);
753 $this->assertSelfUser($user);
754 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
755 $this->assertEquals('6fdbe8', $user['profile_link_color']);
756 $this->assertEquals('ededed', $user['profile_background_color']);
760 * Test the api_get_user() function with a custom Frio schema.
762 * @runInSeparateProcess
764 public function testApiGetUserWithCustomFrioSchema()
766 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
767 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
768 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
769 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
770 $user = api_get_user($this->app);
771 $this->assertSelfUser($user);
772 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
773 $this->assertEquals('123456', $user['profile_link_color']);
774 $this->assertEquals('123456', $user['profile_background_color']);
778 * Test the api_get_user() function with an empty Frio schema.
780 * @runInSeparateProcess
782 public function testApiGetUserWithEmptyFrioSchema()
784 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
785 $user = api_get_user($this->app);
786 $this->assertSelfUser($user);
787 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
788 $this->assertEquals('6fdbe8', $user['profile_link_color']);
789 $this->assertEquals('ededed', $user['profile_background_color']);
793 * Test the api_get_user() function with an user that is not allowed to use the API.
795 * @runInSeparateProcess
797 public function testApiGetUserWithoutApiUser()
799 $_SERVER['PHP_AUTH_USER'] = 'Test user';
800 $_SERVER['PHP_AUTH_PW'] = 'password';
801 $_SESSION['allow_api'] = false;
802 $this->assertFalse(api_get_user($this->app));
806 * Test the api_get_user() function with an user ID in a GET parameter.
808 * @runInSeparateProcess
810 public function testApiGetUserWithGetId()
812 $_GET['user_id'] = $this->otherUser['id'];
813 $this->assertOtherUser(api_get_user($this->app));
817 * Test the api_get_user() function with a wrong user ID in a GET parameter.
819 * @runInSeparateProcess
820 * @expectedException Friendica\Network\HTTPException\BadRequestException
822 public function testApiGetUserWithWrongGetId()
824 $_GET['user_id'] = $this->wrongUserId;
825 $this->assertOtherUser(api_get_user($this->app));
829 * Test the api_get_user() function with an user name in a GET parameter.
831 * @runInSeparateProcess
833 public function testApiGetUserWithGetName()
835 $_GET['screen_name'] = $this->selfUser['nick'];
836 $this->assertSelfUser(api_get_user($this->app));
840 * Test the api_get_user() function with a profile URL in a GET parameter.
842 * @runInSeparateProcess
844 public function testApiGetUserWithGetUrl()
846 $_GET['profileurl'] = $this->selfUser['nurl'];
847 $this->assertSelfUser(api_get_user($this->app));
851 * Test the api_get_user() function with an user ID in the API path.
853 * @runInSeparateProcess
855 public function testApiGetUserWithNumericCalledApi()
858 $called_api = ['api_path'];
859 $this->app->argv[1] = $this->otherUser['id'].'.json';
860 $this->assertOtherUser(api_get_user($this->app));
864 * Test the api_get_user() function with the $called_api global variable.
866 * @runInSeparateProcess
868 public function testApiGetUserWithCalledApi()
871 $called_api = ['api', 'api_path'];
872 $this->assertSelfUser(api_get_user($this->app));
876 * Test the api_get_user() function with a valid user.
878 * @runInSeparateProcess
880 public function testApiGetUserWithCorrectUser()
882 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
886 * Test the api_get_user() function with a wrong user ID.
888 * @runInSeparateProcess
889 * @expectedException Friendica\Network\HTTPException\BadRequestException
891 public function testApiGetUserWithWrongUser()
893 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
897 * Test the api_get_user() function with a 0 user ID.
899 * @runInSeparateProcess
901 public function testApiGetUserWithZeroUser()
903 $this->assertSelfUser(api_get_user($this->app, 0));
907 * Test the api_item_get_user() function.
909 * @runInSeparateProcess
911 public function testApiItemGetUser()
913 $users = api_item_get_user($this->app, []);
914 $this->assertSelfUser($users[0]);
918 * Test the api_item_get_user() function with a different item parent.
921 public function testApiItemGetUserWithDifferentParent()
923 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
924 $this->assertSelfUser($users[0]);
925 $this->assertEquals($users[0], $users[1]);
929 * Test the api_walk_recursive() function.
932 public function testApiWalkRecursive()
940 // Should we test this with a callback that actually does something?
948 * Test the api_walk_recursive() function with an array.
951 public function testApiWalkRecursiveWithArray()
953 $array = [['item1'], ['item2']];
959 // Should we test this with a callback that actually does something?
967 * Test the api_reformat_xml() function.
970 public function testApiReformatXml()
974 $this->assertTrue(api_reformat_xml($item, $key));
975 $this->assertEquals('true', $item);
979 * Test the api_reformat_xml() function with a statusnet_api key.
982 public function testApiReformatXmlWithStatusnetKey()
985 $key = 'statusnet_api';
986 $this->assertTrue(api_reformat_xml($item, $key));
987 $this->assertEquals('statusnet:api', $key);
991 * Test the api_reformat_xml() function with a friendica_api key.
994 public function testApiReformatXmlWithFriendicaKey()
997 $key = 'friendica_api';
998 $this->assertTrue(api_reformat_xml($item, $key));
999 $this->assertEquals('friendica:api', $key);
1003 * Test the api_create_xml() function.
1006 public function testApiCreateXml()
1008 $this->assertEquals(
1009 '<?xml version="1.0"?>'."\n".
1010 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1011 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1012 'xmlns:georss="http://www.georss.org/georss">'."\n".
1013 ' <data>some_data</data>'."\n".
1014 '</root_element>'."\n",
1015 api_create_xml(['data' => ['some_data']], 'root_element')
1020 * Test the api_create_xml() function without any XML namespace.
1023 public function testApiCreateXmlWithoutNamespaces()
1025 $this->assertEquals(
1026 '<?xml version="1.0"?>'."\n".
1028 ' <data>some_data</data>'."\n".
1030 api_create_xml(['data' => ['some_data']], 'ok')
1035 * Test the api_format_data() function.
1038 public function testApiFormatData()
1040 $data = ['some_data'];
1041 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1045 * Test the api_format_data() function with an XML result.
1048 public function testApiFormatDataWithXml()
1050 $this->assertEquals(
1051 '<?xml version="1.0"?>'."\n".
1052 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1053 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1054 'xmlns:georss="http://www.georss.org/georss">'."\n".
1055 ' <data>some_data</data>'."\n".
1056 '</root_element>'."\n",
1057 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1062 * Test the api_account_verify_credentials() function.
1065 public function testApiAccountVerifyCredentials()
1067 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1071 * Test the api_account_verify_credentials() function without an authenticated user.
1073 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1075 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1077 $_SESSION['authenticated'] = false;
1078 api_account_verify_credentials('json');
1082 * Test the requestdata() function.
1085 public function testRequestdata()
1087 $this->assertNull(requestdata('variable_name'));
1091 * Test the requestdata() function with a POST parameter.
1094 public function testRequestdataWithPost()
1096 $_POST['variable_name'] = 'variable_value';
1097 $this->assertEquals('variable_value', requestdata('variable_name'));
1101 * Test the requestdata() function with a GET parameter.
1104 public function testRequestdataWithGet()
1106 $_GET['variable_name'] = 'variable_value';
1107 $this->assertEquals('variable_value', requestdata('variable_name'));
1111 * Test the api_statuses_mediap() function.
1114 public function testApiStatusesMediap()
1116 $this->app->argc = 2;
1124 'tmp_name' => $this->getTempImage(),
1125 'name' => 'spacer.png',
1126 'type' => 'image/png'
1129 $_GET['status'] = '<b>Status content</b>';
1131 $result = api_statuses_mediap('json');
1132 $this->assertStatus($result['status']);
1136 * Test the api_statuses_mediap() function without an authenticated user.
1138 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1140 public function testApiStatusesMediapWithoutAuthenticatedUser()
1142 $_SESSION['authenticated'] = false;
1143 api_statuses_mediap('json');
1147 * Test the api_statuses_update() function.
1150 public function testApiStatusesUpdate()
1152 $_GET['status'] = 'Status content #friendica';
1153 $_GET['in_reply_to_status_id'] = -1;
1162 'tmp_name' => $this->getTempImage(),
1163 'name' => 'spacer.png',
1164 'type' => 'image/png'
1168 $result = api_statuses_update('json');
1169 $this->assertStatus($result['status']);
1173 * Test the api_statuses_update() function with an HTML status.
1176 public function testApiStatusesUpdateWithHtml()
1178 $_GET['htmlstatus'] = '<b>Status content</b>';
1180 $result = api_statuses_update('json');
1181 $this->assertStatus($result['status']);
1185 * Test the api_statuses_update() function without an authenticated user.
1187 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1189 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1191 $_SESSION['authenticated'] = false;
1192 api_statuses_update('json');
1196 * Test the api_statuses_update() function with a parent status.
1199 public function testApiStatusesUpdateWithParent()
1201 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1205 * Test the api_statuses_update() function with a media_ids parameter.
1208 public function testApiStatusesUpdateWithMediaIds()
1210 $this->markTestIncomplete();
1214 * Test the api_statuses_update() function with the throttle limit reached.
1217 public function testApiStatusesUpdateWithDayThrottleReached()
1219 $this->markTestIncomplete();
1223 * Test the api_media_upload() function.
1225 * @expectedException Friendica\Network\HTTPException\BadRequestException
1227 public function testApiMediaUpload()
1233 * Test the api_media_upload() function without an authenticated user.
1235 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1237 public function testApiMediaUploadWithoutAuthenticatedUser()
1239 $_SESSION['authenticated'] = false;
1244 * Test the api_media_upload() function with an invalid uploaded media.
1246 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1248 public function testApiMediaUploadWithMedia()
1253 'tmp_name' => 'tmp_name'
1260 * Test the api_media_upload() function with an valid uploaded media.
1263 public function testApiMediaUploadWithValidMedia()
1271 'tmp_name' => $this->getTempImage(),
1272 'name' => 'spacer.png',
1273 'type' => 'image/png'
1279 $result = api_media_upload();
1280 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1281 $this->assertEquals(1, $result['media']['image']['w']);
1282 $this->assertEquals(1, $result['media']['image']['h']);
1283 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1287 * Test the api_status_show() function.
1289 public function testApiStatusShowWithJson()
1291 $result = api_status_show('json', 1);
1292 $this->assertStatus($result['status']);
1296 * Test the api_status_show() function with an XML result.
1298 public function testApiStatusShowWithXml()
1300 $result = api_status_show('xml', 1);
1301 $this->assertXml($result, 'statuses');
1305 * Test the api_get_last_status() function
1307 public function testApiGetLastStatus()
1309 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1311 $this->assertNotNull($item);
1315 * Test the api_users_show() function.
1318 public function testApiUsersShow()
1320 $result = api_users_show('json');
1321 // We can't use assertSelfUser() here because the user object is missing some properties.
1322 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1323 $this->assertEquals('DFRN', $result['user']['location']);
1324 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1325 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1326 $this->assertEquals('dfrn', $result['user']['network']);
1327 $this->assertTrue($result['user']['verified']);
1331 * Test the api_users_show() function with an XML result.
1334 public function testApiUsersShowWithXml()
1336 $result = api_users_show('xml');
1337 $this->assertXml($result, 'statuses');
1341 * Test the api_users_search() function.
1344 public function testApiUsersSearch()
1346 $_GET['q'] = 'othercontact';
1347 $result = api_users_search('json');
1348 $this->assertOtherUser($result['users'][0]);
1352 * Test the api_users_search() function with an XML result.
1355 public function testApiUsersSearchWithXml()
1357 $_GET['q'] = 'othercontact';
1358 $result = api_users_search('xml');
1359 $this->assertXml($result, 'users');
1363 * Test the api_users_search() function without a GET q parameter.
1365 * @expectedException Friendica\Network\HTTPException\BadRequestException
1367 public function testApiUsersSearchWithoutQuery()
1369 api_users_search('json');
1373 * Test the api_users_lookup() function.
1375 * @expectedException Friendica\Network\HTTPException\NotFoundException
1377 public function testApiUsersLookup()
1379 api_users_lookup('json');
1383 * Test the api_users_lookup() function with an user ID.
1386 public function testApiUsersLookupWithUserId()
1388 $_REQUEST['user_id'] = $this->otherUser['id'];
1389 $result = api_users_lookup('json');
1390 $this->assertOtherUser($result['users'][0]);
1394 * Test the api_search() function.
1397 public function testApiSearch()
1399 $_REQUEST['q'] = 'reply';
1400 $_REQUEST['max_id'] = 10;
1401 $result = api_search('json');
1402 foreach ($result['status'] as $status) {
1403 $this->assertStatus($status);
1404 $this->assertContains('reply', $status['text'], null, true);
1409 * Test the api_search() function a count parameter.
1412 public function testApiSearchWithCount()
1414 $_REQUEST['q'] = 'reply';
1415 $_REQUEST['count'] = 20;
1416 $result = api_search('json');
1417 foreach ($result['status'] as $status) {
1418 $this->assertStatus($status);
1419 $this->assertContains('reply', $status['text'], null, true);
1424 * Test the api_search() function with an rpp parameter.
1427 public function testApiSearchWithRpp()
1429 $_REQUEST['q'] = 'reply';
1430 $_REQUEST['rpp'] = 20;
1431 $result = api_search('json');
1432 foreach ($result['status'] as $status) {
1433 $this->assertStatus($status);
1434 $this->assertContains('reply', $status['text'], null, true);
1439 * Test the api_search() function with an q parameter contains hashtag.
1442 public function testApiSearchWithHashtag()
1444 $_REQUEST['q'] = '%23friendica';
1445 $result = api_search('json');
1446 foreach ($result['status'] as $status) {
1447 $this->assertStatus($status);
1448 $this->assertContains('#friendica', $status['text'], null, true);
1453 * Test the api_search() function with an exclude_replies parameter.
1456 public function testApiSearchWithExcludeReplies()
1458 $_REQUEST['max_id'] = 10;
1459 $_REQUEST['exclude_replies'] = true;
1460 $_REQUEST['q'] = 'friendica';
1461 $result = api_search('json');
1462 foreach ($result['status'] as $status) {
1463 $this->assertStatus($status);
1468 * Test the api_search() function without an authenticated user.
1470 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1472 public function testApiSearchWithUnallowedUser()
1474 $_SESSION['allow_api'] = false;
1475 $_GET['screen_name'] = $this->selfUser['nick'];
1480 * Test the api_search() function without any GET query parameter.
1482 * @expectedException Friendica\Network\HTTPException\BadRequestException
1484 public function testApiSearchWithoutQuery()
1490 * Test the api_statuses_home_timeline() function.
1493 public function testApiStatusesHomeTimeline()
1495 $_REQUEST['max_id'] = 10;
1496 $_REQUEST['exclude_replies'] = true;
1497 $_REQUEST['conversation_id'] = 1;
1498 $result = api_statuses_home_timeline('json');
1499 $this->assertNotEmpty($result['status']);
1500 foreach ($result['status'] as $status) {
1501 $this->assertStatus($status);
1506 * Test the api_statuses_home_timeline() function with a negative page parameter.
1509 public function testApiStatusesHomeTimelineWithNegativePage()
1511 $_REQUEST['page'] = -2;
1512 $result = api_statuses_home_timeline('json');
1513 $this->assertNotEmpty($result['status']);
1514 foreach ($result['status'] as $status) {
1515 $this->assertStatus($status);
1520 * Test the api_statuses_home_timeline() with an unallowed user.
1522 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1524 public function testApiStatusesHomeTimelineWithUnallowedUser()
1526 $_SESSION['allow_api'] = false;
1527 $_GET['screen_name'] = $this->selfUser['nick'];
1528 api_statuses_home_timeline('json');
1532 * Test the api_statuses_home_timeline() function with an RSS result.
1535 public function testApiStatusesHomeTimelineWithRss()
1537 $result = api_statuses_home_timeline('rss');
1538 $this->assertXml($result, 'statuses');
1542 * Test the api_statuses_public_timeline() function.
1545 public function testApiStatusesPublicTimeline()
1547 $_REQUEST['max_id'] = 10;
1548 $_REQUEST['conversation_id'] = 1;
1549 $result = api_statuses_public_timeline('json');
1550 $this->assertNotEmpty($result['status']);
1551 foreach ($result['status'] as $status) {
1552 $this->assertStatus($status);
1557 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1560 public function testApiStatusesPublicTimelineWithExcludeReplies()
1562 $_REQUEST['max_id'] = 10;
1563 $_REQUEST['exclude_replies'] = true;
1564 $result = api_statuses_public_timeline('json');
1565 $this->assertNotEmpty($result['status']);
1566 foreach ($result['status'] as $status) {
1567 $this->assertStatus($status);
1572 * Test the api_statuses_public_timeline() function with a negative page parameter.
1575 public function testApiStatusesPublicTimelineWithNegativePage()
1577 $_REQUEST['page'] = -2;
1578 $result = api_statuses_public_timeline('json');
1579 $this->assertNotEmpty($result['status']);
1580 foreach ($result['status'] as $status) {
1581 $this->assertStatus($status);
1586 * Test the api_statuses_public_timeline() function with an unallowed user.
1588 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1590 public function testApiStatusesPublicTimelineWithUnallowedUser()
1592 $_SESSION['allow_api'] = false;
1593 $_GET['screen_name'] = $this->selfUser['nick'];
1594 api_statuses_public_timeline('json');
1598 * Test the api_statuses_public_timeline() function with an RSS result.
1601 public function testApiStatusesPublicTimelineWithRss()
1603 $result = api_statuses_public_timeline('rss');
1604 $this->assertXml($result, 'statuses');
1608 * Test the api_statuses_networkpublic_timeline() function.
1611 public function testApiStatusesNetworkpublicTimeline()
1613 $_REQUEST['max_id'] = 10;
1614 $result = api_statuses_networkpublic_timeline('json');
1615 $this->assertNotEmpty($result['status']);
1616 foreach ($result['status'] as $status) {
1617 $this->assertStatus($status);
1622 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1625 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1627 $_REQUEST['page'] = -2;
1628 $result = api_statuses_networkpublic_timeline('json');
1629 $this->assertNotEmpty($result['status']);
1630 foreach ($result['status'] as $status) {
1631 $this->assertStatus($status);
1636 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1638 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1640 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1642 $_SESSION['allow_api'] = false;
1643 $_GET['screen_name'] = $this->selfUser['nick'];
1644 api_statuses_networkpublic_timeline('json');
1648 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1651 public function testApiStatusesNetworkpublicTimelineWithRss()
1653 $result = api_statuses_networkpublic_timeline('rss');
1654 $this->assertXml($result, 'statuses');
1658 * Test the api_statuses_show() function.
1660 * @expectedException Friendica\Network\HTTPException\BadRequestException
1662 public function testApiStatusesShow()
1664 api_statuses_show('json');
1668 * Test the api_statuses_show() function with an ID.
1671 public function testApiStatusesShowWithId()
1673 $this->app->argv[3] = 1;
1674 $result = api_statuses_show('json');
1675 $this->assertStatus($result['status']);
1679 * Test the api_statuses_show() function with the conversation parameter.
1682 public function testApiStatusesShowWithConversation()
1684 $this->app->argv[3] = 1;
1685 $_REQUEST['conversation'] = 1;
1686 $result = api_statuses_show('json');
1687 $this->assertNotEmpty($result['status']);
1688 foreach ($result['status'] as $status) {
1689 $this->assertStatus($status);
1694 * Test the api_statuses_show() function with an unallowed user.
1696 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1698 public function testApiStatusesShowWithUnallowedUser()
1700 $_SESSION['allow_api'] = false;
1701 $_GET['screen_name'] = $this->selfUser['nick'];
1702 api_statuses_show('json');
1706 * Test the api_conversation_show() function.
1708 * @expectedException Friendica\Network\HTTPException\BadRequestException
1710 public function testApiConversationShow()
1712 api_conversation_show('json');
1716 * Test the api_conversation_show() function with an ID.
1719 public function testApiConversationShowWithId()
1721 $this->app->argv[3] = 1;
1722 $_REQUEST['max_id'] = 10;
1723 $_REQUEST['page'] = -2;
1724 $result = api_conversation_show('json');
1725 $this->assertNotEmpty($result['status']);
1726 foreach ($result['status'] as $status) {
1727 $this->assertStatus($status);
1732 * Test the api_conversation_show() function with an unallowed user.
1734 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1736 public function testApiConversationShowWithUnallowedUser()
1738 $_SESSION['allow_api'] = false;
1739 $_GET['screen_name'] = $this->selfUser['nick'];
1740 api_conversation_show('json');
1744 * Test the api_statuses_repeat() function.
1746 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1748 public function testApiStatusesRepeat()
1750 api_statuses_repeat('json');
1754 * Test the api_statuses_repeat() function without an authenticated user.
1756 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1758 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1760 $_SESSION['authenticated'] = false;
1761 api_statuses_repeat('json');
1765 * Test the api_statuses_repeat() function with an ID.
1768 public function testApiStatusesRepeatWithId()
1770 $this->app->argv[3] = 1;
1771 $result = api_statuses_repeat('json');
1772 $this->assertStatus($result['status']);
1774 // Also test with a shared status
1775 $this->app->argv[3] = 5;
1776 $result = api_statuses_repeat('json');
1777 $this->assertStatus($result['status']);
1781 * Test the api_statuses_destroy() function.
1783 * @expectedException Friendica\Network\HTTPException\BadRequestException
1785 public function testApiStatusesDestroy()
1787 api_statuses_destroy('json');
1791 * Test the api_statuses_destroy() function without an authenticated user.
1793 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1795 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1797 $_SESSION['authenticated'] = false;
1798 api_statuses_destroy('json');
1802 * Test the api_statuses_destroy() function with an ID.
1805 public function testApiStatusesDestroyWithId()
1807 $this->app->argv[3] = 1;
1808 $result = api_statuses_destroy('json');
1809 $this->assertStatus($result['status']);
1813 * Test the api_statuses_mentions() function.
1816 public function testApiStatusesMentions()
1818 $this->app->user = ['nickname' => $this->selfUser['nick']];
1819 $_REQUEST['max_id'] = 10;
1820 $result = api_statuses_mentions('json');
1821 $this->assertEmpty($result['status']);
1822 // We should test with mentions in the database.
1826 * Test the api_statuses_mentions() function with a negative page parameter.
1829 public function testApiStatusesMentionsWithNegativePage()
1831 $_REQUEST['page'] = -2;
1832 $result = api_statuses_mentions('json');
1833 $this->assertEmpty($result['status']);
1837 * Test the api_statuses_mentions() function with an unallowed user.
1839 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1841 public function testApiStatusesMentionsWithUnallowedUser()
1843 $_SESSION['allow_api'] = false;
1844 $_GET['screen_name'] = $this->selfUser['nick'];
1845 api_statuses_mentions('json');
1849 * Test the api_statuses_mentions() function with an RSS result.
1852 public function testApiStatusesMentionsWithRss()
1854 $result = api_statuses_mentions('rss');
1855 $this->assertXml($result, 'statuses');
1859 * Test the api_statuses_user_timeline() function.
1862 public function testApiStatusesUserTimeline()
1864 $_REQUEST['max_id'] = 10;
1865 $_REQUEST['exclude_replies'] = true;
1866 $_REQUEST['conversation_id'] = 1;
1867 $result = api_statuses_user_timeline('json');
1868 $this->assertNotEmpty($result['status']);
1869 foreach ($result['status'] as $status) {
1870 $this->assertStatus($status);
1875 * Test the api_statuses_user_timeline() function with a negative page parameter.
1878 public function testApiStatusesUserTimelineWithNegativePage()
1880 $_REQUEST['page'] = -2;
1881 $result = api_statuses_user_timeline('json');
1882 $this->assertNotEmpty($result['status']);
1883 foreach ($result['status'] as $status) {
1884 $this->assertStatus($status);
1889 * Test the api_statuses_user_timeline() function with an RSS result.
1892 public function testApiStatusesUserTimelineWithRss()
1894 $result = api_statuses_user_timeline('rss');
1895 $this->assertXml($result, 'statuses');
1899 * Test the api_statuses_user_timeline() function with an unallowed user.
1901 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1903 public function testApiStatusesUserTimelineWithUnallowedUser()
1905 $_SESSION['allow_api'] = false;
1906 $_GET['screen_name'] = $this->selfUser['nick'];
1907 api_statuses_user_timeline('json');
1911 * Test the api_favorites_create_destroy() function.
1913 * @expectedException Friendica\Network\HTTPException\BadRequestException
1915 public function testApiFavoritesCreateDestroy()
1917 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1918 $this->app->argc = count($this->app->argv);
1919 api_favorites_create_destroy('json');
1923 * Test the api_favorites_create_destroy() function with an invalid ID.
1925 * @expectedException Friendica\Network\HTTPException\BadRequestException
1927 public function testApiFavoritesCreateDestroyWithInvalidId()
1929 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1930 $this->app->argc = count($this->app->argv);
1931 api_favorites_create_destroy('json');
1935 * Test the api_favorites_create_destroy() function with an invalid action.
1937 * @expectedException Friendica\Network\HTTPException\BadRequestException
1939 public function testApiFavoritesCreateDestroyWithInvalidAction()
1941 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1942 $this->app->argc = count($this->app->argv);
1943 $_REQUEST['id'] = 1;
1944 api_favorites_create_destroy('json');
1948 * Test the api_favorites_create_destroy() function with the create action.
1951 public function testApiFavoritesCreateDestroyWithCreateAction()
1953 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1954 $this->app->argc = count($this->app->argv);
1955 $_REQUEST['id'] = 3;
1956 $result = api_favorites_create_destroy('json');
1957 $this->assertStatus($result['status']);
1961 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1964 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1966 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1967 $this->app->argc = count($this->app->argv);
1968 $_REQUEST['id'] = 3;
1969 $result = api_favorites_create_destroy('rss');
1970 $this->assertXml($result, 'status');
1974 * Test the api_favorites_create_destroy() function with the destroy action.
1977 public function testApiFavoritesCreateDestroyWithDestroyAction()
1979 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1980 $this->app->argc = count($this->app->argv);
1981 $_REQUEST['id'] = 3;
1982 $result = api_favorites_create_destroy('json');
1983 $this->assertStatus($result['status']);
1987 * Test the api_favorites_create_destroy() function without an authenticated user.
1989 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1991 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1993 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1994 $this->app->argc = count($this->app->argv);
1995 $_SESSION['authenticated'] = false;
1996 api_favorites_create_destroy('json');
2000 * Test the api_favorites() function.
2003 public function testApiFavorites()
2005 $_REQUEST['page'] = -1;
2006 $_REQUEST['max_id'] = 10;
2007 $result = api_favorites('json');
2008 foreach ($result['status'] as $status) {
2009 $this->assertStatus($status);
2014 * Test the api_favorites() function with an RSS result.
2017 public function testApiFavoritesWithRss()
2019 $result = api_favorites('rss');
2020 $this->assertXml($result, 'statuses');
2024 * Test the api_favorites() function with an unallowed user.
2026 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2028 public function testApiFavoritesWithUnallowedUser()
2030 $_SESSION['allow_api'] = false;
2031 $_GET['screen_name'] = $this->selfUser['nick'];
2032 api_favorites('json');
2036 * Test the api_format_messages() function.
2039 public function testApiFormatMessages()
2041 $result = api_format_messages(
2042 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2043 ['id' => 2, 'screen_name' => 'recipient_name'],
2044 ['id' => 3, 'screen_name' => 'sender_name']
2046 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2047 $this->assertEquals(1, $result['id']);
2048 $this->assertEquals(2, $result['recipient_id']);
2049 $this->assertEquals(3, $result['sender_id']);
2050 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2051 $this->assertEquals('sender_name', $result['sender_screen_name']);
2055 * Test the api_format_messages() function with HTML.
2058 public function testApiFormatMessagesWithHtmlText()
2060 $_GET['getText'] = 'html';
2061 $result = api_format_messages(
2062 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2063 ['id' => 2, 'screen_name' => 'recipient_name'],
2064 ['id' => 3, 'screen_name' => 'sender_name']
2066 $this->assertEquals('item_title', $result['title']);
2067 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2071 * Test the api_format_messages() function with plain text.
2074 public function testApiFormatMessagesWithPlainText()
2076 $_GET['getText'] = 'plain';
2077 $result = api_format_messages(
2078 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2079 ['id' => 2, 'screen_name' => 'recipient_name'],
2080 ['id' => 3, 'screen_name' => 'sender_name']
2082 $this->assertEquals('item_title', $result['title']);
2083 $this->assertEquals('item_body', $result['text']);
2087 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2090 public function testApiFormatMessagesWithoutUserObjects()
2092 $_GET['getUserObjects'] = 'false';
2093 $result = api_format_messages(
2094 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2095 ['id' => 2, 'screen_name' => 'recipient_name'],
2096 ['id' => 3, 'screen_name' => 'sender_name']
2098 $this->assertTrue(!isset($result['sender']));
2099 $this->assertTrue(!isset($result['recipient']));
2103 * Test the api_convert_item() function.
2106 public function testApiConvertItem()
2108 $result = api_convert_item(
2110 'network' => 'feed',
2111 'title' => 'item_title',
2112 // We need a long string to test that it is correctly cut
2113 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2114 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2115 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2116 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2117 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2118 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2119 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2120 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2121 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2122 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2123 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2124 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2125 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2126 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2127 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2128 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2129 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2130 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2131 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2132 'repellat officia illum quos impedit quam iste esse unde qui '.
2133 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2134 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2135 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2136 'plink' => 'item_plink'
2139 $this->assertStringStartsWith('item_title', $result['text']);
2140 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2144 * Test the api_convert_item() function with an empty item body.
2147 public function testApiConvertItemWithoutBody()
2149 $result = api_convert_item(
2151 'network' => 'feed',
2152 'title' => 'item_title',
2154 'plink' => 'item_plink'
2157 $this->assertEquals('item_title', $result['text']);
2158 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2162 * Test the api_convert_item() function with the title in the body.
2165 public function testApiConvertItemWithTitleInBody()
2167 $result = api_convert_item(
2169 'title' => 'item_title',
2170 'body' => 'item_title item_body'
2173 $this->assertEquals('item_title item_body', $result['text']);
2174 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2178 * Test the api_get_attachments() function.
2181 public function testApiGetAttachments()
2184 $this->assertEmpty(api_get_attachments($body));
2188 * Test the api_get_attachments() function with an img tag.
2191 public function testApiGetAttachmentsWithImage()
2193 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2194 $this->assertInternalType('array', api_get_attachments($body));
2198 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2201 public function testApiGetAttachmentsWithImageAndAndStatus()
2203 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2204 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2205 $this->assertInternalType('array', api_get_attachments($body));
2209 * Test the api_get_entitities() function.
2212 public function testApiGetEntitities()
2215 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2219 * Test the api_get_entitities() function with the include_entities parameter.
2222 public function testApiGetEntititiesWithIncludeEntities()
2224 $_REQUEST['include_entities'] = 'true';
2226 $result = api_get_entitities($text, 'bbcode');
2227 $this->assertInternalType('array', $result['hashtags']);
2228 $this->assertInternalType('array', $result['symbols']);
2229 $this->assertInternalType('array', $result['urls']);
2230 $this->assertInternalType('array', $result['user_mentions']);
2234 * Test the api_format_items_embeded_images() function.
2237 public function testApiFormatItemsEmbededImages()
2239 $this->assertEquals(
2240 'text ' . System::baseUrl() . '/display/item_guid',
2241 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2246 * Test the api_contactlink_to_array() function.
2249 public function testApiContactlinkToArray()
2251 $this->assertEquals(
2256 api_contactlink_to_array('text')
2261 * Test the api_contactlink_to_array() function with an URL.
2264 public function testApiContactlinkToArrayWithUrl()
2266 $this->assertEquals(
2268 'name' => ['link_text'],
2271 api_contactlink_to_array('text <a href="url">link_text</a>')
2276 * Test the api_format_items_activities() function.
2279 public function testApiFormatItemsActivities()
2281 $item = ['uid' => 0, 'uri' => ''];
2282 $result = api_format_items_activities($item);
2283 $this->assertArrayHasKey('like', $result);
2284 $this->assertArrayHasKey('dislike', $result);
2285 $this->assertArrayHasKey('attendyes', $result);
2286 $this->assertArrayHasKey('attendno', $result);
2287 $this->assertArrayHasKey('attendmaybe', $result);
2291 * Test the api_format_items_activities() function with an XML result.
2294 public function testApiFormatItemsActivitiesWithXml()
2296 $item = ['uid' => 0, 'uri' => ''];
2297 $result = api_format_items_activities($item, 'xml');
2298 $this->assertArrayHasKey('friendica:like', $result);
2299 $this->assertArrayHasKey('friendica:dislike', $result);
2300 $this->assertArrayHasKey('friendica:attendyes', $result);
2301 $this->assertArrayHasKey('friendica:attendno', $result);
2302 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2306 * Test the api_format_items_profiles() function.
2309 public function testApiFormatItemsProfiles()
2312 'id' => 'profile_id',
2313 'profile-name' => 'profile_name',
2314 'is-default' => true,
2315 'hide-friends' => true,
2316 'photo' => 'profile_photo',
2317 'thumb' => 'profile_thumb',
2319 'net-publish' => true,
2320 'pdesc' => 'description',
2321 'dob' => 'date_of_birth',
2322 'address' => 'address',
2323 'locality' => 'city',
2324 'region' => 'region',
2325 'postal-code' => 'postal_code',
2326 'country-name' => 'country',
2327 'hometown' => 'hometown',
2328 'gender' => 'gender',
2329 'marital' => 'marital',
2330 'with' => 'marital_with',
2331 'howlong' => 'marital_since',
2332 'sexual' => 'sexual',
2333 'politic' => 'politic',
2334 'religion' => 'religion',
2335 'pub_keywords' => 'public_keywords',
2336 'prv_keywords' => 'private_keywords',
2339 'dislikes' => 'dislikes',
2345 'interest' => 'interest',
2346 'romance' => 'romance',
2348 'education' => 'education',
2349 'contact' => 'social_networks',
2350 'homepage' => 'homepage'
2352 $result = api_format_items_profiles($profile_row);
2353 $this->assertEquals(
2355 'profile_id' => 'profile_id',
2356 'profile_name' => 'profile_name',
2357 'is_default' => true,
2358 'hide_friends' => true,
2359 'profile_photo' => 'profile_photo',
2360 'profile_thumb' => 'profile_thumb',
2362 'net_publish' => true,
2363 'description' => 'description',
2364 'date_of_birth' => 'date_of_birth',
2365 'address' => 'address',
2367 'region' => 'region',
2368 'postal_code' => 'postal_code',
2369 'country' => 'country',
2370 'hometown' => 'hometown',
2371 'gender' => 'gender',
2372 'marital' => 'marital',
2373 'marital_with' => 'marital_with',
2374 'marital_since' => 'marital_since',
2375 'sexual' => 'sexual',
2376 'politic' => 'politic',
2377 'religion' => 'religion',
2378 'public_keywords' => 'public_keywords',
2379 'private_keywords' => 'private_keywords',
2382 'dislikes' => 'dislikes',
2388 'interest' => 'interest',
2389 'romance' => 'romance',
2391 'education' => 'education',
2392 'social_networks' => 'social_networks',
2393 'homepage' => 'homepage',
2401 * Test the api_format_items() function.
2404 public function testApiFormatItems()
2408 'item_network' => 'item_network',
2414 'author-network' => Protocol::DFRN,
2415 'author-link' => 'http://localhost/profile/othercontact',
2419 $result = api_format_items($items, ['id' => 0], true);
2420 foreach ($result as $status) {
2421 $this->assertStatus($status);
2426 * Test the api_format_items() function with an XML result.
2429 public function testApiFormatItemsWithXml()
2437 'author-network' => Protocol::DFRN,
2438 'author-link' => 'http://localhost/profile/othercontact',
2442 $result = api_format_items($items, ['id' => 0], true, 'xml');
2443 foreach ($result as $status) {
2444 $this->assertStatus($status);
2449 * Test the api_format_items() function.
2452 public function testApiAccountRateLimitStatus()
2454 $result = api_account_rate_limit_status('json');
2455 $this->assertEquals(150, $result['hash']['remaining_hits']);
2456 $this->assertEquals(150, $result['hash']['hourly_limit']);
2457 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2461 * Test the api_format_items() function with an XML result.
2464 public function testApiAccountRateLimitStatusWithXml()
2466 $result = api_account_rate_limit_status('xml');
2467 $this->assertXml($result, 'hash');
2471 * Test the api_help_test() function.
2474 public function testApiHelpTest()
2476 $result = api_help_test('json');
2477 $this->assertEquals(['ok' => 'ok'], $result);
2481 * Test the api_help_test() function with an XML result.
2484 public function testApiHelpTestWithXml()
2486 $result = api_help_test('xml');
2487 $this->assertXml($result, 'ok');
2491 * Test the api_lists_list() function.
2494 public function testApiListsList()
2496 $result = api_lists_list('json');
2497 $this->assertEquals(['lists_list' => []], $result);
2501 * Test the api_lists_ownerships() function.
2504 public function testApiListsOwnerships()
2506 $result = api_lists_ownerships('json');
2507 foreach ($result['lists']['lists'] as $list) {
2508 $this->assertList($list);
2513 * Test the api_lists_ownerships() function without an authenticated user.
2515 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2517 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2519 $_SESSION['authenticated'] = false;
2520 api_lists_ownerships('json');
2524 * Test the api_lists_statuses() function.
2525 * @expectedException Friendica\Network\HTTPException\BadRequestException
2528 public function testApiListsStatuses()
2530 api_lists_statuses('json');
2534 * Test the api_lists_statuses() function with a list ID.
2537 public function testApiListsStatusesWithListId()
2539 $_REQUEST['list_id'] = 1;
2540 $_REQUEST['page'] = -1;
2541 $_REQUEST['max_id'] = 10;
2542 $result = api_lists_statuses('json');
2543 foreach ($result['status'] as $status) {
2544 $this->assertStatus($status);
2549 * Test the api_lists_statuses() function with a list ID and a RSS result.
2552 public function testApiListsStatusesWithListIdAndRss()
2554 $_REQUEST['list_id'] = 1;
2555 $result = api_lists_statuses('rss');
2556 $this->assertXml($result, 'statuses');
2560 * Test the api_lists_statuses() function with an unallowed user.
2562 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2564 public function testApiListsStatusesWithUnallowedUser()
2566 $_SESSION['allow_api'] = false;
2567 $_GET['screen_name'] = $this->selfUser['nick'];
2568 api_lists_statuses('json');
2572 * Test the api_statuses_f() function.
2575 public function testApiStatusesFWithFriends()
2578 $result = api_statuses_f('friends');
2579 $this->assertArrayHasKey('user', $result);
2583 * Test the api_statuses_f() function.
2586 public function testApiStatusesFWithFollowers()
2588 $result = api_statuses_f('followers');
2589 $this->assertArrayHasKey('user', $result);
2593 * Test the api_statuses_f() function.
2596 public function testApiStatusesFWithBlocks()
2598 $result = api_statuses_f('blocks');
2599 $this->assertArrayHasKey('user', $result);
2603 * Test the api_statuses_f() function.
2606 public function testApiStatusesFWithIncoming()
2608 $result = api_statuses_f('incoming');
2609 $this->assertArrayHasKey('user', $result);
2613 * Test the api_statuses_f() function an undefined cursor GET variable.
2616 public function testApiStatusesFWithUndefinedCursor()
2618 $_GET['cursor'] = 'undefined';
2619 $this->assertFalse(api_statuses_f('friends'));
2623 * Test the api_statuses_friends() function.
2626 public function testApiStatusesFriends()
2628 $result = api_statuses_friends('json');
2629 $this->assertArrayHasKey('user', $result);
2633 * Test the api_statuses_friends() function an undefined cursor GET variable.
2636 public function testApiStatusesFriendsWithUndefinedCursor()
2638 $_GET['cursor'] = 'undefined';
2639 $this->assertFalse(api_statuses_friends('json'));
2643 * Test the api_statuses_followers() function.
2646 public function testApiStatusesFollowers()
2648 $result = api_statuses_followers('json');
2649 $this->assertArrayHasKey('user', $result);
2653 * Test the api_statuses_followers() function an undefined cursor GET variable.
2656 public function testApiStatusesFollowersWithUndefinedCursor()
2658 $_GET['cursor'] = 'undefined';
2659 $this->assertFalse(api_statuses_followers('json'));
2663 * Test the api_blocks_list() function.
2666 public function testApiBlocksList()
2668 $result = api_blocks_list('json');
2669 $this->assertArrayHasKey('user', $result);
2673 * Test the api_blocks_list() function an undefined cursor GET variable.
2676 public function testApiBlocksListWithUndefinedCursor()
2678 $_GET['cursor'] = 'undefined';
2679 $this->assertFalse(api_blocks_list('json'));
2683 * Test the api_friendships_incoming() function.
2686 public function testApiFriendshipsIncoming()
2688 $result = api_friendships_incoming('json');
2689 $this->assertArrayHasKey('id', $result);
2693 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2696 public function testApiFriendshipsIncomingWithUndefinedCursor()
2698 $_GET['cursor'] = 'undefined';
2699 $this->assertFalse(api_friendships_incoming('json'));
2703 * Test the api_statusnet_config() function.
2706 public function testApiStatusnetConfig()
2708 $result = api_statusnet_config('json');
2709 $this->assertEquals('localhost', $result['config']['site']['server']);
2710 $this->assertEquals('default', $result['config']['site']['theme']);
2711 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2712 $this->assertTrue($result['config']['site']['fancy']);
2713 $this->assertEquals('en', $result['config']['site']['language']);
2714 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2715 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2716 $this->assertEquals('false', $result['config']['site']['private']);
2717 $this->assertEquals('false', $result['config']['site']['ssl']);
2718 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2722 * Test the api_statusnet_version() function.
2725 public function testApiStatusnetVersion()
2727 $result = api_statusnet_version('json');
2728 $this->assertEquals('0.9.7', $result['version']);
2732 * Test the api_ff_ids() function.
2735 public function testApiFfIds()
2737 $result = api_ff_ids('json');
2738 $this->assertNull($result);
2742 * Test the api_ff_ids() function with a result.
2745 public function testApiFfIdsWithResult()
2747 $this->markTestIncomplete();
2751 * Test the api_ff_ids() function without an authenticated user.
2753 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2755 public function testApiFfIdsWithoutAuthenticatedUser()
2757 $_SESSION['authenticated'] = false;
2762 * Test the api_friends_ids() function.
2765 public function testApiFriendsIds()
2767 $result = api_friends_ids('json');
2768 $this->assertNull($result);
2772 * Test the api_followers_ids() function.
2775 public function testApiFollowersIds()
2777 $result = api_followers_ids('json');
2778 $this->assertNull($result);
2782 * Test the api_direct_messages_new() function.
2785 public function testApiDirectMessagesNew()
2787 $result = api_direct_messages_new('json');
2788 $this->assertNull($result);
2792 * Test the api_direct_messages_new() function without an authenticated user.
2794 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2796 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2798 $_SESSION['authenticated'] = false;
2799 api_direct_messages_new('json');
2803 * Test the api_direct_messages_new() function with an user ID.
2806 public function testApiDirectMessagesNewWithUserId()
2808 $_POST['text'] = 'message_text';
2809 $_POST['user_id'] = $this->otherUser['id'];
2810 $result = api_direct_messages_new('json');
2811 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2815 * Test the api_direct_messages_new() function with a screen name.
2818 public function testApiDirectMessagesNewWithScreenName()
2820 $_POST['text'] = 'message_text';
2821 $_POST['screen_name'] = $this->friendUser['nick'];
2822 $result = api_direct_messages_new('json');
2823 $this->assertEquals(1, $result['direct_message']['id']);
2824 $this->assertContains('message_text', $result['direct_message']['text']);
2825 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2826 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2830 * Test the api_direct_messages_new() function with a title.
2833 public function testApiDirectMessagesNewWithTitle()
2835 $_POST['text'] = 'message_text';
2836 $_POST['screen_name'] = $this->friendUser['nick'];
2837 $_REQUEST['title'] = 'message_title';
2838 $result = api_direct_messages_new('json');
2839 $this->assertEquals(1, $result['direct_message']['id']);
2840 $this->assertContains('message_text', $result['direct_message']['text']);
2841 $this->assertContains('message_title', $result['direct_message']['text']);
2842 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2843 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2847 * Test the api_direct_messages_new() function with an RSS result.
2850 public function testApiDirectMessagesNewWithRss()
2852 $_POST['text'] = 'message_text';
2853 $_POST['screen_name'] = $this->friendUser['nick'];
2854 $result = api_direct_messages_new('rss');
2855 $this->assertXml($result, 'direct-messages');
2859 * Test the api_direct_messages_destroy() function.
2861 * @expectedException Friendica\Network\HTTPException\BadRequestException
2863 public function testApiDirectMessagesDestroy()
2865 api_direct_messages_destroy('json');
2869 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2872 public function testApiDirectMessagesDestroyWithVerbose()
2874 $_GET['friendica_verbose'] = 'true';
2875 $result = api_direct_messages_destroy('json');
2876 $this->assertEquals(
2879 'result' => 'error',
2880 'message' => 'message id or parenturi not specified'
2888 * Test the api_direct_messages_destroy() function without an authenticated user.
2890 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2892 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2894 $_SESSION['authenticated'] = false;
2895 api_direct_messages_destroy('json');
2899 * Test the api_direct_messages_destroy() function with a non-zero ID.
2901 * @expectedException Friendica\Network\HTTPException\BadRequestException
2903 public function testApiDirectMessagesDestroyWithId()
2905 $_REQUEST['id'] = 1;
2906 api_direct_messages_destroy('json');
2910 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2913 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2915 $_REQUEST['id'] = 1;
2916 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2917 $_GET['friendica_verbose'] = 'true';
2918 $result = api_direct_messages_destroy('json');
2919 $this->assertEquals(
2922 'result' => 'error',
2923 'message' => 'message id not in database'
2931 * Test the api_direct_messages_destroy() function with a non-zero ID.
2934 public function testApiDirectMessagesDestroyWithCorrectId()
2936 $this->markTestIncomplete('We need to add a dataset for this.');
2940 * Test the api_direct_messages_box() function.
2943 public function testApiDirectMessagesBoxWithSentbox()
2945 $_REQUEST['page'] = -1;
2946 $_REQUEST['max_id'] = 10;
2947 $result = api_direct_messages_box('json', 'sentbox', 'false');
2948 $this->assertArrayHasKey('direct_message', $result);
2952 * Test the api_direct_messages_box() function.
2955 public function testApiDirectMessagesBoxWithConversation()
2957 $result = api_direct_messages_box('json', 'conversation', 'false');
2958 $this->assertArrayHasKey('direct_message', $result);
2962 * Test the api_direct_messages_box() function.
2965 public function testApiDirectMessagesBoxWithAll()
2967 $result = api_direct_messages_box('json', 'all', 'false');
2968 $this->assertArrayHasKey('direct_message', $result);
2972 * Test the api_direct_messages_box() function.
2975 public function testApiDirectMessagesBoxWithInbox()
2977 $result = api_direct_messages_box('json', 'inbox', 'false');
2978 $this->assertArrayHasKey('direct_message', $result);
2982 * Test the api_direct_messages_box() function.
2985 public function testApiDirectMessagesBoxWithVerbose()
2987 $result = api_direct_messages_box('json', 'sentbox', 'true');
2988 $this->assertEquals(
2991 'result' => 'error',
2992 'message' => 'no mails available'
3000 * Test the api_direct_messages_box() function with a RSS result.
3003 public function testApiDirectMessagesBoxWithRss()
3005 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3006 $this->assertXml($result, 'direct-messages');
3010 * Test the api_direct_messages_box() function without an authenticated user.
3012 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3014 public function testApiDirectMessagesBoxWithUnallowedUser()
3016 $_SESSION['allow_api'] = false;
3017 $_GET['screen_name'] = $this->selfUser['nick'];
3018 api_direct_messages_box('json', 'sentbox', 'false');
3022 * Test the api_direct_messages_sentbox() function.
3025 public function testApiDirectMessagesSentbox()
3027 $result = api_direct_messages_sentbox('json');
3028 $this->assertArrayHasKey('direct_message', $result);
3032 * Test the api_direct_messages_inbox() function.
3035 public function testApiDirectMessagesInbox()
3037 $result = api_direct_messages_inbox('json');
3038 $this->assertArrayHasKey('direct_message', $result);
3042 * Test the api_direct_messages_all() function.
3045 public function testApiDirectMessagesAll()
3047 $result = api_direct_messages_all('json');
3048 $this->assertArrayHasKey('direct_message', $result);
3052 * Test the api_direct_messages_conversation() function.
3055 public function testApiDirectMessagesConversation()
3057 $result = api_direct_messages_conversation('json');
3058 $this->assertArrayHasKey('direct_message', $result);
3062 * Test the api_oauth_request_token() function.
3065 public function testApiOauthRequestToken()
3067 $this->markTestIncomplete('killme() kills phpunit as well');
3071 * Test the api_oauth_access_token() function.
3074 public function testApiOauthAccessToken()
3076 $this->markTestIncomplete('killme() kills phpunit as well');
3080 * Test the api_fr_photoalbum_delete() function.
3082 * @expectedException Friendica\Network\HTTPException\BadRequestException
3084 public function testApiFrPhotoalbumDelete()
3086 api_fr_photoalbum_delete('json');
3090 * Test the api_fr_photoalbum_delete() function with an album name.
3092 * @expectedException Friendica\Network\HTTPException\BadRequestException
3094 public function testApiFrPhotoalbumDeleteWithAlbum()
3096 $_REQUEST['album'] = 'album_name';
3097 api_fr_photoalbum_delete('json');
3101 * Test the api_fr_photoalbum_delete() function with an album name.
3104 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3106 $this->markTestIncomplete('We need to add a dataset for this.');
3110 * Test the api_fr_photoalbum_delete() function.
3112 * @expectedException Friendica\Network\HTTPException\BadRequestException
3114 public function testApiFrPhotoalbumUpdate()
3116 api_fr_photoalbum_update('json');
3120 * Test the api_fr_photoalbum_delete() function with an album name.
3122 * @expectedException Friendica\Network\HTTPException\BadRequestException
3124 public function testApiFrPhotoalbumUpdateWithAlbum()
3126 $_REQUEST['album'] = 'album_name';
3127 api_fr_photoalbum_update('json');
3131 * Test the api_fr_photoalbum_delete() function with an album name.
3133 * @expectedException Friendica\Network\HTTPException\BadRequestException
3135 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3137 $_REQUEST['album'] = 'album_name';
3138 $_REQUEST['album_new'] = 'album_name';
3139 api_fr_photoalbum_update('json');
3143 * Test the api_fr_photoalbum_update() function without an authenticated user.
3145 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3147 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3149 $_SESSION['authenticated'] = false;
3150 api_fr_photoalbum_update('json');
3154 * Test the api_fr_photoalbum_delete() function with an album name.
3157 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3159 $this->markTestIncomplete('We need to add a dataset for this.');
3163 * Test the api_fr_photos_list() function.
3166 public function testApiFrPhotosList()
3168 $result = api_fr_photos_list('json');
3169 $this->assertArrayHasKey('photo', $result);
3173 * Test the api_fr_photos_list() function without an authenticated user.
3175 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3177 public function testApiFrPhotosListWithoutAuthenticatedUser()
3179 $_SESSION['authenticated'] = false;
3180 api_fr_photos_list('json');
3184 * Test the api_fr_photo_create_update() function.
3186 * @expectedException Friendica\Network\HTTPException\BadRequestException
3188 public function testApiFrPhotoCreateUpdate()
3190 api_fr_photo_create_update('json');
3194 * Test the api_fr_photo_create_update() function without an authenticated user.
3196 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3198 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3200 $_SESSION['authenticated'] = false;
3201 api_fr_photo_create_update('json');
3205 * Test the api_fr_photo_create_update() function with an album name.
3207 * @expectedException Friendica\Network\HTTPException\BadRequestException
3209 public function testApiFrPhotoCreateUpdateWithAlbum()
3211 $_REQUEST['album'] = 'album_name';
3212 api_fr_photo_create_update('json');
3216 * Test the api_fr_photo_create_update() function with the update mode.
3219 public function testApiFrPhotoCreateUpdateWithUpdate()
3221 $this->markTestIncomplete('We need to create a dataset for this');
3225 * Test the api_fr_photo_create_update() function with an uploaded file.
3228 public function testApiFrPhotoCreateUpdateWithFile()
3230 $this->markTestIncomplete();
3234 * Test the api_fr_photo_delete() function.
3236 * @expectedException Friendica\Network\HTTPException\BadRequestException
3238 public function testApiFrPhotoDelete()
3240 api_fr_photo_delete('json');
3244 * Test the api_fr_photo_delete() function without an authenticated user.
3246 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3248 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3250 $_SESSION['authenticated'] = false;
3251 api_fr_photo_delete('json');
3255 * Test the api_fr_photo_delete() function with a photo ID.
3257 * @expectedException Friendica\Network\HTTPException\BadRequestException
3259 public function testApiFrPhotoDeleteWithPhotoId()
3261 $_REQUEST['photo_id'] = 1;
3262 api_fr_photo_delete('json');
3266 * Test the api_fr_photo_delete() function with a correct photo ID.
3269 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3271 $this->markTestIncomplete('We need to create a dataset for this.');
3275 * Test the api_fr_photo_detail() function.
3277 * @expectedException Friendica\Network\HTTPException\BadRequestException
3279 public function testApiFrPhotoDetail()
3281 api_fr_photo_detail('json');
3285 * Test the api_fr_photo_detail() function without an authenticated user.
3287 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3289 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3291 $_SESSION['authenticated'] = false;
3292 api_fr_photo_detail('json');
3296 * Test the api_fr_photo_detail() function with a photo ID.
3298 * @expectedException Friendica\Network\HTTPException\NotFoundException
3300 public function testApiFrPhotoDetailWithPhotoId()
3302 $_REQUEST['photo_id'] = 1;
3303 api_fr_photo_detail('json');
3307 * Test the api_fr_photo_detail() function with a correct photo ID.
3310 public function testApiFrPhotoDetailCorrectPhotoId()
3312 $this->markTestIncomplete('We need to create a dataset for this.');
3316 * Test the api_account_update_profile_image() function.
3318 * @expectedException Friendica\Network\HTTPException\BadRequestException
3320 public function testApiAccountUpdateProfileImage()
3322 api_account_update_profile_image('json');
3326 * Test the api_account_update_profile_image() function without an authenticated user.
3328 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3330 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3332 $_SESSION['authenticated'] = false;
3333 api_account_update_profile_image('json');
3337 * Test the api_account_update_profile_image() function with an uploaded file.
3339 * @expectedException Friendica\Network\HTTPException\BadRequestException
3341 public function testApiAccountUpdateProfileImageWithUpload()
3343 $this->markTestIncomplete();
3348 * Test the api_account_update_profile() function.
3351 public function testApiAccountUpdateProfile()
3353 $_POST['name'] = 'new_name';
3354 $_POST['description'] = 'new_description';
3355 $result = api_account_update_profile('json');
3356 // We can't use assertSelfUser() here because the user object is missing some properties.
3357 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3358 $this->assertEquals('DFRN', $result['user']['location']);
3359 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3360 $this->assertEquals('dfrn', $result['user']['network']);
3361 $this->assertEquals('new_name', $result['user']['name']);
3362 $this->assertEquals('new_description', $result['user']['description']);
3366 * Test the check_acl_input() function.
3369 public function testCheckAclInput()
3371 $result = check_acl_input('<aclstring>');
3372 // Where does this result come from?
3373 $this->assertEquals(1, $result);
3377 * Test the check_acl_input() function with an empty ACL string.
3380 public function testCheckAclInputWithEmptyAclString()
3382 $result = check_acl_input(' ');
3383 $this->assertFalse($result);
3387 * Test the save_media_to_database() function.
3390 public function testSaveMediaToDatabase()
3392 $this->markTestIncomplete();
3396 * Test the post_photo_item() function.
3399 public function testPostPhotoItem()
3401 $this->markTestIncomplete();
3405 * Test the prepare_photo_data() function.
3408 public function testPreparePhotoData()
3410 $this->markTestIncomplete();
3414 * Test the api_friendica_remoteauth() function.
3416 * @expectedException Friendica\Network\HTTPException\BadRequestException
3418 public function testApiFriendicaRemoteauth()
3420 api_friendica_remoteauth();
3424 * Test the api_friendica_remoteauth() function with an URL.
3426 * @expectedException Friendica\Network\HTTPException\BadRequestException
3428 public function testApiFriendicaRemoteauthWithUrl()
3430 $_GET['url'] = 'url';
3431 $_GET['c_url'] = 'url';
3432 api_friendica_remoteauth();
3436 * Test the api_friendica_remoteauth() function with a correct URL.
3439 public function testApiFriendicaRemoteauthWithCorrectUrl()
3441 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3442 $_GET['url'] = 'url';
3443 $_GET['c_url'] = $this->selfUser['nurl'];
3444 api_friendica_remoteauth();
3448 * Test the api_share_as_retweet() function.
3451 public function testApiShareAsRetweet()
3453 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3454 $result = api_share_as_retweet($item);
3455 $this->assertFalse($result);
3459 * Test the api_share_as_retweet() function with a valid item.
3462 public function testApiShareAsRetweetWithValidItem()
3464 $this->markTestIncomplete();
3468 * Test the api_get_nick() function.
3471 public function testApiGetNick()
3473 $result = api_get_nick($this->otherUser['nurl']);
3474 $this->assertEquals('othercontact', $result);
3478 * Test the api_get_nick() function with a wrong URL.
3481 public function testApiGetNickWithWrongUrl()
3483 $result = api_get_nick('wrong_url');
3484 $this->assertFalse($result);
3488 * Test the api_in_reply_to() function.
3491 public function testApiInReplyTo()
3493 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3494 $this->assertArrayHasKey('status_id', $result);
3495 $this->assertArrayHasKey('user_id', $result);
3496 $this->assertArrayHasKey('status_id_str', $result);
3497 $this->assertArrayHasKey('user_id_str', $result);
3498 $this->assertArrayHasKey('screen_name', $result);
3502 * Test the api_in_reply_to() function with a valid item.
3505 public function testApiInReplyToWithValidItem()
3507 $this->markTestIncomplete();
3511 * Test the api_clean_plain_items() function.
3514 public function testApiCleanPlainItems()
3516 $_REQUEST['include_entities'] = 'true';
3517 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3518 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3522 * Test the api_clean_attachments() function.
3525 public function testApiCleanAttachments()
3527 $this->markTestIncomplete();
3531 * Test the api_best_nickname() function.
3534 public function testApiBestNickname()
3537 $result = api_best_nickname($contacts);
3538 $this->assertNull($result);
3542 * Test the api_best_nickname() function with contacts.
3545 public function testApiBestNicknameWithContacts()
3547 $this->markTestIncomplete();
3551 * Test the api_friendica_group_show() function.
3554 public function testApiFriendicaGroupShow()
3556 $this->markTestIncomplete();
3560 * Test the api_friendica_group_delete() function.
3563 public function testApiFriendicaGroupDelete()
3565 $this->markTestIncomplete();
3569 * Test the api_lists_destroy() function.
3572 public function testApiListsDestroy()
3574 $this->markTestIncomplete();
3578 * Test the group_create() function.
3581 public function testGroupCreate()
3583 $this->markTestIncomplete();
3587 * Test the api_friendica_group_create() function.
3590 public function testApiFriendicaGroupCreate()
3592 $this->markTestIncomplete();
3596 * Test the api_lists_create() function.
3599 public function testApiListsCreate()
3601 $this->markTestIncomplete();
3605 * Test the api_friendica_group_update() function.
3608 public function testApiFriendicaGroupUpdate()
3610 $this->markTestIncomplete();
3614 * Test the api_lists_update() function.
3617 public function testApiListsUpdate()
3619 $this->markTestIncomplete();
3623 * Test the api_friendica_activity() function.
3626 public function testApiFriendicaActivity()
3628 $this->markTestIncomplete();
3632 * Test the api_friendica_notification() function.
3634 * @expectedException Friendica\Network\HTTPException\BadRequestException
3636 public function testApiFriendicaNotification()
3638 api_friendica_notification('json');
3642 * Test the api_friendica_notification() function without an authenticated user.
3644 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3646 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3648 $_SESSION['authenticated'] = false;
3649 api_friendica_notification('json');
3653 * Test the api_friendica_notification() function with an argument count.
3656 public function testApiFriendicaNotificationWithArgumentCount()
3658 $this->app->argv = ['api', 'friendica', 'notification'];
3659 $this->app->argc = count($this->app->argv);
3660 $result = api_friendica_notification('json');
3661 $this->assertEquals(['note' => false], $result);
3665 * Test the api_friendica_notification() function with an XML result.
3668 public function testApiFriendicaNotificationWithXmlResult()
3670 $this->app->argv = ['api', 'friendica', 'notification'];
3671 $this->app->argc = count($this->app->argv);
3672 $result = api_friendica_notification('xml');
3673 $this->assertXml($result, 'notes');
3677 * Test the api_friendica_notification_seen() function.
3680 public function testApiFriendicaNotificationSeen()
3682 $this->markTestIncomplete();
3686 * Test the api_friendica_direct_messages_setseen() function.
3689 public function testApiFriendicaDirectMessagesSetseen()
3691 $this->markTestIncomplete();
3695 * Test the api_friendica_direct_messages_search() function.
3698 public function testApiFriendicaDirectMessagesSearch()
3700 $this->markTestIncomplete();
3704 * Test the api_friendica_profile_show() function.
3707 public function testApiFriendicaProfileShow()
3709 $result = api_friendica_profile_show('json');
3710 // We can't use assertSelfUser() here because the user object is missing some properties.
3711 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3712 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3713 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3714 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3715 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3716 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3717 $this->assertFalse($result['$result']['multi_profiles']);
3721 * Test the api_friendica_profile_show() function with a profile ID.
3724 public function testApiFriendicaProfileShowWithProfileId()
3726 $this->markTestIncomplete('We need to add a dataset for this.');
3730 * Test the api_friendica_profile_show() function with a wrong profile ID.
3732 * @expectedException Friendica\Network\HTTPException\BadRequestException
3734 public function testApiFriendicaProfileShowWithWrongProfileId()
3736 $_REQUEST['profile_id'] = 666;
3737 api_friendica_profile_show('json');
3741 * Test the api_friendica_profile_show() function without an authenticated user.
3743 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3745 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3747 $_SESSION['authenticated'] = false;
3748 api_friendica_profile_show('json');
3752 * Test the api_saved_searches_list() function.
3755 public function testApiSavedSearchesList()
3757 $result = api_saved_searches_list('json');
3758 $this->assertEquals(1, $result['terms'][0]['id']);
3759 $this->assertEquals(1, $result['terms'][0]['id_str']);
3760 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3761 $this->assertEquals('Saved search', $result['terms'][0]['query']);