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\BaseURL;
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
39 protected $friendUser;
43 protected $wrongUserId;
46 * Create variables used by tests.
48 public function setUp()
50 $configModel = new \Friendica\Model\Config\Config(self::$dba);
51 $config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
52 Factory\ConfigFactory::createPConfig(self::$configCache, new Config\Cache\PConfigCache());
53 $logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
54 $baseUrl = new BaseURL($config, $_SERVER);
55 $router = new App\Router();
56 $this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
60 // User data that the test database is populated with
63 'name' => 'Self contact',
64 'nick' => 'selfcontact',
65 'nurl' => 'http://localhost/profile/selfcontact'
69 'name' => 'Friend contact',
70 'nick' => 'friendcontact',
71 'nurl' => 'http://localhost/profile/friendcontact'
75 'name' => 'othercontact',
76 'nick' => 'othercontact',
77 'nurl' => 'http://localhost/profile/othercontact'
80 // User ID that we know is not in the database
81 $this->wrongUserId = 666;
83 // Most API require login so we force the session
86 'authenticated' => true,
87 'uid' => $this->selfUser['id']
90 Config::set('system', 'url', 'http://localhost');
91 Config::set('system', 'hostname', 'localhost');
92 Config::set('system', 'worker_dont_fork', true);
95 Config::set('config', 'hostname', 'localhost');
96 Config::set('system', 'throttle_limit_day', 100);
97 Config::set('system', 'throttle_limit_week', 100);
98 Config::set('system', 'throttle_limit_month', 100);
99 Config::set('system', 'theme', 'system_theme');
103 * Cleanup variables used by tests.
105 protected function tearDown()
109 $this->app->argc = 1;
110 $this->app->argv = ['home'];
114 * Assert that an user array contains expected keys.
115 * @param array $user User array
118 private function assertSelfUser(array $user)
120 $this->assertEquals($this->selfUser['id'], $user['uid']);
121 $this->assertEquals($this->selfUser['id'], $user['cid']);
122 $this->assertEquals(1, $user['self']);
123 $this->assertEquals('DFRN', $user['location']);
124 $this->assertEquals($this->selfUser['name'], $user['name']);
125 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
126 $this->assertEquals('dfrn', $user['network']);
127 $this->assertTrue($user['verified']);
131 * Assert that an user array contains expected keys.
132 * @param array $user User array
135 private function assertOtherUser(array $user)
137 $this->assertEquals($this->otherUser['id'], $user['id']);
138 $this->assertEquals($this->otherUser['id'], $user['id_str']);
139 $this->assertEquals(0, $user['self']);
140 $this->assertEquals($this->otherUser['name'], $user['name']);
141 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
142 $this->assertFalse($user['verified']);
146 * Assert that a status array contains expected keys.
147 * @param array $status Status array
150 private function assertStatus(array $status)
152 $this->assertInternalType('string', $status['text']);
153 $this->assertInternalType('int', $status['id']);
154 // We could probably do more checks here.
158 * Assert that a list array contains expected keys.
159 * @param array $list List array
162 private function assertList(array $list)
164 $this->assertInternalType('string', $list['name']);
165 $this->assertInternalType('int', $list['id']);
166 $this->assertInternalType('string', $list['id_str']);
167 $this->assertContains($list['mode'], ['public', 'private']);
168 // We could probably do more checks here.
172 * Assert that the string is XML and contain the root element.
173 * @param string $result XML string
174 * @param string $root_element Root element name
177 private function assertXml($result, $root_element)
179 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
180 $this->assertContains('<'.$root_element, $result);
181 // We could probably do more checks here.
185 * Get the path to a temporary empty PNG image.
186 * @return string Path
188 private function getTempImage()
190 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
194 // Empty 1x1 px PNG image
195 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
203 * Test the api_user() function.
206 public function testApiUser()
208 $this->assertEquals($this->selfUser['id'], api_user());
212 * Test the api_user() function with an unallowed user.
215 public function testApiUserWithUnallowedUser()
217 $_SESSION = ['allow_api' => false];
218 $this->assertEquals(false, api_user());
222 * Test the api_source() function.
225 public function testApiSource()
227 $this->assertEquals('api', api_source());
231 * Test the api_source() function with a Twidere user agent.
234 public function testApiSourceWithTwidere()
236 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
237 $this->assertEquals('Twidere', api_source());
241 * Test the api_source() function with a GET parameter.
244 public function testApiSourceWithGet()
246 $_GET['source'] = 'source_name';
247 $this->assertEquals('source_name', api_source());
251 * Test the api_date() function.
254 public function testApiDate()
256 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
260 * Test the api_register_func() function.
263 public function testApiRegisterFunc()
275 $this->assertTrue($API['api_path']['auth']);
276 $this->assertEquals('method', $API['api_path']['method']);
277 $this->assertTrue(is_callable($API['api_path']['func']));
281 * Test the api_login() function without any login.
283 * @runInSeparateProcess
284 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
286 public function testApiLoginWithoutLogin()
288 api_login($this->app);
292 * Test the api_login() function with a bad login.
294 * @runInSeparateProcess
295 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
297 public function testApiLoginWithBadLogin()
299 $_SERVER['PHP_AUTH_USER'] = 'user@server';
300 api_login($this->app);
304 * Test the api_login() function with oAuth.
307 public function testApiLoginWithOauth()
309 $this->markTestIncomplete('Can we test this easily?');
313 * Test the api_login() function with authentication provided by an addon.
316 public function testApiLoginWithAddonAuth()
318 $this->markTestIncomplete('Can we test this easily?');
322 * Test the api_login() function with a correct login.
324 * @runInSeparateProcess
326 public function testApiLoginWithCorrectLogin()
328 $_SERVER['PHP_AUTH_USER'] = 'Test user';
329 $_SERVER['PHP_AUTH_PW'] = 'password';
330 api_login($this->app);
334 * Test the api_login() function with a remote user.
336 * @runInSeparateProcess
337 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
339 public function testApiLoginWithRemoteUser()
341 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
342 api_login($this->app);
346 * Test the api_check_method() function.
349 public function testApiCheckMethod()
351 $this->assertFalse(api_check_method('method'));
355 * Test the api_check_method() function with a correct method.
358 public function testApiCheckMethodWithCorrectMethod()
360 $_SERVER['REQUEST_METHOD'] = 'method';
361 $this->assertTrue(api_check_method('method'));
365 * Test the api_check_method() function with a wildcard.
368 public function testApiCheckMethodWithWildcard()
370 $this->assertTrue(api_check_method('*'));
374 * Test the api_call() function.
376 * @runInSeparateProcess
378 public function testApiCall()
382 'method' => 'method',
383 'func' => function () {
384 return ['data' => ['some_data']];
387 $_SERVER['REQUEST_METHOD'] = 'method';
388 $_GET['callback'] = 'callback_name';
390 $this->app->query_string = 'api_path';
392 'callback_name(["some_data"])',
398 * Test the api_call() function with the profiled enabled.
400 * @runInSeparateProcess
402 public function testApiCallWithProfiler()
406 'method' => 'method',
407 'func' => function () {
408 return ['data' => ['some_data']];
411 $_SERVER['REQUEST_METHOD'] = 'method';
412 Config::set('system', 'profiler', true);
413 Config::set('rendertime', 'callstack', true);
414 $this->app->callstack = [
415 'database' => ['some_function' => 200],
416 'database_write' => ['some_function' => 200],
417 'cache' => ['some_function' => 200],
418 'cache_write' => ['some_function' => 200],
419 'network' => ['some_function' => 200]
422 $this->app->query_string = 'api_path';
430 * Test the api_call() function without any result.
432 * @runInSeparateProcess
434 public function testApiCallWithNoResult()
438 'method' => 'method',
439 'func' => function () {
443 $_SERVER['REQUEST_METHOD'] = 'method';
445 $this->app->query_string = 'api_path';
447 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
453 * Test the api_call() function with an unimplemented API.
455 * @runInSeparateProcess
457 public function testApiCallWithUninplementedApi()
460 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
466 * Test the api_call() function with a JSON result.
468 * @runInSeparateProcess
470 public function testApiCallWithJson()
474 'method' => 'method',
475 'func' => function () {
476 return ['data' => ['some_data']];
479 $_SERVER['REQUEST_METHOD'] = 'method';
481 $this->app->query_string = 'api_path.json';
489 * Test the api_call() function with an XML result.
491 * @runInSeparateProcess
493 public function testApiCallWithXml()
497 'method' => 'method',
498 'func' => function () {
502 $_SERVER['REQUEST_METHOD'] = 'method';
504 $this->app->query_string = 'api_path.xml';
512 * Test the api_call() function with an RSS result.
514 * @runInSeparateProcess
516 public function testApiCallWithRss()
520 'method' => 'method',
521 'func' => function () {
525 $_SERVER['REQUEST_METHOD'] = 'method';
527 $this->app->query_string = 'api_path.rss';
529 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
536 * Test the api_call() function with an Atom result.
538 * @runInSeparateProcess
540 public function testApiCallWithAtom()
544 'method' => 'method',
545 'func' => function () {
549 $_SERVER['REQUEST_METHOD'] = 'method';
551 $this->app->query_string = 'api_path.atom';
553 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
560 * Test the api_call() function with an unallowed method.
562 * @runInSeparateProcess
564 public function testApiCallWithWrongMethod()
567 $API['api_path'] = ['method' => 'method'];
569 $this->app->query_string = 'api_path';
571 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
577 * Test the api_call() function with an unauthorized user.
579 * @runInSeparateProcess
581 public function testApiCallWithWrongAuth()
585 'method' => 'method',
588 $_SERVER['REQUEST_METHOD'] = 'method';
589 $_SESSION['authenticated'] = false;
591 $this->app->query_string = 'api_path';
593 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
599 * Test the api_error() function with a JSON result.
601 * @runInSeparateProcess
603 public function testApiErrorWithJson()
606 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
607 api_error('json', new HTTPException\OKException('error_message'))
612 * Test the api_error() function with an XML result.
614 * @runInSeparateProcess
616 public function testApiErrorWithXml()
619 '<?xml version="1.0"?>'."\n".
620 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
621 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
622 'xmlns:georss="http://www.georss.org/georss">'."\n".
623 ' <error>error_message</error>'."\n".
624 ' <code>200 OK</code>'."\n".
627 api_error('xml', new HTTPException\OKException('error_message'))
632 * Test the api_error() function with an RSS result.
634 * @runInSeparateProcess
636 public function testApiErrorWithRss()
639 '<?xml version="1.0"?>'."\n".
640 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
641 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
642 'xmlns:georss="http://www.georss.org/georss">'."\n".
643 ' <error>error_message</error>'."\n".
644 ' <code>200 OK</code>'."\n".
647 api_error('rss', new HTTPException\OKException('error_message'))
652 * Test the api_error() function with an Atom result.
654 * @runInSeparateProcess
656 public function testApiErrorWithAtom()
659 '<?xml version="1.0"?>'."\n".
660 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
661 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
662 'xmlns:georss="http://www.georss.org/georss">'."\n".
663 ' <error>error_message</error>'."\n".
664 ' <code>200 OK</code>'."\n".
667 api_error('atom', new HTTPException\OKException('error_message'))
672 * Test the api_rss_extra() function.
675 public function testApiRssExtra()
677 $user_info = ['url' => 'user_url', 'lang' => 'en'];
678 $result = api_rss_extra($this->app, [], $user_info);
679 $this->assertEquals($user_info, $result['$user']);
680 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
681 $this->assertArrayHasKey('self', $result['$rss']);
682 $this->assertArrayHasKey('base', $result['$rss']);
683 $this->assertArrayHasKey('updated', $result['$rss']);
684 $this->assertArrayHasKey('atom_updated', $result['$rss']);
685 $this->assertArrayHasKey('language', $result['$rss']);
686 $this->assertArrayHasKey('logo', $result['$rss']);
690 * Test the api_rss_extra() function without any user info.
692 * @runInSeparateProcess
694 public function testApiRssExtraWithoutUserInfo()
696 $result = api_rss_extra($this->app, [], null);
697 $this->assertInternalType('array', $result['$user']);
698 $this->assertArrayHasKey('alternate', $result['$rss']);
699 $this->assertArrayHasKey('self', $result['$rss']);
700 $this->assertArrayHasKey('base', $result['$rss']);
701 $this->assertArrayHasKey('updated', $result['$rss']);
702 $this->assertArrayHasKey('atom_updated', $result['$rss']);
703 $this->assertArrayHasKey('language', $result['$rss']);
704 $this->assertArrayHasKey('logo', $result['$rss']);
708 * Test the api_unique_id_to_nurl() function.
711 public function testApiUniqueIdToNurl()
713 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
717 * Test the api_unique_id_to_nurl() function with a correct ID.
720 public function testApiUniqueIdToNurlWithCorrectId()
722 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
726 * Test the api_get_user() function.
728 * @runInSeparateProcess
730 public function testApiGetUser()
732 $user = api_get_user($this->app);
733 $this->assertSelfUser($user);
734 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
735 $this->assertEquals('6fdbe8', $user['profile_link_color']);
736 $this->assertEquals('ededed', $user['profile_background_color']);
740 * Test the api_get_user() function with a Frio schema.
742 * @runInSeparateProcess
744 public function testApiGetUserWithFrioSchema()
746 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
747 $user = api_get_user($this->app);
748 $this->assertSelfUser($user);
749 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
750 $this->assertEquals('6fdbe8', $user['profile_link_color']);
751 $this->assertEquals('ededed', $user['profile_background_color']);
755 * Test the api_get_user() function with a custom Frio schema.
757 * @runInSeparateProcess
759 public function testApiGetUserWithCustomFrioSchema()
761 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
762 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
763 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
764 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
765 $user = api_get_user($this->app);
766 $this->assertSelfUser($user);
767 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
768 $this->assertEquals('123456', $user['profile_link_color']);
769 $this->assertEquals('123456', $user['profile_background_color']);
773 * Test the api_get_user() function with an empty Frio schema.
775 * @runInSeparateProcess
777 public function testApiGetUserWithEmptyFrioSchema()
779 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
780 $user = api_get_user($this->app);
781 $this->assertSelfUser($user);
782 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
783 $this->assertEquals('6fdbe8', $user['profile_link_color']);
784 $this->assertEquals('ededed', $user['profile_background_color']);
788 * Test the api_get_user() function with an user that is not allowed to use the API.
790 * @runInSeparateProcess
792 public function testApiGetUserWithoutApiUser()
794 $_SERVER['PHP_AUTH_USER'] = 'Test user';
795 $_SERVER['PHP_AUTH_PW'] = 'password';
796 $_SESSION['allow_api'] = false;
797 $this->assertFalse(api_get_user($this->app));
801 * Test the api_get_user() function with an user ID in a GET parameter.
803 * @runInSeparateProcess
805 public function testApiGetUserWithGetId()
807 $_GET['user_id'] = $this->otherUser['id'];
808 $this->assertOtherUser(api_get_user($this->app));
812 * Test the api_get_user() function with a wrong user ID in a GET parameter.
814 * @runInSeparateProcess
815 * @expectedException Friendica\Network\HTTPException\BadRequestException
817 public function testApiGetUserWithWrongGetId()
819 $_GET['user_id'] = $this->wrongUserId;
820 $this->assertOtherUser(api_get_user($this->app));
824 * Test the api_get_user() function with an user name in a GET parameter.
826 * @runInSeparateProcess
828 public function testApiGetUserWithGetName()
830 $_GET['screen_name'] = $this->selfUser['nick'];
831 $this->assertSelfUser(api_get_user($this->app));
835 * Test the api_get_user() function with a profile URL in a GET parameter.
837 * @runInSeparateProcess
839 public function testApiGetUserWithGetUrl()
841 $_GET['profileurl'] = $this->selfUser['nurl'];
842 $this->assertSelfUser(api_get_user($this->app));
846 * Test the api_get_user() function with an user ID in the API path.
848 * @runInSeparateProcess
850 public function testApiGetUserWithNumericCalledApi()
853 $called_api = ['api_path'];
854 $this->app->argv[1] = $this->otherUser['id'].'.json';
855 $this->assertOtherUser(api_get_user($this->app));
859 * Test the api_get_user() function with the $called_api global variable.
861 * @runInSeparateProcess
863 public function testApiGetUserWithCalledApi()
866 $called_api = ['api', 'api_path'];
867 $this->assertSelfUser(api_get_user($this->app));
871 * Test the api_get_user() function with a valid user.
873 * @runInSeparateProcess
875 public function testApiGetUserWithCorrectUser()
877 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
881 * Test the api_get_user() function with a wrong user ID.
883 * @runInSeparateProcess
884 * @expectedException Friendica\Network\HTTPException\BadRequestException
886 public function testApiGetUserWithWrongUser()
888 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
892 * Test the api_get_user() function with a 0 user ID.
894 * @runInSeparateProcess
896 public function testApiGetUserWithZeroUser()
898 $this->assertSelfUser(api_get_user($this->app, 0));
902 * Test the api_item_get_user() function.
904 * @runInSeparateProcess
906 public function testApiItemGetUser()
908 $users = api_item_get_user($this->app, []);
909 $this->assertSelfUser($users[0]);
913 * Test the api_item_get_user() function with a different item parent.
916 public function testApiItemGetUserWithDifferentParent()
918 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
919 $this->assertSelfUser($users[0]);
920 $this->assertEquals($users[0], $users[1]);
924 * Test the api_walk_recursive() function.
927 public function testApiWalkRecursive()
935 // Should we test this with a callback that actually does something?
943 * Test the api_walk_recursive() function with an array.
946 public function testApiWalkRecursiveWithArray()
948 $array = [['item1'], ['item2']];
954 // Should we test this with a callback that actually does something?
962 * Test the api_reformat_xml() function.
965 public function testApiReformatXml()
969 $this->assertTrue(api_reformat_xml($item, $key));
970 $this->assertEquals('true', $item);
974 * Test the api_reformat_xml() function with a statusnet_api key.
977 public function testApiReformatXmlWithStatusnetKey()
980 $key = 'statusnet_api';
981 $this->assertTrue(api_reformat_xml($item, $key));
982 $this->assertEquals('statusnet:api', $key);
986 * Test the api_reformat_xml() function with a friendica_api key.
989 public function testApiReformatXmlWithFriendicaKey()
992 $key = 'friendica_api';
993 $this->assertTrue(api_reformat_xml($item, $key));
994 $this->assertEquals('friendica:api', $key);
998 * Test the api_create_xml() function.
1001 public function testApiCreateXml()
1003 $this->assertEquals(
1004 '<?xml version="1.0"?>'."\n".
1005 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1006 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1007 'xmlns:georss="http://www.georss.org/georss">'."\n".
1008 ' <data>some_data</data>'."\n".
1009 '</root_element>'."\n",
1010 api_create_xml(['data' => ['some_data']], 'root_element')
1015 * Test the api_create_xml() function without any XML namespace.
1018 public function testApiCreateXmlWithoutNamespaces()
1020 $this->assertEquals(
1021 '<?xml version="1.0"?>'."\n".
1023 ' <data>some_data</data>'."\n".
1025 api_create_xml(['data' => ['some_data']], 'ok')
1030 * Test the api_format_data() function.
1033 public function testApiFormatData()
1035 $data = ['some_data'];
1036 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1040 * Test the api_format_data() function with an XML result.
1043 public function testApiFormatDataWithXml()
1045 $this->assertEquals(
1046 '<?xml version="1.0"?>'."\n".
1047 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1048 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1049 'xmlns:georss="http://www.georss.org/georss">'."\n".
1050 ' <data>some_data</data>'."\n".
1051 '</root_element>'."\n",
1052 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1057 * Test the api_account_verify_credentials() function.
1060 public function testApiAccountVerifyCredentials()
1062 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1066 * Test the api_account_verify_credentials() function without an authenticated user.
1068 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1070 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1072 $_SESSION['authenticated'] = false;
1073 api_account_verify_credentials('json');
1077 * Test the requestdata() function.
1080 public function testRequestdata()
1082 $this->assertNull(requestdata('variable_name'));
1086 * Test the requestdata() function with a POST parameter.
1089 public function testRequestdataWithPost()
1091 $_POST['variable_name'] = 'variable_value';
1092 $this->assertEquals('variable_value', requestdata('variable_name'));
1096 * Test the requestdata() function with a GET parameter.
1099 public function testRequestdataWithGet()
1101 $_GET['variable_name'] = 'variable_value';
1102 $this->assertEquals('variable_value', requestdata('variable_name'));
1106 * Test the api_statuses_mediap() function.
1109 public function testApiStatusesMediap()
1111 $this->app->argc = 2;
1119 'tmp_name' => $this->getTempImage(),
1120 'name' => 'spacer.png',
1121 'type' => 'image/png'
1124 $_GET['status'] = '<b>Status content</b>';
1126 $result = api_statuses_mediap('json');
1127 $this->assertStatus($result['status']);
1131 * Test the api_statuses_mediap() function without an authenticated user.
1133 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1135 public function testApiStatusesMediapWithoutAuthenticatedUser()
1137 $_SESSION['authenticated'] = false;
1138 api_statuses_mediap('json');
1142 * Test the api_statuses_update() function.
1145 public function testApiStatusesUpdate()
1147 $_GET['status'] = 'Status content #friendica';
1148 $_GET['in_reply_to_status_id'] = -1;
1157 'tmp_name' => $this->getTempImage(),
1158 'name' => 'spacer.png',
1159 'type' => 'image/png'
1163 $result = api_statuses_update('json');
1164 $this->assertStatus($result['status']);
1168 * Test the api_statuses_update() function with an HTML status.
1171 public function testApiStatusesUpdateWithHtml()
1173 $_GET['htmlstatus'] = '<b>Status content</b>';
1175 $result = api_statuses_update('json');
1176 $this->assertStatus($result['status']);
1180 * Test the api_statuses_update() function without an authenticated user.
1182 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1184 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1186 $_SESSION['authenticated'] = false;
1187 api_statuses_update('json');
1191 * Test the api_statuses_update() function with a parent status.
1194 public function testApiStatusesUpdateWithParent()
1196 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1200 * Test the api_statuses_update() function with a media_ids parameter.
1203 public function testApiStatusesUpdateWithMediaIds()
1205 $this->markTestIncomplete();
1209 * Test the api_statuses_update() function with the throttle limit reached.
1212 public function testApiStatusesUpdateWithDayThrottleReached()
1214 $this->markTestIncomplete();
1218 * Test the api_media_upload() function.
1220 * @expectedException Friendica\Network\HTTPException\BadRequestException
1222 public function testApiMediaUpload()
1228 * Test the api_media_upload() function without an authenticated user.
1230 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1232 public function testApiMediaUploadWithoutAuthenticatedUser()
1234 $_SESSION['authenticated'] = false;
1239 * Test the api_media_upload() function with an invalid uploaded media.
1241 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1243 public function testApiMediaUploadWithMedia()
1248 'tmp_name' => 'tmp_name'
1255 * Test the api_media_upload() function with an valid uploaded media.
1258 public function testApiMediaUploadWithValidMedia()
1266 'tmp_name' => $this->getTempImage(),
1267 'name' => 'spacer.png',
1268 'type' => 'image/png'
1274 $result = api_media_upload();
1275 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1276 $this->assertEquals(1, $result['media']['image']['w']);
1277 $this->assertEquals(1, $result['media']['image']['h']);
1278 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1282 * Test the api_status_show() function.
1284 public function testApiStatusShowWithJson()
1286 $result = api_status_show('json', 1);
1287 $this->assertStatus($result['status']);
1291 * Test the api_status_show() function with an XML result.
1293 public function testApiStatusShowWithXml()
1295 $result = api_status_show('xml', 1);
1296 $this->assertXml($result, 'statuses');
1300 * Test the api_get_last_status() function
1302 public function testApiGetLastStatus()
1304 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1306 $this->assertNotNull($item);
1310 * Test the api_users_show() function.
1313 public function testApiUsersShow()
1315 $result = api_users_show('json');
1316 // We can't use assertSelfUser() here because the user object is missing some properties.
1317 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1318 $this->assertEquals('DFRN', $result['user']['location']);
1319 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1320 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1321 $this->assertEquals('dfrn', $result['user']['network']);
1322 $this->assertTrue($result['user']['verified']);
1326 * Test the api_users_show() function with an XML result.
1329 public function testApiUsersShowWithXml()
1331 $result = api_users_show('xml');
1332 $this->assertXml($result, 'statuses');
1336 * Test the api_users_search() function.
1339 public function testApiUsersSearch()
1341 $_GET['q'] = 'othercontact';
1342 $result = api_users_search('json');
1343 $this->assertOtherUser($result['users'][0]);
1347 * Test the api_users_search() function with an XML result.
1350 public function testApiUsersSearchWithXml()
1352 $_GET['q'] = 'othercontact';
1353 $result = api_users_search('xml');
1354 $this->assertXml($result, 'users');
1358 * Test the api_users_search() function without a GET q parameter.
1360 * @expectedException Friendica\Network\HTTPException\BadRequestException
1362 public function testApiUsersSearchWithoutQuery()
1364 api_users_search('json');
1368 * Test the api_users_lookup() function.
1370 * @expectedException Friendica\Network\HTTPException\NotFoundException
1372 public function testApiUsersLookup()
1374 api_users_lookup('json');
1378 * Test the api_users_lookup() function with an user ID.
1381 public function testApiUsersLookupWithUserId()
1383 $_REQUEST['user_id'] = $this->otherUser['id'];
1384 $result = api_users_lookup('json');
1385 $this->assertOtherUser($result['users'][0]);
1389 * Test the api_search() function.
1392 public function testApiSearch()
1394 $_REQUEST['q'] = 'reply';
1395 $_REQUEST['max_id'] = 10;
1396 $result = api_search('json');
1397 foreach ($result['status'] as $status) {
1398 $this->assertStatus($status);
1399 $this->assertContains('reply', $status['text'], null, true);
1404 * Test the api_search() function a count parameter.
1407 public function testApiSearchWithCount()
1409 $_REQUEST['q'] = 'reply';
1410 $_REQUEST['count'] = 20;
1411 $result = api_search('json');
1412 foreach ($result['status'] as $status) {
1413 $this->assertStatus($status);
1414 $this->assertContains('reply', $status['text'], null, true);
1419 * Test the api_search() function with an rpp parameter.
1422 public function testApiSearchWithRpp()
1424 $_REQUEST['q'] = 'reply';
1425 $_REQUEST['rpp'] = 20;
1426 $result = api_search('json');
1427 foreach ($result['status'] as $status) {
1428 $this->assertStatus($status);
1429 $this->assertContains('reply', $status['text'], null, true);
1434 * Test the api_search() function with an q parameter contains hashtag.
1437 public function testApiSearchWithHashtag()
1439 $_REQUEST['q'] = '%23friendica';
1440 $result = api_search('json');
1441 foreach ($result['status'] as $status) {
1442 $this->assertStatus($status);
1443 $this->assertContains('#friendica', $status['text'], null, true);
1448 * Test the api_search() function with an exclude_replies parameter.
1451 public function testApiSearchWithExcludeReplies()
1453 $_REQUEST['max_id'] = 10;
1454 $_REQUEST['exclude_replies'] = true;
1455 $_REQUEST['q'] = 'friendica';
1456 $result = api_search('json');
1457 foreach ($result['status'] as $status) {
1458 $this->assertStatus($status);
1463 * Test the api_search() function without an authenticated user.
1465 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1467 public function testApiSearchWithUnallowedUser()
1469 $_SESSION['allow_api'] = false;
1470 $_GET['screen_name'] = $this->selfUser['nick'];
1475 * Test the api_search() function without any GET query parameter.
1477 * @expectedException Friendica\Network\HTTPException\BadRequestException
1479 public function testApiSearchWithoutQuery()
1485 * Test the api_statuses_home_timeline() function.
1488 public function testApiStatusesHomeTimeline()
1490 $_REQUEST['max_id'] = 10;
1491 $_REQUEST['exclude_replies'] = true;
1492 $_REQUEST['conversation_id'] = 1;
1493 $result = api_statuses_home_timeline('json');
1494 $this->assertNotEmpty($result['status']);
1495 foreach ($result['status'] as $status) {
1496 $this->assertStatus($status);
1501 * Test the api_statuses_home_timeline() function with a negative page parameter.
1504 public function testApiStatusesHomeTimelineWithNegativePage()
1506 $_REQUEST['page'] = -2;
1507 $result = api_statuses_home_timeline('json');
1508 $this->assertNotEmpty($result['status']);
1509 foreach ($result['status'] as $status) {
1510 $this->assertStatus($status);
1515 * Test the api_statuses_home_timeline() with an unallowed user.
1517 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1519 public function testApiStatusesHomeTimelineWithUnallowedUser()
1521 $_SESSION['allow_api'] = false;
1522 $_GET['screen_name'] = $this->selfUser['nick'];
1523 api_statuses_home_timeline('json');
1527 * Test the api_statuses_home_timeline() function with an RSS result.
1530 public function testApiStatusesHomeTimelineWithRss()
1532 $result = api_statuses_home_timeline('rss');
1533 $this->assertXml($result, 'statuses');
1537 * Test the api_statuses_public_timeline() function.
1540 public function testApiStatusesPublicTimeline()
1542 $_REQUEST['max_id'] = 10;
1543 $_REQUEST['conversation_id'] = 1;
1544 $result = api_statuses_public_timeline('json');
1545 $this->assertNotEmpty($result['status']);
1546 foreach ($result['status'] as $status) {
1547 $this->assertStatus($status);
1552 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1555 public function testApiStatusesPublicTimelineWithExcludeReplies()
1557 $_REQUEST['max_id'] = 10;
1558 $_REQUEST['exclude_replies'] = true;
1559 $result = api_statuses_public_timeline('json');
1560 $this->assertNotEmpty($result['status']);
1561 foreach ($result['status'] as $status) {
1562 $this->assertStatus($status);
1567 * Test the api_statuses_public_timeline() function with a negative page parameter.
1570 public function testApiStatusesPublicTimelineWithNegativePage()
1572 $_REQUEST['page'] = -2;
1573 $result = api_statuses_public_timeline('json');
1574 $this->assertNotEmpty($result['status']);
1575 foreach ($result['status'] as $status) {
1576 $this->assertStatus($status);
1581 * Test the api_statuses_public_timeline() function with an unallowed user.
1583 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1585 public function testApiStatusesPublicTimelineWithUnallowedUser()
1587 $_SESSION['allow_api'] = false;
1588 $_GET['screen_name'] = $this->selfUser['nick'];
1589 api_statuses_public_timeline('json');
1593 * Test the api_statuses_public_timeline() function with an RSS result.
1596 public function testApiStatusesPublicTimelineWithRss()
1598 $result = api_statuses_public_timeline('rss');
1599 $this->assertXml($result, 'statuses');
1603 * Test the api_statuses_networkpublic_timeline() function.
1606 public function testApiStatusesNetworkpublicTimeline()
1608 $_REQUEST['max_id'] = 10;
1609 $result = api_statuses_networkpublic_timeline('json');
1610 $this->assertNotEmpty($result['status']);
1611 foreach ($result['status'] as $status) {
1612 $this->assertStatus($status);
1617 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1620 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1622 $_REQUEST['page'] = -2;
1623 $result = api_statuses_networkpublic_timeline('json');
1624 $this->assertNotEmpty($result['status']);
1625 foreach ($result['status'] as $status) {
1626 $this->assertStatus($status);
1631 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1633 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1635 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1637 $_SESSION['allow_api'] = false;
1638 $_GET['screen_name'] = $this->selfUser['nick'];
1639 api_statuses_networkpublic_timeline('json');
1643 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1646 public function testApiStatusesNetworkpublicTimelineWithRss()
1648 $result = api_statuses_networkpublic_timeline('rss');
1649 $this->assertXml($result, 'statuses');
1653 * Test the api_statuses_show() function.
1655 * @expectedException Friendica\Network\HTTPException\BadRequestException
1657 public function testApiStatusesShow()
1659 api_statuses_show('json');
1663 * Test the api_statuses_show() function with an ID.
1666 public function testApiStatusesShowWithId()
1668 $this->app->argv[3] = 1;
1669 $result = api_statuses_show('json');
1670 $this->assertStatus($result['status']);
1674 * Test the api_statuses_show() function with the conversation parameter.
1677 public function testApiStatusesShowWithConversation()
1679 $this->app->argv[3] = 1;
1680 $_REQUEST['conversation'] = 1;
1681 $result = api_statuses_show('json');
1682 $this->assertNotEmpty($result['status']);
1683 foreach ($result['status'] as $status) {
1684 $this->assertStatus($status);
1689 * Test the api_statuses_show() function with an unallowed user.
1691 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1693 public function testApiStatusesShowWithUnallowedUser()
1695 $_SESSION['allow_api'] = false;
1696 $_GET['screen_name'] = $this->selfUser['nick'];
1697 api_statuses_show('json');
1701 * Test the api_conversation_show() function.
1703 * @expectedException Friendica\Network\HTTPException\BadRequestException
1705 public function testApiConversationShow()
1707 api_conversation_show('json');
1711 * Test the api_conversation_show() function with an ID.
1714 public function testApiConversationShowWithId()
1716 $this->app->argv[3] = 1;
1717 $_REQUEST['max_id'] = 10;
1718 $_REQUEST['page'] = -2;
1719 $result = api_conversation_show('json');
1720 $this->assertNotEmpty($result['status']);
1721 foreach ($result['status'] as $status) {
1722 $this->assertStatus($status);
1727 * Test the api_conversation_show() function with an unallowed user.
1729 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1731 public function testApiConversationShowWithUnallowedUser()
1733 $_SESSION['allow_api'] = false;
1734 $_GET['screen_name'] = $this->selfUser['nick'];
1735 api_conversation_show('json');
1739 * Test the api_statuses_repeat() function.
1741 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1743 public function testApiStatusesRepeat()
1745 api_statuses_repeat('json');
1749 * Test the api_statuses_repeat() function without an authenticated user.
1751 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1753 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1755 $_SESSION['authenticated'] = false;
1756 api_statuses_repeat('json');
1760 * Test the api_statuses_repeat() function with an ID.
1763 public function testApiStatusesRepeatWithId()
1765 $this->app->argv[3] = 1;
1766 $result = api_statuses_repeat('json');
1767 $this->assertStatus($result['status']);
1769 // Also test with a shared status
1770 $this->app->argv[3] = 5;
1771 $result = api_statuses_repeat('json');
1772 $this->assertStatus($result['status']);
1776 * Test the api_statuses_destroy() function.
1778 * @expectedException Friendica\Network\HTTPException\BadRequestException
1780 public function testApiStatusesDestroy()
1782 api_statuses_destroy('json');
1786 * Test the api_statuses_destroy() function without an authenticated user.
1788 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1790 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1792 $_SESSION['authenticated'] = false;
1793 api_statuses_destroy('json');
1797 * Test the api_statuses_destroy() function with an ID.
1800 public function testApiStatusesDestroyWithId()
1802 $this->app->argv[3] = 1;
1803 $result = api_statuses_destroy('json');
1804 $this->assertStatus($result['status']);
1808 * Test the api_statuses_mentions() function.
1811 public function testApiStatusesMentions()
1813 $this->app->user = ['nickname' => $this->selfUser['nick']];
1814 $_REQUEST['max_id'] = 10;
1815 $result = api_statuses_mentions('json');
1816 $this->assertEmpty($result['status']);
1817 // We should test with mentions in the database.
1821 * Test the api_statuses_mentions() function with a negative page parameter.
1824 public function testApiStatusesMentionsWithNegativePage()
1826 $_REQUEST['page'] = -2;
1827 $result = api_statuses_mentions('json');
1828 $this->assertEmpty($result['status']);
1832 * Test the api_statuses_mentions() function with an unallowed user.
1834 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1836 public function testApiStatusesMentionsWithUnallowedUser()
1838 $_SESSION['allow_api'] = false;
1839 $_GET['screen_name'] = $this->selfUser['nick'];
1840 api_statuses_mentions('json');
1844 * Test the api_statuses_mentions() function with an RSS result.
1847 public function testApiStatusesMentionsWithRss()
1849 $result = api_statuses_mentions('rss');
1850 $this->assertXml($result, 'statuses');
1854 * Test the api_statuses_user_timeline() function.
1857 public function testApiStatusesUserTimeline()
1859 $_REQUEST['max_id'] = 10;
1860 $_REQUEST['exclude_replies'] = true;
1861 $_REQUEST['conversation_id'] = 1;
1862 $result = api_statuses_user_timeline('json');
1863 $this->assertNotEmpty($result['status']);
1864 foreach ($result['status'] as $status) {
1865 $this->assertStatus($status);
1870 * Test the api_statuses_user_timeline() function with a negative page parameter.
1873 public function testApiStatusesUserTimelineWithNegativePage()
1875 $_REQUEST['page'] = -2;
1876 $result = api_statuses_user_timeline('json');
1877 $this->assertNotEmpty($result['status']);
1878 foreach ($result['status'] as $status) {
1879 $this->assertStatus($status);
1884 * Test the api_statuses_user_timeline() function with an RSS result.
1887 public function testApiStatusesUserTimelineWithRss()
1889 $result = api_statuses_user_timeline('rss');
1890 $this->assertXml($result, 'statuses');
1894 * Test the api_statuses_user_timeline() function with an unallowed user.
1896 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1898 public function testApiStatusesUserTimelineWithUnallowedUser()
1900 $_SESSION['allow_api'] = false;
1901 $_GET['screen_name'] = $this->selfUser['nick'];
1902 api_statuses_user_timeline('json');
1906 * Test the api_favorites_create_destroy() function.
1908 * @expectedException Friendica\Network\HTTPException\BadRequestException
1910 public function testApiFavoritesCreateDestroy()
1912 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1913 $this->app->argc = count($this->app->argv);
1914 api_favorites_create_destroy('json');
1918 * Test the api_favorites_create_destroy() function with an invalid ID.
1920 * @expectedException Friendica\Network\HTTPException\BadRequestException
1922 public function testApiFavoritesCreateDestroyWithInvalidId()
1924 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1925 $this->app->argc = count($this->app->argv);
1926 api_favorites_create_destroy('json');
1930 * Test the api_favorites_create_destroy() function with an invalid action.
1932 * @expectedException Friendica\Network\HTTPException\BadRequestException
1934 public function testApiFavoritesCreateDestroyWithInvalidAction()
1936 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1937 $this->app->argc = count($this->app->argv);
1938 $_REQUEST['id'] = 1;
1939 api_favorites_create_destroy('json');
1943 * Test the api_favorites_create_destroy() function with the create action.
1946 public function testApiFavoritesCreateDestroyWithCreateAction()
1948 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1949 $this->app->argc = count($this->app->argv);
1950 $_REQUEST['id'] = 3;
1951 $result = api_favorites_create_destroy('json');
1952 $this->assertStatus($result['status']);
1956 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1959 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1961 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1962 $this->app->argc = count($this->app->argv);
1963 $_REQUEST['id'] = 3;
1964 $result = api_favorites_create_destroy('rss');
1965 $this->assertXml($result, 'status');
1969 * Test the api_favorites_create_destroy() function with the destroy action.
1972 public function testApiFavoritesCreateDestroyWithDestroyAction()
1974 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1975 $this->app->argc = count($this->app->argv);
1976 $_REQUEST['id'] = 3;
1977 $result = api_favorites_create_destroy('json');
1978 $this->assertStatus($result['status']);
1982 * Test the api_favorites_create_destroy() function without an authenticated user.
1984 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1986 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1988 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1989 $this->app->argc = count($this->app->argv);
1990 $_SESSION['authenticated'] = false;
1991 api_favorites_create_destroy('json');
1995 * Test the api_favorites() function.
1998 public function testApiFavorites()
2000 $_REQUEST['page'] = -1;
2001 $_REQUEST['max_id'] = 10;
2002 $result = api_favorites('json');
2003 foreach ($result['status'] as $status) {
2004 $this->assertStatus($status);
2009 * Test the api_favorites() function with an RSS result.
2012 public function testApiFavoritesWithRss()
2014 $result = api_favorites('rss');
2015 $this->assertXml($result, 'statuses');
2019 * Test the api_favorites() function with an unallowed user.
2021 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2023 public function testApiFavoritesWithUnallowedUser()
2025 $_SESSION['allow_api'] = false;
2026 $_GET['screen_name'] = $this->selfUser['nick'];
2027 api_favorites('json');
2031 * Test the api_format_messages() function.
2034 public function testApiFormatMessages()
2036 $result = api_format_messages(
2037 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2038 ['id' => 2, 'screen_name' => 'recipient_name'],
2039 ['id' => 3, 'screen_name' => 'sender_name']
2041 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2042 $this->assertEquals(1, $result['id']);
2043 $this->assertEquals(2, $result['recipient_id']);
2044 $this->assertEquals(3, $result['sender_id']);
2045 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2046 $this->assertEquals('sender_name', $result['sender_screen_name']);
2050 * Test the api_format_messages() function with HTML.
2053 public function testApiFormatMessagesWithHtmlText()
2055 $_GET['getText'] = 'html';
2056 $result = api_format_messages(
2057 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2058 ['id' => 2, 'screen_name' => 'recipient_name'],
2059 ['id' => 3, 'screen_name' => 'sender_name']
2061 $this->assertEquals('item_title', $result['title']);
2062 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2066 * Test the api_format_messages() function with plain text.
2069 public function testApiFormatMessagesWithPlainText()
2071 $_GET['getText'] = 'plain';
2072 $result = api_format_messages(
2073 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2074 ['id' => 2, 'screen_name' => 'recipient_name'],
2075 ['id' => 3, 'screen_name' => 'sender_name']
2077 $this->assertEquals('item_title', $result['title']);
2078 $this->assertEquals('item_body', $result['text']);
2082 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2085 public function testApiFormatMessagesWithoutUserObjects()
2087 $_GET['getUserObjects'] = 'false';
2088 $result = api_format_messages(
2089 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2090 ['id' => 2, 'screen_name' => 'recipient_name'],
2091 ['id' => 3, 'screen_name' => 'sender_name']
2093 $this->assertTrue(!isset($result['sender']));
2094 $this->assertTrue(!isset($result['recipient']));
2098 * Test the api_convert_item() function.
2101 public function testApiConvertItem()
2103 $result = api_convert_item(
2105 'network' => 'feed',
2106 'title' => 'item_title',
2107 // We need a long string to test that it is correctly cut
2108 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2109 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2110 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2111 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2112 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2113 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2114 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2115 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2116 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2117 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2118 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2119 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2120 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2121 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2122 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2123 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2124 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2125 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2126 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2127 'repellat officia illum quos impedit quam iste esse unde qui '.
2128 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2129 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2130 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2131 'plink' => 'item_plink'
2134 $this->assertStringStartsWith('item_title', $result['text']);
2135 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2139 * Test the api_convert_item() function with an empty item body.
2142 public function testApiConvertItemWithoutBody()
2144 $result = api_convert_item(
2146 'network' => 'feed',
2147 'title' => 'item_title',
2149 'plink' => 'item_plink'
2152 $this->assertEquals('item_title', $result['text']);
2153 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2157 * Test the api_convert_item() function with the title in the body.
2160 public function testApiConvertItemWithTitleInBody()
2162 $result = api_convert_item(
2164 'title' => 'item_title',
2165 'body' => 'item_title item_body'
2168 $this->assertEquals('item_title item_body', $result['text']);
2169 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2173 * Test the api_get_attachments() function.
2176 public function testApiGetAttachments()
2179 $this->assertEmpty(api_get_attachments($body));
2183 * Test the api_get_attachments() function with an img tag.
2186 public function testApiGetAttachmentsWithImage()
2188 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2189 $this->assertInternalType('array', api_get_attachments($body));
2193 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2196 public function testApiGetAttachmentsWithImageAndAndStatus()
2198 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2199 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2200 $this->assertInternalType('array', api_get_attachments($body));
2204 * Test the api_get_entitities() function.
2207 public function testApiGetEntitities()
2210 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2214 * Test the api_get_entitities() function with the include_entities parameter.
2217 public function testApiGetEntititiesWithIncludeEntities()
2219 $_REQUEST['include_entities'] = 'true';
2221 $result = api_get_entitities($text, 'bbcode');
2222 $this->assertInternalType('array', $result['hashtags']);
2223 $this->assertInternalType('array', $result['symbols']);
2224 $this->assertInternalType('array', $result['urls']);
2225 $this->assertInternalType('array', $result['user_mentions']);
2229 * Test the api_format_items_embeded_images() function.
2232 public function testApiFormatItemsEmbededImages()
2234 $this->assertEquals(
2235 'text ' . System::baseUrl() . '/display/item_guid',
2236 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2241 * Test the api_contactlink_to_array() function.
2244 public function testApiContactlinkToArray()
2246 $this->assertEquals(
2251 api_contactlink_to_array('text')
2256 * Test the api_contactlink_to_array() function with an URL.
2259 public function testApiContactlinkToArrayWithUrl()
2261 $this->assertEquals(
2263 'name' => ['link_text'],
2266 api_contactlink_to_array('text <a href="url">link_text</a>')
2271 * Test the api_format_items_activities() function.
2274 public function testApiFormatItemsActivities()
2276 $item = ['uid' => 0, 'uri' => ''];
2277 $result = api_format_items_activities($item);
2278 $this->assertArrayHasKey('like', $result);
2279 $this->assertArrayHasKey('dislike', $result);
2280 $this->assertArrayHasKey('attendyes', $result);
2281 $this->assertArrayHasKey('attendno', $result);
2282 $this->assertArrayHasKey('attendmaybe', $result);
2286 * Test the api_format_items_activities() function with an XML result.
2289 public function testApiFormatItemsActivitiesWithXml()
2291 $item = ['uid' => 0, 'uri' => ''];
2292 $result = api_format_items_activities($item, 'xml');
2293 $this->assertArrayHasKey('friendica:like', $result);
2294 $this->assertArrayHasKey('friendica:dislike', $result);
2295 $this->assertArrayHasKey('friendica:attendyes', $result);
2296 $this->assertArrayHasKey('friendica:attendno', $result);
2297 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2301 * Test the api_format_items_profiles() function.
2304 public function testApiFormatItemsProfiles()
2307 'id' => 'profile_id',
2308 'profile-name' => 'profile_name',
2309 'is-default' => true,
2310 'hide-friends' => true,
2311 'photo' => 'profile_photo',
2312 'thumb' => 'profile_thumb',
2314 'net-publish' => true,
2315 'pdesc' => 'description',
2316 'dob' => 'date_of_birth',
2317 'address' => 'address',
2318 'locality' => 'city',
2319 'region' => 'region',
2320 'postal-code' => 'postal_code',
2321 'country-name' => 'country',
2322 'hometown' => 'hometown',
2323 'gender' => 'gender',
2324 'marital' => 'marital',
2325 'with' => 'marital_with',
2326 'howlong' => 'marital_since',
2327 'sexual' => 'sexual',
2328 'politic' => 'politic',
2329 'religion' => 'religion',
2330 'pub_keywords' => 'public_keywords',
2331 'prv_keywords' => 'private_keywords',
2334 'dislikes' => 'dislikes',
2340 'interest' => 'interest',
2341 'romance' => 'romance',
2343 'education' => 'education',
2344 'contact' => 'social_networks',
2345 'homepage' => 'homepage'
2347 $result = api_format_items_profiles($profile_row);
2348 $this->assertEquals(
2350 'profile_id' => 'profile_id',
2351 'profile_name' => 'profile_name',
2352 'is_default' => true,
2353 'hide_friends' => true,
2354 'profile_photo' => 'profile_photo',
2355 'profile_thumb' => 'profile_thumb',
2357 'net_publish' => true,
2358 'description' => 'description',
2359 'date_of_birth' => 'date_of_birth',
2360 'address' => 'address',
2362 'region' => 'region',
2363 'postal_code' => 'postal_code',
2364 'country' => 'country',
2365 'hometown' => 'hometown',
2366 'gender' => 'gender',
2367 'marital' => 'marital',
2368 'marital_with' => 'marital_with',
2369 'marital_since' => 'marital_since',
2370 'sexual' => 'sexual',
2371 'politic' => 'politic',
2372 'religion' => 'religion',
2373 'public_keywords' => 'public_keywords',
2374 'private_keywords' => 'private_keywords',
2377 'dislikes' => 'dislikes',
2383 'interest' => 'interest',
2384 'romance' => 'romance',
2386 'education' => 'education',
2387 'social_networks' => 'social_networks',
2388 'homepage' => 'homepage',
2396 * Test the api_format_items() function.
2399 public function testApiFormatItems()
2403 'item_network' => 'item_network',
2409 'author-network' => Protocol::DFRN,
2410 'author-link' => 'http://localhost/profile/othercontact',
2414 $result = api_format_items($items, ['id' => 0], true);
2415 foreach ($result as $status) {
2416 $this->assertStatus($status);
2421 * Test the api_format_items() function with an XML result.
2424 public function testApiFormatItemsWithXml()
2432 'author-network' => Protocol::DFRN,
2433 'author-link' => 'http://localhost/profile/othercontact',
2437 $result = api_format_items($items, ['id' => 0], true, 'xml');
2438 foreach ($result as $status) {
2439 $this->assertStatus($status);
2444 * Test the api_format_items() function.
2447 public function testApiAccountRateLimitStatus()
2449 $result = api_account_rate_limit_status('json');
2450 $this->assertEquals(150, $result['hash']['remaining_hits']);
2451 $this->assertEquals(150, $result['hash']['hourly_limit']);
2452 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2456 * Test the api_format_items() function with an XML result.
2459 public function testApiAccountRateLimitStatusWithXml()
2461 $result = api_account_rate_limit_status('xml');
2462 $this->assertXml($result, 'hash');
2466 * Test the api_help_test() function.
2469 public function testApiHelpTest()
2471 $result = api_help_test('json');
2472 $this->assertEquals(['ok' => 'ok'], $result);
2476 * Test the api_help_test() function with an XML result.
2479 public function testApiHelpTestWithXml()
2481 $result = api_help_test('xml');
2482 $this->assertXml($result, 'ok');
2486 * Test the api_lists_list() function.
2489 public function testApiListsList()
2491 $result = api_lists_list('json');
2492 $this->assertEquals(['lists_list' => []], $result);
2496 * Test the api_lists_ownerships() function.
2499 public function testApiListsOwnerships()
2501 $result = api_lists_ownerships('json');
2502 foreach ($result['lists']['lists'] as $list) {
2503 $this->assertList($list);
2508 * Test the api_lists_ownerships() function without an authenticated user.
2510 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2512 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2514 $_SESSION['authenticated'] = false;
2515 api_lists_ownerships('json');
2519 * Test the api_lists_statuses() function.
2520 * @expectedException Friendica\Network\HTTPException\BadRequestException
2523 public function testApiListsStatuses()
2525 api_lists_statuses('json');
2529 * Test the api_lists_statuses() function with a list ID.
2532 public function testApiListsStatusesWithListId()
2534 $_REQUEST['list_id'] = 1;
2535 $_REQUEST['page'] = -1;
2536 $_REQUEST['max_id'] = 10;
2537 $result = api_lists_statuses('json');
2538 foreach ($result['status'] as $status) {
2539 $this->assertStatus($status);
2544 * Test the api_lists_statuses() function with a list ID and a RSS result.
2547 public function testApiListsStatusesWithListIdAndRss()
2549 $_REQUEST['list_id'] = 1;
2550 $result = api_lists_statuses('rss');
2551 $this->assertXml($result, 'statuses');
2555 * Test the api_lists_statuses() function with an unallowed user.
2557 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2559 public function testApiListsStatusesWithUnallowedUser()
2561 $_SESSION['allow_api'] = false;
2562 $_GET['screen_name'] = $this->selfUser['nick'];
2563 api_lists_statuses('json');
2567 * Test the api_statuses_f() function.
2570 public function testApiStatusesFWithFriends()
2573 $result = api_statuses_f('friends');
2574 $this->assertArrayHasKey('user', $result);
2578 * Test the api_statuses_f() function.
2581 public function testApiStatusesFWithFollowers()
2583 $result = api_statuses_f('followers');
2584 $this->assertArrayHasKey('user', $result);
2588 * Test the api_statuses_f() function.
2591 public function testApiStatusesFWithBlocks()
2593 $result = api_statuses_f('blocks');
2594 $this->assertArrayHasKey('user', $result);
2598 * Test the api_statuses_f() function.
2601 public function testApiStatusesFWithIncoming()
2603 $result = api_statuses_f('incoming');
2604 $this->assertArrayHasKey('user', $result);
2608 * Test the api_statuses_f() function an undefined cursor GET variable.
2611 public function testApiStatusesFWithUndefinedCursor()
2613 $_GET['cursor'] = 'undefined';
2614 $this->assertFalse(api_statuses_f('friends'));
2618 * Test the api_statuses_friends() function.
2621 public function testApiStatusesFriends()
2623 $result = api_statuses_friends('json');
2624 $this->assertArrayHasKey('user', $result);
2628 * Test the api_statuses_friends() function an undefined cursor GET variable.
2631 public function testApiStatusesFriendsWithUndefinedCursor()
2633 $_GET['cursor'] = 'undefined';
2634 $this->assertFalse(api_statuses_friends('json'));
2638 * Test the api_statuses_followers() function.
2641 public function testApiStatusesFollowers()
2643 $result = api_statuses_followers('json');
2644 $this->assertArrayHasKey('user', $result);
2648 * Test the api_statuses_followers() function an undefined cursor GET variable.
2651 public function testApiStatusesFollowersWithUndefinedCursor()
2653 $_GET['cursor'] = 'undefined';
2654 $this->assertFalse(api_statuses_followers('json'));
2658 * Test the api_blocks_list() function.
2661 public function testApiBlocksList()
2663 $result = api_blocks_list('json');
2664 $this->assertArrayHasKey('user', $result);
2668 * Test the api_blocks_list() function an undefined cursor GET variable.
2671 public function testApiBlocksListWithUndefinedCursor()
2673 $_GET['cursor'] = 'undefined';
2674 $this->assertFalse(api_blocks_list('json'));
2678 * Test the api_friendships_incoming() function.
2681 public function testApiFriendshipsIncoming()
2683 $result = api_friendships_incoming('json');
2684 $this->assertArrayHasKey('id', $result);
2688 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2691 public function testApiFriendshipsIncomingWithUndefinedCursor()
2693 $_GET['cursor'] = 'undefined';
2694 $this->assertFalse(api_friendships_incoming('json'));
2698 * Test the api_statusnet_config() function.
2701 public function testApiStatusnetConfig()
2703 $result = api_statusnet_config('json');
2704 $this->assertEquals('localhost', $result['config']['site']['server']);
2705 $this->assertEquals('default', $result['config']['site']['theme']);
2706 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2707 $this->assertTrue($result['config']['site']['fancy']);
2708 $this->assertEquals('en', $result['config']['site']['language']);
2709 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2710 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2711 $this->assertEquals('false', $result['config']['site']['private']);
2712 $this->assertEquals('false', $result['config']['site']['ssl']);
2713 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2717 * Test the api_statusnet_version() function.
2720 public function testApiStatusnetVersion()
2722 $result = api_statusnet_version('json');
2723 $this->assertEquals('0.9.7', $result['version']);
2727 * Test the api_ff_ids() function.
2730 public function testApiFfIds()
2732 $result = api_ff_ids('json');
2733 $this->assertNull($result);
2737 * Test the api_ff_ids() function with a result.
2740 public function testApiFfIdsWithResult()
2742 $this->markTestIncomplete();
2746 * Test the api_ff_ids() function without an authenticated user.
2748 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2750 public function testApiFfIdsWithoutAuthenticatedUser()
2752 $_SESSION['authenticated'] = false;
2757 * Test the api_friends_ids() function.
2760 public function testApiFriendsIds()
2762 $result = api_friends_ids('json');
2763 $this->assertNull($result);
2767 * Test the api_followers_ids() function.
2770 public function testApiFollowersIds()
2772 $result = api_followers_ids('json');
2773 $this->assertNull($result);
2777 * Test the api_direct_messages_new() function.
2780 public function testApiDirectMessagesNew()
2782 $result = api_direct_messages_new('json');
2783 $this->assertNull($result);
2787 * Test the api_direct_messages_new() function without an authenticated user.
2789 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2791 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2793 $_SESSION['authenticated'] = false;
2794 api_direct_messages_new('json');
2798 * Test the api_direct_messages_new() function with an user ID.
2801 public function testApiDirectMessagesNewWithUserId()
2803 $_POST['text'] = 'message_text';
2804 $_POST['user_id'] = $this->otherUser['id'];
2805 $result = api_direct_messages_new('json');
2806 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2810 * Test the api_direct_messages_new() function with a screen name.
2813 public function testApiDirectMessagesNewWithScreenName()
2815 $_POST['text'] = 'message_text';
2816 $_POST['screen_name'] = $this->friendUser['nick'];
2817 $result = api_direct_messages_new('json');
2818 $this->assertEquals(1, $result['direct_message']['id']);
2819 $this->assertContains('message_text', $result['direct_message']['text']);
2820 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2821 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2825 * Test the api_direct_messages_new() function with a title.
2828 public function testApiDirectMessagesNewWithTitle()
2830 $_POST['text'] = 'message_text';
2831 $_POST['screen_name'] = $this->friendUser['nick'];
2832 $_REQUEST['title'] = 'message_title';
2833 $result = api_direct_messages_new('json');
2834 $this->assertEquals(1, $result['direct_message']['id']);
2835 $this->assertContains('message_text', $result['direct_message']['text']);
2836 $this->assertContains('message_title', $result['direct_message']['text']);
2837 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2838 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2842 * Test the api_direct_messages_new() function with an RSS result.
2845 public function testApiDirectMessagesNewWithRss()
2847 $_POST['text'] = 'message_text';
2848 $_POST['screen_name'] = $this->friendUser['nick'];
2849 $result = api_direct_messages_new('rss');
2850 $this->assertXml($result, 'direct-messages');
2854 * Test the api_direct_messages_destroy() function.
2856 * @expectedException Friendica\Network\HTTPException\BadRequestException
2858 public function testApiDirectMessagesDestroy()
2860 api_direct_messages_destroy('json');
2864 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2867 public function testApiDirectMessagesDestroyWithVerbose()
2869 $_GET['friendica_verbose'] = 'true';
2870 $result = api_direct_messages_destroy('json');
2871 $this->assertEquals(
2874 'result' => 'error',
2875 'message' => 'message id or parenturi not specified'
2883 * Test the api_direct_messages_destroy() function without an authenticated user.
2885 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2887 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2889 $_SESSION['authenticated'] = false;
2890 api_direct_messages_destroy('json');
2894 * Test the api_direct_messages_destroy() function with a non-zero ID.
2896 * @expectedException Friendica\Network\HTTPException\BadRequestException
2898 public function testApiDirectMessagesDestroyWithId()
2900 $_REQUEST['id'] = 1;
2901 api_direct_messages_destroy('json');
2905 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2908 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2910 $_REQUEST['id'] = 1;
2911 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2912 $_GET['friendica_verbose'] = 'true';
2913 $result = api_direct_messages_destroy('json');
2914 $this->assertEquals(
2917 'result' => 'error',
2918 'message' => 'message id not in database'
2926 * Test the api_direct_messages_destroy() function with a non-zero ID.
2929 public function testApiDirectMessagesDestroyWithCorrectId()
2931 $this->markTestIncomplete('We need to add a dataset for this.');
2935 * Test the api_direct_messages_box() function.
2938 public function testApiDirectMessagesBoxWithSentbox()
2940 $_REQUEST['page'] = -1;
2941 $_REQUEST['max_id'] = 10;
2942 $result = api_direct_messages_box('json', 'sentbox', 'false');
2943 $this->assertArrayHasKey('direct_message', $result);
2947 * Test the api_direct_messages_box() function.
2950 public function testApiDirectMessagesBoxWithConversation()
2952 $result = api_direct_messages_box('json', 'conversation', 'false');
2953 $this->assertArrayHasKey('direct_message', $result);
2957 * Test the api_direct_messages_box() function.
2960 public function testApiDirectMessagesBoxWithAll()
2962 $result = api_direct_messages_box('json', 'all', 'false');
2963 $this->assertArrayHasKey('direct_message', $result);
2967 * Test the api_direct_messages_box() function.
2970 public function testApiDirectMessagesBoxWithInbox()
2972 $result = api_direct_messages_box('json', 'inbox', 'false');
2973 $this->assertArrayHasKey('direct_message', $result);
2977 * Test the api_direct_messages_box() function.
2980 public function testApiDirectMessagesBoxWithVerbose()
2982 $result = api_direct_messages_box('json', 'sentbox', 'true');
2983 $this->assertEquals(
2986 'result' => 'error',
2987 'message' => 'no mails available'
2995 * Test the api_direct_messages_box() function with a RSS result.
2998 public function testApiDirectMessagesBoxWithRss()
3000 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3001 $this->assertXml($result, 'direct-messages');
3005 * Test the api_direct_messages_box() function without an authenticated user.
3007 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3009 public function testApiDirectMessagesBoxWithUnallowedUser()
3011 $_SESSION['allow_api'] = false;
3012 $_GET['screen_name'] = $this->selfUser['nick'];
3013 api_direct_messages_box('json', 'sentbox', 'false');
3017 * Test the api_direct_messages_sentbox() function.
3020 public function testApiDirectMessagesSentbox()
3022 $result = api_direct_messages_sentbox('json');
3023 $this->assertArrayHasKey('direct_message', $result);
3027 * Test the api_direct_messages_inbox() function.
3030 public function testApiDirectMessagesInbox()
3032 $result = api_direct_messages_inbox('json');
3033 $this->assertArrayHasKey('direct_message', $result);
3037 * Test the api_direct_messages_all() function.
3040 public function testApiDirectMessagesAll()
3042 $result = api_direct_messages_all('json');
3043 $this->assertArrayHasKey('direct_message', $result);
3047 * Test the api_direct_messages_conversation() function.
3050 public function testApiDirectMessagesConversation()
3052 $result = api_direct_messages_conversation('json');
3053 $this->assertArrayHasKey('direct_message', $result);
3057 * Test the api_oauth_request_token() function.
3060 public function testApiOauthRequestToken()
3062 $this->markTestIncomplete('killme() kills phpunit as well');
3066 * Test the api_oauth_access_token() function.
3069 public function testApiOauthAccessToken()
3071 $this->markTestIncomplete('killme() kills phpunit as well');
3075 * Test the api_fr_photoalbum_delete() function.
3077 * @expectedException Friendica\Network\HTTPException\BadRequestException
3079 public function testApiFrPhotoalbumDelete()
3081 api_fr_photoalbum_delete('json');
3085 * Test the api_fr_photoalbum_delete() function with an album name.
3087 * @expectedException Friendica\Network\HTTPException\BadRequestException
3089 public function testApiFrPhotoalbumDeleteWithAlbum()
3091 $_REQUEST['album'] = 'album_name';
3092 api_fr_photoalbum_delete('json');
3096 * Test the api_fr_photoalbum_delete() function with an album name.
3099 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3101 $this->markTestIncomplete('We need to add a dataset for this.');
3105 * Test the api_fr_photoalbum_delete() function.
3107 * @expectedException Friendica\Network\HTTPException\BadRequestException
3109 public function testApiFrPhotoalbumUpdate()
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 testApiFrPhotoalbumUpdateWithAlbum()
3121 $_REQUEST['album'] = 'album_name';
3122 api_fr_photoalbum_update('json');
3126 * Test the api_fr_photoalbum_delete() function with an album name.
3128 * @expectedException Friendica\Network\HTTPException\BadRequestException
3130 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3132 $_REQUEST['album'] = 'album_name';
3133 $_REQUEST['album_new'] = 'album_name';
3134 api_fr_photoalbum_update('json');
3138 * Test the api_fr_photoalbum_update() function without an authenticated user.
3140 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3142 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3144 $_SESSION['authenticated'] = false;
3145 api_fr_photoalbum_update('json');
3149 * Test the api_fr_photoalbum_delete() function with an album name.
3152 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3154 $this->markTestIncomplete('We need to add a dataset for this.');
3158 * Test the api_fr_photos_list() function.
3161 public function testApiFrPhotosList()
3163 $result = api_fr_photos_list('json');
3164 $this->assertArrayHasKey('photo', $result);
3168 * Test the api_fr_photos_list() function without an authenticated user.
3170 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3172 public function testApiFrPhotosListWithoutAuthenticatedUser()
3174 $_SESSION['authenticated'] = false;
3175 api_fr_photos_list('json');
3179 * Test the api_fr_photo_create_update() function.
3181 * @expectedException Friendica\Network\HTTPException\BadRequestException
3183 public function testApiFrPhotoCreateUpdate()
3185 api_fr_photo_create_update('json');
3189 * Test the api_fr_photo_create_update() function without an authenticated user.
3191 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3193 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3195 $_SESSION['authenticated'] = false;
3196 api_fr_photo_create_update('json');
3200 * Test the api_fr_photo_create_update() function with an album name.
3202 * @expectedException Friendica\Network\HTTPException\BadRequestException
3204 public function testApiFrPhotoCreateUpdateWithAlbum()
3206 $_REQUEST['album'] = 'album_name';
3207 api_fr_photo_create_update('json');
3211 * Test the api_fr_photo_create_update() function with the update mode.
3214 public function testApiFrPhotoCreateUpdateWithUpdate()
3216 $this->markTestIncomplete('We need to create a dataset for this');
3220 * Test the api_fr_photo_create_update() function with an uploaded file.
3223 public function testApiFrPhotoCreateUpdateWithFile()
3225 $this->markTestIncomplete();
3229 * Test the api_fr_photo_delete() function.
3231 * @expectedException Friendica\Network\HTTPException\BadRequestException
3233 public function testApiFrPhotoDelete()
3235 api_fr_photo_delete('json');
3239 * Test the api_fr_photo_delete() function without an authenticated user.
3241 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3243 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3245 $_SESSION['authenticated'] = false;
3246 api_fr_photo_delete('json');
3250 * Test the api_fr_photo_delete() function with a photo ID.
3252 * @expectedException Friendica\Network\HTTPException\BadRequestException
3254 public function testApiFrPhotoDeleteWithPhotoId()
3256 $_REQUEST['photo_id'] = 1;
3257 api_fr_photo_delete('json');
3261 * Test the api_fr_photo_delete() function with a correct photo ID.
3264 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3266 $this->markTestIncomplete('We need to create a dataset for this.');
3270 * Test the api_fr_photo_detail() function.
3272 * @expectedException Friendica\Network\HTTPException\BadRequestException
3274 public function testApiFrPhotoDetail()
3276 api_fr_photo_detail('json');
3280 * Test the api_fr_photo_detail() function without an authenticated user.
3282 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3284 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3286 $_SESSION['authenticated'] = false;
3287 api_fr_photo_detail('json');
3291 * Test the api_fr_photo_detail() function with a photo ID.
3293 * @expectedException Friendica\Network\HTTPException\NotFoundException
3295 public function testApiFrPhotoDetailWithPhotoId()
3297 $_REQUEST['photo_id'] = 1;
3298 api_fr_photo_detail('json');
3302 * Test the api_fr_photo_detail() function with a correct photo ID.
3305 public function testApiFrPhotoDetailCorrectPhotoId()
3307 $this->markTestIncomplete('We need to create a dataset for this.');
3311 * Test the api_account_update_profile_image() function.
3313 * @expectedException Friendica\Network\HTTPException\BadRequestException
3315 public function testApiAccountUpdateProfileImage()
3317 api_account_update_profile_image('json');
3321 * Test the api_account_update_profile_image() function without an authenticated user.
3323 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3325 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3327 $_SESSION['authenticated'] = false;
3328 api_account_update_profile_image('json');
3332 * Test the api_account_update_profile_image() function with an uploaded file.
3334 * @expectedException Friendica\Network\HTTPException\BadRequestException
3336 public function testApiAccountUpdateProfileImageWithUpload()
3338 $this->markTestIncomplete();
3343 * Test the api_account_update_profile() function.
3346 public function testApiAccountUpdateProfile()
3348 $_POST['name'] = 'new_name';
3349 $_POST['description'] = 'new_description';
3350 $result = api_account_update_profile('json');
3351 // We can't use assertSelfUser() here because the user object is missing some properties.
3352 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3353 $this->assertEquals('DFRN', $result['user']['location']);
3354 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3355 $this->assertEquals('dfrn', $result['user']['network']);
3356 $this->assertEquals('new_name', $result['user']['name']);
3357 $this->assertEquals('new_description', $result['user']['description']);
3361 * Test the check_acl_input() function.
3364 public function testCheckAclInput()
3366 $result = check_acl_input('<aclstring>');
3367 // Where does this result come from?
3368 $this->assertEquals(1, $result);
3372 * Test the check_acl_input() function with an empty ACL string.
3375 public function testCheckAclInputWithEmptyAclString()
3377 $result = check_acl_input(' ');
3378 $this->assertFalse($result);
3382 * Test the save_media_to_database() function.
3385 public function testSaveMediaToDatabase()
3387 $this->markTestIncomplete();
3391 * Test the post_photo_item() function.
3394 public function testPostPhotoItem()
3396 $this->markTestIncomplete();
3400 * Test the prepare_photo_data() function.
3403 public function testPreparePhotoData()
3405 $this->markTestIncomplete();
3409 * Test the api_friendica_remoteauth() function.
3411 * @expectedException Friendica\Network\HTTPException\BadRequestException
3413 public function testApiFriendicaRemoteauth()
3415 api_friendica_remoteauth();
3419 * Test the api_friendica_remoteauth() function with an URL.
3421 * @expectedException Friendica\Network\HTTPException\BadRequestException
3423 public function testApiFriendicaRemoteauthWithUrl()
3425 $_GET['url'] = 'url';
3426 $_GET['c_url'] = 'url';
3427 api_friendica_remoteauth();
3431 * Test the api_friendica_remoteauth() function with a correct URL.
3434 public function testApiFriendicaRemoteauthWithCorrectUrl()
3436 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3437 $_GET['url'] = 'url';
3438 $_GET['c_url'] = $this->selfUser['nurl'];
3439 api_friendica_remoteauth();
3443 * Test the api_share_as_retweet() function.
3446 public function testApiShareAsRetweet()
3448 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3449 $result = api_share_as_retweet($item);
3450 $this->assertFalse($result);
3454 * Test the api_share_as_retweet() function with a valid item.
3457 public function testApiShareAsRetweetWithValidItem()
3459 $this->markTestIncomplete();
3463 * Test the api_get_nick() function.
3466 public function testApiGetNick()
3468 $result = api_get_nick($this->otherUser['nurl']);
3469 $this->assertEquals('othercontact', $result);
3473 * Test the api_get_nick() function with a wrong URL.
3476 public function testApiGetNickWithWrongUrl()
3478 $result = api_get_nick('wrong_url');
3479 $this->assertFalse($result);
3483 * Test the api_in_reply_to() function.
3486 public function testApiInReplyTo()
3488 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3489 $this->assertArrayHasKey('status_id', $result);
3490 $this->assertArrayHasKey('user_id', $result);
3491 $this->assertArrayHasKey('status_id_str', $result);
3492 $this->assertArrayHasKey('user_id_str', $result);
3493 $this->assertArrayHasKey('screen_name', $result);
3497 * Test the api_in_reply_to() function with a valid item.
3500 public function testApiInReplyToWithValidItem()
3502 $this->markTestIncomplete();
3506 * Test the api_clean_plain_items() function.
3509 public function testApiCleanPlainItems()
3511 $_REQUEST['include_entities'] = 'true';
3512 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3513 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3517 * Test the api_clean_attachments() function.
3520 public function testApiCleanAttachments()
3522 $this->markTestIncomplete();
3526 * Test the api_best_nickname() function.
3529 public function testApiBestNickname()
3532 $result = api_best_nickname($contacts);
3533 $this->assertNull($result);
3537 * Test the api_best_nickname() function with contacts.
3540 public function testApiBestNicknameWithContacts()
3542 $this->markTestIncomplete();
3546 * Test the api_friendica_group_show() function.
3549 public function testApiFriendicaGroupShow()
3551 $this->markTestIncomplete();
3555 * Test the api_friendica_group_delete() function.
3558 public function testApiFriendicaGroupDelete()
3560 $this->markTestIncomplete();
3564 * Test the api_lists_destroy() function.
3567 public function testApiListsDestroy()
3569 $this->markTestIncomplete();
3573 * Test the group_create() function.
3576 public function testGroupCreate()
3578 $this->markTestIncomplete();
3582 * Test the api_friendica_group_create() function.
3585 public function testApiFriendicaGroupCreate()
3587 $this->markTestIncomplete();
3591 * Test the api_lists_create() function.
3594 public function testApiListsCreate()
3596 $this->markTestIncomplete();
3600 * Test the api_friendica_group_update() function.
3603 public function testApiFriendicaGroupUpdate()
3605 $this->markTestIncomplete();
3609 * Test the api_lists_update() function.
3612 public function testApiListsUpdate()
3614 $this->markTestIncomplete();
3618 * Test the api_friendica_activity() function.
3621 public function testApiFriendicaActivity()
3623 $this->markTestIncomplete();
3627 * Test the api_friendica_notification() function.
3629 * @expectedException Friendica\Network\HTTPException\BadRequestException
3631 public function testApiFriendicaNotification()
3633 api_friendica_notification('json');
3637 * Test the api_friendica_notification() function without an authenticated user.
3639 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3641 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3643 $_SESSION['authenticated'] = false;
3644 api_friendica_notification('json');
3648 * Test the api_friendica_notification() function with an argument count.
3651 public function testApiFriendicaNotificationWithArgumentCount()
3653 $this->app->argv = ['api', 'friendica', 'notification'];
3654 $this->app->argc = count($this->app->argv);
3655 $result = api_friendica_notification('json');
3656 $this->assertEquals(['note' => false], $result);
3660 * Test the api_friendica_notification() function with an XML result.
3663 public function testApiFriendicaNotificationWithXmlResult()
3665 $this->app->argv = ['api', 'friendica', 'notification'];
3666 $this->app->argc = count($this->app->argv);
3667 $result = api_friendica_notification('xml');
3668 $this->assertXml($result, 'notes');
3672 * Test the api_friendica_notification_seen() function.
3675 public function testApiFriendicaNotificationSeen()
3677 $this->markTestIncomplete();
3681 * Test the api_friendica_direct_messages_setseen() function.
3684 public function testApiFriendicaDirectMessagesSetseen()
3686 $this->markTestIncomplete();
3690 * Test the api_friendica_direct_messages_search() function.
3693 public function testApiFriendicaDirectMessagesSearch()
3695 $this->markTestIncomplete();
3699 * Test the api_friendica_profile_show() function.
3702 public function testApiFriendicaProfileShow()
3704 $result = api_friendica_profile_show('json');
3705 // We can't use assertSelfUser() here because the user object is missing some properties.
3706 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3707 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3708 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3709 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3710 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3711 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3712 $this->assertFalse($result['$result']['multi_profiles']);
3716 * Test the api_friendica_profile_show() function with a profile ID.
3719 public function testApiFriendicaProfileShowWithProfileId()
3721 $this->markTestIncomplete('We need to add a dataset for this.');
3725 * Test the api_friendica_profile_show() function with a wrong profile ID.
3727 * @expectedException Friendica\Network\HTTPException\BadRequestException
3729 public function testApiFriendicaProfileShowWithWrongProfileId()
3731 $_REQUEST['profile_id'] = 666;
3732 api_friendica_profile_show('json');
3736 * Test the api_friendica_profile_show() function without an authenticated user.
3738 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3740 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3742 $_SESSION['authenticated'] = false;
3743 api_friendica_profile_show('json');
3747 * Test the api_saved_searches_list() function.
3750 public function testApiSavedSearchesList()
3752 $result = api_saved_searches_list('json');
3753 $this->assertEquals(1, $result['terms'][0]['id']);
3754 $this->assertEquals(1, $result['terms'][0]['id_str']);
3755 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3756 $this->assertEquals('Saved search', $result['terms'][0]['query']);