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 $basedir = BasePath::create(dirname(__DIR__) . '/../');
40 $configLoader = new Cache\ConfigCacheLoader($basedir);
41 $configCache = Factory\ConfigFactory::createCache($configLoader);
42 Factory\DBFactory::init($configCache, $_SERVER);
43 $config = Factory\ConfigFactory::createConfig($configCache);
44 Factory\ConfigFactory::createPConfig($configCache);
45 $logger = Factory\LoggerFactory::create('test', $config);
46 $profiler = Factory\ProfilerFactory::create($logger, $config);
47 $this->app = new App($config, $logger, $profiler, false);
48 $this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
52 // User data that the test database is populated with
55 'name' => 'Self contact',
56 'nick' => 'selfcontact',
57 'nurl' => 'http://localhost/profile/selfcontact'
61 'name' => 'Friend contact',
62 'nick' => 'friendcontact',
63 'nurl' => 'http://localhost/profile/friendcontact'
67 'name' => 'othercontact',
68 'nick' => 'othercontact',
69 'nurl' => 'http://localhost/profile/othercontact'
72 // User ID that we know is not in the database
73 $this->wrongUserId = 666;
75 // Most API require login so we force the session
78 'authenticated' => true,
79 'uid' => $this->selfUser['id']
82 Config::set('system', 'url', 'http://localhost');
83 Config::set('system', 'hostname', 'localhost');
84 Config::set('system', 'worker_dont_fork', true);
87 Config::set('config', 'hostname', 'localhost');
88 Config::set('system', 'throttle_limit_day', 100);
89 Config::set('system', 'throttle_limit_week', 100);
90 Config::set('system', 'throttle_limit_month', 100);
91 Config::set('system', 'theme', 'system_theme');
95 * Cleanup variables used by tests.
97 protected function tearDown()
101 $this->app->argc = 1;
102 $this->app->argv = ['home'];
106 * Assert that an user array contains expected keys.
107 * @param array $user User array
110 private function assertSelfUser(array $user)
112 $this->assertEquals($this->selfUser['id'], $user['uid']);
113 $this->assertEquals($this->selfUser['id'], $user['cid']);
114 $this->assertEquals(1, $user['self']);
115 $this->assertEquals('DFRN', $user['location']);
116 $this->assertEquals($this->selfUser['name'], $user['name']);
117 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
118 $this->assertEquals('dfrn', $user['network']);
119 $this->assertTrue($user['verified']);
123 * Assert that an user array contains expected keys.
124 * @param array $user User array
127 private function assertOtherUser(array $user)
129 $this->assertEquals($this->otherUser['id'], $user['id']);
130 $this->assertEquals($this->otherUser['id'], $user['id_str']);
131 $this->assertEquals(0, $user['self']);
132 $this->assertEquals($this->otherUser['name'], $user['name']);
133 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
134 $this->assertFalse($user['verified']);
138 * Assert that a status array contains expected keys.
139 * @param array $status Status array
142 private function assertStatus(array $status)
144 $this->assertInternalType('string', $status['text']);
145 $this->assertInternalType('int', $status['id']);
146 // We could probably do more checks here.
150 * Assert that a list array contains expected keys.
151 * @param array $list List array
154 private function assertList(array $list)
156 $this->assertInternalType('string', $list['name']);
157 $this->assertInternalType('int', $list['id']);
158 $this->assertInternalType('string', $list['id_str']);
159 $this->assertContains($list['mode'], ['public', 'private']);
160 // We could probably do more checks here.
164 * Assert that the string is XML and contain the root element.
165 * @param string $result XML string
166 * @param string $root_element Root element name
169 private function assertXml($result, $root_element)
171 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
172 $this->assertContains('<'.$root_element, $result);
173 // We could probably do more checks here.
177 * Get the path to a temporary empty PNG image.
178 * @return string Path
180 private function getTempImage()
182 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
186 // Empty 1x1 px PNG image
187 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
195 * Test the api_user() function.
198 public function testApiUser()
200 $this->assertEquals($this->selfUser['id'], api_user());
204 * Test the api_user() function with an unallowed user.
207 public function testApiUserWithUnallowedUser()
209 $_SESSION = ['allow_api' => false];
210 $this->assertEquals(false, api_user());
214 * Test the api_source() function.
217 public function testApiSource()
219 $this->assertEquals('api', api_source());
223 * Test the api_source() function with a Twidere user agent.
226 public function testApiSourceWithTwidere()
228 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
229 $this->assertEquals('Twidere', api_source());
233 * Test the api_source() function with a GET parameter.
236 public function testApiSourceWithGet()
238 $_GET['source'] = 'source_name';
239 $this->assertEquals('source_name', api_source());
243 * Test the api_date() function.
246 public function testApiDate()
248 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
252 * Test the api_register_func() function.
255 public function testApiRegisterFunc()
267 $this->assertTrue($API['api_path']['auth']);
268 $this->assertEquals('method', $API['api_path']['method']);
269 $this->assertTrue(is_callable($API['api_path']['func']));
273 * Test the api_login() function without any login.
275 * @runInSeparateProcess
276 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
278 public function testApiLoginWithoutLogin()
280 api_login($this->app);
284 * Test the api_login() function with a bad login.
286 * @runInSeparateProcess
287 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
289 public function testApiLoginWithBadLogin()
291 $_SERVER['PHP_AUTH_USER'] = 'user@server';
292 api_login($this->app);
296 * Test the api_login() function with oAuth.
299 public function testApiLoginWithOauth()
301 $this->markTestIncomplete('Can we test this easily?');
305 * Test the api_login() function with authentication provided by an addon.
308 public function testApiLoginWithAddonAuth()
310 $this->markTestIncomplete('Can we test this easily?');
314 * Test the api_login() function with a correct login.
316 * @runInSeparateProcess
318 public function testApiLoginWithCorrectLogin()
320 $_SERVER['PHP_AUTH_USER'] = 'Test user';
321 $_SERVER['PHP_AUTH_PW'] = 'password';
322 api_login($this->app);
326 * Test the api_login() function with a remote user.
328 * @runInSeparateProcess
329 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
331 public function testApiLoginWithRemoteUser()
333 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
334 api_login($this->app);
338 * Test the api_check_method() function.
341 public function testApiCheckMethod()
343 $this->assertFalse(api_check_method('method'));
347 * Test the api_check_method() function with a correct method.
350 public function testApiCheckMethodWithCorrectMethod()
352 $_SERVER['REQUEST_METHOD'] = 'method';
353 $this->assertTrue(api_check_method('method'));
357 * Test the api_check_method() function with a wildcard.
360 public function testApiCheckMethodWithWildcard()
362 $this->assertTrue(api_check_method('*'));
366 * Test the api_call() function.
368 * @runInSeparateProcess
370 public function testApiCall()
374 'method' => 'method',
375 'func' => function () {
376 return ['data' => ['some_data']];
379 $_SERVER['REQUEST_METHOD'] = 'method';
380 $_GET['callback'] = 'callback_name';
382 $this->app->query_string = 'api_path';
384 'callback_name(["some_data"])',
390 * Test the api_call() function with the profiled enabled.
392 * @runInSeparateProcess
394 public function testApiCallWithProfiler()
398 'method' => 'method',
399 'func' => function () {
400 return ['data' => ['some_data']];
403 $_SERVER['REQUEST_METHOD'] = 'method';
404 Config::set('system', 'profiler', true);
405 Config::set('rendertime', 'callstack', true);
406 $this->app->callstack = [
407 'database' => ['some_function' => 200],
408 'database_write' => ['some_function' => 200],
409 'cache' => ['some_function' => 200],
410 'cache_write' => ['some_function' => 200],
411 'network' => ['some_function' => 200]
414 $this->app->query_string = 'api_path';
422 * Test the api_call() function without any result.
424 * @runInSeparateProcess
426 public function testApiCallWithNoResult()
430 'method' => 'method',
431 'func' => function () {
435 $_SERVER['REQUEST_METHOD'] = 'method';
437 $this->app->query_string = 'api_path';
439 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
445 * Test the api_call() function with an unimplemented API.
447 * @runInSeparateProcess
449 public function testApiCallWithUninplementedApi()
452 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
458 * Test the api_call() function with a JSON result.
460 * @runInSeparateProcess
462 public function testApiCallWithJson()
466 'method' => 'method',
467 'func' => function () {
468 return ['data' => ['some_data']];
471 $_SERVER['REQUEST_METHOD'] = 'method';
473 $this->app->query_string = 'api_path.json';
481 * Test the api_call() function with an XML result.
483 * @runInSeparateProcess
485 public function testApiCallWithXml()
489 'method' => 'method',
490 'func' => function () {
494 $_SERVER['REQUEST_METHOD'] = 'method';
496 $this->app->query_string = 'api_path.xml';
504 * Test the api_call() function with an RSS result.
506 * @runInSeparateProcess
508 public function testApiCallWithRss()
512 'method' => 'method',
513 'func' => function () {
517 $_SERVER['REQUEST_METHOD'] = 'method';
519 $this->app->query_string = 'api_path.rss';
521 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
528 * Test the api_call() function with an Atom result.
530 * @runInSeparateProcess
532 public function testApiCallWithAtom()
536 'method' => 'method',
537 'func' => function () {
541 $_SERVER['REQUEST_METHOD'] = 'method';
543 $this->app->query_string = 'api_path.atom';
545 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
552 * Test the api_call() function with an unallowed method.
554 * @runInSeparateProcess
556 public function testApiCallWithWrongMethod()
559 $API['api_path'] = ['method' => 'method'];
561 $this->app->query_string = 'api_path';
563 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
569 * Test the api_call() function with an unauthorized user.
571 * @runInSeparateProcess
573 public function testApiCallWithWrongAuth()
577 'method' => 'method',
580 $_SERVER['REQUEST_METHOD'] = 'method';
581 $_SESSION['authenticated'] = false;
583 $this->app->query_string = 'api_path';
585 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
591 * Test the api_error() function with a JSON result.
593 * @runInSeparateProcess
595 public function testApiErrorWithJson()
598 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
599 api_error('json', new HTTPException('error_message'))
604 * Test the api_error() function with an XML result.
606 * @runInSeparateProcess
608 public function testApiErrorWithXml()
611 '<?xml version="1.0"?>'."\n".
612 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
613 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
614 'xmlns:georss="http://www.georss.org/georss">'."\n".
615 ' <error>error_message</error>'."\n".
616 ' <code>200 Friendica\Network\HTTP</code>'."\n".
619 api_error('xml', new HTTPException('error_message'))
624 * Test the api_error() function with an RSS result.
626 * @runInSeparateProcess
628 public function testApiErrorWithRss()
631 '<?xml version="1.0"?>'."\n".
632 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
633 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
634 'xmlns:georss="http://www.georss.org/georss">'."\n".
635 ' <error>error_message</error>'."\n".
636 ' <code>200 Friendica\Network\HTTP</code>'."\n".
639 api_error('rss', new HTTPException('error_message'))
644 * Test the api_error() function with an Atom result.
646 * @runInSeparateProcess
648 public function testApiErrorWithAtom()
651 '<?xml version="1.0"?>'."\n".
652 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
653 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
654 'xmlns:georss="http://www.georss.org/georss">'."\n".
655 ' <error>error_message</error>'."\n".
656 ' <code>200 Friendica\Network\HTTP</code>'."\n".
659 api_error('atom', new HTTPException('error_message'))
664 * Test the api_rss_extra() function.
667 public function testApiRssExtra()
669 $user_info = ['url' => 'user_url', 'lang' => 'en'];
670 $result = api_rss_extra($this->app, [], $user_info);
671 $this->assertEquals($user_info, $result['$user']);
672 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
673 $this->assertArrayHasKey('self', $result['$rss']);
674 $this->assertArrayHasKey('base', $result['$rss']);
675 $this->assertArrayHasKey('updated', $result['$rss']);
676 $this->assertArrayHasKey('atom_updated', $result['$rss']);
677 $this->assertArrayHasKey('language', $result['$rss']);
678 $this->assertArrayHasKey('logo', $result['$rss']);
682 * Test the api_rss_extra() function without any user info.
684 * @runInSeparateProcess
686 public function testApiRssExtraWithoutUserInfo()
688 $result = api_rss_extra($this->app, [], null);
689 $this->assertInternalType('array', $result['$user']);
690 $this->assertArrayHasKey('alternate', $result['$rss']);
691 $this->assertArrayHasKey('self', $result['$rss']);
692 $this->assertArrayHasKey('base', $result['$rss']);
693 $this->assertArrayHasKey('updated', $result['$rss']);
694 $this->assertArrayHasKey('atom_updated', $result['$rss']);
695 $this->assertArrayHasKey('language', $result['$rss']);
696 $this->assertArrayHasKey('logo', $result['$rss']);
700 * Test the api_unique_id_to_nurl() function.
703 public function testApiUniqueIdToNurl()
705 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
709 * Test the api_unique_id_to_nurl() function with a correct ID.
712 public function testApiUniqueIdToNurlWithCorrectId()
714 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
718 * Test the api_get_user() function.
720 * @runInSeparateProcess
722 public function testApiGetUser()
724 $user = api_get_user($this->app);
725 $this->assertSelfUser($user);
726 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
727 $this->assertEquals('6fdbe8', $user['profile_link_color']);
728 $this->assertEquals('ededed', $user['profile_background_color']);
732 * Test the api_get_user() function with a Frio schema.
734 * @runInSeparateProcess
736 public function testApiGetUserWithFrioSchema()
738 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
739 $user = api_get_user($this->app);
740 $this->assertSelfUser($user);
741 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
742 $this->assertEquals('6fdbe8', $user['profile_link_color']);
743 $this->assertEquals('ededed', $user['profile_background_color']);
747 * Test the api_get_user() function with a custom Frio schema.
749 * @runInSeparateProcess
751 public function testApiGetUserWithCustomFrioSchema()
753 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
754 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
755 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
756 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
757 $user = api_get_user($this->app);
758 $this->assertSelfUser($user);
759 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
760 $this->assertEquals('123456', $user['profile_link_color']);
761 $this->assertEquals('123456', $user['profile_background_color']);
765 * Test the api_get_user() function with an empty Frio schema.
767 * @runInSeparateProcess
769 public function testApiGetUserWithEmptyFrioSchema()
771 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
772 $user = api_get_user($this->app);
773 $this->assertSelfUser($user);
774 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
775 $this->assertEquals('6fdbe8', $user['profile_link_color']);
776 $this->assertEquals('ededed', $user['profile_background_color']);
780 * Test the api_get_user() function with an user that is not allowed to use the API.
782 * @runInSeparateProcess
784 public function testApiGetUserWithoutApiUser()
786 $_SERVER['PHP_AUTH_USER'] = 'Test user';
787 $_SERVER['PHP_AUTH_PW'] = 'password';
788 $_SESSION['allow_api'] = false;
789 $this->assertFalse(api_get_user($this->app));
793 * Test the api_get_user() function with an user ID in a GET parameter.
795 * @runInSeparateProcess
797 public function testApiGetUserWithGetId()
799 $_GET['user_id'] = $this->otherUser['id'];
800 $this->assertOtherUser(api_get_user($this->app));
804 * Test the api_get_user() function with a wrong user ID in a GET parameter.
806 * @runInSeparateProcess
807 * @expectedException Friendica\Network\HTTPException\BadRequestException
809 public function testApiGetUserWithWrongGetId()
811 $_GET['user_id'] = $this->wrongUserId;
812 $this->assertOtherUser(api_get_user($this->app));
816 * Test the api_get_user() function with an user name in a GET parameter.
818 * @runInSeparateProcess
820 public function testApiGetUserWithGetName()
822 $_GET['screen_name'] = $this->selfUser['nick'];
823 $this->assertSelfUser(api_get_user($this->app));
827 * Test the api_get_user() function with a profile URL in a GET parameter.
829 * @runInSeparateProcess
831 public function testApiGetUserWithGetUrl()
833 $_GET['profileurl'] = $this->selfUser['nurl'];
834 $this->assertSelfUser(api_get_user($this->app));
838 * Test the api_get_user() function with an user ID in the API path.
840 * @runInSeparateProcess
842 public function testApiGetUserWithNumericCalledApi()
845 $called_api = ['api_path'];
846 $this->app->argv[1] = $this->otherUser['id'].'.json';
847 $this->assertOtherUser(api_get_user($this->app));
851 * Test the api_get_user() function with the $called_api global variable.
853 * @runInSeparateProcess
855 public function testApiGetUserWithCalledApi()
858 $called_api = ['api', 'api_path'];
859 $this->assertSelfUser(api_get_user($this->app));
863 * Test the api_get_user() function with a valid user.
865 * @runInSeparateProcess
867 public function testApiGetUserWithCorrectUser()
869 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
873 * Test the api_get_user() function with a wrong user ID.
875 * @runInSeparateProcess
876 * @expectedException Friendica\Network\HTTPException\BadRequestException
878 public function testApiGetUserWithWrongUser()
880 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
884 * Test the api_get_user() function with a 0 user ID.
886 * @runInSeparateProcess
888 public function testApiGetUserWithZeroUser()
890 $this->assertSelfUser(api_get_user($this->app, 0));
894 * Test the api_item_get_user() function.
896 * @runInSeparateProcess
898 public function testApiItemGetUser()
900 $users = api_item_get_user($this->app, []);
901 $this->assertSelfUser($users[0]);
905 * Test the api_item_get_user() function with a different item parent.
908 public function testApiItemGetUserWithDifferentParent()
910 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
911 $this->assertSelfUser($users[0]);
912 $this->assertEquals($users[0], $users[1]);
916 * Test the api_walk_recursive() function.
919 public function testApiWalkRecursive()
927 // Should we test this with a callback that actually does something?
935 * Test the api_walk_recursive() function with an array.
938 public function testApiWalkRecursiveWithArray()
940 $array = [['item1'], ['item2']];
946 // Should we test this with a callback that actually does something?
954 * Test the api_reformat_xml() function.
957 public function testApiReformatXml()
961 $this->assertTrue(api_reformat_xml($item, $key));
962 $this->assertEquals('true', $item);
966 * Test the api_reformat_xml() function with a statusnet_api key.
969 public function testApiReformatXmlWithStatusnetKey()
972 $key = 'statusnet_api';
973 $this->assertTrue(api_reformat_xml($item, $key));
974 $this->assertEquals('statusnet:api', $key);
978 * Test the api_reformat_xml() function with a friendica_api key.
981 public function testApiReformatXmlWithFriendicaKey()
984 $key = 'friendica_api';
985 $this->assertTrue(api_reformat_xml($item, $key));
986 $this->assertEquals('friendica:api', $key);
990 * Test the api_create_xml() function.
993 public function testApiCreateXml()
996 '<?xml version="1.0"?>'."\n".
997 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
998 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
999 'xmlns:georss="http://www.georss.org/georss">'."\n".
1000 ' <data>some_data</data>'."\n".
1001 '</root_element>'."\n",
1002 api_create_xml(['data' => ['some_data']], 'root_element')
1007 * Test the api_create_xml() function without any XML namespace.
1010 public function testApiCreateXmlWithoutNamespaces()
1012 $this->assertEquals(
1013 '<?xml version="1.0"?>'."\n".
1015 ' <data>some_data</data>'."\n".
1017 api_create_xml(['data' => ['some_data']], 'ok')
1022 * Test the api_format_data() function.
1025 public function testApiFormatData()
1027 $data = ['some_data'];
1028 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1032 * Test the api_format_data() function with an XML result.
1035 public function testApiFormatDataWithXml()
1037 $this->assertEquals(
1038 '<?xml version="1.0"?>'."\n".
1039 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1040 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1041 'xmlns:georss="http://www.georss.org/georss">'."\n".
1042 ' <data>some_data</data>'."\n".
1043 '</root_element>'."\n",
1044 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1049 * Test the api_account_verify_credentials() function.
1052 public function testApiAccountVerifyCredentials()
1054 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1058 * Test the api_account_verify_credentials() function without an authenticated user.
1060 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1062 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1064 $_SESSION['authenticated'] = false;
1065 api_account_verify_credentials('json');
1069 * Test the requestdata() function.
1072 public function testRequestdata()
1074 $this->assertNull(requestdata('variable_name'));
1078 * Test the requestdata() function with a POST parameter.
1081 public function testRequestdataWithPost()
1083 $_POST['variable_name'] = 'variable_value';
1084 $this->assertEquals('variable_value', requestdata('variable_name'));
1088 * Test the requestdata() function with a GET parameter.
1091 public function testRequestdataWithGet()
1093 $_GET['variable_name'] = 'variable_value';
1094 $this->assertEquals('variable_value', requestdata('variable_name'));
1098 * Test the api_statuses_mediap() function.
1101 public function testApiStatusesMediap()
1103 $this->app->argc = 2;
1111 'tmp_name' => $this->getTempImage(),
1112 'name' => 'spacer.png',
1113 'type' => 'image/png'
1116 $_GET['status'] = '<b>Status content</b>';
1118 $result = api_statuses_mediap('json');
1119 $this->assertStatus($result['status']);
1123 * Test the api_statuses_mediap() function without an authenticated user.
1125 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1127 public function testApiStatusesMediapWithoutAuthenticatedUser()
1129 $_SESSION['authenticated'] = false;
1130 api_statuses_mediap('json');
1134 * Test the api_statuses_update() function.
1137 public function testApiStatusesUpdate()
1139 $_GET['status'] = 'Status content #friendica';
1140 $_GET['in_reply_to_status_id'] = -1;
1149 'tmp_name' => $this->getTempImage(),
1150 'name' => 'spacer.png',
1151 'type' => 'image/png'
1155 $result = api_statuses_update('json');
1156 $this->assertStatus($result['status']);
1160 * Test the api_statuses_update() function with an HTML status.
1163 public function testApiStatusesUpdateWithHtml()
1165 $_GET['htmlstatus'] = '<b>Status content</b>';
1167 $result = api_statuses_update('json');
1168 $this->assertStatus($result['status']);
1172 * Test the api_statuses_update() function without an authenticated user.
1174 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1176 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1178 $_SESSION['authenticated'] = false;
1179 api_statuses_update('json');
1183 * Test the api_statuses_update() function with a parent status.
1186 public function testApiStatusesUpdateWithParent()
1188 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1192 * Test the api_statuses_update() function with a media_ids parameter.
1195 public function testApiStatusesUpdateWithMediaIds()
1197 $this->markTestIncomplete();
1201 * Test the api_statuses_update() function with the throttle limit reached.
1204 public function testApiStatusesUpdateWithDayThrottleReached()
1206 $this->markTestIncomplete();
1210 * Test the api_media_upload() function.
1212 * @expectedException Friendica\Network\HTTPException\BadRequestException
1214 public function testApiMediaUpload()
1220 * Test the api_media_upload() function without an authenticated user.
1222 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1224 public function testApiMediaUploadWithoutAuthenticatedUser()
1226 $_SESSION['authenticated'] = false;
1231 * Test the api_media_upload() function with an invalid uploaded media.
1233 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1235 public function testApiMediaUploadWithMedia()
1240 'tmp_name' => 'tmp_name'
1247 * Test the api_media_upload() function with an valid uploaded media.
1250 public function testApiMediaUploadWithValidMedia()
1258 'tmp_name' => $this->getTempImage(),
1259 'name' => 'spacer.png',
1260 'type' => 'image/png'
1266 $result = api_media_upload();
1267 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1268 $this->assertEquals(1, $result['media']['image']['w']);
1269 $this->assertEquals(1, $result['media']['image']['h']);
1270 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1274 * Test the api_status_show() function.
1277 public function testApiStatusShow()
1279 $result = api_status_show('json');
1280 $this->assertStatus($result['status']);
1284 * Test the api_status_show() function with an XML result.
1287 public function testApiStatusShowWithXml()
1289 $result = api_status_show('xml');
1290 $this->assertXml($result, 'statuses');
1294 * Test the api_status_show() function with a raw result.
1297 public function testApiStatusShowWithRaw()
1299 $this->assertStatus(api_status_show('raw'));
1303 * Test the api_users_show() function.
1306 public function testApiUsersShow()
1308 $result = api_users_show('json');
1309 // We can't use assertSelfUser() here because the user object is missing some properties.
1310 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1311 $this->assertEquals('DFRN', $result['user']['location']);
1312 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1313 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1314 $this->assertEquals('dfrn', $result['user']['network']);
1315 $this->assertTrue($result['user']['verified']);
1319 * Test the api_users_show() function with an XML result.
1322 public function testApiUsersShowWithXml()
1324 $result = api_users_show('xml');
1325 $this->assertXml($result, 'statuses');
1329 * Test the api_users_search() function.
1332 public function testApiUsersSearch()
1334 $_GET['q'] = 'othercontact';
1335 $result = api_users_search('json');
1336 $this->assertOtherUser($result['users'][0]);
1340 * Test the api_users_search() function with an XML result.
1343 public function testApiUsersSearchWithXml()
1345 $_GET['q'] = 'othercontact';
1346 $result = api_users_search('xml');
1347 $this->assertXml($result, 'users');
1351 * Test the api_users_search() function without a GET q parameter.
1353 * @expectedException Friendica\Network\HTTPException\BadRequestException
1355 public function testApiUsersSearchWithoutQuery()
1357 api_users_search('json');
1361 * Test the api_users_lookup() function.
1363 * @expectedException Friendica\Network\HTTPException\NotFoundException
1365 public function testApiUsersLookup()
1367 api_users_lookup('json');
1371 * Test the api_users_lookup() function with an user ID.
1374 public function testApiUsersLookupWithUserId()
1376 $_REQUEST['user_id'] = $this->otherUser['id'];
1377 $result = api_users_lookup('json');
1378 $this->assertOtherUser($result['users'][0]);
1382 * Test the api_search() function.
1385 public function testApiSearch()
1387 $_REQUEST['q'] = 'reply';
1388 $_REQUEST['max_id'] = 10;
1389 $result = api_search('json');
1390 foreach ($result['status'] as $status) {
1391 $this->assertStatus($status);
1392 $this->assertContains('reply', $status['text'], null, true);
1397 * Test the api_search() function a count parameter.
1400 public function testApiSearchWithCount()
1402 $_REQUEST['q'] = 'reply';
1403 $_REQUEST['count'] = 20;
1404 $result = api_search('json');
1405 foreach ($result['status'] as $status) {
1406 $this->assertStatus($status);
1407 $this->assertContains('reply', $status['text'], null, true);
1412 * Test the api_search() function with an rpp parameter.
1415 public function testApiSearchWithRpp()
1417 $_REQUEST['q'] = 'reply';
1418 $_REQUEST['rpp'] = 20;
1419 $result = api_search('json');
1420 foreach ($result['status'] as $status) {
1421 $this->assertStatus($status);
1422 $this->assertContains('reply', $status['text'], null, true);
1427 * Test the api_search() function with an q parameter contains hashtag.
1430 public function testApiSearchWithHashtag()
1432 $_REQUEST['q'] = '%23friendica';
1433 $result = api_search('json');
1434 foreach ($result['status'] as $status) {
1435 $this->assertStatus($status);
1436 $this->assertContains('#friendica', $status['text'], null, true);
1441 * Test the api_search() function with an exclude_replies parameter.
1444 public function testApiSearchWithExcludeReplies()
1446 $_REQUEST['max_id'] = 10;
1447 $_REQUEST['exclude_replies'] = true;
1448 $_REQUEST['q'] = 'friendica';
1449 $result = api_search('json');
1450 foreach ($result['status'] as $status) {
1451 $this->assertStatus($status);
1456 * Test the api_search() function without an authenticated user.
1458 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1460 public function testApiSearchWithUnallowedUser()
1462 $_SESSION['allow_api'] = false;
1463 $_GET['screen_name'] = $this->selfUser['nick'];
1468 * Test the api_search() function without any GET query parameter.
1470 * @expectedException Friendica\Network\HTTPException\BadRequestException
1472 public function testApiSearchWithoutQuery()
1478 * Test the api_statuses_home_timeline() function.
1481 public function testApiStatusesHomeTimeline()
1483 $_REQUEST['max_id'] = 10;
1484 $_REQUEST['exclude_replies'] = true;
1485 $_REQUEST['conversation_id'] = 1;
1486 $result = api_statuses_home_timeline('json');
1487 $this->assertNotEmpty($result['status']);
1488 foreach ($result['status'] as $status) {
1489 $this->assertStatus($status);
1494 * Test the api_statuses_home_timeline() function with a negative page parameter.
1497 public function testApiStatusesHomeTimelineWithNegativePage()
1499 $_REQUEST['page'] = -2;
1500 $result = api_statuses_home_timeline('json');
1501 $this->assertNotEmpty($result['status']);
1502 foreach ($result['status'] as $status) {
1503 $this->assertStatus($status);
1508 * Test the api_statuses_home_timeline() with an unallowed user.
1510 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1512 public function testApiStatusesHomeTimelineWithUnallowedUser()
1514 $_SESSION['allow_api'] = false;
1515 $_GET['screen_name'] = $this->selfUser['nick'];
1516 api_statuses_home_timeline('json');
1520 * Test the api_statuses_home_timeline() function with an RSS result.
1523 public function testApiStatusesHomeTimelineWithRss()
1525 $result = api_statuses_home_timeline('rss');
1526 $this->assertXml($result, 'statuses');
1530 * Test the api_statuses_public_timeline() function.
1533 public function testApiStatusesPublicTimeline()
1535 $_REQUEST['max_id'] = 10;
1536 $_REQUEST['conversation_id'] = 1;
1537 $result = api_statuses_public_timeline('json');
1538 $this->assertNotEmpty($result['status']);
1539 foreach ($result['status'] as $status) {
1540 $this->assertStatus($status);
1545 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1548 public function testApiStatusesPublicTimelineWithExcludeReplies()
1550 $_REQUEST['max_id'] = 10;
1551 $_REQUEST['exclude_replies'] = true;
1552 $result = api_statuses_public_timeline('json');
1553 $this->assertNotEmpty($result['status']);
1554 foreach ($result['status'] as $status) {
1555 $this->assertStatus($status);
1560 * Test the api_statuses_public_timeline() function with a negative page parameter.
1563 public function testApiStatusesPublicTimelineWithNegativePage()
1565 $_REQUEST['page'] = -2;
1566 $result = api_statuses_public_timeline('json');
1567 $this->assertNotEmpty($result['status']);
1568 foreach ($result['status'] as $status) {
1569 $this->assertStatus($status);
1574 * Test the api_statuses_public_timeline() function with an unallowed user.
1576 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1578 public function testApiStatusesPublicTimelineWithUnallowedUser()
1580 $_SESSION['allow_api'] = false;
1581 $_GET['screen_name'] = $this->selfUser['nick'];
1582 api_statuses_public_timeline('json');
1586 * Test the api_statuses_public_timeline() function with an RSS result.
1589 public function testApiStatusesPublicTimelineWithRss()
1591 $result = api_statuses_public_timeline('rss');
1592 $this->assertXml($result, 'statuses');
1596 * Test the api_statuses_networkpublic_timeline() function.
1599 public function testApiStatusesNetworkpublicTimeline()
1601 $_REQUEST['max_id'] = 10;
1602 $result = api_statuses_networkpublic_timeline('json');
1603 $this->assertNotEmpty($result['status']);
1604 foreach ($result['status'] as $status) {
1605 $this->assertStatus($status);
1610 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1613 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1615 $_REQUEST['page'] = -2;
1616 $result = api_statuses_networkpublic_timeline('json');
1617 $this->assertNotEmpty($result['status']);
1618 foreach ($result['status'] as $status) {
1619 $this->assertStatus($status);
1624 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1626 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1628 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1630 $_SESSION['allow_api'] = false;
1631 $_GET['screen_name'] = $this->selfUser['nick'];
1632 api_statuses_networkpublic_timeline('json');
1636 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1639 public function testApiStatusesNetworkpublicTimelineWithRss()
1641 $result = api_statuses_networkpublic_timeline('rss');
1642 $this->assertXml($result, 'statuses');
1646 * Test the api_statuses_show() function.
1648 * @expectedException Friendica\Network\HTTPException\BadRequestException
1650 public function testApiStatusesShow()
1652 api_statuses_show('json');
1656 * Test the api_statuses_show() function with an ID.
1659 public function testApiStatusesShowWithId()
1661 $this->app->argv[3] = 1;
1662 $result = api_statuses_show('json');
1663 $this->assertStatus($result['status']);
1667 * Test the api_statuses_show() function with the conversation parameter.
1670 public function testApiStatusesShowWithConversation()
1672 $this->app->argv[3] = 1;
1673 $_REQUEST['conversation'] = 1;
1674 $result = api_statuses_show('json');
1675 $this->assertNotEmpty($result['status']);
1676 foreach ($result['status'] as $status) {
1677 $this->assertStatus($status);
1682 * Test the api_statuses_show() function with an unallowed user.
1684 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1686 public function testApiStatusesShowWithUnallowedUser()
1688 $_SESSION['allow_api'] = false;
1689 $_GET['screen_name'] = $this->selfUser['nick'];
1690 api_statuses_show('json');
1694 * Test the api_conversation_show() function.
1696 * @expectedException Friendica\Network\HTTPException\BadRequestException
1698 public function testApiConversationShow()
1700 api_conversation_show('json');
1704 * Test the api_conversation_show() function with an ID.
1707 public function testApiConversationShowWithId()
1709 $this->app->argv[3] = 1;
1710 $_REQUEST['max_id'] = 10;
1711 $_REQUEST['page'] = -2;
1712 $result = api_conversation_show('json');
1713 $this->assertNotEmpty($result['status']);
1714 foreach ($result['status'] as $status) {
1715 $this->assertStatus($status);
1720 * Test the api_conversation_show() function with an unallowed user.
1722 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1724 public function testApiConversationShowWithUnallowedUser()
1726 $_SESSION['allow_api'] = false;
1727 $_GET['screen_name'] = $this->selfUser['nick'];
1728 api_conversation_show('json');
1732 * Test the api_statuses_repeat() function.
1734 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1736 public function testApiStatusesRepeat()
1738 api_statuses_repeat('json');
1742 * Test the api_statuses_repeat() function without an authenticated user.
1744 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1746 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1748 $_SESSION['authenticated'] = false;
1749 api_statuses_repeat('json');
1753 * Test the api_statuses_repeat() function with an ID.
1756 public function testApiStatusesRepeatWithId()
1758 $this->app->argv[3] = 1;
1759 $result = api_statuses_repeat('json');
1760 $this->assertStatus($result['status']);
1762 // Also test with a shared status
1763 $this->app->argv[3] = 5;
1764 $result = api_statuses_repeat('json');
1765 $this->assertStatus($result['status']);
1769 * Test the api_statuses_destroy() function.
1771 * @expectedException Friendica\Network\HTTPException\BadRequestException
1773 public function testApiStatusesDestroy()
1775 api_statuses_destroy('json');
1779 * Test the api_statuses_destroy() function without an authenticated user.
1781 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1783 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1785 $_SESSION['authenticated'] = false;
1786 api_statuses_destroy('json');
1790 * Test the api_statuses_destroy() function with an ID.
1793 public function testApiStatusesDestroyWithId()
1795 $this->app->argv[3] = 1;
1796 $result = api_statuses_destroy('json');
1797 $this->assertStatus($result['status']);
1801 * Test the api_statuses_mentions() function.
1804 public function testApiStatusesMentions()
1806 $this->app->user = ['nickname' => $this->selfUser['nick']];
1807 $_REQUEST['max_id'] = 10;
1808 $result = api_statuses_mentions('json');
1809 $this->assertEmpty($result['status']);
1810 // We should test with mentions in the database.
1814 * Test the api_statuses_mentions() function with a negative page parameter.
1817 public function testApiStatusesMentionsWithNegativePage()
1819 $_REQUEST['page'] = -2;
1820 $result = api_statuses_mentions('json');
1821 $this->assertEmpty($result['status']);
1825 * Test the api_statuses_mentions() function with an unallowed user.
1827 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1829 public function testApiStatusesMentionsWithUnallowedUser()
1831 $_SESSION['allow_api'] = false;
1832 $_GET['screen_name'] = $this->selfUser['nick'];
1833 api_statuses_mentions('json');
1837 * Test the api_statuses_mentions() function with an RSS result.
1840 public function testApiStatusesMentionsWithRss()
1842 $result = api_statuses_mentions('rss');
1843 $this->assertXml($result, 'statuses');
1847 * Test the api_statuses_user_timeline() function.
1850 public function testApiStatusesUserTimeline()
1852 $_REQUEST['max_id'] = 10;
1853 $_REQUEST['exclude_replies'] = true;
1854 $_REQUEST['conversation_id'] = 1;
1855 $result = api_statuses_user_timeline('json');
1856 $this->assertNotEmpty($result['status']);
1857 foreach ($result['status'] as $status) {
1858 $this->assertStatus($status);
1863 * Test the api_statuses_user_timeline() function with a negative page parameter.
1866 public function testApiStatusesUserTimelineWithNegativePage()
1868 $_REQUEST['page'] = -2;
1869 $result = api_statuses_user_timeline('json');
1870 $this->assertNotEmpty($result['status']);
1871 foreach ($result['status'] as $status) {
1872 $this->assertStatus($status);
1877 * Test the api_statuses_user_timeline() function with an RSS result.
1880 public function testApiStatusesUserTimelineWithRss()
1882 $result = api_statuses_user_timeline('rss');
1883 $this->assertXml($result, 'statuses');
1887 * Test the api_statuses_user_timeline() function with an unallowed user.
1889 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1891 public function testApiStatusesUserTimelineWithUnallowedUser()
1893 $_SESSION['allow_api'] = false;
1894 $_GET['screen_name'] = $this->selfUser['nick'];
1895 api_statuses_user_timeline('json');
1899 * Test the api_favorites_create_destroy() function.
1901 * @expectedException Friendica\Network\HTTPException\BadRequestException
1903 public function testApiFavoritesCreateDestroy()
1905 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1906 $this->app->argc = count($this->app->argv);
1907 api_favorites_create_destroy('json');
1911 * Test the api_favorites_create_destroy() function with an invalid ID.
1913 * @expectedException Friendica\Network\HTTPException\BadRequestException
1915 public function testApiFavoritesCreateDestroyWithInvalidId()
1917 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
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 action.
1925 * @expectedException Friendica\Network\HTTPException\BadRequestException
1927 public function testApiFavoritesCreateDestroyWithInvalidAction()
1929 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1930 $this->app->argc = count($this->app->argv);
1931 $_REQUEST['id'] = 1;
1932 api_favorites_create_destroy('json');
1936 * Test the api_favorites_create_destroy() function with the create action.
1939 public function testApiFavoritesCreateDestroyWithCreateAction()
1941 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1942 $this->app->argc = count($this->app->argv);
1943 $_REQUEST['id'] = 3;
1944 $result = api_favorites_create_destroy('json');
1945 $this->assertStatus($result['status']);
1949 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1952 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1954 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1955 $this->app->argc = count($this->app->argv);
1956 $_REQUEST['id'] = 3;
1957 $result = api_favorites_create_destroy('rss');
1958 $this->assertXml($result, 'status');
1962 * Test the api_favorites_create_destroy() function with the destroy action.
1965 public function testApiFavoritesCreateDestroyWithDestroyAction()
1967 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1968 $this->app->argc = count($this->app->argv);
1969 $_REQUEST['id'] = 3;
1970 $result = api_favorites_create_destroy('json');
1971 $this->assertStatus($result['status']);
1975 * Test the api_favorites_create_destroy() function without an authenticated user.
1977 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1979 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1981 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1982 $this->app->argc = count($this->app->argv);
1983 $_SESSION['authenticated'] = false;
1984 api_favorites_create_destroy('json');
1988 * Test the api_favorites() function.
1991 public function testApiFavorites()
1993 $_REQUEST['page'] = -1;
1994 $_REQUEST['max_id'] = 10;
1995 $result = api_favorites('json');
1996 foreach ($result['status'] as $status) {
1997 $this->assertStatus($status);
2002 * Test the api_favorites() function with an RSS result.
2005 public function testApiFavoritesWithRss()
2007 $result = api_favorites('rss');
2008 $this->assertXml($result, 'statuses');
2012 * Test the api_favorites() function with an unallowed user.
2014 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2016 public function testApiFavoritesWithUnallowedUser()
2018 $_SESSION['allow_api'] = false;
2019 $_GET['screen_name'] = $this->selfUser['nick'];
2020 api_favorites('json');
2024 * Test the api_format_messages() function.
2027 public function testApiFormatMessages()
2029 $result = api_format_messages(
2030 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2031 ['id' => 2, 'screen_name' => 'recipient_name'],
2032 ['id' => 3, 'screen_name' => 'sender_name']
2034 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2035 $this->assertEquals(1, $result['id']);
2036 $this->assertEquals(2, $result['recipient_id']);
2037 $this->assertEquals(3, $result['sender_id']);
2038 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2039 $this->assertEquals('sender_name', $result['sender_screen_name']);
2043 * Test the api_format_messages() function with HTML.
2046 public function testApiFormatMessagesWithHtmlText()
2048 $_GET['getText'] = 'html';
2049 $result = api_format_messages(
2050 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2051 ['id' => 2, 'screen_name' => 'recipient_name'],
2052 ['id' => 3, 'screen_name' => 'sender_name']
2054 $this->assertEquals('item_title', $result['title']);
2055 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2059 * Test the api_format_messages() function with plain text.
2062 public function testApiFormatMessagesWithPlainText()
2064 $_GET['getText'] = 'plain';
2065 $result = api_format_messages(
2066 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2067 ['id' => 2, 'screen_name' => 'recipient_name'],
2068 ['id' => 3, 'screen_name' => 'sender_name']
2070 $this->assertEquals('item_title', $result['title']);
2071 $this->assertEquals('item_body', $result['text']);
2075 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2078 public function testApiFormatMessagesWithoutUserObjects()
2080 $_GET['getUserObjects'] = 'false';
2081 $result = api_format_messages(
2082 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2083 ['id' => 2, 'screen_name' => 'recipient_name'],
2084 ['id' => 3, 'screen_name' => 'sender_name']
2086 $this->assertTrue(!isset($result['sender']));
2087 $this->assertTrue(!isset($result['recipient']));
2091 * Test the api_convert_item() function.
2094 public function testApiConvertItem()
2096 $result = api_convert_item(
2098 'network' => 'feed',
2099 'title' => 'item_title',
2100 // We need a long string to test that it is correctly cut
2101 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2102 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2103 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2104 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2105 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2106 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2107 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2108 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2109 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2110 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2111 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2112 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2113 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2114 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2115 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2116 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2117 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2118 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2119 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2120 'repellat officia illum quos impedit quam iste esse unde qui '.
2121 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2122 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2123 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2124 'plink' => 'item_plink'
2127 $this->assertStringStartsWith('item_title', $result['text']);
2128 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2132 * Test the api_convert_item() function with an empty item body.
2135 public function testApiConvertItemWithoutBody()
2137 $result = api_convert_item(
2139 'network' => 'feed',
2140 'title' => 'item_title',
2142 'plink' => 'item_plink'
2145 $this->assertEquals('item_title', $result['text']);
2146 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2150 * Test the api_convert_item() function with the title in the body.
2153 public function testApiConvertItemWithTitleInBody()
2155 $result = api_convert_item(
2157 'title' => 'item_title',
2158 'body' => 'item_title item_body'
2161 $this->assertEquals('item_title item_body', $result['text']);
2162 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2166 * Test the api_get_attachments() function.
2169 public function testApiGetAttachments()
2172 $this->assertEmpty(api_get_attachments($body));
2176 * Test the api_get_attachments() function with an img tag.
2179 public function testApiGetAttachmentsWithImage()
2181 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2182 $this->assertInternalType('array', api_get_attachments($body));
2186 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2189 public function testApiGetAttachmentsWithImageAndAndStatus()
2191 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2192 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2193 $this->assertInternalType('array', api_get_attachments($body));
2197 * Test the api_get_entitities() function.
2200 public function testApiGetEntitities()
2203 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2207 * Test the api_get_entitities() function with the include_entities parameter.
2210 public function testApiGetEntititiesWithIncludeEntities()
2212 $_REQUEST['include_entities'] = 'true';
2214 $result = api_get_entitities($text, 'bbcode');
2215 $this->assertInternalType('array', $result['hashtags']);
2216 $this->assertInternalType('array', $result['symbols']);
2217 $this->assertInternalType('array', $result['urls']);
2218 $this->assertInternalType('array', $result['user_mentions']);
2222 * Test the api_format_items_embeded_images() function.
2225 public function testApiFormatItemsEmbededImages()
2227 $this->assertEquals(
2228 'text ' . System::baseUrl() . '/display/item_guid',
2229 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2234 * Test the api_contactlink_to_array() function.
2237 public function testApiContactlinkToArray()
2239 $this->assertEquals(
2244 api_contactlink_to_array('text')
2249 * Test the api_contactlink_to_array() function with an URL.
2252 public function testApiContactlinkToArrayWithUrl()
2254 $this->assertEquals(
2256 'name' => ['link_text'],
2259 api_contactlink_to_array('text <a href="url">link_text</a>')
2264 * Test the api_format_items_activities() function.
2267 public function testApiFormatItemsActivities()
2269 $item = ['uid' => 0, 'uri' => ''];
2270 $result = api_format_items_activities($item);
2271 $this->assertArrayHasKey('like', $result);
2272 $this->assertArrayHasKey('dislike', $result);
2273 $this->assertArrayHasKey('attendyes', $result);
2274 $this->assertArrayHasKey('attendno', $result);
2275 $this->assertArrayHasKey('attendmaybe', $result);
2279 * Test the api_format_items_activities() function with an XML result.
2282 public function testApiFormatItemsActivitiesWithXml()
2284 $item = ['uid' => 0, 'uri' => ''];
2285 $result = api_format_items_activities($item, 'xml');
2286 $this->assertArrayHasKey('friendica:like', $result);
2287 $this->assertArrayHasKey('friendica:dislike', $result);
2288 $this->assertArrayHasKey('friendica:attendyes', $result);
2289 $this->assertArrayHasKey('friendica:attendno', $result);
2290 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2294 * Test the api_format_items_profiles() function.
2297 public function testApiFormatItemsProfiles()
2300 'id' => 'profile_id',
2301 'profile-name' => 'profile_name',
2302 'is-default' => true,
2303 'hide-friends' => true,
2304 'photo' => 'profile_photo',
2305 'thumb' => 'profile_thumb',
2307 'net-publish' => true,
2308 'pdesc' => 'description',
2309 'dob' => 'date_of_birth',
2310 'address' => 'address',
2311 'locality' => 'city',
2312 'region' => 'region',
2313 'postal-code' => 'postal_code',
2314 'country-name' => 'country',
2315 'hometown' => 'hometown',
2316 'gender' => 'gender',
2317 'marital' => 'marital',
2318 'with' => 'marital_with',
2319 'howlong' => 'marital_since',
2320 'sexual' => 'sexual',
2321 'politic' => 'politic',
2322 'religion' => 'religion',
2323 'pub_keywords' => 'public_keywords',
2324 'prv_keywords' => 'private_keywords',
2327 'dislikes' => 'dislikes',
2333 'interest' => 'interest',
2334 'romance' => 'romance',
2336 'education' => 'education',
2337 'contact' => 'social_networks',
2338 'homepage' => 'homepage'
2340 $result = api_format_items_profiles($profile_row);
2341 $this->assertEquals(
2343 'profile_id' => 'profile_id',
2344 'profile_name' => 'profile_name',
2345 'is_default' => true,
2346 'hide_friends' => true,
2347 'profile_photo' => 'profile_photo',
2348 'profile_thumb' => 'profile_thumb',
2350 'net_publish' => true,
2351 'description' => 'description',
2352 'date_of_birth' => 'date_of_birth',
2353 'address' => 'address',
2355 'region' => 'region',
2356 'postal_code' => 'postal_code',
2357 'country' => 'country',
2358 'hometown' => 'hometown',
2359 'gender' => 'gender',
2360 'marital' => 'marital',
2361 'marital_with' => 'marital_with',
2362 'marital_since' => 'marital_since',
2363 'sexual' => 'sexual',
2364 'politic' => 'politic',
2365 'religion' => 'religion',
2366 'public_keywords' => 'public_keywords',
2367 'private_keywords' => 'private_keywords',
2370 'dislikes' => 'dislikes',
2376 'interest' => 'interest',
2377 'romance' => 'romance',
2379 'education' => 'education',
2380 'social_networks' => 'social_networks',
2381 'homepage' => 'homepage',
2389 * Test the api_format_items() function.
2392 public function testApiFormatItems()
2396 'item_network' => 'item_network',
2402 'author-network' => Protocol::DFRN,
2403 'author-link' => 'http://localhost/profile/othercontact',
2407 $result = api_format_items($items, ['id' => 0], true);
2408 foreach ($result as $status) {
2409 $this->assertStatus($status);
2414 * Test the api_format_items() function with an XML result.
2417 public function testApiFormatItemsWithXml()
2425 'author-network' => Protocol::DFRN,
2426 'author-link' => 'http://localhost/profile/othercontact',
2430 $result = api_format_items($items, ['id' => 0], true, 'xml');
2431 foreach ($result as $status) {
2432 $this->assertStatus($status);
2437 * Test the api_format_items() function.
2440 public function testApiAccountRateLimitStatus()
2442 $result = api_account_rate_limit_status('json');
2443 $this->assertEquals(150, $result['hash']['remaining_hits']);
2444 $this->assertEquals(150, $result['hash']['hourly_limit']);
2445 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2449 * Test the api_format_items() function with an XML result.
2452 public function testApiAccountRateLimitStatusWithXml()
2454 $result = api_account_rate_limit_status('xml');
2455 $this->assertXml($result, 'hash');
2459 * Test the api_help_test() function.
2462 public function testApiHelpTest()
2464 $result = api_help_test('json');
2465 $this->assertEquals(['ok' => 'ok'], $result);
2469 * Test the api_help_test() function with an XML result.
2472 public function testApiHelpTestWithXml()
2474 $result = api_help_test('xml');
2475 $this->assertXml($result, 'ok');
2479 * Test the api_lists_list() function.
2482 public function testApiListsList()
2484 $result = api_lists_list('json');
2485 $this->assertEquals(['lists_list' => []], $result);
2489 * Test the api_lists_ownerships() function.
2492 public function testApiListsOwnerships()
2494 $result = api_lists_ownerships('json');
2495 foreach ($result['lists']['lists'] as $list) {
2496 $this->assertList($list);
2501 * Test the api_lists_ownerships() function without an authenticated user.
2503 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2505 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2507 $_SESSION['authenticated'] = false;
2508 api_lists_ownerships('json');
2512 * Test the api_lists_statuses() function.
2513 * @expectedException Friendica\Network\HTTPException\BadRequestException
2516 public function testApiListsStatuses()
2518 api_lists_statuses('json');
2522 * Test the api_lists_statuses() function with a list ID.
2525 public function testApiListsStatusesWithListId()
2527 $_REQUEST['list_id'] = 1;
2528 $_REQUEST['page'] = -1;
2529 $_REQUEST['max_id'] = 10;
2530 $result = api_lists_statuses('json');
2531 foreach ($result['status'] as $status) {
2532 $this->assertStatus($status);
2537 * Test the api_lists_statuses() function with a list ID and a RSS result.
2540 public function testApiListsStatusesWithListIdAndRss()
2542 $_REQUEST['list_id'] = 1;
2543 $result = api_lists_statuses('rss');
2544 $this->assertXml($result, 'statuses');
2548 * Test the api_lists_statuses() function with an unallowed user.
2550 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2552 public function testApiListsStatusesWithUnallowedUser()
2554 $_SESSION['allow_api'] = false;
2555 $_GET['screen_name'] = $this->selfUser['nick'];
2556 api_lists_statuses('json');
2560 * Test the api_statuses_f() function.
2563 public function testApiStatusesFWithFriends()
2566 $result = api_statuses_f('friends');
2567 $this->assertArrayHasKey('user', $result);
2571 * Test the api_statuses_f() function.
2574 public function testApiStatusesFWithFollowers()
2576 $result = api_statuses_f('followers');
2577 $this->assertArrayHasKey('user', $result);
2581 * Test the api_statuses_f() function.
2584 public function testApiStatusesFWithBlocks()
2586 $result = api_statuses_f('blocks');
2587 $this->assertArrayHasKey('user', $result);
2591 * Test the api_statuses_f() function.
2594 public function testApiStatusesFWithIncoming()
2596 $result = api_statuses_f('incoming');
2597 $this->assertArrayHasKey('user', $result);
2601 * Test the api_statuses_f() function an undefined cursor GET variable.
2604 public function testApiStatusesFWithUndefinedCursor()
2606 $_GET['cursor'] = 'undefined';
2607 $this->assertFalse(api_statuses_f('friends'));
2611 * Test the api_statuses_friends() function.
2614 public function testApiStatusesFriends()
2616 $result = api_statuses_friends('json');
2617 $this->assertArrayHasKey('user', $result);
2621 * Test the api_statuses_friends() function an undefined cursor GET variable.
2624 public function testApiStatusesFriendsWithUndefinedCursor()
2626 $_GET['cursor'] = 'undefined';
2627 $this->assertFalse(api_statuses_friends('json'));
2631 * Test the api_statuses_followers() function.
2634 public function testApiStatusesFollowers()
2636 $result = api_statuses_followers('json');
2637 $this->assertArrayHasKey('user', $result);
2641 * Test the api_statuses_followers() function an undefined cursor GET variable.
2644 public function testApiStatusesFollowersWithUndefinedCursor()
2646 $_GET['cursor'] = 'undefined';
2647 $this->assertFalse(api_statuses_followers('json'));
2651 * Test the api_blocks_list() function.
2654 public function testApiBlocksList()
2656 $result = api_blocks_list('json');
2657 $this->assertArrayHasKey('user', $result);
2661 * Test the api_blocks_list() function an undefined cursor GET variable.
2664 public function testApiBlocksListWithUndefinedCursor()
2666 $_GET['cursor'] = 'undefined';
2667 $this->assertFalse(api_blocks_list('json'));
2671 * Test the api_friendships_incoming() function.
2674 public function testApiFriendshipsIncoming()
2676 $result = api_friendships_incoming('json');
2677 $this->assertArrayHasKey('id', $result);
2681 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2684 public function testApiFriendshipsIncomingWithUndefinedCursor()
2686 $_GET['cursor'] = 'undefined';
2687 $this->assertFalse(api_friendships_incoming('json'));
2691 * Test the api_statusnet_config() function.
2694 public function testApiStatusnetConfig()
2696 $result = api_statusnet_config('json');
2697 $this->assertEquals('localhost', $result['config']['site']['server']);
2698 $this->assertEquals('default', $result['config']['site']['theme']);
2699 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2700 $this->assertTrue($result['config']['site']['fancy']);
2701 $this->assertEquals('en', $result['config']['site']['language']);
2702 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2703 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2704 $this->assertEquals('false', $result['config']['site']['private']);
2705 $this->assertEquals('false', $result['config']['site']['ssl']);
2706 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2710 * Test the api_statusnet_version() function.
2713 public function testApiStatusnetVersion()
2715 $result = api_statusnet_version('json');
2716 $this->assertEquals('0.9.7', $result['version']);
2720 * Test the api_ff_ids() function.
2723 public function testApiFfIds()
2725 $result = api_ff_ids('json');
2726 $this->assertNull($result);
2730 * Test the api_ff_ids() function with a result.
2733 public function testApiFfIdsWithResult()
2735 $this->markTestIncomplete();
2739 * Test the api_ff_ids() function without an authenticated user.
2741 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2743 public function testApiFfIdsWithoutAuthenticatedUser()
2745 $_SESSION['authenticated'] = false;
2750 * Test the api_friends_ids() function.
2753 public function testApiFriendsIds()
2755 $result = api_friends_ids('json');
2756 $this->assertNull($result);
2760 * Test the api_followers_ids() function.
2763 public function testApiFollowersIds()
2765 $result = api_followers_ids('json');
2766 $this->assertNull($result);
2770 * Test the api_direct_messages_new() function.
2773 public function testApiDirectMessagesNew()
2775 $result = api_direct_messages_new('json');
2776 $this->assertNull($result);
2780 * Test the api_direct_messages_new() function without an authenticated user.
2782 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2784 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2786 $_SESSION['authenticated'] = false;
2787 api_direct_messages_new('json');
2791 * Test the api_direct_messages_new() function with an user ID.
2794 public function testApiDirectMessagesNewWithUserId()
2796 $_POST['text'] = 'message_text';
2797 $_POST['user_id'] = $this->otherUser['id'];
2798 $result = api_direct_messages_new('json');
2799 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2803 * Test the api_direct_messages_new() function with a screen name.
2806 public function testApiDirectMessagesNewWithScreenName()
2808 $_POST['text'] = 'message_text';
2809 $_POST['screen_name'] = $this->friendUser['nick'];
2810 $result = api_direct_messages_new('json');
2811 $this->assertEquals(1, $result['direct_message']['id']);
2812 $this->assertContains('message_text', $result['direct_message']['text']);
2813 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2814 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2818 * Test the api_direct_messages_new() function with a title.
2821 public function testApiDirectMessagesNewWithTitle()
2823 $_POST['text'] = 'message_text';
2824 $_POST['screen_name'] = $this->friendUser['nick'];
2825 $_REQUEST['title'] = 'message_title';
2826 $result = api_direct_messages_new('json');
2827 $this->assertEquals(1, $result['direct_message']['id']);
2828 $this->assertContains('message_text', $result['direct_message']['text']);
2829 $this->assertContains('message_title', $result['direct_message']['text']);
2830 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2831 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2835 * Test the api_direct_messages_new() function with an RSS result.
2838 public function testApiDirectMessagesNewWithRss()
2840 $_POST['text'] = 'message_text';
2841 $_POST['screen_name'] = $this->friendUser['nick'];
2842 $result = api_direct_messages_new('rss');
2843 $this->assertXml($result, 'direct-messages');
2847 * Test the api_direct_messages_destroy() function.
2849 * @expectedException Friendica\Network\HTTPException\BadRequestException
2851 public function testApiDirectMessagesDestroy()
2853 api_direct_messages_destroy('json');
2857 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2860 public function testApiDirectMessagesDestroyWithVerbose()
2862 $_GET['friendica_verbose'] = 'true';
2863 $result = api_direct_messages_destroy('json');
2864 $this->assertEquals(
2867 'result' => 'error',
2868 'message' => 'message id or parenturi not specified'
2876 * Test the api_direct_messages_destroy() function without an authenticated user.
2878 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2880 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2882 $_SESSION['authenticated'] = false;
2883 api_direct_messages_destroy('json');
2887 * Test the api_direct_messages_destroy() function with a non-zero ID.
2889 * @expectedException Friendica\Network\HTTPException\BadRequestException
2891 public function testApiDirectMessagesDestroyWithId()
2893 $_REQUEST['id'] = 1;
2894 api_direct_messages_destroy('json');
2898 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2901 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2903 $_REQUEST['id'] = 1;
2904 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2905 $_GET['friendica_verbose'] = 'true';
2906 $result = api_direct_messages_destroy('json');
2907 $this->assertEquals(
2910 'result' => 'error',
2911 'message' => 'message id not in database'
2919 * Test the api_direct_messages_destroy() function with a non-zero ID.
2922 public function testApiDirectMessagesDestroyWithCorrectId()
2924 $this->markTestIncomplete('We need to add a dataset for this.');
2928 * Test the api_direct_messages_box() function.
2931 public function testApiDirectMessagesBoxWithSentbox()
2933 $_REQUEST['page'] = -1;
2934 $_REQUEST['max_id'] = 10;
2935 $result = api_direct_messages_box('json', 'sentbox', 'false');
2936 $this->assertArrayHasKey('direct_message', $result);
2940 * Test the api_direct_messages_box() function.
2943 public function testApiDirectMessagesBoxWithConversation()
2945 $result = api_direct_messages_box('json', 'conversation', 'false');
2946 $this->assertArrayHasKey('direct_message', $result);
2950 * Test the api_direct_messages_box() function.
2953 public function testApiDirectMessagesBoxWithAll()
2955 $result = api_direct_messages_box('json', 'all', 'false');
2956 $this->assertArrayHasKey('direct_message', $result);
2960 * Test the api_direct_messages_box() function.
2963 public function testApiDirectMessagesBoxWithInbox()
2965 $result = api_direct_messages_box('json', 'inbox', 'false');
2966 $this->assertArrayHasKey('direct_message', $result);
2970 * Test the api_direct_messages_box() function.
2973 public function testApiDirectMessagesBoxWithVerbose()
2975 $result = api_direct_messages_box('json', 'sentbox', 'true');
2976 $this->assertEquals(
2979 'result' => 'error',
2980 'message' => 'no mails available'
2988 * Test the api_direct_messages_box() function with a RSS result.
2991 public function testApiDirectMessagesBoxWithRss()
2993 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2994 $this->assertXml($result, 'direct-messages');
2998 * Test the api_direct_messages_box() function without an authenticated user.
3000 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3002 public function testApiDirectMessagesBoxWithUnallowedUser()
3004 $_SESSION['allow_api'] = false;
3005 $_GET['screen_name'] = $this->selfUser['nick'];
3006 api_direct_messages_box('json', 'sentbox', 'false');
3010 * Test the api_direct_messages_sentbox() function.
3013 public function testApiDirectMessagesSentbox()
3015 $result = api_direct_messages_sentbox('json');
3016 $this->assertArrayHasKey('direct_message', $result);
3020 * Test the api_direct_messages_inbox() function.
3023 public function testApiDirectMessagesInbox()
3025 $result = api_direct_messages_inbox('json');
3026 $this->assertArrayHasKey('direct_message', $result);
3030 * Test the api_direct_messages_all() function.
3033 public function testApiDirectMessagesAll()
3035 $result = api_direct_messages_all('json');
3036 $this->assertArrayHasKey('direct_message', $result);
3040 * Test the api_direct_messages_conversation() function.
3043 public function testApiDirectMessagesConversation()
3045 $result = api_direct_messages_conversation('json');
3046 $this->assertArrayHasKey('direct_message', $result);
3050 * Test the api_oauth_request_token() function.
3053 public function testApiOauthRequestToken()
3055 $this->markTestIncomplete('killme() kills phpunit as well');
3059 * Test the api_oauth_access_token() function.
3062 public function testApiOauthAccessToken()
3064 $this->markTestIncomplete('killme() kills phpunit as well');
3068 * Test the api_fr_photoalbum_delete() function.
3070 * @expectedException Friendica\Network\HTTPException\BadRequestException
3072 public function testApiFrPhotoalbumDelete()
3074 api_fr_photoalbum_delete('json');
3078 * Test the api_fr_photoalbum_delete() function with an album name.
3080 * @expectedException Friendica\Network\HTTPException\BadRequestException
3082 public function testApiFrPhotoalbumDeleteWithAlbum()
3084 $_REQUEST['album'] = 'album_name';
3085 api_fr_photoalbum_delete('json');
3089 * Test the api_fr_photoalbum_delete() function with an album name.
3092 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3094 $this->markTestIncomplete('We need to add a dataset for this.');
3098 * Test the api_fr_photoalbum_delete() function.
3100 * @expectedException Friendica\Network\HTTPException\BadRequestException
3102 public function testApiFrPhotoalbumUpdate()
3104 api_fr_photoalbum_update('json');
3108 * Test the api_fr_photoalbum_delete() function with an album name.
3110 * @expectedException Friendica\Network\HTTPException\BadRequestException
3112 public function testApiFrPhotoalbumUpdateWithAlbum()
3114 $_REQUEST['album'] = 'album_name';
3115 api_fr_photoalbum_update('json');
3119 * Test the api_fr_photoalbum_delete() function with an album name.
3121 * @expectedException Friendica\Network\HTTPException\BadRequestException
3123 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3125 $_REQUEST['album'] = 'album_name';
3126 $_REQUEST['album_new'] = 'album_name';
3127 api_fr_photoalbum_update('json');
3131 * Test the api_fr_photoalbum_update() function without an authenticated user.
3133 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3135 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3137 $_SESSION['authenticated'] = false;
3138 api_fr_photoalbum_update('json');
3142 * Test the api_fr_photoalbum_delete() function with an album name.
3145 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3147 $this->markTestIncomplete('We need to add a dataset for this.');
3151 * Test the api_fr_photos_list() function.
3154 public function testApiFrPhotosList()
3156 $result = api_fr_photos_list('json');
3157 $this->assertArrayHasKey('photo', $result);
3161 * Test the api_fr_photos_list() function without an authenticated user.
3163 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3165 public function testApiFrPhotosListWithoutAuthenticatedUser()
3167 $_SESSION['authenticated'] = false;
3168 api_fr_photos_list('json');
3172 * Test the api_fr_photo_create_update() function.
3174 * @expectedException Friendica\Network\HTTPException\BadRequestException
3176 public function testApiFrPhotoCreateUpdate()
3178 api_fr_photo_create_update('json');
3182 * Test the api_fr_photo_create_update() function without an authenticated user.
3184 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3186 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3188 $_SESSION['authenticated'] = false;
3189 api_fr_photo_create_update('json');
3193 * Test the api_fr_photo_create_update() function with an album name.
3195 * @expectedException Friendica\Network\HTTPException\BadRequestException
3197 public function testApiFrPhotoCreateUpdateWithAlbum()
3199 $_REQUEST['album'] = 'album_name';
3200 api_fr_photo_create_update('json');
3204 * Test the api_fr_photo_create_update() function with the update mode.
3207 public function testApiFrPhotoCreateUpdateWithUpdate()
3209 $this->markTestIncomplete('We need to create a dataset for this');
3213 * Test the api_fr_photo_create_update() function with an uploaded file.
3216 public function testApiFrPhotoCreateUpdateWithFile()
3218 $this->markTestIncomplete();
3222 * Test the api_fr_photo_delete() function.
3224 * @expectedException Friendica\Network\HTTPException\BadRequestException
3226 public function testApiFrPhotoDelete()
3228 api_fr_photo_delete('json');
3232 * Test the api_fr_photo_delete() function without an authenticated user.
3234 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3236 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3238 $_SESSION['authenticated'] = false;
3239 api_fr_photo_delete('json');
3243 * Test the api_fr_photo_delete() function with a photo ID.
3245 * @expectedException Friendica\Network\HTTPException\BadRequestException
3247 public function testApiFrPhotoDeleteWithPhotoId()
3249 $_REQUEST['photo_id'] = 1;
3250 api_fr_photo_delete('json');
3254 * Test the api_fr_photo_delete() function with a correct photo ID.
3257 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3259 $this->markTestIncomplete('We need to create a dataset for this.');
3263 * Test the api_fr_photo_detail() function.
3265 * @expectedException Friendica\Network\HTTPException\BadRequestException
3267 public function testApiFrPhotoDetail()
3269 api_fr_photo_detail('json');
3273 * Test the api_fr_photo_detail() function without an authenticated user.
3275 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3277 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3279 $_SESSION['authenticated'] = false;
3280 api_fr_photo_detail('json');
3284 * Test the api_fr_photo_detail() function with a photo ID.
3286 * @expectedException Friendica\Network\HTTPException\NotFoundException
3288 public function testApiFrPhotoDetailWithPhotoId()
3290 $_REQUEST['photo_id'] = 1;
3291 api_fr_photo_detail('json');
3295 * Test the api_fr_photo_detail() function with a correct photo ID.
3298 public function testApiFrPhotoDetailCorrectPhotoId()
3300 $this->markTestIncomplete('We need to create a dataset for this.');
3304 * Test the api_account_update_profile_image() function.
3306 * @expectedException Friendica\Network\HTTPException\BadRequestException
3308 public function testApiAccountUpdateProfileImage()
3310 api_account_update_profile_image('json');
3314 * Test the api_account_update_profile_image() function without an authenticated user.
3316 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3318 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3320 $_SESSION['authenticated'] = false;
3321 api_account_update_profile_image('json');
3325 * Test the api_account_update_profile_image() function with an uploaded file.
3327 * @expectedException Friendica\Network\HTTPException\BadRequestException
3329 public function testApiAccountUpdateProfileImageWithUpload()
3331 $this->markTestIncomplete();
3336 * Test the api_account_update_profile() function.
3339 public function testApiAccountUpdateProfile()
3341 $_POST['name'] = 'new_name';
3342 $_POST['description'] = 'new_description';
3343 $result = api_account_update_profile('json');
3344 // We can't use assertSelfUser() here because the user object is missing some properties.
3345 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3346 $this->assertEquals('DFRN', $result['user']['location']);
3347 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3348 $this->assertEquals('dfrn', $result['user']['network']);
3349 $this->assertEquals('new_name', $result['user']['name']);
3350 $this->assertEquals('new_description', $result['user']['description']);
3354 * Test the check_acl_input() function.
3357 public function testCheckAclInput()
3359 $result = check_acl_input('<aclstring>');
3360 // Where does this result come from?
3361 $this->assertEquals(1, $result);
3365 * Test the check_acl_input() function with an empty ACL string.
3368 public function testCheckAclInputWithEmptyAclString()
3370 $result = check_acl_input(' ');
3371 $this->assertFalse($result);
3375 * Test the save_media_to_database() function.
3378 public function testSaveMediaToDatabase()
3380 $this->markTestIncomplete();
3384 * Test the post_photo_item() function.
3387 public function testPostPhotoItem()
3389 $this->markTestIncomplete();
3393 * Test the prepare_photo_data() function.
3396 public function testPreparePhotoData()
3398 $this->markTestIncomplete();
3402 * Test the api_friendica_remoteauth() function.
3404 * @expectedException Friendica\Network\HTTPException\BadRequestException
3406 public function testApiFriendicaRemoteauth()
3408 api_friendica_remoteauth();
3412 * Test the api_friendica_remoteauth() function with an URL.
3414 * @expectedException Friendica\Network\HTTPException\BadRequestException
3416 public function testApiFriendicaRemoteauthWithUrl()
3418 $_GET['url'] = 'url';
3419 $_GET['c_url'] = 'url';
3420 api_friendica_remoteauth();
3424 * Test the api_friendica_remoteauth() function with a correct URL.
3427 public function testApiFriendicaRemoteauthWithCorrectUrl()
3429 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3430 $_GET['url'] = 'url';
3431 $_GET['c_url'] = $this->selfUser['nurl'];
3432 api_friendica_remoteauth();
3436 * Test the api_share_as_retweet() function.
3439 public function testApiShareAsRetweet()
3441 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3442 $result = api_share_as_retweet($item);
3443 $this->assertFalse($result);
3447 * Test the api_share_as_retweet() function with a valid item.
3450 public function testApiShareAsRetweetWithValidItem()
3452 $this->markTestIncomplete();
3456 * Test the api_get_nick() function.
3459 public function testApiGetNick()
3461 $result = api_get_nick($this->otherUser['nurl']);
3462 $this->assertEquals('othercontact', $result);
3466 * Test the api_get_nick() function with a wrong URL.
3469 public function testApiGetNickWithWrongUrl()
3471 $result = api_get_nick('wrong_url');
3472 $this->assertFalse($result);
3476 * Test the api_in_reply_to() function.
3479 public function testApiInReplyTo()
3481 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3482 $this->assertArrayHasKey('status_id', $result);
3483 $this->assertArrayHasKey('user_id', $result);
3484 $this->assertArrayHasKey('status_id_str', $result);
3485 $this->assertArrayHasKey('user_id_str', $result);
3486 $this->assertArrayHasKey('screen_name', $result);
3490 * Test the api_in_reply_to() function with a valid item.
3493 public function testApiInReplyToWithValidItem()
3495 $this->markTestIncomplete();
3499 * Test the api_clean_plain_items() function.
3502 public function testApiCleanPlainItems()
3504 $_REQUEST['include_entities'] = 'true';
3505 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3506 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3510 * Test the api_clean_attachments() function.
3513 public function testApiCleanAttachments()
3515 $this->markTestIncomplete();
3519 * Test the api_best_nickname() function.
3522 public function testApiBestNickname()
3525 $result = api_best_nickname($contacts);
3526 $this->assertNull($result);
3530 * Test the api_best_nickname() function with contacts.
3533 public function testApiBestNicknameWithContacts()
3535 $this->markTestIncomplete();
3539 * Test the api_friendica_group_show() function.
3542 public function testApiFriendicaGroupShow()
3544 $this->markTestIncomplete();
3548 * Test the api_friendica_group_delete() function.
3551 public function testApiFriendicaGroupDelete()
3553 $this->markTestIncomplete();
3557 * Test the api_lists_destroy() function.
3560 public function testApiListsDestroy()
3562 $this->markTestIncomplete();
3566 * Test the group_create() function.
3569 public function testGroupCreate()
3571 $this->markTestIncomplete();
3575 * Test the api_friendica_group_create() function.
3578 public function testApiFriendicaGroupCreate()
3580 $this->markTestIncomplete();
3584 * Test the api_lists_create() function.
3587 public function testApiListsCreate()
3589 $this->markTestIncomplete();
3593 * Test the api_friendica_group_update() function.
3596 public function testApiFriendicaGroupUpdate()
3598 $this->markTestIncomplete();
3602 * Test the api_lists_update() function.
3605 public function testApiListsUpdate()
3607 $this->markTestIncomplete();
3611 * Test the api_friendica_activity() function.
3614 public function testApiFriendicaActivity()
3616 $this->markTestIncomplete();
3620 * Test the api_friendica_notification() function.
3622 * @expectedException Friendica\Network\HTTPException\BadRequestException
3624 public function testApiFriendicaNotification()
3626 api_friendica_notification('json');
3630 * Test the api_friendica_notification() function without an authenticated user.
3632 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3634 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3636 $_SESSION['authenticated'] = false;
3637 api_friendica_notification('json');
3641 * Test the api_friendica_notification() function with an argument count.
3644 public function testApiFriendicaNotificationWithArgumentCount()
3646 $this->app->argv = ['api', 'friendica', 'notification'];
3647 $this->app->argc = count($this->app->argv);
3648 $result = api_friendica_notification('json');
3649 $this->assertEquals(['note' => false], $result);
3653 * Test the api_friendica_notification() function with an XML result.
3656 public function testApiFriendicaNotificationWithXmlResult()
3658 $this->app->argv = ['api', 'friendica', 'notification'];
3659 $this->app->argc = count($this->app->argv);
3660 $result = api_friendica_notification('xml');
3661 $this->assertXml($result, 'notes');
3665 * Test the api_friendica_notification_seen() function.
3668 public function testApiFriendicaNotificationSeen()
3670 $this->markTestIncomplete();
3674 * Test the api_friendica_direct_messages_setseen() function.
3677 public function testApiFriendicaDirectMessagesSetseen()
3679 $this->markTestIncomplete();
3683 * Test the api_friendica_direct_messages_search() function.
3686 public function testApiFriendicaDirectMessagesSearch()
3688 $this->markTestIncomplete();
3692 * Test the api_friendica_profile_show() function.
3695 public function testApiFriendicaProfileShow()
3697 $result = api_friendica_profile_show('json');
3698 // We can't use assertSelfUser() here because the user object is missing some properties.
3699 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3700 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3701 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3702 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3703 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3704 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3705 $this->assertFalse($result['$result']['multi_profiles']);
3709 * Test the api_friendica_profile_show() function with a profile ID.
3712 public function testApiFriendicaProfileShowWithProfileId()
3714 $this->markTestIncomplete('We need to add a dataset for this.');
3718 * Test the api_friendica_profile_show() function with a wrong profile ID.
3720 * @expectedException Friendica\Network\HTTPException\BadRequestException
3722 public function testApiFriendicaProfileShowWithWrongProfileId()
3724 $_REQUEST['profile_id'] = 666;
3725 api_friendica_profile_show('json');
3729 * Test the api_friendica_profile_show() function without an authenticated user.
3731 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3733 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3735 $_SESSION['authenticated'] = false;
3736 api_friendica_profile_show('json');
3740 * Test the api_saved_searches_list() function.
3743 public function testApiSavedSearchesList()
3745 $result = api_saved_searches_list('json');
3746 $this->assertEquals(1, $result['terms'][0]['id']);
3747 $this->assertEquals(1, $result['terms'][0]['id_str']);
3748 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3749 $this->assertEquals('Saved search', $result['terms'][0]['query']);