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;
16 * Tests for the API functions.
18 * Functions that use header() need to be tested in a separate process.
19 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
21 class ApiTest extends DatabaseTest
25 * Create variables used by tests.
27 protected function setUp()
32 // Reusable App object
33 $this->app = new App(__DIR__.'/../');
36 // User data that the test database is populated with
39 'name' => 'Self contact',
40 'nick' => 'selfcontact',
41 'nurl' => 'http://localhost/profile/selfcontact'
45 'name' => 'Friend contact',
46 'nick' => 'friendcontact',
47 'nurl' => 'http://localhost/profile/friendcontact'
51 'name' => 'othercontact',
52 'nick' => 'othercontact',
53 'nurl' => 'http://localhost/profile/othercontact'
56 // User ID that we know is not in the database
57 $this->wrongUserId = 666;
59 // Most API require login so we force the session
62 'authenticated' => true,
63 'uid' => $this->selfUser['id']
67 Config::set('config', 'hostname', 'localhost');
68 Config::set('system', 'throttle_limit_day', 100);
69 Config::set('system', 'throttle_limit_week', 100);
70 Config::set('system', 'throttle_limit_month', 100);
71 Config::set('system', 'theme', 'system_theme');
75 * Assert that an user array contains expected keys.
76 * @param array $user User array
79 private function assertSelfUser(array $user)
81 $this->assertEquals($this->selfUser['id'], $user['uid']);
82 $this->assertEquals($this->selfUser['id'], $user['cid']);
83 $this->assertEquals(1, $user['self']);
84 $this->assertEquals('Friendica', $user['location']);
85 $this->assertEquals($this->selfUser['name'], $user['name']);
86 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
87 $this->assertEquals('dfrn', $user['network']);
88 $this->assertTrue($user['verified']);
92 * Assert that an user array contains expected keys.
93 * @param array $user User array
96 private function assertOtherUser(array $user)
98 $this->assertEquals($this->otherUser['id'], $user['id']);
99 $this->assertEquals($this->otherUser['id'], $user['id_str']);
100 $this->assertEquals(0, $user['self']);
101 $this->assertEquals($this->otherUser['name'], $user['name']);
102 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
103 $this->assertFalse($user['verified']);
107 * Assert that a status array contains expected keys.
108 * @param array $status Status array
111 private function assertStatus(array $status)
113 $this->assertInternalType('string', $status['text']);
114 $this->assertInternalType('int', $status['id']);
115 // We could probably do more checks here.
119 * Assert that a list array contains expected keys.
120 * @param array $list List array
123 private function assertList(array $list)
125 $this->assertInternalType('string', $list['name']);
126 $this->assertInternalType('int', $list['id']);
127 $this->assertInternalType('string', $list['id_str']);
128 $this->assertContains($list['mode'], ['public', 'private']);
129 // We could probably do more checks here.
133 * Assert that the string is XML and contain the root element.
134 * @param string $result XML string
135 * @param string $root_element Root element name
138 private function assertXml($result, $root_element)
140 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
141 $this->assertContains('<'.$root_element, $result);
142 // We could probably do more checks here.
146 * Get the path to a temporary empty PNG image.
147 * @return string Path
149 private function getTempImage()
151 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
155 // Empty 1x1 px PNG image
156 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
164 * Test the api_user() function.
167 public function testApiUser()
169 $this->assertEquals($this->selfUser['id'], api_user());
173 * Test the api_user() function with an unallowed user.
176 public function testApiUserWithUnallowedUser()
178 $_SESSION = ['allow_api' => false];
179 $this->assertEquals(false, api_user());
183 * Test the api_source() function.
186 public function testApiSource()
188 $this->assertEquals('api', api_source());
192 * Test the api_source() function with a Twidere user agent.
195 public function testApiSourceWithTwidere()
197 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
198 $this->assertEquals('Twidere', api_source());
202 * Test the api_source() function with a GET parameter.
205 public function testApiSourceWithGet()
207 $_GET['source'] = 'source_name';
208 $this->assertEquals('source_name', api_source());
212 * Test the api_date() function.
215 public function testApiDate()
217 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
221 * Test the api_register_func() function.
224 public function testApiRegisterFunc()
236 $this->assertTrue($API['api_path']['auth']);
237 $this->assertEquals('method', $API['api_path']['method']);
238 $this->assertTrue(is_callable($API['api_path']['func']));
242 * Test the api_login() function without any login.
244 * @runInSeparateProcess
245 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
247 public function testApiLoginWithoutLogin()
249 api_login($this->app);
253 * Test the api_login() function with a bad login.
255 * @runInSeparateProcess
256 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
258 public function testApiLoginWithBadLogin()
260 $_SERVER['PHP_AUTH_USER'] = 'user@server';
261 api_login($this->app);
265 * Test the api_login() function with oAuth.
268 public function testApiLoginWithOauth()
270 $this->markTestIncomplete('Can we test this easily?');
274 * Test the api_login() function with authentication provided by an addon.
277 public function testApiLoginWithAddonAuth()
279 $this->markTestIncomplete('Can we test this easily?');
283 * Test the api_login() function with a correct login.
285 * @runInSeparateProcess
287 public function testApiLoginWithCorrectLogin()
289 $_SERVER['PHP_AUTH_USER'] = 'Test user';
290 $_SERVER['PHP_AUTH_PW'] = 'password';
291 api_login($this->app);
295 * Test the api_login() function with a remote user.
297 * @runInSeparateProcess
298 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
300 public function testApiLoginWithRemoteUser()
302 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
303 api_login($this->app);
307 * Test the api_check_method() function.
310 public function testApiCheckMethod()
312 $this->assertFalse(api_check_method('method'));
316 * Test the api_check_method() function with a correct method.
319 public function testApiCheckMethodWithCorrectMethod()
321 $_SERVER['REQUEST_METHOD'] = 'method';
322 $this->assertTrue(api_check_method('method'));
326 * Test the api_check_method() function with a wildcard.
329 public function testApiCheckMethodWithWildcard()
331 $this->assertTrue(api_check_method('*'));
335 * Test the api_call() function.
337 * @runInSeparateProcess
339 public function testApiCall()
343 'method' => 'method',
344 'func' => function () {
345 return ['data' => ['some_data']];
348 $_SERVER['REQUEST_METHOD'] = 'method';
349 $_GET['callback'] = 'callback_name';
351 $this->app->query_string = 'api_path';
353 'callback_name(["some_data"])',
359 * Test the api_call() function with the profiled enabled.
361 * @runInSeparateProcess
363 public function testApiCallWithProfiler()
367 'method' => 'method',
368 'func' => function () {
369 return ['data' => ['some_data']];
372 $_SERVER['REQUEST_METHOD'] = 'method';
373 Config::set('system', 'profiler', true);
374 Config::set('rendertime', 'callstack', true);
375 $this->app->callstack = [
376 'database' => ['some_function' => 200],
377 'database_write' => ['some_function' => 200],
378 'cache' => ['some_function' => 200],
379 'cache_write' => ['some_function' => 200],
380 'network' => ['some_function' => 200]
383 $this->app->query_string = 'api_path';
391 * Test the api_call() function without any result.
393 * @runInSeparateProcess
395 public function testApiCallWithNoResult()
399 'method' => 'method',
400 'func' => function () {
404 $_SERVER['REQUEST_METHOD'] = 'method';
406 $this->app->query_string = 'api_path';
408 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
414 * Test the api_call() function with an unimplemented API.
416 * @runInSeparateProcess
418 public function testApiCallWithUninplementedApi()
421 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
427 * Test the api_call() function with a JSON result.
429 * @runInSeparateProcess
431 public function testApiCallWithJson()
435 'method' => 'method',
436 'func' => function () {
437 return ['data' => ['some_data']];
440 $_SERVER['REQUEST_METHOD'] = 'method';
442 $this->app->query_string = 'api_path.json';
450 * Test the api_call() function with an XML result.
452 * @runInSeparateProcess
454 public function testApiCallWithXml()
458 'method' => 'method',
459 'func' => function () {
463 $_SERVER['REQUEST_METHOD'] = 'method';
465 $this->app->query_string = 'api_path.xml';
473 * Test the api_call() function with an RSS result.
475 * @runInSeparateProcess
477 public function testApiCallWithRss()
481 'method' => 'method',
482 'func' => function () {
486 $_SERVER['REQUEST_METHOD'] = 'method';
488 $this->app->query_string = 'api_path.rss';
490 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
497 * Test the api_call() function with an Atom result.
499 * @runInSeparateProcess
501 public function testApiCallWithAtom()
505 'method' => 'method',
506 'func' => function () {
510 $_SERVER['REQUEST_METHOD'] = 'method';
512 $this->app->query_string = 'api_path.atom';
514 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
521 * Test the api_call() function with an unallowed method.
523 * @runInSeparateProcess
525 public function testApiCallWithWrongMethod()
528 $API['api_path'] = ['method' => 'method'];
530 $this->app->query_string = 'api_path';
532 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
538 * Test the api_call() function with an unauthorized user.
540 * @runInSeparateProcess
542 public function testApiCallWithWrongAuth()
546 'method' => 'method',
549 $_SERVER['REQUEST_METHOD'] = 'method';
550 $_SESSION['authenticated'] = false;
552 $this->app->query_string = 'api_path';
554 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
560 * Test the api_error() function with a JSON result.
562 * @runInSeparateProcess
564 public function testApiErrorWithJson()
567 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
568 api_error('json', new HTTPException('error_message'))
573 * Test the api_error() function with an XML result.
575 * @runInSeparateProcess
577 public function testApiErrorWithXml()
580 '<?xml version="1.0"?>'."\n".
581 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
582 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
583 'xmlns:georss="http://www.georss.org/georss">'."\n".
584 ' <error>error_message</error>'."\n".
585 ' <code>200 Friendica\Network\HTTP</code>'."\n".
588 api_error('xml', new HTTPException('error_message'))
593 * Test the api_error() function with an RSS result.
595 * @runInSeparateProcess
597 public function testApiErrorWithRss()
600 '<?xml version="1.0"?>'."\n".
601 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
602 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
603 'xmlns:georss="http://www.georss.org/georss">'."\n".
604 ' <error>error_message</error>'."\n".
605 ' <code>200 Friendica\Network\HTTP</code>'."\n".
608 api_error('rss', new HTTPException('error_message'))
613 * Test the api_error() function with an Atom result.
615 * @runInSeparateProcess
617 public function testApiErrorWithAtom()
620 '<?xml version="1.0"?>'."\n".
621 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
622 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
623 'xmlns:georss="http://www.georss.org/georss">'."\n".
624 ' <error>error_message</error>'."\n".
625 ' <code>200 Friendica\Network\HTTP</code>'."\n".
628 api_error('atom', new HTTPException('error_message'))
633 * Test the api_rss_extra() function.
636 public function testApiRssExtra()
638 $user_info = ['url' => 'user_url', 'lang' => 'en'];
639 $result = api_rss_extra($this->app, [], $user_info);
640 $this->assertEquals($user_info, $result['$user']);
641 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
642 $this->assertArrayHasKey('self', $result['$rss']);
643 $this->assertArrayHasKey('base', $result['$rss']);
644 $this->assertArrayHasKey('updated', $result['$rss']);
645 $this->assertArrayHasKey('atom_updated', $result['$rss']);
646 $this->assertArrayHasKey('language', $result['$rss']);
647 $this->assertArrayHasKey('logo', $result['$rss']);
651 * Test the api_rss_extra() function without any user info.
653 * @runInSeparateProcess
655 public function testApiRssExtraWithoutUserInfo()
657 $result = api_rss_extra($this->app, [], null);
658 $this->assertInternalType('array', $result['$user']);
659 $this->assertArrayHasKey('alternate', $result['$rss']);
660 $this->assertArrayHasKey('self', $result['$rss']);
661 $this->assertArrayHasKey('base', $result['$rss']);
662 $this->assertArrayHasKey('updated', $result['$rss']);
663 $this->assertArrayHasKey('atom_updated', $result['$rss']);
664 $this->assertArrayHasKey('language', $result['$rss']);
665 $this->assertArrayHasKey('logo', $result['$rss']);
669 * Test the api_unique_id_to_nurl() function.
672 public function testApiUniqueIdToNurl()
674 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
678 * Test the api_unique_id_to_nurl() function with a correct ID.
681 public function testApiUniqueIdToNurlWithCorrectId()
683 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
687 * Test the api_get_user() function.
689 * @runInSeparateProcess
691 public function testApiGetUser()
693 $user = api_get_user($this->app);
694 $this->assertSelfUser($user);
695 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
696 $this->assertEquals('6fdbe8', $user['profile_link_color']);
697 $this->assertEquals('ededed', $user['profile_background_color']);
701 * Test the api_get_user() function with a Frio schema.
703 * @runInSeparateProcess
705 public function testApiGetUserWithFrioSchema()
707 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
708 $user = api_get_user($this->app);
709 $this->assertSelfUser($user);
710 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
711 $this->assertEquals('6fdbe8', $user['profile_link_color']);
712 $this->assertEquals('ededed', $user['profile_background_color']);
716 * Test the api_get_user() function with a custom Frio schema.
718 * @runInSeparateProcess
720 public function testApiGetUserWithCustomFrioSchema()
722 var_dump($this->app->mode, \Friendica\App::MODE_DBCONFIGAVAILABLE, $this->app->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE);
724 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
725 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
726 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
727 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
729 var_dump($ret1, $ret2, $ret3, $ret4, dba::inArray(dba::select('pconfig', [])));
731 $user = api_get_user($this->app);
732 $this->assertSelfUser($user);
733 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
734 $this->assertEquals('123456', $user['profile_link_color']);
735 $this->assertEquals('123456', $user['profile_background_color']);
739 * Test the api_get_user() function with an empty Frio schema.
741 * @runInSeparateProcess
743 public function testApiGetUserWithEmptyFrioSchema()
745 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
746 $user = api_get_user($this->app);
747 $this->assertSelfUser($user);
748 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
749 $this->assertEquals('6fdbe8', $user['profile_link_color']);
750 $this->assertEquals('ededed', $user['profile_background_color']);
754 * Test the api_get_user() function with an user that is not allowed to use the API.
756 * @runInSeparateProcess
758 public function testApiGetUserWithoutApiUser()
760 $_SERVER['PHP_AUTH_USER'] = 'Test user';
761 $_SERVER['PHP_AUTH_PW'] = 'password';
762 $_SESSION['allow_api'] = false;
763 $this->assertFalse(api_get_user($this->app));
767 * Test the api_get_user() function with an user ID in a GET parameter.
769 * @runInSeparateProcess
771 public function testApiGetUserWithGetId()
773 $_GET['user_id'] = $this->otherUser['id'];
774 $this->assertOtherUser(api_get_user($this->app));
778 * Test the api_get_user() function with a wrong user ID in a GET parameter.
780 * @runInSeparateProcess
781 * @expectedException Friendica\Network\HTTPException\BadRequestException
783 public function testApiGetUserWithWrongGetId()
785 $_GET['user_id'] = $this->wrongUserId;
786 $this->assertOtherUser(api_get_user($this->app));
790 * Test the api_get_user() function with an user name in a GET parameter.
792 * @runInSeparateProcess
794 public function testApiGetUserWithGetName()
796 $_GET['screen_name'] = $this->selfUser['nick'];
797 $this->assertSelfUser(api_get_user($this->app));
801 * Test the api_get_user() function with a profile URL in a GET parameter.
803 * @runInSeparateProcess
805 public function testApiGetUserWithGetUrl()
807 $_GET['profileurl'] = $this->selfUser['nurl'];
808 $this->assertSelfUser(api_get_user($this->app));
812 * Test the api_get_user() function with an user ID in the API path.
814 * @runInSeparateProcess
816 public function testApiGetUserWithNumericCalledApi()
819 $called_api = ['api_path'];
820 $this->app->argv[1] = $this->otherUser['id'].'.json';
821 $this->assertOtherUser(api_get_user($this->app));
825 * Test the api_get_user() function with the $called_api global variable.
827 * @runInSeparateProcess
829 public function testApiGetUserWithCalledApi()
832 $called_api = ['api', 'api_path'];
833 $this->assertSelfUser(api_get_user($this->app));
837 * Test the api_get_user() function with a valid user.
839 * @runInSeparateProcess
841 public function testApiGetUserWithCorrectUser()
843 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
847 * Test the api_get_user() function with a wrong user ID.
849 * @runInSeparateProcess
850 * @expectedException Friendica\Network\HTTPException\BadRequestException
852 public function testApiGetUserWithWrongUser()
854 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
858 * Test the api_get_user() function with a 0 user ID.
860 * @runInSeparateProcess
862 public function testApiGetUserWithZeroUser()
864 $this->assertSelfUser(api_get_user($this->app, 0));
868 * Test the api_item_get_user() function.
870 * @runInSeparateProcess
872 public function testApiItemGetUser()
874 $users = api_item_get_user($this->app, []);
875 $this->assertSelfUser($users[0]);
879 * Test the api_item_get_user() function with a different item parent.
882 public function testApiItemGetUserWithDifferentParent()
884 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
885 $this->assertSelfUser($users[0]);
886 $this->assertEquals($users[0], $users[1]);
890 * Test the api_walk_recursive() function.
893 public function testApiWalkRecursive()
901 // Should we test this with a callback that actually does something?
909 * Test the api_walk_recursive() function with an array.
912 public function testApiWalkRecursiveWithArray()
914 $array = [['item1'], ['item2']];
920 // Should we test this with a callback that actually does something?
928 * Test the api_reformat_xml() function.
931 public function testApiReformatXml()
935 $this->assertTrue(api_reformat_xml($item, $key));
936 $this->assertEquals('true', $item);
940 * Test the api_reformat_xml() function with a statusnet_api key.
943 public function testApiReformatXmlWithStatusnetKey()
946 $key = 'statusnet_api';
947 $this->assertTrue(api_reformat_xml($item, $key));
948 $this->assertEquals('statusnet:api', $key);
952 * Test the api_reformat_xml() function with a friendica_api key.
955 public function testApiReformatXmlWithFriendicaKey()
958 $key = 'friendica_api';
959 $this->assertTrue(api_reformat_xml($item, $key));
960 $this->assertEquals('friendica:api', $key);
964 * Test the api_create_xml() function.
967 public function testApiCreateXml()
970 '<?xml version="1.0"?>'."\n".
971 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
972 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
973 'xmlns:georss="http://www.georss.org/georss">'."\n".
974 ' <data>some_data</data>'."\n".
975 '</root_element>'."\n",
976 api_create_xml(['data' => ['some_data']], 'root_element')
981 * Test the api_create_xml() function without any XML namespace.
984 public function testApiCreateXmlWithoutNamespaces()
987 '<?xml version="1.0"?>'."\n".
989 ' <data>some_data</data>'."\n".
991 api_create_xml(['data' => ['some_data']], 'ok')
996 * Test the api_format_data() function.
999 public function testApiFormatData()
1001 $data = ['some_data'];
1002 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1006 * Test the api_format_data() function with an XML result.
1009 public function testApiFormatDataWithXml()
1011 $this->assertEquals(
1012 '<?xml version="1.0"?>'."\n".
1013 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1014 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1015 'xmlns:georss="http://www.georss.org/georss">'."\n".
1016 ' <data>some_data</data>'."\n".
1017 '</root_element>'."\n",
1018 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1023 * Test the api_account_verify_credentials() function.
1026 public function testApiAccountVerifyCredentials()
1028 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1032 * Test the api_account_verify_credentials() function without an authenticated user.
1034 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1036 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1038 $_SESSION['authenticated'] = false;
1039 api_account_verify_credentials('json');
1043 * Test the requestdata() function.
1046 public function testRequestdata()
1048 $this->assertNull(requestdata('variable_name'));
1052 * Test the requestdata() function with a POST parameter.
1055 public function testRequestdataWithPost()
1057 $_POST['variable_name'] = 'variable_value';
1058 $this->assertEquals('variable_value', requestdata('variable_name'));
1062 * Test the requestdata() function with a GET parameter.
1065 public function testRequestdataWithGet()
1067 $_GET['variable_name'] = 'variable_value';
1068 $this->assertEquals('variable_value', requestdata('variable_name'));
1072 * Test the api_statuses_mediap() function.
1075 public function testApiStatusesMediap()
1077 $this->app->argc = 2;
1085 'tmp_name' => $this->getTempImage(),
1086 'name' => 'spacer.png',
1087 'type' => 'image/png'
1090 $_GET['status'] = '<b>Status content</b>';
1092 $result = api_statuses_mediap('json');
1093 $this->assertStatus($result['status']);
1097 * Test the api_statuses_mediap() function without an authenticated user.
1099 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1101 public function testApiStatusesMediapWithoutAuthenticatedUser()
1103 $_SESSION['authenticated'] = false;
1104 api_statuses_mediap('json');
1108 * Test the api_statuses_update() function.
1111 public function testApiStatusesUpdate()
1113 $_GET['status'] = 'Status content';
1114 $_GET['in_reply_to_status_id'] = -1;
1123 'tmp_name' => $this->getTempImage(),
1124 'name' => 'spacer.png',
1125 'type' => 'image/png'
1129 $result = api_statuses_update('json');
1130 $this->assertStatus($result['status']);
1134 * Test the api_statuses_update() function with an HTML status.
1137 public function testApiStatusesUpdateWithHtml()
1139 $_GET['htmlstatus'] = '<b>Status content</b>';
1141 $result = api_statuses_update('json');
1142 $this->assertStatus($result['status']);
1146 * Test the api_statuses_update() function without an authenticated user.
1148 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1150 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1152 $_SESSION['authenticated'] = false;
1153 api_statuses_update('json');
1157 * Test the api_statuses_update() function with a parent status.
1160 public function testApiStatusesUpdateWithParent()
1162 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1166 * Test the api_statuses_update() function with a media_ids parameter.
1169 public function testApiStatusesUpdateWithMediaIds()
1171 $this->markTestIncomplete();
1175 * Test the api_statuses_update() function with the throttle limit reached.
1178 public function testApiStatusesUpdateWithDayThrottleReached()
1180 $this->markTestIncomplete();
1184 * Test the api_media_upload() function.
1186 * @expectedException Friendica\Network\HTTPException\BadRequestException
1188 public function testApiMediaUpload()
1194 * Test the api_media_upload() function without an authenticated user.
1196 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1198 public function testApiMediaUploadWithoutAuthenticatedUser()
1200 $_SESSION['authenticated'] = false;
1205 * Test the api_media_upload() function with an invalid uploaded media.
1207 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1209 public function testApiMediaUploadWithMedia()
1220 * Test the api_media_upload() function with an valid uploaded media.
1223 public function testApiMediaUploadWithValidMedia()
1231 'tmp_name' => $this->getTempImage(),
1232 'name' => 'spacer.png',
1233 'type' => 'image/png'
1239 $result = api_media_upload();
1240 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1241 $this->assertEquals(1, $result['media']['image']['w']);
1242 $this->assertEquals(1, $result['media']['image']['h']);
1246 * Test the api_status_show() function.
1249 public function testApiStatusShow()
1251 $result = api_status_show('json');
1252 $this->assertStatus($result['status']);
1256 * Test the api_status_show() function with an XML result.
1259 public function testApiStatusShowWithXml()
1261 $result = api_status_show('xml');
1262 $this->assertXml($result, 'statuses');
1266 * Test the api_status_show() function with a raw result.
1269 public function testApiStatusShowWithRaw()
1271 $this->assertStatus(api_status_show('raw'));
1275 * Test the api_users_show() function.
1278 public function testApiUsersShow()
1280 $result = api_users_show('json');
1281 // We can't use assertSelfUser() here because the user object is missing some properties.
1282 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1283 $this->assertEquals('Friendica', $result['user']['location']);
1284 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1285 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1286 $this->assertEquals('dfrn', $result['user']['network']);
1287 $this->assertTrue($result['user']['verified']);
1291 * Test the api_users_show() function with an XML result.
1294 public function testApiUsersShowWithXml()
1296 $result = api_users_show('xml');
1297 $this->assertXml($result, 'statuses');
1301 * Test the api_users_search() function.
1304 public function testApiUsersSearch()
1306 $_GET['q'] = 'othercontact';
1307 $result = api_users_search('json');
1308 $this->assertOtherUser($result['users'][0]);
1312 * Test the api_users_search() function with an XML result.
1315 public function testApiUsersSearchWithXml()
1317 $_GET['q'] = 'othercontact';
1318 $result = api_users_search('xml');
1319 $this->assertXml($result, 'users');
1323 * Test the api_users_search() function without a GET q parameter.
1325 * @expectedException Friendica\Network\HTTPException\BadRequestException
1327 public function testApiUsersSearchWithoutQuery()
1329 api_users_search('json');
1333 * Test the api_users_lookup() function.
1335 * @expectedException Friendica\Network\HTTPException\NotFoundException
1337 public function testApiUsersLookup()
1339 api_users_lookup('json');
1343 * Test the api_users_lookup() function with an user ID.
1346 public function testApiUsersLookupWithUserId()
1348 $_REQUEST['user_id'] = $this->otherUser['id'];
1349 $result = api_users_lookup('json');
1350 $this->assertOtherUser($result['users'][0]);
1354 * Test the api_search() function.
1357 public function testApiSearch()
1359 $_REQUEST['q'] = 'reply';
1360 $_REQUEST['max_id'] = 10;
1361 $result = api_search('json');
1362 foreach ($result['status'] as $status) {
1363 $this->assertStatus($status);
1364 $this->assertContains('reply', $status['text'], null, true);
1369 * Test the api_search() function a count parameter.
1372 public function testApiSearchWithCount()
1374 $_REQUEST['q'] = 'reply';
1375 $_REQUEST['count'] = 20;
1376 $result = api_search('json');
1377 foreach ($result['status'] as $status) {
1378 $this->assertStatus($status);
1379 $this->assertContains('reply', $status['text'], null, true);
1384 * Test the api_search() function with an rpp parameter.
1387 public function testApiSearchWithRpp()
1389 $_REQUEST['q'] = 'reply';
1390 $_REQUEST['rpp'] = 20;
1391 $result = api_search('json');
1392 foreach ($result['status'] as $status) {
1393 $this->assertStatus($status);
1394 $this->assertContains('reply', $status['text'], null, true);
1400 * Test the api_search() function without an authenticated user.
1402 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1404 public function testApiSearchWithUnallowedUser()
1406 $_SESSION['allow_api'] = false;
1407 $_GET['screen_name'] = $this->selfUser['nick'];
1412 * Test the api_search() function without any GET query parameter.
1414 * @expectedException Friendica\Network\HTTPException\BadRequestException
1416 public function testApiSearchWithoutQuery()
1422 * Test the api_statuses_home_timeline() function.
1425 public function testApiStatusesHomeTimeline()
1427 $_REQUEST['max_id'] = 10;
1428 $_REQUEST['exclude_replies'] = true;
1429 $_REQUEST['conversation_id'] = 1;
1430 $result = api_statuses_home_timeline('json');
1431 $this->assertNotEmpty($result['status']);
1432 foreach ($result['status'] as $status) {
1433 $this->assertStatus($status);
1438 * Test the api_statuses_home_timeline() function with a negative page parameter.
1441 public function testApiStatusesHomeTimelineWithNegativePage()
1443 $_REQUEST['page'] = -2;
1444 $result = api_statuses_home_timeline('json');
1445 $this->assertNotEmpty($result['status']);
1446 foreach ($result['status'] as $status) {
1447 $this->assertStatus($status);
1452 * Test the api_statuses_home_timeline() with an unallowed user.
1454 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1456 public function testApiStatusesHomeTimelineWithUnallowedUser()
1458 $_SESSION['allow_api'] = false;
1459 $_GET['screen_name'] = $this->selfUser['nick'];
1460 api_statuses_home_timeline('json');
1464 * Test the api_statuses_home_timeline() function with an RSS result.
1467 public function testApiStatusesHomeTimelineWithRss()
1469 $result = api_statuses_home_timeline('rss');
1470 $this->assertXml($result, 'statuses');
1474 * Test the api_statuses_public_timeline() function.
1477 public function testApiStatusesPublicTimeline()
1479 $_REQUEST['max_id'] = 10;
1480 $_REQUEST['conversation_id'] = 1;
1481 $result = api_statuses_public_timeline('json');
1482 $this->assertNotEmpty($result['status']);
1483 foreach ($result['status'] as $status) {
1484 $this->assertStatus($status);
1489 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1492 public function testApiStatusesPublicTimelineWithExcludeReplies()
1494 $_REQUEST['max_id'] = 10;
1495 $_REQUEST['exclude_replies'] = true;
1496 $result = api_statuses_public_timeline('json');
1497 $this->assertNotEmpty($result['status']);
1498 foreach ($result['status'] as $status) {
1499 $this->assertStatus($status);
1504 * Test the api_statuses_public_timeline() function with a negative page parameter.
1507 public function testApiStatusesPublicTimelineWithNegativePage()
1509 $_REQUEST['page'] = -2;
1510 $result = api_statuses_public_timeline('json');
1511 $this->assertNotEmpty($result['status']);
1512 foreach ($result['status'] as $status) {
1513 $this->assertStatus($status);
1518 * Test the api_statuses_public_timeline() function with an unallowed user.
1520 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1522 public function testApiStatusesPublicTimelineWithUnallowedUser()
1524 $_SESSION['allow_api'] = false;
1525 $_GET['screen_name'] = $this->selfUser['nick'];
1526 api_statuses_public_timeline('json');
1530 * Test the api_statuses_public_timeline() function with an RSS result.
1533 public function testApiStatusesPublicTimelineWithRss()
1535 $result = api_statuses_public_timeline('rss');
1536 $this->assertXml($result, 'statuses');
1540 * Test the api_statuses_networkpublic_timeline() function.
1543 public function testApiStatusesNetworkpublicTimeline()
1545 $_REQUEST['max_id'] = 10;
1546 $result = api_statuses_networkpublic_timeline('json');
1547 $this->assertNotEmpty($result['status']);
1548 foreach ($result['status'] as $status) {
1549 $this->assertStatus($status);
1554 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1557 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1559 $_REQUEST['page'] = -2;
1560 $result = api_statuses_networkpublic_timeline('json');
1561 $this->assertNotEmpty($result['status']);
1562 foreach ($result['status'] as $status) {
1563 $this->assertStatus($status);
1568 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1570 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1572 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1574 $_SESSION['allow_api'] = false;
1575 $_GET['screen_name'] = $this->selfUser['nick'];
1576 api_statuses_networkpublic_timeline('json');
1580 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1583 public function testApiStatusesNetworkpublicTimelineWithRss()
1585 $result = api_statuses_networkpublic_timeline('rss');
1586 $this->assertXml($result, 'statuses');
1590 * Test the api_statuses_show() function.
1592 * @expectedException Friendica\Network\HTTPException\BadRequestException
1594 public function testApiStatusesShow()
1596 api_statuses_show('json');
1600 * Test the api_statuses_show() function with an ID.
1603 public function testApiStatusesShowWithId()
1605 $this->app->argv[3] = 1;
1606 $result = api_statuses_show('json');
1607 $this->assertStatus($result['status']);
1611 * Test the api_statuses_show() function with the conversation parameter.
1614 public function testApiStatusesShowWithConversation()
1616 $this->app->argv[3] = 1;
1617 $_REQUEST['conversation'] = 1;
1618 $result = api_statuses_show('json');
1619 $this->assertNotEmpty($result['status']);
1620 foreach ($result['status'] as $status) {
1621 $this->assertStatus($status);
1626 * Test the api_statuses_show() function with an unallowed user.
1628 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1630 public function testApiStatusesShowWithUnallowedUser()
1632 $_SESSION['allow_api'] = false;
1633 $_GET['screen_name'] = $this->selfUser['nick'];
1634 api_statuses_show('json');
1638 * Test the api_conversation_show() function.
1640 * @expectedException Friendica\Network\HTTPException\BadRequestException
1642 public function testApiConversationShow()
1644 api_conversation_show('json');
1648 * Test the api_conversation_show() function with an ID.
1651 public function testApiConversationShowWithId()
1653 $this->app->argv[3] = 1;
1654 $_REQUEST['max_id'] = 10;
1655 $_REQUEST['page'] = -2;
1656 $result = api_conversation_show('json');
1657 $this->assertNotEmpty($result['status']);
1658 foreach ($result['status'] as $status) {
1659 $this->assertStatus($status);
1664 * Test the api_conversation_show() function with an unallowed user.
1666 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1668 public function testApiConversationShowWithUnallowedUser()
1670 $_SESSION['allow_api'] = false;
1671 $_GET['screen_name'] = $this->selfUser['nick'];
1672 api_conversation_show('json');
1676 * Test the api_statuses_repeat() function.
1678 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1680 public function testApiStatusesRepeat()
1682 api_statuses_repeat('json');
1686 * Test the api_statuses_repeat() function without an authenticated user.
1688 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1690 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1692 $_SESSION['authenticated'] = false;
1693 api_statuses_repeat('json');
1697 * Test the api_statuses_repeat() function with an ID.
1700 public function testApiStatusesRepeatWithId()
1702 $this->app->argv[3] = 1;
1703 $result = api_statuses_repeat('json');
1704 $this->assertStatus($result['status']);
1706 // Also test with a shared status
1707 $this->app->argv[3] = 5;
1708 $result = api_statuses_repeat('json');
1709 $this->assertStatus($result['status']);
1713 * Test the api_statuses_destroy() function.
1715 * @expectedException Friendica\Network\HTTPException\BadRequestException
1717 public function testApiStatusesDestroy()
1719 api_statuses_destroy('json');
1723 * Test the api_statuses_destroy() function without an authenticated user.
1725 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1727 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1729 $_SESSION['authenticated'] = false;
1730 api_statuses_destroy('json');
1734 * Test the api_statuses_destroy() function with an ID.
1737 public function testApiStatusesDestroyWithId()
1739 $this->app->argv[3] = 1;
1740 $result = api_statuses_destroy('json');
1741 $this->assertStatus($result['status']);
1745 * Test the api_statuses_mentions() function.
1748 public function testApiStatusesMentions()
1750 $this->app->user = ['nickname' => $this->selfUser['nick']];
1751 $_REQUEST['max_id'] = 10;
1752 $result = api_statuses_mentions('json');
1753 $this->assertEmpty($result['status']);
1754 // We should test with mentions in the database.
1758 * Test the api_statuses_mentions() function with a negative page parameter.
1761 public function testApiStatusesMentionsWithNegativePage()
1763 $_REQUEST['page'] = -2;
1764 $result = api_statuses_mentions('json');
1765 $this->assertEmpty($result['status']);
1769 * Test the api_statuses_mentions() function with an unallowed user.
1771 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1773 public function testApiStatusesMentionsWithUnallowedUser()
1775 $_SESSION['allow_api'] = false;
1776 $_GET['screen_name'] = $this->selfUser['nick'];
1777 api_statuses_mentions('json');
1781 * Test the api_statuses_mentions() function with an RSS result.
1784 public function testApiStatusesMentionsWithRss()
1786 $result = api_statuses_mentions('rss');
1787 $this->assertXml($result, 'statuses');
1791 * Test the api_statuses_user_timeline() function.
1794 public function testApiStatusesUserTimeline()
1796 $_REQUEST['max_id'] = 10;
1797 $_REQUEST['exclude_replies'] = true;
1798 $_REQUEST['conversation_id'] = 1;
1799 $result = api_statuses_user_timeline('json');
1800 $this->assertNotEmpty($result['status']);
1801 foreach ($result['status'] as $status) {
1802 $this->assertStatus($status);
1807 * Test the api_statuses_user_timeline() function with a negative page parameter.
1810 public function testApiStatusesUserTimelineWithNegativePage()
1812 $_REQUEST['page'] = -2;
1813 $result = api_statuses_user_timeline('json');
1814 $this->assertNotEmpty($result['status']);
1815 foreach ($result['status'] as $status) {
1816 $this->assertStatus($status);
1821 * Test the api_statuses_user_timeline() function with an RSS result.
1824 public function testApiStatusesUserTimelineWithRss()
1826 $result = api_statuses_user_timeline('rss');
1827 $this->assertXml($result, 'statuses');
1831 * Test the api_statuses_user_timeline() function with an unallowed user.
1833 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1835 public function testApiStatusesUserTimelineWithUnallowedUser()
1837 $_SESSION['allow_api'] = false;
1838 $_GET['screen_name'] = $this->selfUser['nick'];
1839 api_statuses_user_timeline('json');
1843 * Test the api_favorites_create_destroy() function.
1845 * @expectedException Friendica\Network\HTTPException\BadRequestException
1847 public function testApiFavoritesCreateDestroy()
1849 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1850 $this->app->argc = count($this->app->argv);
1851 api_favorites_create_destroy('json');
1855 * Test the api_favorites_create_destroy() function with an invalid ID.
1857 * @expectedException Friendica\Network\HTTPException\BadRequestException
1859 public function testApiFavoritesCreateDestroyWithInvalidId()
1861 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1862 $this->app->argc = count($this->app->argv);
1863 api_favorites_create_destroy('json');
1867 * Test the api_favorites_create_destroy() function with an invalid action.
1869 * @expectedException Friendica\Network\HTTPException\BadRequestException
1871 public function testApiFavoritesCreateDestroyWithInvalidAction()
1873 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1874 $this->app->argc = count($this->app->argv);
1875 $_REQUEST['id'] = 1;
1876 api_favorites_create_destroy('json');
1880 * Test the api_favorites_create_destroy() function with the create action.
1883 public function testApiFavoritesCreateDestroyWithCreateAction()
1885 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1886 $this->app->argc = count($this->app->argv);
1887 $_REQUEST['id'] = 3;
1888 $result = api_favorites_create_destroy('json');
1889 $this->assertStatus($result['status']);
1893 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1896 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1898 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1899 $this->app->argc = count($this->app->argv);
1900 $_REQUEST['id'] = 3;
1901 $result = api_favorites_create_destroy('rss');
1902 $this->assertXml($result, 'status');
1906 * Test the api_favorites_create_destroy() function with the destroy action.
1909 public function testApiFavoritesCreateDestroyWithDestroyAction()
1911 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1912 $this->app->argc = count($this->app->argv);
1913 $_REQUEST['id'] = 3;
1914 $result = api_favorites_create_destroy('json');
1915 $this->assertStatus($result['status']);
1919 * Test the api_favorites_create_destroy() function without an authenticated user.
1921 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1923 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1925 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1926 $this->app->argc = count($this->app->argv);
1927 $_SESSION['authenticated'] = false;
1928 api_favorites_create_destroy('json');
1932 * Test the api_favorites() function.
1935 public function testApiFavorites()
1937 $_REQUEST['page'] = -1;
1938 $_REQUEST['max_id'] = 10;
1939 $result = api_favorites('json');
1940 foreach ($result['status'] as $status) {
1941 $this->assertStatus($status);
1946 * Test the api_favorites() function with an RSS result.
1949 public function testApiFavoritesWithRss()
1951 $result = api_favorites('rss');
1952 $this->assertXml($result, 'statuses');
1956 * Test the api_favorites() function with an unallowed user.
1958 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1960 public function testApiFavoritesWithUnallowedUser()
1962 $_SESSION['allow_api'] = false;
1963 $_GET['screen_name'] = $this->selfUser['nick'];
1964 api_favorites('json');
1968 * Test the api_format_messages() function.
1971 public function testApiFormatMessages()
1973 $result = api_format_messages(
1974 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1975 ['id' => 2, 'screen_name' => 'recipient_name'],
1976 ['id' => 3, 'screen_name' => 'sender_name']
1978 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1979 $this->assertEquals(1, $result['id']);
1980 $this->assertEquals(2, $result['recipient_id']);
1981 $this->assertEquals(3, $result['sender_id']);
1982 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1983 $this->assertEquals('sender_name', $result['sender_screen_name']);
1987 * Test the api_format_messages() function with HTML.
1990 public function testApiFormatMessagesWithHtmlText()
1992 $_GET['getText'] = 'html';
1993 $result = api_format_messages(
1994 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1995 ['id' => 2, 'screen_name' => 'recipient_name'],
1996 ['id' => 3, 'screen_name' => 'sender_name']
1998 $this->assertEquals('item_title', $result['title']);
1999 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2003 * Test the api_format_messages() function with plain text.
2006 public function testApiFormatMessagesWithPlainText()
2008 $_GET['getText'] = 'plain';
2009 $result = api_format_messages(
2010 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2011 ['id' => 2, 'screen_name' => 'recipient_name'],
2012 ['id' => 3, 'screen_name' => 'sender_name']
2014 $this->assertEquals('item_title', $result['title']);
2015 $this->assertEquals('item_body', $result['text']);
2019 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2022 public function testApiFormatMessagesWithoutUserObjects()
2024 $_GET['getUserObjects'] = 'false';
2025 $result = api_format_messages(
2026 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2027 ['id' => 2, 'screen_name' => 'recipient_name'],
2028 ['id' => 3, 'screen_name' => 'sender_name']
2030 $this->assertTrue(!isset($result['sender']));
2031 $this->assertTrue(!isset($result['recipient']));
2035 * Test the api_convert_item() function.
2038 public function testApiConvertItem()
2040 $result = api_convert_item(
2042 'network' => 'feed',
2043 'title' => 'item_title',
2044 // We need a long string to test that it is correctly cut
2045 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2046 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2047 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2048 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2049 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2050 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2051 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2052 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2053 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2054 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2055 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2056 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2057 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2058 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2059 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2060 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2061 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2062 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2063 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2064 'repellat officia illum quos impedit quam iste esse unde qui '.
2065 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2066 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2067 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2068 'plink' => 'item_plink'
2071 $this->assertStringStartsWith('item_title', $result['text']);
2072 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2076 * Test the api_convert_item() function with an empty item body.
2079 public function testApiConvertItemWithoutBody()
2081 $result = api_convert_item(
2083 'network' => 'feed',
2084 'title' => 'item_title',
2086 'plink' => 'item_plink'
2089 $this->assertEquals('item_title', $result['text']);
2090 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2094 * Test the api_convert_item() function with the title in the body.
2097 public function testApiConvertItemWithTitleInBody()
2099 $result = api_convert_item(
2101 'title' => 'item_title',
2102 'body' => 'item_title item_body'
2105 $this->assertEquals('item_title item_body', $result['text']);
2106 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2110 * Test the api_get_attachments() function.
2113 public function testApiGetAttachments()
2116 $this->assertEmpty(api_get_attachments($body));
2120 * Test the api_get_attachments() function with an img tag.
2123 public function testApiGetAttachmentsWithImage()
2125 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2126 $this->assertInternalType('array', api_get_attachments($body));
2130 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2133 public function testApiGetAttachmentsWithImageAndAndStatus()
2135 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2136 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2137 $this->assertInternalType('array', api_get_attachments($body));
2141 * Test the api_get_entitities() function.
2144 public function testApiGetEntitities()
2147 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2151 * Test the api_get_entitities() function with the include_entities parameter.
2154 public function testApiGetEntititiesWithIncludeEntities()
2156 $_REQUEST['include_entities'] = 'true';
2158 $result = api_get_entitities($text, 'bbcode');
2159 $this->assertInternalType('array', $result['hashtags']);
2160 $this->assertInternalType('array', $result['symbols']);
2161 $this->assertInternalType('array', $result['urls']);
2162 $this->assertInternalType('array', $result['user_mentions']);
2166 * Test the api_format_items_embeded_images() function.
2169 public function testApiFormatItemsEmbededImages()
2171 $this->assertEquals(
2172 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
2173 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2178 * Test the api_contactlink_to_array() function.
2181 public function testApiContactlinkToArray()
2183 $this->assertEquals(
2188 api_contactlink_to_array('text')
2193 * Test the api_contactlink_to_array() function with an URL.
2196 public function testApiContactlinkToArrayWithUrl()
2198 $this->assertEquals(
2200 'name' => ['link_text'],
2203 api_contactlink_to_array('text <a href="url">link_text</a>')
2208 * Test the api_format_items_activities() function.
2211 public function testApiFormatItemsActivities()
2213 $item = ['uid' => 0, 'uri' => ''];
2214 $result = api_format_items_activities($item);
2215 $this->assertArrayHasKey('like', $result);
2216 $this->assertArrayHasKey('dislike', $result);
2217 $this->assertArrayHasKey('attendyes', $result);
2218 $this->assertArrayHasKey('attendno', $result);
2219 $this->assertArrayHasKey('attendmaybe', $result);
2223 * Test the api_format_items_activities() function with an XML result.
2226 public function testApiFormatItemsActivitiesWithXml()
2228 $item = ['uid' => 0, 'uri' => ''];
2229 $result = api_format_items_activities($item, 'xml');
2230 $this->assertArrayHasKey('friendica:like', $result);
2231 $this->assertArrayHasKey('friendica:dislike', $result);
2232 $this->assertArrayHasKey('friendica:attendyes', $result);
2233 $this->assertArrayHasKey('friendica:attendno', $result);
2234 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2238 * Test the api_format_items_profiles() function.
2241 public function testApiFormatItemsProfiles()
2244 'id' => 'profile_id',
2245 'profile-name' => 'profile_name',
2246 'is-default' => true,
2247 'hide-friends' => true,
2248 'photo' => 'profile_photo',
2249 'thumb' => 'profile_thumb',
2251 'net-publish' => true,
2252 'pdesc' => 'description',
2253 'dob' => 'date_of_birth',
2254 'address' => 'address',
2255 'locality' => 'city',
2256 'region' => 'region',
2257 'postal-code' => 'postal_code',
2258 'country-name' => 'country',
2259 'hometown' => 'hometown',
2260 'gender' => 'gender',
2261 'marital' => 'marital',
2262 'with' => 'marital_with',
2263 'howlong' => 'marital_since',
2264 'sexual' => 'sexual',
2265 'politic' => 'politic',
2266 'religion' => 'religion',
2267 'pub_keywords' => 'public_keywords',
2268 'prv_keywords' => 'private_keywords',
2271 'dislikes' => 'dislikes',
2277 'interest' => 'interest',
2278 'romance' => 'romance',
2280 'education' => 'education',
2281 'contact' => 'social_networks',
2282 'homepage' => 'homepage'
2284 $result = api_format_items_profiles($profile_row);
2285 $this->assertEquals(
2287 'profile_id' => 'profile_id',
2288 'profile_name' => 'profile_name',
2289 'is_default' => true,
2290 'hide_friends' => true,
2291 'profile_photo' => 'profile_photo',
2292 'profile_thumb' => 'profile_thumb',
2294 'net_publish' => true,
2295 'description' => 'description',
2296 'date_of_birth' => 'date_of_birth',
2297 'address' => 'address',
2299 'region' => 'region',
2300 'postal_code' => 'postal_code',
2301 'country' => 'country',
2302 'hometown' => 'hometown',
2303 'gender' => 'gender',
2304 'marital' => 'marital',
2305 'marital_with' => 'marital_with',
2306 'marital_since' => 'marital_since',
2307 'sexual' => 'sexual',
2308 'politic' => 'politic',
2309 'religion' => 'religion',
2310 'public_keywords' => 'public_keywords',
2311 'private_keywords' => 'private_keywords',
2314 'dislikes' => 'dislikes',
2320 'interest' => 'interest',
2321 'romance' => 'romance',
2323 'education' => 'education',
2324 'social_networks' => 'social_networks',
2325 'homepage' => 'homepage',
2333 * Test the api_format_items() function.
2336 public function testApiFormatItems()
2340 'item_network' => 'item_network',
2346 'author-network' => \Friendica\Core\Protocol::DFRN,
2347 'author-link' => 'http://localhost/profile/othercontact',
2351 $result = api_format_items($items, ['id' => 0], true);
2352 foreach ($result as $status) {
2353 $this->assertStatus($status);
2358 * Test the api_format_items() function with an XML result.
2361 public function testApiFormatItemsWithXml()
2369 'author-network' => \Friendica\Core\Protocol::DFRN,
2370 'author-link' => 'http://localhost/profile/othercontact',
2374 $result = api_format_items($items, ['id' => 0], true, 'xml');
2375 foreach ($result as $status) {
2376 $this->assertStatus($status);
2381 * Test the api_format_items() function.
2384 public function testApiAccountRateLimitStatus()
2386 $result = api_account_rate_limit_status('json');
2387 $this->assertEquals(150, $result['hash']['remaining_hits']);
2388 $this->assertEquals(150, $result['hash']['hourly_limit']);
2389 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2393 * Test the api_format_items() function with an XML result.
2396 public function testApiAccountRateLimitStatusWithXml()
2398 $result = api_account_rate_limit_status('xml');
2399 $this->assertXml($result, 'hash');
2403 * Test the api_help_test() function.
2406 public function testApiHelpTest()
2408 $result = api_help_test('json');
2409 $this->assertEquals(['ok' => 'ok'], $result);
2413 * Test the api_help_test() function with an XML result.
2416 public function testApiHelpTestWithXml()
2418 $result = api_help_test('xml');
2419 $this->assertXml($result, 'ok');
2423 * Test the api_lists_list() function.
2426 public function testApiListsList()
2428 $result = api_lists_list('json');
2429 $this->assertEquals(['lists_list' => []], $result);
2433 * Test the api_lists_ownerships() function.
2436 public function testApiListsOwnerships()
2438 $result = api_lists_ownerships('json');
2439 foreach ($result['lists']['lists'] as $list) {
2440 $this->assertList($list);
2445 * Test the api_lists_ownerships() function without an authenticated user.
2447 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2449 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2451 $_SESSION['authenticated'] = false;
2452 api_lists_ownerships('json');
2456 * Test the api_lists_statuses() function.
2457 * @expectedException Friendica\Network\HTTPException\BadRequestException
2460 public function testApiListsStatuses()
2462 api_lists_statuses('json');
2466 * Test the api_lists_statuses() function with a list ID.
2469 public function testApiListsStatusesWithListId()
2471 $_REQUEST['list_id'] = 1;
2472 $_REQUEST['page'] = -1;
2473 $_REQUEST['max_id'] = 10;
2474 $result = api_lists_statuses('json');
2475 foreach ($result['status'] as $status) {
2476 $this->assertStatus($status);
2481 * Test the api_lists_statuses() function with a list ID and a RSS result.
2484 public function testApiListsStatusesWithListIdAndRss()
2486 $_REQUEST['list_id'] = 1;
2487 $result = api_lists_statuses('rss');
2488 $this->assertXml($result, 'statuses');
2492 * Test the api_lists_statuses() function with an unallowed user.
2494 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2496 public function testApiListsStatusesWithUnallowedUser()
2498 $_SESSION['allow_api'] = false;
2499 $_GET['screen_name'] = $this->selfUser['nick'];
2500 api_lists_statuses('json');
2504 * Test the api_statuses_f() function.
2507 public function testApiStatusesFWithFriends()
2510 $result = api_statuses_f('friends');
2511 $this->assertArrayHasKey('user', $result);
2515 * Test the api_statuses_f() function.
2518 public function testApiStatusesFWithFollowers()
2520 $result = api_statuses_f('followers');
2521 $this->assertArrayHasKey('user', $result);
2525 * Test the api_statuses_f() function.
2528 public function testApiStatusesFWithBlocks()
2530 $result = api_statuses_f('blocks');
2531 $this->assertArrayHasKey('user', $result);
2535 * Test the api_statuses_f() function.
2538 public function testApiStatusesFWithIncoming()
2540 $result = api_statuses_f('incoming');
2541 $this->assertArrayHasKey('user', $result);
2545 * Test the api_statuses_f() function an undefined cursor GET variable.
2548 public function testApiStatusesFWithUndefinedCursor()
2550 $_GET['cursor'] = 'undefined';
2551 $this->assertFalse(api_statuses_f('friends'));
2555 * Test the api_statuses_friends() function.
2558 public function testApiStatusesFriends()
2560 $result = api_statuses_friends('json');
2561 $this->assertArrayHasKey('user', $result);
2565 * Test the api_statuses_friends() function an undefined cursor GET variable.
2568 public function testApiStatusesFriendsWithUndefinedCursor()
2570 $_GET['cursor'] = 'undefined';
2571 $this->assertFalse(api_statuses_friends('json'));
2575 * Test the api_statuses_followers() function.
2578 public function testApiStatusesFollowers()
2580 $result = api_statuses_followers('json');
2581 $this->assertArrayHasKey('user', $result);
2585 * Test the api_statuses_followers() function an undefined cursor GET variable.
2588 public function testApiStatusesFollowersWithUndefinedCursor()
2590 $_GET['cursor'] = 'undefined';
2591 $this->assertFalse(api_statuses_followers('json'));
2595 * Test the api_blocks_list() function.
2598 public function testApiBlocksList()
2600 $result = api_blocks_list('json');
2601 $this->assertArrayHasKey('user', $result);
2605 * Test the api_blocks_list() function an undefined cursor GET variable.
2608 public function testApiBlocksListWithUndefinedCursor()
2610 $_GET['cursor'] = 'undefined';
2611 $this->assertFalse(api_blocks_list('json'));
2615 * Test the api_friendships_incoming() function.
2618 public function testApiFriendshipsIncoming()
2620 $result = api_friendships_incoming('json');
2621 $this->assertArrayHasKey('id', $result);
2625 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2628 public function testApiFriendshipsIncomingWithUndefinedCursor()
2630 $_GET['cursor'] = 'undefined';
2631 $this->assertFalse(api_friendships_incoming('json'));
2635 * Test the api_statusnet_config() function.
2638 public function testApiStatusnetConfig()
2640 $result = api_statusnet_config('json');
2641 $this->assertEquals('localhost', $result['config']['site']['server']);
2642 $this->assertEquals('default', $result['config']['site']['theme']);
2643 $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2644 $this->assertTrue($result['config']['site']['fancy']);
2645 $this->assertEquals('en', $result['config']['site']['language']);
2646 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2647 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2648 $this->assertEquals('false', $result['config']['site']['private']);
2649 $this->assertEquals('false', $result['config']['site']['ssl']);
2650 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2654 * Test the api_statusnet_version() function.
2657 public function testApiStatusnetVersion()
2659 $result = api_statusnet_version('json');
2660 $this->assertEquals('0.9.7', $result['version']);
2664 * Test the api_ff_ids() function.
2667 public function testApiFfIds()
2669 $result = api_ff_ids('json');
2670 $this->assertNull($result);
2674 * Test the api_ff_ids() function with a result.
2677 public function testApiFfIdsWithResult()
2679 $this->markTestIncomplete();
2683 * Test the api_ff_ids() function without an authenticated user.
2685 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2687 public function testApiFfIdsWithoutAuthenticatedUser()
2689 $_SESSION['authenticated'] = false;
2694 * Test the api_friends_ids() function.
2697 public function testApiFriendsIds()
2699 $result = api_friends_ids('json');
2700 $this->assertNull($result);
2704 * Test the api_followers_ids() function.
2707 public function testApiFollowersIds()
2709 $result = api_followers_ids('json');
2710 $this->assertNull($result);
2714 * Test the api_direct_messages_new() function.
2717 public function testApiDirectMessagesNew()
2719 $result = api_direct_messages_new('json');
2720 $this->assertNull($result);
2724 * Test the api_direct_messages_new() function without an authenticated user.
2726 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2728 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2730 $_SESSION['authenticated'] = false;
2731 api_direct_messages_new('json');
2735 * Test the api_direct_messages_new() function with an user ID.
2738 public function testApiDirectMessagesNewWithUserId()
2740 $_POST['text'] = 'message_text';
2741 $_POST['user_id'] = $this->otherUser['id'];
2742 $result = api_direct_messages_new('json');
2743 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2747 * Test the api_direct_messages_new() function with a screen name.
2750 public function testApiDirectMessagesNewWithScreenName()
2752 $_POST['text'] = 'message_text';
2753 $_POST['screen_name'] = $this->friendUser['nick'];
2754 $result = api_direct_messages_new('json');
2755 $this->assertEquals(1, $result['direct_message']['id']);
2756 $this->assertContains('message_text', $result['direct_message']['text']);
2757 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2758 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2762 * Test the api_direct_messages_new() function with a title.
2765 public function testApiDirectMessagesNewWithTitle()
2767 $_POST['text'] = 'message_text';
2768 $_POST['screen_name'] = $this->friendUser['nick'];
2769 $_REQUEST['title'] = 'message_title';
2770 $result = api_direct_messages_new('json');
2771 $this->assertEquals(1, $result['direct_message']['id']);
2772 $this->assertContains('message_text', $result['direct_message']['text']);
2773 $this->assertContains('message_title', $result['direct_message']['text']);
2774 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2775 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2779 * Test the api_direct_messages_new() function with an RSS result.
2782 public function testApiDirectMessagesNewWithRss()
2784 $_POST['text'] = 'message_text';
2785 $_POST['screen_name'] = $this->friendUser['nick'];
2786 $result = api_direct_messages_new('rss');
2787 $this->assertXml($result, 'direct-messages');
2791 * Test the api_direct_messages_destroy() function.
2793 * @expectedException Friendica\Network\HTTPException\BadRequestException
2795 public function testApiDirectMessagesDestroy()
2797 api_direct_messages_destroy('json');
2801 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2804 public function testApiDirectMessagesDestroyWithVerbose()
2806 $_GET['friendica_verbose'] = 'true';
2807 $result = api_direct_messages_destroy('json');
2808 $this->assertEquals(
2811 'result' => 'error',
2812 'message' => 'message id or parenturi not specified'
2820 * Test the api_direct_messages_destroy() function without an authenticated user.
2822 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2824 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2826 $_SESSION['authenticated'] = false;
2827 api_direct_messages_destroy('json');
2831 * Test the api_direct_messages_destroy() function with a non-zero ID.
2833 * @expectedException Friendica\Network\HTTPException\BadRequestException
2835 public function testApiDirectMessagesDestroyWithId()
2837 $_REQUEST['id'] = 1;
2838 api_direct_messages_destroy('json');
2842 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2845 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2847 $_REQUEST['id'] = 1;
2848 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2849 $_GET['friendica_verbose'] = 'true';
2850 $result = api_direct_messages_destroy('json');
2851 $this->assertEquals(
2854 'result' => 'error',
2855 'message' => 'message id not in database'
2863 * Test the api_direct_messages_destroy() function with a non-zero ID.
2866 public function testApiDirectMessagesDestroyWithCorrectId()
2868 $this->markTestIncomplete('We need to add a dataset for this.');
2872 * Test the api_direct_messages_box() function.
2875 public function testApiDirectMessagesBoxWithSentbox()
2877 $_REQUEST['page'] = -1;
2878 $_REQUEST['max_id'] = 10;
2879 $result = api_direct_messages_box('json', 'sentbox', 'false');
2880 $this->assertArrayHasKey('direct_message', $result);
2884 * Test the api_direct_messages_box() function.
2887 public function testApiDirectMessagesBoxWithConversation()
2889 $result = api_direct_messages_box('json', 'conversation', 'false');
2890 $this->assertArrayHasKey('direct_message', $result);
2894 * Test the api_direct_messages_box() function.
2897 public function testApiDirectMessagesBoxWithAll()
2899 $result = api_direct_messages_box('json', 'all', 'false');
2900 $this->assertArrayHasKey('direct_message', $result);
2904 * Test the api_direct_messages_box() function.
2907 public function testApiDirectMessagesBoxWithInbox()
2909 $result = api_direct_messages_box('json', 'inbox', 'false');
2910 $this->assertArrayHasKey('direct_message', $result);
2914 * Test the api_direct_messages_box() function.
2917 public function testApiDirectMessagesBoxWithVerbose()
2919 $result = api_direct_messages_box('json', 'sentbox', 'true');
2920 $this->assertEquals(
2923 'result' => 'error',
2924 'message' => 'no mails available'
2932 * Test the api_direct_messages_box() function with a RSS result.
2935 public function testApiDirectMessagesBoxWithRss()
2937 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2938 $this->assertXml($result, 'direct-messages');
2942 * Test the api_direct_messages_box() function without an authenticated user.
2944 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2946 public function testApiDirectMessagesBoxWithUnallowedUser()
2948 $_SESSION['allow_api'] = false;
2949 $_GET['screen_name'] = $this->selfUser['nick'];
2950 api_direct_messages_box('json', 'sentbox', 'false');
2954 * Test the api_direct_messages_sentbox() function.
2957 public function testApiDirectMessagesSentbox()
2959 $result = api_direct_messages_sentbox('json');
2960 $this->assertArrayHasKey('direct_message', $result);
2964 * Test the api_direct_messages_inbox() function.
2967 public function testApiDirectMessagesInbox()
2969 $result = api_direct_messages_inbox('json');
2970 $this->assertArrayHasKey('direct_message', $result);
2974 * Test the api_direct_messages_all() function.
2977 public function testApiDirectMessagesAll()
2979 $result = api_direct_messages_all('json');
2980 $this->assertArrayHasKey('direct_message', $result);
2984 * Test the api_direct_messages_conversation() function.
2987 public function testApiDirectMessagesConversation()
2989 $result = api_direct_messages_conversation('json');
2990 $this->assertArrayHasKey('direct_message', $result);
2994 * Test the api_oauth_request_token() function.
2997 public function testApiOauthRequestToken()
2999 $this->markTestIncomplete('killme() kills phpunit as well');
3003 * Test the api_oauth_access_token() function.
3006 public function testApiOauthAccessToken()
3008 $this->markTestIncomplete('killme() kills phpunit as well');
3012 * Test the api_fr_photoalbum_delete() function.
3014 * @expectedException Friendica\Network\HTTPException\BadRequestException
3016 public function testApiFrPhotoalbumDelete()
3018 api_fr_photoalbum_delete('json');
3022 * Test the api_fr_photoalbum_delete() function with an album name.
3024 * @expectedException Friendica\Network\HTTPException\BadRequestException
3026 public function testApiFrPhotoalbumDeleteWithAlbum()
3028 $_REQUEST['album'] = 'album_name';
3029 api_fr_photoalbum_delete('json');
3033 * Test the api_fr_photoalbum_delete() function with an album name.
3036 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3038 $this->markTestIncomplete('We need to add a dataset for this.');
3042 * Test the api_fr_photoalbum_delete() function.
3044 * @expectedException Friendica\Network\HTTPException\BadRequestException
3046 public function testApiFrPhotoalbumUpdate()
3048 api_fr_photoalbum_update('json');
3052 * Test the api_fr_photoalbum_delete() function with an album name.
3054 * @expectedException Friendica\Network\HTTPException\BadRequestException
3056 public function testApiFrPhotoalbumUpdateWithAlbum()
3058 $_REQUEST['album'] = 'album_name';
3059 api_fr_photoalbum_update('json');
3063 * Test the api_fr_photoalbum_delete() function with an album name.
3065 * @expectedException Friendica\Network\HTTPException\BadRequestException
3067 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3069 $_REQUEST['album'] = 'album_name';
3070 $_REQUEST['album_new'] = 'album_name';
3071 api_fr_photoalbum_update('json');
3075 * Test the api_fr_photoalbum_update() function without an authenticated user.
3077 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3079 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3081 $_SESSION['authenticated'] = false;
3082 api_fr_photoalbum_update('json');
3086 * Test the api_fr_photoalbum_delete() function with an album name.
3089 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3091 $this->markTestIncomplete('We need to add a dataset for this.');
3095 * Test the api_fr_photos_list() function.
3098 public function testApiFrPhotosList()
3100 $result = api_fr_photos_list('json');
3101 $this->assertArrayHasKey('photo', $result);
3105 * Test the api_fr_photos_list() function without an authenticated user.
3107 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3109 public function testApiFrPhotosListWithoutAuthenticatedUser()
3111 $_SESSION['authenticated'] = false;
3112 api_fr_photos_list('json');
3116 * Test the api_fr_photo_create_update() function.
3118 * @expectedException Friendica\Network\HTTPException\BadRequestException
3120 public function testApiFrPhotoCreateUpdate()
3122 api_fr_photo_create_update('json');
3126 * Test the api_fr_photo_create_update() function without an authenticated user.
3128 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3130 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3132 $_SESSION['authenticated'] = false;
3133 api_fr_photo_create_update('json');
3137 * Test the api_fr_photo_create_update() function with an album name.
3139 * @expectedException Friendica\Network\HTTPException\BadRequestException
3141 public function testApiFrPhotoCreateUpdateWithAlbum()
3143 $_REQUEST['album'] = 'album_name';
3144 api_fr_photo_create_update('json');
3148 * Test the api_fr_photo_create_update() function with the update mode.
3151 public function testApiFrPhotoCreateUpdateWithUpdate()
3153 $this->markTestIncomplete('We need to create a dataset for this');
3157 * Test the api_fr_photo_create_update() function with an uploaded file.
3160 public function testApiFrPhotoCreateUpdateWithFile()
3162 $this->markTestIncomplete();
3166 * Test the api_fr_photo_delete() function.
3168 * @expectedException Friendica\Network\HTTPException\BadRequestException
3170 public function testApiFrPhotoDelete()
3172 api_fr_photo_delete('json');
3176 * Test the api_fr_photo_delete() function without an authenticated user.
3178 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3180 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3182 $_SESSION['authenticated'] = false;
3183 api_fr_photo_delete('json');
3187 * Test the api_fr_photo_delete() function with a photo ID.
3189 * @expectedException Friendica\Network\HTTPException\BadRequestException
3191 public function testApiFrPhotoDeleteWithPhotoId()
3193 $_REQUEST['photo_id'] = 1;
3194 api_fr_photo_delete('json');
3198 * Test the api_fr_photo_delete() function with a correct photo ID.
3201 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3203 $this->markTestIncomplete('We need to create a dataset for this.');
3207 * Test the api_fr_photo_detail() function.
3209 * @expectedException Friendica\Network\HTTPException\BadRequestException
3211 public function testApiFrPhotoDetail()
3213 api_fr_photo_detail('json');
3217 * Test the api_fr_photo_detail() function without an authenticated user.
3219 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3221 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3223 $_SESSION['authenticated'] = false;
3224 api_fr_photo_detail('json');
3228 * Test the api_fr_photo_detail() function with a photo ID.
3230 * @expectedException Friendica\Network\HTTPException\NotFoundException
3232 public function testApiFrPhotoDetailWithPhotoId()
3234 $_REQUEST['photo_id'] = 1;
3235 api_fr_photo_detail('json');
3239 * Test the api_fr_photo_detail() function with a correct photo ID.
3242 public function testApiFrPhotoDetailCorrectPhotoId()
3244 $this->markTestIncomplete('We need to create a dataset for this.');
3248 * Test the api_account_update_profile_image() function.
3250 * @expectedException Friendica\Network\HTTPException\BadRequestException
3252 public function testApiAccountUpdateProfileImage()
3254 api_account_update_profile_image('json');
3258 * Test the api_account_update_profile_image() function without an authenticated user.
3260 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3262 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3264 $_SESSION['authenticated'] = false;
3265 api_account_update_profile_image('json');
3269 * Test the api_account_update_profile_image() function with an uploaded file.
3271 * @expectedException Friendica\Network\HTTPException\BadRequestException
3273 public function testApiAccountUpdateProfileImageWithUpload()
3275 $this->markTestIncomplete();
3280 * Test the api_account_update_profile() function.
3283 public function testApiAccountUpdateProfile()
3285 $_POST['name'] = 'new_name';
3286 $_POST['description'] = 'new_description';
3287 $result = api_account_update_profile('json');
3288 // We can't use assertSelfUser() here because the user object is missing some properties.
3289 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3290 $this->assertEquals('Friendica', $result['user']['location']);
3291 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3292 $this->assertEquals('dfrn', $result['user']['network']);
3293 $this->assertEquals('new_name', $result['user']['name']);
3294 $this->assertEquals('new_description', $result['user']['description']);
3298 * Test the check_acl_input() function.
3301 public function testCheckAclInput()
3303 $result = check_acl_input('<aclstring>');
3304 // Where does this result come from?
3305 $this->assertEquals(1, $result);
3309 * Test the check_acl_input() function with an empty ACL string.
3312 public function testCheckAclInputWithEmptyAclString()
3314 $result = check_acl_input(' ');
3315 $this->assertFalse($result);
3319 * Test the save_media_to_database() function.
3322 public function testSaveMediaToDatabase()
3324 $this->markTestIncomplete();
3328 * Test the post_photo_item() function.
3331 public function testPostPhotoItem()
3333 $this->markTestIncomplete();
3337 * Test the prepare_photo_data() function.
3340 public function testPreparePhotoData()
3342 $this->markTestIncomplete();
3346 * Test the api_friendica_remoteauth() function.
3348 * @expectedException Friendica\Network\HTTPException\BadRequestException
3350 public function testApiFriendicaRemoteauth()
3352 api_friendica_remoteauth();
3356 * Test the api_friendica_remoteauth() function with an URL.
3358 * @expectedException Friendica\Network\HTTPException\BadRequestException
3360 public function testApiFriendicaRemoteauthWithUrl()
3362 $_GET['url'] = 'url';
3363 $_GET['c_url'] = 'url';
3364 api_friendica_remoteauth();
3368 * Test the api_friendica_remoteauth() function with a correct URL.
3371 public function testApiFriendicaRemoteauthWithCorrectUrl()
3373 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3374 $_GET['url'] = 'url';
3375 $_GET['c_url'] = $this->selfUser['nurl'];
3376 api_friendica_remoteauth();
3380 * Test the api_share_as_retweet() function.
3383 public function testApiShareAsRetweet()
3385 $item = ['body' => ''];
3386 $result = api_share_as_retweet($item);
3387 $this->assertFalse($result);
3391 * Test the api_share_as_retweet() function with a valid item.
3394 public function testApiShareAsRetweetWithValidItem()
3396 $this->markTestIncomplete();
3400 * Test the api_get_nick() function.
3403 public function testApiGetNick()
3405 $result = api_get_nick($this->otherUser['nurl']);
3406 $this->assertEquals('othercontact', $result);
3410 * Test the api_get_nick() function with a wrong URL.
3413 public function testApiGetNickWithWrongUrl()
3415 $result = api_get_nick('wrong_url');
3416 $this->assertFalse($result);
3420 * Test the api_in_reply_to() function.
3423 public function testApiInReplyTo()
3425 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3426 $this->assertArrayHasKey('status_id', $result);
3427 $this->assertArrayHasKey('user_id', $result);
3428 $this->assertArrayHasKey('status_id_str', $result);
3429 $this->assertArrayHasKey('user_id_str', $result);
3430 $this->assertArrayHasKey('screen_name', $result);
3434 * Test the api_in_reply_to() function with a valid item.
3437 public function testApiInReplyToWithValidItem()
3439 $this->markTestIncomplete();
3443 * Test the api_clean_plain_items() function.
3446 public function testApiCleanPlainItems()
3448 $_REQUEST['include_entities'] = 'true';
3449 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3450 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3454 * Test the api_clean_attachments() function.
3457 public function testApiCleanAttachments()
3459 $this->markTestIncomplete();
3463 * Test the api_best_nickname() function.
3466 public function testApiBestNickname()
3469 $result = api_best_nickname($contacts);
3470 $this->assertNull($result);
3474 * Test the api_best_nickname() function with contacts.
3477 public function testApiBestNicknameWithContacts()
3479 $this->markTestIncomplete();
3483 * Test the api_friendica_group_show() function.
3486 public function testApiFriendicaGroupShow()
3488 $this->markTestIncomplete();
3492 * Test the api_friendica_group_delete() function.
3495 public function testApiFriendicaGroupDelete()
3497 $this->markTestIncomplete();
3501 * Test the api_lists_destroy() function.
3504 public function testApiListsDestroy()
3506 $this->markTestIncomplete();
3510 * Test the group_create() function.
3513 public function testGroupCreate()
3515 $this->markTestIncomplete();
3519 * Test the api_friendica_group_create() function.
3522 public function testApiFriendicaGroupCreate()
3524 $this->markTestIncomplete();
3528 * Test the api_lists_create() function.
3531 public function testApiListsCreate()
3533 $this->markTestIncomplete();
3537 * Test the api_friendica_group_update() function.
3540 public function testApiFriendicaGroupUpdate()
3542 $this->markTestIncomplete();
3546 * Test the api_lists_update() function.
3549 public function testApiListsUpdate()
3551 $this->markTestIncomplete();
3555 * Test the api_friendica_activity() function.
3558 public function testApiFriendicaActivity()
3560 $this->markTestIncomplete();
3564 * Test the api_friendica_notification() function.
3566 * @expectedException Friendica\Network\HTTPException\BadRequestException
3568 public function testApiFriendicaNotification()
3570 api_friendica_notification('json');
3574 * Test the api_friendica_notification() function without an authenticated user.
3576 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3578 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3580 $_SESSION['authenticated'] = false;
3581 api_friendica_notification('json');
3585 * Test the api_friendica_notification() function with an argument count.
3588 public function testApiFriendicaNotificationWithArgumentCount()
3590 $this->app->argv = ['api', 'friendica', 'notification'];
3591 $this->app->argc = count($this->app->argv);
3592 $result = api_friendica_notification('json');
3593 $this->assertEquals(['note' => false], $result);
3597 * Test the api_friendica_notification() function with an XML result.
3600 public function testApiFriendicaNotificationWithXmlResult()
3602 $this->app->argv = ['api', 'friendica', 'notification'];
3603 $this->app->argc = count($this->app->argv);
3604 $result = api_friendica_notification('xml');
3605 $this->assertXml($result, 'notes');
3609 * Test the api_friendica_notification_seen() function.
3612 public function testApiFriendicaNotificationSeen()
3614 $this->markTestIncomplete();
3618 * Test the api_friendica_direct_messages_setseen() function.
3621 public function testApiFriendicaDirectMessagesSetseen()
3623 $this->markTestIncomplete();
3627 * Test the api_friendica_direct_messages_search() function.
3630 public function testApiFriendicaDirectMessagesSearch()
3632 $this->markTestIncomplete();
3636 * Test the api_friendica_profile_show() function.
3639 public function testApiFriendicaProfileShow()
3641 $result = api_friendica_profile_show('json');
3642 // We can't use assertSelfUser() here because the user object is missing some properties.
3643 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3644 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3645 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3646 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3647 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3648 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3649 $this->assertFalse($result['$result']['multi_profiles']);
3653 * Test the api_friendica_profile_show() function with a profile ID.
3656 public function testApiFriendicaProfileShowWithProfileId()
3658 $this->markTestIncomplete('We need to add a dataset for this.');
3662 * Test the api_friendica_profile_show() function with a wrong profile ID.
3664 * @expectedException Friendica\Network\HTTPException\BadRequestException
3666 public function testApiFriendicaProfileShowWithWrongProfileId()
3668 $_REQUEST['profile_id'] = 666;
3669 api_friendica_profile_show('json');
3673 * Test the api_friendica_profile_show() function without an authenticated user.
3675 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3677 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3679 $_SESSION['authenticated'] = false;
3680 api_friendica_profile_show('json');
3684 * Test the api_saved_searches_list() function.
3687 public function testApiSavedSearchesList()
3689 $result = api_saved_searches_list('json');
3690 $this->assertEquals(1, $result['terms'][0]['id']);
3691 $this->assertEquals(1, $result['terms'][0]['id_str']);
3692 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3693 $this->assertEquals('Saved search', $result['terms'][0]['query']);