6 namespace Friendica\Test;
8 use Friendica\BaseObject;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Network\HTTPException;
14 use Friendica\Util\LoggerFactory;
15 use Monolog\Handler\TestHandler;
17 require_once __DIR__ . '/../../include/api.php';
20 * Tests for the API functions.
22 * Functions that use header() need to be tested in a separate process.
23 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
25 class ApiTest extends DatabaseTest
28 * @var TestHandler Can handle log-outputs
33 * Create variables used by tests.
35 public function setUp()
39 $this->app = BaseObject::getApp();
40 $this->logOutput = LoggerFactory::enableTest($this->app->getLogger());
42 // User data that the test database is populated with
45 'name' => 'Self contact',
46 'nick' => 'selfcontact',
47 'nurl' => 'http://localhost/profile/selfcontact'
51 'name' => 'Friend contact',
52 'nick' => 'friendcontact',
53 'nurl' => 'http://localhost/profile/friendcontact'
57 'name' => 'othercontact',
58 'nick' => 'othercontact',
59 'nurl' => 'http://localhost/profile/othercontact'
62 // User ID that we know is not in the database
63 $this->wrongUserId = 666;
65 // Most API require login so we force the session
68 'authenticated' => true,
69 'uid' => $this->selfUser['id']
72 Config::set('system', 'url', 'http://localhost');
73 Config::set('system', 'hostname', 'localhost');
74 Config::set('system', 'worker_dont_fork', true);
77 Config::set('config', 'hostname', 'localhost');
78 Config::set('system', 'throttle_limit_day', 100);
79 Config::set('system', 'throttle_limit_week', 100);
80 Config::set('system', 'throttle_limit_month', 100);
81 Config::set('system', 'theme', 'system_theme');
85 * Cleanup variables used by tests.
87 protected function tearDown()
92 $this->app->argv = ['home'];
96 * Assert that an user array contains expected keys.
97 * @param array $user User array
100 private function assertSelfUser(array $user)
102 $this->assertEquals($this->selfUser['id'], $user['uid']);
103 $this->assertEquals($this->selfUser['id'], $user['cid']);
104 $this->assertEquals(1, $user['self']);
105 $this->assertEquals('DFRN', $user['location']);
106 $this->assertEquals($this->selfUser['name'], $user['name']);
107 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
108 $this->assertEquals('dfrn', $user['network']);
109 $this->assertTrue($user['verified']);
113 * Assert that an user array contains expected keys.
114 * @param array $user User array
117 private function assertOtherUser(array $user)
119 $this->assertEquals($this->otherUser['id'], $user['id']);
120 $this->assertEquals($this->otherUser['id'], $user['id_str']);
121 $this->assertEquals(0, $user['self']);
122 $this->assertEquals($this->otherUser['name'], $user['name']);
123 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
124 $this->assertFalse($user['verified']);
128 * Assert that a status array contains expected keys.
129 * @param array $status Status array
132 private function assertStatus(array $status)
134 $this->assertInternalType('string', $status['text']);
135 $this->assertInternalType('int', $status['id']);
136 // We could probably do more checks here.
140 * Assert that a list array contains expected keys.
141 * @param array $list List array
144 private function assertList(array $list)
146 $this->assertInternalType('string', $list['name']);
147 $this->assertInternalType('int', $list['id']);
148 $this->assertInternalType('string', $list['id_str']);
149 $this->assertContains($list['mode'], ['public', 'private']);
150 // We could probably do more checks here.
154 * Assert that the string is XML and contain the root element.
155 * @param string $result XML string
156 * @param string $root_element Root element name
159 private function assertXml($result, $root_element)
161 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
162 $this->assertContains('<'.$root_element, $result);
163 // We could probably do more checks here.
167 * Get the path to a temporary empty PNG image.
168 * @return string Path
170 private function getTempImage()
172 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
176 // Empty 1x1 px PNG image
177 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
185 * Test the api_user() function.
188 public function testApiUser()
190 $this->assertEquals($this->selfUser['id'], api_user());
194 * Test the api_user() function with an unallowed user.
197 public function testApiUserWithUnallowedUser()
199 $_SESSION = ['allow_api' => false];
200 $this->assertEquals(false, api_user());
204 * Test the api_source() function.
207 public function testApiSource()
209 $this->assertEquals('api', api_source());
213 * Test the api_source() function with a Twidere user agent.
216 public function testApiSourceWithTwidere()
218 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
219 $this->assertEquals('Twidere', api_source());
223 * Test the api_source() function with a GET parameter.
226 public function testApiSourceWithGet()
228 $_GET['source'] = 'source_name';
229 $this->assertEquals('source_name', api_source());
233 * Test the api_date() function.
236 public function testApiDate()
238 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
242 * Test the api_register_func() function.
245 public function testApiRegisterFunc()
257 $this->assertTrue($API['api_path']['auth']);
258 $this->assertEquals('method', $API['api_path']['method']);
259 $this->assertTrue(is_callable($API['api_path']['func']));
263 * Test the api_login() function without any login.
265 * @runInSeparateProcess
266 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
268 public function testApiLoginWithoutLogin()
270 api_login($this->app);
274 * Test the api_login() function with a bad login.
276 * @runInSeparateProcess
277 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
279 public function testApiLoginWithBadLogin()
281 $_SERVER['PHP_AUTH_USER'] = 'user@server';
282 api_login($this->app);
286 * Test the api_login() function with oAuth.
289 public function testApiLoginWithOauth()
291 $this->markTestIncomplete('Can we test this easily?');
295 * Test the api_login() function with authentication provided by an addon.
298 public function testApiLoginWithAddonAuth()
300 $this->markTestIncomplete('Can we test this easily?');
304 * Test the api_login() function with a correct login.
306 * @runInSeparateProcess
308 public function testApiLoginWithCorrectLogin()
310 $_SERVER['PHP_AUTH_USER'] = 'Test user';
311 $_SERVER['PHP_AUTH_PW'] = 'password';
312 api_login($this->app);
316 * Test the api_login() function with a remote user.
318 * @runInSeparateProcess
319 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
321 public function testApiLoginWithRemoteUser()
323 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
324 api_login($this->app);
328 * Test the api_check_method() function.
331 public function testApiCheckMethod()
333 $this->assertFalse(api_check_method('method'));
337 * Test the api_check_method() function with a correct method.
340 public function testApiCheckMethodWithCorrectMethod()
342 $_SERVER['REQUEST_METHOD'] = 'method';
343 $this->assertTrue(api_check_method('method'));
347 * Test the api_check_method() function with a wildcard.
350 public function testApiCheckMethodWithWildcard()
352 $this->assertTrue(api_check_method('*'));
356 * Test the api_call() function.
358 * @runInSeparateProcess
360 public function testApiCall()
364 'method' => 'method',
365 'func' => function () {
366 return ['data' => ['some_data']];
369 $_SERVER['REQUEST_METHOD'] = 'method';
370 $_GET['callback'] = 'callback_name';
372 $this->app->query_string = 'api_path';
374 'callback_name(["some_data"])',
380 * Test the api_call() function with the profiled enabled.
382 * @runInSeparateProcess
384 public function testApiCallWithProfiler()
388 'method' => 'method',
389 'func' => function () {
390 return ['data' => ['some_data']];
393 $_SERVER['REQUEST_METHOD'] = 'method';
394 Config::set('system', 'profiler', true);
395 Config::set('rendertime', 'callstack', true);
396 $this->app->callstack = [
397 'database' => ['some_function' => 200],
398 'database_write' => ['some_function' => 200],
399 'cache' => ['some_function' => 200],
400 'cache_write' => ['some_function' => 200],
401 'network' => ['some_function' => 200]
404 $this->app->query_string = 'api_path';
412 * Test the api_call() function without any result.
414 * @runInSeparateProcess
416 public function testApiCallWithNoResult()
420 'method' => 'method',
421 'func' => function () {
425 $_SERVER['REQUEST_METHOD'] = 'method';
427 $this->app->query_string = 'api_path';
429 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
435 * Test the api_call() function with an unimplemented API.
437 * @runInSeparateProcess
439 public function testApiCallWithUninplementedApi()
442 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
448 * Test the api_call() function with a JSON result.
450 * @runInSeparateProcess
452 public function testApiCallWithJson()
456 'method' => 'method',
457 'func' => function () {
458 return ['data' => ['some_data']];
461 $_SERVER['REQUEST_METHOD'] = 'method';
463 $this->app->query_string = 'api_path.json';
471 * Test the api_call() function with an XML result.
473 * @runInSeparateProcess
475 public function testApiCallWithXml()
479 'method' => 'method',
480 'func' => function () {
484 $_SERVER['REQUEST_METHOD'] = 'method';
486 $this->app->query_string = 'api_path.xml';
494 * Test the api_call() function with an RSS result.
496 * @runInSeparateProcess
498 public function testApiCallWithRss()
502 'method' => 'method',
503 'func' => function () {
507 $_SERVER['REQUEST_METHOD'] = 'method';
509 $this->app->query_string = 'api_path.rss';
511 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
518 * Test the api_call() function with an Atom result.
520 * @runInSeparateProcess
522 public function testApiCallWithAtom()
526 'method' => 'method',
527 'func' => function () {
531 $_SERVER['REQUEST_METHOD'] = 'method';
533 $this->app->query_string = 'api_path.atom';
535 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
542 * Test the api_call() function with an unallowed method.
544 * @runInSeparateProcess
546 public function testApiCallWithWrongMethod()
549 $API['api_path'] = ['method' => 'method'];
551 $this->app->query_string = 'api_path';
553 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
559 * Test the api_call() function with an unauthorized user.
561 * @runInSeparateProcess
563 public function testApiCallWithWrongAuth()
567 'method' => 'method',
570 $_SERVER['REQUEST_METHOD'] = 'method';
571 $_SESSION['authenticated'] = false;
573 $this->app->query_string = 'api_path';
575 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
581 * Test the api_error() function with a JSON result.
583 * @runInSeparateProcess
585 public function testApiErrorWithJson()
588 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
589 api_error('json', new HTTPException('error_message'))
594 * Test the api_error() function with an XML result.
596 * @runInSeparateProcess
598 public function testApiErrorWithXml()
601 '<?xml version="1.0"?>'."\n".
602 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
603 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
604 'xmlns:georss="http://www.georss.org/georss">'."\n".
605 ' <error>error_message</error>'."\n".
606 ' <code>200 Friendica\Network\HTTP</code>'."\n".
609 api_error('xml', new HTTPException('error_message'))
614 * Test the api_error() function with an RSS result.
616 * @runInSeparateProcess
618 public function testApiErrorWithRss()
621 '<?xml version="1.0"?>'."\n".
622 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
623 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
624 'xmlns:georss="http://www.georss.org/georss">'."\n".
625 ' <error>error_message</error>'."\n".
626 ' <code>200 Friendica\Network\HTTP</code>'."\n".
629 api_error('rss', new HTTPException('error_message'))
634 * Test the api_error() function with an Atom result.
636 * @runInSeparateProcess
638 public function testApiErrorWithAtom()
641 '<?xml version="1.0"?>'."\n".
642 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
643 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
644 'xmlns:georss="http://www.georss.org/georss">'."\n".
645 ' <error>error_message</error>'."\n".
646 ' <code>200 Friendica\Network\HTTP</code>'."\n".
649 api_error('atom', new HTTPException('error_message'))
654 * Test the api_rss_extra() function.
657 public function testApiRssExtra()
659 $user_info = ['url' => 'user_url', 'lang' => 'en'];
660 $result = api_rss_extra($this->app, [], $user_info);
661 $this->assertEquals($user_info, $result['$user']);
662 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
663 $this->assertArrayHasKey('self', $result['$rss']);
664 $this->assertArrayHasKey('base', $result['$rss']);
665 $this->assertArrayHasKey('updated', $result['$rss']);
666 $this->assertArrayHasKey('atom_updated', $result['$rss']);
667 $this->assertArrayHasKey('language', $result['$rss']);
668 $this->assertArrayHasKey('logo', $result['$rss']);
672 * Test the api_rss_extra() function without any user info.
674 * @runInSeparateProcess
676 public function testApiRssExtraWithoutUserInfo()
678 $result = api_rss_extra($this->app, [], null);
679 $this->assertInternalType('array', $result['$user']);
680 $this->assertArrayHasKey('alternate', $result['$rss']);
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_unique_id_to_nurl() function.
693 public function testApiUniqueIdToNurl()
695 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
699 * Test the api_unique_id_to_nurl() function with a correct ID.
702 public function testApiUniqueIdToNurlWithCorrectId()
704 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
708 * Test the api_get_user() function.
710 * @runInSeparateProcess
712 public function testApiGetUser()
714 $user = api_get_user($this->app);
715 $this->assertSelfUser($user);
716 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
717 $this->assertEquals('6fdbe8', $user['profile_link_color']);
718 $this->assertEquals('ededed', $user['profile_background_color']);
722 * Test the api_get_user() function with a Frio schema.
724 * @runInSeparateProcess
726 public function testApiGetUserWithFrioSchema()
728 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
729 $user = api_get_user($this->app);
730 $this->assertSelfUser($user);
731 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
732 $this->assertEquals('6fdbe8', $user['profile_link_color']);
733 $this->assertEquals('ededed', $user['profile_background_color']);
737 * Test the api_get_user() function with a custom Frio schema.
739 * @runInSeparateProcess
741 public function testApiGetUserWithCustomFrioSchema()
743 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
744 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
745 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
746 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
747 $user = api_get_user($this->app);
748 $this->assertSelfUser($user);
749 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
750 $this->assertEquals('123456', $user['profile_link_color']);
751 $this->assertEquals('123456', $user['profile_background_color']);
755 * Test the api_get_user() function with an empty Frio schema.
757 * @runInSeparateProcess
759 public function testApiGetUserWithEmptyFrioSchema()
761 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
762 $user = api_get_user($this->app);
763 $this->assertSelfUser($user);
764 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
765 $this->assertEquals('6fdbe8', $user['profile_link_color']);
766 $this->assertEquals('ededed', $user['profile_background_color']);
770 * Test the api_get_user() function with an user that is not allowed to use the API.
772 * @runInSeparateProcess
774 public function testApiGetUserWithoutApiUser()
776 $_SERVER['PHP_AUTH_USER'] = 'Test user';
777 $_SERVER['PHP_AUTH_PW'] = 'password';
778 $_SESSION['allow_api'] = false;
779 $this->assertFalse(api_get_user($this->app));
783 * Test the api_get_user() function with an user ID in a GET parameter.
785 * @runInSeparateProcess
787 public function testApiGetUserWithGetId()
789 $_GET['user_id'] = $this->otherUser['id'];
790 $this->assertOtherUser(api_get_user($this->app));
794 * Test the api_get_user() function with a wrong user ID in a GET parameter.
796 * @runInSeparateProcess
797 * @expectedException Friendica\Network\HTTPException\BadRequestException
799 public function testApiGetUserWithWrongGetId()
801 $_GET['user_id'] = $this->wrongUserId;
802 $this->assertOtherUser(api_get_user($this->app));
806 * Test the api_get_user() function with an user name in a GET parameter.
808 * @runInSeparateProcess
810 public function testApiGetUserWithGetName()
812 $_GET['screen_name'] = $this->selfUser['nick'];
813 $this->assertSelfUser(api_get_user($this->app));
817 * Test the api_get_user() function with a profile URL in a GET parameter.
819 * @runInSeparateProcess
821 public function testApiGetUserWithGetUrl()
823 $_GET['profileurl'] = $this->selfUser['nurl'];
824 $this->assertSelfUser(api_get_user($this->app));
828 * Test the api_get_user() function with an user ID in the API path.
830 * @runInSeparateProcess
832 public function testApiGetUserWithNumericCalledApi()
835 $called_api = ['api_path'];
836 $this->app->argv[1] = $this->otherUser['id'].'.json';
837 $this->assertOtherUser(api_get_user($this->app));
841 * Test the api_get_user() function with the $called_api global variable.
843 * @runInSeparateProcess
845 public function testApiGetUserWithCalledApi()
848 $called_api = ['api', 'api_path'];
849 $this->assertSelfUser(api_get_user($this->app));
853 * Test the api_get_user() function with a valid user.
855 * @runInSeparateProcess
857 public function testApiGetUserWithCorrectUser()
859 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
863 * Test the api_get_user() function with a wrong user ID.
865 * @runInSeparateProcess
866 * @expectedException Friendica\Network\HTTPException\BadRequestException
868 public function testApiGetUserWithWrongUser()
870 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
874 * Test the api_get_user() function with a 0 user ID.
876 * @runInSeparateProcess
878 public function testApiGetUserWithZeroUser()
880 $this->assertSelfUser(api_get_user($this->app, 0));
884 * Test the api_item_get_user() function.
886 * @runInSeparateProcess
888 public function testApiItemGetUser()
890 $users = api_item_get_user($this->app, []);
891 $this->assertSelfUser($users[0]);
895 * Test the api_item_get_user() function with a different item parent.
898 public function testApiItemGetUserWithDifferentParent()
900 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
901 $this->assertSelfUser($users[0]);
902 $this->assertEquals($users[0], $users[1]);
906 * Test the api_walk_recursive() function.
909 public function testApiWalkRecursive()
917 // Should we test this with a callback that actually does something?
925 * Test the api_walk_recursive() function with an array.
928 public function testApiWalkRecursiveWithArray()
930 $array = [['item1'], ['item2']];
936 // Should we test this with a callback that actually does something?
944 * Test the api_reformat_xml() function.
947 public function testApiReformatXml()
951 $this->assertTrue(api_reformat_xml($item, $key));
952 $this->assertEquals('true', $item);
956 * Test the api_reformat_xml() function with a statusnet_api key.
959 public function testApiReformatXmlWithStatusnetKey()
962 $key = 'statusnet_api';
963 $this->assertTrue(api_reformat_xml($item, $key));
964 $this->assertEquals('statusnet:api', $key);
968 * Test the api_reformat_xml() function with a friendica_api key.
971 public function testApiReformatXmlWithFriendicaKey()
974 $key = 'friendica_api';
975 $this->assertTrue(api_reformat_xml($item, $key));
976 $this->assertEquals('friendica:api', $key);
980 * Test the api_create_xml() function.
983 public function testApiCreateXml()
986 '<?xml version="1.0"?>'."\n".
987 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
988 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
989 'xmlns:georss="http://www.georss.org/georss">'."\n".
990 ' <data>some_data</data>'."\n".
991 '</root_element>'."\n",
992 api_create_xml(['data' => ['some_data']], 'root_element')
997 * Test the api_create_xml() function without any XML namespace.
1000 public function testApiCreateXmlWithoutNamespaces()
1002 $this->assertEquals(
1003 '<?xml version="1.0"?>'."\n".
1005 ' <data>some_data</data>'."\n".
1007 api_create_xml(['data' => ['some_data']], 'ok')
1012 * Test the api_format_data() function.
1015 public function testApiFormatData()
1017 $data = ['some_data'];
1018 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1022 * Test the api_format_data() function with an XML result.
1025 public function testApiFormatDataWithXml()
1027 $this->assertEquals(
1028 '<?xml version="1.0"?>'."\n".
1029 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1030 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1031 'xmlns:georss="http://www.georss.org/georss">'."\n".
1032 ' <data>some_data</data>'."\n".
1033 '</root_element>'."\n",
1034 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1039 * Test the api_account_verify_credentials() function.
1042 public function testApiAccountVerifyCredentials()
1044 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1048 * Test the api_account_verify_credentials() function without an authenticated user.
1050 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1052 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1054 $_SESSION['authenticated'] = false;
1055 api_account_verify_credentials('json');
1059 * Test the requestdata() function.
1062 public function testRequestdata()
1064 $this->assertNull(requestdata('variable_name'));
1068 * Test the requestdata() function with a POST parameter.
1071 public function testRequestdataWithPost()
1073 $_POST['variable_name'] = 'variable_value';
1074 $this->assertEquals('variable_value', requestdata('variable_name'));
1078 * Test the requestdata() function with a GET parameter.
1081 public function testRequestdataWithGet()
1083 $_GET['variable_name'] = 'variable_value';
1084 $this->assertEquals('variable_value', requestdata('variable_name'));
1088 * Test the api_statuses_mediap() function.
1091 public function testApiStatusesMediap()
1093 $this->app->argc = 2;
1101 'tmp_name' => $this->getTempImage(),
1102 'name' => 'spacer.png',
1103 'type' => 'image/png'
1106 $_GET['status'] = '<b>Status content</b>';
1108 $result = api_statuses_mediap('json');
1109 $this->assertStatus($result['status']);
1113 * Test the api_statuses_mediap() function without an authenticated user.
1115 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1117 public function testApiStatusesMediapWithoutAuthenticatedUser()
1119 $_SESSION['authenticated'] = false;
1120 api_statuses_mediap('json');
1124 * Test the api_statuses_update() function.
1127 public function testApiStatusesUpdate()
1129 $_GET['status'] = 'Status content #friendica';
1130 $_GET['in_reply_to_status_id'] = -1;
1139 'tmp_name' => $this->getTempImage(),
1140 'name' => 'spacer.png',
1141 'type' => 'image/png'
1145 $result = api_statuses_update('json');
1146 $this->assertStatus($result['status']);
1150 * Test the api_statuses_update() function with an HTML status.
1153 public function testApiStatusesUpdateWithHtml()
1155 $_GET['htmlstatus'] = '<b>Status content</b>';
1157 $result = api_statuses_update('json');
1158 $this->assertStatus($result['status']);
1162 * Test the api_statuses_update() function without an authenticated user.
1164 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1166 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1168 $_SESSION['authenticated'] = false;
1169 api_statuses_update('json');
1173 * Test the api_statuses_update() function with a parent status.
1176 public function testApiStatusesUpdateWithParent()
1178 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1182 * Test the api_statuses_update() function with a media_ids parameter.
1185 public function testApiStatusesUpdateWithMediaIds()
1187 $this->markTestIncomplete();
1191 * Test the api_statuses_update() function with the throttle limit reached.
1194 public function testApiStatusesUpdateWithDayThrottleReached()
1196 $this->markTestIncomplete();
1200 * Test the api_media_upload() function.
1202 * @expectedException Friendica\Network\HTTPException\BadRequestException
1204 public function testApiMediaUpload()
1210 * Test the api_media_upload() function without an authenticated user.
1212 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1214 public function testApiMediaUploadWithoutAuthenticatedUser()
1216 $_SESSION['authenticated'] = false;
1221 * Test the api_media_upload() function with an invalid uploaded media.
1223 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1225 public function testApiMediaUploadWithMedia()
1230 'tmp_name' => 'tmp_name'
1237 * Test the api_media_upload() function with an valid uploaded media.
1240 public function testApiMediaUploadWithValidMedia()
1248 'tmp_name' => $this->getTempImage(),
1249 'name' => 'spacer.png',
1250 'type' => 'image/png'
1256 $result = api_media_upload();
1257 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1258 $this->assertEquals(1, $result['media']['image']['w']);
1259 $this->assertEquals(1, $result['media']['image']['h']);
1260 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1264 * Test the api_status_show() function.
1267 public function testApiStatusShow()
1269 $result = api_status_show('json');
1270 $this->assertStatus($result['status']);
1274 * Test the api_status_show() function with an XML result.
1277 public function testApiStatusShowWithXml()
1279 $result = api_status_show('xml');
1280 $this->assertXml($result, 'statuses');
1284 * Test the api_status_show() function with a raw result.
1287 public function testApiStatusShowWithRaw()
1289 $this->assertStatus(api_status_show('raw'));
1293 * Test the api_users_show() function.
1296 public function testApiUsersShow()
1298 $result = api_users_show('json');
1299 // We can't use assertSelfUser() here because the user object is missing some properties.
1300 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1301 $this->assertEquals('DFRN', $result['user']['location']);
1302 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1303 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1304 $this->assertEquals('dfrn', $result['user']['network']);
1305 $this->assertTrue($result['user']['verified']);
1309 * Test the api_users_show() function with an XML result.
1312 public function testApiUsersShowWithXml()
1314 $result = api_users_show('xml');
1315 $this->assertXml($result, 'statuses');
1319 * Test the api_users_search() function.
1322 public function testApiUsersSearch()
1324 $_GET['q'] = 'othercontact';
1325 $result = api_users_search('json');
1326 $this->assertOtherUser($result['users'][0]);
1330 * Test the api_users_search() function with an XML result.
1333 public function testApiUsersSearchWithXml()
1335 $_GET['q'] = 'othercontact';
1336 $result = api_users_search('xml');
1337 $this->assertXml($result, 'users');
1341 * Test the api_users_search() function without a GET q parameter.
1343 * @expectedException Friendica\Network\HTTPException\BadRequestException
1345 public function testApiUsersSearchWithoutQuery()
1347 api_users_search('json');
1351 * Test the api_users_lookup() function.
1353 * @expectedException Friendica\Network\HTTPException\NotFoundException
1355 public function testApiUsersLookup()
1357 api_users_lookup('json');
1361 * Test the api_users_lookup() function with an user ID.
1364 public function testApiUsersLookupWithUserId()
1366 $_REQUEST['user_id'] = $this->otherUser['id'];
1367 $result = api_users_lookup('json');
1368 $this->assertOtherUser($result['users'][0]);
1372 * Test the api_search() function.
1375 public function testApiSearch()
1377 $_REQUEST['q'] = 'reply';
1378 $_REQUEST['max_id'] = 10;
1379 $result = api_search('json');
1380 foreach ($result['status'] as $status) {
1381 $this->assertStatus($status);
1382 $this->assertContains('reply', $status['text'], null, true);
1387 * Test the api_search() function a count parameter.
1390 public function testApiSearchWithCount()
1392 $_REQUEST['q'] = 'reply';
1393 $_REQUEST['count'] = 20;
1394 $result = api_search('json');
1395 foreach ($result['status'] as $status) {
1396 $this->assertStatus($status);
1397 $this->assertContains('reply', $status['text'], null, true);
1402 * Test the api_search() function with an rpp parameter.
1405 public function testApiSearchWithRpp()
1407 $_REQUEST['q'] = 'reply';
1408 $_REQUEST['rpp'] = 20;
1409 $result = api_search('json');
1410 foreach ($result['status'] as $status) {
1411 $this->assertStatus($status);
1412 $this->assertContains('reply', $status['text'], null, true);
1417 * Test the api_search() function with an q parameter contains hashtag.
1420 public function testApiSearchWithHashtag()
1422 $_REQUEST['q'] = '%23friendica';
1423 $result = api_search('json');
1424 foreach ($result['status'] as $status) {
1425 $this->assertStatus($status);
1426 $this->assertContains('#friendica', $status['text'], null, true);
1431 * Test the api_search() function with an exclude_replies parameter.
1434 public function testApiSearchWithExcludeReplies()
1436 $_REQUEST['max_id'] = 10;
1437 $_REQUEST['exclude_replies'] = true;
1438 $_REQUEST['q'] = 'friendica';
1439 $result = api_search('json');
1440 foreach ($result['status'] as $status) {
1441 $this->assertStatus($status);
1446 * Test the api_search() function without an authenticated user.
1448 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1450 public function testApiSearchWithUnallowedUser()
1452 $_SESSION['allow_api'] = false;
1453 $_GET['screen_name'] = $this->selfUser['nick'];
1458 * Test the api_search() function without any GET query parameter.
1460 * @expectedException Friendica\Network\HTTPException\BadRequestException
1462 public function testApiSearchWithoutQuery()
1468 * Test the api_statuses_home_timeline() function.
1471 public function testApiStatusesHomeTimeline()
1473 $_REQUEST['max_id'] = 10;
1474 $_REQUEST['exclude_replies'] = true;
1475 $_REQUEST['conversation_id'] = 1;
1476 $result = api_statuses_home_timeline('json');
1477 $this->assertNotEmpty($result['status']);
1478 foreach ($result['status'] as $status) {
1479 $this->assertStatus($status);
1484 * Test the api_statuses_home_timeline() function with a negative page parameter.
1487 public function testApiStatusesHomeTimelineWithNegativePage()
1489 $_REQUEST['page'] = -2;
1490 $result = api_statuses_home_timeline('json');
1491 $this->assertNotEmpty($result['status']);
1492 foreach ($result['status'] as $status) {
1493 $this->assertStatus($status);
1498 * Test the api_statuses_home_timeline() with an unallowed user.
1500 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1502 public function testApiStatusesHomeTimelineWithUnallowedUser()
1504 $_SESSION['allow_api'] = false;
1505 $_GET['screen_name'] = $this->selfUser['nick'];
1506 api_statuses_home_timeline('json');
1510 * Test the api_statuses_home_timeline() function with an RSS result.
1513 public function testApiStatusesHomeTimelineWithRss()
1515 $result = api_statuses_home_timeline('rss');
1516 $this->assertXml($result, 'statuses');
1520 * Test the api_statuses_public_timeline() function.
1523 public function testApiStatusesPublicTimeline()
1525 $_REQUEST['max_id'] = 10;
1526 $_REQUEST['conversation_id'] = 1;
1527 $result = api_statuses_public_timeline('json');
1528 $this->assertNotEmpty($result['status']);
1529 foreach ($result['status'] as $status) {
1530 $this->assertStatus($status);
1535 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1538 public function testApiStatusesPublicTimelineWithExcludeReplies()
1540 $_REQUEST['max_id'] = 10;
1541 $_REQUEST['exclude_replies'] = true;
1542 $result = api_statuses_public_timeline('json');
1543 $this->assertNotEmpty($result['status']);
1544 foreach ($result['status'] as $status) {
1545 $this->assertStatus($status);
1550 * Test the api_statuses_public_timeline() function with a negative page parameter.
1553 public function testApiStatusesPublicTimelineWithNegativePage()
1555 $_REQUEST['page'] = -2;
1556 $result = api_statuses_public_timeline('json');
1557 $this->assertNotEmpty($result['status']);
1558 foreach ($result['status'] as $status) {
1559 $this->assertStatus($status);
1564 * Test the api_statuses_public_timeline() function with an unallowed user.
1566 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1568 public function testApiStatusesPublicTimelineWithUnallowedUser()
1570 $_SESSION['allow_api'] = false;
1571 $_GET['screen_name'] = $this->selfUser['nick'];
1572 api_statuses_public_timeline('json');
1576 * Test the api_statuses_public_timeline() function with an RSS result.
1579 public function testApiStatusesPublicTimelineWithRss()
1581 $result = api_statuses_public_timeline('rss');
1582 $this->assertXml($result, 'statuses');
1586 * Test the api_statuses_networkpublic_timeline() function.
1589 public function testApiStatusesNetworkpublicTimeline()
1591 $_REQUEST['max_id'] = 10;
1592 $result = api_statuses_networkpublic_timeline('json');
1593 $this->assertNotEmpty($result['status']);
1594 foreach ($result['status'] as $status) {
1595 $this->assertStatus($status);
1600 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1603 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1605 $_REQUEST['page'] = -2;
1606 $result = api_statuses_networkpublic_timeline('json');
1607 $this->assertNotEmpty($result['status']);
1608 foreach ($result['status'] as $status) {
1609 $this->assertStatus($status);
1614 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1616 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1618 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1620 $_SESSION['allow_api'] = false;
1621 $_GET['screen_name'] = $this->selfUser['nick'];
1622 api_statuses_networkpublic_timeline('json');
1626 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1629 public function testApiStatusesNetworkpublicTimelineWithRss()
1631 $result = api_statuses_networkpublic_timeline('rss');
1632 $this->assertXml($result, 'statuses');
1636 * Test the api_statuses_show() function.
1638 * @expectedException Friendica\Network\HTTPException\BadRequestException
1640 public function testApiStatusesShow()
1642 api_statuses_show('json');
1646 * Test the api_statuses_show() function with an ID.
1649 public function testApiStatusesShowWithId()
1651 $this->app->argv[3] = 1;
1652 $result = api_statuses_show('json');
1653 $this->assertStatus($result['status']);
1657 * Test the api_statuses_show() function with the conversation parameter.
1660 public function testApiStatusesShowWithConversation()
1662 $this->app->argv[3] = 1;
1663 $_REQUEST['conversation'] = 1;
1664 $result = api_statuses_show('json');
1665 $this->assertNotEmpty($result['status']);
1666 foreach ($result['status'] as $status) {
1667 $this->assertStatus($status);
1672 * Test the api_statuses_show() function with an unallowed user.
1674 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1676 public function testApiStatusesShowWithUnallowedUser()
1678 $_SESSION['allow_api'] = false;
1679 $_GET['screen_name'] = $this->selfUser['nick'];
1680 api_statuses_show('json');
1684 * Test the api_conversation_show() function.
1686 * @expectedException Friendica\Network\HTTPException\BadRequestException
1688 public function testApiConversationShow()
1690 api_conversation_show('json');
1694 * Test the api_conversation_show() function with an ID.
1697 public function testApiConversationShowWithId()
1699 $this->app->argv[3] = 1;
1700 $_REQUEST['max_id'] = 10;
1701 $_REQUEST['page'] = -2;
1702 $result = api_conversation_show('json');
1703 $this->assertNotEmpty($result['status']);
1704 foreach ($result['status'] as $status) {
1705 $this->assertStatus($status);
1710 * Test the api_conversation_show() function with an unallowed user.
1712 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1714 public function testApiConversationShowWithUnallowedUser()
1716 $_SESSION['allow_api'] = false;
1717 $_GET['screen_name'] = $this->selfUser['nick'];
1718 api_conversation_show('json');
1722 * Test the api_statuses_repeat() function.
1724 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1726 public function testApiStatusesRepeat()
1728 api_statuses_repeat('json');
1732 * Test the api_statuses_repeat() function without an authenticated user.
1734 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1736 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1738 $_SESSION['authenticated'] = false;
1739 api_statuses_repeat('json');
1743 * Test the api_statuses_repeat() function with an ID.
1746 public function testApiStatusesRepeatWithId()
1748 $this->app->argv[3] = 1;
1749 $result = api_statuses_repeat('json');
1750 $this->assertStatus($result['status']);
1752 // Also test with a shared status
1753 $this->app->argv[3] = 5;
1754 $result = api_statuses_repeat('json');
1755 $this->assertStatus($result['status']);
1759 * Test the api_statuses_destroy() function.
1761 * @expectedException Friendica\Network\HTTPException\BadRequestException
1763 public function testApiStatusesDestroy()
1765 api_statuses_destroy('json');
1769 * Test the api_statuses_destroy() function without an authenticated user.
1771 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1773 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1775 $_SESSION['authenticated'] = false;
1776 api_statuses_destroy('json');
1780 * Test the api_statuses_destroy() function with an ID.
1783 public function testApiStatusesDestroyWithId()
1785 $this->app->argv[3] = 1;
1786 $result = api_statuses_destroy('json');
1787 $this->assertStatus($result['status']);
1791 * Test the api_statuses_mentions() function.
1794 public function testApiStatusesMentions()
1796 $this->app->user = ['nickname' => $this->selfUser['nick']];
1797 $_REQUEST['max_id'] = 10;
1798 $result = api_statuses_mentions('json');
1799 $this->assertEmpty($result['status']);
1800 // We should test with mentions in the database.
1804 * Test the api_statuses_mentions() function with a negative page parameter.
1807 public function testApiStatusesMentionsWithNegativePage()
1809 $_REQUEST['page'] = -2;
1810 $result = api_statuses_mentions('json');
1811 $this->assertEmpty($result['status']);
1815 * Test the api_statuses_mentions() function with an unallowed user.
1817 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1819 public function testApiStatusesMentionsWithUnallowedUser()
1821 $_SESSION['allow_api'] = false;
1822 $_GET['screen_name'] = $this->selfUser['nick'];
1823 api_statuses_mentions('json');
1827 * Test the api_statuses_mentions() function with an RSS result.
1830 public function testApiStatusesMentionsWithRss()
1832 $result = api_statuses_mentions('rss');
1833 $this->assertXml($result, 'statuses');
1837 * Test the api_statuses_user_timeline() function.
1840 public function testApiStatusesUserTimeline()
1842 $_REQUEST['max_id'] = 10;
1843 $_REQUEST['exclude_replies'] = true;
1844 $_REQUEST['conversation_id'] = 1;
1845 $result = api_statuses_user_timeline('json');
1846 $this->assertNotEmpty($result['status']);
1847 foreach ($result['status'] as $status) {
1848 $this->assertStatus($status);
1853 * Test the api_statuses_user_timeline() function with a negative page parameter.
1856 public function testApiStatusesUserTimelineWithNegativePage()
1858 $_REQUEST['page'] = -2;
1859 $result = api_statuses_user_timeline('json');
1860 $this->assertNotEmpty($result['status']);
1861 foreach ($result['status'] as $status) {
1862 $this->assertStatus($status);
1867 * Test the api_statuses_user_timeline() function with an RSS result.
1870 public function testApiStatusesUserTimelineWithRss()
1872 $result = api_statuses_user_timeline('rss');
1873 $this->assertXml($result, 'statuses');
1877 * Test the api_statuses_user_timeline() function with an unallowed user.
1879 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1881 public function testApiStatusesUserTimelineWithUnallowedUser()
1883 $_SESSION['allow_api'] = false;
1884 $_GET['screen_name'] = $this->selfUser['nick'];
1885 api_statuses_user_timeline('json');
1889 * Test the api_favorites_create_destroy() function.
1891 * @expectedException Friendica\Network\HTTPException\BadRequestException
1893 public function testApiFavoritesCreateDestroy()
1895 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1896 $this->app->argc = count($this->app->argv);
1897 api_favorites_create_destroy('json');
1901 * Test the api_favorites_create_destroy() function with an invalid ID.
1903 * @expectedException Friendica\Network\HTTPException\BadRequestException
1905 public function testApiFavoritesCreateDestroyWithInvalidId()
1907 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1908 $this->app->argc = count($this->app->argv);
1909 api_favorites_create_destroy('json');
1913 * Test the api_favorites_create_destroy() function with an invalid action.
1915 * @expectedException Friendica\Network\HTTPException\BadRequestException
1917 public function testApiFavoritesCreateDestroyWithInvalidAction()
1919 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1920 $this->app->argc = count($this->app->argv);
1921 $_REQUEST['id'] = 1;
1922 api_favorites_create_destroy('json');
1926 * Test the api_favorites_create_destroy() function with the create action.
1929 public function testApiFavoritesCreateDestroyWithCreateAction()
1931 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1932 $this->app->argc = count($this->app->argv);
1933 $_REQUEST['id'] = 3;
1934 $result = api_favorites_create_destroy('json');
1935 $this->assertStatus($result['status']);
1939 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1942 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1944 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1945 $this->app->argc = count($this->app->argv);
1946 $_REQUEST['id'] = 3;
1947 $result = api_favorites_create_destroy('rss');
1948 $this->assertXml($result, 'status');
1952 * Test the api_favorites_create_destroy() function with the destroy action.
1955 public function testApiFavoritesCreateDestroyWithDestroyAction()
1957 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1958 $this->app->argc = count($this->app->argv);
1959 $_REQUEST['id'] = 3;
1960 $result = api_favorites_create_destroy('json');
1961 $this->assertStatus($result['status']);
1965 * Test the api_favorites_create_destroy() function without an authenticated user.
1967 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1969 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1971 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1972 $this->app->argc = count($this->app->argv);
1973 $_SESSION['authenticated'] = false;
1974 api_favorites_create_destroy('json');
1978 * Test the api_favorites() function.
1981 public function testApiFavorites()
1983 $_REQUEST['page'] = -1;
1984 $_REQUEST['max_id'] = 10;
1985 $result = api_favorites('json');
1986 foreach ($result['status'] as $status) {
1987 $this->assertStatus($status);
1992 * Test the api_favorites() function with an RSS result.
1995 public function testApiFavoritesWithRss()
1997 $result = api_favorites('rss');
1998 $this->assertXml($result, 'statuses');
2002 * Test the api_favorites() function with an unallowed user.
2004 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2006 public function testApiFavoritesWithUnallowedUser()
2008 $_SESSION['allow_api'] = false;
2009 $_GET['screen_name'] = $this->selfUser['nick'];
2010 api_favorites('json');
2014 * Test the api_format_messages() function.
2017 public function testApiFormatMessages()
2019 $result = api_format_messages(
2020 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2021 ['id' => 2, 'screen_name' => 'recipient_name'],
2022 ['id' => 3, 'screen_name' => 'sender_name']
2024 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2025 $this->assertEquals(1, $result['id']);
2026 $this->assertEquals(2, $result['recipient_id']);
2027 $this->assertEquals(3, $result['sender_id']);
2028 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2029 $this->assertEquals('sender_name', $result['sender_screen_name']);
2033 * Test the api_format_messages() function with HTML.
2036 public function testApiFormatMessagesWithHtmlText()
2038 $_GET['getText'] = 'html';
2039 $result = api_format_messages(
2040 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2041 ['id' => 2, 'screen_name' => 'recipient_name'],
2042 ['id' => 3, 'screen_name' => 'sender_name']
2044 $this->assertEquals('item_title', $result['title']);
2045 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2049 * Test the api_format_messages() function with plain text.
2052 public function testApiFormatMessagesWithPlainText()
2054 $_GET['getText'] = 'plain';
2055 $result = api_format_messages(
2056 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2057 ['id' => 2, 'screen_name' => 'recipient_name'],
2058 ['id' => 3, 'screen_name' => 'sender_name']
2060 $this->assertEquals('item_title', $result['title']);
2061 $this->assertEquals('item_body', $result['text']);
2065 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2068 public function testApiFormatMessagesWithoutUserObjects()
2070 $_GET['getUserObjects'] = 'false';
2071 $result = api_format_messages(
2072 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2073 ['id' => 2, 'screen_name' => 'recipient_name'],
2074 ['id' => 3, 'screen_name' => 'sender_name']
2076 $this->assertTrue(!isset($result['sender']));
2077 $this->assertTrue(!isset($result['recipient']));
2081 * Test the api_convert_item() function.
2084 public function testApiConvertItem()
2086 $result = api_convert_item(
2088 'network' => 'feed',
2089 'title' => 'item_title',
2090 // We need a long string to test that it is correctly cut
2091 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2092 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2093 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2094 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2095 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2096 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2097 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2098 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2099 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2100 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2101 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2102 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2103 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2104 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2105 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2106 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2107 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2108 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2109 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2110 'repellat officia illum quos impedit quam iste esse unde qui '.
2111 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2112 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2113 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2114 'plink' => 'item_plink'
2117 $this->assertStringStartsWith('item_title', $result['text']);
2118 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2122 * Test the api_convert_item() function with an empty item body.
2125 public function testApiConvertItemWithoutBody()
2127 $result = api_convert_item(
2129 'network' => 'feed',
2130 'title' => 'item_title',
2132 'plink' => 'item_plink'
2135 $this->assertEquals('item_title', $result['text']);
2136 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2140 * Test the api_convert_item() function with the title in the body.
2143 public function testApiConvertItemWithTitleInBody()
2145 $result = api_convert_item(
2147 'title' => 'item_title',
2148 'body' => 'item_title item_body'
2151 $this->assertEquals('item_title item_body', $result['text']);
2152 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2156 * Test the api_get_attachments() function.
2159 public function testApiGetAttachments()
2162 $this->assertEmpty(api_get_attachments($body));
2166 * Test the api_get_attachments() function with an img tag.
2169 public function testApiGetAttachmentsWithImage()
2171 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2172 $this->assertInternalType('array', api_get_attachments($body));
2176 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2179 public function testApiGetAttachmentsWithImageAndAndStatus()
2181 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2182 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2183 $this->assertInternalType('array', api_get_attachments($body));
2187 * Test the api_get_entitities() function.
2190 public function testApiGetEntitities()
2193 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2197 * Test the api_get_entitities() function with the include_entities parameter.
2200 public function testApiGetEntititiesWithIncludeEntities()
2202 $_REQUEST['include_entities'] = 'true';
2204 $result = api_get_entitities($text, 'bbcode');
2205 $this->assertInternalType('array', $result['hashtags']);
2206 $this->assertInternalType('array', $result['symbols']);
2207 $this->assertInternalType('array', $result['urls']);
2208 $this->assertInternalType('array', $result['user_mentions']);
2212 * Test the api_format_items_embeded_images() function.
2215 public function testApiFormatItemsEmbededImages()
2217 $this->assertEquals(
2218 'text ' . System::baseUrl() . '/display/item_guid',
2219 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2224 * Test the api_contactlink_to_array() function.
2227 public function testApiContactlinkToArray()
2229 $this->assertEquals(
2234 api_contactlink_to_array('text')
2239 * Test the api_contactlink_to_array() function with an URL.
2242 public function testApiContactlinkToArrayWithUrl()
2244 $this->assertEquals(
2246 'name' => ['link_text'],
2249 api_contactlink_to_array('text <a href="url">link_text</a>')
2254 * Test the api_format_items_activities() function.
2257 public function testApiFormatItemsActivities()
2259 $item = ['uid' => 0, 'uri' => ''];
2260 $result = api_format_items_activities($item);
2261 $this->assertArrayHasKey('like', $result);
2262 $this->assertArrayHasKey('dislike', $result);
2263 $this->assertArrayHasKey('attendyes', $result);
2264 $this->assertArrayHasKey('attendno', $result);
2265 $this->assertArrayHasKey('attendmaybe', $result);
2269 * Test the api_format_items_activities() function with an XML result.
2272 public function testApiFormatItemsActivitiesWithXml()
2274 $item = ['uid' => 0, 'uri' => ''];
2275 $result = api_format_items_activities($item, 'xml');
2276 $this->assertArrayHasKey('friendica:like', $result);
2277 $this->assertArrayHasKey('friendica:dislike', $result);
2278 $this->assertArrayHasKey('friendica:attendyes', $result);
2279 $this->assertArrayHasKey('friendica:attendno', $result);
2280 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2284 * Test the api_format_items_profiles() function.
2287 public function testApiFormatItemsProfiles()
2290 'id' => 'profile_id',
2291 'profile-name' => 'profile_name',
2292 'is-default' => true,
2293 'hide-friends' => true,
2294 'photo' => 'profile_photo',
2295 'thumb' => 'profile_thumb',
2297 'net-publish' => true,
2298 'pdesc' => 'description',
2299 'dob' => 'date_of_birth',
2300 'address' => 'address',
2301 'locality' => 'city',
2302 'region' => 'region',
2303 'postal-code' => 'postal_code',
2304 'country-name' => 'country',
2305 'hometown' => 'hometown',
2306 'gender' => 'gender',
2307 'marital' => 'marital',
2308 'with' => 'marital_with',
2309 'howlong' => 'marital_since',
2310 'sexual' => 'sexual',
2311 'politic' => 'politic',
2312 'religion' => 'religion',
2313 'pub_keywords' => 'public_keywords',
2314 'prv_keywords' => 'private_keywords',
2317 'dislikes' => 'dislikes',
2323 'interest' => 'interest',
2324 'romance' => 'romance',
2326 'education' => 'education',
2327 'contact' => 'social_networks',
2328 'homepage' => 'homepage'
2330 $result = api_format_items_profiles($profile_row);
2331 $this->assertEquals(
2333 'profile_id' => 'profile_id',
2334 'profile_name' => 'profile_name',
2335 'is_default' => true,
2336 'hide_friends' => true,
2337 'profile_photo' => 'profile_photo',
2338 'profile_thumb' => 'profile_thumb',
2340 'net_publish' => true,
2341 'description' => 'description',
2342 'date_of_birth' => 'date_of_birth',
2343 'address' => 'address',
2345 'region' => 'region',
2346 'postal_code' => 'postal_code',
2347 'country' => 'country',
2348 'hometown' => 'hometown',
2349 'gender' => 'gender',
2350 'marital' => 'marital',
2351 'marital_with' => 'marital_with',
2352 'marital_since' => 'marital_since',
2353 'sexual' => 'sexual',
2354 'politic' => 'politic',
2355 'religion' => 'religion',
2356 'public_keywords' => 'public_keywords',
2357 'private_keywords' => 'private_keywords',
2360 'dislikes' => 'dislikes',
2366 'interest' => 'interest',
2367 'romance' => 'romance',
2369 'education' => 'education',
2370 'social_networks' => 'social_networks',
2371 'homepage' => 'homepage',
2379 * Test the api_format_items() function.
2382 public function testApiFormatItems()
2386 'item_network' => 'item_network',
2392 'author-network' => Protocol::DFRN,
2393 'author-link' => 'http://localhost/profile/othercontact',
2397 $result = api_format_items($items, ['id' => 0], true);
2398 foreach ($result as $status) {
2399 $this->assertStatus($status);
2404 * Test the api_format_items() function with an XML result.
2407 public function testApiFormatItemsWithXml()
2415 'author-network' => Protocol::DFRN,
2416 'author-link' => 'http://localhost/profile/othercontact',
2420 $result = api_format_items($items, ['id' => 0], true, 'xml');
2421 foreach ($result as $status) {
2422 $this->assertStatus($status);
2427 * Test the api_format_items() function.
2430 public function testApiAccountRateLimitStatus()
2432 $result = api_account_rate_limit_status('json');
2433 $this->assertEquals(150, $result['hash']['remaining_hits']);
2434 $this->assertEquals(150, $result['hash']['hourly_limit']);
2435 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2439 * Test the api_format_items() function with an XML result.
2442 public function testApiAccountRateLimitStatusWithXml()
2444 $result = api_account_rate_limit_status('xml');
2445 $this->assertXml($result, 'hash');
2449 * Test the api_help_test() function.
2452 public function testApiHelpTest()
2454 $result = api_help_test('json');
2455 $this->assertEquals(['ok' => 'ok'], $result);
2459 * Test the api_help_test() function with an XML result.
2462 public function testApiHelpTestWithXml()
2464 $result = api_help_test('xml');
2465 $this->assertXml($result, 'ok');
2469 * Test the api_lists_list() function.
2472 public function testApiListsList()
2474 $result = api_lists_list('json');
2475 $this->assertEquals(['lists_list' => []], $result);
2479 * Test the api_lists_ownerships() function.
2482 public function testApiListsOwnerships()
2484 $result = api_lists_ownerships('json');
2485 foreach ($result['lists']['lists'] as $list) {
2486 $this->assertList($list);
2491 * Test the api_lists_ownerships() function without an authenticated user.
2493 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2495 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2497 $_SESSION['authenticated'] = false;
2498 api_lists_ownerships('json');
2502 * Test the api_lists_statuses() function.
2503 * @expectedException Friendica\Network\HTTPException\BadRequestException
2506 public function testApiListsStatuses()
2508 api_lists_statuses('json');
2512 * Test the api_lists_statuses() function with a list ID.
2515 public function testApiListsStatusesWithListId()
2517 $_REQUEST['list_id'] = 1;
2518 $_REQUEST['page'] = -1;
2519 $_REQUEST['max_id'] = 10;
2520 $result = api_lists_statuses('json');
2521 foreach ($result['status'] as $status) {
2522 $this->assertStatus($status);
2527 * Test the api_lists_statuses() function with a list ID and a RSS result.
2530 public function testApiListsStatusesWithListIdAndRss()
2532 $_REQUEST['list_id'] = 1;
2533 $result = api_lists_statuses('rss');
2534 $this->assertXml($result, 'statuses');
2538 * Test the api_lists_statuses() function with an unallowed user.
2540 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2542 public function testApiListsStatusesWithUnallowedUser()
2544 $_SESSION['allow_api'] = false;
2545 $_GET['screen_name'] = $this->selfUser['nick'];
2546 api_lists_statuses('json');
2550 * Test the api_statuses_f() function.
2553 public function testApiStatusesFWithFriends()
2556 $result = api_statuses_f('friends');
2557 $this->assertArrayHasKey('user', $result);
2561 * Test the api_statuses_f() function.
2564 public function testApiStatusesFWithFollowers()
2566 $result = api_statuses_f('followers');
2567 $this->assertArrayHasKey('user', $result);
2571 * Test the api_statuses_f() function.
2574 public function testApiStatusesFWithBlocks()
2576 $result = api_statuses_f('blocks');
2577 $this->assertArrayHasKey('user', $result);
2581 * Test the api_statuses_f() function.
2584 public function testApiStatusesFWithIncoming()
2586 $result = api_statuses_f('incoming');
2587 $this->assertArrayHasKey('user', $result);
2591 * Test the api_statuses_f() function an undefined cursor GET variable.
2594 public function testApiStatusesFWithUndefinedCursor()
2596 $_GET['cursor'] = 'undefined';
2597 $this->assertFalse(api_statuses_f('friends'));
2601 * Test the api_statuses_friends() function.
2604 public function testApiStatusesFriends()
2606 $result = api_statuses_friends('json');
2607 $this->assertArrayHasKey('user', $result);
2611 * Test the api_statuses_friends() function an undefined cursor GET variable.
2614 public function testApiStatusesFriendsWithUndefinedCursor()
2616 $_GET['cursor'] = 'undefined';
2617 $this->assertFalse(api_statuses_friends('json'));
2621 * Test the api_statuses_followers() function.
2624 public function testApiStatusesFollowers()
2626 $result = api_statuses_followers('json');
2627 $this->assertArrayHasKey('user', $result);
2631 * Test the api_statuses_followers() function an undefined cursor GET variable.
2634 public function testApiStatusesFollowersWithUndefinedCursor()
2636 $_GET['cursor'] = 'undefined';
2637 $this->assertFalse(api_statuses_followers('json'));
2641 * Test the api_blocks_list() function.
2644 public function testApiBlocksList()
2646 $result = api_blocks_list('json');
2647 $this->assertArrayHasKey('user', $result);
2651 * Test the api_blocks_list() function an undefined cursor GET variable.
2654 public function testApiBlocksListWithUndefinedCursor()
2656 $_GET['cursor'] = 'undefined';
2657 $this->assertFalse(api_blocks_list('json'));
2661 * Test the api_friendships_incoming() function.
2664 public function testApiFriendshipsIncoming()
2666 $result = api_friendships_incoming('json');
2667 $this->assertArrayHasKey('id', $result);
2671 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2674 public function testApiFriendshipsIncomingWithUndefinedCursor()
2676 $_GET['cursor'] = 'undefined';
2677 $this->assertFalse(api_friendships_incoming('json'));
2681 * Test the api_statusnet_config() function.
2684 public function testApiStatusnetConfig()
2686 $result = api_statusnet_config('json');
2687 $this->assertEquals('localhost', $result['config']['site']['server']);
2688 $this->assertEquals('default', $result['config']['site']['theme']);
2689 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2690 $this->assertTrue($result['config']['site']['fancy']);
2691 $this->assertEquals('en', $result['config']['site']['language']);
2692 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2693 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2694 $this->assertEquals('false', $result['config']['site']['private']);
2695 $this->assertEquals('false', $result['config']['site']['ssl']);
2696 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2700 * Test the api_statusnet_version() function.
2703 public function testApiStatusnetVersion()
2705 $result = api_statusnet_version('json');
2706 $this->assertEquals('0.9.7', $result['version']);
2710 * Test the api_ff_ids() function.
2713 public function testApiFfIds()
2715 $result = api_ff_ids('json');
2716 $this->assertNull($result);
2720 * Test the api_ff_ids() function with a result.
2723 public function testApiFfIdsWithResult()
2725 $this->markTestIncomplete();
2729 * Test the api_ff_ids() function without an authenticated user.
2731 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2733 public function testApiFfIdsWithoutAuthenticatedUser()
2735 $_SESSION['authenticated'] = false;
2740 * Test the api_friends_ids() function.
2743 public function testApiFriendsIds()
2745 $result = api_friends_ids('json');
2746 $this->assertNull($result);
2750 * Test the api_followers_ids() function.
2753 public function testApiFollowersIds()
2755 $result = api_followers_ids('json');
2756 $this->assertNull($result);
2760 * Test the api_direct_messages_new() function.
2763 public function testApiDirectMessagesNew()
2765 $result = api_direct_messages_new('json');
2766 $this->assertNull($result);
2770 * Test the api_direct_messages_new() function without an authenticated user.
2772 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2774 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2776 $_SESSION['authenticated'] = false;
2777 api_direct_messages_new('json');
2781 * Test the api_direct_messages_new() function with an user ID.
2784 public function testApiDirectMessagesNewWithUserId()
2786 $_POST['text'] = 'message_text';
2787 $_POST['user_id'] = $this->otherUser['id'];
2788 $result = api_direct_messages_new('json');
2789 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2793 * Test the api_direct_messages_new() function with a screen name.
2796 public function testApiDirectMessagesNewWithScreenName()
2798 $_POST['text'] = 'message_text';
2799 $_POST['screen_name'] = $this->friendUser['nick'];
2800 $result = api_direct_messages_new('json');
2801 $this->assertEquals(1, $result['direct_message']['id']);
2802 $this->assertContains('message_text', $result['direct_message']['text']);
2803 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2804 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2808 * Test the api_direct_messages_new() function with a title.
2811 public function testApiDirectMessagesNewWithTitle()
2813 $_POST['text'] = 'message_text';
2814 $_POST['screen_name'] = $this->friendUser['nick'];
2815 $_REQUEST['title'] = 'message_title';
2816 $result = api_direct_messages_new('json');
2817 $this->assertEquals(1, $result['direct_message']['id']);
2818 $this->assertContains('message_text', $result['direct_message']['text']);
2819 $this->assertContains('message_title', $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 an RSS result.
2828 public function testApiDirectMessagesNewWithRss()
2830 $_POST['text'] = 'message_text';
2831 $_POST['screen_name'] = $this->friendUser['nick'];
2832 $result = api_direct_messages_new('rss');
2833 $this->assertXml($result, 'direct-messages');
2837 * Test the api_direct_messages_destroy() function.
2839 * @expectedException Friendica\Network\HTTPException\BadRequestException
2841 public function testApiDirectMessagesDestroy()
2843 api_direct_messages_destroy('json');
2847 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2850 public function testApiDirectMessagesDestroyWithVerbose()
2852 $_GET['friendica_verbose'] = 'true';
2853 $result = api_direct_messages_destroy('json');
2854 $this->assertEquals(
2857 'result' => 'error',
2858 'message' => 'message id or parenturi not specified'
2866 * Test the api_direct_messages_destroy() function without an authenticated user.
2868 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2870 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2872 $_SESSION['authenticated'] = false;
2873 api_direct_messages_destroy('json');
2877 * Test the api_direct_messages_destroy() function with a non-zero ID.
2879 * @expectedException Friendica\Network\HTTPException\BadRequestException
2881 public function testApiDirectMessagesDestroyWithId()
2883 $_REQUEST['id'] = 1;
2884 api_direct_messages_destroy('json');
2888 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2891 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2893 $_REQUEST['id'] = 1;
2894 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2895 $_GET['friendica_verbose'] = 'true';
2896 $result = api_direct_messages_destroy('json');
2897 $this->assertEquals(
2900 'result' => 'error',
2901 'message' => 'message id not in database'
2909 * Test the api_direct_messages_destroy() function with a non-zero ID.
2912 public function testApiDirectMessagesDestroyWithCorrectId()
2914 $this->markTestIncomplete('We need to add a dataset for this.');
2918 * Test the api_direct_messages_box() function.
2921 public function testApiDirectMessagesBoxWithSentbox()
2923 $_REQUEST['page'] = -1;
2924 $_REQUEST['max_id'] = 10;
2925 $result = api_direct_messages_box('json', 'sentbox', 'false');
2926 $this->assertArrayHasKey('direct_message', $result);
2930 * Test the api_direct_messages_box() function.
2933 public function testApiDirectMessagesBoxWithConversation()
2935 $result = api_direct_messages_box('json', 'conversation', 'false');
2936 $this->assertArrayHasKey('direct_message', $result);
2940 * Test the api_direct_messages_box() function.
2943 public function testApiDirectMessagesBoxWithAll()
2945 $result = api_direct_messages_box('json', 'all', 'false');
2946 $this->assertArrayHasKey('direct_message', $result);
2950 * Test the api_direct_messages_box() function.
2953 public function testApiDirectMessagesBoxWithInbox()
2955 $result = api_direct_messages_box('json', 'inbox', 'false');
2956 $this->assertArrayHasKey('direct_message', $result);
2960 * Test the api_direct_messages_box() function.
2963 public function testApiDirectMessagesBoxWithVerbose()
2965 $result = api_direct_messages_box('json', 'sentbox', 'true');
2966 $this->assertEquals(
2969 'result' => 'error',
2970 'message' => 'no mails available'
2978 * Test the api_direct_messages_box() function with a RSS result.
2981 public function testApiDirectMessagesBoxWithRss()
2983 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2984 $this->assertXml($result, 'direct-messages');
2988 * Test the api_direct_messages_box() function without an authenticated user.
2990 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2992 public function testApiDirectMessagesBoxWithUnallowedUser()
2994 $_SESSION['allow_api'] = false;
2995 $_GET['screen_name'] = $this->selfUser['nick'];
2996 api_direct_messages_box('json', 'sentbox', 'false');
3000 * Test the api_direct_messages_sentbox() function.
3003 public function testApiDirectMessagesSentbox()
3005 $result = api_direct_messages_sentbox('json');
3006 $this->assertArrayHasKey('direct_message', $result);
3010 * Test the api_direct_messages_inbox() function.
3013 public function testApiDirectMessagesInbox()
3015 $result = api_direct_messages_inbox('json');
3016 $this->assertArrayHasKey('direct_message', $result);
3020 * Test the api_direct_messages_all() function.
3023 public function testApiDirectMessagesAll()
3025 $result = api_direct_messages_all('json');
3026 $this->assertArrayHasKey('direct_message', $result);
3030 * Test the api_direct_messages_conversation() function.
3033 public function testApiDirectMessagesConversation()
3035 $result = api_direct_messages_conversation('json');
3036 $this->assertArrayHasKey('direct_message', $result);
3040 * Test the api_oauth_request_token() function.
3043 public function testApiOauthRequestToken()
3045 $this->markTestIncomplete('killme() kills phpunit as well');
3049 * Test the api_oauth_access_token() function.
3052 public function testApiOauthAccessToken()
3054 $this->markTestIncomplete('killme() kills phpunit as well');
3058 * Test the api_fr_photoalbum_delete() function.
3060 * @expectedException Friendica\Network\HTTPException\BadRequestException
3062 public function testApiFrPhotoalbumDelete()
3064 api_fr_photoalbum_delete('json');
3068 * Test the api_fr_photoalbum_delete() function with an album name.
3070 * @expectedException Friendica\Network\HTTPException\BadRequestException
3072 public function testApiFrPhotoalbumDeleteWithAlbum()
3074 $_REQUEST['album'] = 'album_name';
3075 api_fr_photoalbum_delete('json');
3079 * Test the api_fr_photoalbum_delete() function with an album name.
3082 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3084 $this->markTestIncomplete('We need to add a dataset for this.');
3088 * Test the api_fr_photoalbum_delete() function.
3090 * @expectedException Friendica\Network\HTTPException\BadRequestException
3092 public function testApiFrPhotoalbumUpdate()
3094 api_fr_photoalbum_update('json');
3098 * Test the api_fr_photoalbum_delete() function with an album name.
3100 * @expectedException Friendica\Network\HTTPException\BadRequestException
3102 public function testApiFrPhotoalbumUpdateWithAlbum()
3104 $_REQUEST['album'] = 'album_name';
3105 api_fr_photoalbum_update('json');
3109 * Test the api_fr_photoalbum_delete() function with an album name.
3111 * @expectedException Friendica\Network\HTTPException\BadRequestException
3113 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3115 $_REQUEST['album'] = 'album_name';
3116 $_REQUEST['album_new'] = 'album_name';
3117 api_fr_photoalbum_update('json');
3121 * Test the api_fr_photoalbum_update() function without an authenticated user.
3123 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3125 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3127 $_SESSION['authenticated'] = false;
3128 api_fr_photoalbum_update('json');
3132 * Test the api_fr_photoalbum_delete() function with an album name.
3135 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3137 $this->markTestIncomplete('We need to add a dataset for this.');
3141 * Test the api_fr_photos_list() function.
3144 public function testApiFrPhotosList()
3146 $result = api_fr_photos_list('json');
3147 $this->assertArrayHasKey('photo', $result);
3151 * Test the api_fr_photos_list() function without an authenticated user.
3153 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3155 public function testApiFrPhotosListWithoutAuthenticatedUser()
3157 $_SESSION['authenticated'] = false;
3158 api_fr_photos_list('json');
3162 * Test the api_fr_photo_create_update() function.
3164 * @expectedException Friendica\Network\HTTPException\BadRequestException
3166 public function testApiFrPhotoCreateUpdate()
3168 api_fr_photo_create_update('json');
3172 * Test the api_fr_photo_create_update() function without an authenticated user.
3174 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3176 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3178 $_SESSION['authenticated'] = false;
3179 api_fr_photo_create_update('json');
3183 * Test the api_fr_photo_create_update() function with an album name.
3185 * @expectedException Friendica\Network\HTTPException\BadRequestException
3187 public function testApiFrPhotoCreateUpdateWithAlbum()
3189 $_REQUEST['album'] = 'album_name';
3190 api_fr_photo_create_update('json');
3194 * Test the api_fr_photo_create_update() function with the update mode.
3197 public function testApiFrPhotoCreateUpdateWithUpdate()
3199 $this->markTestIncomplete('We need to create a dataset for this');
3203 * Test the api_fr_photo_create_update() function with an uploaded file.
3206 public function testApiFrPhotoCreateUpdateWithFile()
3208 $this->markTestIncomplete();
3212 * Test the api_fr_photo_delete() function.
3214 * @expectedException Friendica\Network\HTTPException\BadRequestException
3216 public function testApiFrPhotoDelete()
3218 api_fr_photo_delete('json');
3222 * Test the api_fr_photo_delete() function without an authenticated user.
3224 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3226 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3228 $_SESSION['authenticated'] = false;
3229 api_fr_photo_delete('json');
3233 * Test the api_fr_photo_delete() function with a photo ID.
3235 * @expectedException Friendica\Network\HTTPException\BadRequestException
3237 public function testApiFrPhotoDeleteWithPhotoId()
3239 $_REQUEST['photo_id'] = 1;
3240 api_fr_photo_delete('json');
3244 * Test the api_fr_photo_delete() function with a correct photo ID.
3247 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3249 $this->markTestIncomplete('We need to create a dataset for this.');
3253 * Test the api_fr_photo_detail() function.
3255 * @expectedException Friendica\Network\HTTPException\BadRequestException
3257 public function testApiFrPhotoDetail()
3259 api_fr_photo_detail('json');
3263 * Test the api_fr_photo_detail() function without an authenticated user.
3265 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3267 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3269 $_SESSION['authenticated'] = false;
3270 api_fr_photo_detail('json');
3274 * Test the api_fr_photo_detail() function with a photo ID.
3276 * @expectedException Friendica\Network\HTTPException\NotFoundException
3278 public function testApiFrPhotoDetailWithPhotoId()
3280 $_REQUEST['photo_id'] = 1;
3281 api_fr_photo_detail('json');
3285 * Test the api_fr_photo_detail() function with a correct photo ID.
3288 public function testApiFrPhotoDetailCorrectPhotoId()
3290 $this->markTestIncomplete('We need to create a dataset for this.');
3294 * Test the api_account_update_profile_image() function.
3296 * @expectedException Friendica\Network\HTTPException\BadRequestException
3298 public function testApiAccountUpdateProfileImage()
3300 api_account_update_profile_image('json');
3304 * Test the api_account_update_profile_image() function without an authenticated user.
3306 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3308 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3310 $_SESSION['authenticated'] = false;
3311 api_account_update_profile_image('json');
3315 * Test the api_account_update_profile_image() function with an uploaded file.
3317 * @expectedException Friendica\Network\HTTPException\BadRequestException
3319 public function testApiAccountUpdateProfileImageWithUpload()
3321 $this->markTestIncomplete();
3326 * Test the api_account_update_profile() function.
3329 public function testApiAccountUpdateProfile()
3331 $_POST['name'] = 'new_name';
3332 $_POST['description'] = 'new_description';
3333 $result = api_account_update_profile('json');
3334 // We can't use assertSelfUser() here because the user object is missing some properties.
3335 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3336 $this->assertEquals('DFRN', $result['user']['location']);
3337 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3338 $this->assertEquals('dfrn', $result['user']['network']);
3339 $this->assertEquals('new_name', $result['user']['name']);
3340 $this->assertEquals('new_description', $result['user']['description']);
3344 * Test the check_acl_input() function.
3347 public function testCheckAclInput()
3349 $result = check_acl_input('<aclstring>');
3350 // Where does this result come from?
3351 $this->assertEquals(1, $result);
3355 * Test the check_acl_input() function with an empty ACL string.
3358 public function testCheckAclInputWithEmptyAclString()
3360 $result = check_acl_input(' ');
3361 $this->assertFalse($result);
3365 * Test the save_media_to_database() function.
3368 public function testSaveMediaToDatabase()
3370 $this->markTestIncomplete();
3374 * Test the post_photo_item() function.
3377 public function testPostPhotoItem()
3379 $this->markTestIncomplete();
3383 * Test the prepare_photo_data() function.
3386 public function testPreparePhotoData()
3388 $this->markTestIncomplete();
3392 * Test the api_friendica_remoteauth() function.
3394 * @expectedException Friendica\Network\HTTPException\BadRequestException
3396 public function testApiFriendicaRemoteauth()
3398 api_friendica_remoteauth();
3402 * Test the api_friendica_remoteauth() function with an URL.
3404 * @expectedException Friendica\Network\HTTPException\BadRequestException
3406 public function testApiFriendicaRemoteauthWithUrl()
3408 $_GET['url'] = 'url';
3409 $_GET['c_url'] = 'url';
3410 api_friendica_remoteauth();
3414 * Test the api_friendica_remoteauth() function with a correct URL.
3417 public function testApiFriendicaRemoteauthWithCorrectUrl()
3419 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3420 $_GET['url'] = 'url';
3421 $_GET['c_url'] = $this->selfUser['nurl'];
3422 api_friendica_remoteauth();
3426 * Test the api_share_as_retweet() function.
3429 public function testApiShareAsRetweet()
3431 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3432 $result = api_share_as_retweet($item);
3433 $this->assertFalse($result);
3437 * Test the api_share_as_retweet() function with a valid item.
3440 public function testApiShareAsRetweetWithValidItem()
3442 $this->markTestIncomplete();
3446 * Test the api_get_nick() function.
3449 public function testApiGetNick()
3451 $result = api_get_nick($this->otherUser['nurl']);
3452 $this->assertEquals('othercontact', $result);
3456 * Test the api_get_nick() function with a wrong URL.
3459 public function testApiGetNickWithWrongUrl()
3461 $result = api_get_nick('wrong_url');
3462 $this->assertFalse($result);
3466 * Test the api_in_reply_to() function.
3469 public function testApiInReplyTo()
3471 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3472 $this->assertArrayHasKey('status_id', $result);
3473 $this->assertArrayHasKey('user_id', $result);
3474 $this->assertArrayHasKey('status_id_str', $result);
3475 $this->assertArrayHasKey('user_id_str', $result);
3476 $this->assertArrayHasKey('screen_name', $result);
3480 * Test the api_in_reply_to() function with a valid item.
3483 public function testApiInReplyToWithValidItem()
3485 $this->markTestIncomplete();
3489 * Test the api_clean_plain_items() function.
3492 public function testApiCleanPlainItems()
3494 $_REQUEST['include_entities'] = 'true';
3495 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3496 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3500 * Test the api_clean_attachments() function.
3503 public function testApiCleanAttachments()
3505 $this->markTestIncomplete();
3509 * Test the api_best_nickname() function.
3512 public function testApiBestNickname()
3515 $result = api_best_nickname($contacts);
3516 $this->assertNull($result);
3520 * Test the api_best_nickname() function with contacts.
3523 public function testApiBestNicknameWithContacts()
3525 $this->markTestIncomplete();
3529 * Test the api_friendica_group_show() function.
3532 public function testApiFriendicaGroupShow()
3534 $this->markTestIncomplete();
3538 * Test the api_friendica_group_delete() function.
3541 public function testApiFriendicaGroupDelete()
3543 $this->markTestIncomplete();
3547 * Test the api_lists_destroy() function.
3550 public function testApiListsDestroy()
3552 $this->markTestIncomplete();
3556 * Test the group_create() function.
3559 public function testGroupCreate()
3561 $this->markTestIncomplete();
3565 * Test the api_friendica_group_create() function.
3568 public function testApiFriendicaGroupCreate()
3570 $this->markTestIncomplete();
3574 * Test the api_lists_create() function.
3577 public function testApiListsCreate()
3579 $this->markTestIncomplete();
3583 * Test the api_friendica_group_update() function.
3586 public function testApiFriendicaGroupUpdate()
3588 $this->markTestIncomplete();
3592 * Test the api_lists_update() function.
3595 public function testApiListsUpdate()
3597 $this->markTestIncomplete();
3601 * Test the api_friendica_activity() function.
3604 public function testApiFriendicaActivity()
3606 $this->markTestIncomplete();
3610 * Test the api_friendica_notification() function.
3612 * @expectedException Friendica\Network\HTTPException\BadRequestException
3614 public function testApiFriendicaNotification()
3616 api_friendica_notification('json');
3620 * Test the api_friendica_notification() function without an authenticated user.
3622 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3624 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3626 $_SESSION['authenticated'] = false;
3627 api_friendica_notification('json');
3631 * Test the api_friendica_notification() function with an argument count.
3634 public function testApiFriendicaNotificationWithArgumentCount()
3636 $this->app->argv = ['api', 'friendica', 'notification'];
3637 $this->app->argc = count($this->app->argv);
3638 $result = api_friendica_notification('json');
3639 $this->assertEquals(['note' => false], $result);
3643 * Test the api_friendica_notification() function with an XML result.
3646 public function testApiFriendicaNotificationWithXmlResult()
3648 $this->app->argv = ['api', 'friendica', 'notification'];
3649 $this->app->argc = count($this->app->argv);
3650 $result = api_friendica_notification('xml');
3651 $this->assertXml($result, 'notes');
3655 * Test the api_friendica_notification_seen() function.
3658 public function testApiFriendicaNotificationSeen()
3660 $this->markTestIncomplete();
3664 * Test the api_friendica_direct_messages_setseen() function.
3667 public function testApiFriendicaDirectMessagesSetseen()
3669 $this->markTestIncomplete();
3673 * Test the api_friendica_direct_messages_search() function.
3676 public function testApiFriendicaDirectMessagesSearch()
3678 $this->markTestIncomplete();
3682 * Test the api_friendica_profile_show() function.
3685 public function testApiFriendicaProfileShow()
3687 $result = api_friendica_profile_show('json');
3688 // We can't use assertSelfUser() here because the user object is missing some properties.
3689 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3690 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3691 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3692 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3693 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3694 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3695 $this->assertFalse($result['$result']['multi_profiles']);
3699 * Test the api_friendica_profile_show() function with a profile ID.
3702 public function testApiFriendicaProfileShowWithProfileId()
3704 $this->markTestIncomplete('We need to add a dataset for this.');
3708 * Test the api_friendica_profile_show() function with a wrong profile ID.
3710 * @expectedException Friendica\Network\HTTPException\BadRequestException
3712 public function testApiFriendicaProfileShowWithWrongProfileId()
3714 $_REQUEST['profile_id'] = 666;
3715 api_friendica_profile_show('json');
3719 * Test the api_friendica_profile_show() function without an authenticated user.
3721 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3723 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3725 $_SESSION['authenticated'] = false;
3726 api_friendica_profile_show('json');
3730 * Test the api_saved_searches_list() function.
3733 public function testApiSavedSearchesList()
3735 $result = api_saved_searches_list('json');
3736 $this->assertEquals(1, $result['terms'][0]['id']);
3737 $this->assertEquals(1, $result['terms'][0]['id_str']);
3738 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3739 $this->assertEquals('Saved search', $result['terms'][0]['query']);