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 Monolog\Handler\TestHandler;
18 require_once __DIR__ . '/../../include/api.php';
21 * Tests for the API functions.
23 * Functions that use header() need to be tested in a separate process.
24 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
26 class ApiTest extends DatabaseTest
29 * @var TestHandler Can handle log-outputs
34 * Create variables used by tests.
36 public function setUp()
38 $basedir = BasePath::create(dirname(__DIR__) . '/../');
39 $configLoader = new Config\ConfigCacheLoader($basedir);
40 $config = Factory\ConfigFactory::createCache($configLoader);
41 $logger = Factory\LoggerFactory::create('test', $config);
42 $profiler = Factory\ProfilerFactory::create($logger, $config);
43 $this->app = new App($config, $logger, $profiler, false);
44 $this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
48 // User data that the test database is populated with
51 'name' => 'Self contact',
52 'nick' => 'selfcontact',
53 'nurl' => 'http://localhost/profile/selfcontact'
57 'name' => 'Friend contact',
58 'nick' => 'friendcontact',
59 'nurl' => 'http://localhost/profile/friendcontact'
63 'name' => 'othercontact',
64 'nick' => 'othercontact',
65 'nurl' => 'http://localhost/profile/othercontact'
68 // User ID that we know is not in the database
69 $this->wrongUserId = 666;
71 // Most API require login so we force the session
74 'authenticated' => true,
75 'uid' => $this->selfUser['id']
78 Config::set('system', 'url', 'http://localhost');
79 Config::set('system', 'hostname', 'localhost');
80 Config::set('system', 'worker_dont_fork', true);
83 Config::set('config', 'hostname', 'localhost');
84 Config::set('system', 'throttle_limit_day', 100);
85 Config::set('system', 'throttle_limit_week', 100);
86 Config::set('system', 'throttle_limit_month', 100);
87 Config::set('system', 'theme', 'system_theme');
91 * Cleanup variables used by tests.
93 protected function tearDown()
98 $this->app->argv = ['home'];
102 * Assert that an user array contains expected keys.
103 * @param array $user User array
106 private function assertSelfUser(array $user)
108 $this->assertEquals($this->selfUser['id'], $user['uid']);
109 $this->assertEquals($this->selfUser['id'], $user['cid']);
110 $this->assertEquals(1, $user['self']);
111 $this->assertEquals('DFRN', $user['location']);
112 $this->assertEquals($this->selfUser['name'], $user['name']);
113 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
114 $this->assertEquals('dfrn', $user['network']);
115 $this->assertTrue($user['verified']);
119 * Assert that an user array contains expected keys.
120 * @param array $user User array
123 private function assertOtherUser(array $user)
125 $this->assertEquals($this->otherUser['id'], $user['id']);
126 $this->assertEquals($this->otherUser['id'], $user['id_str']);
127 $this->assertEquals(0, $user['self']);
128 $this->assertEquals($this->otherUser['name'], $user['name']);
129 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
130 $this->assertFalse($user['verified']);
134 * Assert that a status array contains expected keys.
135 * @param array $status Status array
138 private function assertStatus(array $status)
140 $this->assertInternalType('string', $status['text']);
141 $this->assertInternalType('int', $status['id']);
142 // We could probably do more checks here.
146 * Assert that a list array contains expected keys.
147 * @param array $list List array
150 private function assertList(array $list)
152 $this->assertInternalType('string', $list['name']);
153 $this->assertInternalType('int', $list['id']);
154 $this->assertInternalType('string', $list['id_str']);
155 $this->assertContains($list['mode'], ['public', 'private']);
156 // We could probably do more checks here.
160 * Assert that the string is XML and contain the root element.
161 * @param string $result XML string
162 * @param string $root_element Root element name
165 private function assertXml($result, $root_element)
167 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
168 $this->assertContains('<'.$root_element, $result);
169 // We could probably do more checks here.
173 * Get the path to a temporary empty PNG image.
174 * @return string Path
176 private function getTempImage()
178 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
182 // Empty 1x1 px PNG image
183 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
191 * Test the api_user() function.
194 public function testApiUser()
196 $this->assertEquals($this->selfUser['id'], api_user());
200 * Test the api_user() function with an unallowed user.
203 public function testApiUserWithUnallowedUser()
205 $_SESSION = ['allow_api' => false];
206 $this->assertEquals(false, api_user());
210 * Test the api_source() function.
213 public function testApiSource()
215 $this->assertEquals('api', api_source());
219 * Test the api_source() function with a Twidere user agent.
222 public function testApiSourceWithTwidere()
224 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
225 $this->assertEquals('Twidere', api_source());
229 * Test the api_source() function with a GET parameter.
232 public function testApiSourceWithGet()
234 $_GET['source'] = 'source_name';
235 $this->assertEquals('source_name', api_source());
239 * Test the api_date() function.
242 public function testApiDate()
244 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
248 * Test the api_register_func() function.
251 public function testApiRegisterFunc()
263 $this->assertTrue($API['api_path']['auth']);
264 $this->assertEquals('method', $API['api_path']['method']);
265 $this->assertTrue(is_callable($API['api_path']['func']));
269 * Test the api_login() function without any login.
271 * @runInSeparateProcess
272 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
274 public function testApiLoginWithoutLogin()
276 api_login($this->app);
280 * Test the api_login() function with a bad login.
282 * @runInSeparateProcess
283 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
285 public function testApiLoginWithBadLogin()
287 $_SERVER['PHP_AUTH_USER'] = 'user@server';
288 api_login($this->app);
292 * Test the api_login() function with oAuth.
295 public function testApiLoginWithOauth()
297 $this->markTestIncomplete('Can we test this easily?');
301 * Test the api_login() function with authentication provided by an addon.
304 public function testApiLoginWithAddonAuth()
306 $this->markTestIncomplete('Can we test this easily?');
310 * Test the api_login() function with a correct login.
312 * @runInSeparateProcess
314 public function testApiLoginWithCorrectLogin()
316 $_SERVER['PHP_AUTH_USER'] = 'Test user';
317 $_SERVER['PHP_AUTH_PW'] = 'password';
318 api_login($this->app);
322 * Test the api_login() function with a remote user.
324 * @runInSeparateProcess
325 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
327 public function testApiLoginWithRemoteUser()
329 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
330 api_login($this->app);
334 * Test the api_check_method() function.
337 public function testApiCheckMethod()
339 $this->assertFalse(api_check_method('method'));
343 * Test the api_check_method() function with a correct method.
346 public function testApiCheckMethodWithCorrectMethod()
348 $_SERVER['REQUEST_METHOD'] = 'method';
349 $this->assertTrue(api_check_method('method'));
353 * Test the api_check_method() function with a wildcard.
356 public function testApiCheckMethodWithWildcard()
358 $this->assertTrue(api_check_method('*'));
362 * Test the api_call() function.
364 * @runInSeparateProcess
366 public function testApiCall()
370 'method' => 'method',
371 'func' => function () {
372 return ['data' => ['some_data']];
375 $_SERVER['REQUEST_METHOD'] = 'method';
376 $_GET['callback'] = 'callback_name';
378 $this->app->query_string = 'api_path';
380 'callback_name(["some_data"])',
386 * Test the api_call() function with the profiled enabled.
388 * @runInSeparateProcess
390 public function testApiCallWithProfiler()
394 'method' => 'method',
395 'func' => function () {
396 return ['data' => ['some_data']];
399 $_SERVER['REQUEST_METHOD'] = 'method';
400 Config::set('system', 'profiler', true);
401 Config::set('rendertime', 'callstack', true);
402 $this->app->callstack = [
403 'database' => ['some_function' => 200],
404 'database_write' => ['some_function' => 200],
405 'cache' => ['some_function' => 200],
406 'cache_write' => ['some_function' => 200],
407 'network' => ['some_function' => 200]
410 $this->app->query_string = 'api_path';
418 * Test the api_call() function without any result.
420 * @runInSeparateProcess
422 public function testApiCallWithNoResult()
426 'method' => 'method',
427 'func' => function () {
431 $_SERVER['REQUEST_METHOD'] = 'method';
433 $this->app->query_string = 'api_path';
435 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
441 * Test the api_call() function with an unimplemented API.
443 * @runInSeparateProcess
445 public function testApiCallWithUninplementedApi()
448 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
454 * Test the api_call() function with a JSON result.
456 * @runInSeparateProcess
458 public function testApiCallWithJson()
462 'method' => 'method',
463 'func' => function () {
464 return ['data' => ['some_data']];
467 $_SERVER['REQUEST_METHOD'] = 'method';
469 $this->app->query_string = 'api_path.json';
477 * Test the api_call() function with an XML result.
479 * @runInSeparateProcess
481 public function testApiCallWithXml()
485 'method' => 'method',
486 'func' => function () {
490 $_SERVER['REQUEST_METHOD'] = 'method';
492 $this->app->query_string = 'api_path.xml';
500 * Test the api_call() function with an RSS result.
502 * @runInSeparateProcess
504 public function testApiCallWithRss()
508 'method' => 'method',
509 'func' => function () {
513 $_SERVER['REQUEST_METHOD'] = 'method';
515 $this->app->query_string = 'api_path.rss';
517 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
524 * Test the api_call() function with an Atom result.
526 * @runInSeparateProcess
528 public function testApiCallWithAtom()
532 'method' => 'method',
533 'func' => function () {
537 $_SERVER['REQUEST_METHOD'] = 'method';
539 $this->app->query_string = 'api_path.atom';
541 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
548 * Test the api_call() function with an unallowed method.
550 * @runInSeparateProcess
552 public function testApiCallWithWrongMethod()
555 $API['api_path'] = ['method' => 'method'];
557 $this->app->query_string = 'api_path';
559 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
565 * Test the api_call() function with an unauthorized user.
567 * @runInSeparateProcess
569 public function testApiCallWithWrongAuth()
573 'method' => 'method',
576 $_SERVER['REQUEST_METHOD'] = 'method';
577 $_SESSION['authenticated'] = false;
579 $this->app->query_string = 'api_path';
581 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
587 * Test the api_error() function with a JSON result.
589 * @runInSeparateProcess
591 public function testApiErrorWithJson()
594 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
595 api_error('json', new HTTPException('error_message'))
600 * Test the api_error() function with an XML result.
602 * @runInSeparateProcess
604 public function testApiErrorWithXml()
607 '<?xml version="1.0"?>'."\n".
608 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
609 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
610 'xmlns:georss="http://www.georss.org/georss">'."\n".
611 ' <error>error_message</error>'."\n".
612 ' <code>200 Friendica\Network\HTTP</code>'."\n".
615 api_error('xml', new HTTPException('error_message'))
620 * Test the api_error() function with an RSS result.
622 * @runInSeparateProcess
624 public function testApiErrorWithRss()
627 '<?xml version="1.0"?>'."\n".
628 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
629 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
630 'xmlns:georss="http://www.georss.org/georss">'."\n".
631 ' <error>error_message</error>'."\n".
632 ' <code>200 Friendica\Network\HTTP</code>'."\n".
635 api_error('rss', new HTTPException('error_message'))
640 * Test the api_error() function with an Atom result.
642 * @runInSeparateProcess
644 public function testApiErrorWithAtom()
647 '<?xml version="1.0"?>'."\n".
648 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
649 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
650 'xmlns:georss="http://www.georss.org/georss">'."\n".
651 ' <error>error_message</error>'."\n".
652 ' <code>200 Friendica\Network\HTTP</code>'."\n".
655 api_error('atom', new HTTPException('error_message'))
660 * Test the api_rss_extra() function.
663 public function testApiRssExtra()
665 $user_info = ['url' => 'user_url', 'lang' => 'en'];
666 $result = api_rss_extra($this->app, [], $user_info);
667 $this->assertEquals($user_info, $result['$user']);
668 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
669 $this->assertArrayHasKey('self', $result['$rss']);
670 $this->assertArrayHasKey('base', $result['$rss']);
671 $this->assertArrayHasKey('updated', $result['$rss']);
672 $this->assertArrayHasKey('atom_updated', $result['$rss']);
673 $this->assertArrayHasKey('language', $result['$rss']);
674 $this->assertArrayHasKey('logo', $result['$rss']);
678 * Test the api_rss_extra() function without any user info.
680 * @runInSeparateProcess
682 public function testApiRssExtraWithoutUserInfo()
684 $result = api_rss_extra($this->app, [], null);
685 $this->assertInternalType('array', $result['$user']);
686 $this->assertArrayHasKey('alternate', $result['$rss']);
687 $this->assertArrayHasKey('self', $result['$rss']);
688 $this->assertArrayHasKey('base', $result['$rss']);
689 $this->assertArrayHasKey('updated', $result['$rss']);
690 $this->assertArrayHasKey('atom_updated', $result['$rss']);
691 $this->assertArrayHasKey('language', $result['$rss']);
692 $this->assertArrayHasKey('logo', $result['$rss']);
696 * Test the api_unique_id_to_nurl() function.
699 public function testApiUniqueIdToNurl()
701 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
705 * Test the api_unique_id_to_nurl() function with a correct ID.
708 public function testApiUniqueIdToNurlWithCorrectId()
710 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
714 * Test the api_get_user() function.
716 * @runInSeparateProcess
718 public function testApiGetUser()
720 $user = api_get_user($this->app);
721 $this->assertSelfUser($user);
722 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
723 $this->assertEquals('6fdbe8', $user['profile_link_color']);
724 $this->assertEquals('ededed', $user['profile_background_color']);
728 * Test the api_get_user() function with a Frio schema.
730 * @runInSeparateProcess
732 public function testApiGetUserWithFrioSchema()
734 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
735 $user = api_get_user($this->app);
736 $this->assertSelfUser($user);
737 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
738 $this->assertEquals('6fdbe8', $user['profile_link_color']);
739 $this->assertEquals('ededed', $user['profile_background_color']);
743 * Test the api_get_user() function with a custom Frio schema.
745 * @runInSeparateProcess
747 public function testApiGetUserWithCustomFrioSchema()
749 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
750 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
751 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
752 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
753 $user = api_get_user($this->app);
754 $this->assertSelfUser($user);
755 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
756 $this->assertEquals('123456', $user['profile_link_color']);
757 $this->assertEquals('123456', $user['profile_background_color']);
761 * Test the api_get_user() function with an empty Frio schema.
763 * @runInSeparateProcess
765 public function testApiGetUserWithEmptyFrioSchema()
767 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
768 $user = api_get_user($this->app);
769 $this->assertSelfUser($user);
770 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
771 $this->assertEquals('6fdbe8', $user['profile_link_color']);
772 $this->assertEquals('ededed', $user['profile_background_color']);
776 * Test the api_get_user() function with an user that is not allowed to use the API.
778 * @runInSeparateProcess
780 public function testApiGetUserWithoutApiUser()
782 $_SERVER['PHP_AUTH_USER'] = 'Test user';
783 $_SERVER['PHP_AUTH_PW'] = 'password';
784 $_SESSION['allow_api'] = false;
785 $this->assertFalse(api_get_user($this->app));
789 * Test the api_get_user() function with an user ID in a GET parameter.
791 * @runInSeparateProcess
793 public function testApiGetUserWithGetId()
795 $_GET['user_id'] = $this->otherUser['id'];
796 $this->assertOtherUser(api_get_user($this->app));
800 * Test the api_get_user() function with a wrong user ID in a GET parameter.
802 * @runInSeparateProcess
803 * @expectedException Friendica\Network\HTTPException\BadRequestException
805 public function testApiGetUserWithWrongGetId()
807 $_GET['user_id'] = $this->wrongUserId;
808 $this->assertOtherUser(api_get_user($this->app));
812 * Test the api_get_user() function with an user name in a GET parameter.
814 * @runInSeparateProcess
816 public function testApiGetUserWithGetName()
818 $_GET['screen_name'] = $this->selfUser['nick'];
819 $this->assertSelfUser(api_get_user($this->app));
823 * Test the api_get_user() function with a profile URL in a GET parameter.
825 * @runInSeparateProcess
827 public function testApiGetUserWithGetUrl()
829 $_GET['profileurl'] = $this->selfUser['nurl'];
830 $this->assertSelfUser(api_get_user($this->app));
834 * Test the api_get_user() function with an user ID in the API path.
836 * @runInSeparateProcess
838 public function testApiGetUserWithNumericCalledApi()
841 $called_api = ['api_path'];
842 $this->app->argv[1] = $this->otherUser['id'].'.json';
843 $this->assertOtherUser(api_get_user($this->app));
847 * Test the api_get_user() function with the $called_api global variable.
849 * @runInSeparateProcess
851 public function testApiGetUserWithCalledApi()
854 $called_api = ['api', 'api_path'];
855 $this->assertSelfUser(api_get_user($this->app));
859 * Test the api_get_user() function with a valid user.
861 * @runInSeparateProcess
863 public function testApiGetUserWithCorrectUser()
865 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
869 * Test the api_get_user() function with a wrong user ID.
871 * @runInSeparateProcess
872 * @expectedException Friendica\Network\HTTPException\BadRequestException
874 public function testApiGetUserWithWrongUser()
876 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
880 * Test the api_get_user() function with a 0 user ID.
882 * @runInSeparateProcess
884 public function testApiGetUserWithZeroUser()
886 $this->assertSelfUser(api_get_user($this->app, 0));
890 * Test the api_item_get_user() function.
892 * @runInSeparateProcess
894 public function testApiItemGetUser()
896 $users = api_item_get_user($this->app, []);
897 $this->assertSelfUser($users[0]);
901 * Test the api_item_get_user() function with a different item parent.
904 public function testApiItemGetUserWithDifferentParent()
906 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
907 $this->assertSelfUser($users[0]);
908 $this->assertEquals($users[0], $users[1]);
912 * Test the api_walk_recursive() function.
915 public function testApiWalkRecursive()
923 // Should we test this with a callback that actually does something?
931 * Test the api_walk_recursive() function with an array.
934 public function testApiWalkRecursiveWithArray()
936 $array = [['item1'], ['item2']];
942 // Should we test this with a callback that actually does something?
950 * Test the api_reformat_xml() function.
953 public function testApiReformatXml()
957 $this->assertTrue(api_reformat_xml($item, $key));
958 $this->assertEquals('true', $item);
962 * Test the api_reformat_xml() function with a statusnet_api key.
965 public function testApiReformatXmlWithStatusnetKey()
968 $key = 'statusnet_api';
969 $this->assertTrue(api_reformat_xml($item, $key));
970 $this->assertEquals('statusnet:api', $key);
974 * Test the api_reformat_xml() function with a friendica_api key.
977 public function testApiReformatXmlWithFriendicaKey()
980 $key = 'friendica_api';
981 $this->assertTrue(api_reformat_xml($item, $key));
982 $this->assertEquals('friendica:api', $key);
986 * Test the api_create_xml() function.
989 public function testApiCreateXml()
992 '<?xml version="1.0"?>'."\n".
993 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
994 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
995 'xmlns:georss="http://www.georss.org/georss">'."\n".
996 ' <data>some_data</data>'."\n".
997 '</root_element>'."\n",
998 api_create_xml(['data' => ['some_data']], 'root_element')
1003 * Test the api_create_xml() function without any XML namespace.
1006 public function testApiCreateXmlWithoutNamespaces()
1008 $this->assertEquals(
1009 '<?xml version="1.0"?>'."\n".
1011 ' <data>some_data</data>'."\n".
1013 api_create_xml(['data' => ['some_data']], 'ok')
1018 * Test the api_format_data() function.
1021 public function testApiFormatData()
1023 $data = ['some_data'];
1024 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1028 * Test the api_format_data() function with an XML result.
1031 public function testApiFormatDataWithXml()
1033 $this->assertEquals(
1034 '<?xml version="1.0"?>'."\n".
1035 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1036 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1037 'xmlns:georss="http://www.georss.org/georss">'."\n".
1038 ' <data>some_data</data>'."\n".
1039 '</root_element>'."\n",
1040 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1045 * Test the api_account_verify_credentials() function.
1048 public function testApiAccountVerifyCredentials()
1050 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1054 * Test the api_account_verify_credentials() function without an authenticated user.
1056 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1058 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1060 $_SESSION['authenticated'] = false;
1061 api_account_verify_credentials('json');
1065 * Test the requestdata() function.
1068 public function testRequestdata()
1070 $this->assertNull(requestdata('variable_name'));
1074 * Test the requestdata() function with a POST parameter.
1077 public function testRequestdataWithPost()
1079 $_POST['variable_name'] = 'variable_value';
1080 $this->assertEquals('variable_value', requestdata('variable_name'));
1084 * Test the requestdata() function with a GET parameter.
1087 public function testRequestdataWithGet()
1089 $_GET['variable_name'] = 'variable_value';
1090 $this->assertEquals('variable_value', requestdata('variable_name'));
1094 * Test the api_statuses_mediap() function.
1097 public function testApiStatusesMediap()
1099 $this->app->argc = 2;
1107 'tmp_name' => $this->getTempImage(),
1108 'name' => 'spacer.png',
1109 'type' => 'image/png'
1112 $_GET['status'] = '<b>Status content</b>';
1114 $result = api_statuses_mediap('json');
1115 $this->assertStatus($result['status']);
1119 * Test the api_statuses_mediap() function without an authenticated user.
1121 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1123 public function testApiStatusesMediapWithoutAuthenticatedUser()
1125 $_SESSION['authenticated'] = false;
1126 api_statuses_mediap('json');
1130 * Test the api_statuses_update() function.
1133 public function testApiStatusesUpdate()
1135 $_GET['status'] = 'Status content #friendica';
1136 $_GET['in_reply_to_status_id'] = -1;
1145 'tmp_name' => $this->getTempImage(),
1146 'name' => 'spacer.png',
1147 'type' => 'image/png'
1151 $result = api_statuses_update('json');
1152 $this->assertStatus($result['status']);
1156 * Test the api_statuses_update() function with an HTML status.
1159 public function testApiStatusesUpdateWithHtml()
1161 $_GET['htmlstatus'] = '<b>Status content</b>';
1163 $result = api_statuses_update('json');
1164 $this->assertStatus($result['status']);
1168 * Test the api_statuses_update() function without an authenticated user.
1170 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1172 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1174 $_SESSION['authenticated'] = false;
1175 api_statuses_update('json');
1179 * Test the api_statuses_update() function with a parent status.
1182 public function testApiStatusesUpdateWithParent()
1184 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1188 * Test the api_statuses_update() function with a media_ids parameter.
1191 public function testApiStatusesUpdateWithMediaIds()
1193 $this->markTestIncomplete();
1197 * Test the api_statuses_update() function with the throttle limit reached.
1200 public function testApiStatusesUpdateWithDayThrottleReached()
1202 $this->markTestIncomplete();
1206 * Test the api_media_upload() function.
1208 * @expectedException Friendica\Network\HTTPException\BadRequestException
1210 public function testApiMediaUpload()
1216 * Test the api_media_upload() function without an authenticated user.
1218 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1220 public function testApiMediaUploadWithoutAuthenticatedUser()
1222 $_SESSION['authenticated'] = false;
1227 * Test the api_media_upload() function with an invalid uploaded media.
1229 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1231 public function testApiMediaUploadWithMedia()
1236 'tmp_name' => 'tmp_name'
1243 * Test the api_media_upload() function with an valid uploaded media.
1246 public function testApiMediaUploadWithValidMedia()
1254 'tmp_name' => $this->getTempImage(),
1255 'name' => 'spacer.png',
1256 'type' => 'image/png'
1262 $result = api_media_upload();
1263 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1264 $this->assertEquals(1, $result['media']['image']['w']);
1265 $this->assertEquals(1, $result['media']['image']['h']);
1266 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1270 * Test the api_status_show() function.
1273 public function testApiStatusShow()
1275 $result = api_status_show('json');
1276 $this->assertStatus($result['status']);
1280 * Test the api_status_show() function with an XML result.
1283 public function testApiStatusShowWithXml()
1285 $result = api_status_show('xml');
1286 $this->assertXml($result, 'statuses');
1290 * Test the api_status_show() function with a raw result.
1293 public function testApiStatusShowWithRaw()
1295 $this->assertStatus(api_status_show('raw'));
1299 * Test the api_users_show() function.
1302 public function testApiUsersShow()
1304 $result = api_users_show('json');
1305 // We can't use assertSelfUser() here because the user object is missing some properties.
1306 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1307 $this->assertEquals('DFRN', $result['user']['location']);
1308 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1309 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1310 $this->assertEquals('dfrn', $result['user']['network']);
1311 $this->assertTrue($result['user']['verified']);
1315 * Test the api_users_show() function with an XML result.
1318 public function testApiUsersShowWithXml()
1320 $result = api_users_show('xml');
1321 $this->assertXml($result, 'statuses');
1325 * Test the api_users_search() function.
1328 public function testApiUsersSearch()
1330 $_GET['q'] = 'othercontact';
1331 $result = api_users_search('json');
1332 $this->assertOtherUser($result['users'][0]);
1336 * Test the api_users_search() function with an XML result.
1339 public function testApiUsersSearchWithXml()
1341 $_GET['q'] = 'othercontact';
1342 $result = api_users_search('xml');
1343 $this->assertXml($result, 'users');
1347 * Test the api_users_search() function without a GET q parameter.
1349 * @expectedException Friendica\Network\HTTPException\BadRequestException
1351 public function testApiUsersSearchWithoutQuery()
1353 api_users_search('json');
1357 * Test the api_users_lookup() function.
1359 * @expectedException Friendica\Network\HTTPException\NotFoundException
1361 public function testApiUsersLookup()
1363 api_users_lookup('json');
1367 * Test the api_users_lookup() function with an user ID.
1370 public function testApiUsersLookupWithUserId()
1372 $_REQUEST['user_id'] = $this->otherUser['id'];
1373 $result = api_users_lookup('json');
1374 $this->assertOtherUser($result['users'][0]);
1378 * Test the api_search() function.
1381 public function testApiSearch()
1383 $_REQUEST['q'] = 'reply';
1384 $_REQUEST['max_id'] = 10;
1385 $result = api_search('json');
1386 foreach ($result['status'] as $status) {
1387 $this->assertStatus($status);
1388 $this->assertContains('reply', $status['text'], null, true);
1393 * Test the api_search() function a count parameter.
1396 public function testApiSearchWithCount()
1398 $_REQUEST['q'] = 'reply';
1399 $_REQUEST['count'] = 20;
1400 $result = api_search('json');
1401 foreach ($result['status'] as $status) {
1402 $this->assertStatus($status);
1403 $this->assertContains('reply', $status['text'], null, true);
1408 * Test the api_search() function with an rpp parameter.
1411 public function testApiSearchWithRpp()
1413 $_REQUEST['q'] = 'reply';
1414 $_REQUEST['rpp'] = 20;
1415 $result = api_search('json');
1416 foreach ($result['status'] as $status) {
1417 $this->assertStatus($status);
1418 $this->assertContains('reply', $status['text'], null, true);
1423 * Test the api_search() function with an q parameter contains hashtag.
1426 public function testApiSearchWithHashtag()
1428 $_REQUEST['q'] = '%23friendica';
1429 $result = api_search('json');
1430 foreach ($result['status'] as $status) {
1431 $this->assertStatus($status);
1432 $this->assertContains('#friendica', $status['text'], null, true);
1437 * Test the api_search() function with an exclude_replies parameter.
1440 public function testApiSearchWithExcludeReplies()
1442 $_REQUEST['max_id'] = 10;
1443 $_REQUEST['exclude_replies'] = true;
1444 $_REQUEST['q'] = 'friendica';
1445 $result = api_search('json');
1446 foreach ($result['status'] as $status) {
1447 $this->assertStatus($status);
1452 * Test the api_search() function without an authenticated user.
1454 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1456 public function testApiSearchWithUnallowedUser()
1458 $_SESSION['allow_api'] = false;
1459 $_GET['screen_name'] = $this->selfUser['nick'];
1464 * Test the api_search() function without any GET query parameter.
1466 * @expectedException Friendica\Network\HTTPException\BadRequestException
1468 public function testApiSearchWithoutQuery()
1474 * Test the api_statuses_home_timeline() function.
1477 public function testApiStatusesHomeTimeline()
1479 $_REQUEST['max_id'] = 10;
1480 $_REQUEST['exclude_replies'] = true;
1481 $_REQUEST['conversation_id'] = 1;
1482 $result = api_statuses_home_timeline('json');
1483 $this->assertNotEmpty($result['status']);
1484 foreach ($result['status'] as $status) {
1485 $this->assertStatus($status);
1490 * Test the api_statuses_home_timeline() function with a negative page parameter.
1493 public function testApiStatusesHomeTimelineWithNegativePage()
1495 $_REQUEST['page'] = -2;
1496 $result = api_statuses_home_timeline('json');
1497 $this->assertNotEmpty($result['status']);
1498 foreach ($result['status'] as $status) {
1499 $this->assertStatus($status);
1504 * Test the api_statuses_home_timeline() with an unallowed user.
1506 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1508 public function testApiStatusesHomeTimelineWithUnallowedUser()
1510 $_SESSION['allow_api'] = false;
1511 $_GET['screen_name'] = $this->selfUser['nick'];
1512 api_statuses_home_timeline('json');
1516 * Test the api_statuses_home_timeline() function with an RSS result.
1519 public function testApiStatusesHomeTimelineWithRss()
1521 $result = api_statuses_home_timeline('rss');
1522 $this->assertXml($result, 'statuses');
1526 * Test the api_statuses_public_timeline() function.
1529 public function testApiStatusesPublicTimeline()
1531 $_REQUEST['max_id'] = 10;
1532 $_REQUEST['conversation_id'] = 1;
1533 $result = api_statuses_public_timeline('json');
1534 $this->assertNotEmpty($result['status']);
1535 foreach ($result['status'] as $status) {
1536 $this->assertStatus($status);
1541 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1544 public function testApiStatusesPublicTimelineWithExcludeReplies()
1546 $_REQUEST['max_id'] = 10;
1547 $_REQUEST['exclude_replies'] = true;
1548 $result = api_statuses_public_timeline('json');
1549 $this->assertNotEmpty($result['status']);
1550 foreach ($result['status'] as $status) {
1551 $this->assertStatus($status);
1556 * Test the api_statuses_public_timeline() function with a negative page parameter.
1559 public function testApiStatusesPublicTimelineWithNegativePage()
1561 $_REQUEST['page'] = -2;
1562 $result = api_statuses_public_timeline('json');
1563 $this->assertNotEmpty($result['status']);
1564 foreach ($result['status'] as $status) {
1565 $this->assertStatus($status);
1570 * Test the api_statuses_public_timeline() function with an unallowed user.
1572 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1574 public function testApiStatusesPublicTimelineWithUnallowedUser()
1576 $_SESSION['allow_api'] = false;
1577 $_GET['screen_name'] = $this->selfUser['nick'];
1578 api_statuses_public_timeline('json');
1582 * Test the api_statuses_public_timeline() function with an RSS result.
1585 public function testApiStatusesPublicTimelineWithRss()
1587 $result = api_statuses_public_timeline('rss');
1588 $this->assertXml($result, 'statuses');
1592 * Test the api_statuses_networkpublic_timeline() function.
1595 public function testApiStatusesNetworkpublicTimeline()
1597 $_REQUEST['max_id'] = 10;
1598 $result = api_statuses_networkpublic_timeline('json');
1599 $this->assertNotEmpty($result['status']);
1600 foreach ($result['status'] as $status) {
1601 $this->assertStatus($status);
1606 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1609 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1611 $_REQUEST['page'] = -2;
1612 $result = api_statuses_networkpublic_timeline('json');
1613 $this->assertNotEmpty($result['status']);
1614 foreach ($result['status'] as $status) {
1615 $this->assertStatus($status);
1620 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1622 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1624 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1626 $_SESSION['allow_api'] = false;
1627 $_GET['screen_name'] = $this->selfUser['nick'];
1628 api_statuses_networkpublic_timeline('json');
1632 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1635 public function testApiStatusesNetworkpublicTimelineWithRss()
1637 $result = api_statuses_networkpublic_timeline('rss');
1638 $this->assertXml($result, 'statuses');
1642 * Test the api_statuses_show() function.
1644 * @expectedException Friendica\Network\HTTPException\BadRequestException
1646 public function testApiStatusesShow()
1648 api_statuses_show('json');
1652 * Test the api_statuses_show() function with an ID.
1655 public function testApiStatusesShowWithId()
1657 $this->app->argv[3] = 1;
1658 $result = api_statuses_show('json');
1659 $this->assertStatus($result['status']);
1663 * Test the api_statuses_show() function with the conversation parameter.
1666 public function testApiStatusesShowWithConversation()
1668 $this->app->argv[3] = 1;
1669 $_REQUEST['conversation'] = 1;
1670 $result = api_statuses_show('json');
1671 $this->assertNotEmpty($result['status']);
1672 foreach ($result['status'] as $status) {
1673 $this->assertStatus($status);
1678 * Test the api_statuses_show() function with an unallowed user.
1680 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1682 public function testApiStatusesShowWithUnallowedUser()
1684 $_SESSION['allow_api'] = false;
1685 $_GET['screen_name'] = $this->selfUser['nick'];
1686 api_statuses_show('json');
1690 * Test the api_conversation_show() function.
1692 * @expectedException Friendica\Network\HTTPException\BadRequestException
1694 public function testApiConversationShow()
1696 api_conversation_show('json');
1700 * Test the api_conversation_show() function with an ID.
1703 public function testApiConversationShowWithId()
1705 $this->app->argv[3] = 1;
1706 $_REQUEST['max_id'] = 10;
1707 $_REQUEST['page'] = -2;
1708 $result = api_conversation_show('json');
1709 $this->assertNotEmpty($result['status']);
1710 foreach ($result['status'] as $status) {
1711 $this->assertStatus($status);
1716 * Test the api_conversation_show() function with an unallowed user.
1718 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1720 public function testApiConversationShowWithUnallowedUser()
1722 $_SESSION['allow_api'] = false;
1723 $_GET['screen_name'] = $this->selfUser['nick'];
1724 api_conversation_show('json');
1728 * Test the api_statuses_repeat() function.
1730 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1732 public function testApiStatusesRepeat()
1734 api_statuses_repeat('json');
1738 * Test the api_statuses_repeat() function without an authenticated user.
1740 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1742 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1744 $_SESSION['authenticated'] = false;
1745 api_statuses_repeat('json');
1749 * Test the api_statuses_repeat() function with an ID.
1752 public function testApiStatusesRepeatWithId()
1754 $this->app->argv[3] = 1;
1755 $result = api_statuses_repeat('json');
1756 $this->assertStatus($result['status']);
1758 // Also test with a shared status
1759 $this->app->argv[3] = 5;
1760 $result = api_statuses_repeat('json');
1761 $this->assertStatus($result['status']);
1765 * Test the api_statuses_destroy() function.
1767 * @expectedException Friendica\Network\HTTPException\BadRequestException
1769 public function testApiStatusesDestroy()
1771 api_statuses_destroy('json');
1775 * Test the api_statuses_destroy() function without an authenticated user.
1777 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1779 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1781 $_SESSION['authenticated'] = false;
1782 api_statuses_destroy('json');
1786 * Test the api_statuses_destroy() function with an ID.
1789 public function testApiStatusesDestroyWithId()
1791 $this->app->argv[3] = 1;
1792 $result = api_statuses_destroy('json');
1793 $this->assertStatus($result['status']);
1797 * Test the api_statuses_mentions() function.
1800 public function testApiStatusesMentions()
1802 $this->app->user = ['nickname' => $this->selfUser['nick']];
1803 $_REQUEST['max_id'] = 10;
1804 $result = api_statuses_mentions('json');
1805 $this->assertEmpty($result['status']);
1806 // We should test with mentions in the database.
1810 * Test the api_statuses_mentions() function with a negative page parameter.
1813 public function testApiStatusesMentionsWithNegativePage()
1815 $_REQUEST['page'] = -2;
1816 $result = api_statuses_mentions('json');
1817 $this->assertEmpty($result['status']);
1821 * Test the api_statuses_mentions() function with an unallowed user.
1823 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1825 public function testApiStatusesMentionsWithUnallowedUser()
1827 $_SESSION['allow_api'] = false;
1828 $_GET['screen_name'] = $this->selfUser['nick'];
1829 api_statuses_mentions('json');
1833 * Test the api_statuses_mentions() function with an RSS result.
1836 public function testApiStatusesMentionsWithRss()
1838 $result = api_statuses_mentions('rss');
1839 $this->assertXml($result, 'statuses');
1843 * Test the api_statuses_user_timeline() function.
1846 public function testApiStatusesUserTimeline()
1848 $_REQUEST['max_id'] = 10;
1849 $_REQUEST['exclude_replies'] = true;
1850 $_REQUEST['conversation_id'] = 1;
1851 $result = api_statuses_user_timeline('json');
1852 $this->assertNotEmpty($result['status']);
1853 foreach ($result['status'] as $status) {
1854 $this->assertStatus($status);
1859 * Test the api_statuses_user_timeline() function with a negative page parameter.
1862 public function testApiStatusesUserTimelineWithNegativePage()
1864 $_REQUEST['page'] = -2;
1865 $result = api_statuses_user_timeline('json');
1866 $this->assertNotEmpty($result['status']);
1867 foreach ($result['status'] as $status) {
1868 $this->assertStatus($status);
1873 * Test the api_statuses_user_timeline() function with an RSS result.
1876 public function testApiStatusesUserTimelineWithRss()
1878 $result = api_statuses_user_timeline('rss');
1879 $this->assertXml($result, 'statuses');
1883 * Test the api_statuses_user_timeline() function with an unallowed user.
1885 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1887 public function testApiStatusesUserTimelineWithUnallowedUser()
1889 $_SESSION['allow_api'] = false;
1890 $_GET['screen_name'] = $this->selfUser['nick'];
1891 api_statuses_user_timeline('json');
1895 * Test the api_favorites_create_destroy() function.
1897 * @expectedException Friendica\Network\HTTPException\BadRequestException
1899 public function testApiFavoritesCreateDestroy()
1901 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1902 $this->app->argc = count($this->app->argv);
1903 api_favorites_create_destroy('json');
1907 * Test the api_favorites_create_destroy() function with an invalid ID.
1909 * @expectedException Friendica\Network\HTTPException\BadRequestException
1911 public function testApiFavoritesCreateDestroyWithInvalidId()
1913 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1914 $this->app->argc = count($this->app->argv);
1915 api_favorites_create_destroy('json');
1919 * Test the api_favorites_create_destroy() function with an invalid action.
1921 * @expectedException Friendica\Network\HTTPException\BadRequestException
1923 public function testApiFavoritesCreateDestroyWithInvalidAction()
1925 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1926 $this->app->argc = count($this->app->argv);
1927 $_REQUEST['id'] = 1;
1928 api_favorites_create_destroy('json');
1932 * Test the api_favorites_create_destroy() function with the create action.
1935 public function testApiFavoritesCreateDestroyWithCreateAction()
1937 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1938 $this->app->argc = count($this->app->argv);
1939 $_REQUEST['id'] = 3;
1940 $result = api_favorites_create_destroy('json');
1941 $this->assertStatus($result['status']);
1945 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1948 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1950 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1951 $this->app->argc = count($this->app->argv);
1952 $_REQUEST['id'] = 3;
1953 $result = api_favorites_create_destroy('rss');
1954 $this->assertXml($result, 'status');
1958 * Test the api_favorites_create_destroy() function with the destroy action.
1961 public function testApiFavoritesCreateDestroyWithDestroyAction()
1963 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1964 $this->app->argc = count($this->app->argv);
1965 $_REQUEST['id'] = 3;
1966 $result = api_favorites_create_destroy('json');
1967 $this->assertStatus($result['status']);
1971 * Test the api_favorites_create_destroy() function without an authenticated user.
1973 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1975 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1977 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1978 $this->app->argc = count($this->app->argv);
1979 $_SESSION['authenticated'] = false;
1980 api_favorites_create_destroy('json');
1984 * Test the api_favorites() function.
1987 public function testApiFavorites()
1989 $_REQUEST['page'] = -1;
1990 $_REQUEST['max_id'] = 10;
1991 $result = api_favorites('json');
1992 foreach ($result['status'] as $status) {
1993 $this->assertStatus($status);
1998 * Test the api_favorites() function with an RSS result.
2001 public function testApiFavoritesWithRss()
2003 $result = api_favorites('rss');
2004 $this->assertXml($result, 'statuses');
2008 * Test the api_favorites() function with an unallowed user.
2010 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2012 public function testApiFavoritesWithUnallowedUser()
2014 $_SESSION['allow_api'] = false;
2015 $_GET['screen_name'] = $this->selfUser['nick'];
2016 api_favorites('json');
2020 * Test the api_format_messages() function.
2023 public function testApiFormatMessages()
2025 $result = api_format_messages(
2026 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2027 ['id' => 2, 'screen_name' => 'recipient_name'],
2028 ['id' => 3, 'screen_name' => 'sender_name']
2030 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2031 $this->assertEquals(1, $result['id']);
2032 $this->assertEquals(2, $result['recipient_id']);
2033 $this->assertEquals(3, $result['sender_id']);
2034 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2035 $this->assertEquals('sender_name', $result['sender_screen_name']);
2039 * Test the api_format_messages() function with HTML.
2042 public function testApiFormatMessagesWithHtmlText()
2044 $_GET['getText'] = 'html';
2045 $result = api_format_messages(
2046 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2047 ['id' => 2, 'screen_name' => 'recipient_name'],
2048 ['id' => 3, 'screen_name' => 'sender_name']
2050 $this->assertEquals('item_title', $result['title']);
2051 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2055 * Test the api_format_messages() function with plain text.
2058 public function testApiFormatMessagesWithPlainText()
2060 $_GET['getText'] = 'plain';
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('item_body', $result['text']);
2071 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2074 public function testApiFormatMessagesWithoutUserObjects()
2076 $_GET['getUserObjects'] = 'false';
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->assertTrue(!isset($result['sender']));
2083 $this->assertTrue(!isset($result['recipient']));
2087 * Test the api_convert_item() function.
2090 public function testApiConvertItem()
2092 $result = api_convert_item(
2094 'network' => 'feed',
2095 'title' => 'item_title',
2096 // We need a long string to test that it is correctly cut
2097 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2098 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2099 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2100 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2101 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2102 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2103 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2104 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2105 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2106 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2107 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2108 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2109 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2110 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2111 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2112 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2113 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2114 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2115 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2116 'repellat officia illum quos impedit quam iste esse unde qui '.
2117 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2118 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2119 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2120 'plink' => 'item_plink'
2123 $this->assertStringStartsWith('item_title', $result['text']);
2124 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2128 * Test the api_convert_item() function with an empty item body.
2131 public function testApiConvertItemWithoutBody()
2133 $result = api_convert_item(
2135 'network' => 'feed',
2136 'title' => 'item_title',
2138 'plink' => 'item_plink'
2141 $this->assertEquals('item_title', $result['text']);
2142 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2146 * Test the api_convert_item() function with the title in the body.
2149 public function testApiConvertItemWithTitleInBody()
2151 $result = api_convert_item(
2153 'title' => 'item_title',
2154 'body' => 'item_title item_body'
2157 $this->assertEquals('item_title item_body', $result['text']);
2158 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2162 * Test the api_get_attachments() function.
2165 public function testApiGetAttachments()
2168 $this->assertEmpty(api_get_attachments($body));
2172 * Test the api_get_attachments() function with an img tag.
2175 public function testApiGetAttachmentsWithImage()
2177 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2178 $this->assertInternalType('array', api_get_attachments($body));
2182 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2185 public function testApiGetAttachmentsWithImageAndAndStatus()
2187 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2188 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2189 $this->assertInternalType('array', api_get_attachments($body));
2193 * Test the api_get_entitities() function.
2196 public function testApiGetEntitities()
2199 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2203 * Test the api_get_entitities() function with the include_entities parameter.
2206 public function testApiGetEntititiesWithIncludeEntities()
2208 $_REQUEST['include_entities'] = 'true';
2210 $result = api_get_entitities($text, 'bbcode');
2211 $this->assertInternalType('array', $result['hashtags']);
2212 $this->assertInternalType('array', $result['symbols']);
2213 $this->assertInternalType('array', $result['urls']);
2214 $this->assertInternalType('array', $result['user_mentions']);
2218 * Test the api_format_items_embeded_images() function.
2221 public function testApiFormatItemsEmbededImages()
2223 $this->assertEquals(
2224 'text ' . System::baseUrl() . '/display/item_guid',
2225 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2230 * Test the api_contactlink_to_array() function.
2233 public function testApiContactlinkToArray()
2235 $this->assertEquals(
2240 api_contactlink_to_array('text')
2245 * Test the api_contactlink_to_array() function with an URL.
2248 public function testApiContactlinkToArrayWithUrl()
2250 $this->assertEquals(
2252 'name' => ['link_text'],
2255 api_contactlink_to_array('text <a href="url">link_text</a>')
2260 * Test the api_format_items_activities() function.
2263 public function testApiFormatItemsActivities()
2265 $item = ['uid' => 0, 'uri' => ''];
2266 $result = api_format_items_activities($item);
2267 $this->assertArrayHasKey('like', $result);
2268 $this->assertArrayHasKey('dislike', $result);
2269 $this->assertArrayHasKey('attendyes', $result);
2270 $this->assertArrayHasKey('attendno', $result);
2271 $this->assertArrayHasKey('attendmaybe', $result);
2275 * Test the api_format_items_activities() function with an XML result.
2278 public function testApiFormatItemsActivitiesWithXml()
2280 $item = ['uid' => 0, 'uri' => ''];
2281 $result = api_format_items_activities($item, 'xml');
2282 $this->assertArrayHasKey('friendica:like', $result);
2283 $this->assertArrayHasKey('friendica:dislike', $result);
2284 $this->assertArrayHasKey('friendica:attendyes', $result);
2285 $this->assertArrayHasKey('friendica:attendno', $result);
2286 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2290 * Test the api_format_items_profiles() function.
2293 public function testApiFormatItemsProfiles()
2296 'id' => 'profile_id',
2297 'profile-name' => 'profile_name',
2298 'is-default' => true,
2299 'hide-friends' => true,
2300 'photo' => 'profile_photo',
2301 'thumb' => 'profile_thumb',
2303 'net-publish' => true,
2304 'pdesc' => 'description',
2305 'dob' => 'date_of_birth',
2306 'address' => 'address',
2307 'locality' => 'city',
2308 'region' => 'region',
2309 'postal-code' => 'postal_code',
2310 'country-name' => 'country',
2311 'hometown' => 'hometown',
2312 'gender' => 'gender',
2313 'marital' => 'marital',
2314 'with' => 'marital_with',
2315 'howlong' => 'marital_since',
2316 'sexual' => 'sexual',
2317 'politic' => 'politic',
2318 'religion' => 'religion',
2319 'pub_keywords' => 'public_keywords',
2320 'prv_keywords' => 'private_keywords',
2323 'dislikes' => 'dislikes',
2329 'interest' => 'interest',
2330 'romance' => 'romance',
2332 'education' => 'education',
2333 'contact' => 'social_networks',
2334 'homepage' => 'homepage'
2336 $result = api_format_items_profiles($profile_row);
2337 $this->assertEquals(
2339 'profile_id' => 'profile_id',
2340 'profile_name' => 'profile_name',
2341 'is_default' => true,
2342 'hide_friends' => true,
2343 'profile_photo' => 'profile_photo',
2344 'profile_thumb' => 'profile_thumb',
2346 'net_publish' => true,
2347 'description' => 'description',
2348 'date_of_birth' => 'date_of_birth',
2349 'address' => 'address',
2351 'region' => 'region',
2352 'postal_code' => 'postal_code',
2353 'country' => 'country',
2354 'hometown' => 'hometown',
2355 'gender' => 'gender',
2356 'marital' => 'marital',
2357 'marital_with' => 'marital_with',
2358 'marital_since' => 'marital_since',
2359 'sexual' => 'sexual',
2360 'politic' => 'politic',
2361 'religion' => 'religion',
2362 'public_keywords' => 'public_keywords',
2363 'private_keywords' => 'private_keywords',
2366 'dislikes' => 'dislikes',
2372 'interest' => 'interest',
2373 'romance' => 'romance',
2375 'education' => 'education',
2376 'social_networks' => 'social_networks',
2377 'homepage' => 'homepage',
2385 * Test the api_format_items() function.
2388 public function testApiFormatItems()
2392 'item_network' => 'item_network',
2398 'author-network' => Protocol::DFRN,
2399 'author-link' => 'http://localhost/profile/othercontact',
2403 $result = api_format_items($items, ['id' => 0], true);
2404 foreach ($result as $status) {
2405 $this->assertStatus($status);
2410 * Test the api_format_items() function with an XML result.
2413 public function testApiFormatItemsWithXml()
2421 'author-network' => Protocol::DFRN,
2422 'author-link' => 'http://localhost/profile/othercontact',
2426 $result = api_format_items($items, ['id' => 0], true, 'xml');
2427 foreach ($result as $status) {
2428 $this->assertStatus($status);
2433 * Test the api_format_items() function.
2436 public function testApiAccountRateLimitStatus()
2438 $result = api_account_rate_limit_status('json');
2439 $this->assertEquals(150, $result['hash']['remaining_hits']);
2440 $this->assertEquals(150, $result['hash']['hourly_limit']);
2441 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2445 * Test the api_format_items() function with an XML result.
2448 public function testApiAccountRateLimitStatusWithXml()
2450 $result = api_account_rate_limit_status('xml');
2451 $this->assertXml($result, 'hash');
2455 * Test the api_help_test() function.
2458 public function testApiHelpTest()
2460 $result = api_help_test('json');
2461 $this->assertEquals(['ok' => 'ok'], $result);
2465 * Test the api_help_test() function with an XML result.
2468 public function testApiHelpTestWithXml()
2470 $result = api_help_test('xml');
2471 $this->assertXml($result, 'ok');
2475 * Test the api_lists_list() function.
2478 public function testApiListsList()
2480 $result = api_lists_list('json');
2481 $this->assertEquals(['lists_list' => []], $result);
2485 * Test the api_lists_ownerships() function.
2488 public function testApiListsOwnerships()
2490 $result = api_lists_ownerships('json');
2491 foreach ($result['lists']['lists'] as $list) {
2492 $this->assertList($list);
2497 * Test the api_lists_ownerships() function without an authenticated user.
2499 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2501 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2503 $_SESSION['authenticated'] = false;
2504 api_lists_ownerships('json');
2508 * Test the api_lists_statuses() function.
2509 * @expectedException Friendica\Network\HTTPException\BadRequestException
2512 public function testApiListsStatuses()
2514 api_lists_statuses('json');
2518 * Test the api_lists_statuses() function with a list ID.
2521 public function testApiListsStatusesWithListId()
2523 $_REQUEST['list_id'] = 1;
2524 $_REQUEST['page'] = -1;
2525 $_REQUEST['max_id'] = 10;
2526 $result = api_lists_statuses('json');
2527 foreach ($result['status'] as $status) {
2528 $this->assertStatus($status);
2533 * Test the api_lists_statuses() function with a list ID and a RSS result.
2536 public function testApiListsStatusesWithListIdAndRss()
2538 $_REQUEST['list_id'] = 1;
2539 $result = api_lists_statuses('rss');
2540 $this->assertXml($result, 'statuses');
2544 * Test the api_lists_statuses() function with an unallowed user.
2546 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2548 public function testApiListsStatusesWithUnallowedUser()
2550 $_SESSION['allow_api'] = false;
2551 $_GET['screen_name'] = $this->selfUser['nick'];
2552 api_lists_statuses('json');
2556 * Test the api_statuses_f() function.
2559 public function testApiStatusesFWithFriends()
2562 $result = api_statuses_f('friends');
2563 $this->assertArrayHasKey('user', $result);
2567 * Test the api_statuses_f() function.
2570 public function testApiStatusesFWithFollowers()
2572 $result = api_statuses_f('followers');
2573 $this->assertArrayHasKey('user', $result);
2577 * Test the api_statuses_f() function.
2580 public function testApiStatusesFWithBlocks()
2582 $result = api_statuses_f('blocks');
2583 $this->assertArrayHasKey('user', $result);
2587 * Test the api_statuses_f() function.
2590 public function testApiStatusesFWithIncoming()
2592 $result = api_statuses_f('incoming');
2593 $this->assertArrayHasKey('user', $result);
2597 * Test the api_statuses_f() function an undefined cursor GET variable.
2600 public function testApiStatusesFWithUndefinedCursor()
2602 $_GET['cursor'] = 'undefined';
2603 $this->assertFalse(api_statuses_f('friends'));
2607 * Test the api_statuses_friends() function.
2610 public function testApiStatusesFriends()
2612 $result = api_statuses_friends('json');
2613 $this->assertArrayHasKey('user', $result);
2617 * Test the api_statuses_friends() function an undefined cursor GET variable.
2620 public function testApiStatusesFriendsWithUndefinedCursor()
2622 $_GET['cursor'] = 'undefined';
2623 $this->assertFalse(api_statuses_friends('json'));
2627 * Test the api_statuses_followers() function.
2630 public function testApiStatusesFollowers()
2632 $result = api_statuses_followers('json');
2633 $this->assertArrayHasKey('user', $result);
2637 * Test the api_statuses_followers() function an undefined cursor GET variable.
2640 public function testApiStatusesFollowersWithUndefinedCursor()
2642 $_GET['cursor'] = 'undefined';
2643 $this->assertFalse(api_statuses_followers('json'));
2647 * Test the api_blocks_list() function.
2650 public function testApiBlocksList()
2652 $result = api_blocks_list('json');
2653 $this->assertArrayHasKey('user', $result);
2657 * Test the api_blocks_list() function an undefined cursor GET variable.
2660 public function testApiBlocksListWithUndefinedCursor()
2662 $_GET['cursor'] = 'undefined';
2663 $this->assertFalse(api_blocks_list('json'));
2667 * Test the api_friendships_incoming() function.
2670 public function testApiFriendshipsIncoming()
2672 $result = api_friendships_incoming('json');
2673 $this->assertArrayHasKey('id', $result);
2677 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2680 public function testApiFriendshipsIncomingWithUndefinedCursor()
2682 $_GET['cursor'] = 'undefined';
2683 $this->assertFalse(api_friendships_incoming('json'));
2687 * Test the api_statusnet_config() function.
2690 public function testApiStatusnetConfig()
2692 $result = api_statusnet_config('json');
2693 $this->assertEquals('localhost', $result['config']['site']['server']);
2694 $this->assertEquals('default', $result['config']['site']['theme']);
2695 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2696 $this->assertTrue($result['config']['site']['fancy']);
2697 $this->assertEquals('en', $result['config']['site']['language']);
2698 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2699 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2700 $this->assertEquals('false', $result['config']['site']['private']);
2701 $this->assertEquals('false', $result['config']['site']['ssl']);
2702 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2706 * Test the api_statusnet_version() function.
2709 public function testApiStatusnetVersion()
2711 $result = api_statusnet_version('json');
2712 $this->assertEquals('0.9.7', $result['version']);
2716 * Test the api_ff_ids() function.
2719 public function testApiFfIds()
2721 $result = api_ff_ids('json');
2722 $this->assertNull($result);
2726 * Test the api_ff_ids() function with a result.
2729 public function testApiFfIdsWithResult()
2731 $this->markTestIncomplete();
2735 * Test the api_ff_ids() function without an authenticated user.
2737 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2739 public function testApiFfIdsWithoutAuthenticatedUser()
2741 $_SESSION['authenticated'] = false;
2746 * Test the api_friends_ids() function.
2749 public function testApiFriendsIds()
2751 $result = api_friends_ids('json');
2752 $this->assertNull($result);
2756 * Test the api_followers_ids() function.
2759 public function testApiFollowersIds()
2761 $result = api_followers_ids('json');
2762 $this->assertNull($result);
2766 * Test the api_direct_messages_new() function.
2769 public function testApiDirectMessagesNew()
2771 $result = api_direct_messages_new('json');
2772 $this->assertNull($result);
2776 * Test the api_direct_messages_new() function without an authenticated user.
2778 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2780 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2782 $_SESSION['authenticated'] = false;
2783 api_direct_messages_new('json');
2787 * Test the api_direct_messages_new() function with an user ID.
2790 public function testApiDirectMessagesNewWithUserId()
2792 $_POST['text'] = 'message_text';
2793 $_POST['user_id'] = $this->otherUser['id'];
2794 $result = api_direct_messages_new('json');
2795 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2799 * Test the api_direct_messages_new() function with a screen name.
2802 public function testApiDirectMessagesNewWithScreenName()
2804 $_POST['text'] = 'message_text';
2805 $_POST['screen_name'] = $this->friendUser['nick'];
2806 $result = api_direct_messages_new('json');
2807 $this->assertEquals(1, $result['direct_message']['id']);
2808 $this->assertContains('message_text', $result['direct_message']['text']);
2809 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2810 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2814 * Test the api_direct_messages_new() function with a title.
2817 public function testApiDirectMessagesNewWithTitle()
2819 $_POST['text'] = 'message_text';
2820 $_POST['screen_name'] = $this->friendUser['nick'];
2821 $_REQUEST['title'] = 'message_title';
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->assertContains('message_title', $result['direct_message']['text']);
2826 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2827 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2831 * Test the api_direct_messages_new() function with an RSS result.
2834 public function testApiDirectMessagesNewWithRss()
2836 $_POST['text'] = 'message_text';
2837 $_POST['screen_name'] = $this->friendUser['nick'];
2838 $result = api_direct_messages_new('rss');
2839 $this->assertXml($result, 'direct-messages');
2843 * Test the api_direct_messages_destroy() function.
2845 * @expectedException Friendica\Network\HTTPException\BadRequestException
2847 public function testApiDirectMessagesDestroy()
2849 api_direct_messages_destroy('json');
2853 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2856 public function testApiDirectMessagesDestroyWithVerbose()
2858 $_GET['friendica_verbose'] = 'true';
2859 $result = api_direct_messages_destroy('json');
2860 $this->assertEquals(
2863 'result' => 'error',
2864 'message' => 'message id or parenturi not specified'
2872 * Test the api_direct_messages_destroy() function without an authenticated user.
2874 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2876 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2878 $_SESSION['authenticated'] = false;
2879 api_direct_messages_destroy('json');
2883 * Test the api_direct_messages_destroy() function with a non-zero ID.
2885 * @expectedException Friendica\Network\HTTPException\BadRequestException
2887 public function testApiDirectMessagesDestroyWithId()
2889 $_REQUEST['id'] = 1;
2890 api_direct_messages_destroy('json');
2894 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2897 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2899 $_REQUEST['id'] = 1;
2900 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2901 $_GET['friendica_verbose'] = 'true';
2902 $result = api_direct_messages_destroy('json');
2903 $this->assertEquals(
2906 'result' => 'error',
2907 'message' => 'message id not in database'
2915 * Test the api_direct_messages_destroy() function with a non-zero ID.
2918 public function testApiDirectMessagesDestroyWithCorrectId()
2920 $this->markTestIncomplete('We need to add a dataset for this.');
2924 * Test the api_direct_messages_box() function.
2927 public function testApiDirectMessagesBoxWithSentbox()
2929 $_REQUEST['page'] = -1;
2930 $_REQUEST['max_id'] = 10;
2931 $result = api_direct_messages_box('json', 'sentbox', 'false');
2932 $this->assertArrayHasKey('direct_message', $result);
2936 * Test the api_direct_messages_box() function.
2939 public function testApiDirectMessagesBoxWithConversation()
2941 $result = api_direct_messages_box('json', 'conversation', 'false');
2942 $this->assertArrayHasKey('direct_message', $result);
2946 * Test the api_direct_messages_box() function.
2949 public function testApiDirectMessagesBoxWithAll()
2951 $result = api_direct_messages_box('json', 'all', 'false');
2952 $this->assertArrayHasKey('direct_message', $result);
2956 * Test the api_direct_messages_box() function.
2959 public function testApiDirectMessagesBoxWithInbox()
2961 $result = api_direct_messages_box('json', 'inbox', 'false');
2962 $this->assertArrayHasKey('direct_message', $result);
2966 * Test the api_direct_messages_box() function.
2969 public function testApiDirectMessagesBoxWithVerbose()
2971 $result = api_direct_messages_box('json', 'sentbox', 'true');
2972 $this->assertEquals(
2975 'result' => 'error',
2976 'message' => 'no mails available'
2984 * Test the api_direct_messages_box() function with a RSS result.
2987 public function testApiDirectMessagesBoxWithRss()
2989 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2990 $this->assertXml($result, 'direct-messages');
2994 * Test the api_direct_messages_box() function without an authenticated user.
2996 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2998 public function testApiDirectMessagesBoxWithUnallowedUser()
3000 $_SESSION['allow_api'] = false;
3001 $_GET['screen_name'] = $this->selfUser['nick'];
3002 api_direct_messages_box('json', 'sentbox', 'false');
3006 * Test the api_direct_messages_sentbox() function.
3009 public function testApiDirectMessagesSentbox()
3011 $result = api_direct_messages_sentbox('json');
3012 $this->assertArrayHasKey('direct_message', $result);
3016 * Test the api_direct_messages_inbox() function.
3019 public function testApiDirectMessagesInbox()
3021 $result = api_direct_messages_inbox('json');
3022 $this->assertArrayHasKey('direct_message', $result);
3026 * Test the api_direct_messages_all() function.
3029 public function testApiDirectMessagesAll()
3031 $result = api_direct_messages_all('json');
3032 $this->assertArrayHasKey('direct_message', $result);
3036 * Test the api_direct_messages_conversation() function.
3039 public function testApiDirectMessagesConversation()
3041 $result = api_direct_messages_conversation('json');
3042 $this->assertArrayHasKey('direct_message', $result);
3046 * Test the api_oauth_request_token() function.
3049 public function testApiOauthRequestToken()
3051 $this->markTestIncomplete('killme() kills phpunit as well');
3055 * Test the api_oauth_access_token() function.
3058 public function testApiOauthAccessToken()
3060 $this->markTestIncomplete('killme() kills phpunit as well');
3064 * Test the api_fr_photoalbum_delete() function.
3066 * @expectedException Friendica\Network\HTTPException\BadRequestException
3068 public function testApiFrPhotoalbumDelete()
3070 api_fr_photoalbum_delete('json');
3074 * Test the api_fr_photoalbum_delete() function with an album name.
3076 * @expectedException Friendica\Network\HTTPException\BadRequestException
3078 public function testApiFrPhotoalbumDeleteWithAlbum()
3080 $_REQUEST['album'] = 'album_name';
3081 api_fr_photoalbum_delete('json');
3085 * Test the api_fr_photoalbum_delete() function with an album name.
3088 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3090 $this->markTestIncomplete('We need to add a dataset for this.');
3094 * Test the api_fr_photoalbum_delete() function.
3096 * @expectedException Friendica\Network\HTTPException\BadRequestException
3098 public function testApiFrPhotoalbumUpdate()
3100 api_fr_photoalbum_update('json');
3104 * Test the api_fr_photoalbum_delete() function with an album name.
3106 * @expectedException Friendica\Network\HTTPException\BadRequestException
3108 public function testApiFrPhotoalbumUpdateWithAlbum()
3110 $_REQUEST['album'] = 'album_name';
3111 api_fr_photoalbum_update('json');
3115 * Test the api_fr_photoalbum_delete() function with an album name.
3117 * @expectedException Friendica\Network\HTTPException\BadRequestException
3119 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3121 $_REQUEST['album'] = 'album_name';
3122 $_REQUEST['album_new'] = 'album_name';
3123 api_fr_photoalbum_update('json');
3127 * Test the api_fr_photoalbum_update() function without an authenticated user.
3129 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3131 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3133 $_SESSION['authenticated'] = false;
3134 api_fr_photoalbum_update('json');
3138 * Test the api_fr_photoalbum_delete() function with an album name.
3141 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3143 $this->markTestIncomplete('We need to add a dataset for this.');
3147 * Test the api_fr_photos_list() function.
3150 public function testApiFrPhotosList()
3152 $result = api_fr_photos_list('json');
3153 $this->assertArrayHasKey('photo', $result);
3157 * Test the api_fr_photos_list() function without an authenticated user.
3159 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3161 public function testApiFrPhotosListWithoutAuthenticatedUser()
3163 $_SESSION['authenticated'] = false;
3164 api_fr_photos_list('json');
3168 * Test the api_fr_photo_create_update() function.
3170 * @expectedException Friendica\Network\HTTPException\BadRequestException
3172 public function testApiFrPhotoCreateUpdate()
3174 api_fr_photo_create_update('json');
3178 * Test the api_fr_photo_create_update() function without an authenticated user.
3180 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3182 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3184 $_SESSION['authenticated'] = false;
3185 api_fr_photo_create_update('json');
3189 * Test the api_fr_photo_create_update() function with an album name.
3191 * @expectedException Friendica\Network\HTTPException\BadRequestException
3193 public function testApiFrPhotoCreateUpdateWithAlbum()
3195 $_REQUEST['album'] = 'album_name';
3196 api_fr_photo_create_update('json');
3200 * Test the api_fr_photo_create_update() function with the update mode.
3203 public function testApiFrPhotoCreateUpdateWithUpdate()
3205 $this->markTestIncomplete('We need to create a dataset for this');
3209 * Test the api_fr_photo_create_update() function with an uploaded file.
3212 public function testApiFrPhotoCreateUpdateWithFile()
3214 $this->markTestIncomplete();
3218 * Test the api_fr_photo_delete() function.
3220 * @expectedException Friendica\Network\HTTPException\BadRequestException
3222 public function testApiFrPhotoDelete()
3224 api_fr_photo_delete('json');
3228 * Test the api_fr_photo_delete() function without an authenticated user.
3230 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3232 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3234 $_SESSION['authenticated'] = false;
3235 api_fr_photo_delete('json');
3239 * Test the api_fr_photo_delete() function with a photo ID.
3241 * @expectedException Friendica\Network\HTTPException\BadRequestException
3243 public function testApiFrPhotoDeleteWithPhotoId()
3245 $_REQUEST['photo_id'] = 1;
3246 api_fr_photo_delete('json');
3250 * Test the api_fr_photo_delete() function with a correct photo ID.
3253 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3255 $this->markTestIncomplete('We need to create a dataset for this.');
3259 * Test the api_fr_photo_detail() function.
3261 * @expectedException Friendica\Network\HTTPException\BadRequestException
3263 public function testApiFrPhotoDetail()
3265 api_fr_photo_detail('json');
3269 * Test the api_fr_photo_detail() function without an authenticated user.
3271 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3273 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3275 $_SESSION['authenticated'] = false;
3276 api_fr_photo_detail('json');
3280 * Test the api_fr_photo_detail() function with a photo ID.
3282 * @expectedException Friendica\Network\HTTPException\NotFoundException
3284 public function testApiFrPhotoDetailWithPhotoId()
3286 $_REQUEST['photo_id'] = 1;
3287 api_fr_photo_detail('json');
3291 * Test the api_fr_photo_detail() function with a correct photo ID.
3294 public function testApiFrPhotoDetailCorrectPhotoId()
3296 $this->markTestIncomplete('We need to create a dataset for this.');
3300 * Test the api_account_update_profile_image() function.
3302 * @expectedException Friendica\Network\HTTPException\BadRequestException
3304 public function testApiAccountUpdateProfileImage()
3306 api_account_update_profile_image('json');
3310 * Test the api_account_update_profile_image() function without an authenticated user.
3312 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3314 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3316 $_SESSION['authenticated'] = false;
3317 api_account_update_profile_image('json');
3321 * Test the api_account_update_profile_image() function with an uploaded file.
3323 * @expectedException Friendica\Network\HTTPException\BadRequestException
3325 public function testApiAccountUpdateProfileImageWithUpload()
3327 $this->markTestIncomplete();
3332 * Test the api_account_update_profile() function.
3335 public function testApiAccountUpdateProfile()
3337 $_POST['name'] = 'new_name';
3338 $_POST['description'] = 'new_description';
3339 $result = api_account_update_profile('json');
3340 // We can't use assertSelfUser() here because the user object is missing some properties.
3341 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3342 $this->assertEquals('DFRN', $result['user']['location']);
3343 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3344 $this->assertEquals('dfrn', $result['user']['network']);
3345 $this->assertEquals('new_name', $result['user']['name']);
3346 $this->assertEquals('new_description', $result['user']['description']);
3350 * Test the check_acl_input() function.
3353 public function testCheckAclInput()
3355 $result = check_acl_input('<aclstring>');
3356 // Where does this result come from?
3357 $this->assertEquals(1, $result);
3361 * Test the check_acl_input() function with an empty ACL string.
3364 public function testCheckAclInputWithEmptyAclString()
3366 $result = check_acl_input(' ');
3367 $this->assertFalse($result);
3371 * Test the save_media_to_database() function.
3374 public function testSaveMediaToDatabase()
3376 $this->markTestIncomplete();
3380 * Test the post_photo_item() function.
3383 public function testPostPhotoItem()
3385 $this->markTestIncomplete();
3389 * Test the prepare_photo_data() function.
3392 public function testPreparePhotoData()
3394 $this->markTestIncomplete();
3398 * Test the api_friendica_remoteauth() function.
3400 * @expectedException Friendica\Network\HTTPException\BadRequestException
3402 public function testApiFriendicaRemoteauth()
3404 api_friendica_remoteauth();
3408 * Test the api_friendica_remoteauth() function with an URL.
3410 * @expectedException Friendica\Network\HTTPException\BadRequestException
3412 public function testApiFriendicaRemoteauthWithUrl()
3414 $_GET['url'] = 'url';
3415 $_GET['c_url'] = 'url';
3416 api_friendica_remoteauth();
3420 * Test the api_friendica_remoteauth() function with a correct URL.
3423 public function testApiFriendicaRemoteauthWithCorrectUrl()
3425 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3426 $_GET['url'] = 'url';
3427 $_GET['c_url'] = $this->selfUser['nurl'];
3428 api_friendica_remoteauth();
3432 * Test the api_share_as_retweet() function.
3435 public function testApiShareAsRetweet()
3437 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3438 $result = api_share_as_retweet($item);
3439 $this->assertFalse($result);
3443 * Test the api_share_as_retweet() function with a valid item.
3446 public function testApiShareAsRetweetWithValidItem()
3448 $this->markTestIncomplete();
3452 * Test the api_get_nick() function.
3455 public function testApiGetNick()
3457 $result = api_get_nick($this->otherUser['nurl']);
3458 $this->assertEquals('othercontact', $result);
3462 * Test the api_get_nick() function with a wrong URL.
3465 public function testApiGetNickWithWrongUrl()
3467 $result = api_get_nick('wrong_url');
3468 $this->assertFalse($result);
3472 * Test the api_in_reply_to() function.
3475 public function testApiInReplyTo()
3477 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3478 $this->assertArrayHasKey('status_id', $result);
3479 $this->assertArrayHasKey('user_id', $result);
3480 $this->assertArrayHasKey('status_id_str', $result);
3481 $this->assertArrayHasKey('user_id_str', $result);
3482 $this->assertArrayHasKey('screen_name', $result);
3486 * Test the api_in_reply_to() function with a valid item.
3489 public function testApiInReplyToWithValidItem()
3491 $this->markTestIncomplete();
3495 * Test the api_clean_plain_items() function.
3498 public function testApiCleanPlainItems()
3500 $_REQUEST['include_entities'] = 'true';
3501 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3502 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3506 * Test the api_clean_attachments() function.
3509 public function testApiCleanAttachments()
3511 $this->markTestIncomplete();
3515 * Test the api_best_nickname() function.
3518 public function testApiBestNickname()
3521 $result = api_best_nickname($contacts);
3522 $this->assertNull($result);
3526 * Test the api_best_nickname() function with contacts.
3529 public function testApiBestNicknameWithContacts()
3531 $this->markTestIncomplete();
3535 * Test the api_friendica_group_show() function.
3538 public function testApiFriendicaGroupShow()
3540 $this->markTestIncomplete();
3544 * Test the api_friendica_group_delete() function.
3547 public function testApiFriendicaGroupDelete()
3549 $this->markTestIncomplete();
3553 * Test the api_lists_destroy() function.
3556 public function testApiListsDestroy()
3558 $this->markTestIncomplete();
3562 * Test the group_create() function.
3565 public function testGroupCreate()
3567 $this->markTestIncomplete();
3571 * Test the api_friendica_group_create() function.
3574 public function testApiFriendicaGroupCreate()
3576 $this->markTestIncomplete();
3580 * Test the api_lists_create() function.
3583 public function testApiListsCreate()
3585 $this->markTestIncomplete();
3589 * Test the api_friendica_group_update() function.
3592 public function testApiFriendicaGroupUpdate()
3594 $this->markTestIncomplete();
3598 * Test the api_lists_update() function.
3601 public function testApiListsUpdate()
3603 $this->markTestIncomplete();
3607 * Test the api_friendica_activity() function.
3610 public function testApiFriendicaActivity()
3612 $this->markTestIncomplete();
3616 * Test the api_friendica_notification() function.
3618 * @expectedException Friendica\Network\HTTPException\BadRequestException
3620 public function testApiFriendicaNotification()
3622 api_friendica_notification('json');
3626 * Test the api_friendica_notification() function without an authenticated user.
3628 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3630 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3632 $_SESSION['authenticated'] = false;
3633 api_friendica_notification('json');
3637 * Test the api_friendica_notification() function with an argument count.
3640 public function testApiFriendicaNotificationWithArgumentCount()
3642 $this->app->argv = ['api', 'friendica', 'notification'];
3643 $this->app->argc = count($this->app->argv);
3644 $result = api_friendica_notification('json');
3645 $this->assertEquals(['note' => false], $result);
3649 * Test the api_friendica_notification() function with an XML result.
3652 public function testApiFriendicaNotificationWithXmlResult()
3654 $this->app->argv = ['api', 'friendica', 'notification'];
3655 $this->app->argc = count($this->app->argv);
3656 $result = api_friendica_notification('xml');
3657 $this->assertXml($result, 'notes');
3661 * Test the api_friendica_notification_seen() function.
3664 public function testApiFriendicaNotificationSeen()
3666 $this->markTestIncomplete();
3670 * Test the api_friendica_direct_messages_setseen() function.
3673 public function testApiFriendicaDirectMessagesSetseen()
3675 $this->markTestIncomplete();
3679 * Test the api_friendica_direct_messages_search() function.
3682 public function testApiFriendicaDirectMessagesSearch()
3684 $this->markTestIncomplete();
3688 * Test the api_friendica_profile_show() function.
3691 public function testApiFriendicaProfileShow()
3693 $result = api_friendica_profile_show('json');
3694 // We can't use assertSelfUser() here because the user object is missing some properties.
3695 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3696 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3697 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3698 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3699 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3700 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3701 $this->assertFalse($result['$result']['multi_profiles']);
3705 * Test the api_friendica_profile_show() function with a profile ID.
3708 public function testApiFriendicaProfileShowWithProfileId()
3710 $this->markTestIncomplete('We need to add a dataset for this.');
3714 * Test the api_friendica_profile_show() function with a wrong profile ID.
3716 * @expectedException Friendica\Network\HTTPException\BadRequestException
3718 public function testApiFriendicaProfileShowWithWrongProfileId()
3720 $_REQUEST['profile_id'] = 666;
3721 api_friendica_profile_show('json');
3725 * Test the api_friendica_profile_show() function without an authenticated user.
3727 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3729 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3731 $_SESSION['authenticated'] = false;
3732 api_friendica_profile_show('json');
3736 * Test the api_saved_searches_list() function.
3739 public function testApiSavedSearchesList()
3741 $result = api_saved_searches_list('json');
3742 $this->assertEquals(1, $result['terms'][0]['id']);
3743 $this->assertEquals(1, $result['terms'][0]['id_str']);
3744 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3745 $this->assertEquals('Saved search', $result['terms'][0]['query']);