6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Network\BadRequestException;
12 use Friendica\Network\HTTPException;
13 use Friendica\Render\FriendicaSmarty;
15 require_once 'include/dba.php';
18 * Tests for the API functions.
20 * Functions that use header() need to be tested in a separate process.
21 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
23 class ApiTest extends DatabaseTest
27 * Create variables used by tests.
29 protected function setUp()
34 // Reusable App object
35 $this->app = new App(__DIR__.'/../');
38 // User data that the test database is populated with
41 'name' => 'Self contact',
42 'nick' => 'selfcontact',
43 'nurl' => 'http://localhost/profile/selfcontact'
47 'name' => 'Friend contact',
48 'nick' => 'friendcontact',
49 'nurl' => 'http://localhost/profile/friendcontact'
53 'name' => 'othercontact',
54 'nick' => 'othercontact',
55 'nurl' => 'http://localhost/profile/othercontact'
58 // User ID that we know is not in the database
59 $this->wrongUserId = 666;
61 // Most API require login so we force the session
64 'authenticated' => true,
65 'uid' => $this->selfUser['id']
69 Config::set('config', 'hostname', 'localhost');
70 Config::set('system', 'throttle_limit_day', 100);
71 Config::set('system', 'throttle_limit_week', 100);
72 Config::set('system', 'throttle_limit_month', 100);
73 Config::set('system', 'theme', 'system_theme');
77 * Assert that an user array contains expected keys.
78 * @param array $user User array
81 private function assertSelfUser(array $user)
83 $this->assertEquals($this->selfUser['id'], $user['uid']);
84 $this->assertEquals($this->selfUser['id'], $user['cid']);
85 $this->assertEquals(1, $user['self']);
86 $this->assertEquals('Friendica', $user['location']);
87 $this->assertEquals($this->selfUser['name'], $user['name']);
88 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
89 $this->assertEquals('dfrn', $user['network']);
90 $this->assertTrue($user['verified']);
94 * Assert that an user array contains expected keys.
95 * @param array $user User array
98 private function assertOtherUser(array $user)
100 $this->assertEquals($this->otherUser['id'], $user['id']);
101 $this->assertEquals($this->otherUser['id'], $user['id_str']);
102 $this->assertEquals(0, $user['self']);
103 $this->assertEquals($this->otherUser['name'], $user['name']);
104 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
105 $this->assertFalse($user['verified']);
109 * Assert that a status array contains expected keys.
110 * @param array $status Status array
113 private function assertStatus(array $status)
115 $this->assertInternalType('string', $status['text']);
116 $this->assertInternalType('int', $status['id']);
117 // We could probably do more checks here.
121 * Assert that a list array contains expected keys.
122 * @param array $list List array
125 private function assertList(array $list)
127 $this->assertInternalType('string', $list['name']);
128 $this->assertInternalType('int', $list['id']);
129 $this->assertInternalType('string', $list['id_str']);
130 $this->assertContains($list['mode'], ['public', 'private']);
131 // We could probably do more checks here.
135 * Assert that the string is XML and contain the root element.
136 * @param string $result XML string
137 * @param string $root_element Root element name
140 private function assertXml($result, $root_element)
142 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
143 $this->assertContains('<'.$root_element, $result);
144 // We could probably do more checks here.
148 * Get the path to a temporary empty PNG image.
149 * @return string Path
151 private function getTempImage()
153 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
157 // Empty 1x1 px PNG image
158 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
166 * Test the api_user() function.
169 public function testApiUser()
171 $this->assertEquals($this->selfUser['id'], api_user());
175 * Test the api_user() function with an unallowed user.
178 public function testApiUserWithUnallowedUser()
180 $_SESSION = ['allow_api' => false];
181 $this->assertEquals(false, api_user());
185 * Test the api_source() function.
188 public function testApiSource()
190 $this->assertEquals('api', api_source());
194 * Test the api_source() function with a Twidere user agent.
197 public function testApiSourceWithTwidere()
199 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
200 $this->assertEquals('Twidere', api_source());
204 * Test the api_source() function with a GET parameter.
207 public function testApiSourceWithGet()
209 $_GET['source'] = 'source_name';
210 $this->assertEquals('source_name', api_source());
214 * Test the api_date() function.
217 public function testApiDate()
219 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
223 * Test the api_register_func() function.
226 public function testApiRegisterFunc()
238 $this->assertTrue($API['api_path']['auth']);
239 $this->assertEquals('method', $API['api_path']['method']);
240 $this->assertTrue(is_callable($API['api_path']['func']));
244 * Test the api_login() function without any login.
246 * @runInSeparateProcess
247 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
249 public function testApiLoginWithoutLogin()
251 api_login($this->app);
255 * Test the api_login() function with a bad login.
257 * @runInSeparateProcess
258 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
260 public function testApiLoginWithBadLogin()
262 $_SERVER['PHP_AUTH_USER'] = 'user@server';
263 api_login($this->app);
267 * Test the api_login() function with oAuth.
270 public function testApiLoginWithOauth()
272 $this->markTestIncomplete('Can we test this easily?');
276 * Test the api_login() function with authentication provided by an addon.
279 public function testApiLoginWithAddonAuth()
281 $this->markTestIncomplete('Can we test this easily?');
285 * Test the api_login() function with a correct login.
287 * @runInSeparateProcess
289 public function testApiLoginWithCorrectLogin()
291 $_SERVER['PHP_AUTH_USER'] = 'Test user';
292 $_SERVER['PHP_AUTH_PW'] = 'password';
293 api_login($this->app);
297 * Test the api_login() function with a remote user.
299 * @runInSeparateProcess
300 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
302 public function testApiLoginWithRemoteUser()
304 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
305 api_login($this->app);
309 * Test the api_check_method() function.
312 public function testApiCheckMethod()
314 $this->assertFalse(api_check_method('method'));
318 * Test the api_check_method() function with a correct method.
321 public function testApiCheckMethodWithCorrectMethod()
323 $_SERVER['REQUEST_METHOD'] = 'method';
324 $this->assertTrue(api_check_method('method'));
328 * Test the api_check_method() function with a wildcard.
331 public function testApiCheckMethodWithWildcard()
333 $this->assertTrue(api_check_method('*'));
337 * Test the api_call() function.
339 * @runInSeparateProcess
341 public function testApiCall()
345 'method' => 'method',
346 'func' => function () {
347 return ['data' => ['some_data']];
350 $_SERVER['REQUEST_METHOD'] = 'method';
351 $_GET['callback'] = 'callback_name';
353 $this->app->query_string = 'api_path';
355 'callback_name(["some_data"])',
361 * Test the api_call() function with the profiled enabled.
363 * @runInSeparateProcess
365 public function testApiCallWithProfiler()
369 'method' => 'method',
370 'func' => function () {
371 return ['data' => ['some_data']];
374 $_SERVER['REQUEST_METHOD'] = 'method';
375 Config::set('system', 'profiler', true);
376 Config::set('rendertime', 'callstack', true);
377 $this->app->callstack = [
378 'database' => ['some_function' => 200],
379 'database_write' => ['some_function' => 200],
380 'cache' => ['some_function' => 200],
381 'cache_write' => ['some_function' => 200],
382 'network' => ['some_function' => 200]
385 $this->app->query_string = 'api_path';
393 * Test the api_call() function without any result.
395 * @runInSeparateProcess
397 public function testApiCallWithNoResult()
401 'method' => 'method',
402 'func' => function () {
406 $_SERVER['REQUEST_METHOD'] = 'method';
408 $this->app->query_string = 'api_path';
410 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
416 * Test the api_call() function with an unimplemented API.
418 * @runInSeparateProcess
420 public function testApiCallWithUninplementedApi()
423 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
429 * Test the api_call() function with a JSON result.
431 * @runInSeparateProcess
433 public function testApiCallWithJson()
437 'method' => 'method',
438 'func' => function () {
439 return ['data' => ['some_data']];
442 $_SERVER['REQUEST_METHOD'] = 'method';
444 $this->app->query_string = 'api_path.json';
452 * Test the api_call() function with an XML result.
454 * @runInSeparateProcess
456 public function testApiCallWithXml()
460 'method' => 'method',
461 'func' => function () {
465 $_SERVER['REQUEST_METHOD'] = 'method';
467 $this->app->query_string = 'api_path.xml';
475 * Test the api_call() function with an RSS result.
477 * @runInSeparateProcess
479 public function testApiCallWithRss()
483 'method' => 'method',
484 'func' => function () {
488 $_SERVER['REQUEST_METHOD'] = 'method';
490 $this->app->query_string = 'api_path.rss';
492 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
499 * Test the api_call() function with an Atom result.
501 * @runInSeparateProcess
503 public function testApiCallWithAtom()
507 'method' => 'method',
508 'func' => function () {
512 $_SERVER['REQUEST_METHOD'] = 'method';
514 $this->app->query_string = 'api_path.atom';
516 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
523 * Test the api_call() function with an unallowed method.
525 * @runInSeparateProcess
527 public function testApiCallWithWrongMethod()
530 $API['api_path'] = ['method' => 'method'];
532 $this->app->query_string = 'api_path';
534 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
540 * Test the api_call() function with an unauthorized user.
542 * @runInSeparateProcess
544 public function testApiCallWithWrongAuth()
548 'method' => 'method',
551 $_SERVER['REQUEST_METHOD'] = 'method';
552 $_SESSION['authenticated'] = false;
554 $this->app->query_string = 'api_path';
556 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
562 * Test the api_error() function with a JSON result.
564 * @runInSeparateProcess
566 public function testApiErrorWithJson()
569 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
570 api_error('json', new HTTPException('error_message'))
575 * Test the api_error() function with an XML result.
577 * @runInSeparateProcess
579 public function testApiErrorWithXml()
582 '<?xml version="1.0"?>'."\n".
583 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
584 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
585 'xmlns:georss="http://www.georss.org/georss">'."\n".
586 ' <error>error_message</error>'."\n".
587 ' <code>200 Friendica\Network\HTTP</code>'."\n".
590 api_error('xml', new HTTPException('error_message'))
595 * Test the api_error() function with an RSS result.
597 * @runInSeparateProcess
599 public function testApiErrorWithRss()
602 '<?xml version="1.0"?>'."\n".
603 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
604 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
605 'xmlns:georss="http://www.georss.org/georss">'."\n".
606 ' <error>error_message</error>'."\n".
607 ' <code>200 Friendica\Network\HTTP</code>'."\n".
610 api_error('rss', new HTTPException('error_message'))
615 * Test the api_error() function with an Atom result.
617 * @runInSeparateProcess
619 public function testApiErrorWithAtom()
622 '<?xml version="1.0"?>'."\n".
623 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
624 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
625 'xmlns:georss="http://www.georss.org/georss">'."\n".
626 ' <error>error_message</error>'."\n".
627 ' <code>200 Friendica\Network\HTTP</code>'."\n".
630 api_error('atom', new HTTPException('error_message'))
635 * Test the api_rss_extra() function.
638 public function testApiRssExtra()
640 $user_info = ['url' => 'user_url', 'language' => 'en'];
641 $result = api_rss_extra($this->app, [], $user_info);
642 $this->assertEquals($user_info, $result['$user']);
643 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
644 $this->assertArrayHasKey('self', $result['$rss']);
645 $this->assertArrayHasKey('base', $result['$rss']);
646 $this->assertArrayHasKey('updated', $result['$rss']);
647 $this->assertArrayHasKey('atom_updated', $result['$rss']);
648 $this->assertArrayHasKey('language', $result['$rss']);
649 $this->assertArrayHasKey('logo', $result['$rss']);
653 * Test the api_rss_extra() function without any user info.
655 * @runInSeparateProcess
657 public function testApiRssExtraWithoutUserInfo()
659 $result = api_rss_extra($this->app, [], null);
660 $this->assertInternalType('array', $result['$user']);
661 $this->assertArrayHasKey('alternate', $result['$rss']);
662 $this->assertArrayHasKey('self', $result['$rss']);
663 $this->assertArrayHasKey('base', $result['$rss']);
664 $this->assertArrayHasKey('updated', $result['$rss']);
665 $this->assertArrayHasKey('atom_updated', $result['$rss']);
666 $this->assertArrayHasKey('language', $result['$rss']);
667 $this->assertArrayHasKey('logo', $result['$rss']);
671 * Test the api_unique_id_to_nurl() function.
674 public function testApiUniqueIdToNurl()
676 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
680 * Test the api_unique_id_to_nurl() function with a correct ID.
683 public function testApiUniqueIdToNurlWithCorrectId()
685 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
689 * Test the api_get_user() function.
691 * @runInSeparateProcess
693 public function testApiGetUser()
695 $user = api_get_user($this->app);
696 $this->assertSelfUser($user);
697 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
698 $this->assertEquals('6fdbe8', $user['profile_link_color']);
699 $this->assertEquals('ededed', $user['profile_background_color']);
703 * Test the api_get_user() function with a Frio schema.
705 * @runInSeparateProcess
707 public function testApiGetUserWithFrioSchema()
709 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
710 $user = api_get_user($this->app);
711 $this->assertSelfUser($user);
712 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
713 $this->assertEquals('6fdbe8', $user['profile_link_color']);
714 $this->assertEquals('ededed', $user['profile_background_color']);
718 * Test the api_get_user() function with a custom Frio schema.
720 * @runInSeparateProcess
722 public function testApiGetUserWithCustomFrioSchema()
724 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
725 PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
726 PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
727 PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
728 $user = api_get_user($this->app);
729 $this->assertSelfUser($user);
730 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
731 $this->assertEquals('123456', $user['profile_link_color']);
732 $this->assertEquals('123456', $user['profile_background_color']);
736 * Test the api_get_user() function with an empty Frio schema.
738 * @runInSeparateProcess
740 public function testApiGetUserWithEmptyFrioSchema()
742 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
743 $user = api_get_user($this->app);
744 $this->assertSelfUser($user);
745 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
746 $this->assertEquals('6fdbe8', $user['profile_link_color']);
747 $this->assertEquals('ededed', $user['profile_background_color']);
751 * Test the api_get_user() function with an user that is not allowed to use the API.
753 * @runInSeparateProcess
755 public function testApiGetUserWithoutApiUser()
757 $_SERVER['PHP_AUTH_USER'] = 'Test user';
758 $_SERVER['PHP_AUTH_PW'] = 'password';
759 $_SESSION['allow_api'] = false;
760 $this->assertFalse(api_get_user($this->app));
764 * Test the api_get_user() function with an user ID in a GET parameter.
766 * @runInSeparateProcess
768 public function testApiGetUserWithGetId()
770 $_GET['user_id'] = $this->otherUser['id'];
771 $this->assertOtherUser(api_get_user($this->app));
775 * Test the api_get_user() function with a wrong user ID in a GET parameter.
777 * @runInSeparateProcess
778 * @expectedException Friendica\Network\HTTPException\BadRequestException
780 public function testApiGetUserWithWrongGetId()
782 $_GET['user_id'] = $this->wrongUserId;
783 $this->assertOtherUser(api_get_user($this->app));
787 * Test the api_get_user() function with an user name in a GET parameter.
789 * @runInSeparateProcess
791 public function testApiGetUserWithGetName()
793 $_GET['screen_name'] = $this->selfUser['nick'];
794 $this->assertSelfUser(api_get_user($this->app));
798 * Test the api_get_user() function with a profile URL in a GET parameter.
800 * @runInSeparateProcess
802 public function testApiGetUserWithGetUrl()
804 $_GET['profileurl'] = $this->selfUser['nurl'];
805 $this->assertSelfUser(api_get_user($this->app));
809 * Test the api_get_user() function with an user ID in the API path.
811 * @runInSeparateProcess
813 public function testApiGetUserWithNumericCalledApi()
816 $called_api = ['api_path'];
817 $this->app->argv[1] = $this->otherUser['id'].'.json';
818 $this->assertOtherUser(api_get_user($this->app));
822 * Test the api_get_user() function with the $called_api global variable.
824 * @runInSeparateProcess
826 public function testApiGetUserWithCalledApi()
829 $called_api = ['api', 'api_path'];
830 $this->assertSelfUser(api_get_user($this->app));
834 * Test the api_get_user() function with a valid user.
836 * @runInSeparateProcess
838 public function testApiGetUserWithCorrectUser()
840 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
844 * Test the api_get_user() function with a wrong user ID.
846 * @runInSeparateProcess
847 * @expectedException Friendica\Network\HTTPException\BadRequestException
849 public function testApiGetUserWithWrongUser()
851 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
855 * Test the api_get_user() function with a 0 user ID.
857 * @runInSeparateProcess
859 public function testApiGetUserWithZeroUser()
861 $this->assertSelfUser(api_get_user($this->app, 0));
865 * Test the api_item_get_user() function.
867 * @runInSeparateProcess
869 public function testApiItemGetUser()
871 $users = api_item_get_user($this->app, []);
872 $this->assertSelfUser($users[0]);
876 * Test the api_item_get_user() function with a different item parent.
879 public function testApiItemGetUserWithDifferentParent()
881 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
882 $this->assertSelfUser($users[0]);
883 $this->assertEquals($users[0], $users[1]);
887 * Test the api_walk_recursive() function.
890 public function testApiWalkRecursive()
898 // Should we test this with a callback that actually does something?
906 * Test the api_walk_recursive() function with an array.
909 public function testApiWalkRecursiveWithArray()
911 $array = [['item1'], ['item2']];
917 // Should we test this with a callback that actually does something?
925 * Test the api_reformat_xml() function.
928 public function testApiReformatXml()
932 $this->assertTrue(api_reformat_xml($item, $key));
933 $this->assertEquals('true', $item);
937 * Test the api_reformat_xml() function with a statusnet_api key.
940 public function testApiReformatXmlWithStatusnetKey()
943 $key = 'statusnet_api';
944 $this->assertTrue(api_reformat_xml($item, $key));
945 $this->assertEquals('statusnet:api', $key);
949 * Test the api_reformat_xml() function with a friendica_api key.
952 public function testApiReformatXmlWithFriendicaKey()
955 $key = 'friendica_api';
956 $this->assertTrue(api_reformat_xml($item, $key));
957 $this->assertEquals('friendica:api', $key);
961 * Test the api_create_xml() function.
964 public function testApiCreateXml()
967 '<?xml version="1.0"?>'."\n".
968 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
969 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
970 'xmlns:georss="http://www.georss.org/georss">'."\n".
971 ' <data>some_data</data>'."\n".
972 '</root_element>'."\n",
973 api_create_xml(['data' => ['some_data']], 'root_element')
978 * Test the api_create_xml() function without any XML namespace.
981 public function testApiCreateXmlWithoutNamespaces()
984 '<?xml version="1.0"?>'."\n".
986 ' <data>some_data</data>'."\n".
988 api_create_xml(['data' => ['some_data']], 'ok')
993 * Test the api_format_data() function.
996 public function testApiFormatData()
998 $data = ['some_data'];
999 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1003 * Test the api_format_data() function with an XML result.
1006 public function testApiFormatDataWithXml()
1008 $this->assertEquals(
1009 '<?xml version="1.0"?>'."\n".
1010 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1011 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1012 'xmlns:georss="http://www.georss.org/georss">'."\n".
1013 ' <data>some_data</data>'."\n".
1014 '</root_element>'."\n",
1015 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1020 * Test the api_account_verify_credentials() function.
1023 public function testApiAccountVerifyCredentials()
1025 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1029 * Test the api_account_verify_credentials() function without an authenticated user.
1031 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1033 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1035 $_SESSION['authenticated'] = false;
1036 api_account_verify_credentials('json');
1040 * Test the requestdata() function.
1043 public function testRequestdata()
1045 $this->assertNull(requestdata('variable_name'));
1049 * Test the requestdata() function with a POST parameter.
1052 public function testRequestdataWithPost()
1054 $_POST['variable_name'] = 'variable_value';
1055 $this->assertEquals('variable_value', requestdata('variable_name'));
1059 * Test the requestdata() function with a GET parameter.
1062 public function testRequestdataWithGet()
1064 $_GET['variable_name'] = 'variable_value';
1065 $this->assertEquals('variable_value', requestdata('variable_name'));
1069 * Test the api_statuses_mediap() function.
1072 public function testApiStatusesMediap()
1074 $this->app->argc = 2;
1082 'tmp_name' => $this->getTempImage(),
1083 'name' => 'spacer.png',
1084 'type' => 'image/png'
1087 $_GET['status'] = '<b>Status content</b>';
1089 $result = api_statuses_mediap('json');
1090 $this->assertStatus($result['status']);
1094 * Test the api_statuses_mediap() function without an authenticated user.
1096 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1098 public function testApiStatusesMediapWithoutAuthenticatedUser()
1100 $_SESSION['authenticated'] = false;
1101 api_statuses_mediap('json');
1105 * Test the api_statuses_update() function.
1108 public function testApiStatusesUpdate()
1110 $_GET['status'] = 'Status content';
1111 $_GET['in_reply_to_status_id'] = -1;
1120 'tmp_name' => $this->getTempImage(),
1121 'name' => 'spacer.png',
1122 'type' => 'image/png'
1126 $result = api_statuses_update('json');
1127 $this->assertStatus($result['status']);
1131 * Test the api_statuses_update() function with an HTML status.
1134 public function testApiStatusesUpdateWithHtml()
1136 $_GET['htmlstatus'] = '<b>Status content</b>';
1138 $result = api_statuses_update('json');
1139 $this->assertStatus($result['status']);
1143 * Test the api_statuses_update() function without an authenticated user.
1145 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1147 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1149 $_SESSION['authenticated'] = false;
1150 api_statuses_update('json');
1154 * Test the api_statuses_update() function with a parent status.
1157 public function testApiStatusesUpdateWithParent()
1159 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1163 * Test the api_statuses_update() function with a media_ids parameter.
1166 public function testApiStatusesUpdateWithMediaIds()
1168 $this->markTestIncomplete();
1172 * Test the api_statuses_update() function with the throttle limit reached.
1175 public function testApiStatusesUpdateWithDayThrottleReached()
1177 $this->markTestIncomplete();
1181 * Test the api_media_upload() function.
1183 * @expectedException Friendica\Network\HTTPException\BadRequestException
1185 public function testApiMediaUpload()
1191 * Test the api_media_upload() function without an authenticated user.
1193 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1195 public function testApiMediaUploadWithoutAuthenticatedUser()
1197 $_SESSION['authenticated'] = false;
1202 * Test the api_media_upload() function with an invalid uploaded media.
1204 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1206 public function testApiMediaUploadWithMedia()
1217 * Test the api_media_upload() function with an valid uploaded media.
1220 public function testApiMediaUploadWithValidMedia()
1228 'tmp_name' => $this->getTempImage(),
1229 'name' => 'spacer.png',
1230 'type' => 'image/png'
1236 $result = api_media_upload();
1237 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1238 $this->assertEquals(1, $result['media']['image']['w']);
1239 $this->assertEquals(1, $result['media']['image']['h']);
1243 * Test the api_status_show() function.
1246 public function testApiStatusShow()
1248 $result = api_status_show('json');
1249 $this->assertStatus($result['status']);
1253 * Test the api_status_show() function with an XML result.
1256 public function testApiStatusShowWithXml()
1258 $result = api_status_show('xml');
1259 $this->assertXml($result, 'statuses');
1263 * Test the api_status_show() function with a raw result.
1266 public function testApiStatusShowWithRaw()
1268 $this->assertStatus(api_status_show('raw'));
1272 * Test the api_users_show() function.
1275 public function testApiUsersShow()
1277 $result = api_users_show('json');
1278 // We can't use assertSelfUser() here because the user object is missing some properties.
1279 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1280 $this->assertEquals('Friendica', $result['user']['location']);
1281 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1282 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1283 $this->assertEquals('dfrn', $result['user']['network']);
1284 $this->assertTrue($result['user']['verified']);
1288 * Test the api_users_show() function with an XML result.
1291 public function testApiUsersShowWithXml()
1293 $result = api_users_show('xml');
1294 $this->assertXml($result, 'statuses');
1298 * Test the api_users_search() function.
1301 public function testApiUsersSearch()
1303 $_GET['q'] = 'othercontact';
1304 $result = api_users_search('json');
1305 $this->assertOtherUser($result['users'][0]);
1309 * Test the api_users_search() function with an XML result.
1312 public function testApiUsersSearchWithXml()
1314 $_GET['q'] = 'othercontact';
1315 $result = api_users_search('xml');
1316 $this->assertXml($result, 'users');
1320 * Test the api_users_search() function without a GET q parameter.
1322 * @expectedException Friendica\Network\HTTPException\BadRequestException
1324 public function testApiUsersSearchWithoutQuery()
1326 api_users_search('json');
1330 * Test the api_users_lookup() function.
1332 * @expectedException Friendica\Network\HTTPException\NotFoundException
1334 public function testApiUsersLookup()
1336 api_users_lookup('json');
1340 * Test the api_users_lookup() function with an user ID.
1343 public function testApiUsersLookupWithUserId()
1345 $_REQUEST['user_id'] = $this->otherUser['id'];
1346 $result = api_users_lookup('json');
1347 $this->assertOtherUser($result['users'][0]);
1351 * Test the api_search() function.
1354 public function testApiSearch()
1356 $_REQUEST['q'] = 'reply';
1357 $_REQUEST['max_id'] = 10;
1358 $result = api_search('json');
1359 foreach ($result['status'] as $status) {
1360 $this->assertStatus($status);
1361 $this->assertContains('reply', $status['text'], null, true);
1366 * Test the api_search() function a count parameter.
1369 public function testApiSearchWithCount()
1371 $_REQUEST['q'] = 'reply';
1372 $_REQUEST['count'] = 20;
1373 $result = api_search('json');
1374 foreach ($result['status'] as $status) {
1375 $this->assertStatus($status);
1376 $this->assertContains('reply', $status['text'], null, true);
1381 * Test the api_search() function with an rpp parameter.
1384 public function testApiSearchWithRpp()
1386 $_REQUEST['q'] = 'reply';
1387 $_REQUEST['rpp'] = 20;
1388 $result = api_search('json');
1389 foreach ($result['status'] as $status) {
1390 $this->assertStatus($status);
1391 $this->assertContains('reply', $status['text'], null, true);
1397 * Test the api_search() function without an authenticated user.
1399 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1401 public function testApiSearchWithUnallowedUser()
1403 $_SESSION['allow_api'] = false;
1404 $_GET['screen_name'] = $this->selfUser['nick'];
1409 * Test the api_search() function without any GET query parameter.
1411 * @expectedException Friendica\Network\HTTPException\BadRequestException
1413 public function testApiSearchWithoutQuery()
1419 * Test the api_statuses_home_timeline() function.
1422 public function testApiStatusesHomeTimeline()
1424 $_REQUEST['max_id'] = 10;
1425 $_REQUEST['exclude_replies'] = true;
1426 $_REQUEST['conversation_id'] = 1;
1427 $result = api_statuses_home_timeline('json');
1428 $this->assertNotEmpty($result['status']);
1429 foreach ($result['status'] as $status) {
1430 $this->assertStatus($status);
1435 * Test the api_statuses_home_timeline() function with a negative page parameter.
1438 public function testApiStatusesHomeTimelineWithNegativePage()
1440 $_REQUEST['page'] = -2;
1441 $result = api_statuses_home_timeline('json');
1442 $this->assertNotEmpty($result['status']);
1443 foreach ($result['status'] as $status) {
1444 $this->assertStatus($status);
1449 * Test the api_statuses_home_timeline() with an unallowed user.
1451 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1453 public function testApiStatusesHomeTimelineWithUnallowedUser()
1455 $_SESSION['allow_api'] = false;
1456 $_GET['screen_name'] = $this->selfUser['nick'];
1457 api_statuses_home_timeline('json');
1461 * Test the api_statuses_home_timeline() function with an RSS result.
1464 public function testApiStatusesHomeTimelineWithRss()
1466 $result = api_statuses_home_timeline('rss');
1467 $this->assertXml($result, 'statuses');
1471 * Test the api_statuses_public_timeline() function.
1474 public function testApiStatusesPublicTimeline()
1476 $_REQUEST['max_id'] = 10;
1477 $_REQUEST['conversation_id'] = 1;
1478 $result = api_statuses_public_timeline('json');
1479 $this->assertNotEmpty($result['status']);
1480 foreach ($result['status'] as $status) {
1481 $this->assertStatus($status);
1486 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1489 public function testApiStatusesPublicTimelineWithExcludeReplies()
1491 $_REQUEST['max_id'] = 10;
1492 $_REQUEST['exclude_replies'] = true;
1493 $result = api_statuses_public_timeline('json');
1494 $this->assertNotEmpty($result['status']);
1495 foreach ($result['status'] as $status) {
1496 $this->assertStatus($status);
1501 * Test the api_statuses_public_timeline() function with a negative page parameter.
1504 public function testApiStatusesPublicTimelineWithNegativePage()
1506 $_REQUEST['page'] = -2;
1507 $result = api_statuses_public_timeline('json');
1508 $this->assertNotEmpty($result['status']);
1509 foreach ($result['status'] as $status) {
1510 $this->assertStatus($status);
1515 * Test the api_statuses_public_timeline() function with an unallowed user.
1517 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1519 public function testApiStatusesPublicTimelineWithUnallowedUser()
1521 $_SESSION['allow_api'] = false;
1522 $_GET['screen_name'] = $this->selfUser['nick'];
1523 api_statuses_public_timeline('json');
1527 * Test the api_statuses_public_timeline() function with an RSS result.
1530 public function testApiStatusesPublicTimelineWithRss()
1532 $result = api_statuses_public_timeline('rss');
1533 $this->assertXml($result, 'statuses');
1537 * Test the api_statuses_networkpublic_timeline() function.
1540 public function testApiStatusesNetworkpublicTimeline()
1542 $_REQUEST['max_id'] = 10;
1543 $result = api_statuses_networkpublic_timeline('json');
1544 $this->assertNotEmpty($result['status']);
1545 foreach ($result['status'] as $status) {
1546 $this->assertStatus($status);
1551 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1554 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1556 $_REQUEST['page'] = -2;
1557 $result = api_statuses_networkpublic_timeline('json');
1558 $this->assertNotEmpty($result['status']);
1559 foreach ($result['status'] as $status) {
1560 $this->assertStatus($status);
1565 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1567 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1569 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1571 $_SESSION['allow_api'] = false;
1572 $_GET['screen_name'] = $this->selfUser['nick'];
1573 api_statuses_networkpublic_timeline('json');
1577 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1580 public function testApiStatusesNetworkpublicTimelineWithRss()
1582 $result = api_statuses_networkpublic_timeline('rss');
1583 $this->assertXml($result, 'statuses');
1587 * Test the api_statuses_show() function.
1589 * @expectedException Friendica\Network\HTTPException\BadRequestException
1591 public function testApiStatusesShow()
1593 api_statuses_show('json');
1597 * Test the api_statuses_show() function with an ID.
1600 public function testApiStatusesShowWithId()
1602 $this->app->argv[3] = 1;
1603 $result = api_statuses_show('json');
1604 $this->assertStatus($result['status']);
1608 * Test the api_statuses_show() function with the conversation parameter.
1611 public function testApiStatusesShowWithConversation()
1613 $this->app->argv[3] = 1;
1614 $_REQUEST['conversation'] = 1;
1615 $result = api_statuses_show('json');
1616 $this->assertNotEmpty($result['status']);
1617 foreach ($result['status'] as $status) {
1618 $this->assertStatus($status);
1623 * Test the api_statuses_show() function with an unallowed user.
1625 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1627 public function testApiStatusesShowWithUnallowedUser()
1629 $_SESSION['allow_api'] = false;
1630 $_GET['screen_name'] = $this->selfUser['nick'];
1631 api_statuses_show('json');
1635 * Test the api_conversation_show() function.
1637 * @expectedException Friendica\Network\HTTPException\BadRequestException
1639 public function testApiConversationShow()
1641 api_conversation_show('json');
1645 * Test the api_conversation_show() function with an ID.
1648 public function testApiConversationShowWithId()
1650 $this->app->argv[3] = 1;
1651 $_REQUEST['max_id'] = 10;
1652 $_REQUEST['page'] = -2;
1653 $result = api_conversation_show('json');
1654 $this->assertNotEmpty($result['status']);
1655 foreach ($result['status'] as $status) {
1656 $this->assertStatus($status);
1661 * Test the api_conversation_show() function with an unallowed user.
1663 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1665 public function testApiConversationShowWithUnallowedUser()
1667 $_SESSION['allow_api'] = false;
1668 $_GET['screen_name'] = $this->selfUser['nick'];
1669 api_conversation_show('json');
1673 * Test the api_statuses_repeat() function.
1675 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1677 public function testApiStatusesRepeat()
1679 api_statuses_repeat('json');
1683 * Test the api_statuses_repeat() function without an authenticated user.
1685 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1687 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1689 $_SESSION['authenticated'] = false;
1690 api_statuses_repeat('json');
1694 * Test the api_statuses_repeat() function with an ID.
1697 public function testApiStatusesRepeatWithId()
1699 $this->app->argv[3] = 1;
1700 $result = api_statuses_repeat('json');
1701 $this->assertStatus($result['status']);
1703 // Also test with a shared status
1704 $this->app->argv[3] = 5;
1705 $result = api_statuses_repeat('json');
1706 $this->assertStatus($result['status']);
1710 * Test the api_statuses_destroy() function.
1712 * @expectedException Friendica\Network\HTTPException\BadRequestException
1714 public function testApiStatusesDestroy()
1716 api_statuses_destroy('json');
1720 * Test the api_statuses_destroy() function without an authenticated user.
1722 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1724 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1726 $_SESSION['authenticated'] = false;
1727 api_statuses_destroy('json');
1731 * Test the api_statuses_destroy() function with an ID.
1734 public function testApiStatusesDestroyWithId()
1736 $this->app->argv[3] = 1;
1737 $result = api_statuses_destroy('json');
1738 $this->assertStatus($result['status']);
1742 * Test the api_statuses_mentions() function.
1745 public function testApiStatusesMentions()
1747 $this->app->user = ['nickname' => $this->selfUser['nick']];
1748 $_REQUEST['max_id'] = 10;
1749 $result = api_statuses_mentions('json');
1750 $this->assertEmpty($result['status']);
1751 // We should test with mentions in the database.
1755 * Test the api_statuses_mentions() function with a negative page parameter.
1758 public function testApiStatusesMentionsWithNegativePage()
1760 $_REQUEST['page'] = -2;
1761 $result = api_statuses_mentions('json');
1762 $this->assertEmpty($result['status']);
1766 * Test the api_statuses_mentions() function with an unallowed user.
1768 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1770 public function testApiStatusesMentionsWithUnallowedUser()
1772 $_SESSION['allow_api'] = false;
1773 $_GET['screen_name'] = $this->selfUser['nick'];
1774 api_statuses_mentions('json');
1778 * Test the api_statuses_mentions() function with an RSS result.
1781 public function testApiStatusesMentionsWithRss()
1783 $result = api_statuses_mentions('rss');
1784 $this->assertXml($result, 'statuses');
1788 * Test the api_statuses_user_timeline() function.
1791 public function testApiStatusesUserTimeline()
1793 $_REQUEST['max_id'] = 10;
1794 $_REQUEST['exclude_replies'] = true;
1795 $_REQUEST['conversation_id'] = 1;
1796 $result = api_statuses_user_timeline('json');
1797 $this->assertNotEmpty($result['status']);
1798 foreach ($result['status'] as $status) {
1799 $this->assertStatus($status);
1804 * Test the api_statuses_user_timeline() function with a negative page parameter.
1807 public function testApiStatusesUserTimelineWithNegativePage()
1809 $_REQUEST['page'] = -2;
1810 $result = api_statuses_user_timeline('json');
1811 $this->assertNotEmpty($result['status']);
1812 foreach ($result['status'] as $status) {
1813 $this->assertStatus($status);
1818 * Test the api_statuses_user_timeline() function with an RSS result.
1821 public function testApiStatusesUserTimelineWithRss()
1823 $result = api_statuses_user_timeline('rss');
1824 $this->assertXml($result, 'statuses');
1828 * Test the api_statuses_user_timeline() function with an unallowed user.
1830 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1832 public function testApiStatusesUserTimelineWithUnallowedUser()
1834 $_SESSION['allow_api'] = false;
1835 $_GET['screen_name'] = $this->selfUser['nick'];
1836 api_statuses_user_timeline('json');
1840 * Test the api_favorites_create_destroy() function.
1842 * @expectedException Friendica\Network\HTTPException\BadRequestException
1844 public function testApiFavoritesCreateDestroy()
1846 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1847 $this->app->argc = count($this->app->argv);
1848 api_favorites_create_destroy('json');
1852 * Test the api_favorites_create_destroy() function with an invalid ID.
1854 * @expectedException Friendica\Network\HTTPException\BadRequestException
1856 public function testApiFavoritesCreateDestroyWithInvalidId()
1858 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1859 $this->app->argc = count($this->app->argv);
1860 api_favorites_create_destroy('json');
1864 * Test the api_favorites_create_destroy() function with an invalid action.
1866 * @expectedException Friendica\Network\HTTPException\BadRequestException
1868 public function testApiFavoritesCreateDestroyWithInvalidAction()
1870 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1871 $this->app->argc = count($this->app->argv);
1872 $_REQUEST['id'] = 1;
1873 api_favorites_create_destroy('json');
1877 * Test the api_favorites_create_destroy() function with the create action.
1880 public function testApiFavoritesCreateDestroyWithCreateAction()
1882 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1883 $this->app->argc = count($this->app->argv);
1884 $_REQUEST['id'] = 3;
1885 $result = api_favorites_create_destroy('json');
1886 $this->assertStatus($result['status']);
1890 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1893 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1895 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1896 $this->app->argc = count($this->app->argv);
1897 $_REQUEST['id'] = 3;
1898 $result = api_favorites_create_destroy('rss');
1899 $this->assertXml($result, 'status');
1903 * Test the api_favorites_create_destroy() function with the destroy action.
1906 public function testApiFavoritesCreateDestroyWithDestroyAction()
1908 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1909 $this->app->argc = count($this->app->argv);
1910 $_REQUEST['id'] = 3;
1911 $result = api_favorites_create_destroy('json');
1912 $this->assertStatus($result['status']);
1916 * Test the api_favorites_create_destroy() function without an authenticated user.
1918 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1920 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1922 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1923 $this->app->argc = count($this->app->argv);
1924 $_SESSION['authenticated'] = false;
1925 api_favorites_create_destroy('json');
1929 * Test the api_favorites() function.
1932 public function testApiFavorites()
1934 $_REQUEST['page'] = -1;
1935 $_REQUEST['max_id'] = 10;
1936 $result = api_favorites('json');
1937 foreach ($result['status'] as $status) {
1938 $this->assertStatus($status);
1943 * Test the api_favorites() function with an RSS result.
1946 public function testApiFavoritesWithRss()
1948 $result = api_favorites('rss');
1949 $this->assertXml($result, 'statuses');
1953 * Test the api_favorites() function with an unallowed user.
1955 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1957 public function testApiFavoritesWithUnallowedUser()
1959 $_SESSION['allow_api'] = false;
1960 $_GET['screen_name'] = $this->selfUser['nick'];
1961 api_favorites('json');
1965 * Test the api_format_messages() function.
1968 public function testApiFormatMessages()
1970 $result = api_format_messages(
1971 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1972 ['id' => 2, 'screen_name' => 'recipient_name'],
1973 ['id' => 3, 'screen_name' => 'sender_name']
1975 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1976 $this->assertEquals(1, $result['id']);
1977 $this->assertEquals(2, $result['recipient_id']);
1978 $this->assertEquals(3, $result['sender_id']);
1979 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1980 $this->assertEquals('sender_name', $result['sender_screen_name']);
1984 * Test the api_format_messages() function with HTML.
1987 public function testApiFormatMessagesWithHtmlText()
1989 $_GET['getText'] = 'html';
1990 $result = api_format_messages(
1991 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1992 ['id' => 2, 'screen_name' => 'recipient_name'],
1993 ['id' => 3, 'screen_name' => 'sender_name']
1995 $this->assertEquals('item_title', $result['title']);
1996 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2000 * Test the api_format_messages() function with plain text.
2003 public function testApiFormatMessagesWithPlainText()
2005 $_GET['getText'] = 'plain';
2006 $result = api_format_messages(
2007 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2008 ['id' => 2, 'screen_name' => 'recipient_name'],
2009 ['id' => 3, 'screen_name' => 'sender_name']
2011 $this->assertEquals('item_title', $result['title']);
2012 $this->assertEquals('item_body', $result['text']);
2016 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2019 public function testApiFormatMessagesWithoutUserObjects()
2021 $_GET['getUserObjects'] = 'false';
2022 $result = api_format_messages(
2023 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2024 ['id' => 2, 'screen_name' => 'recipient_name'],
2025 ['id' => 3, 'screen_name' => 'sender_name']
2027 $this->assertTrue(!isset($result['sender']));
2028 $this->assertTrue(!isset($result['recipient']));
2032 * Test the api_convert_item() function.
2035 public function testApiConvertItem()
2037 $result = api_convert_item(
2039 'network' => 'feed',
2040 'title' => 'item_title',
2041 // We need a long string to test that it is correctly cut
2042 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2043 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2044 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2045 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2046 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2047 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2048 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2049 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2050 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2051 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2052 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2053 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2054 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2055 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2056 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2057 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2058 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2059 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2060 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2061 'repellat officia illum quos impedit quam iste esse unde qui '.
2062 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2063 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2064 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2065 'plink' => 'item_plink'
2068 $this->assertStringStartsWith('item_title', $result['text']);
2069 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2073 * Test the api_convert_item() function with an empty item body.
2076 public function testApiConvertItemWithoutBody()
2078 $result = api_convert_item(
2080 'network' => 'feed',
2081 'title' => 'item_title',
2083 'plink' => 'item_plink'
2086 $this->assertEquals('item_title', $result['text']);
2087 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2091 * Test the api_convert_item() function with the title in the body.
2094 public function testApiConvertItemWithTitleInBody()
2096 $result = api_convert_item(
2098 'title' => 'item_title',
2099 'body' => 'item_title item_body'
2102 $this->assertEquals('item_title item_body', $result['text']);
2103 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2107 * Test the api_get_attachments() function.
2110 public function testApiGetAttachments()
2113 $this->assertEmpty(api_get_attachments($body));
2117 * Test the api_get_attachments() function with an img tag.
2120 public function testApiGetAttachmentsWithImage()
2122 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2123 $this->assertInternalType('array', api_get_attachments($body));
2127 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2130 public function testApiGetAttachmentsWithImageAndAndStatus()
2132 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2133 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2134 $this->assertInternalType('array', api_get_attachments($body));
2138 * Test the api_get_entitities() function.
2141 public function testApiGetEntitities()
2144 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2148 * Test the api_get_entitities() function with the include_entities parameter.
2151 public function testApiGetEntititiesWithIncludeEntities()
2153 $_REQUEST['include_entities'] = 'true';
2155 $result = api_get_entitities($text, 'bbcode');
2156 $this->assertInternalType('array', $result['hashtags']);
2157 $this->assertInternalType('array', $result['symbols']);
2158 $this->assertInternalType('array', $result['urls']);
2159 $this->assertInternalType('array', $result['user_mentions']);
2163 * Test the api_format_items_embeded_images() function.
2166 public function testApiFormatItemsEmbededImages()
2168 $this->assertEquals(
2169 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
2170 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2175 * Test the api_contactlink_to_array() function.
2178 public function testApiContactlinkToArray()
2180 $this->assertEquals(
2185 api_contactlink_to_array('text')
2190 * Test the api_contactlink_to_array() function with an URL.
2193 public function testApiContactlinkToArrayWithUrl()
2195 $this->assertEquals(
2197 'name' => ['link_text'],
2200 api_contactlink_to_array('text <a href="url">link_text</a>')
2205 * Test the api_format_items_activities() function.
2208 public function testApiFormatItemsActivities()
2210 $item = ['uid' => 0, 'uri' => ''];
2211 $result = api_format_items_activities($item);
2212 $this->assertArrayHasKey('like', $result);
2213 $this->assertArrayHasKey('dislike', $result);
2214 $this->assertArrayHasKey('attendyes', $result);
2215 $this->assertArrayHasKey('attendno', $result);
2216 $this->assertArrayHasKey('attendmaybe', $result);
2220 * Test the api_format_items_activities() function with an XML result.
2223 public function testApiFormatItemsActivitiesWithXml()
2225 $item = ['uid' => 0, 'uri' => ''];
2226 $result = api_format_items_activities($item, 'xml');
2227 $this->assertArrayHasKey('friendica:like', $result);
2228 $this->assertArrayHasKey('friendica:dislike', $result);
2229 $this->assertArrayHasKey('friendica:attendyes', $result);
2230 $this->assertArrayHasKey('friendica:attendno', $result);
2231 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2235 * Test the api_format_items_profiles() function.
2238 public function testApiFormatItemsProfiles()
2241 'id' => 'profile_id',
2242 'profile-name' => 'profile_name',
2243 'is-default' => true,
2244 'hide-friends' => true,
2245 'photo' => 'profile_photo',
2246 'thumb' => 'profile_thumb',
2248 'net-publish' => true,
2249 'pdesc' => 'description',
2250 'dob' => 'date_of_birth',
2251 'address' => 'address',
2252 'locality' => 'city',
2253 'region' => 'region',
2254 'postal-code' => 'postal_code',
2255 'country-name' => 'country',
2256 'hometown' => 'hometown',
2257 'gender' => 'gender',
2258 'marital' => 'marital',
2259 'with' => 'marital_with',
2260 'howlong' => 'marital_since',
2261 'sexual' => 'sexual',
2262 'politic' => 'politic',
2263 'religion' => 'religion',
2264 'pub_keywords' => 'public_keywords',
2265 'prv_keywords' => 'private_keywords',
2268 'dislikes' => 'dislikes',
2274 'interest' => 'interest',
2275 'romance' => 'romance',
2277 'education' => 'education',
2278 'contact' => 'social_networks',
2279 'homepage' => 'homepage'
2281 $result = api_format_items_profiles($profile_row);
2282 $this->assertEquals(
2284 'profile_id' => 'profile_id',
2285 'profile_name' => 'profile_name',
2286 'is_default' => true,
2287 'hide_friends' => true,
2288 'profile_photo' => 'profile_photo',
2289 'profile_thumb' => 'profile_thumb',
2291 'net_publish' => true,
2292 'description' => 'description',
2293 'date_of_birth' => 'date_of_birth',
2294 'address' => 'address',
2296 'region' => 'region',
2297 'postal_code' => 'postal_code',
2298 'country' => 'country',
2299 'hometown' => 'hometown',
2300 'gender' => 'gender',
2301 'marital' => 'marital',
2302 'marital_with' => 'marital_with',
2303 'marital_since' => 'marital_since',
2304 'sexual' => 'sexual',
2305 'politic' => 'politic',
2306 'religion' => 'religion',
2307 'public_keywords' => 'public_keywords',
2308 'private_keywords' => 'private_keywords',
2311 'dislikes' => 'dislikes',
2317 'interest' => 'interest',
2318 'romance' => 'romance',
2320 'education' => 'education',
2321 'social_networks' => 'social_networks',
2322 'homepage' => 'homepage',
2330 * Test the api_format_items() function.
2333 public function testApiFormatItems()
2337 'item_network' => 'item_network',
2346 $result = api_format_items($items, ['id' => 0], true);
2347 foreach ($result as $status) {
2348 $this->assertStatus($status);
2353 * Test the api_format_items() function with an XML result.
2356 public function testApiFormatItemsWithXml()
2367 $result = api_format_items($items, ['id' => 0], true, 'xml');
2368 foreach ($result as $status) {
2369 $this->assertStatus($status);
2374 * Test the api_format_items() function.
2377 public function testApiAccountRateLimitStatus()
2379 $result = api_account_rate_limit_status('json');
2380 $this->assertEquals(150, $result['hash']['remaining_hits']);
2381 $this->assertEquals(150, $result['hash']['hourly_limit']);
2382 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2386 * Test the api_format_items() function with an XML result.
2389 public function testApiAccountRateLimitStatusWithXml()
2391 $result = api_account_rate_limit_status('xml');
2392 $this->assertXml($result, 'hash');
2396 * Test the api_help_test() function.
2399 public function testApiHelpTest()
2401 $result = api_help_test('json');
2402 $this->assertEquals(['ok' => 'ok'], $result);
2406 * Test the api_help_test() function with an XML result.
2409 public function testApiHelpTestWithXml()
2411 $result = api_help_test('xml');
2412 $this->assertXml($result, 'ok');
2416 * Test the api_lists_list() function.
2419 public function testApiListsList()
2421 $result = api_lists_list('json');
2422 $this->assertEquals(['lists_list' => []], $result);
2426 * Test the api_lists_ownerships() function.
2429 public function testApiListsOwnerships()
2431 $result = api_lists_ownerships('json');
2432 foreach ($result['lists']['lists'] as $list) {
2433 $this->assertList($list);
2438 * Test the api_lists_ownerships() function without an authenticated user.
2440 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2442 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2444 $_SESSION['authenticated'] = false;
2445 api_lists_ownerships('json');
2449 * Test the api_lists_statuses() function.
2450 * @expectedException Friendica\Network\HTTPException\BadRequestException
2453 public function testApiListsStatuses()
2455 api_lists_statuses('json');
2459 * Test the api_lists_statuses() function with a list ID.
2462 public function testApiListsStatusesWithListId()
2464 $_REQUEST['list_id'] = 1;
2465 $_REQUEST['page'] = -1;
2466 $_REQUEST['max_id'] = 10;
2467 $result = api_lists_statuses('json');
2468 foreach ($result['status'] as $status) {
2469 $this->assertStatus($status);
2474 * Test the api_lists_statuses() function with a list ID and a RSS result.
2477 public function testApiListsStatusesWithListIdAndRss()
2479 $_REQUEST['list_id'] = 1;
2480 $result = api_lists_statuses('rss');
2481 $this->assertXml($result, 'statuses');
2485 * Test the api_lists_statuses() function with an unallowed user.
2487 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2489 public function testApiListsStatusesWithUnallowedUser()
2491 $_SESSION['allow_api'] = false;
2492 $_GET['screen_name'] = $this->selfUser['nick'];
2493 api_lists_statuses('json');
2497 * Test the api_statuses_f() function.
2500 public function testApiStatusesFWithFriends()
2503 $result = api_statuses_f('friends');
2504 $this->assertArrayHasKey('user', $result);
2508 * Test the api_statuses_f() function.
2511 public function testApiStatusesFWithFollowers()
2513 $result = api_statuses_f('followers');
2514 $this->assertArrayHasKey('user', $result);
2518 * Test the api_statuses_f() function.
2521 public function testApiStatusesFWithBlocks()
2523 $result = api_statuses_f('blocks');
2524 $this->assertArrayHasKey('user', $result);
2528 * Test the api_statuses_f() function.
2531 public function testApiStatusesFWithIncoming()
2533 $result = api_statuses_f('incoming');
2534 $this->assertArrayHasKey('user', $result);
2538 * Test the api_statuses_f() function an undefined cursor GET variable.
2541 public function testApiStatusesFWithUndefinedCursor()
2543 $_GET['cursor'] = 'undefined';
2544 $this->assertFalse(api_statuses_f('friends'));
2548 * Test the api_statuses_friends() function.
2551 public function testApiStatusesFriends()
2553 $result = api_statuses_friends('json');
2554 $this->assertArrayHasKey('user', $result);
2558 * Test the api_statuses_friends() function an undefined cursor GET variable.
2561 public function testApiStatusesFriendsWithUndefinedCursor()
2563 $_GET['cursor'] = 'undefined';
2564 $this->assertFalse(api_statuses_friends('json'));
2568 * Test the api_statuses_followers() function.
2571 public function testApiStatusesFollowers()
2573 $result = api_statuses_followers('json');
2574 $this->assertArrayHasKey('user', $result);
2578 * Test the api_statuses_followers() function an undefined cursor GET variable.
2581 public function testApiStatusesFollowersWithUndefinedCursor()
2583 $_GET['cursor'] = 'undefined';
2584 $this->assertFalse(api_statuses_followers('json'));
2588 * Test the api_blocks_list() function.
2591 public function testApiBlocksList()
2593 $result = api_blocks_list('json');
2594 $this->assertArrayHasKey('user', $result);
2598 * Test the api_blocks_list() function an undefined cursor GET variable.
2601 public function testApiBlocksListWithUndefinedCursor()
2603 $_GET['cursor'] = 'undefined';
2604 $this->assertFalse(api_blocks_list('json'));
2608 * Test the api_friendships_incoming() function.
2611 public function testApiFriendshipsIncoming()
2613 $result = api_friendships_incoming('json');
2614 $this->assertArrayHasKey('id', $result);
2618 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2621 public function testApiFriendshipsIncomingWithUndefinedCursor()
2623 $_GET['cursor'] = 'undefined';
2624 $this->assertFalse(api_friendships_incoming('json'));
2628 * Test the api_statusnet_config() function.
2631 public function testApiStatusnetConfig()
2633 $result = api_statusnet_config('json');
2634 $this->assertEquals('localhost', $result['config']['site']['server']);
2635 $this->assertEquals('default', $result['config']['site']['theme']);
2636 $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2637 $this->assertTrue($result['config']['site']['fancy']);
2638 $this->assertEquals('en', $result['config']['site']['language']);
2639 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2640 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2641 $this->assertEquals('false', $result['config']['site']['private']);
2642 $this->assertEquals('false', $result['config']['site']['ssl']);
2643 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2647 * Test the api_statusnet_version() function.
2650 public function testApiStatusnetVersion()
2652 $result = api_statusnet_version('json');
2653 $this->assertEquals('0.9.7', $result['version']);
2657 * Test the api_ff_ids() function.
2660 public function testApiFfIds()
2662 $result = api_ff_ids('json');
2663 $this->assertNull($result);
2667 * Test the api_ff_ids() function with a result.
2670 public function testApiFfIdsWithResult()
2672 $this->markTestIncomplete();
2676 * Test the api_ff_ids() function without an authenticated user.
2678 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2680 public function testApiFfIdsWithoutAuthenticatedUser()
2682 $_SESSION['authenticated'] = false;
2687 * Test the api_friends_ids() function.
2690 public function testApiFriendsIds()
2692 $result = api_friends_ids('json');
2693 $this->assertNull($result);
2697 * Test the api_followers_ids() function.
2700 public function testApiFollowersIds()
2702 $result = api_followers_ids('json');
2703 $this->assertNull($result);
2707 * Test the api_direct_messages_new() function.
2710 public function testApiDirectMessagesNew()
2712 $result = api_direct_messages_new('json');
2713 $this->assertNull($result);
2717 * Test the api_direct_messages_new() function without an authenticated user.
2719 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2721 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2723 $_SESSION['authenticated'] = false;
2724 api_direct_messages_new('json');
2728 * Test the api_direct_messages_new() function with an user ID.
2731 public function testApiDirectMessagesNewWithUserId()
2733 $_POST['text'] = 'message_text';
2734 $_POST['user_id'] = $this->otherUser['id'];
2735 $result = api_direct_messages_new('json');
2736 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2740 * Test the api_direct_messages_new() function with a screen name.
2743 public function testApiDirectMessagesNewWithScreenName()
2745 $_POST['text'] = 'message_text';
2746 $_POST['screen_name'] = $this->friendUser['nick'];
2747 $result = api_direct_messages_new('json');
2748 $this->assertEquals(1, $result['direct_message']['id']);
2749 $this->assertContains('message_text', $result['direct_message']['text']);
2750 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2751 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2755 * Test the api_direct_messages_new() function with a title.
2758 public function testApiDirectMessagesNewWithTitle()
2760 $_POST['text'] = 'message_text';
2761 $_POST['screen_name'] = $this->friendUser['nick'];
2762 $_REQUEST['title'] = 'message_title';
2763 $result = api_direct_messages_new('json');
2764 $this->assertEquals(1, $result['direct_message']['id']);
2765 $this->assertContains('message_text', $result['direct_message']['text']);
2766 $this->assertContains('message_title', $result['direct_message']['text']);
2767 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2768 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2772 * Test the api_direct_messages_new() function with an RSS result.
2775 public function testApiDirectMessagesNewWithRss()
2777 $_POST['text'] = 'message_text';
2778 $_POST['screen_name'] = $this->friendUser['nick'];
2779 $result = api_direct_messages_new('rss');
2780 $this->assertXml($result, 'direct-messages');
2784 * Test the api_direct_messages_destroy() function.
2786 * @expectedException Friendica\Network\HTTPException\BadRequestException
2788 public function testApiDirectMessagesDestroy()
2790 api_direct_messages_destroy('json');
2794 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2797 public function testApiDirectMessagesDestroyWithVerbose()
2799 $_GET['friendica_verbose'] = 'true';
2800 $result = api_direct_messages_destroy('json');
2801 $this->assertEquals(
2804 'result' => 'error',
2805 'message' => 'message id or parenturi not specified'
2813 * Test the api_direct_messages_destroy() function without an authenticated user.
2815 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2817 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2819 $_SESSION['authenticated'] = false;
2820 api_direct_messages_destroy('json');
2824 * Test the api_direct_messages_destroy() function with a non-zero ID.
2826 * @expectedException Friendica\Network\HTTPException\BadRequestException
2828 public function testApiDirectMessagesDestroyWithId()
2830 $_REQUEST['id'] = 1;
2831 api_direct_messages_destroy('json');
2835 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2838 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2840 $_REQUEST['id'] = 1;
2841 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2842 $_GET['friendica_verbose'] = 'true';
2843 $result = api_direct_messages_destroy('json');
2844 $this->assertEquals(
2847 'result' => 'error',
2848 'message' => 'message id not in database'
2856 * Test the api_direct_messages_destroy() function with a non-zero ID.
2859 public function testApiDirectMessagesDestroyWithCorrectId()
2861 $this->markTestIncomplete('We need to add a dataset for this.');
2865 * Test the api_direct_messages_box() function.
2868 public function testApiDirectMessagesBoxWithSentbox()
2870 $_REQUEST['page'] = -1;
2871 $_REQUEST['max_id'] = 10;
2872 $result = api_direct_messages_box('json', 'sentbox', 'false');
2873 $this->assertArrayHasKey('direct_message', $result);
2877 * Test the api_direct_messages_box() function.
2880 public function testApiDirectMessagesBoxWithConversation()
2882 $result = api_direct_messages_box('json', 'conversation', 'false');
2883 $this->assertArrayHasKey('direct_message', $result);
2887 * Test the api_direct_messages_box() function.
2890 public function testApiDirectMessagesBoxWithAll()
2892 $result = api_direct_messages_box('json', 'all', 'false');
2893 $this->assertArrayHasKey('direct_message', $result);
2897 * Test the api_direct_messages_box() function.
2900 public function testApiDirectMessagesBoxWithInbox()
2902 $result = api_direct_messages_box('json', 'inbox', 'false');
2903 $this->assertArrayHasKey('direct_message', $result);
2907 * Test the api_direct_messages_box() function.
2910 public function testApiDirectMessagesBoxWithVerbose()
2912 $result = api_direct_messages_box('json', 'sentbox', 'true');
2913 $this->assertEquals(
2916 'result' => 'error',
2917 'message' => 'no mails available'
2925 * Test the api_direct_messages_box() function with a RSS result.
2928 public function testApiDirectMessagesBoxWithRss()
2930 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2931 $this->assertXml($result, 'direct-messages');
2935 * Test the api_direct_messages_box() function without an authenticated user.
2937 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2939 public function testApiDirectMessagesBoxWithUnallowedUser()
2941 $_SESSION['allow_api'] = false;
2942 $_GET['screen_name'] = $this->selfUser['nick'];
2943 api_direct_messages_box('json', 'sentbox', 'false');
2947 * Test the api_direct_messages_sentbox() function.
2950 public function testApiDirectMessagesSentbox()
2952 $result = api_direct_messages_sentbox('json');
2953 $this->assertArrayHasKey('direct_message', $result);
2957 * Test the api_direct_messages_inbox() function.
2960 public function testApiDirectMessagesInbox()
2962 $result = api_direct_messages_inbox('json');
2963 $this->assertArrayHasKey('direct_message', $result);
2967 * Test the api_direct_messages_all() function.
2970 public function testApiDirectMessagesAll()
2972 $result = api_direct_messages_all('json');
2973 $this->assertArrayHasKey('direct_message', $result);
2977 * Test the api_direct_messages_conversation() function.
2980 public function testApiDirectMessagesConversation()
2982 $result = api_direct_messages_conversation('json');
2983 $this->assertArrayHasKey('direct_message', $result);
2987 * Test the api_oauth_request_token() function.
2990 public function testApiOauthRequestToken()
2992 $this->markTestIncomplete('killme() kills phpunit as well');
2996 * Test the api_oauth_access_token() function.
2999 public function testApiOauthAccessToken()
3001 $this->markTestIncomplete('killme() kills phpunit as well');
3005 * Test the api_fr_photoalbum_delete() function.
3007 * @expectedException Friendica\Network\HTTPException\BadRequestException
3009 public function testApiFrPhotoalbumDelete()
3011 api_fr_photoalbum_delete('json');
3015 * Test the api_fr_photoalbum_delete() function with an album name.
3017 * @expectedException Friendica\Network\HTTPException\BadRequestException
3019 public function testApiFrPhotoalbumDeleteWithAlbum()
3021 $_REQUEST['album'] = 'album_name';
3022 api_fr_photoalbum_delete('json');
3026 * Test the api_fr_photoalbum_delete() function with an album name.
3029 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3031 $this->markTestIncomplete('We need to add a dataset for this.');
3035 * Test the api_fr_photoalbum_delete() function.
3037 * @expectedException Friendica\Network\HTTPException\BadRequestException
3039 public function testApiFrPhotoalbumUpdate()
3041 api_fr_photoalbum_update('json');
3045 * Test the api_fr_photoalbum_delete() function with an album name.
3047 * @expectedException Friendica\Network\HTTPException\BadRequestException
3049 public function testApiFrPhotoalbumUpdateWithAlbum()
3051 $_REQUEST['album'] = 'album_name';
3052 api_fr_photoalbum_update('json');
3056 * Test the api_fr_photoalbum_delete() function with an album name.
3058 * @expectedException Friendica\Network\HTTPException\BadRequestException
3060 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3062 $_REQUEST['album'] = 'album_name';
3063 $_REQUEST['album_new'] = 'album_name';
3064 api_fr_photoalbum_update('json');
3068 * Test the api_fr_photoalbum_update() function without an authenticated user.
3070 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3072 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3074 $_SESSION['authenticated'] = false;
3075 api_fr_photoalbum_update('json');
3079 * Test the api_fr_photoalbum_delete() function with an album name.
3082 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3084 $this->markTestIncomplete('We need to add a dataset for this.');
3088 * Test the api_fr_photos_list() function.
3091 public function testApiFrPhotosList()
3093 $result = api_fr_photos_list('json');
3094 $this->assertArrayHasKey('photo', $result);
3098 * Test the api_fr_photos_list() function without an authenticated user.
3100 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3102 public function testApiFrPhotosListWithoutAuthenticatedUser()
3104 $_SESSION['authenticated'] = false;
3105 api_fr_photos_list('json');
3109 * Test the api_fr_photo_create_update() function.
3111 * @expectedException Friendica\Network\HTTPException\BadRequestException
3113 public function testApiFrPhotoCreateUpdate()
3115 api_fr_photo_create_update('json');
3119 * Test the api_fr_photo_create_update() function without an authenticated user.
3121 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3123 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3125 $_SESSION['authenticated'] = false;
3126 api_fr_photo_create_update('json');
3130 * Test the api_fr_photo_create_update() function with an album name.
3132 * @expectedException Friendica\Network\HTTPException\BadRequestException
3134 public function testApiFrPhotoCreateUpdateWithAlbum()
3136 $_REQUEST['album'] = 'album_name';
3137 api_fr_photo_create_update('json');
3141 * Test the api_fr_photo_create_update() function with the update mode.
3144 public function testApiFrPhotoCreateUpdateWithUpdate()
3146 $this->markTestIncomplete('We need to create a dataset for this');
3150 * Test the api_fr_photo_create_update() function with an uploaded file.
3153 public function testApiFrPhotoCreateUpdateWithFile()
3155 $this->markTestIncomplete();
3159 * Test the api_fr_photo_delete() function.
3161 * @expectedException Friendica\Network\HTTPException\BadRequestException
3163 public function testApiFrPhotoDelete()
3165 api_fr_photo_delete('json');
3169 * Test the api_fr_photo_delete() function without an authenticated user.
3171 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3173 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3175 $_SESSION['authenticated'] = false;
3176 api_fr_photo_delete('json');
3180 * Test the api_fr_photo_delete() function with a photo ID.
3182 * @expectedException Friendica\Network\HTTPException\BadRequestException
3184 public function testApiFrPhotoDeleteWithPhotoId()
3186 $_REQUEST['photo_id'] = 1;
3187 api_fr_photo_delete('json');
3191 * Test the api_fr_photo_delete() function with a correct photo ID.
3194 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3196 $this->markTestIncomplete('We need to create a dataset for this.');
3200 * Test the api_fr_photo_detail() function.
3202 * @expectedException Friendica\Network\HTTPException\BadRequestException
3204 public function testApiFrPhotoDetail()
3206 api_fr_photo_detail('json');
3210 * Test the api_fr_photo_detail() function without an authenticated user.
3212 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3214 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3216 $_SESSION['authenticated'] = false;
3217 api_fr_photo_detail('json');
3221 * Test the api_fr_photo_detail() function with a photo ID.
3223 * @expectedException Friendica\Network\HTTPException\NotFoundException
3225 public function testApiFrPhotoDetailWithPhotoId()
3227 $_REQUEST['photo_id'] = 1;
3228 api_fr_photo_detail('json');
3232 * Test the api_fr_photo_detail() function with a correct photo ID.
3235 public function testApiFrPhotoDetailCorrectPhotoId()
3237 $this->markTestIncomplete('We need to create a dataset for this.');
3241 * Test the api_account_update_profile_image() function.
3243 * @expectedException Friendica\Network\HTTPException\BadRequestException
3245 public function testApiAccountUpdateProfileImage()
3247 api_account_update_profile_image('json');
3251 * Test the api_account_update_profile_image() function without an authenticated user.
3253 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3255 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3257 $_SESSION['authenticated'] = false;
3258 api_account_update_profile_image('json');
3262 * Test the api_account_update_profile_image() function with an uploaded file.
3264 * @expectedException Friendica\Network\HTTPException\BadRequestException
3266 public function testApiAccountUpdateProfileImageWithUpload()
3268 $this->markTestIncomplete();
3273 * Test the api_account_update_profile() function.
3276 public function testApiAccountUpdateProfile()
3278 $_POST['name'] = 'new_name';
3279 $_POST['description'] = 'new_description';
3280 $result = api_account_update_profile('json');
3281 // We can't use assertSelfUser() here because the user object is missing some properties.
3282 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3283 $this->assertEquals('Friendica', $result['user']['location']);
3284 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3285 $this->assertEquals('dfrn', $result['user']['network']);
3286 $this->assertEquals('new_name', $result['user']['name']);
3287 $this->assertEquals('new_description', $result['user']['description']);
3291 * Test the check_acl_input() function.
3294 public function testCheckAclInput()
3296 $result = check_acl_input('<aclstring>');
3297 // Where does this result come from?
3298 $this->assertEquals(1, $result);
3302 * Test the check_acl_input() function with an empty ACL string.
3305 public function testCheckAclInputWithEmptyAclString()
3307 $result = check_acl_input(' ');
3308 $this->assertFalse($result);
3312 * Test the save_media_to_database() function.
3315 public function testSaveMediaToDatabase()
3317 $this->markTestIncomplete();
3321 * Test the post_photo_item() function.
3324 public function testPostPhotoItem()
3326 $this->markTestIncomplete();
3330 * Test the prepare_photo_data() function.
3333 public function testPreparePhotoData()
3335 $this->markTestIncomplete();
3339 * Test the api_friendica_remoteauth() function.
3341 * @expectedException Friendica\Network\HTTPException\BadRequestException
3343 public function testApiFriendicaRemoteauth()
3345 api_friendica_remoteauth();
3349 * Test the api_friendica_remoteauth() function with an URL.
3351 * @expectedException Friendica\Network\HTTPException\BadRequestException
3353 public function testApiFriendicaRemoteauthWithUrl()
3355 $_GET['url'] = 'url';
3356 $_GET['c_url'] = 'url';
3357 api_friendica_remoteauth();
3361 * Test the api_friendica_remoteauth() function with a correct URL.
3364 public function testApiFriendicaRemoteauthWithCorrectUrl()
3366 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3367 $_GET['url'] = 'url';
3368 $_GET['c_url'] = $this->selfUser['nurl'];
3369 api_friendica_remoteauth();
3373 * Test the api_share_as_retweet() function.
3376 public function testApiShareAsRetweet()
3378 $item = ['body' => ''];
3379 $result = api_share_as_retweet($item);
3380 $this->assertFalse($result);
3384 * Test the api_share_as_retweet() function with a valid item.
3387 public function testApiShareAsRetweetWithValidItem()
3389 $this->markTestIncomplete();
3393 * Test the api_get_nick() function.
3396 public function testApiGetNick()
3398 var_dump(\dba::inArray(\dba::select('contact')));
3400 $result = api_get_nick($this->otherUser['nurl']);
3401 $this->assertEquals('othercontact', $result);
3405 * Test the api_get_nick() function with a wrong URL.
3408 public function testApiGetNickWithWrongUrl()
3410 $result = api_get_nick('wrong_url');
3411 $this->assertFalse($result);
3415 * Test the api_in_reply_to() function.
3418 public function testApiInReplyTo()
3420 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3421 $this->assertArrayHasKey('status_id', $result);
3422 $this->assertArrayHasKey('user_id', $result);
3423 $this->assertArrayHasKey('status_id_str', $result);
3424 $this->assertArrayHasKey('user_id_str', $result);
3425 $this->assertArrayHasKey('screen_name', $result);
3429 * Test the api_in_reply_to() function with a valid item.
3432 public function testApiInReplyToWithValidItem()
3434 $this->markTestIncomplete();
3438 * Test the api_clean_plain_items() function.
3441 public function testApiCleanPlainItems()
3443 $_REQUEST['include_entities'] = 'true';
3444 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3445 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3449 * Test the api_clean_attachments() function.
3452 public function testApiCleanAttachments()
3454 $this->markTestIncomplete();
3458 * Test the api_best_nickname() function.
3461 public function testApiBestNickname()
3464 $result = api_best_nickname($contacts);
3465 $this->assertNull($result);
3469 * Test the api_best_nickname() function with contacts.
3472 public function testApiBestNicknameWithContacts()
3474 $this->markTestIncomplete();
3478 * Test the api_friendica_group_show() function.
3481 public function testApiFriendicaGroupShow()
3483 $this->markTestIncomplete();
3487 * Test the api_friendica_group_delete() function.
3490 public function testApiFriendicaGroupDelete()
3492 $this->markTestIncomplete();
3496 * Test the api_lists_destroy() function.
3499 public function testApiListsDestroy()
3501 $this->markTestIncomplete();
3505 * Test the group_create() function.
3508 public function testGroupCreate()
3510 $this->markTestIncomplete();
3514 * Test the api_friendica_group_create() function.
3517 public function testApiFriendicaGroupCreate()
3519 $this->markTestIncomplete();
3523 * Test the api_lists_create() function.
3526 public function testApiListsCreate()
3528 $this->markTestIncomplete();
3532 * Test the api_friendica_group_update() function.
3535 public function testApiFriendicaGroupUpdate()
3537 $this->markTestIncomplete();
3541 * Test the api_lists_update() function.
3544 public function testApiListsUpdate()
3546 $this->markTestIncomplete();
3550 * Test the api_friendica_activity() function.
3553 public function testApiFriendicaActivity()
3555 $this->markTestIncomplete();
3559 * Test the api_friendica_notification() function.
3561 * @expectedException Friendica\Network\HTTPException\BadRequestException
3563 public function testApiFriendicaNotification()
3565 api_friendica_notification('json');
3569 * Test the api_friendica_notification() function without an authenticated user.
3571 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3573 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3575 $_SESSION['authenticated'] = false;
3576 api_friendica_notification('json');
3580 * Test the api_friendica_notification() function with an argument count.
3583 public function testApiFriendicaNotificationWithArgumentCount()
3585 $this->app->argv = ['api', 'friendica', 'notification'];
3586 $this->app->argc = count($this->app->argv);
3587 $result = api_friendica_notification('json');
3588 $this->assertEquals(['note' => false], $result);
3592 * Test the api_friendica_notification() function with an XML result.
3595 public function testApiFriendicaNotificationWithXmlResult()
3597 $this->app->argv = ['api', 'friendica', 'notification'];
3598 $this->app->argc = count($this->app->argv);
3599 $result = api_friendica_notification('xml');
3600 $this->assertXml($result, 'notes');
3604 * Test the api_friendica_notification_seen() function.
3607 public function testApiFriendicaNotificationSeen()
3609 $this->markTestIncomplete();
3613 * Test the api_friendica_direct_messages_setseen() function.
3616 public function testApiFriendicaDirectMessagesSetseen()
3618 $this->markTestIncomplete();
3622 * Test the api_friendica_direct_messages_search() function.
3625 public function testApiFriendicaDirectMessagesSearch()
3627 $this->markTestIncomplete();
3631 * Test the api_friendica_profile_show() function.
3634 public function testApiFriendicaProfileShow()
3636 $result = api_friendica_profile_show('json');
3637 // We can't use assertSelfUser() here because the user object is missing some properties.
3638 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3639 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3640 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3641 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3642 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3643 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3644 $this->assertFalse($result['$result']['multi_profiles']);
3648 * Test the api_friendica_profile_show() function with a profile ID.
3651 public function testApiFriendicaProfileShowWithProfileId()
3653 $this->markTestIncomplete('We need to add a dataset for this.');
3657 * Test the api_friendica_profile_show() function with a wrong profile ID.
3659 * @expectedException Friendica\Network\HTTPException\BadRequestException
3661 public function testApiFriendicaProfileShowWithWrongProfileId()
3663 $_REQUEST['profile_id'] = 666;
3664 api_friendica_profile_show('json');
3668 * Test the api_friendica_profile_show() function without an authenticated user.
3670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3672 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3674 $_SESSION['authenticated'] = false;
3675 api_friendica_profile_show('json');
3679 * Test the api_saved_searches_list() function.
3682 public function testApiSavedSearchesList()
3684 $result = api_saved_searches_list('json');
3685 $this->assertEquals(1, $result['terms'][0]['id']);
3686 $this->assertEquals(1, $result['terms'][0]['id_str']);
3687 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3688 $this->assertEquals('Saved search', $result['terms'][0]['query']);