6 namespace Friendica\Test;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Network\BadRequestException;
11 use Friendica\Network\HTTPException;
12 use Friendica\Render\FriendicaSmarty;
15 * Tests for the API functions.
17 * Functions that use header() need to be tested in a separate process.
18 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
20 class ApiTest extends DatabaseTest
24 * Create variables used by tests.
26 protected function setUp()
30 // User data that the test database is populated with
33 'name' => 'Self contact',
34 'nick' => 'selfcontact',
35 'nurl' => 'http://localhost/profile/selfcontact'
39 'name' => 'Friend contact',
40 'nick' => 'friendcontact',
41 'nurl' => 'http://localhost/profile/friendcontact'
45 'name' => 'othercontact',
46 'nick' => 'othercontact',
47 'nurl' => 'http://localhost/profile/othercontact'
50 // User ID that we know is not in the database
51 $this->wrongUserId = 666;
53 // Most API require login so we force the session
56 'authenticated' => true,
57 'uid' => $this->selfUser['id']
62 * Assert that an user array contains expected keys.
63 * @param array $user User array
66 private function assertSelfUser(array $user)
68 $this->assertEquals($this->selfUser['id'], $user['uid']);
69 $this->assertEquals($this->selfUser['id'], $user['cid']);
70 $this->assertEquals(1, $user['self']);
71 $this->assertEquals('Friendica', $user['location']);
72 $this->assertEquals($this->selfUser['name'], $user['name']);
73 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
74 $this->assertEquals('dfrn', $user['network']);
75 $this->assertTrue($user['verified']);
79 * Assert that an user array contains expected keys.
80 * @param array $user User array
83 private function assertOtherUser(array $user)
85 $this->assertEquals($this->otherUser['id'], $user['id']);
86 $this->assertEquals($this->otherUser['id'], $user['id_str']);
87 $this->assertEquals(0, $user['self']);
88 $this->assertEquals($this->otherUser['name'], $user['name']);
89 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
90 $this->assertFalse($user['verified']);
94 * Assert that a status array contains expected keys.
95 * @param array $status Status array
98 private function assertStatus(array $status)
100 $this->assertInternalType('string', $status['text']);
101 $this->assertInternalType('int', $status['id']);
102 // We could probably do more checks here.
106 * Assert that a list array contains expected keys.
107 * @param array $list List array
110 private function assertList(array $list)
112 $this->assertInternalType('string', $list['name']);
113 $this->assertInternalType('int', $list['id']);
114 $this->assertInternalType('string', $list['id_str']);
115 $this->assertContains($list['mode'], ['public', 'private']);
116 // We could probably do more checks here.
120 * Assert that the string is XML and contain the root element.
121 * @param string $result XML string
122 * @param string $root_element Root element name
125 private function assertXml($result, $root_element)
127 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
128 $this->assertContains('<'.$root_element, $result);
129 // We could probably do more checks here.
133 * Get the path to a temporary empty PNG image.
134 * @return string Path
136 private function getTempImage()
138 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
142 // Empty 1x1 px PNG image
143 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
151 * Test the api_user() function.
154 public function testApiUser()
156 $this->assertEquals($this->selfUser['id'], api_user());
160 * Test the api_user() function with an unallowed user.
163 public function testApiUserWithUnallowedUser()
165 $_SESSION = ['allow_api' => false];
166 $this->assertEquals(false, api_user());
170 * Test the api_source() function.
173 public function testApiSource()
175 $this->assertEquals('api', api_source());
179 * Test the api_source() function with a Twidere user agent.
182 public function testApiSourceWithTwidere()
184 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
185 $this->assertEquals('Twidere', api_source());
189 * Test the api_source() function with a GET parameter.
192 public function testApiSourceWithGet()
194 $_GET['source'] = 'source_name';
195 $this->assertEquals('source_name', api_source());
199 * Test the api_date() function.
202 public function testApiDate()
204 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
208 * Test the api_register_func() function.
211 public function testApiRegisterFunc()
223 $this->assertTrue($API['api_path']['auth']);
224 $this->assertEquals('method', $API['api_path']['method']);
225 $this->assertTrue(is_callable($API['api_path']['func']));
229 * Test the api_login() function without any login.
231 * @runInSeparateProcess
232 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
234 public function testApiLoginWithoutLogin()
236 api_login($this->app);
240 * Test the api_login() function with a bad login.
242 * @runInSeparateProcess
243 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
245 public function testApiLoginWithBadLogin()
247 $_SERVER['PHP_AUTH_USER'] = 'user@server';
248 api_login($this->app);
252 * Test the api_login() function with oAuth.
255 public function testApiLoginWithOauth()
257 $this->markTestIncomplete('Can we test this easily?');
261 * Test the api_login() function with authentication provided by an addon.
264 public function testApiLoginWithAddonAuth()
266 $this->markTestIncomplete('Can we test this easily?');
270 * Test the api_login() function with a correct login.
272 * @runInSeparateProcess
274 public function testApiLoginWithCorrectLogin()
276 $_SERVER['PHP_AUTH_USER'] = 'Test user';
277 $_SERVER['PHP_AUTH_PW'] = 'password';
278 api_login($this->app);
282 * Test the api_login() function with a remote user.
284 * @runInSeparateProcess
285 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
287 public function testApiLoginWithRemoteUser()
289 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
290 api_login($this->app);
294 * Test the api_check_method() function.
297 public function testApiCheckMethod()
299 $this->assertFalse(api_check_method('method'));
303 * Test the api_check_method() function with a correct method.
306 public function testApiCheckMethodWithCorrectMethod()
308 $_SERVER['REQUEST_METHOD'] = 'method';
309 $this->assertTrue(api_check_method('method'));
313 * Test the api_check_method() function with a wildcard.
316 public function testApiCheckMethodWithWildcard()
318 $this->assertTrue(api_check_method('*'));
322 * Test the api_call() function.
324 * @runInSeparateProcess
326 public function testApiCall()
330 'method' => 'method',
331 'func' => function () {
332 return ['data' => ['some_data']];
335 $_SERVER['REQUEST_METHOD'] = 'method';
336 $_GET['callback'] = 'callback_name';
338 $this->app->query_string = 'api_path';
340 'callback_name(["some_data"])',
346 * Test the api_call() function with the profiled enabled.
348 * @runInSeparateProcess
350 public function testApiCallWithProfiler()
354 'method' => 'method',
355 'func' => function () {
356 return ['data' => ['some_data']];
359 $_SERVER['REQUEST_METHOD'] = 'method';
360 Config::set('system', 'profiler', true);
361 Config::set('rendertime', 'callstack', true);
362 $this->app->callstack = [
363 'database' => ['some_function' => 200],
364 'database_write' => ['some_function' => 200],
365 'cache' => ['some_function' => 200],
366 'cache_write' => ['some_function' => 200],
367 'network' => ['some_function' => 200]
370 $this->app->query_string = 'api_path';
378 * Test the api_call() function without any result.
380 * @runInSeparateProcess
382 public function testApiCallWithNoResult()
386 'method' => 'method',
387 'func' => function () {
391 $_SERVER['REQUEST_METHOD'] = 'method';
393 $this->app->query_string = 'api_path';
395 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
401 * Test the api_call() function with an unimplemented API.
403 * @runInSeparateProcess
405 public function testApiCallWithUninplementedApi()
408 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
414 * Test the api_call() function with a JSON result.
416 * @runInSeparateProcess
418 public function testApiCallWithJson()
422 'method' => 'method',
423 'func' => function () {
424 return ['data' => ['some_data']];
427 $_SERVER['REQUEST_METHOD'] = 'method';
429 $this->app->query_string = 'api_path.json';
437 * Test the api_call() function with an XML result.
439 * @runInSeparateProcess
441 public function testApiCallWithXml()
445 'method' => 'method',
446 'func' => function () {
450 $_SERVER['REQUEST_METHOD'] = 'method';
452 $this->app->query_string = 'api_path.xml';
460 * Test the api_call() function with an RSS result.
462 * @runInSeparateProcess
464 public function testApiCallWithRss()
468 'method' => 'method',
469 'func' => function () {
473 $_SERVER['REQUEST_METHOD'] = 'method';
475 $this->app->query_string = 'api_path.rss';
477 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
484 * Test the api_call() function with an Atom result.
486 * @runInSeparateProcess
488 public function testApiCallWithAtom()
492 'method' => 'method',
493 'func' => function () {
497 $_SERVER['REQUEST_METHOD'] = 'method';
499 $this->app->query_string = 'api_path.atom';
501 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
508 * Test the api_call() function with an unallowed method.
510 * @runInSeparateProcess
512 public function testApiCallWithWrongMethod()
515 $API['api_path'] = ['method' => 'method'];
517 $this->app->query_string = 'api_path';
519 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
525 * Test the api_call() function with an unauthorized user.
527 * @runInSeparateProcess
529 public function testApiCallWithWrongAuth()
533 'method' => 'method',
536 $_SERVER['REQUEST_METHOD'] = 'method';
537 $_SESSION['authenticated'] = false;
539 $this->app->query_string = 'api_path';
541 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
547 * Test the api_error() function with a JSON result.
549 * @runInSeparateProcess
551 public function testApiErrorWithJson()
554 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
555 api_error('json', new HTTPException('error_message'))
560 * Test the api_error() function with an XML result.
562 * @runInSeparateProcess
564 public function testApiErrorWithXml()
567 '<?xml version="1.0"?>'."\n".
568 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
569 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
570 'xmlns:georss="http://www.georss.org/georss">'."\n".
571 ' <error>error_message</error>'."\n".
572 ' <code>200 Friendica\Network\HTTP</code>'."\n".
575 api_error('xml', new HTTPException('error_message'))
580 * Test the api_error() function with an RSS result.
582 * @runInSeparateProcess
584 public function testApiErrorWithRss()
587 '<?xml version="1.0"?>'."\n".
588 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
589 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
590 'xmlns:georss="http://www.georss.org/georss">'."\n".
591 ' <error>error_message</error>'."\n".
592 ' <code>200 Friendica\Network\HTTP</code>'."\n".
595 api_error('rss', new HTTPException('error_message'))
600 * Test the api_error() function with an Atom result.
602 * @runInSeparateProcess
604 public function testApiErrorWithAtom()
607 '<?xml version="1.0"?>'."\n".
608 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
609 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
610 'xmlns:georss="http://www.georss.org/georss">'."\n".
611 ' <error>error_message</error>'."\n".
612 ' <code>200 Friendica\Network\HTTP</code>'."\n".
615 api_error('atom', new HTTPException('error_message'))
620 * Test the api_rss_extra() function.
623 public function testApiRssExtra()
625 $user_info = ['url' => 'user_url', 'lang' => 'en'];
626 $result = api_rss_extra($this->app, [], $user_info);
627 $this->assertEquals($user_info, $result['$user']);
628 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
629 $this->assertArrayHasKey('self', $result['$rss']);
630 $this->assertArrayHasKey('base', $result['$rss']);
631 $this->assertArrayHasKey('updated', $result['$rss']);
632 $this->assertArrayHasKey('atom_updated', $result['$rss']);
633 $this->assertArrayHasKey('language', $result['$rss']);
634 $this->assertArrayHasKey('logo', $result['$rss']);
638 * Test the api_rss_extra() function without any user info.
640 * @runInSeparateProcess
642 public function testApiRssExtraWithoutUserInfo()
644 $result = api_rss_extra($this->app, [], null);
645 $this->assertInternalType('array', $result['$user']);
646 $this->assertArrayHasKey('alternate', $result['$rss']);
647 $this->assertArrayHasKey('self', $result['$rss']);
648 $this->assertArrayHasKey('base', $result['$rss']);
649 $this->assertArrayHasKey('updated', $result['$rss']);
650 $this->assertArrayHasKey('atom_updated', $result['$rss']);
651 $this->assertArrayHasKey('language', $result['$rss']);
652 $this->assertArrayHasKey('logo', $result['$rss']);
656 * Test the api_unique_id_to_nurl() function.
659 public function testApiUniqueIdToNurl()
661 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
665 * Test the api_unique_id_to_nurl() function with a correct ID.
668 public function testApiUniqueIdToNurlWithCorrectId()
670 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
674 * Test the api_get_user() function.
676 * @runInSeparateProcess
678 public function testApiGetUser()
680 $user = api_get_user($this->app);
681 $this->assertSelfUser($user);
682 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
683 $this->assertEquals('6fdbe8', $user['profile_link_color']);
684 $this->assertEquals('ededed', $user['profile_background_color']);
688 * Test the api_get_user() function with a Frio schema.
690 * @runInSeparateProcess
692 public function testApiGetUserWithFrioSchema()
694 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
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 custom Frio schema.
705 * @runInSeparateProcess
707 public function testApiGetUserWithCustomFrioSchema()
709 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
710 PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
711 PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
712 PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
713 $user = api_get_user($this->app);
714 $this->assertSelfUser($user);
715 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
716 $this->assertEquals('123456', $user['profile_link_color']);
717 $this->assertEquals('123456', $user['profile_background_color']);
721 * Test the api_get_user() function with an empty Frio schema.
723 * @runInSeparateProcess
725 public function testApiGetUserWithEmptyFrioSchema()
727 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
728 $user = api_get_user($this->app);
729 $this->assertSelfUser($user);
730 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
731 $this->assertEquals('6fdbe8', $user['profile_link_color']);
732 $this->assertEquals('ededed', $user['profile_background_color']);
736 * Test the api_get_user() function with an user that is not allowed to use the API.
738 * @runInSeparateProcess
740 public function testApiGetUserWithoutApiUser()
742 $_SERVER['PHP_AUTH_USER'] = 'Test user';
743 $_SERVER['PHP_AUTH_PW'] = 'password';
744 $_SESSION['allow_api'] = false;
745 $this->assertFalse(api_get_user($this->app));
749 * Test the api_get_user() function with an user ID in a GET parameter.
751 * @runInSeparateProcess
753 public function testApiGetUserWithGetId()
755 $_GET['user_id'] = $this->otherUser['id'];
756 $this->assertOtherUser(api_get_user($this->app));
760 * Test the api_get_user() function with a wrong user ID in a GET parameter.
762 * @runInSeparateProcess
763 * @expectedException Friendica\Network\HTTPException\BadRequestException
765 public function testApiGetUserWithWrongGetId()
767 $_GET['user_id'] = $this->wrongUserId;
768 $this->assertOtherUser(api_get_user($this->app));
772 * Test the api_get_user() function with an user name in a GET parameter.
774 * @runInSeparateProcess
776 public function testApiGetUserWithGetName()
778 $_GET['screen_name'] = $this->selfUser['nick'];
779 $this->assertSelfUser(api_get_user($this->app));
783 * Test the api_get_user() function with a profile URL in a GET parameter.
785 * @runInSeparateProcess
787 public function testApiGetUserWithGetUrl()
789 $_GET['profileurl'] = $this->selfUser['nurl'];
790 $this->assertSelfUser(api_get_user($this->app));
794 * Test the api_get_user() function with an user ID in the API path.
796 * @runInSeparateProcess
798 public function testApiGetUserWithNumericCalledApi()
801 $called_api = ['api_path'];
802 $this->app->argv[1] = $this->otherUser['id'].'.json';
803 $this->assertOtherUser(api_get_user($this->app));
807 * Test the api_get_user() function with the $called_api global variable.
809 * @runInSeparateProcess
811 public function testApiGetUserWithCalledApi()
814 $called_api = ['api', 'api_path'];
815 $this->assertSelfUser(api_get_user($this->app));
819 * Test the api_get_user() function with a valid user.
821 * @runInSeparateProcess
823 public function testApiGetUserWithCorrectUser()
825 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
829 * Test the api_get_user() function with a wrong user ID.
831 * @runInSeparateProcess
832 * @expectedException Friendica\Network\HTTPException\BadRequestException
834 public function testApiGetUserWithWrongUser()
836 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
840 * Test the api_get_user() function with a 0 user ID.
842 * @runInSeparateProcess
844 public function testApiGetUserWithZeroUser()
846 $this->assertSelfUser(api_get_user($this->app, 0));
850 * Test the api_item_get_user() function.
852 * @runInSeparateProcess
854 public function testApiItemGetUser()
856 $users = api_item_get_user($this->app, []);
857 $this->assertSelfUser($users[0]);
861 * Test the api_item_get_user() function with a different item parent.
864 public function testApiItemGetUserWithDifferentParent()
866 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
867 $this->assertSelfUser($users[0]);
868 $this->assertEquals($users[0], $users[1]);
872 * Test the api_walk_recursive() function.
875 public function testApiWalkRecursive()
883 // Should we test this with a callback that actually does something?
891 * Test the api_walk_recursive() function with an array.
894 public function testApiWalkRecursiveWithArray()
896 $array = [['item1'], ['item2']];
902 // Should we test this with a callback that actually does something?
910 * Test the api_reformat_xml() function.
913 public function testApiReformatXml()
917 $this->assertTrue(api_reformat_xml($item, $key));
918 $this->assertEquals('true', $item);
922 * Test the api_reformat_xml() function with a statusnet_api key.
925 public function testApiReformatXmlWithStatusnetKey()
928 $key = 'statusnet_api';
929 $this->assertTrue(api_reformat_xml($item, $key));
930 $this->assertEquals('statusnet:api', $key);
934 * Test the api_reformat_xml() function with a friendica_api key.
937 public function testApiReformatXmlWithFriendicaKey()
940 $key = 'friendica_api';
941 $this->assertTrue(api_reformat_xml($item, $key));
942 $this->assertEquals('friendica:api', $key);
946 * Test the api_create_xml() function.
949 public function testApiCreateXml()
952 '<?xml version="1.0"?>'."\n".
953 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
954 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
955 'xmlns:georss="http://www.georss.org/georss">'."\n".
956 ' <data>some_data</data>'."\n".
957 '</root_element>'."\n",
958 api_create_xml(['data' => ['some_data']], 'root_element')
963 * Test the api_create_xml() function without any XML namespace.
966 public function testApiCreateXmlWithoutNamespaces()
969 '<?xml version="1.0"?>'."\n".
971 ' <data>some_data</data>'."\n".
973 api_create_xml(['data' => ['some_data']], 'ok')
978 * Test the api_format_data() function.
981 public function testApiFormatData()
983 $data = ['some_data'];
984 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
988 * Test the api_format_data() function with an XML result.
991 public function testApiFormatDataWithXml()
994 '<?xml version="1.0"?>'."\n".
995 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
996 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
997 'xmlns:georss="http://www.georss.org/georss">'."\n".
998 ' <data>some_data</data>'."\n".
999 '</root_element>'."\n",
1000 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1005 * Test the api_account_verify_credentials() function.
1008 public function testApiAccountVerifyCredentials()
1010 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1014 * Test the api_account_verify_credentials() function without an authenticated user.
1016 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1018 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1020 $_SESSION['authenticated'] = false;
1021 api_account_verify_credentials('json');
1025 * Test the requestdata() function.
1028 public function testRequestdata()
1030 $this->assertNull(requestdata('variable_name'));
1034 * Test the requestdata() function with a POST parameter.
1037 public function testRequestdataWithPost()
1039 $_POST['variable_name'] = 'variable_value';
1040 $this->assertEquals('variable_value', requestdata('variable_name'));
1044 * Test the requestdata() function with a GET parameter.
1047 public function testRequestdataWithGet()
1049 $_GET['variable_name'] = 'variable_value';
1050 $this->assertEquals('variable_value', requestdata('variable_name'));
1054 * Test the api_statuses_mediap() function.
1057 public function testApiStatusesMediap()
1059 $this->app->argc = 2;
1067 'tmp_name' => $this->getTempImage(),
1068 'name' => 'spacer.png',
1069 'type' => 'image/png'
1072 $_GET['status'] = '<b>Status content</b>';
1074 $result = api_statuses_mediap('json');
1075 $this->assertStatus($result['status']);
1079 * Test the api_statuses_mediap() function without an authenticated user.
1081 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1083 public function testApiStatusesMediapWithoutAuthenticatedUser()
1085 $_SESSION['authenticated'] = false;
1086 api_statuses_mediap('json');
1090 * Test the api_statuses_update() function.
1093 public function testApiStatusesUpdate()
1095 $_GET['status'] = 'Status content';
1096 $_GET['in_reply_to_status_id'] = -1;
1105 'tmp_name' => $this->getTempImage(),
1106 'name' => 'spacer.png',
1107 'type' => 'image/png'
1111 $result = api_statuses_update('json');
1112 $this->assertStatus($result['status']);
1116 * Test the api_statuses_update() function with an HTML status.
1119 public function testApiStatusesUpdateWithHtml()
1121 $_GET['htmlstatus'] = '<b>Status content</b>';
1123 $result = api_statuses_update('json');
1124 $this->assertStatus($result['status']);
1128 * Test the api_statuses_update() function without an authenticated user.
1130 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1132 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1134 $_SESSION['authenticated'] = false;
1135 api_statuses_update('json');
1139 * Test the api_statuses_update() function with a parent status.
1142 public function testApiStatusesUpdateWithParent()
1144 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1148 * Test the api_statuses_update() function with a media_ids parameter.
1151 public function testApiStatusesUpdateWithMediaIds()
1153 $this->markTestIncomplete();
1157 * Test the api_statuses_update() function with the throttle limit reached.
1160 public function testApiStatusesUpdateWithDayThrottleReached()
1162 $this->markTestIncomplete();
1166 * Test the api_media_upload() function.
1168 * @expectedException Friendica\Network\HTTPException\BadRequestException
1170 public function testApiMediaUpload()
1176 * Test the api_media_upload() function without an authenticated user.
1178 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1180 public function testApiMediaUploadWithoutAuthenticatedUser()
1182 $_SESSION['authenticated'] = false;
1187 * Test the api_media_upload() function with an invalid uploaded media.
1189 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1191 public function testApiMediaUploadWithMedia()
1202 * Test the api_media_upload() function with an valid uploaded media.
1205 public function testApiMediaUploadWithValidMedia()
1213 'tmp_name' => $this->getTempImage(),
1214 'name' => 'spacer.png',
1215 'type' => 'image/png'
1221 $result = api_media_upload();
1222 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1223 $this->assertEquals(1, $result['media']['image']['w']);
1224 $this->assertEquals(1, $result['media']['image']['h']);
1228 * Test the api_status_show() function.
1231 public function testApiStatusShow()
1233 $result = api_status_show('json');
1234 $this->assertStatus($result['status']);
1238 * Test the api_status_show() function with an XML result.
1241 public function testApiStatusShowWithXml()
1243 $result = api_status_show('xml');
1244 $this->assertXml($result, 'statuses');
1248 * Test the api_status_show() function with a raw result.
1251 public function testApiStatusShowWithRaw()
1253 $this->assertStatus(api_status_show('raw'));
1257 * Test the api_users_show() function.
1260 public function testApiUsersShow()
1262 $result = api_users_show('json');
1263 // We can't use assertSelfUser() here because the user object is missing some properties.
1264 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1265 $this->assertEquals('Friendica', $result['user']['location']);
1266 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1267 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1268 $this->assertEquals('dfrn', $result['user']['network']);
1269 $this->assertTrue($result['user']['verified']);
1273 * Test the api_users_show() function with an XML result.
1276 public function testApiUsersShowWithXml()
1278 $result = api_users_show('xml');
1279 $this->assertXml($result, 'statuses');
1283 * Test the api_users_search() function.
1286 public function testApiUsersSearch()
1288 $_GET['q'] = 'othercontact';
1289 $result = api_users_search('json');
1290 $this->assertOtherUser($result['users'][0]);
1294 * Test the api_users_search() function with an XML result.
1297 public function testApiUsersSearchWithXml()
1299 $_GET['q'] = 'othercontact';
1300 $result = api_users_search('xml');
1301 $this->assertXml($result, 'users');
1305 * Test the api_users_search() function without a GET q parameter.
1307 * @expectedException Friendica\Network\HTTPException\BadRequestException
1309 public function testApiUsersSearchWithoutQuery()
1311 api_users_search('json');
1315 * Test the api_users_lookup() function.
1317 * @expectedException Friendica\Network\HTTPException\NotFoundException
1319 public function testApiUsersLookup()
1321 api_users_lookup('json');
1325 * Test the api_users_lookup() function with an user ID.
1328 public function testApiUsersLookupWithUserId()
1330 $_REQUEST['user_id'] = $this->otherUser['id'];
1331 $result = api_users_lookup('json');
1332 $this->assertOtherUser($result['users'][0]);
1336 * Test the api_search() function.
1339 public function testApiSearch()
1341 $_REQUEST['q'] = 'reply';
1342 $_REQUEST['max_id'] = 10;
1343 $result = api_search('json');
1344 foreach ($result['status'] as $status) {
1345 $this->assertStatus($status);
1346 $this->assertContains('reply', $status['text'], null, true);
1351 * Test the api_search() function a count parameter.
1354 public function testApiSearchWithCount()
1356 $_REQUEST['q'] = 'reply';
1357 $_REQUEST['count'] = 20;
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 with an rpp parameter.
1369 public function testApiSearchWithRpp()
1371 $_REQUEST['q'] = 'reply';
1372 $_REQUEST['rpp'] = 20;
1373 $result = api_search('json');
1374 foreach ($result['status'] as $status) {
1375 $this->assertStatus($status);
1376 $this->assertContains('reply', $status['text'], null, true);
1382 * Test the api_search() function without an authenticated user.
1384 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1386 public function testApiSearchWithUnallowedUser()
1388 $_SESSION['allow_api'] = false;
1389 $_GET['screen_name'] = $this->selfUser['nick'];
1394 * Test the api_search() function without any GET query parameter.
1396 * @expectedException Friendica\Network\HTTPException\BadRequestException
1398 public function testApiSearchWithoutQuery()
1404 * Test the api_statuses_home_timeline() function.
1407 public function testApiStatusesHomeTimeline()
1409 $_REQUEST['max_id'] = 10;
1410 $_REQUEST['exclude_replies'] = true;
1411 $_REQUEST['conversation_id'] = 1;
1412 $result = api_statuses_home_timeline('json');
1413 $this->assertNotEmpty($result['status']);
1414 foreach ($result['status'] as $status) {
1415 $this->assertStatus($status);
1420 * Test the api_statuses_home_timeline() function with a negative page parameter.
1423 public function testApiStatusesHomeTimelineWithNegativePage()
1425 $_REQUEST['page'] = -2;
1426 $result = api_statuses_home_timeline('json');
1427 $this->assertNotEmpty($result['status']);
1428 foreach ($result['status'] as $status) {
1429 $this->assertStatus($status);
1434 * Test the api_statuses_home_timeline() with an unallowed user.
1436 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1438 public function testApiStatusesHomeTimelineWithUnallowedUser()
1440 $_SESSION['allow_api'] = false;
1441 $_GET['screen_name'] = $this->selfUser['nick'];
1442 api_statuses_home_timeline('json');
1446 * Test the api_statuses_home_timeline() function with an RSS result.
1449 public function testApiStatusesHomeTimelineWithRss()
1451 $result = api_statuses_home_timeline('rss');
1452 $this->assertXml($result, 'statuses');
1456 * Test the api_statuses_public_timeline() function.
1459 public function testApiStatusesPublicTimeline()
1461 $_REQUEST['max_id'] = 10;
1462 $_REQUEST['conversation_id'] = 1;
1463 $result = api_statuses_public_timeline('json');
1464 $this->assertNotEmpty($result['status']);
1465 foreach ($result['status'] as $status) {
1466 $this->assertStatus($status);
1471 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1474 public function testApiStatusesPublicTimelineWithExcludeReplies()
1476 $_REQUEST['max_id'] = 10;
1477 $_REQUEST['exclude_replies'] = true;
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 a negative page parameter.
1489 public function testApiStatusesPublicTimelineWithNegativePage()
1491 $_REQUEST['page'] = -2;
1492 $result = api_statuses_public_timeline('json');
1493 $this->assertNotEmpty($result['status']);
1494 foreach ($result['status'] as $status) {
1495 $this->assertStatus($status);
1500 * Test the api_statuses_public_timeline() function with an unallowed user.
1502 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1504 public function testApiStatusesPublicTimelineWithUnallowedUser()
1506 $_SESSION['allow_api'] = false;
1507 $_GET['screen_name'] = $this->selfUser['nick'];
1508 api_statuses_public_timeline('json');
1512 * Test the api_statuses_public_timeline() function with an RSS result.
1515 public function testApiStatusesPublicTimelineWithRss()
1517 $result = api_statuses_public_timeline('rss');
1518 $this->assertXml($result, 'statuses');
1522 * Test the api_statuses_networkpublic_timeline() function.
1525 public function testApiStatusesNetworkpublicTimeline()
1527 $_REQUEST['max_id'] = 10;
1528 $result = api_statuses_networkpublic_timeline('json');
1529 $this->assertNotEmpty($result['status']);
1530 foreach ($result['status'] as $status) {
1531 $this->assertStatus($status);
1536 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1539 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1541 $_REQUEST['page'] = -2;
1542 $result = api_statuses_networkpublic_timeline('json');
1543 $this->assertNotEmpty($result['status']);
1544 foreach ($result['status'] as $status) {
1545 $this->assertStatus($status);
1550 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1552 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1554 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1556 $_SESSION['allow_api'] = false;
1557 $_GET['screen_name'] = $this->selfUser['nick'];
1558 api_statuses_networkpublic_timeline('json');
1562 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1565 public function testApiStatusesNetworkpublicTimelineWithRss()
1567 $result = api_statuses_networkpublic_timeline('rss');
1568 $this->assertXml($result, 'statuses');
1572 * Test the api_statuses_show() function.
1574 * @expectedException Friendica\Network\HTTPException\BadRequestException
1576 public function testApiStatusesShow()
1578 api_statuses_show('json');
1582 * Test the api_statuses_show() function with an ID.
1585 public function testApiStatusesShowWithId()
1587 $this->app->argv[3] = 1;
1588 $result = api_statuses_show('json');
1589 $this->assertStatus($result['status']);
1593 * Test the api_statuses_show() function with the conversation parameter.
1596 public function testApiStatusesShowWithConversation()
1598 $this->app->argv[3] = 1;
1599 $_REQUEST['conversation'] = 1;
1600 $result = api_statuses_show('json');
1601 $this->assertNotEmpty($result['status']);
1602 foreach ($result['status'] as $status) {
1603 $this->assertStatus($status);
1608 * Test the api_statuses_show() function with an unallowed user.
1610 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1612 public function testApiStatusesShowWithUnallowedUser()
1614 $_SESSION['allow_api'] = false;
1615 $_GET['screen_name'] = $this->selfUser['nick'];
1616 api_statuses_show('json');
1620 * Test the api_conversation_show() function.
1622 * @expectedException Friendica\Network\HTTPException\BadRequestException
1624 public function testApiConversationShow()
1626 api_conversation_show('json');
1630 * Test the api_conversation_show() function with an ID.
1633 public function testApiConversationShowWithId()
1635 $this->app->argv[3] = 1;
1636 $_REQUEST['max_id'] = 10;
1637 $_REQUEST['page'] = -2;
1638 $result = api_conversation_show('json');
1639 $this->assertNotEmpty($result['status']);
1640 foreach ($result['status'] as $status) {
1641 $this->assertStatus($status);
1646 * Test the api_conversation_show() function with an unallowed user.
1648 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1650 public function testApiConversationShowWithUnallowedUser()
1652 $_SESSION['allow_api'] = false;
1653 $_GET['screen_name'] = $this->selfUser['nick'];
1654 api_conversation_show('json');
1658 * Test the api_statuses_repeat() function.
1660 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1662 public function testApiStatusesRepeat()
1664 api_statuses_repeat('json');
1668 * Test the api_statuses_repeat() function without an authenticated user.
1670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1672 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1674 $_SESSION['authenticated'] = false;
1675 api_statuses_repeat('json');
1679 * Test the api_statuses_repeat() function with an ID.
1682 public function testApiStatusesRepeatWithId()
1684 $this->app->argv[3] = 1;
1685 $result = api_statuses_repeat('json');
1686 $this->assertStatus($result['status']);
1688 // Also test with a shared status
1689 $this->app->argv[3] = 5;
1690 $result = api_statuses_repeat('json');
1691 $this->assertStatus($result['status']);
1695 * Test the api_statuses_destroy() function.
1697 * @expectedException Friendica\Network\HTTPException\BadRequestException
1699 public function testApiStatusesDestroy()
1701 api_statuses_destroy('json');
1705 * Test the api_statuses_destroy() function without an authenticated user.
1707 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1709 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1711 $_SESSION['authenticated'] = false;
1712 api_statuses_destroy('json');
1716 * Test the api_statuses_destroy() function with an ID.
1719 public function testApiStatusesDestroyWithId()
1721 $this->app->argv[3] = 1;
1722 $result = api_statuses_destroy('json');
1723 $this->assertStatus($result['status']);
1727 * Test the api_statuses_mentions() function.
1730 public function testApiStatusesMentions()
1732 $this->app->user = ['nickname' => $this->selfUser['nick']];
1733 $_REQUEST['max_id'] = 10;
1734 $result = api_statuses_mentions('json');
1735 $this->assertEmpty($result['status']);
1736 // We should test with mentions in the database.
1740 * Test the api_statuses_mentions() function with a negative page parameter.
1743 public function testApiStatusesMentionsWithNegativePage()
1745 $_REQUEST['page'] = -2;
1746 $result = api_statuses_mentions('json');
1747 $this->assertEmpty($result['status']);
1751 * Test the api_statuses_mentions() function with an unallowed user.
1753 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1755 public function testApiStatusesMentionsWithUnallowedUser()
1757 $_SESSION['allow_api'] = false;
1758 $_GET['screen_name'] = $this->selfUser['nick'];
1759 api_statuses_mentions('json');
1763 * Test the api_statuses_mentions() function with an RSS result.
1766 public function testApiStatusesMentionsWithRss()
1768 $result = api_statuses_mentions('rss');
1769 $this->assertXml($result, 'statuses');
1773 * Test the api_statuses_user_timeline() function.
1776 public function testApiStatusesUserTimeline()
1778 $_REQUEST['max_id'] = 10;
1779 $_REQUEST['exclude_replies'] = true;
1780 $_REQUEST['conversation_id'] = 1;
1781 $result = api_statuses_user_timeline('json');
1782 $this->assertNotEmpty($result['status']);
1783 foreach ($result['status'] as $status) {
1784 $this->assertStatus($status);
1789 * Test the api_statuses_user_timeline() function with a negative page parameter.
1792 public function testApiStatusesUserTimelineWithNegativePage()
1794 $_REQUEST['page'] = -2;
1795 $result = api_statuses_user_timeline('json');
1796 $this->assertNotEmpty($result['status']);
1797 foreach ($result['status'] as $status) {
1798 $this->assertStatus($status);
1803 * Test the api_statuses_user_timeline() function with an RSS result.
1806 public function testApiStatusesUserTimelineWithRss()
1808 $result = api_statuses_user_timeline('rss');
1809 $this->assertXml($result, 'statuses');
1813 * Test the api_statuses_user_timeline() function with an unallowed user.
1815 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1817 public function testApiStatusesUserTimelineWithUnallowedUser()
1819 $_SESSION['allow_api'] = false;
1820 $_GET['screen_name'] = $this->selfUser['nick'];
1821 api_statuses_user_timeline('json');
1825 * Test the api_favorites_create_destroy() function.
1827 * @expectedException Friendica\Network\HTTPException\BadRequestException
1829 public function testApiFavoritesCreateDestroy()
1831 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1832 $this->app->argc = count($this->app->argv);
1833 api_favorites_create_destroy('json');
1837 * Test the api_favorites_create_destroy() function with an invalid ID.
1839 * @expectedException Friendica\Network\HTTPException\BadRequestException
1841 public function testApiFavoritesCreateDestroyWithInvalidId()
1843 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1844 $this->app->argc = count($this->app->argv);
1845 api_favorites_create_destroy('json');
1849 * Test the api_favorites_create_destroy() function with an invalid action.
1851 * @expectedException Friendica\Network\HTTPException\BadRequestException
1853 public function testApiFavoritesCreateDestroyWithInvalidAction()
1855 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1856 $this->app->argc = count($this->app->argv);
1857 $_REQUEST['id'] = 1;
1858 api_favorites_create_destroy('json');
1862 * Test the api_favorites_create_destroy() function with the create action.
1865 public function testApiFavoritesCreateDestroyWithCreateAction()
1867 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1868 $this->app->argc = count($this->app->argv);
1869 $_REQUEST['id'] = 3;
1870 $result = api_favorites_create_destroy('json');
1871 $this->assertStatus($result['status']);
1875 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1878 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1880 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1881 $this->app->argc = count($this->app->argv);
1882 $_REQUEST['id'] = 3;
1883 $result = api_favorites_create_destroy('rss');
1884 $this->assertXml($result, 'status');
1888 * Test the api_favorites_create_destroy() function with the destroy action.
1891 public function testApiFavoritesCreateDestroyWithDestroyAction()
1893 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1894 $this->app->argc = count($this->app->argv);
1895 $_REQUEST['id'] = 3;
1896 $result = api_favorites_create_destroy('json');
1897 $this->assertStatus($result['status']);
1901 * Test the api_favorites_create_destroy() function without an authenticated user.
1903 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1905 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1907 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1908 $this->app->argc = count($this->app->argv);
1909 $_SESSION['authenticated'] = false;
1910 api_favorites_create_destroy('json');
1914 * Test the api_favorites() function.
1917 public function testApiFavorites()
1919 $_REQUEST['page'] = -1;
1920 $_REQUEST['max_id'] = 10;
1921 $result = api_favorites('json');
1922 foreach ($result['status'] as $status) {
1923 $this->assertStatus($status);
1928 * Test the api_favorites() function with an RSS result.
1931 public function testApiFavoritesWithRss()
1933 $result = api_favorites('rss');
1934 $this->assertXml($result, 'statuses');
1938 * Test the api_favorites() function with an unallowed user.
1940 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1942 public function testApiFavoritesWithUnallowedUser()
1944 $_SESSION['allow_api'] = false;
1945 $_GET['screen_name'] = $this->selfUser['nick'];
1946 api_favorites('json');
1950 * Test the api_format_messages() function.
1953 public function testApiFormatMessages()
1955 $result = api_format_messages(
1956 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1957 ['id' => 2, 'screen_name' => 'recipient_name'],
1958 ['id' => 3, 'screen_name' => 'sender_name']
1960 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1961 $this->assertEquals(1, $result['id']);
1962 $this->assertEquals(2, $result['recipient_id']);
1963 $this->assertEquals(3, $result['sender_id']);
1964 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1965 $this->assertEquals('sender_name', $result['sender_screen_name']);
1969 * Test the api_format_messages() function with HTML.
1972 public function testApiFormatMessagesWithHtmlText()
1974 $_GET['getText'] = 'html';
1975 $result = api_format_messages(
1976 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1977 ['id' => 2, 'screen_name' => 'recipient_name'],
1978 ['id' => 3, 'screen_name' => 'sender_name']
1980 $this->assertEquals('item_title', $result['title']);
1981 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1985 * Test the api_format_messages() function with plain text.
1988 public function testApiFormatMessagesWithPlainText()
1990 $_GET['getText'] = 'plain';
1991 $result = api_format_messages(
1992 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1993 ['id' => 2, 'screen_name' => 'recipient_name'],
1994 ['id' => 3, 'screen_name' => 'sender_name']
1996 $this->assertEquals('item_title', $result['title']);
1997 $this->assertEquals('item_body', $result['text']);
2001 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2004 public function testApiFormatMessagesWithoutUserObjects()
2006 $_GET['getUserObjects'] = 'false';
2007 $result = api_format_messages(
2008 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2009 ['id' => 2, 'screen_name' => 'recipient_name'],
2010 ['id' => 3, 'screen_name' => 'sender_name']
2012 $this->assertTrue(!isset($result['sender']));
2013 $this->assertTrue(!isset($result['recipient']));
2017 * Test the api_convert_item() function.
2020 public function testApiConvertItem()
2022 $result = api_convert_item(
2024 'network' => 'feed',
2025 'title' => 'item_title',
2026 // We need a long string to test that it is correctly cut
2027 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2028 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2029 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2030 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2031 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2032 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2033 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2034 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2035 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2036 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2037 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2038 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2039 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2040 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2041 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2042 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2043 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2044 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2045 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2046 'repellat officia illum quos impedit quam iste esse unde qui '.
2047 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2048 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2049 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2050 'plink' => 'item_plink'
2053 $this->assertStringStartsWith('item_title', $result['text']);
2054 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2058 * Test the api_convert_item() function with an empty item body.
2061 public function testApiConvertItemWithoutBody()
2063 $result = api_convert_item(
2065 'network' => 'feed',
2066 'title' => 'item_title',
2068 'plink' => 'item_plink'
2071 $this->assertEquals('item_title', $result['text']);
2072 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2076 * Test the api_convert_item() function with the title in the body.
2079 public function testApiConvertItemWithTitleInBody()
2081 $result = api_convert_item(
2083 'title' => 'item_title',
2084 'body' => 'item_title item_body'
2087 $this->assertEquals('item_title item_body', $result['text']);
2088 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2092 * Test the api_get_attachments() function.
2095 public function testApiGetAttachments()
2098 $this->assertEmpty(api_get_attachments($body));
2102 * Test the api_get_attachments() function with an img tag.
2105 public function testApiGetAttachmentsWithImage()
2107 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2108 $this->assertInternalType('array', api_get_attachments($body));
2112 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2115 public function testApiGetAttachmentsWithImageAndAndStatus()
2117 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2118 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2119 $this->assertInternalType('array', api_get_attachments($body));
2123 * Test the api_get_entitities() function.
2126 public function testApiGetEntitities()
2129 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2133 * Test the api_get_entitities() function with the include_entities parameter.
2136 public function testApiGetEntititiesWithIncludeEntities()
2138 $_REQUEST['include_entities'] = 'true';
2140 $result = api_get_entitities($text, 'bbcode');
2141 $this->assertInternalType('array', $result['hashtags']);
2142 $this->assertInternalType('array', $result['symbols']);
2143 $this->assertInternalType('array', $result['urls']);
2144 $this->assertInternalType('array', $result['user_mentions']);
2148 * Test the api_format_items_embeded_images() function.
2151 public function testApiFormatItemsEmbededImages()
2153 $this->assertEquals(
2154 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
2155 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2160 * Test the api_contactlink_to_array() function.
2163 public function testApiContactlinkToArray()
2165 $this->assertEquals(
2170 api_contactlink_to_array('text')
2175 * Test the api_contactlink_to_array() function with an URL.
2178 public function testApiContactlinkToArrayWithUrl()
2180 $this->assertEquals(
2182 'name' => ['link_text'],
2185 api_contactlink_to_array('text <a href="url">link_text</a>')
2190 * Test the api_format_items_activities() function.
2193 public function testApiFormatItemsActivities()
2195 $item = ['uid' => 0, 'uri' => ''];
2196 $result = api_format_items_activities($item);
2197 $this->assertArrayHasKey('like', $result);
2198 $this->assertArrayHasKey('dislike', $result);
2199 $this->assertArrayHasKey('attendyes', $result);
2200 $this->assertArrayHasKey('attendno', $result);
2201 $this->assertArrayHasKey('attendmaybe', $result);
2205 * Test the api_format_items_activities() function with an XML result.
2208 public function testApiFormatItemsActivitiesWithXml()
2210 $item = ['uid' => 0, 'uri' => ''];
2211 $result = api_format_items_activities($item, 'xml');
2212 $this->assertArrayHasKey('friendica:like', $result);
2213 $this->assertArrayHasKey('friendica:dislike', $result);
2214 $this->assertArrayHasKey('friendica:attendyes', $result);
2215 $this->assertArrayHasKey('friendica:attendno', $result);
2216 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2220 * Test the api_format_items_profiles() function.
2223 public function testApiFormatItemsProfiles()
2226 'id' => 'profile_id',
2227 'profile-name' => 'profile_name',
2228 'is-default' => true,
2229 'hide-friends' => true,
2230 'photo' => 'profile_photo',
2231 'thumb' => 'profile_thumb',
2233 'net-publish' => true,
2234 'pdesc' => 'description',
2235 'dob' => 'date_of_birth',
2236 'address' => 'address',
2237 'locality' => 'city',
2238 'region' => 'region',
2239 'postal-code' => 'postal_code',
2240 'country-name' => 'country',
2241 'hometown' => 'hometown',
2242 'gender' => 'gender',
2243 'marital' => 'marital',
2244 'with' => 'marital_with',
2245 'howlong' => 'marital_since',
2246 'sexual' => 'sexual',
2247 'politic' => 'politic',
2248 'religion' => 'religion',
2249 'pub_keywords' => 'public_keywords',
2250 'prv_keywords' => 'private_keywords',
2253 'dislikes' => 'dislikes',
2259 'interest' => 'interest',
2260 'romance' => 'romance',
2262 'education' => 'education',
2263 'contact' => 'social_networks',
2264 'homepage' => 'homepage'
2266 $result = api_format_items_profiles($profile_row);
2267 $this->assertEquals(
2269 'profile_id' => 'profile_id',
2270 'profile_name' => 'profile_name',
2271 'is_default' => true,
2272 'hide_friends' => true,
2273 'profile_photo' => 'profile_photo',
2274 'profile_thumb' => 'profile_thumb',
2276 'net_publish' => true,
2277 'description' => 'description',
2278 'date_of_birth' => 'date_of_birth',
2279 'address' => 'address',
2281 'region' => 'region',
2282 'postal_code' => 'postal_code',
2283 'country' => 'country',
2284 'hometown' => 'hometown',
2285 'gender' => 'gender',
2286 'marital' => 'marital',
2287 'marital_with' => 'marital_with',
2288 'marital_since' => 'marital_since',
2289 'sexual' => 'sexual',
2290 'politic' => 'politic',
2291 'religion' => 'religion',
2292 'public_keywords' => 'public_keywords',
2293 'private_keywords' => 'private_keywords',
2296 'dislikes' => 'dislikes',
2302 'interest' => 'interest',
2303 'romance' => 'romance',
2305 'education' => 'education',
2306 'social_networks' => 'social_networks',
2307 'homepage' => 'homepage',
2315 * Test the api_format_items() function.
2318 public function testApiFormatItems()
2322 'item_network' => 'item_network',
2328 'author-network' => \Friendica\Core\Protocol::DFRN,
2329 'author-link' => 'http://localhost/profile/othercontact',
2333 $result = api_format_items($items, ['id' => 0], true);
2334 foreach ($result as $status) {
2335 $this->assertStatus($status);
2340 * Test the api_format_items() function with an XML result.
2343 public function testApiFormatItemsWithXml()
2351 'author-network' => \Friendica\Core\Protocol::DFRN,
2352 'author-link' => 'http://localhost/profile/othercontact',
2356 $result = api_format_items($items, ['id' => 0], true, 'xml');
2357 foreach ($result as $status) {
2358 $this->assertStatus($status);
2363 * Test the api_format_items() function.
2366 public function testApiAccountRateLimitStatus()
2368 $result = api_account_rate_limit_status('json');
2369 $this->assertEquals(150, $result['hash']['remaining_hits']);
2370 $this->assertEquals(150, $result['hash']['hourly_limit']);
2371 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2375 * Test the api_format_items() function with an XML result.
2378 public function testApiAccountRateLimitStatusWithXml()
2380 $result = api_account_rate_limit_status('xml');
2381 $this->assertXml($result, 'hash');
2385 * Test the api_help_test() function.
2388 public function testApiHelpTest()
2390 $result = api_help_test('json');
2391 $this->assertEquals(['ok' => 'ok'], $result);
2395 * Test the api_help_test() function with an XML result.
2398 public function testApiHelpTestWithXml()
2400 $result = api_help_test('xml');
2401 $this->assertXml($result, 'ok');
2405 * Test the api_lists_list() function.
2408 public function testApiListsList()
2410 $result = api_lists_list('json');
2411 $this->assertEquals(['lists_list' => []], $result);
2415 * Test the api_lists_ownerships() function.
2418 public function testApiListsOwnerships()
2420 $result = api_lists_ownerships('json');
2421 foreach ($result['lists']['lists'] as $list) {
2422 $this->assertList($list);
2427 * Test the api_lists_ownerships() function without an authenticated user.
2429 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2431 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2433 $_SESSION['authenticated'] = false;
2434 api_lists_ownerships('json');
2438 * Test the api_lists_statuses() function.
2439 * @expectedException Friendica\Network\HTTPException\BadRequestException
2442 public function testApiListsStatuses()
2444 api_lists_statuses('json');
2448 * Test the api_lists_statuses() function with a list ID.
2451 public function testApiListsStatusesWithListId()
2453 $_REQUEST['list_id'] = 1;
2454 $_REQUEST['page'] = -1;
2455 $_REQUEST['max_id'] = 10;
2456 $result = api_lists_statuses('json');
2457 foreach ($result['status'] as $status) {
2458 $this->assertStatus($status);
2463 * Test the api_lists_statuses() function with a list ID and a RSS result.
2466 public function testApiListsStatusesWithListIdAndRss()
2468 $_REQUEST['list_id'] = 1;
2469 $result = api_lists_statuses('rss');
2470 $this->assertXml($result, 'statuses');
2474 * Test the api_lists_statuses() function with an unallowed user.
2476 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2478 public function testApiListsStatusesWithUnallowedUser()
2480 $_SESSION['allow_api'] = false;
2481 $_GET['screen_name'] = $this->selfUser['nick'];
2482 api_lists_statuses('json');
2486 * Test the api_statuses_f() function.
2489 public function testApiStatusesFWithFriends()
2492 $result = api_statuses_f('friends');
2493 $this->assertArrayHasKey('user', $result);
2497 * Test the api_statuses_f() function.
2500 public function testApiStatusesFWithFollowers()
2502 $result = api_statuses_f('followers');
2503 $this->assertArrayHasKey('user', $result);
2507 * Test the api_statuses_f() function.
2510 public function testApiStatusesFWithBlocks()
2512 $result = api_statuses_f('blocks');
2513 $this->assertArrayHasKey('user', $result);
2517 * Test the api_statuses_f() function.
2520 public function testApiStatusesFWithIncoming()
2522 $result = api_statuses_f('incoming');
2523 $this->assertArrayHasKey('user', $result);
2527 * Test the api_statuses_f() function an undefined cursor GET variable.
2530 public function testApiStatusesFWithUndefinedCursor()
2532 $_GET['cursor'] = 'undefined';
2533 $this->assertFalse(api_statuses_f('friends'));
2537 * Test the api_statuses_friends() function.
2540 public function testApiStatusesFriends()
2542 $result = api_statuses_friends('json');
2543 $this->assertArrayHasKey('user', $result);
2547 * Test the api_statuses_friends() function an undefined cursor GET variable.
2550 public function testApiStatusesFriendsWithUndefinedCursor()
2552 $_GET['cursor'] = 'undefined';
2553 $this->assertFalse(api_statuses_friends('json'));
2557 * Test the api_statuses_followers() function.
2560 public function testApiStatusesFollowers()
2562 $result = api_statuses_followers('json');
2563 $this->assertArrayHasKey('user', $result);
2567 * Test the api_statuses_followers() function an undefined cursor GET variable.
2570 public function testApiStatusesFollowersWithUndefinedCursor()
2572 $_GET['cursor'] = 'undefined';
2573 $this->assertFalse(api_statuses_followers('json'));
2577 * Test the api_blocks_list() function.
2580 public function testApiBlocksList()
2582 $result = api_blocks_list('json');
2583 $this->assertArrayHasKey('user', $result);
2587 * Test the api_blocks_list() function an undefined cursor GET variable.
2590 public function testApiBlocksListWithUndefinedCursor()
2592 $_GET['cursor'] = 'undefined';
2593 $this->assertFalse(api_blocks_list('json'));
2597 * Test the api_friendships_incoming() function.
2600 public function testApiFriendshipsIncoming()
2602 $result = api_friendships_incoming('json');
2603 $this->assertArrayHasKey('id', $result);
2607 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2610 public function testApiFriendshipsIncomingWithUndefinedCursor()
2612 $_GET['cursor'] = 'undefined';
2613 $this->assertFalse(api_friendships_incoming('json'));
2617 * Test the api_statusnet_config() function.
2620 public function testApiStatusnetConfig()
2622 $result = api_statusnet_config('json');
2623 $this->assertEquals('localhost', $result['config']['site']['server']);
2624 $this->assertEquals('default', $result['config']['site']['theme']);
2625 $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2626 $this->assertTrue($result['config']['site']['fancy']);
2627 $this->assertEquals('en', $result['config']['site']['language']);
2628 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2629 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2630 $this->assertEquals('false', $result['config']['site']['private']);
2631 $this->assertEquals('false', $result['config']['site']['ssl']);
2632 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2636 * Test the api_statusnet_version() function.
2639 public function testApiStatusnetVersion()
2641 $result = api_statusnet_version('json');
2642 $this->assertEquals('0.9.7', $result['version']);
2646 * Test the api_ff_ids() function.
2649 public function testApiFfIds()
2651 $result = api_ff_ids('json');
2652 $this->assertNull($result);
2656 * Test the api_ff_ids() function with a result.
2659 public function testApiFfIdsWithResult()
2661 $this->markTestIncomplete();
2665 * Test the api_ff_ids() function without an authenticated user.
2667 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2669 public function testApiFfIdsWithoutAuthenticatedUser()
2671 $_SESSION['authenticated'] = false;
2676 * Test the api_friends_ids() function.
2679 public function testApiFriendsIds()
2681 $result = api_friends_ids('json');
2682 $this->assertNull($result);
2686 * Test the api_followers_ids() function.
2689 public function testApiFollowersIds()
2691 $result = api_followers_ids('json');
2692 $this->assertNull($result);
2696 * Test the api_direct_messages_new() function.
2699 public function testApiDirectMessagesNew()
2701 $result = api_direct_messages_new('json');
2702 $this->assertNull($result);
2706 * Test the api_direct_messages_new() function without an authenticated user.
2708 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2710 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2712 $_SESSION['authenticated'] = false;
2713 api_direct_messages_new('json');
2717 * Test the api_direct_messages_new() function with an user ID.
2720 public function testApiDirectMessagesNewWithUserId()
2722 $_POST['text'] = 'message_text';
2723 $_POST['user_id'] = $this->otherUser['id'];
2724 $result = api_direct_messages_new('json');
2725 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2729 * Test the api_direct_messages_new() function with a screen name.
2732 public function testApiDirectMessagesNewWithScreenName()
2734 $_POST['text'] = 'message_text';
2735 $_POST['screen_name'] = $this->friendUser['nick'];
2736 $result = api_direct_messages_new('json');
2737 $this->assertEquals(1, $result['direct_message']['id']);
2738 $this->assertContains('message_text', $result['direct_message']['text']);
2739 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2740 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2744 * Test the api_direct_messages_new() function with a title.
2747 public function testApiDirectMessagesNewWithTitle()
2749 $_POST['text'] = 'message_text';
2750 $_POST['screen_name'] = $this->friendUser['nick'];
2751 $_REQUEST['title'] = 'message_title';
2752 $result = api_direct_messages_new('json');
2753 $this->assertEquals(1, $result['direct_message']['id']);
2754 $this->assertContains('message_text', $result['direct_message']['text']);
2755 $this->assertContains('message_title', $result['direct_message']['text']);
2756 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2757 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2761 * Test the api_direct_messages_new() function with an RSS result.
2764 public function testApiDirectMessagesNewWithRss()
2766 $_POST['text'] = 'message_text';
2767 $_POST['screen_name'] = $this->friendUser['nick'];
2768 $result = api_direct_messages_new('rss');
2769 $this->assertXml($result, 'direct-messages');
2773 * Test the api_direct_messages_destroy() function.
2775 * @expectedException Friendica\Network\HTTPException\BadRequestException
2777 public function testApiDirectMessagesDestroy()
2779 api_direct_messages_destroy('json');
2783 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2786 public function testApiDirectMessagesDestroyWithVerbose()
2788 $_GET['friendica_verbose'] = 'true';
2789 $result = api_direct_messages_destroy('json');
2790 $this->assertEquals(
2793 'result' => 'error',
2794 'message' => 'message id or parenturi not specified'
2802 * Test the api_direct_messages_destroy() function without an authenticated user.
2804 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2806 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2808 $_SESSION['authenticated'] = false;
2809 api_direct_messages_destroy('json');
2813 * Test the api_direct_messages_destroy() function with a non-zero ID.
2815 * @expectedException Friendica\Network\HTTPException\BadRequestException
2817 public function testApiDirectMessagesDestroyWithId()
2819 $_REQUEST['id'] = 1;
2820 api_direct_messages_destroy('json');
2824 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2827 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2829 $_REQUEST['id'] = 1;
2830 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2831 $_GET['friendica_verbose'] = 'true';
2832 $result = api_direct_messages_destroy('json');
2833 $this->assertEquals(
2836 'result' => 'error',
2837 'message' => 'message id not in database'
2845 * Test the api_direct_messages_destroy() function with a non-zero ID.
2848 public function testApiDirectMessagesDestroyWithCorrectId()
2850 $this->markTestIncomplete('We need to add a dataset for this.');
2854 * Test the api_direct_messages_box() function.
2857 public function testApiDirectMessagesBoxWithSentbox()
2859 $_REQUEST['page'] = -1;
2860 $_REQUEST['max_id'] = 10;
2861 $result = api_direct_messages_box('json', 'sentbox', 'false');
2862 $this->assertArrayHasKey('direct_message', $result);
2866 * Test the api_direct_messages_box() function.
2869 public function testApiDirectMessagesBoxWithConversation()
2871 $result = api_direct_messages_box('json', 'conversation', 'false');
2872 $this->assertArrayHasKey('direct_message', $result);
2876 * Test the api_direct_messages_box() function.
2879 public function testApiDirectMessagesBoxWithAll()
2881 $result = api_direct_messages_box('json', 'all', 'false');
2882 $this->assertArrayHasKey('direct_message', $result);
2886 * Test the api_direct_messages_box() function.
2889 public function testApiDirectMessagesBoxWithInbox()
2891 $result = api_direct_messages_box('json', 'inbox', 'false');
2892 $this->assertArrayHasKey('direct_message', $result);
2896 * Test the api_direct_messages_box() function.
2899 public function testApiDirectMessagesBoxWithVerbose()
2901 $result = api_direct_messages_box('json', 'sentbox', 'true');
2902 $this->assertEquals(
2905 'result' => 'error',
2906 'message' => 'no mails available'
2914 * Test the api_direct_messages_box() function with a RSS result.
2917 public function testApiDirectMessagesBoxWithRss()
2919 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2920 $this->assertXml($result, 'direct-messages');
2924 * Test the api_direct_messages_box() function without an authenticated user.
2926 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2928 public function testApiDirectMessagesBoxWithUnallowedUser()
2930 $_SESSION['allow_api'] = false;
2931 $_GET['screen_name'] = $this->selfUser['nick'];
2932 api_direct_messages_box('json', 'sentbox', 'false');
2936 * Test the api_direct_messages_sentbox() function.
2939 public function testApiDirectMessagesSentbox()
2941 $result = api_direct_messages_sentbox('json');
2942 $this->assertArrayHasKey('direct_message', $result);
2946 * Test the api_direct_messages_inbox() function.
2949 public function testApiDirectMessagesInbox()
2951 $result = api_direct_messages_inbox('json');
2952 $this->assertArrayHasKey('direct_message', $result);
2956 * Test the api_direct_messages_all() function.
2959 public function testApiDirectMessagesAll()
2961 $result = api_direct_messages_all('json');
2962 $this->assertArrayHasKey('direct_message', $result);
2966 * Test the api_direct_messages_conversation() function.
2969 public function testApiDirectMessagesConversation()
2971 $result = api_direct_messages_conversation('json');
2972 $this->assertArrayHasKey('direct_message', $result);
2976 * Test the api_oauth_request_token() function.
2979 public function testApiOauthRequestToken()
2981 $this->markTestIncomplete('killme() kills phpunit as well');
2985 * Test the api_oauth_access_token() function.
2988 public function testApiOauthAccessToken()
2990 $this->markTestIncomplete('killme() kills phpunit as well');
2994 * Test the api_fr_photoalbum_delete() function.
2996 * @expectedException Friendica\Network\HTTPException\BadRequestException
2998 public function testApiFrPhotoalbumDelete()
3000 api_fr_photoalbum_delete('json');
3004 * Test the api_fr_photoalbum_delete() function with an album name.
3006 * @expectedException Friendica\Network\HTTPException\BadRequestException
3008 public function testApiFrPhotoalbumDeleteWithAlbum()
3010 $_REQUEST['album'] = 'album_name';
3011 api_fr_photoalbum_delete('json');
3015 * Test the api_fr_photoalbum_delete() function with an album name.
3018 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3020 $this->markTestIncomplete('We need to add a dataset for this.');
3024 * Test the api_fr_photoalbum_delete() function.
3026 * @expectedException Friendica\Network\HTTPException\BadRequestException
3028 public function testApiFrPhotoalbumUpdate()
3030 api_fr_photoalbum_update('json');
3034 * Test the api_fr_photoalbum_delete() function with an album name.
3036 * @expectedException Friendica\Network\HTTPException\BadRequestException
3038 public function testApiFrPhotoalbumUpdateWithAlbum()
3040 $_REQUEST['album'] = 'album_name';
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 testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3051 $_REQUEST['album'] = 'album_name';
3052 $_REQUEST['album_new'] = 'album_name';
3053 api_fr_photoalbum_update('json');
3057 * Test the api_fr_photoalbum_update() function without an authenticated user.
3059 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3061 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3063 $_SESSION['authenticated'] = false;
3064 api_fr_photoalbum_update('json');
3068 * Test the api_fr_photoalbum_delete() function with an album name.
3071 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3073 $this->markTestIncomplete('We need to add a dataset for this.');
3077 * Test the api_fr_photos_list() function.
3080 public function testApiFrPhotosList()
3082 $result = api_fr_photos_list('json');
3083 $this->assertArrayHasKey('photo', $result);
3087 * Test the api_fr_photos_list() function without an authenticated user.
3089 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3091 public function testApiFrPhotosListWithoutAuthenticatedUser()
3093 $_SESSION['authenticated'] = false;
3094 api_fr_photos_list('json');
3098 * Test the api_fr_photo_create_update() function.
3100 * @expectedException Friendica\Network\HTTPException\BadRequestException
3102 public function testApiFrPhotoCreateUpdate()
3104 api_fr_photo_create_update('json');
3108 * Test the api_fr_photo_create_update() function without an authenticated user.
3110 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3112 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3114 $_SESSION['authenticated'] = false;
3115 api_fr_photo_create_update('json');
3119 * Test the api_fr_photo_create_update() function with an album name.
3121 * @expectedException Friendica\Network\HTTPException\BadRequestException
3123 public function testApiFrPhotoCreateUpdateWithAlbum()
3125 $_REQUEST['album'] = 'album_name';
3126 api_fr_photo_create_update('json');
3130 * Test the api_fr_photo_create_update() function with the update mode.
3133 public function testApiFrPhotoCreateUpdateWithUpdate()
3135 $this->markTestIncomplete('We need to create a dataset for this');
3139 * Test the api_fr_photo_create_update() function with an uploaded file.
3142 public function testApiFrPhotoCreateUpdateWithFile()
3144 $this->markTestIncomplete();
3148 * Test the api_fr_photo_delete() function.
3150 * @expectedException Friendica\Network\HTTPException\BadRequestException
3152 public function testApiFrPhotoDelete()
3154 api_fr_photo_delete('json');
3158 * Test the api_fr_photo_delete() function without an authenticated user.
3160 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3162 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3164 $_SESSION['authenticated'] = false;
3165 api_fr_photo_delete('json');
3169 * Test the api_fr_photo_delete() function with a photo ID.
3171 * @expectedException Friendica\Network\HTTPException\BadRequestException
3173 public function testApiFrPhotoDeleteWithPhotoId()
3175 $_REQUEST['photo_id'] = 1;
3176 api_fr_photo_delete('json');
3180 * Test the api_fr_photo_delete() function with a correct photo ID.
3183 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3185 $this->markTestIncomplete('We need to create a dataset for this.');
3189 * Test the api_fr_photo_detail() function.
3191 * @expectedException Friendica\Network\HTTPException\BadRequestException
3193 public function testApiFrPhotoDetail()
3195 api_fr_photo_detail('json');
3199 * Test the api_fr_photo_detail() function without an authenticated user.
3201 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3203 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3205 $_SESSION['authenticated'] = false;
3206 api_fr_photo_detail('json');
3210 * Test the api_fr_photo_detail() function with a photo ID.
3212 * @expectedException Friendica\Network\HTTPException\NotFoundException
3214 public function testApiFrPhotoDetailWithPhotoId()
3216 $_REQUEST['photo_id'] = 1;
3217 api_fr_photo_detail('json');
3221 * Test the api_fr_photo_detail() function with a correct photo ID.
3224 public function testApiFrPhotoDetailCorrectPhotoId()
3226 $this->markTestIncomplete('We need to create a dataset for this.');
3230 * Test the api_account_update_profile_image() function.
3232 * @expectedException Friendica\Network\HTTPException\BadRequestException
3234 public function testApiAccountUpdateProfileImage()
3236 api_account_update_profile_image('json');
3240 * Test the api_account_update_profile_image() function without an authenticated user.
3242 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3244 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3246 $_SESSION['authenticated'] = false;
3247 api_account_update_profile_image('json');
3251 * Test the api_account_update_profile_image() function with an uploaded file.
3253 * @expectedException Friendica\Network\HTTPException\BadRequestException
3255 public function testApiAccountUpdateProfileImageWithUpload()
3257 $this->markTestIncomplete();
3262 * Test the api_account_update_profile() function.
3265 public function testApiAccountUpdateProfile()
3267 $_POST['name'] = 'new_name';
3268 $_POST['description'] = 'new_description';
3269 $result = api_account_update_profile('json');
3270 // We can't use assertSelfUser() here because the user object is missing some properties.
3271 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3272 $this->assertEquals('Friendica', $result['user']['location']);
3273 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3274 $this->assertEquals('dfrn', $result['user']['network']);
3275 $this->assertEquals('new_name', $result['user']['name']);
3276 $this->assertEquals('new_description', $result['user']['description']);
3280 * Test the check_acl_input() function.
3283 public function testCheckAclInput()
3285 $result = check_acl_input('<aclstring>');
3286 // Where does this result come from?
3287 $this->assertEquals(1, $result);
3291 * Test the check_acl_input() function with an empty ACL string.
3294 public function testCheckAclInputWithEmptyAclString()
3296 $result = check_acl_input(' ');
3297 $this->assertFalse($result);
3301 * Test the save_media_to_database() function.
3304 public function testSaveMediaToDatabase()
3306 $this->markTestIncomplete();
3310 * Test the post_photo_item() function.
3313 public function testPostPhotoItem()
3315 $this->markTestIncomplete();
3319 * Test the prepare_photo_data() function.
3322 public function testPreparePhotoData()
3324 $this->markTestIncomplete();
3328 * Test the api_friendica_remoteauth() function.
3330 * @expectedException Friendica\Network\HTTPException\BadRequestException
3332 public function testApiFriendicaRemoteauth()
3334 api_friendica_remoteauth();
3338 * Test the api_friendica_remoteauth() function with an URL.
3340 * @expectedException Friendica\Network\HTTPException\BadRequestException
3342 public function testApiFriendicaRemoteauthWithUrl()
3344 $_GET['url'] = 'url';
3345 $_GET['c_url'] = 'url';
3346 api_friendica_remoteauth();
3350 * Test the api_friendica_remoteauth() function with a correct URL.
3353 public function testApiFriendicaRemoteauthWithCorrectUrl()
3355 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3356 $_GET['url'] = 'url';
3357 $_GET['c_url'] = $this->selfUser['nurl'];
3358 api_friendica_remoteauth();
3362 * Test the api_share_as_retweet() function.
3365 public function testApiShareAsRetweet()
3367 $item = ['body' => ''];
3368 $result = api_share_as_retweet($item);
3369 $this->assertFalse($result);
3373 * Test the api_share_as_retweet() function with a valid item.
3376 public function testApiShareAsRetweetWithValidItem()
3378 $this->markTestIncomplete();
3382 * Test the api_get_nick() function.
3385 public function testApiGetNick()
3387 $result = api_get_nick($this->otherUser['nurl']);
3388 $this->assertEquals('othercontact', $result);
3392 * Test the api_get_nick() function with a wrong URL.
3395 public function testApiGetNickWithWrongUrl()
3397 $result = api_get_nick('wrong_url');
3398 $this->assertFalse($result);
3402 * Test the api_in_reply_to() function.
3405 public function testApiInReplyTo()
3407 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3408 $this->assertArrayHasKey('status_id', $result);
3409 $this->assertArrayHasKey('user_id', $result);
3410 $this->assertArrayHasKey('status_id_str', $result);
3411 $this->assertArrayHasKey('user_id_str', $result);
3412 $this->assertArrayHasKey('screen_name', $result);
3416 * Test the api_in_reply_to() function with a valid item.
3419 public function testApiInReplyToWithValidItem()
3421 $this->markTestIncomplete();
3425 * Test the api_clean_plain_items() function.
3428 public function testApiCleanPlainItems()
3430 $_REQUEST['include_entities'] = 'true';
3431 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3432 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3436 * Test the api_clean_attachments() function.
3439 public function testApiCleanAttachments()
3441 $this->markTestIncomplete();
3445 * Test the api_best_nickname() function.
3448 public function testApiBestNickname()
3451 $result = api_best_nickname($contacts);
3452 $this->assertNull($result);
3456 * Test the api_best_nickname() function with contacts.
3459 public function testApiBestNicknameWithContacts()
3461 $this->markTestIncomplete();
3465 * Test the api_friendica_group_show() function.
3468 public function testApiFriendicaGroupShow()
3470 $this->markTestIncomplete();
3474 * Test the api_friendica_group_delete() function.
3477 public function testApiFriendicaGroupDelete()
3479 $this->markTestIncomplete();
3483 * Test the api_lists_destroy() function.
3486 public function testApiListsDestroy()
3488 $this->markTestIncomplete();
3492 * Test the group_create() function.
3495 public function testGroupCreate()
3497 $this->markTestIncomplete();
3501 * Test the api_friendica_group_create() function.
3504 public function testApiFriendicaGroupCreate()
3506 $this->markTestIncomplete();
3510 * Test the api_lists_create() function.
3513 public function testApiListsCreate()
3515 $this->markTestIncomplete();
3519 * Test the api_friendica_group_update() function.
3522 public function testApiFriendicaGroupUpdate()
3524 $this->markTestIncomplete();
3528 * Test the api_lists_update() function.
3531 public function testApiListsUpdate()
3533 $this->markTestIncomplete();
3537 * Test the api_friendica_activity() function.
3540 public function testApiFriendicaActivity()
3542 $this->markTestIncomplete();
3546 * Test the api_friendica_notification() function.
3548 * @expectedException Friendica\Network\HTTPException\BadRequestException
3550 public function testApiFriendicaNotification()
3552 api_friendica_notification('json');
3556 * Test the api_friendica_notification() function without an authenticated user.
3558 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3560 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3562 $_SESSION['authenticated'] = false;
3563 api_friendica_notification('json');
3567 * Test the api_friendica_notification() function with an argument count.
3570 public function testApiFriendicaNotificationWithArgumentCount()
3572 $this->app->argv = ['api', 'friendica', 'notification'];
3573 $this->app->argc = count($this->app->argv);
3574 $result = api_friendica_notification('json');
3575 $this->assertEquals(['note' => false], $result);
3579 * Test the api_friendica_notification() function with an XML result.
3582 public function testApiFriendicaNotificationWithXmlResult()
3584 $this->app->argv = ['api', 'friendica', 'notification'];
3585 $this->app->argc = count($this->app->argv);
3586 $result = api_friendica_notification('xml');
3587 $this->assertXml($result, 'notes');
3591 * Test the api_friendica_notification_seen() function.
3594 public function testApiFriendicaNotificationSeen()
3596 $this->markTestIncomplete();
3600 * Test the api_friendica_direct_messages_setseen() function.
3603 public function testApiFriendicaDirectMessagesSetseen()
3605 $this->markTestIncomplete();
3609 * Test the api_friendica_direct_messages_search() function.
3612 public function testApiFriendicaDirectMessagesSearch()
3614 $this->markTestIncomplete();
3618 * Test the api_friendica_profile_show() function.
3621 public function testApiFriendicaProfileShow()
3623 $result = api_friendica_profile_show('json');
3624 // We can't use assertSelfUser() here because the user object is missing some properties.
3625 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3626 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3627 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3628 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3629 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3630 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3631 $this->assertFalse($result['$result']['multi_profiles']);
3635 * Test the api_friendica_profile_show() function with a profile ID.
3638 public function testApiFriendicaProfileShowWithProfileId()
3640 $this->markTestIncomplete('We need to add a dataset for this.');
3644 * Test the api_friendica_profile_show() function with a wrong profile ID.
3646 * @expectedException Friendica\Network\HTTPException\BadRequestException
3648 public function testApiFriendicaProfileShowWithWrongProfileId()
3650 $_REQUEST['profile_id'] = 666;
3651 api_friendica_profile_show('json');
3655 * Test the api_friendica_profile_show() function without an authenticated user.
3657 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3659 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3661 $_SESSION['authenticated'] = false;
3662 api_friendica_profile_show('json');
3666 * Test the api_saved_searches_list() function.
3669 public function testApiSavedSearchesList()
3671 $result = api_saved_searches_list('json');
3672 $this->assertEquals(1, $result['terms'][0]['id']);
3673 $this->assertEquals(1, $result['terms'][0]['id_str']);
3674 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3675 $this->assertEquals('Saved search', $result['terms'][0]['query']);