6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Factory;
14 use Friendica\Network\HTTPException;
15 use Friendica\Util\BasePath;
16 use Monolog\Handler\TestHandler;
18 require_once __DIR__ . '/../../include/api.php';
21 * Tests for the API functions.
23 * Functions that use header() need to be tested in a separate process.
24 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
26 class ApiTest extends DatabaseTest
29 * @var TestHandler Can handle log-outputs
34 * Create variables used by tests.
36 public function setUp()
38 $basedir = BasePath::create(dirname(__DIR__) . '/../');
39 $configLoader = new Config\ConfigCacheLoader($basedir);
40 $config = Factory\ConfigFactory::createCache($configLoader);
41 $logger = Factory\LoggerFactory::create('test', $config);
42 $this->app = new App($config, $logger, false);
43 $this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
47 // User data that the test database is populated with
50 'name' => 'Self contact',
51 'nick' => 'selfcontact',
52 'nurl' => 'http://localhost/profile/selfcontact'
56 'name' => 'Friend contact',
57 'nick' => 'friendcontact',
58 'nurl' => 'http://localhost/profile/friendcontact'
62 'name' => 'othercontact',
63 'nick' => 'othercontact',
64 'nurl' => 'http://localhost/profile/othercontact'
67 // User ID that we know is not in the database
68 $this->wrongUserId = 666;
70 // Most API require login so we force the session
73 'authenticated' => true,
74 'uid' => $this->selfUser['id']
77 Config::set('system', 'url', 'http://localhost');
78 Config::set('system', 'hostname', 'localhost');
79 Config::set('system', 'worker_dont_fork', true);
82 Config::set('config', 'hostname', 'localhost');
83 Config::set('system', 'throttle_limit_day', 100);
84 Config::set('system', 'throttle_limit_week', 100);
85 Config::set('system', 'throttle_limit_month', 100);
86 Config::set('system', 'theme', 'system_theme');
90 * Cleanup variables used by tests.
92 protected function tearDown()
97 $this->app->argv = ['home'];
101 * Assert that an user array contains expected keys.
102 * @param array $user User array
105 private function assertSelfUser(array $user)
107 $this->assertEquals($this->selfUser['id'], $user['uid']);
108 $this->assertEquals($this->selfUser['id'], $user['cid']);
109 $this->assertEquals(1, $user['self']);
110 $this->assertEquals('DFRN', $user['location']);
111 $this->assertEquals($this->selfUser['name'], $user['name']);
112 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
113 $this->assertEquals('dfrn', $user['network']);
114 $this->assertTrue($user['verified']);
118 * Assert that an user array contains expected keys.
119 * @param array $user User array
122 private function assertOtherUser(array $user)
124 $this->assertEquals($this->otherUser['id'], $user['id']);
125 $this->assertEquals($this->otherUser['id'], $user['id_str']);
126 $this->assertEquals(0, $user['self']);
127 $this->assertEquals($this->otherUser['name'], $user['name']);
128 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
129 $this->assertFalse($user['verified']);
133 * Assert that a status array contains expected keys.
134 * @param array $status Status array
137 private function assertStatus(array $status)
139 $this->assertInternalType('string', $status['text']);
140 $this->assertInternalType('int', $status['id']);
141 // We could probably do more checks here.
145 * Assert that a list array contains expected keys.
146 * @param array $list List array
149 private function assertList(array $list)
151 $this->assertInternalType('string', $list['name']);
152 $this->assertInternalType('int', $list['id']);
153 $this->assertInternalType('string', $list['id_str']);
154 $this->assertContains($list['mode'], ['public', 'private']);
155 // We could probably do more checks here.
159 * Assert that the string is XML and contain the root element.
160 * @param string $result XML string
161 * @param string $root_element Root element name
164 private function assertXml($result, $root_element)
166 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
167 $this->assertContains('<'.$root_element, $result);
168 // We could probably do more checks here.
172 * Get the path to a temporary empty PNG image.
173 * @return string Path
175 private function getTempImage()
177 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
181 // Empty 1x1 px PNG image
182 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
190 * Test the api_user() function.
193 public function testApiUser()
195 $this->assertEquals($this->selfUser['id'], api_user());
199 * Test the api_user() function with an unallowed user.
202 public function testApiUserWithUnallowedUser()
204 $_SESSION = ['allow_api' => false];
205 $this->assertEquals(false, api_user());
209 * Test the api_source() function.
212 public function testApiSource()
214 $this->assertEquals('api', api_source());
218 * Test the api_source() function with a Twidere user agent.
221 public function testApiSourceWithTwidere()
223 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
224 $this->assertEquals('Twidere', api_source());
228 * Test the api_source() function with a GET parameter.
231 public function testApiSourceWithGet()
233 $_GET['source'] = 'source_name';
234 $this->assertEquals('source_name', api_source());
238 * Test the api_date() function.
241 public function testApiDate()
243 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
247 * Test the api_register_func() function.
250 public function testApiRegisterFunc()
262 $this->assertTrue($API['api_path']['auth']);
263 $this->assertEquals('method', $API['api_path']['method']);
264 $this->assertTrue(is_callable($API['api_path']['func']));
268 * Test the api_login() function without any login.
270 * @runInSeparateProcess
271 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
273 public function testApiLoginWithoutLogin()
275 api_login($this->app);
279 * Test the api_login() function with a bad login.
281 * @runInSeparateProcess
282 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
284 public function testApiLoginWithBadLogin()
286 $_SERVER['PHP_AUTH_USER'] = 'user@server';
287 api_login($this->app);
291 * Test the api_login() function with oAuth.
294 public function testApiLoginWithOauth()
296 $this->markTestIncomplete('Can we test this easily?');
300 * Test the api_login() function with authentication provided by an addon.
303 public function testApiLoginWithAddonAuth()
305 $this->markTestIncomplete('Can we test this easily?');
309 * Test the api_login() function with a correct login.
311 * @runInSeparateProcess
313 public function testApiLoginWithCorrectLogin()
315 $_SERVER['PHP_AUTH_USER'] = 'Test user';
316 $_SERVER['PHP_AUTH_PW'] = 'password';
317 api_login($this->app);
321 * Test the api_login() function with a remote user.
323 * @runInSeparateProcess
324 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
326 public function testApiLoginWithRemoteUser()
328 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
329 api_login($this->app);
333 * Test the api_check_method() function.
336 public function testApiCheckMethod()
338 $this->assertFalse(api_check_method('method'));
342 * Test the api_check_method() function with a correct method.
345 public function testApiCheckMethodWithCorrectMethod()
347 $_SERVER['REQUEST_METHOD'] = 'method';
348 $this->assertTrue(api_check_method('method'));
352 * Test the api_check_method() function with a wildcard.
355 public function testApiCheckMethodWithWildcard()
357 $this->assertTrue(api_check_method('*'));
361 * Test the api_call() function.
363 * @runInSeparateProcess
365 public function testApiCall()
369 'method' => 'method',
370 'func' => function () {
371 return ['data' => ['some_data']];
374 $_SERVER['REQUEST_METHOD'] = 'method';
375 $_GET['callback'] = 'callback_name';
377 $this->app->query_string = 'api_path';
379 'callback_name(["some_data"])',
385 * Test the api_call() function with the profiled enabled.
387 * @runInSeparateProcess
389 public function testApiCallWithProfiler()
393 'method' => 'method',
394 'func' => function () {
395 return ['data' => ['some_data']];
398 $_SERVER['REQUEST_METHOD'] = 'method';
399 Config::set('system', 'profiler', true);
400 Config::set('rendertime', 'callstack', true);
401 $this->app->callstack = [
402 'database' => ['some_function' => 200],
403 'database_write' => ['some_function' => 200],
404 'cache' => ['some_function' => 200],
405 'cache_write' => ['some_function' => 200],
406 'network' => ['some_function' => 200]
409 $this->app->query_string = 'api_path';
417 * Test the api_call() function without any result.
419 * @runInSeparateProcess
421 public function testApiCallWithNoResult()
425 'method' => 'method',
426 'func' => function () {
430 $_SERVER['REQUEST_METHOD'] = 'method';
432 $this->app->query_string = 'api_path';
434 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
440 * Test the api_call() function with an unimplemented API.
442 * @runInSeparateProcess
444 public function testApiCallWithUninplementedApi()
447 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
453 * Test the api_call() function with a JSON result.
455 * @runInSeparateProcess
457 public function testApiCallWithJson()
461 'method' => 'method',
462 'func' => function () {
463 return ['data' => ['some_data']];
466 $_SERVER['REQUEST_METHOD'] = 'method';
468 $this->app->query_string = 'api_path.json';
476 * Test the api_call() function with an XML result.
478 * @runInSeparateProcess
480 public function testApiCallWithXml()
484 'method' => 'method',
485 'func' => function () {
489 $_SERVER['REQUEST_METHOD'] = 'method';
491 $this->app->query_string = 'api_path.xml';
499 * Test the api_call() function with an RSS result.
501 * @runInSeparateProcess
503 public function testApiCallWithRss()
507 'method' => 'method',
508 'func' => function () {
512 $_SERVER['REQUEST_METHOD'] = 'method';
514 $this->app->query_string = 'api_path.rss';
516 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
523 * Test the api_call() function with an Atom result.
525 * @runInSeparateProcess
527 public function testApiCallWithAtom()
531 'method' => 'method',
532 'func' => function () {
536 $_SERVER['REQUEST_METHOD'] = 'method';
538 $this->app->query_string = 'api_path.atom';
540 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
547 * Test the api_call() function with an unallowed method.
549 * @runInSeparateProcess
551 public function testApiCallWithWrongMethod()
554 $API['api_path'] = ['method' => 'method'];
556 $this->app->query_string = 'api_path';
558 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
564 * Test the api_call() function with an unauthorized user.
566 * @runInSeparateProcess
568 public function testApiCallWithWrongAuth()
572 'method' => 'method',
575 $_SERVER['REQUEST_METHOD'] = 'method';
576 $_SESSION['authenticated'] = false;
578 $this->app->query_string = 'api_path';
580 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
586 * Test the api_error() function with a JSON result.
588 * @runInSeparateProcess
590 public function testApiErrorWithJson()
593 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
594 api_error('json', new HTTPException('error_message'))
599 * Test the api_error() function with an XML result.
601 * @runInSeparateProcess
603 public function testApiErrorWithXml()
606 '<?xml version="1.0"?>'."\n".
607 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
608 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
609 'xmlns:georss="http://www.georss.org/georss">'."\n".
610 ' <error>error_message</error>'."\n".
611 ' <code>200 Friendica\Network\HTTP</code>'."\n".
614 api_error('xml', new HTTPException('error_message'))
619 * Test the api_error() function with an RSS result.
621 * @runInSeparateProcess
623 public function testApiErrorWithRss()
626 '<?xml version="1.0"?>'."\n".
627 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
628 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
629 'xmlns:georss="http://www.georss.org/georss">'."\n".
630 ' <error>error_message</error>'."\n".
631 ' <code>200 Friendica\Network\HTTP</code>'."\n".
634 api_error('rss', new HTTPException('error_message'))
639 * Test the api_error() function with an Atom result.
641 * @runInSeparateProcess
643 public function testApiErrorWithAtom()
646 '<?xml version="1.0"?>'."\n".
647 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
648 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
649 'xmlns:georss="http://www.georss.org/georss">'."\n".
650 ' <error>error_message</error>'."\n".
651 ' <code>200 Friendica\Network\HTTP</code>'."\n".
654 api_error('atom', new HTTPException('error_message'))
659 * Test the api_rss_extra() function.
662 public function testApiRssExtra()
664 $user_info = ['url' => 'user_url', 'lang' => 'en'];
665 $result = api_rss_extra($this->app, [], $user_info);
666 $this->assertEquals($user_info, $result['$user']);
667 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
668 $this->assertArrayHasKey('self', $result['$rss']);
669 $this->assertArrayHasKey('base', $result['$rss']);
670 $this->assertArrayHasKey('updated', $result['$rss']);
671 $this->assertArrayHasKey('atom_updated', $result['$rss']);
672 $this->assertArrayHasKey('language', $result['$rss']);
673 $this->assertArrayHasKey('logo', $result['$rss']);
677 * Test the api_rss_extra() function without any user info.
679 * @runInSeparateProcess
681 public function testApiRssExtraWithoutUserInfo()
683 $result = api_rss_extra($this->app, [], null);
684 $this->assertInternalType('array', $result['$user']);
685 $this->assertArrayHasKey('alternate', $result['$rss']);
686 $this->assertArrayHasKey('self', $result['$rss']);
687 $this->assertArrayHasKey('base', $result['$rss']);
688 $this->assertArrayHasKey('updated', $result['$rss']);
689 $this->assertArrayHasKey('atom_updated', $result['$rss']);
690 $this->assertArrayHasKey('language', $result['$rss']);
691 $this->assertArrayHasKey('logo', $result['$rss']);
695 * Test the api_unique_id_to_nurl() function.
698 public function testApiUniqueIdToNurl()
700 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
704 * Test the api_unique_id_to_nurl() function with a correct ID.
707 public function testApiUniqueIdToNurlWithCorrectId()
709 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
713 * Test the api_get_user() function.
715 * @runInSeparateProcess
717 public function testApiGetUser()
719 $user = api_get_user($this->app);
720 $this->assertSelfUser($user);
721 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
722 $this->assertEquals('6fdbe8', $user['profile_link_color']);
723 $this->assertEquals('ededed', $user['profile_background_color']);
727 * Test the api_get_user() function with a Frio schema.
729 * @runInSeparateProcess
731 public function testApiGetUserWithFrioSchema()
733 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
734 $user = api_get_user($this->app);
735 $this->assertSelfUser($user);
736 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
737 $this->assertEquals('6fdbe8', $user['profile_link_color']);
738 $this->assertEquals('ededed', $user['profile_background_color']);
742 * Test the api_get_user() function with a custom Frio schema.
744 * @runInSeparateProcess
746 public function testApiGetUserWithCustomFrioSchema()
748 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
749 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
750 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
751 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
752 $user = api_get_user($this->app);
753 $this->assertSelfUser($user);
754 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
755 $this->assertEquals('123456', $user['profile_link_color']);
756 $this->assertEquals('123456', $user['profile_background_color']);
760 * Test the api_get_user() function with an empty Frio schema.
762 * @runInSeparateProcess
764 public function testApiGetUserWithEmptyFrioSchema()
766 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
767 $user = api_get_user($this->app);
768 $this->assertSelfUser($user);
769 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
770 $this->assertEquals('6fdbe8', $user['profile_link_color']);
771 $this->assertEquals('ededed', $user['profile_background_color']);
775 * Test the api_get_user() function with an user that is not allowed to use the API.
777 * @runInSeparateProcess
779 public function testApiGetUserWithoutApiUser()
781 $_SERVER['PHP_AUTH_USER'] = 'Test user';
782 $_SERVER['PHP_AUTH_PW'] = 'password';
783 $_SESSION['allow_api'] = false;
784 $this->assertFalse(api_get_user($this->app));
788 * Test the api_get_user() function with an user ID in a GET parameter.
790 * @runInSeparateProcess
792 public function testApiGetUserWithGetId()
794 $_GET['user_id'] = $this->otherUser['id'];
795 $this->assertOtherUser(api_get_user($this->app));
799 * Test the api_get_user() function with a wrong user ID in a GET parameter.
801 * @runInSeparateProcess
802 * @expectedException Friendica\Network\HTTPException\BadRequestException
804 public function testApiGetUserWithWrongGetId()
806 $_GET['user_id'] = $this->wrongUserId;
807 $this->assertOtherUser(api_get_user($this->app));
811 * Test the api_get_user() function with an user name in a GET parameter.
813 * @runInSeparateProcess
815 public function testApiGetUserWithGetName()
817 $_GET['screen_name'] = $this->selfUser['nick'];
818 $this->assertSelfUser(api_get_user($this->app));
822 * Test the api_get_user() function with a profile URL in a GET parameter.
824 * @runInSeparateProcess
826 public function testApiGetUserWithGetUrl()
828 $_GET['profileurl'] = $this->selfUser['nurl'];
829 $this->assertSelfUser(api_get_user($this->app));
833 * Test the api_get_user() function with an user ID in the API path.
835 * @runInSeparateProcess
837 public function testApiGetUserWithNumericCalledApi()
840 $called_api = ['api_path'];
841 $this->app->argv[1] = $this->otherUser['id'].'.json';
842 $this->assertOtherUser(api_get_user($this->app));
846 * Test the api_get_user() function with the $called_api global variable.
848 * @runInSeparateProcess
850 public function testApiGetUserWithCalledApi()
853 $called_api = ['api', 'api_path'];
854 $this->assertSelfUser(api_get_user($this->app));
858 * Test the api_get_user() function with a valid user.
860 * @runInSeparateProcess
862 public function testApiGetUserWithCorrectUser()
864 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
868 * Test the api_get_user() function with a wrong user ID.
870 * @runInSeparateProcess
871 * @expectedException Friendica\Network\HTTPException\BadRequestException
873 public function testApiGetUserWithWrongUser()
875 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
879 * Test the api_get_user() function with a 0 user ID.
881 * @runInSeparateProcess
883 public function testApiGetUserWithZeroUser()
885 $this->assertSelfUser(api_get_user($this->app, 0));
889 * Test the api_item_get_user() function.
891 * @runInSeparateProcess
893 public function testApiItemGetUser()
895 $users = api_item_get_user($this->app, []);
896 $this->assertSelfUser($users[0]);
900 * Test the api_item_get_user() function with a different item parent.
903 public function testApiItemGetUserWithDifferentParent()
905 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
906 $this->assertSelfUser($users[0]);
907 $this->assertEquals($users[0], $users[1]);
911 * Test the api_walk_recursive() function.
914 public function testApiWalkRecursive()
922 // Should we test this with a callback that actually does something?
930 * Test the api_walk_recursive() function with an array.
933 public function testApiWalkRecursiveWithArray()
935 $array = [['item1'], ['item2']];
941 // Should we test this with a callback that actually does something?
949 * Test the api_reformat_xml() function.
952 public function testApiReformatXml()
956 $this->assertTrue(api_reformat_xml($item, $key));
957 $this->assertEquals('true', $item);
961 * Test the api_reformat_xml() function with a statusnet_api key.
964 public function testApiReformatXmlWithStatusnetKey()
967 $key = 'statusnet_api';
968 $this->assertTrue(api_reformat_xml($item, $key));
969 $this->assertEquals('statusnet:api', $key);
973 * Test the api_reformat_xml() function with a friendica_api key.
976 public function testApiReformatXmlWithFriendicaKey()
979 $key = 'friendica_api';
980 $this->assertTrue(api_reformat_xml($item, $key));
981 $this->assertEquals('friendica:api', $key);
985 * Test the api_create_xml() function.
988 public function testApiCreateXml()
991 '<?xml version="1.0"?>'."\n".
992 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
993 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
994 'xmlns:georss="http://www.georss.org/georss">'."\n".
995 ' <data>some_data</data>'."\n".
996 '</root_element>'."\n",
997 api_create_xml(['data' => ['some_data']], 'root_element')
1002 * Test the api_create_xml() function without any XML namespace.
1005 public function testApiCreateXmlWithoutNamespaces()
1007 $this->assertEquals(
1008 '<?xml version="1.0"?>'."\n".
1010 ' <data>some_data</data>'."\n".
1012 api_create_xml(['data' => ['some_data']], 'ok')
1017 * Test the api_format_data() function.
1020 public function testApiFormatData()
1022 $data = ['some_data'];
1023 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1027 * Test the api_format_data() function with an XML result.
1030 public function testApiFormatDataWithXml()
1032 $this->assertEquals(
1033 '<?xml version="1.0"?>'."\n".
1034 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1035 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1036 'xmlns:georss="http://www.georss.org/georss">'."\n".
1037 ' <data>some_data</data>'."\n".
1038 '</root_element>'."\n",
1039 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1044 * Test the api_account_verify_credentials() function.
1047 public function testApiAccountVerifyCredentials()
1049 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1053 * Test the api_account_verify_credentials() function without an authenticated user.
1055 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1057 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1059 $_SESSION['authenticated'] = false;
1060 api_account_verify_credentials('json');
1064 * Test the requestdata() function.
1067 public function testRequestdata()
1069 $this->assertNull(requestdata('variable_name'));
1073 * Test the requestdata() function with a POST parameter.
1076 public function testRequestdataWithPost()
1078 $_POST['variable_name'] = 'variable_value';
1079 $this->assertEquals('variable_value', requestdata('variable_name'));
1083 * Test the requestdata() function with a GET parameter.
1086 public function testRequestdataWithGet()
1088 $_GET['variable_name'] = 'variable_value';
1089 $this->assertEquals('variable_value', requestdata('variable_name'));
1093 * Test the api_statuses_mediap() function.
1096 public function testApiStatusesMediap()
1098 $this->app->argc = 2;
1106 'tmp_name' => $this->getTempImage(),
1107 'name' => 'spacer.png',
1108 'type' => 'image/png'
1111 $_GET['status'] = '<b>Status content</b>';
1113 $result = api_statuses_mediap('json');
1114 $this->assertStatus($result['status']);
1118 * Test the api_statuses_mediap() function without an authenticated user.
1120 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1122 public function testApiStatusesMediapWithoutAuthenticatedUser()
1124 $_SESSION['authenticated'] = false;
1125 api_statuses_mediap('json');
1129 * Test the api_statuses_update() function.
1132 public function testApiStatusesUpdate()
1134 $_GET['status'] = 'Status content #friendica';
1135 $_GET['in_reply_to_status_id'] = -1;
1144 'tmp_name' => $this->getTempImage(),
1145 'name' => 'spacer.png',
1146 'type' => 'image/png'
1150 $result = api_statuses_update('json');
1151 $this->assertStatus($result['status']);
1155 * Test the api_statuses_update() function with an HTML status.
1158 public function testApiStatusesUpdateWithHtml()
1160 $_GET['htmlstatus'] = '<b>Status content</b>';
1162 $result = api_statuses_update('json');
1163 $this->assertStatus($result['status']);
1167 * Test the api_statuses_update() function without an authenticated user.
1169 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1171 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1173 $_SESSION['authenticated'] = false;
1174 api_statuses_update('json');
1178 * Test the api_statuses_update() function with a parent status.
1181 public function testApiStatusesUpdateWithParent()
1183 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1187 * Test the api_statuses_update() function with a media_ids parameter.
1190 public function testApiStatusesUpdateWithMediaIds()
1192 $this->markTestIncomplete();
1196 * Test the api_statuses_update() function with the throttle limit reached.
1199 public function testApiStatusesUpdateWithDayThrottleReached()
1201 $this->markTestIncomplete();
1205 * Test the api_media_upload() function.
1207 * @expectedException Friendica\Network\HTTPException\BadRequestException
1209 public function testApiMediaUpload()
1215 * Test the api_media_upload() function without an authenticated user.
1217 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1219 public function testApiMediaUploadWithoutAuthenticatedUser()
1221 $_SESSION['authenticated'] = false;
1226 * Test the api_media_upload() function with an invalid uploaded media.
1228 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1230 public function testApiMediaUploadWithMedia()
1235 'tmp_name' => 'tmp_name'
1242 * Test the api_media_upload() function with an valid uploaded media.
1245 public function testApiMediaUploadWithValidMedia()
1253 'tmp_name' => $this->getTempImage(),
1254 'name' => 'spacer.png',
1255 'type' => 'image/png'
1261 $result = api_media_upload();
1262 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1263 $this->assertEquals(1, $result['media']['image']['w']);
1264 $this->assertEquals(1, $result['media']['image']['h']);
1265 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1269 * Test the api_status_show() function.
1272 public function testApiStatusShow()
1274 $result = api_status_show('json');
1275 $this->assertStatus($result['status']);
1279 * Test the api_status_show() function with an XML result.
1282 public function testApiStatusShowWithXml()
1284 $result = api_status_show('xml');
1285 $this->assertXml($result, 'statuses');
1289 * Test the api_status_show() function with a raw result.
1292 public function testApiStatusShowWithRaw()
1294 $this->assertStatus(api_status_show('raw'));
1298 * Test the api_users_show() function.
1301 public function testApiUsersShow()
1303 $result = api_users_show('json');
1304 // We can't use assertSelfUser() here because the user object is missing some properties.
1305 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1306 $this->assertEquals('DFRN', $result['user']['location']);
1307 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1308 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1309 $this->assertEquals('dfrn', $result['user']['network']);
1310 $this->assertTrue($result['user']['verified']);
1314 * Test the api_users_show() function with an XML result.
1317 public function testApiUsersShowWithXml()
1319 $result = api_users_show('xml');
1320 $this->assertXml($result, 'statuses');
1324 * Test the api_users_search() function.
1327 public function testApiUsersSearch()
1329 $_GET['q'] = 'othercontact';
1330 $result = api_users_search('json');
1331 $this->assertOtherUser($result['users'][0]);
1335 * Test the api_users_search() function with an XML result.
1338 public function testApiUsersSearchWithXml()
1340 $_GET['q'] = 'othercontact';
1341 $result = api_users_search('xml');
1342 $this->assertXml($result, 'users');
1346 * Test the api_users_search() function without a GET q parameter.
1348 * @expectedException Friendica\Network\HTTPException\BadRequestException
1350 public function testApiUsersSearchWithoutQuery()
1352 api_users_search('json');
1356 * Test the api_users_lookup() function.
1358 * @expectedException Friendica\Network\HTTPException\NotFoundException
1360 public function testApiUsersLookup()
1362 api_users_lookup('json');
1366 * Test the api_users_lookup() function with an user ID.
1369 public function testApiUsersLookupWithUserId()
1371 $_REQUEST['user_id'] = $this->otherUser['id'];
1372 $result = api_users_lookup('json');
1373 $this->assertOtherUser($result['users'][0]);
1377 * Test the api_search() function.
1380 public function testApiSearch()
1382 $_REQUEST['q'] = 'reply';
1383 $_REQUEST['max_id'] = 10;
1384 $result = api_search('json');
1385 foreach ($result['status'] as $status) {
1386 $this->assertStatus($status);
1387 $this->assertContains('reply', $status['text'], null, true);
1392 * Test the api_search() function a count parameter.
1395 public function testApiSearchWithCount()
1397 $_REQUEST['q'] = 'reply';
1398 $_REQUEST['count'] = 20;
1399 $result = api_search('json');
1400 foreach ($result['status'] as $status) {
1401 $this->assertStatus($status);
1402 $this->assertContains('reply', $status['text'], null, true);
1407 * Test the api_search() function with an rpp parameter.
1410 public function testApiSearchWithRpp()
1412 $_REQUEST['q'] = 'reply';
1413 $_REQUEST['rpp'] = 20;
1414 $result = api_search('json');
1415 foreach ($result['status'] as $status) {
1416 $this->assertStatus($status);
1417 $this->assertContains('reply', $status['text'], null, true);
1422 * Test the api_search() function with an q parameter contains hashtag.
1425 public function testApiSearchWithHashtag()
1427 $_REQUEST['q'] = '%23friendica';
1428 $result = api_search('json');
1429 foreach ($result['status'] as $status) {
1430 $this->assertStatus($status);
1431 $this->assertContains('#friendica', $status['text'], null, true);
1436 * Test the api_search() function with an exclude_replies parameter.
1439 public function testApiSearchWithExcludeReplies()
1441 $_REQUEST['max_id'] = 10;
1442 $_REQUEST['exclude_replies'] = true;
1443 $_REQUEST['q'] = 'friendica';
1444 $result = api_search('json');
1445 foreach ($result['status'] as $status) {
1446 $this->assertStatus($status);
1451 * Test the api_search() function without an authenticated user.
1453 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1455 public function testApiSearchWithUnallowedUser()
1457 $_SESSION['allow_api'] = false;
1458 $_GET['screen_name'] = $this->selfUser['nick'];
1463 * Test the api_search() function without any GET query parameter.
1465 * @expectedException Friendica\Network\HTTPException\BadRequestException
1467 public function testApiSearchWithoutQuery()
1473 * Test the api_statuses_home_timeline() function.
1476 public function testApiStatusesHomeTimeline()
1478 $_REQUEST['max_id'] = 10;
1479 $_REQUEST['exclude_replies'] = true;
1480 $_REQUEST['conversation_id'] = 1;
1481 $result = api_statuses_home_timeline('json');
1482 $this->assertNotEmpty($result['status']);
1483 foreach ($result['status'] as $status) {
1484 $this->assertStatus($status);
1489 * Test the api_statuses_home_timeline() function with a negative page parameter.
1492 public function testApiStatusesHomeTimelineWithNegativePage()
1494 $_REQUEST['page'] = -2;
1495 $result = api_statuses_home_timeline('json');
1496 $this->assertNotEmpty($result['status']);
1497 foreach ($result['status'] as $status) {
1498 $this->assertStatus($status);
1503 * Test the api_statuses_home_timeline() with an unallowed user.
1505 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1507 public function testApiStatusesHomeTimelineWithUnallowedUser()
1509 $_SESSION['allow_api'] = false;
1510 $_GET['screen_name'] = $this->selfUser['nick'];
1511 api_statuses_home_timeline('json');
1515 * Test the api_statuses_home_timeline() function with an RSS result.
1518 public function testApiStatusesHomeTimelineWithRss()
1520 $result = api_statuses_home_timeline('rss');
1521 $this->assertXml($result, 'statuses');
1525 * Test the api_statuses_public_timeline() function.
1528 public function testApiStatusesPublicTimeline()
1530 $_REQUEST['max_id'] = 10;
1531 $_REQUEST['conversation_id'] = 1;
1532 $result = api_statuses_public_timeline('json');
1533 $this->assertNotEmpty($result['status']);
1534 foreach ($result['status'] as $status) {
1535 $this->assertStatus($status);
1540 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1543 public function testApiStatusesPublicTimelineWithExcludeReplies()
1545 $_REQUEST['max_id'] = 10;
1546 $_REQUEST['exclude_replies'] = true;
1547 $result = api_statuses_public_timeline('json');
1548 $this->assertNotEmpty($result['status']);
1549 foreach ($result['status'] as $status) {
1550 $this->assertStatus($status);
1555 * Test the api_statuses_public_timeline() function with a negative page parameter.
1558 public function testApiStatusesPublicTimelineWithNegativePage()
1560 $_REQUEST['page'] = -2;
1561 $result = api_statuses_public_timeline('json');
1562 $this->assertNotEmpty($result['status']);
1563 foreach ($result['status'] as $status) {
1564 $this->assertStatus($status);
1569 * Test the api_statuses_public_timeline() function with an unallowed user.
1571 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1573 public function testApiStatusesPublicTimelineWithUnallowedUser()
1575 $_SESSION['allow_api'] = false;
1576 $_GET['screen_name'] = $this->selfUser['nick'];
1577 api_statuses_public_timeline('json');
1581 * Test the api_statuses_public_timeline() function with an RSS result.
1584 public function testApiStatusesPublicTimelineWithRss()
1586 $result = api_statuses_public_timeline('rss');
1587 $this->assertXml($result, 'statuses');
1591 * Test the api_statuses_networkpublic_timeline() function.
1594 public function testApiStatusesNetworkpublicTimeline()
1596 $_REQUEST['max_id'] = 10;
1597 $result = api_statuses_networkpublic_timeline('json');
1598 $this->assertNotEmpty($result['status']);
1599 foreach ($result['status'] as $status) {
1600 $this->assertStatus($status);
1605 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1608 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1610 $_REQUEST['page'] = -2;
1611 $result = api_statuses_networkpublic_timeline('json');
1612 $this->assertNotEmpty($result['status']);
1613 foreach ($result['status'] as $status) {
1614 $this->assertStatus($status);
1619 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1621 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1623 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1625 $_SESSION['allow_api'] = false;
1626 $_GET['screen_name'] = $this->selfUser['nick'];
1627 api_statuses_networkpublic_timeline('json');
1631 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1634 public function testApiStatusesNetworkpublicTimelineWithRss()
1636 $result = api_statuses_networkpublic_timeline('rss');
1637 $this->assertXml($result, 'statuses');
1641 * Test the api_statuses_show() function.
1643 * @expectedException Friendica\Network\HTTPException\BadRequestException
1645 public function testApiStatusesShow()
1647 api_statuses_show('json');
1651 * Test the api_statuses_show() function with an ID.
1654 public function testApiStatusesShowWithId()
1656 $this->app->argv[3] = 1;
1657 $result = api_statuses_show('json');
1658 $this->assertStatus($result['status']);
1662 * Test the api_statuses_show() function with the conversation parameter.
1665 public function testApiStatusesShowWithConversation()
1667 $this->app->argv[3] = 1;
1668 $_REQUEST['conversation'] = 1;
1669 $result = api_statuses_show('json');
1670 $this->assertNotEmpty($result['status']);
1671 foreach ($result['status'] as $status) {
1672 $this->assertStatus($status);
1677 * Test the api_statuses_show() function with an unallowed user.
1679 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1681 public function testApiStatusesShowWithUnallowedUser()
1683 $_SESSION['allow_api'] = false;
1684 $_GET['screen_name'] = $this->selfUser['nick'];
1685 api_statuses_show('json');
1689 * Test the api_conversation_show() function.
1691 * @expectedException Friendica\Network\HTTPException\BadRequestException
1693 public function testApiConversationShow()
1695 api_conversation_show('json');
1699 * Test the api_conversation_show() function with an ID.
1702 public function testApiConversationShowWithId()
1704 $this->app->argv[3] = 1;
1705 $_REQUEST['max_id'] = 10;
1706 $_REQUEST['page'] = -2;
1707 $result = api_conversation_show('json');
1708 $this->assertNotEmpty($result['status']);
1709 foreach ($result['status'] as $status) {
1710 $this->assertStatus($status);
1715 * Test the api_conversation_show() function with an unallowed user.
1717 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1719 public function testApiConversationShowWithUnallowedUser()
1721 $_SESSION['allow_api'] = false;
1722 $_GET['screen_name'] = $this->selfUser['nick'];
1723 api_conversation_show('json');
1727 * Test the api_statuses_repeat() function.
1729 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1731 public function testApiStatusesRepeat()
1733 api_statuses_repeat('json');
1737 * Test the api_statuses_repeat() function without an authenticated user.
1739 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1741 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1743 $_SESSION['authenticated'] = false;
1744 api_statuses_repeat('json');
1748 * Test the api_statuses_repeat() function with an ID.
1751 public function testApiStatusesRepeatWithId()
1753 $this->app->argv[3] = 1;
1754 $result = api_statuses_repeat('json');
1755 $this->assertStatus($result['status']);
1757 // Also test with a shared status
1758 $this->app->argv[3] = 5;
1759 $result = api_statuses_repeat('json');
1760 $this->assertStatus($result['status']);
1764 * Test the api_statuses_destroy() function.
1766 * @expectedException Friendica\Network\HTTPException\BadRequestException
1768 public function testApiStatusesDestroy()
1770 api_statuses_destroy('json');
1774 * Test the api_statuses_destroy() function without an authenticated user.
1776 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1778 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1780 $_SESSION['authenticated'] = false;
1781 api_statuses_destroy('json');
1785 * Test the api_statuses_destroy() function with an ID.
1788 public function testApiStatusesDestroyWithId()
1790 $this->app->argv[3] = 1;
1791 $result = api_statuses_destroy('json');
1792 $this->assertStatus($result['status']);
1796 * Test the api_statuses_mentions() function.
1799 public function testApiStatusesMentions()
1801 $this->app->user = ['nickname' => $this->selfUser['nick']];
1802 $_REQUEST['max_id'] = 10;
1803 $result = api_statuses_mentions('json');
1804 $this->assertEmpty($result['status']);
1805 // We should test with mentions in the database.
1809 * Test the api_statuses_mentions() function with a negative page parameter.
1812 public function testApiStatusesMentionsWithNegativePage()
1814 $_REQUEST['page'] = -2;
1815 $result = api_statuses_mentions('json');
1816 $this->assertEmpty($result['status']);
1820 * Test the api_statuses_mentions() function with an unallowed user.
1822 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1824 public function testApiStatusesMentionsWithUnallowedUser()
1826 $_SESSION['allow_api'] = false;
1827 $_GET['screen_name'] = $this->selfUser['nick'];
1828 api_statuses_mentions('json');
1832 * Test the api_statuses_mentions() function with an RSS result.
1835 public function testApiStatusesMentionsWithRss()
1837 $result = api_statuses_mentions('rss');
1838 $this->assertXml($result, 'statuses');
1842 * Test the api_statuses_user_timeline() function.
1845 public function testApiStatusesUserTimeline()
1847 $_REQUEST['max_id'] = 10;
1848 $_REQUEST['exclude_replies'] = true;
1849 $_REQUEST['conversation_id'] = 1;
1850 $result = api_statuses_user_timeline('json');
1851 $this->assertNotEmpty($result['status']);
1852 foreach ($result['status'] as $status) {
1853 $this->assertStatus($status);
1858 * Test the api_statuses_user_timeline() function with a negative page parameter.
1861 public function testApiStatusesUserTimelineWithNegativePage()
1863 $_REQUEST['page'] = -2;
1864 $result = api_statuses_user_timeline('json');
1865 $this->assertNotEmpty($result['status']);
1866 foreach ($result['status'] as $status) {
1867 $this->assertStatus($status);
1872 * Test the api_statuses_user_timeline() function with an RSS result.
1875 public function testApiStatusesUserTimelineWithRss()
1877 $result = api_statuses_user_timeline('rss');
1878 $this->assertXml($result, 'statuses');
1882 * Test the api_statuses_user_timeline() function with an unallowed user.
1884 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1886 public function testApiStatusesUserTimelineWithUnallowedUser()
1888 $_SESSION['allow_api'] = false;
1889 $_GET['screen_name'] = $this->selfUser['nick'];
1890 api_statuses_user_timeline('json');
1894 * Test the api_favorites_create_destroy() function.
1896 * @expectedException Friendica\Network\HTTPException\BadRequestException
1898 public function testApiFavoritesCreateDestroy()
1900 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1901 $this->app->argc = count($this->app->argv);
1902 api_favorites_create_destroy('json');
1906 * Test the api_favorites_create_destroy() function with an invalid ID.
1908 * @expectedException Friendica\Network\HTTPException\BadRequestException
1910 public function testApiFavoritesCreateDestroyWithInvalidId()
1912 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1913 $this->app->argc = count($this->app->argv);
1914 api_favorites_create_destroy('json');
1918 * Test the api_favorites_create_destroy() function with an invalid action.
1920 * @expectedException Friendica\Network\HTTPException\BadRequestException
1922 public function testApiFavoritesCreateDestroyWithInvalidAction()
1924 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1925 $this->app->argc = count($this->app->argv);
1926 $_REQUEST['id'] = 1;
1927 api_favorites_create_destroy('json');
1931 * Test the api_favorites_create_destroy() function with the create action.
1934 public function testApiFavoritesCreateDestroyWithCreateAction()
1936 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1937 $this->app->argc = count($this->app->argv);
1938 $_REQUEST['id'] = 3;
1939 $result = api_favorites_create_destroy('json');
1940 $this->assertStatus($result['status']);
1944 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1947 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1949 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1950 $this->app->argc = count($this->app->argv);
1951 $_REQUEST['id'] = 3;
1952 $result = api_favorites_create_destroy('rss');
1953 $this->assertXml($result, 'status');
1957 * Test the api_favorites_create_destroy() function with the destroy action.
1960 public function testApiFavoritesCreateDestroyWithDestroyAction()
1962 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1963 $this->app->argc = count($this->app->argv);
1964 $_REQUEST['id'] = 3;
1965 $result = api_favorites_create_destroy('json');
1966 $this->assertStatus($result['status']);
1970 * Test the api_favorites_create_destroy() function without an authenticated user.
1972 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1974 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1976 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1977 $this->app->argc = count($this->app->argv);
1978 $_SESSION['authenticated'] = false;
1979 api_favorites_create_destroy('json');
1983 * Test the api_favorites() function.
1986 public function testApiFavorites()
1988 $_REQUEST['page'] = -1;
1989 $_REQUEST['max_id'] = 10;
1990 $result = api_favorites('json');
1991 foreach ($result['status'] as $status) {
1992 $this->assertStatus($status);
1997 * Test the api_favorites() function with an RSS result.
2000 public function testApiFavoritesWithRss()
2002 $result = api_favorites('rss');
2003 $this->assertXml($result, 'statuses');
2007 * Test the api_favorites() function with an unallowed user.
2009 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2011 public function testApiFavoritesWithUnallowedUser()
2013 $_SESSION['allow_api'] = false;
2014 $_GET['screen_name'] = $this->selfUser['nick'];
2015 api_favorites('json');
2019 * Test the api_format_messages() function.
2022 public function testApiFormatMessages()
2024 $result = api_format_messages(
2025 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2026 ['id' => 2, 'screen_name' => 'recipient_name'],
2027 ['id' => 3, 'screen_name' => 'sender_name']
2029 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2030 $this->assertEquals(1, $result['id']);
2031 $this->assertEquals(2, $result['recipient_id']);
2032 $this->assertEquals(3, $result['sender_id']);
2033 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2034 $this->assertEquals('sender_name', $result['sender_screen_name']);
2038 * Test the api_format_messages() function with HTML.
2041 public function testApiFormatMessagesWithHtmlText()
2043 $_GET['getText'] = 'html';
2044 $result = api_format_messages(
2045 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2046 ['id' => 2, 'screen_name' => 'recipient_name'],
2047 ['id' => 3, 'screen_name' => 'sender_name']
2049 $this->assertEquals('item_title', $result['title']);
2050 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2054 * Test the api_format_messages() function with plain text.
2057 public function testApiFormatMessagesWithPlainText()
2059 $_GET['getText'] = 'plain';
2060 $result = api_format_messages(
2061 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2062 ['id' => 2, 'screen_name' => 'recipient_name'],
2063 ['id' => 3, 'screen_name' => 'sender_name']
2065 $this->assertEquals('item_title', $result['title']);
2066 $this->assertEquals('item_body', $result['text']);
2070 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2073 public function testApiFormatMessagesWithoutUserObjects()
2075 $_GET['getUserObjects'] = 'false';
2076 $result = api_format_messages(
2077 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2078 ['id' => 2, 'screen_name' => 'recipient_name'],
2079 ['id' => 3, 'screen_name' => 'sender_name']
2081 $this->assertTrue(!isset($result['sender']));
2082 $this->assertTrue(!isset($result['recipient']));
2086 * Test the api_convert_item() function.
2089 public function testApiConvertItem()
2091 $result = api_convert_item(
2093 'network' => 'feed',
2094 'title' => 'item_title',
2095 // We need a long string to test that it is correctly cut
2096 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2097 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2098 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2099 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2100 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2101 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2102 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2103 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2104 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2105 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2106 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2107 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2108 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2109 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2110 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2111 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2112 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2113 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2114 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2115 'repellat officia illum quos impedit quam iste esse unde qui '.
2116 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2117 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2118 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2119 'plink' => 'item_plink'
2122 $this->assertStringStartsWith('item_title', $result['text']);
2123 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2127 * Test the api_convert_item() function with an empty item body.
2130 public function testApiConvertItemWithoutBody()
2132 $result = api_convert_item(
2134 'network' => 'feed',
2135 'title' => 'item_title',
2137 'plink' => 'item_plink'
2140 $this->assertEquals('item_title', $result['text']);
2141 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2145 * Test the api_convert_item() function with the title in the body.
2148 public function testApiConvertItemWithTitleInBody()
2150 $result = api_convert_item(
2152 'title' => 'item_title',
2153 'body' => 'item_title item_body'
2156 $this->assertEquals('item_title item_body', $result['text']);
2157 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2161 * Test the api_get_attachments() function.
2164 public function testApiGetAttachments()
2167 $this->assertEmpty(api_get_attachments($body));
2171 * Test the api_get_attachments() function with an img tag.
2174 public function testApiGetAttachmentsWithImage()
2176 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2177 $this->assertInternalType('array', api_get_attachments($body));
2181 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2184 public function testApiGetAttachmentsWithImageAndAndStatus()
2186 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2187 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2188 $this->assertInternalType('array', api_get_attachments($body));
2192 * Test the api_get_entitities() function.
2195 public function testApiGetEntitities()
2198 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2202 * Test the api_get_entitities() function with the include_entities parameter.
2205 public function testApiGetEntititiesWithIncludeEntities()
2207 $_REQUEST['include_entities'] = 'true';
2209 $result = api_get_entitities($text, 'bbcode');
2210 $this->assertInternalType('array', $result['hashtags']);
2211 $this->assertInternalType('array', $result['symbols']);
2212 $this->assertInternalType('array', $result['urls']);
2213 $this->assertInternalType('array', $result['user_mentions']);
2217 * Test the api_format_items_embeded_images() function.
2220 public function testApiFormatItemsEmbededImages()
2222 $this->assertEquals(
2223 'text ' . System::baseUrl() . '/display/item_guid',
2224 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2229 * Test the api_contactlink_to_array() function.
2232 public function testApiContactlinkToArray()
2234 $this->assertEquals(
2239 api_contactlink_to_array('text')
2244 * Test the api_contactlink_to_array() function with an URL.
2247 public function testApiContactlinkToArrayWithUrl()
2249 $this->assertEquals(
2251 'name' => ['link_text'],
2254 api_contactlink_to_array('text <a href="url">link_text</a>')
2259 * Test the api_format_items_activities() function.
2262 public function testApiFormatItemsActivities()
2264 $item = ['uid' => 0, 'uri' => ''];
2265 $result = api_format_items_activities($item);
2266 $this->assertArrayHasKey('like', $result);
2267 $this->assertArrayHasKey('dislike', $result);
2268 $this->assertArrayHasKey('attendyes', $result);
2269 $this->assertArrayHasKey('attendno', $result);
2270 $this->assertArrayHasKey('attendmaybe', $result);
2274 * Test the api_format_items_activities() function with an XML result.
2277 public function testApiFormatItemsActivitiesWithXml()
2279 $item = ['uid' => 0, 'uri' => ''];
2280 $result = api_format_items_activities($item, 'xml');
2281 $this->assertArrayHasKey('friendica:like', $result);
2282 $this->assertArrayHasKey('friendica:dislike', $result);
2283 $this->assertArrayHasKey('friendica:attendyes', $result);
2284 $this->assertArrayHasKey('friendica:attendno', $result);
2285 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2289 * Test the api_format_items_profiles() function.
2292 public function testApiFormatItemsProfiles()
2295 'id' => 'profile_id',
2296 'profile-name' => 'profile_name',
2297 'is-default' => true,
2298 'hide-friends' => true,
2299 'photo' => 'profile_photo',
2300 'thumb' => 'profile_thumb',
2302 'net-publish' => true,
2303 'pdesc' => 'description',
2304 'dob' => 'date_of_birth',
2305 'address' => 'address',
2306 'locality' => 'city',
2307 'region' => 'region',
2308 'postal-code' => 'postal_code',
2309 'country-name' => 'country',
2310 'hometown' => 'hometown',
2311 'gender' => 'gender',
2312 'marital' => 'marital',
2313 'with' => 'marital_with',
2314 'howlong' => 'marital_since',
2315 'sexual' => 'sexual',
2316 'politic' => 'politic',
2317 'religion' => 'religion',
2318 'pub_keywords' => 'public_keywords',
2319 'prv_keywords' => 'private_keywords',
2322 'dislikes' => 'dislikes',
2328 'interest' => 'interest',
2329 'romance' => 'romance',
2331 'education' => 'education',
2332 'contact' => 'social_networks',
2333 'homepage' => 'homepage'
2335 $result = api_format_items_profiles($profile_row);
2336 $this->assertEquals(
2338 'profile_id' => 'profile_id',
2339 'profile_name' => 'profile_name',
2340 'is_default' => true,
2341 'hide_friends' => true,
2342 'profile_photo' => 'profile_photo',
2343 'profile_thumb' => 'profile_thumb',
2345 'net_publish' => true,
2346 'description' => 'description',
2347 'date_of_birth' => 'date_of_birth',
2348 'address' => 'address',
2350 'region' => 'region',
2351 'postal_code' => 'postal_code',
2352 'country' => 'country',
2353 'hometown' => 'hometown',
2354 'gender' => 'gender',
2355 'marital' => 'marital',
2356 'marital_with' => 'marital_with',
2357 'marital_since' => 'marital_since',
2358 'sexual' => 'sexual',
2359 'politic' => 'politic',
2360 'religion' => 'religion',
2361 'public_keywords' => 'public_keywords',
2362 'private_keywords' => 'private_keywords',
2365 'dislikes' => 'dislikes',
2371 'interest' => 'interest',
2372 'romance' => 'romance',
2374 'education' => 'education',
2375 'social_networks' => 'social_networks',
2376 'homepage' => 'homepage',
2384 * Test the api_format_items() function.
2387 public function testApiFormatItems()
2391 'item_network' => 'item_network',
2397 'author-network' => Protocol::DFRN,
2398 'author-link' => 'http://localhost/profile/othercontact',
2402 $result = api_format_items($items, ['id' => 0], true);
2403 foreach ($result as $status) {
2404 $this->assertStatus($status);
2409 * Test the api_format_items() function with an XML result.
2412 public function testApiFormatItemsWithXml()
2420 'author-network' => Protocol::DFRN,
2421 'author-link' => 'http://localhost/profile/othercontact',
2425 $result = api_format_items($items, ['id' => 0], true, 'xml');
2426 foreach ($result as $status) {
2427 $this->assertStatus($status);
2432 * Test the api_format_items() function.
2435 public function testApiAccountRateLimitStatus()
2437 $result = api_account_rate_limit_status('json');
2438 $this->assertEquals(150, $result['hash']['remaining_hits']);
2439 $this->assertEquals(150, $result['hash']['hourly_limit']);
2440 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2444 * Test the api_format_items() function with an XML result.
2447 public function testApiAccountRateLimitStatusWithXml()
2449 $result = api_account_rate_limit_status('xml');
2450 $this->assertXml($result, 'hash');
2454 * Test the api_help_test() function.
2457 public function testApiHelpTest()
2459 $result = api_help_test('json');
2460 $this->assertEquals(['ok' => 'ok'], $result);
2464 * Test the api_help_test() function with an XML result.
2467 public function testApiHelpTestWithXml()
2469 $result = api_help_test('xml');
2470 $this->assertXml($result, 'ok');
2474 * Test the api_lists_list() function.
2477 public function testApiListsList()
2479 $result = api_lists_list('json');
2480 $this->assertEquals(['lists_list' => []], $result);
2484 * Test the api_lists_ownerships() function.
2487 public function testApiListsOwnerships()
2489 $result = api_lists_ownerships('json');
2490 foreach ($result['lists']['lists'] as $list) {
2491 $this->assertList($list);
2496 * Test the api_lists_ownerships() function without an authenticated user.
2498 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2500 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2502 $_SESSION['authenticated'] = false;
2503 api_lists_ownerships('json');
2507 * Test the api_lists_statuses() function.
2508 * @expectedException Friendica\Network\HTTPException\BadRequestException
2511 public function testApiListsStatuses()
2513 api_lists_statuses('json');
2517 * Test the api_lists_statuses() function with a list ID.
2520 public function testApiListsStatusesWithListId()
2522 $_REQUEST['list_id'] = 1;
2523 $_REQUEST['page'] = -1;
2524 $_REQUEST['max_id'] = 10;
2525 $result = api_lists_statuses('json');
2526 foreach ($result['status'] as $status) {
2527 $this->assertStatus($status);
2532 * Test the api_lists_statuses() function with a list ID and a RSS result.
2535 public function testApiListsStatusesWithListIdAndRss()
2537 $_REQUEST['list_id'] = 1;
2538 $result = api_lists_statuses('rss');
2539 $this->assertXml($result, 'statuses');
2543 * Test the api_lists_statuses() function with an unallowed user.
2545 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2547 public function testApiListsStatusesWithUnallowedUser()
2549 $_SESSION['allow_api'] = false;
2550 $_GET['screen_name'] = $this->selfUser['nick'];
2551 api_lists_statuses('json');
2555 * Test the api_statuses_f() function.
2558 public function testApiStatusesFWithFriends()
2561 $result = api_statuses_f('friends');
2562 $this->assertArrayHasKey('user', $result);
2566 * Test the api_statuses_f() function.
2569 public function testApiStatusesFWithFollowers()
2571 $result = api_statuses_f('followers');
2572 $this->assertArrayHasKey('user', $result);
2576 * Test the api_statuses_f() function.
2579 public function testApiStatusesFWithBlocks()
2581 $result = api_statuses_f('blocks');
2582 $this->assertArrayHasKey('user', $result);
2586 * Test the api_statuses_f() function.
2589 public function testApiStatusesFWithIncoming()
2591 $result = api_statuses_f('incoming');
2592 $this->assertArrayHasKey('user', $result);
2596 * Test the api_statuses_f() function an undefined cursor GET variable.
2599 public function testApiStatusesFWithUndefinedCursor()
2601 $_GET['cursor'] = 'undefined';
2602 $this->assertFalse(api_statuses_f('friends'));
2606 * Test the api_statuses_friends() function.
2609 public function testApiStatusesFriends()
2611 $result = api_statuses_friends('json');
2612 $this->assertArrayHasKey('user', $result);
2616 * Test the api_statuses_friends() function an undefined cursor GET variable.
2619 public function testApiStatusesFriendsWithUndefinedCursor()
2621 $_GET['cursor'] = 'undefined';
2622 $this->assertFalse(api_statuses_friends('json'));
2626 * Test the api_statuses_followers() function.
2629 public function testApiStatusesFollowers()
2631 $result = api_statuses_followers('json');
2632 $this->assertArrayHasKey('user', $result);
2636 * Test the api_statuses_followers() function an undefined cursor GET variable.
2639 public function testApiStatusesFollowersWithUndefinedCursor()
2641 $_GET['cursor'] = 'undefined';
2642 $this->assertFalse(api_statuses_followers('json'));
2646 * Test the api_blocks_list() function.
2649 public function testApiBlocksList()
2651 $result = api_blocks_list('json');
2652 $this->assertArrayHasKey('user', $result);
2656 * Test the api_blocks_list() function an undefined cursor GET variable.
2659 public function testApiBlocksListWithUndefinedCursor()
2661 $_GET['cursor'] = 'undefined';
2662 $this->assertFalse(api_blocks_list('json'));
2666 * Test the api_friendships_incoming() function.
2669 public function testApiFriendshipsIncoming()
2671 $result = api_friendships_incoming('json');
2672 $this->assertArrayHasKey('id', $result);
2676 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2679 public function testApiFriendshipsIncomingWithUndefinedCursor()
2681 $_GET['cursor'] = 'undefined';
2682 $this->assertFalse(api_friendships_incoming('json'));
2686 * Test the api_statusnet_config() function.
2689 public function testApiStatusnetConfig()
2691 $result = api_statusnet_config('json');
2692 $this->assertEquals('localhost', $result['config']['site']['server']);
2693 $this->assertEquals('default', $result['config']['site']['theme']);
2694 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2695 $this->assertTrue($result['config']['site']['fancy']);
2696 $this->assertEquals('en', $result['config']['site']['language']);
2697 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2698 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2699 $this->assertEquals('false', $result['config']['site']['private']);
2700 $this->assertEquals('false', $result['config']['site']['ssl']);
2701 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2705 * Test the api_statusnet_version() function.
2708 public function testApiStatusnetVersion()
2710 $result = api_statusnet_version('json');
2711 $this->assertEquals('0.9.7', $result['version']);
2715 * Test the api_ff_ids() function.
2718 public function testApiFfIds()
2720 $result = api_ff_ids('json');
2721 $this->assertNull($result);
2725 * Test the api_ff_ids() function with a result.
2728 public function testApiFfIdsWithResult()
2730 $this->markTestIncomplete();
2734 * Test the api_ff_ids() function without an authenticated user.
2736 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2738 public function testApiFfIdsWithoutAuthenticatedUser()
2740 $_SESSION['authenticated'] = false;
2745 * Test the api_friends_ids() function.
2748 public function testApiFriendsIds()
2750 $result = api_friends_ids('json');
2751 $this->assertNull($result);
2755 * Test the api_followers_ids() function.
2758 public function testApiFollowersIds()
2760 $result = api_followers_ids('json');
2761 $this->assertNull($result);
2765 * Test the api_direct_messages_new() function.
2768 public function testApiDirectMessagesNew()
2770 $result = api_direct_messages_new('json');
2771 $this->assertNull($result);
2775 * Test the api_direct_messages_new() function without an authenticated user.
2777 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2779 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2781 $_SESSION['authenticated'] = false;
2782 api_direct_messages_new('json');
2786 * Test the api_direct_messages_new() function with an user ID.
2789 public function testApiDirectMessagesNewWithUserId()
2791 $_POST['text'] = 'message_text';
2792 $_POST['user_id'] = $this->otherUser['id'];
2793 $result = api_direct_messages_new('json');
2794 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2798 * Test the api_direct_messages_new() function with a screen name.
2801 public function testApiDirectMessagesNewWithScreenName()
2803 $_POST['text'] = 'message_text';
2804 $_POST['screen_name'] = $this->friendUser['nick'];
2805 $result = api_direct_messages_new('json');
2806 $this->assertEquals(1, $result['direct_message']['id']);
2807 $this->assertContains('message_text', $result['direct_message']['text']);
2808 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2809 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2813 * Test the api_direct_messages_new() function with a title.
2816 public function testApiDirectMessagesNewWithTitle()
2818 $_POST['text'] = 'message_text';
2819 $_POST['screen_name'] = $this->friendUser['nick'];
2820 $_REQUEST['title'] = 'message_title';
2821 $result = api_direct_messages_new('json');
2822 $this->assertEquals(1, $result['direct_message']['id']);
2823 $this->assertContains('message_text', $result['direct_message']['text']);
2824 $this->assertContains('message_title', $result['direct_message']['text']);
2825 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2826 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2830 * Test the api_direct_messages_new() function with an RSS result.
2833 public function testApiDirectMessagesNewWithRss()
2835 $_POST['text'] = 'message_text';
2836 $_POST['screen_name'] = $this->friendUser['nick'];
2837 $result = api_direct_messages_new('rss');
2838 $this->assertXml($result, 'direct-messages');
2842 * Test the api_direct_messages_destroy() function.
2844 * @expectedException Friendica\Network\HTTPException\BadRequestException
2846 public function testApiDirectMessagesDestroy()
2848 api_direct_messages_destroy('json');
2852 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2855 public function testApiDirectMessagesDestroyWithVerbose()
2857 $_GET['friendica_verbose'] = 'true';
2858 $result = api_direct_messages_destroy('json');
2859 $this->assertEquals(
2862 'result' => 'error',
2863 'message' => 'message id or parenturi not specified'
2871 * Test the api_direct_messages_destroy() function without an authenticated user.
2873 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2875 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2877 $_SESSION['authenticated'] = false;
2878 api_direct_messages_destroy('json');
2882 * Test the api_direct_messages_destroy() function with a non-zero ID.
2884 * @expectedException Friendica\Network\HTTPException\BadRequestException
2886 public function testApiDirectMessagesDestroyWithId()
2888 $_REQUEST['id'] = 1;
2889 api_direct_messages_destroy('json');
2893 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2896 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2898 $_REQUEST['id'] = 1;
2899 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2900 $_GET['friendica_verbose'] = 'true';
2901 $result = api_direct_messages_destroy('json');
2902 $this->assertEquals(
2905 'result' => 'error',
2906 'message' => 'message id not in database'
2914 * Test the api_direct_messages_destroy() function with a non-zero ID.
2917 public function testApiDirectMessagesDestroyWithCorrectId()
2919 $this->markTestIncomplete('We need to add a dataset for this.');
2923 * Test the api_direct_messages_box() function.
2926 public function testApiDirectMessagesBoxWithSentbox()
2928 $_REQUEST['page'] = -1;
2929 $_REQUEST['max_id'] = 10;
2930 $result = api_direct_messages_box('json', 'sentbox', 'false');
2931 $this->assertArrayHasKey('direct_message', $result);
2935 * Test the api_direct_messages_box() function.
2938 public function testApiDirectMessagesBoxWithConversation()
2940 $result = api_direct_messages_box('json', 'conversation', 'false');
2941 $this->assertArrayHasKey('direct_message', $result);
2945 * Test the api_direct_messages_box() function.
2948 public function testApiDirectMessagesBoxWithAll()
2950 $result = api_direct_messages_box('json', 'all', 'false');
2951 $this->assertArrayHasKey('direct_message', $result);
2955 * Test the api_direct_messages_box() function.
2958 public function testApiDirectMessagesBoxWithInbox()
2960 $result = api_direct_messages_box('json', 'inbox', 'false');
2961 $this->assertArrayHasKey('direct_message', $result);
2965 * Test the api_direct_messages_box() function.
2968 public function testApiDirectMessagesBoxWithVerbose()
2970 $result = api_direct_messages_box('json', 'sentbox', 'true');
2971 $this->assertEquals(
2974 'result' => 'error',
2975 'message' => 'no mails available'
2983 * Test the api_direct_messages_box() function with a RSS result.
2986 public function testApiDirectMessagesBoxWithRss()
2988 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2989 $this->assertXml($result, 'direct-messages');
2993 * Test the api_direct_messages_box() function without an authenticated user.
2995 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2997 public function testApiDirectMessagesBoxWithUnallowedUser()
2999 $_SESSION['allow_api'] = false;
3000 $_GET['screen_name'] = $this->selfUser['nick'];
3001 api_direct_messages_box('json', 'sentbox', 'false');
3005 * Test the api_direct_messages_sentbox() function.
3008 public function testApiDirectMessagesSentbox()
3010 $result = api_direct_messages_sentbox('json');
3011 $this->assertArrayHasKey('direct_message', $result);
3015 * Test the api_direct_messages_inbox() function.
3018 public function testApiDirectMessagesInbox()
3020 $result = api_direct_messages_inbox('json');
3021 $this->assertArrayHasKey('direct_message', $result);
3025 * Test the api_direct_messages_all() function.
3028 public function testApiDirectMessagesAll()
3030 $result = api_direct_messages_all('json');
3031 $this->assertArrayHasKey('direct_message', $result);
3035 * Test the api_direct_messages_conversation() function.
3038 public function testApiDirectMessagesConversation()
3040 $result = api_direct_messages_conversation('json');
3041 $this->assertArrayHasKey('direct_message', $result);
3045 * Test the api_oauth_request_token() function.
3048 public function testApiOauthRequestToken()
3050 $this->markTestIncomplete('killme() kills phpunit as well');
3054 * Test the api_oauth_access_token() function.
3057 public function testApiOauthAccessToken()
3059 $this->markTestIncomplete('killme() kills phpunit as well');
3063 * Test the api_fr_photoalbum_delete() function.
3065 * @expectedException Friendica\Network\HTTPException\BadRequestException
3067 public function testApiFrPhotoalbumDelete()
3069 api_fr_photoalbum_delete('json');
3073 * Test the api_fr_photoalbum_delete() function with an album name.
3075 * @expectedException Friendica\Network\HTTPException\BadRequestException
3077 public function testApiFrPhotoalbumDeleteWithAlbum()
3079 $_REQUEST['album'] = 'album_name';
3080 api_fr_photoalbum_delete('json');
3084 * Test the api_fr_photoalbum_delete() function with an album name.
3087 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3089 $this->markTestIncomplete('We need to add a dataset for this.');
3093 * Test the api_fr_photoalbum_delete() function.
3095 * @expectedException Friendica\Network\HTTPException\BadRequestException
3097 public function testApiFrPhotoalbumUpdate()
3099 api_fr_photoalbum_update('json');
3103 * Test the api_fr_photoalbum_delete() function with an album name.
3105 * @expectedException Friendica\Network\HTTPException\BadRequestException
3107 public function testApiFrPhotoalbumUpdateWithAlbum()
3109 $_REQUEST['album'] = 'album_name';
3110 api_fr_photoalbum_update('json');
3114 * Test the api_fr_photoalbum_delete() function with an album name.
3116 * @expectedException Friendica\Network\HTTPException\BadRequestException
3118 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3120 $_REQUEST['album'] = 'album_name';
3121 $_REQUEST['album_new'] = 'album_name';
3122 api_fr_photoalbum_update('json');
3126 * Test the api_fr_photoalbum_update() function without an authenticated user.
3128 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3130 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3132 $_SESSION['authenticated'] = false;
3133 api_fr_photoalbum_update('json');
3137 * Test the api_fr_photoalbum_delete() function with an album name.
3140 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3142 $this->markTestIncomplete('We need to add a dataset for this.');
3146 * Test the api_fr_photos_list() function.
3149 public function testApiFrPhotosList()
3151 $result = api_fr_photos_list('json');
3152 $this->assertArrayHasKey('photo', $result);
3156 * Test the api_fr_photos_list() function without an authenticated user.
3158 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3160 public function testApiFrPhotosListWithoutAuthenticatedUser()
3162 $_SESSION['authenticated'] = false;
3163 api_fr_photos_list('json');
3167 * Test the api_fr_photo_create_update() function.
3169 * @expectedException Friendica\Network\HTTPException\BadRequestException
3171 public function testApiFrPhotoCreateUpdate()
3173 api_fr_photo_create_update('json');
3177 * Test the api_fr_photo_create_update() function without an authenticated user.
3179 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3181 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3183 $_SESSION['authenticated'] = false;
3184 api_fr_photo_create_update('json');
3188 * Test the api_fr_photo_create_update() function with an album name.
3190 * @expectedException Friendica\Network\HTTPException\BadRequestException
3192 public function testApiFrPhotoCreateUpdateWithAlbum()
3194 $_REQUEST['album'] = 'album_name';
3195 api_fr_photo_create_update('json');
3199 * Test the api_fr_photo_create_update() function with the update mode.
3202 public function testApiFrPhotoCreateUpdateWithUpdate()
3204 $this->markTestIncomplete('We need to create a dataset for this');
3208 * Test the api_fr_photo_create_update() function with an uploaded file.
3211 public function testApiFrPhotoCreateUpdateWithFile()
3213 $this->markTestIncomplete();
3217 * Test the api_fr_photo_delete() function.
3219 * @expectedException Friendica\Network\HTTPException\BadRequestException
3221 public function testApiFrPhotoDelete()
3223 api_fr_photo_delete('json');
3227 * Test the api_fr_photo_delete() function without an authenticated user.
3229 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3231 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3233 $_SESSION['authenticated'] = false;
3234 api_fr_photo_delete('json');
3238 * Test the api_fr_photo_delete() function with a photo ID.
3240 * @expectedException Friendica\Network\HTTPException\BadRequestException
3242 public function testApiFrPhotoDeleteWithPhotoId()
3244 $_REQUEST['photo_id'] = 1;
3245 api_fr_photo_delete('json');
3249 * Test the api_fr_photo_delete() function with a correct photo ID.
3252 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3254 $this->markTestIncomplete('We need to create a dataset for this.');
3258 * Test the api_fr_photo_detail() function.
3260 * @expectedException Friendica\Network\HTTPException\BadRequestException
3262 public function testApiFrPhotoDetail()
3264 api_fr_photo_detail('json');
3268 * Test the api_fr_photo_detail() function without an authenticated user.
3270 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3272 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3274 $_SESSION['authenticated'] = false;
3275 api_fr_photo_detail('json');
3279 * Test the api_fr_photo_detail() function with a photo ID.
3281 * @expectedException Friendica\Network\HTTPException\NotFoundException
3283 public function testApiFrPhotoDetailWithPhotoId()
3285 $_REQUEST['photo_id'] = 1;
3286 api_fr_photo_detail('json');
3290 * Test the api_fr_photo_detail() function with a correct photo ID.
3293 public function testApiFrPhotoDetailCorrectPhotoId()
3295 $this->markTestIncomplete('We need to create a dataset for this.');
3299 * Test the api_account_update_profile_image() function.
3301 * @expectedException Friendica\Network\HTTPException\BadRequestException
3303 public function testApiAccountUpdateProfileImage()
3305 api_account_update_profile_image('json');
3309 * Test the api_account_update_profile_image() function without an authenticated user.
3311 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3313 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3315 $_SESSION['authenticated'] = false;
3316 api_account_update_profile_image('json');
3320 * Test the api_account_update_profile_image() function with an uploaded file.
3322 * @expectedException Friendica\Network\HTTPException\BadRequestException
3324 public function testApiAccountUpdateProfileImageWithUpload()
3326 $this->markTestIncomplete();
3331 * Test the api_account_update_profile() function.
3334 public function testApiAccountUpdateProfile()
3336 $_POST['name'] = 'new_name';
3337 $_POST['description'] = 'new_description';
3338 $result = api_account_update_profile('json');
3339 // We can't use assertSelfUser() here because the user object is missing some properties.
3340 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3341 $this->assertEquals('DFRN', $result['user']['location']);
3342 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3343 $this->assertEquals('dfrn', $result['user']['network']);
3344 $this->assertEquals('new_name', $result['user']['name']);
3345 $this->assertEquals('new_description', $result['user']['description']);
3349 * Test the check_acl_input() function.
3352 public function testCheckAclInput()
3354 $result = check_acl_input('<aclstring>');
3355 // Where does this result come from?
3356 $this->assertEquals(1, $result);
3360 * Test the check_acl_input() function with an empty ACL string.
3363 public function testCheckAclInputWithEmptyAclString()
3365 $result = check_acl_input(' ');
3366 $this->assertFalse($result);
3370 * Test the save_media_to_database() function.
3373 public function testSaveMediaToDatabase()
3375 $this->markTestIncomplete();
3379 * Test the post_photo_item() function.
3382 public function testPostPhotoItem()
3384 $this->markTestIncomplete();
3388 * Test the prepare_photo_data() function.
3391 public function testPreparePhotoData()
3393 $this->markTestIncomplete();
3397 * Test the api_friendica_remoteauth() function.
3399 * @expectedException Friendica\Network\HTTPException\BadRequestException
3401 public function testApiFriendicaRemoteauth()
3403 api_friendica_remoteauth();
3407 * Test the api_friendica_remoteauth() function with an URL.
3409 * @expectedException Friendica\Network\HTTPException\BadRequestException
3411 public function testApiFriendicaRemoteauthWithUrl()
3413 $_GET['url'] = 'url';
3414 $_GET['c_url'] = 'url';
3415 api_friendica_remoteauth();
3419 * Test the api_friendica_remoteauth() function with a correct URL.
3422 public function testApiFriendicaRemoteauthWithCorrectUrl()
3424 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3425 $_GET['url'] = 'url';
3426 $_GET['c_url'] = $this->selfUser['nurl'];
3427 api_friendica_remoteauth();
3431 * Test the api_share_as_retweet() function.
3434 public function testApiShareAsRetweet()
3436 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3437 $result = api_share_as_retweet($item);
3438 $this->assertFalse($result);
3442 * Test the api_share_as_retweet() function with a valid item.
3445 public function testApiShareAsRetweetWithValidItem()
3447 $this->markTestIncomplete();
3451 * Test the api_get_nick() function.
3454 public function testApiGetNick()
3456 $result = api_get_nick($this->otherUser['nurl']);
3457 $this->assertEquals('othercontact', $result);
3461 * Test the api_get_nick() function with a wrong URL.
3464 public function testApiGetNickWithWrongUrl()
3466 $result = api_get_nick('wrong_url');
3467 $this->assertFalse($result);
3471 * Test the api_in_reply_to() function.
3474 public function testApiInReplyTo()
3476 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3477 $this->assertArrayHasKey('status_id', $result);
3478 $this->assertArrayHasKey('user_id', $result);
3479 $this->assertArrayHasKey('status_id_str', $result);
3480 $this->assertArrayHasKey('user_id_str', $result);
3481 $this->assertArrayHasKey('screen_name', $result);
3485 * Test the api_in_reply_to() function with a valid item.
3488 public function testApiInReplyToWithValidItem()
3490 $this->markTestIncomplete();
3494 * Test the api_clean_plain_items() function.
3497 public function testApiCleanPlainItems()
3499 $_REQUEST['include_entities'] = 'true';
3500 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3501 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3505 * Test the api_clean_attachments() function.
3508 public function testApiCleanAttachments()
3510 $this->markTestIncomplete();
3514 * Test the api_best_nickname() function.
3517 public function testApiBestNickname()
3520 $result = api_best_nickname($contacts);
3521 $this->assertNull($result);
3525 * Test the api_best_nickname() function with contacts.
3528 public function testApiBestNicknameWithContacts()
3530 $this->markTestIncomplete();
3534 * Test the api_friendica_group_show() function.
3537 public function testApiFriendicaGroupShow()
3539 $this->markTestIncomplete();
3543 * Test the api_friendica_group_delete() function.
3546 public function testApiFriendicaGroupDelete()
3548 $this->markTestIncomplete();
3552 * Test the api_lists_destroy() function.
3555 public function testApiListsDestroy()
3557 $this->markTestIncomplete();
3561 * Test the group_create() function.
3564 public function testGroupCreate()
3566 $this->markTestIncomplete();
3570 * Test the api_friendica_group_create() function.
3573 public function testApiFriendicaGroupCreate()
3575 $this->markTestIncomplete();
3579 * Test the api_lists_create() function.
3582 public function testApiListsCreate()
3584 $this->markTestIncomplete();
3588 * Test the api_friendica_group_update() function.
3591 public function testApiFriendicaGroupUpdate()
3593 $this->markTestIncomplete();
3597 * Test the api_lists_update() function.
3600 public function testApiListsUpdate()
3602 $this->markTestIncomplete();
3606 * Test the api_friendica_activity() function.
3609 public function testApiFriendicaActivity()
3611 $this->markTestIncomplete();
3615 * Test the api_friendica_notification() function.
3617 * @expectedException Friendica\Network\HTTPException\BadRequestException
3619 public function testApiFriendicaNotification()
3621 api_friendica_notification('json');
3625 * Test the api_friendica_notification() function without an authenticated user.
3627 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3629 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3631 $_SESSION['authenticated'] = false;
3632 api_friendica_notification('json');
3636 * Test the api_friendica_notification() function with an argument count.
3639 public function testApiFriendicaNotificationWithArgumentCount()
3641 $this->app->argv = ['api', 'friendica', 'notification'];
3642 $this->app->argc = count($this->app->argv);
3643 $result = api_friendica_notification('json');
3644 $this->assertEquals(['note' => false], $result);
3648 * Test the api_friendica_notification() function with an XML result.
3651 public function testApiFriendicaNotificationWithXmlResult()
3653 $this->app->argv = ['api', 'friendica', 'notification'];
3654 $this->app->argc = count($this->app->argv);
3655 $result = api_friendica_notification('xml');
3656 $this->assertXml($result, 'notes');
3660 * Test the api_friendica_notification_seen() function.
3663 public function testApiFriendicaNotificationSeen()
3665 $this->markTestIncomplete();
3669 * Test the api_friendica_direct_messages_setseen() function.
3672 public function testApiFriendicaDirectMessagesSetseen()
3674 $this->markTestIncomplete();
3678 * Test the api_friendica_direct_messages_search() function.
3681 public function testApiFriendicaDirectMessagesSearch()
3683 $this->markTestIncomplete();
3687 * Test the api_friendica_profile_show() function.
3690 public function testApiFriendicaProfileShow()
3692 $result = api_friendica_profile_show('json');
3693 // We can't use assertSelfUser() here because the user object is missing some properties.
3694 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3695 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3696 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3697 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3698 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3699 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3700 $this->assertFalse($result['$result']['multi_profiles']);
3704 * Test the api_friendica_profile_show() function with a profile ID.
3707 public function testApiFriendicaProfileShowWithProfileId()
3709 $this->markTestIncomplete('We need to add a dataset for this.');
3713 * Test the api_friendica_profile_show() function with a wrong profile ID.
3715 * @expectedException Friendica\Network\HTTPException\BadRequestException
3717 public function testApiFriendicaProfileShowWithWrongProfileId()
3719 $_REQUEST['profile_id'] = 666;
3720 api_friendica_profile_show('json');
3724 * Test the api_friendica_profile_show() function without an authenticated user.
3726 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3728 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3730 $_SESSION['authenticated'] = false;
3731 api_friendica_profile_show('json');
3735 * Test the api_saved_searches_list() function.
3738 public function testApiSavedSearchesList()
3740 $result = api_saved_searches_list('json');
3741 $this->assertEquals(1, $result['terms'][0]['id']);
3742 $this->assertEquals(1, $result['terms'][0]['id_str']);
3743 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3744 $this->assertEquals('Saved search', $result['terms'][0]['query']);