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 Friendica\Util\Config\ConfigFileLoader;
17 use Monolog\Handler\TestHandler;
19 require_once __DIR__ . '/../../include/api.php';
22 * Tests for the API functions.
24 * Functions that use header() need to be tested in a separate process.
25 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
27 class ApiTest extends DatabaseTest
30 * @var TestHandler Can handle log-outputs
40 protected $friendUser;
44 protected $wrongUserId;
47 * Create variables used by tests.
49 public function setUp()
51 $basePath = BasePath::create(dirname(__DIR__) . '/../');
52 $mode = new App\Mode($basePath);
53 $configLoader = new ConfigFileLoader($basePath, $mode);
54 $configCache = Factory\ConfigFactory::createCache($configLoader);
55 $profiler = Factory\ProfilerFactory::create($configCache);
56 Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
57 $config = Factory\ConfigFactory::createConfig($configCache);
58 Factory\ConfigFactory::createPConfig($configCache);
59 $logger = Factory\LoggerFactory::create('test', $config, $profiler);
60 $this->app = new App($config, $mode, $logger, $profiler, false);
64 // User data that the test database is populated with
67 'name' => 'Self contact',
68 'nick' => 'selfcontact',
69 'nurl' => 'http://localhost/profile/selfcontact'
73 'name' => 'Friend contact',
74 'nick' => 'friendcontact',
75 'nurl' => 'http://localhost/profile/friendcontact'
79 'name' => 'othercontact',
80 'nick' => 'othercontact',
81 'nurl' => 'http://localhost/profile/othercontact'
84 // User ID that we know is not in the database
85 $this->wrongUserId = 666;
87 // Most API require login so we force the session
90 'authenticated' => true,
91 'uid' => $this->selfUser['id']
94 Config::set('system', 'url', 'http://localhost');
95 Config::set('system', 'hostname', 'localhost');
96 Config::set('system', 'worker_dont_fork', true);
99 Config::set('config', 'hostname', 'localhost');
100 Config::set('system', 'throttle_limit_day', 100);
101 Config::set('system', 'throttle_limit_week', 100);
102 Config::set('system', 'throttle_limit_month', 100);
103 Config::set('system', 'theme', 'system_theme');
107 * Cleanup variables used by tests.
109 protected function tearDown()
113 $this->app->argc = 1;
114 $this->app->argv = ['home'];
118 * Assert that an user array contains expected keys.
119 * @param array $user User array
122 private function assertSelfUser(array $user)
124 $this->assertEquals($this->selfUser['id'], $user['uid']);
125 $this->assertEquals($this->selfUser['id'], $user['cid']);
126 $this->assertEquals(1, $user['self']);
127 $this->assertEquals('DFRN', $user['location']);
128 $this->assertEquals($this->selfUser['name'], $user['name']);
129 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
130 $this->assertEquals('dfrn', $user['network']);
131 $this->assertTrue($user['verified']);
135 * Assert that an user array contains expected keys.
136 * @param array $user User array
139 private function assertOtherUser(array $user)
141 $this->assertEquals($this->otherUser['id'], $user['id']);
142 $this->assertEquals($this->otherUser['id'], $user['id_str']);
143 $this->assertEquals(0, $user['self']);
144 $this->assertEquals($this->otherUser['name'], $user['name']);
145 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
146 $this->assertFalse($user['verified']);
150 * Assert that a status array contains expected keys.
151 * @param array $status Status array
154 private function assertStatus(array $status)
156 $this->assertInternalType('string', $status['text']);
157 $this->assertInternalType('int', $status['id']);
158 // We could probably do more checks here.
162 * Assert that a list array contains expected keys.
163 * @param array $list List array
166 private function assertList(array $list)
168 $this->assertInternalType('string', $list['name']);
169 $this->assertInternalType('int', $list['id']);
170 $this->assertInternalType('string', $list['id_str']);
171 $this->assertContains($list['mode'], ['public', 'private']);
172 // We could probably do more checks here.
176 * Assert that the string is XML and contain the root element.
177 * @param string $result XML string
178 * @param string $root_element Root element name
181 private function assertXml($result, $root_element)
183 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
184 $this->assertContains('<'.$root_element, $result);
185 // We could probably do more checks here.
189 * Get the path to a temporary empty PNG image.
190 * @return string Path
192 private function getTempImage()
194 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
198 // Empty 1x1 px PNG image
199 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
207 * Test the api_user() function.
210 public function testApiUser()
212 $this->assertEquals($this->selfUser['id'], api_user());
216 * Test the api_user() function with an unallowed user.
219 public function testApiUserWithUnallowedUser()
221 $_SESSION = ['allow_api' => false];
222 $this->assertEquals(false, api_user());
226 * Test the api_source() function.
229 public function testApiSource()
231 $this->assertEquals('api', api_source());
235 * Test the api_source() function with a Twidere user agent.
238 public function testApiSourceWithTwidere()
240 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
241 $this->assertEquals('Twidere', api_source());
245 * Test the api_source() function with a GET parameter.
248 public function testApiSourceWithGet()
250 $_GET['source'] = 'source_name';
251 $this->assertEquals('source_name', api_source());
255 * Test the api_date() function.
258 public function testApiDate()
260 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
264 * Test the api_register_func() function.
267 public function testApiRegisterFunc()
279 $this->assertTrue($API['api_path']['auth']);
280 $this->assertEquals('method', $API['api_path']['method']);
281 $this->assertTrue(is_callable($API['api_path']['func']));
285 * Test the api_login() function without any login.
287 * @runInSeparateProcess
288 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
290 public function testApiLoginWithoutLogin()
292 api_login($this->app);
296 * Test the api_login() function with a bad login.
298 * @runInSeparateProcess
299 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
301 public function testApiLoginWithBadLogin()
303 $_SERVER['PHP_AUTH_USER'] = 'user@server';
304 api_login($this->app);
308 * Test the api_login() function with oAuth.
311 public function testApiLoginWithOauth()
313 $this->markTestIncomplete('Can we test this easily?');
317 * Test the api_login() function with authentication provided by an addon.
320 public function testApiLoginWithAddonAuth()
322 $this->markTestIncomplete('Can we test this easily?');
326 * Test the api_login() function with a correct login.
328 * @runInSeparateProcess
330 public function testApiLoginWithCorrectLogin()
332 $_SERVER['PHP_AUTH_USER'] = 'Test user';
333 $_SERVER['PHP_AUTH_PW'] = 'password';
334 api_login($this->app);
338 * Test the api_login() function with a remote user.
340 * @runInSeparateProcess
341 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
343 public function testApiLoginWithRemoteUser()
345 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
346 api_login($this->app);
350 * Test the api_check_method() function.
353 public function testApiCheckMethod()
355 $this->assertFalse(api_check_method('method'));
359 * Test the api_check_method() function with a correct method.
362 public function testApiCheckMethodWithCorrectMethod()
364 $_SERVER['REQUEST_METHOD'] = 'method';
365 $this->assertTrue(api_check_method('method'));
369 * Test the api_check_method() function with a wildcard.
372 public function testApiCheckMethodWithWildcard()
374 $this->assertTrue(api_check_method('*'));
378 * Test the api_call() function.
380 * @runInSeparateProcess
382 public function testApiCall()
386 'method' => 'method',
387 'func' => function () {
388 return ['data' => ['some_data']];
391 $_SERVER['REQUEST_METHOD'] = 'method';
392 $_GET['callback'] = 'callback_name';
394 $this->app->query_string = 'api_path';
396 'callback_name(["some_data"])',
402 * Test the api_call() function with the profiled enabled.
404 * @runInSeparateProcess
406 public function testApiCallWithProfiler()
410 'method' => 'method',
411 'func' => function () {
412 return ['data' => ['some_data']];
415 $_SERVER['REQUEST_METHOD'] = 'method';
416 Config::set('system', 'profiler', true);
417 Config::set('rendertime', 'callstack', true);
418 $this->app->callstack = [
419 'database' => ['some_function' => 200],
420 'database_write' => ['some_function' => 200],
421 'cache' => ['some_function' => 200],
422 'cache_write' => ['some_function' => 200],
423 'network' => ['some_function' => 200]
426 $this->app->query_string = 'api_path';
434 * Test the api_call() function without any result.
436 * @runInSeparateProcess
438 public function testApiCallWithNoResult()
442 'method' => 'method',
443 'func' => function () {
447 $_SERVER['REQUEST_METHOD'] = 'method';
449 $this->app->query_string = 'api_path';
451 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
457 * Test the api_call() function with an unimplemented API.
459 * @runInSeparateProcess
461 public function testApiCallWithUninplementedApi()
464 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
470 * Test the api_call() function with a JSON result.
472 * @runInSeparateProcess
474 public function testApiCallWithJson()
478 'method' => 'method',
479 'func' => function () {
480 return ['data' => ['some_data']];
483 $_SERVER['REQUEST_METHOD'] = 'method';
485 $this->app->query_string = 'api_path.json';
493 * Test the api_call() function with an XML result.
495 * @runInSeparateProcess
497 public function testApiCallWithXml()
501 'method' => 'method',
502 'func' => function () {
506 $_SERVER['REQUEST_METHOD'] = 'method';
508 $this->app->query_string = 'api_path.xml';
516 * Test the api_call() function with an RSS result.
518 * @runInSeparateProcess
520 public function testApiCallWithRss()
524 'method' => 'method',
525 'func' => function () {
529 $_SERVER['REQUEST_METHOD'] = 'method';
531 $this->app->query_string = 'api_path.rss';
533 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
540 * Test the api_call() function with an Atom result.
542 * @runInSeparateProcess
544 public function testApiCallWithAtom()
548 'method' => 'method',
549 'func' => function () {
553 $_SERVER['REQUEST_METHOD'] = 'method';
555 $this->app->query_string = 'api_path.atom';
557 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
564 * Test the api_call() function with an unallowed method.
566 * @runInSeparateProcess
568 public function testApiCallWithWrongMethod()
571 $API['api_path'] = ['method' => 'method'];
573 $this->app->query_string = 'api_path';
575 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
581 * Test the api_call() function with an unauthorized user.
583 * @runInSeparateProcess
585 public function testApiCallWithWrongAuth()
589 'method' => 'method',
592 $_SERVER['REQUEST_METHOD'] = 'method';
593 $_SESSION['authenticated'] = false;
595 $this->app->query_string = 'api_path';
597 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
603 * Test the api_error() function with a JSON result.
605 * @runInSeparateProcess
607 public function testApiErrorWithJson()
610 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
611 api_error('json', new HTTPException('error_message'))
616 * Test the api_error() function with an XML result.
618 * @runInSeparateProcess
620 public function testApiErrorWithXml()
623 '<?xml version="1.0"?>'."\n".
624 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
625 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
626 'xmlns:georss="http://www.georss.org/georss">'."\n".
627 ' <error>error_message</error>'."\n".
628 ' <code>200 Friendica\Network\HTTP</code>'."\n".
631 api_error('xml', new HTTPException('error_message'))
636 * Test the api_error() function with an RSS result.
638 * @runInSeparateProcess
640 public function testApiErrorWithRss()
643 '<?xml version="1.0"?>'."\n".
644 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
645 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
646 'xmlns:georss="http://www.georss.org/georss">'."\n".
647 ' <error>error_message</error>'."\n".
648 ' <code>200 Friendica\Network\HTTP</code>'."\n".
651 api_error('rss', new HTTPException('error_message'))
656 * Test the api_error() function with an Atom result.
658 * @runInSeparateProcess
660 public function testApiErrorWithAtom()
663 '<?xml version="1.0"?>'."\n".
664 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
665 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
666 'xmlns:georss="http://www.georss.org/georss">'."\n".
667 ' <error>error_message</error>'."\n".
668 ' <code>200 Friendica\Network\HTTP</code>'."\n".
671 api_error('atom', new HTTPException('error_message'))
676 * Test the api_rss_extra() function.
679 public function testApiRssExtra()
681 $user_info = ['url' => 'user_url', 'lang' => 'en'];
682 $result = api_rss_extra($this->app, [], $user_info);
683 $this->assertEquals($user_info, $result['$user']);
684 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
685 $this->assertArrayHasKey('self', $result['$rss']);
686 $this->assertArrayHasKey('base', $result['$rss']);
687 $this->assertArrayHasKey('updated', $result['$rss']);
688 $this->assertArrayHasKey('atom_updated', $result['$rss']);
689 $this->assertArrayHasKey('language', $result['$rss']);
690 $this->assertArrayHasKey('logo', $result['$rss']);
694 * Test the api_rss_extra() function without any user info.
696 * @runInSeparateProcess
698 public function testApiRssExtraWithoutUserInfo()
700 $result = api_rss_extra($this->app, [], null);
701 $this->assertInternalType('array', $result['$user']);
702 $this->assertArrayHasKey('alternate', $result['$rss']);
703 $this->assertArrayHasKey('self', $result['$rss']);
704 $this->assertArrayHasKey('base', $result['$rss']);
705 $this->assertArrayHasKey('updated', $result['$rss']);
706 $this->assertArrayHasKey('atom_updated', $result['$rss']);
707 $this->assertArrayHasKey('language', $result['$rss']);
708 $this->assertArrayHasKey('logo', $result['$rss']);
712 * Test the api_unique_id_to_nurl() function.
715 public function testApiUniqueIdToNurl()
717 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
721 * Test the api_unique_id_to_nurl() function with a correct ID.
724 public function testApiUniqueIdToNurlWithCorrectId()
726 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
730 * Test the api_get_user() function.
732 * @runInSeparateProcess
734 public function testApiGetUser()
736 $user = api_get_user($this->app);
737 $this->assertSelfUser($user);
738 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
739 $this->assertEquals('6fdbe8', $user['profile_link_color']);
740 $this->assertEquals('ededed', $user['profile_background_color']);
744 * Test the api_get_user() function with a Frio schema.
746 * @runInSeparateProcess
748 public function testApiGetUserWithFrioSchema()
750 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
751 $user = api_get_user($this->app);
752 $this->assertSelfUser($user);
753 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
754 $this->assertEquals('6fdbe8', $user['profile_link_color']);
755 $this->assertEquals('ededed', $user['profile_background_color']);
759 * Test the api_get_user() function with a custom Frio schema.
761 * @runInSeparateProcess
763 public function testApiGetUserWithCustomFrioSchema()
765 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
766 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
767 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
768 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
769 $user = api_get_user($this->app);
770 $this->assertSelfUser($user);
771 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
772 $this->assertEquals('123456', $user['profile_link_color']);
773 $this->assertEquals('123456', $user['profile_background_color']);
777 * Test the api_get_user() function with an empty Frio schema.
779 * @runInSeparateProcess
781 public function testApiGetUserWithEmptyFrioSchema()
783 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
784 $user = api_get_user($this->app);
785 $this->assertSelfUser($user);
786 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
787 $this->assertEquals('6fdbe8', $user['profile_link_color']);
788 $this->assertEquals('ededed', $user['profile_background_color']);
792 * Test the api_get_user() function with an user that is not allowed to use the API.
794 * @runInSeparateProcess
796 public function testApiGetUserWithoutApiUser()
798 $_SERVER['PHP_AUTH_USER'] = 'Test user';
799 $_SERVER['PHP_AUTH_PW'] = 'password';
800 $_SESSION['allow_api'] = false;
801 $this->assertFalse(api_get_user($this->app));
805 * Test the api_get_user() function with an user ID in a GET parameter.
807 * @runInSeparateProcess
809 public function testApiGetUserWithGetId()
811 $_GET['user_id'] = $this->otherUser['id'];
812 $this->assertOtherUser(api_get_user($this->app));
816 * Test the api_get_user() function with a wrong user ID in a GET parameter.
818 * @runInSeparateProcess
819 * @expectedException Friendica\Network\HTTPException\BadRequestException
821 public function testApiGetUserWithWrongGetId()
823 $_GET['user_id'] = $this->wrongUserId;
824 $this->assertOtherUser(api_get_user($this->app));
828 * Test the api_get_user() function with an user name in a GET parameter.
830 * @runInSeparateProcess
832 public function testApiGetUserWithGetName()
834 $_GET['screen_name'] = $this->selfUser['nick'];
835 $this->assertSelfUser(api_get_user($this->app));
839 * Test the api_get_user() function with a profile URL in a GET parameter.
841 * @runInSeparateProcess
843 public function testApiGetUserWithGetUrl()
845 $_GET['profileurl'] = $this->selfUser['nurl'];
846 $this->assertSelfUser(api_get_user($this->app));
850 * Test the api_get_user() function with an user ID in the API path.
852 * @runInSeparateProcess
854 public function testApiGetUserWithNumericCalledApi()
857 $called_api = ['api_path'];
858 $this->app->argv[1] = $this->otherUser['id'].'.json';
859 $this->assertOtherUser(api_get_user($this->app));
863 * Test the api_get_user() function with the $called_api global variable.
865 * @runInSeparateProcess
867 public function testApiGetUserWithCalledApi()
870 $called_api = ['api', 'api_path'];
871 $this->assertSelfUser(api_get_user($this->app));
875 * Test the api_get_user() function with a valid user.
877 * @runInSeparateProcess
879 public function testApiGetUserWithCorrectUser()
881 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
885 * Test the api_get_user() function with a wrong user ID.
887 * @runInSeparateProcess
888 * @expectedException Friendica\Network\HTTPException\BadRequestException
890 public function testApiGetUserWithWrongUser()
892 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
896 * Test the api_get_user() function with a 0 user ID.
898 * @runInSeparateProcess
900 public function testApiGetUserWithZeroUser()
902 $this->assertSelfUser(api_get_user($this->app, 0));
906 * Test the api_item_get_user() function.
908 * @runInSeparateProcess
910 public function testApiItemGetUser()
912 $users = api_item_get_user($this->app, []);
913 $this->assertSelfUser($users[0]);
917 * Test the api_item_get_user() function with a different item parent.
920 public function testApiItemGetUserWithDifferentParent()
922 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
923 $this->assertSelfUser($users[0]);
924 $this->assertEquals($users[0], $users[1]);
928 * Test the api_walk_recursive() function.
931 public function testApiWalkRecursive()
939 // Should we test this with a callback that actually does something?
947 * Test the api_walk_recursive() function with an array.
950 public function testApiWalkRecursiveWithArray()
952 $array = [['item1'], ['item2']];
958 // Should we test this with a callback that actually does something?
966 * Test the api_reformat_xml() function.
969 public function testApiReformatXml()
973 $this->assertTrue(api_reformat_xml($item, $key));
974 $this->assertEquals('true', $item);
978 * Test the api_reformat_xml() function with a statusnet_api key.
981 public function testApiReformatXmlWithStatusnetKey()
984 $key = 'statusnet_api';
985 $this->assertTrue(api_reformat_xml($item, $key));
986 $this->assertEquals('statusnet:api', $key);
990 * Test the api_reformat_xml() function with a friendica_api key.
993 public function testApiReformatXmlWithFriendicaKey()
996 $key = 'friendica_api';
997 $this->assertTrue(api_reformat_xml($item, $key));
998 $this->assertEquals('friendica:api', $key);
1002 * Test the api_create_xml() function.
1005 public function testApiCreateXml()
1007 $this->assertEquals(
1008 '<?xml version="1.0"?>'."\n".
1009 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1010 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1011 'xmlns:georss="http://www.georss.org/georss">'."\n".
1012 ' <data>some_data</data>'."\n".
1013 '</root_element>'."\n",
1014 api_create_xml(['data' => ['some_data']], 'root_element')
1019 * Test the api_create_xml() function without any XML namespace.
1022 public function testApiCreateXmlWithoutNamespaces()
1024 $this->assertEquals(
1025 '<?xml version="1.0"?>'."\n".
1027 ' <data>some_data</data>'."\n".
1029 api_create_xml(['data' => ['some_data']], 'ok')
1034 * Test the api_format_data() function.
1037 public function testApiFormatData()
1039 $data = ['some_data'];
1040 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1044 * Test the api_format_data() function with an XML result.
1047 public function testApiFormatDataWithXml()
1049 $this->assertEquals(
1050 '<?xml version="1.0"?>'."\n".
1051 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1052 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1053 'xmlns:georss="http://www.georss.org/georss">'."\n".
1054 ' <data>some_data</data>'."\n".
1055 '</root_element>'."\n",
1056 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1061 * Test the api_account_verify_credentials() function.
1064 public function testApiAccountVerifyCredentials()
1066 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1070 * Test the api_account_verify_credentials() function without an authenticated user.
1072 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1074 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1076 $_SESSION['authenticated'] = false;
1077 api_account_verify_credentials('json');
1081 * Test the requestdata() function.
1084 public function testRequestdata()
1086 $this->assertNull(requestdata('variable_name'));
1090 * Test the requestdata() function with a POST parameter.
1093 public function testRequestdataWithPost()
1095 $_POST['variable_name'] = 'variable_value';
1096 $this->assertEquals('variable_value', requestdata('variable_name'));
1100 * Test the requestdata() function with a GET parameter.
1103 public function testRequestdataWithGet()
1105 $_GET['variable_name'] = 'variable_value';
1106 $this->assertEquals('variable_value', requestdata('variable_name'));
1110 * Test the api_statuses_mediap() function.
1113 public function testApiStatusesMediap()
1115 $this->app->argc = 2;
1123 'tmp_name' => $this->getTempImage(),
1124 'name' => 'spacer.png',
1125 'type' => 'image/png'
1128 $_GET['status'] = '<b>Status content</b>';
1130 $result = api_statuses_mediap('json');
1131 $this->assertStatus($result['status']);
1135 * Test the api_statuses_mediap() function without an authenticated user.
1137 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1139 public function testApiStatusesMediapWithoutAuthenticatedUser()
1141 $_SESSION['authenticated'] = false;
1142 api_statuses_mediap('json');
1146 * Test the api_statuses_update() function.
1149 public function testApiStatusesUpdate()
1151 $_GET['status'] = 'Status content #friendica';
1152 $_GET['in_reply_to_status_id'] = -1;
1161 'tmp_name' => $this->getTempImage(),
1162 'name' => 'spacer.png',
1163 'type' => 'image/png'
1167 $result = api_statuses_update('json');
1168 $this->assertStatus($result['status']);
1172 * Test the api_statuses_update() function with an HTML status.
1175 public function testApiStatusesUpdateWithHtml()
1177 $_GET['htmlstatus'] = '<b>Status content</b>';
1179 $result = api_statuses_update('json');
1180 $this->assertStatus($result['status']);
1184 * Test the api_statuses_update() function without an authenticated user.
1186 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1188 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1190 $_SESSION['authenticated'] = false;
1191 api_statuses_update('json');
1195 * Test the api_statuses_update() function with a parent status.
1198 public function testApiStatusesUpdateWithParent()
1200 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1204 * Test the api_statuses_update() function with a media_ids parameter.
1207 public function testApiStatusesUpdateWithMediaIds()
1209 $this->markTestIncomplete();
1213 * Test the api_statuses_update() function with the throttle limit reached.
1216 public function testApiStatusesUpdateWithDayThrottleReached()
1218 $this->markTestIncomplete();
1222 * Test the api_media_upload() function.
1224 * @expectedException Friendica\Network\HTTPException\BadRequestException
1226 public function testApiMediaUpload()
1232 * Test the api_media_upload() function without an authenticated user.
1234 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1236 public function testApiMediaUploadWithoutAuthenticatedUser()
1238 $_SESSION['authenticated'] = false;
1243 * Test the api_media_upload() function with an invalid uploaded media.
1245 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1247 public function testApiMediaUploadWithMedia()
1252 'tmp_name' => 'tmp_name'
1259 * Test the api_media_upload() function with an valid uploaded media.
1262 public function testApiMediaUploadWithValidMedia()
1270 'tmp_name' => $this->getTempImage(),
1271 'name' => 'spacer.png',
1272 'type' => 'image/png'
1278 $result = api_media_upload();
1279 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1280 $this->assertEquals(1, $result['media']['image']['w']);
1281 $this->assertEquals(1, $result['media']['image']['h']);
1282 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1286 * Test the api_status_show() function.
1288 public function testApiStatusShowWithJson()
1290 $result = api_status_show('json', 1);
1291 $this->assertStatus($result['status']);
1295 * Test the api_status_show() function with an XML result.
1297 public function testApiStatusShowWithXml()
1299 $result = api_status_show('xml', 1);
1300 $this->assertXml($result, 'statuses');
1304 * Test the api_get_last_status() function
1306 public function testApiGetLastStatus()
1308 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1310 $this->assertNotNull($item);
1314 * Test the api_users_show() function.
1317 public function testApiUsersShow()
1319 $result = api_users_show('json');
1320 // We can't use assertSelfUser() here because the user object is missing some properties.
1321 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1322 $this->assertEquals('DFRN', $result['user']['location']);
1323 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1324 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1325 $this->assertEquals('dfrn', $result['user']['network']);
1326 $this->assertTrue($result['user']['verified']);
1330 * Test the api_users_show() function with an XML result.
1333 public function testApiUsersShowWithXml()
1335 $result = api_users_show('xml');
1336 $this->assertXml($result, 'statuses');
1340 * Test the api_users_search() function.
1343 public function testApiUsersSearch()
1345 $_GET['q'] = 'othercontact';
1346 $result = api_users_search('json');
1347 $this->assertOtherUser($result['users'][0]);
1351 * Test the api_users_search() function with an XML result.
1354 public function testApiUsersSearchWithXml()
1356 $_GET['q'] = 'othercontact';
1357 $result = api_users_search('xml');
1358 $this->assertXml($result, 'users');
1362 * Test the api_users_search() function without a GET q parameter.
1364 * @expectedException Friendica\Network\HTTPException\BadRequestException
1366 public function testApiUsersSearchWithoutQuery()
1368 api_users_search('json');
1372 * Test the api_users_lookup() function.
1374 * @expectedException Friendica\Network\HTTPException\NotFoundException
1376 public function testApiUsersLookup()
1378 api_users_lookup('json');
1382 * Test the api_users_lookup() function with an user ID.
1385 public function testApiUsersLookupWithUserId()
1387 $_REQUEST['user_id'] = $this->otherUser['id'];
1388 $result = api_users_lookup('json');
1389 $this->assertOtherUser($result['users'][0]);
1393 * Test the api_search() function.
1396 public function testApiSearch()
1398 $_REQUEST['q'] = 'reply';
1399 $_REQUEST['max_id'] = 10;
1400 $result = api_search('json');
1401 foreach ($result['status'] as $status) {
1402 $this->assertStatus($status);
1403 $this->assertContains('reply', $status['text'], null, true);
1408 * Test the api_search() function a count parameter.
1411 public function testApiSearchWithCount()
1413 $_REQUEST['q'] = 'reply';
1414 $_REQUEST['count'] = 20;
1415 $result = api_search('json');
1416 foreach ($result['status'] as $status) {
1417 $this->assertStatus($status);
1418 $this->assertContains('reply', $status['text'], null, true);
1423 * Test the api_search() function with an rpp parameter.
1426 public function testApiSearchWithRpp()
1428 $_REQUEST['q'] = 'reply';
1429 $_REQUEST['rpp'] = 20;
1430 $result = api_search('json');
1431 foreach ($result['status'] as $status) {
1432 $this->assertStatus($status);
1433 $this->assertContains('reply', $status['text'], null, true);
1438 * Test the api_search() function with an q parameter contains hashtag.
1441 public function testApiSearchWithHashtag()
1443 $_REQUEST['q'] = '%23friendica';
1444 $result = api_search('json');
1445 foreach ($result['status'] as $status) {
1446 $this->assertStatus($status);
1447 $this->assertContains('#friendica', $status['text'], null, true);
1452 * Test the api_search() function with an exclude_replies parameter.
1455 public function testApiSearchWithExcludeReplies()
1457 $_REQUEST['max_id'] = 10;
1458 $_REQUEST['exclude_replies'] = true;
1459 $_REQUEST['q'] = 'friendica';
1460 $result = api_search('json');
1461 foreach ($result['status'] as $status) {
1462 $this->assertStatus($status);
1467 * Test the api_search() function without an authenticated user.
1469 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1471 public function testApiSearchWithUnallowedUser()
1473 $_SESSION['allow_api'] = false;
1474 $_GET['screen_name'] = $this->selfUser['nick'];
1479 * Test the api_search() function without any GET query parameter.
1481 * @expectedException Friendica\Network\HTTPException\BadRequestException
1483 public function testApiSearchWithoutQuery()
1489 * Test the api_statuses_home_timeline() function.
1492 public function testApiStatusesHomeTimeline()
1494 $_REQUEST['max_id'] = 10;
1495 $_REQUEST['exclude_replies'] = true;
1496 $_REQUEST['conversation_id'] = 1;
1497 $result = api_statuses_home_timeline('json');
1498 $this->assertNotEmpty($result['status']);
1499 foreach ($result['status'] as $status) {
1500 $this->assertStatus($status);
1505 * Test the api_statuses_home_timeline() function with a negative page parameter.
1508 public function testApiStatusesHomeTimelineWithNegativePage()
1510 $_REQUEST['page'] = -2;
1511 $result = api_statuses_home_timeline('json');
1512 $this->assertNotEmpty($result['status']);
1513 foreach ($result['status'] as $status) {
1514 $this->assertStatus($status);
1519 * Test the api_statuses_home_timeline() with an unallowed user.
1521 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1523 public function testApiStatusesHomeTimelineWithUnallowedUser()
1525 $_SESSION['allow_api'] = false;
1526 $_GET['screen_name'] = $this->selfUser['nick'];
1527 api_statuses_home_timeline('json');
1531 * Test the api_statuses_home_timeline() function with an RSS result.
1534 public function testApiStatusesHomeTimelineWithRss()
1536 $result = api_statuses_home_timeline('rss');
1537 $this->assertXml($result, 'statuses');
1541 * Test the api_statuses_public_timeline() function.
1544 public function testApiStatusesPublicTimeline()
1546 $_REQUEST['max_id'] = 10;
1547 $_REQUEST['conversation_id'] = 1;
1548 $result = api_statuses_public_timeline('json');
1549 $this->assertNotEmpty($result['status']);
1550 foreach ($result['status'] as $status) {
1551 $this->assertStatus($status);
1556 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1559 public function testApiStatusesPublicTimelineWithExcludeReplies()
1561 $_REQUEST['max_id'] = 10;
1562 $_REQUEST['exclude_replies'] = true;
1563 $result = api_statuses_public_timeline('json');
1564 $this->assertNotEmpty($result['status']);
1565 foreach ($result['status'] as $status) {
1566 $this->assertStatus($status);
1571 * Test the api_statuses_public_timeline() function with a negative page parameter.
1574 public function testApiStatusesPublicTimelineWithNegativePage()
1576 $_REQUEST['page'] = -2;
1577 $result = api_statuses_public_timeline('json');
1578 $this->assertNotEmpty($result['status']);
1579 foreach ($result['status'] as $status) {
1580 $this->assertStatus($status);
1585 * Test the api_statuses_public_timeline() function with an unallowed user.
1587 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1589 public function testApiStatusesPublicTimelineWithUnallowedUser()
1591 $_SESSION['allow_api'] = false;
1592 $_GET['screen_name'] = $this->selfUser['nick'];
1593 api_statuses_public_timeline('json');
1597 * Test the api_statuses_public_timeline() function with an RSS result.
1600 public function testApiStatusesPublicTimelineWithRss()
1602 $result = api_statuses_public_timeline('rss');
1603 $this->assertXml($result, 'statuses');
1607 * Test the api_statuses_networkpublic_timeline() function.
1610 public function testApiStatusesNetworkpublicTimeline()
1612 $_REQUEST['max_id'] = 10;
1613 $result = api_statuses_networkpublic_timeline('json');
1614 $this->assertNotEmpty($result['status']);
1615 foreach ($result['status'] as $status) {
1616 $this->assertStatus($status);
1621 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1624 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1626 $_REQUEST['page'] = -2;
1627 $result = api_statuses_networkpublic_timeline('json');
1628 $this->assertNotEmpty($result['status']);
1629 foreach ($result['status'] as $status) {
1630 $this->assertStatus($status);
1635 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1637 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1639 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1641 $_SESSION['allow_api'] = false;
1642 $_GET['screen_name'] = $this->selfUser['nick'];
1643 api_statuses_networkpublic_timeline('json');
1647 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1650 public function testApiStatusesNetworkpublicTimelineWithRss()
1652 $result = api_statuses_networkpublic_timeline('rss');
1653 $this->assertXml($result, 'statuses');
1657 * Test the api_statuses_show() function.
1659 * @expectedException Friendica\Network\HTTPException\BadRequestException
1661 public function testApiStatusesShow()
1663 api_statuses_show('json');
1667 * Test the api_statuses_show() function with an ID.
1670 public function testApiStatusesShowWithId()
1672 $this->app->argv[3] = 1;
1673 $result = api_statuses_show('json');
1674 $this->assertStatus($result['status']);
1678 * Test the api_statuses_show() function with the conversation parameter.
1681 public function testApiStatusesShowWithConversation()
1683 $this->app->argv[3] = 1;
1684 $_REQUEST['conversation'] = 1;
1685 $result = api_statuses_show('json');
1686 $this->assertNotEmpty($result['status']);
1687 foreach ($result['status'] as $status) {
1688 $this->assertStatus($status);
1693 * Test the api_statuses_show() function with an unallowed user.
1695 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1697 public function testApiStatusesShowWithUnallowedUser()
1699 $_SESSION['allow_api'] = false;
1700 $_GET['screen_name'] = $this->selfUser['nick'];
1701 api_statuses_show('json');
1705 * Test the api_conversation_show() function.
1707 * @expectedException Friendica\Network\HTTPException\BadRequestException
1709 public function testApiConversationShow()
1711 api_conversation_show('json');
1715 * Test the api_conversation_show() function with an ID.
1718 public function testApiConversationShowWithId()
1720 $this->app->argv[3] = 1;
1721 $_REQUEST['max_id'] = 10;
1722 $_REQUEST['page'] = -2;
1723 $result = api_conversation_show('json');
1724 $this->assertNotEmpty($result['status']);
1725 foreach ($result['status'] as $status) {
1726 $this->assertStatus($status);
1731 * Test the api_conversation_show() function with an unallowed user.
1733 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1735 public function testApiConversationShowWithUnallowedUser()
1737 $_SESSION['allow_api'] = false;
1738 $_GET['screen_name'] = $this->selfUser['nick'];
1739 api_conversation_show('json');
1743 * Test the api_statuses_repeat() function.
1745 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1747 public function testApiStatusesRepeat()
1749 api_statuses_repeat('json');
1753 * Test the api_statuses_repeat() function without an authenticated user.
1755 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1757 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1759 $_SESSION['authenticated'] = false;
1760 api_statuses_repeat('json');
1764 * Test the api_statuses_repeat() function with an ID.
1767 public function testApiStatusesRepeatWithId()
1769 $this->app->argv[3] = 1;
1770 $result = api_statuses_repeat('json');
1771 $this->assertStatus($result['status']);
1773 // Also test with a shared status
1774 $this->app->argv[3] = 5;
1775 $result = api_statuses_repeat('json');
1776 $this->assertStatus($result['status']);
1780 * Test the api_statuses_destroy() function.
1782 * @expectedException Friendica\Network\HTTPException\BadRequestException
1784 public function testApiStatusesDestroy()
1786 api_statuses_destroy('json');
1790 * Test the api_statuses_destroy() function without an authenticated user.
1792 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1794 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1796 $_SESSION['authenticated'] = false;
1797 api_statuses_destroy('json');
1801 * Test the api_statuses_destroy() function with an ID.
1804 public function testApiStatusesDestroyWithId()
1806 $this->app->argv[3] = 1;
1807 $result = api_statuses_destroy('json');
1808 $this->assertStatus($result['status']);
1812 * Test the api_statuses_mentions() function.
1815 public function testApiStatusesMentions()
1817 $this->app->user = ['nickname' => $this->selfUser['nick']];
1818 $_REQUEST['max_id'] = 10;
1819 $result = api_statuses_mentions('json');
1820 $this->assertEmpty($result['status']);
1821 // We should test with mentions in the database.
1825 * Test the api_statuses_mentions() function with a negative page parameter.
1828 public function testApiStatusesMentionsWithNegativePage()
1830 $_REQUEST['page'] = -2;
1831 $result = api_statuses_mentions('json');
1832 $this->assertEmpty($result['status']);
1836 * Test the api_statuses_mentions() function with an unallowed user.
1838 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1840 public function testApiStatusesMentionsWithUnallowedUser()
1842 $_SESSION['allow_api'] = false;
1843 $_GET['screen_name'] = $this->selfUser['nick'];
1844 api_statuses_mentions('json');
1848 * Test the api_statuses_mentions() function with an RSS result.
1851 public function testApiStatusesMentionsWithRss()
1853 $result = api_statuses_mentions('rss');
1854 $this->assertXml($result, 'statuses');
1858 * Test the api_statuses_user_timeline() function.
1861 public function testApiStatusesUserTimeline()
1863 $_REQUEST['max_id'] = 10;
1864 $_REQUEST['exclude_replies'] = true;
1865 $_REQUEST['conversation_id'] = 1;
1866 $result = api_statuses_user_timeline('json');
1867 $this->assertNotEmpty($result['status']);
1868 foreach ($result['status'] as $status) {
1869 $this->assertStatus($status);
1874 * Test the api_statuses_user_timeline() function with a negative page parameter.
1877 public function testApiStatusesUserTimelineWithNegativePage()
1879 $_REQUEST['page'] = -2;
1880 $result = api_statuses_user_timeline('json');
1881 $this->assertNotEmpty($result['status']);
1882 foreach ($result['status'] as $status) {
1883 $this->assertStatus($status);
1888 * Test the api_statuses_user_timeline() function with an RSS result.
1891 public function testApiStatusesUserTimelineWithRss()
1893 $result = api_statuses_user_timeline('rss');
1894 $this->assertXml($result, 'statuses');
1898 * Test the api_statuses_user_timeline() function with an unallowed user.
1900 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1902 public function testApiStatusesUserTimelineWithUnallowedUser()
1904 $_SESSION['allow_api'] = false;
1905 $_GET['screen_name'] = $this->selfUser['nick'];
1906 api_statuses_user_timeline('json');
1910 * Test the api_favorites_create_destroy() function.
1912 * @expectedException Friendica\Network\HTTPException\BadRequestException
1914 public function testApiFavoritesCreateDestroy()
1916 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1917 $this->app->argc = count($this->app->argv);
1918 api_favorites_create_destroy('json');
1922 * Test the api_favorites_create_destroy() function with an invalid ID.
1924 * @expectedException Friendica\Network\HTTPException\BadRequestException
1926 public function testApiFavoritesCreateDestroyWithInvalidId()
1928 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1929 $this->app->argc = count($this->app->argv);
1930 api_favorites_create_destroy('json');
1934 * Test the api_favorites_create_destroy() function with an invalid action.
1936 * @expectedException Friendica\Network\HTTPException\BadRequestException
1938 public function testApiFavoritesCreateDestroyWithInvalidAction()
1940 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1941 $this->app->argc = count($this->app->argv);
1942 $_REQUEST['id'] = 1;
1943 api_favorites_create_destroy('json');
1947 * Test the api_favorites_create_destroy() function with the create action.
1950 public function testApiFavoritesCreateDestroyWithCreateAction()
1952 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1953 $this->app->argc = count($this->app->argv);
1954 $_REQUEST['id'] = 3;
1955 $result = api_favorites_create_destroy('json');
1956 $this->assertStatus($result['status']);
1960 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1963 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1965 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1966 $this->app->argc = count($this->app->argv);
1967 $_REQUEST['id'] = 3;
1968 $result = api_favorites_create_destroy('rss');
1969 $this->assertXml($result, 'status');
1973 * Test the api_favorites_create_destroy() function with the destroy action.
1976 public function testApiFavoritesCreateDestroyWithDestroyAction()
1978 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1979 $this->app->argc = count($this->app->argv);
1980 $_REQUEST['id'] = 3;
1981 $result = api_favorites_create_destroy('json');
1982 $this->assertStatus($result['status']);
1986 * Test the api_favorites_create_destroy() function without an authenticated user.
1988 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1990 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1992 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1993 $this->app->argc = count($this->app->argv);
1994 $_SESSION['authenticated'] = false;
1995 api_favorites_create_destroy('json');
1999 * Test the api_favorites() function.
2002 public function testApiFavorites()
2004 $_REQUEST['page'] = -1;
2005 $_REQUEST['max_id'] = 10;
2006 $result = api_favorites('json');
2007 foreach ($result['status'] as $status) {
2008 $this->assertStatus($status);
2013 * Test the api_favorites() function with an RSS result.
2016 public function testApiFavoritesWithRss()
2018 $result = api_favorites('rss');
2019 $this->assertXml($result, 'statuses');
2023 * Test the api_favorites() function with an unallowed user.
2025 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2027 public function testApiFavoritesWithUnallowedUser()
2029 $_SESSION['allow_api'] = false;
2030 $_GET['screen_name'] = $this->selfUser['nick'];
2031 api_favorites('json');
2035 * Test the api_format_messages() function.
2038 public function testApiFormatMessages()
2040 $result = api_format_messages(
2041 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2042 ['id' => 2, 'screen_name' => 'recipient_name'],
2043 ['id' => 3, 'screen_name' => 'sender_name']
2045 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2046 $this->assertEquals(1, $result['id']);
2047 $this->assertEquals(2, $result['recipient_id']);
2048 $this->assertEquals(3, $result['sender_id']);
2049 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2050 $this->assertEquals('sender_name', $result['sender_screen_name']);
2054 * Test the api_format_messages() function with HTML.
2057 public function testApiFormatMessagesWithHtmlText()
2059 $_GET['getText'] = 'html';
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('<strong>item_body</strong>', $result['text']);
2070 * Test the api_format_messages() function with plain text.
2073 public function testApiFormatMessagesWithPlainText()
2075 $_GET['getText'] = 'plain';
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->assertEquals('item_title', $result['title']);
2082 $this->assertEquals('item_body', $result['text']);
2086 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2089 public function testApiFormatMessagesWithoutUserObjects()
2091 $_GET['getUserObjects'] = 'false';
2092 $result = api_format_messages(
2093 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2094 ['id' => 2, 'screen_name' => 'recipient_name'],
2095 ['id' => 3, 'screen_name' => 'sender_name']
2097 $this->assertTrue(!isset($result['sender']));
2098 $this->assertTrue(!isset($result['recipient']));
2102 * Test the api_convert_item() function.
2105 public function testApiConvertItem()
2107 $result = api_convert_item(
2109 'network' => 'feed',
2110 'title' => 'item_title',
2111 // We need a long string to test that it is correctly cut
2112 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2113 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2114 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2115 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2116 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2117 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2118 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2119 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2120 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2121 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2122 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2123 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2124 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2125 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2126 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2127 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2128 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2129 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2130 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2131 'repellat officia illum quos impedit quam iste esse unde qui '.
2132 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2133 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2134 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2135 'plink' => 'item_plink'
2138 $this->assertStringStartsWith('item_title', $result['text']);
2139 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2143 * Test the api_convert_item() function with an empty item body.
2146 public function testApiConvertItemWithoutBody()
2148 $result = api_convert_item(
2150 'network' => 'feed',
2151 'title' => 'item_title',
2153 'plink' => 'item_plink'
2156 $this->assertEquals('item_title', $result['text']);
2157 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2161 * Test the api_convert_item() function with the title in the body.
2164 public function testApiConvertItemWithTitleInBody()
2166 $result = api_convert_item(
2168 'title' => 'item_title',
2169 'body' => 'item_title item_body'
2172 $this->assertEquals('item_title item_body', $result['text']);
2173 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2177 * Test the api_get_attachments() function.
2180 public function testApiGetAttachments()
2183 $this->assertEmpty(api_get_attachments($body));
2187 * Test the api_get_attachments() function with an img tag.
2190 public function testApiGetAttachmentsWithImage()
2192 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2193 $this->assertInternalType('array', api_get_attachments($body));
2197 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2200 public function testApiGetAttachmentsWithImageAndAndStatus()
2202 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2203 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2204 $this->assertInternalType('array', api_get_attachments($body));
2208 * Test the api_get_entitities() function.
2211 public function testApiGetEntitities()
2214 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2218 * Test the api_get_entitities() function with the include_entities parameter.
2221 public function testApiGetEntititiesWithIncludeEntities()
2223 $_REQUEST['include_entities'] = 'true';
2225 $result = api_get_entitities($text, 'bbcode');
2226 $this->assertInternalType('array', $result['hashtags']);
2227 $this->assertInternalType('array', $result['symbols']);
2228 $this->assertInternalType('array', $result['urls']);
2229 $this->assertInternalType('array', $result['user_mentions']);
2233 * Test the api_format_items_embeded_images() function.
2236 public function testApiFormatItemsEmbededImages()
2238 $this->assertEquals(
2239 'text ' . System::baseUrl() . '/display/item_guid',
2240 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2245 * Test the api_contactlink_to_array() function.
2248 public function testApiContactlinkToArray()
2250 $this->assertEquals(
2255 api_contactlink_to_array('text')
2260 * Test the api_contactlink_to_array() function with an URL.
2263 public function testApiContactlinkToArrayWithUrl()
2265 $this->assertEquals(
2267 'name' => ['link_text'],
2270 api_contactlink_to_array('text <a href="url">link_text</a>')
2275 * Test the api_format_items_activities() function.
2278 public function testApiFormatItemsActivities()
2280 $item = ['uid' => 0, 'uri' => ''];
2281 $result = api_format_items_activities($item);
2282 $this->assertArrayHasKey('like', $result);
2283 $this->assertArrayHasKey('dislike', $result);
2284 $this->assertArrayHasKey('attendyes', $result);
2285 $this->assertArrayHasKey('attendno', $result);
2286 $this->assertArrayHasKey('attendmaybe', $result);
2290 * Test the api_format_items_activities() function with an XML result.
2293 public function testApiFormatItemsActivitiesWithXml()
2295 $item = ['uid' => 0, 'uri' => ''];
2296 $result = api_format_items_activities($item, 'xml');
2297 $this->assertArrayHasKey('friendica:like', $result);
2298 $this->assertArrayHasKey('friendica:dislike', $result);
2299 $this->assertArrayHasKey('friendica:attendyes', $result);
2300 $this->assertArrayHasKey('friendica:attendno', $result);
2301 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2305 * Test the api_format_items_profiles() function.
2308 public function testApiFormatItemsProfiles()
2311 'id' => 'profile_id',
2312 'profile-name' => 'profile_name',
2313 'is-default' => true,
2314 'hide-friends' => true,
2315 'photo' => 'profile_photo',
2316 'thumb' => 'profile_thumb',
2318 'net-publish' => true,
2319 'pdesc' => 'description',
2320 'dob' => 'date_of_birth',
2321 'address' => 'address',
2322 'locality' => 'city',
2323 'region' => 'region',
2324 'postal-code' => 'postal_code',
2325 'country-name' => 'country',
2326 'hometown' => 'hometown',
2327 'gender' => 'gender',
2328 'marital' => 'marital',
2329 'with' => 'marital_with',
2330 'howlong' => 'marital_since',
2331 'sexual' => 'sexual',
2332 'politic' => 'politic',
2333 'religion' => 'religion',
2334 'pub_keywords' => 'public_keywords',
2335 'prv_keywords' => 'private_keywords',
2338 'dislikes' => 'dislikes',
2344 'interest' => 'interest',
2345 'romance' => 'romance',
2347 'education' => 'education',
2348 'contact' => 'social_networks',
2349 'homepage' => 'homepage'
2351 $result = api_format_items_profiles($profile_row);
2352 $this->assertEquals(
2354 'profile_id' => 'profile_id',
2355 'profile_name' => 'profile_name',
2356 'is_default' => true,
2357 'hide_friends' => true,
2358 'profile_photo' => 'profile_photo',
2359 'profile_thumb' => 'profile_thumb',
2361 'net_publish' => true,
2362 'description' => 'description',
2363 'date_of_birth' => 'date_of_birth',
2364 'address' => 'address',
2366 'region' => 'region',
2367 'postal_code' => 'postal_code',
2368 'country' => 'country',
2369 'hometown' => 'hometown',
2370 'gender' => 'gender',
2371 'marital' => 'marital',
2372 'marital_with' => 'marital_with',
2373 'marital_since' => 'marital_since',
2374 'sexual' => 'sexual',
2375 'politic' => 'politic',
2376 'religion' => 'religion',
2377 'public_keywords' => 'public_keywords',
2378 'private_keywords' => 'private_keywords',
2381 'dislikes' => 'dislikes',
2387 'interest' => 'interest',
2388 'romance' => 'romance',
2390 'education' => 'education',
2391 'social_networks' => 'social_networks',
2392 'homepage' => 'homepage',
2400 * Test the api_format_items() function.
2403 public function testApiFormatItems()
2407 'item_network' => 'item_network',
2413 'author-network' => Protocol::DFRN,
2414 'author-link' => 'http://localhost/profile/othercontact',
2418 $result = api_format_items($items, ['id' => 0], true);
2419 foreach ($result as $status) {
2420 $this->assertStatus($status);
2425 * Test the api_format_items() function with an XML result.
2428 public function testApiFormatItemsWithXml()
2436 'author-network' => Protocol::DFRN,
2437 'author-link' => 'http://localhost/profile/othercontact',
2441 $result = api_format_items($items, ['id' => 0], true, 'xml');
2442 foreach ($result as $status) {
2443 $this->assertStatus($status);
2448 * Test the api_format_items() function.
2451 public function testApiAccountRateLimitStatus()
2453 $result = api_account_rate_limit_status('json');
2454 $this->assertEquals(150, $result['hash']['remaining_hits']);
2455 $this->assertEquals(150, $result['hash']['hourly_limit']);
2456 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2460 * Test the api_format_items() function with an XML result.
2463 public function testApiAccountRateLimitStatusWithXml()
2465 $result = api_account_rate_limit_status('xml');
2466 $this->assertXml($result, 'hash');
2470 * Test the api_help_test() function.
2473 public function testApiHelpTest()
2475 $result = api_help_test('json');
2476 $this->assertEquals(['ok' => 'ok'], $result);
2480 * Test the api_help_test() function with an XML result.
2483 public function testApiHelpTestWithXml()
2485 $result = api_help_test('xml');
2486 $this->assertXml($result, 'ok');
2490 * Test the api_lists_list() function.
2493 public function testApiListsList()
2495 $result = api_lists_list('json');
2496 $this->assertEquals(['lists_list' => []], $result);
2500 * Test the api_lists_ownerships() function.
2503 public function testApiListsOwnerships()
2505 $result = api_lists_ownerships('json');
2506 foreach ($result['lists']['lists'] as $list) {
2507 $this->assertList($list);
2512 * Test the api_lists_ownerships() function without an authenticated user.
2514 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2516 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2518 $_SESSION['authenticated'] = false;
2519 api_lists_ownerships('json');
2523 * Test the api_lists_statuses() function.
2524 * @expectedException Friendica\Network\HTTPException\BadRequestException
2527 public function testApiListsStatuses()
2529 api_lists_statuses('json');
2533 * Test the api_lists_statuses() function with a list ID.
2536 public function testApiListsStatusesWithListId()
2538 $_REQUEST['list_id'] = 1;
2539 $_REQUEST['page'] = -1;
2540 $_REQUEST['max_id'] = 10;
2541 $result = api_lists_statuses('json');
2542 foreach ($result['status'] as $status) {
2543 $this->assertStatus($status);
2548 * Test the api_lists_statuses() function with a list ID and a RSS result.
2551 public function testApiListsStatusesWithListIdAndRss()
2553 $_REQUEST['list_id'] = 1;
2554 $result = api_lists_statuses('rss');
2555 $this->assertXml($result, 'statuses');
2559 * Test the api_lists_statuses() function with an unallowed user.
2561 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2563 public function testApiListsStatusesWithUnallowedUser()
2565 $_SESSION['allow_api'] = false;
2566 $_GET['screen_name'] = $this->selfUser['nick'];
2567 api_lists_statuses('json');
2571 * Test the api_statuses_f() function.
2574 public function testApiStatusesFWithFriends()
2577 $result = api_statuses_f('friends');
2578 $this->assertArrayHasKey('user', $result);
2582 * Test the api_statuses_f() function.
2585 public function testApiStatusesFWithFollowers()
2587 $result = api_statuses_f('followers');
2588 $this->assertArrayHasKey('user', $result);
2592 * Test the api_statuses_f() function.
2595 public function testApiStatusesFWithBlocks()
2597 $result = api_statuses_f('blocks');
2598 $this->assertArrayHasKey('user', $result);
2602 * Test the api_statuses_f() function.
2605 public function testApiStatusesFWithIncoming()
2607 $result = api_statuses_f('incoming');
2608 $this->assertArrayHasKey('user', $result);
2612 * Test the api_statuses_f() function an undefined cursor GET variable.
2615 public function testApiStatusesFWithUndefinedCursor()
2617 $_GET['cursor'] = 'undefined';
2618 $this->assertFalse(api_statuses_f('friends'));
2622 * Test the api_statuses_friends() function.
2625 public function testApiStatusesFriends()
2627 $result = api_statuses_friends('json');
2628 $this->assertArrayHasKey('user', $result);
2632 * Test the api_statuses_friends() function an undefined cursor GET variable.
2635 public function testApiStatusesFriendsWithUndefinedCursor()
2637 $_GET['cursor'] = 'undefined';
2638 $this->assertFalse(api_statuses_friends('json'));
2642 * Test the api_statuses_followers() function.
2645 public function testApiStatusesFollowers()
2647 $result = api_statuses_followers('json');
2648 $this->assertArrayHasKey('user', $result);
2652 * Test the api_statuses_followers() function an undefined cursor GET variable.
2655 public function testApiStatusesFollowersWithUndefinedCursor()
2657 $_GET['cursor'] = 'undefined';
2658 $this->assertFalse(api_statuses_followers('json'));
2662 * Test the api_blocks_list() function.
2665 public function testApiBlocksList()
2667 $result = api_blocks_list('json');
2668 $this->assertArrayHasKey('user', $result);
2672 * Test the api_blocks_list() function an undefined cursor GET variable.
2675 public function testApiBlocksListWithUndefinedCursor()
2677 $_GET['cursor'] = 'undefined';
2678 $this->assertFalse(api_blocks_list('json'));
2682 * Test the api_friendships_incoming() function.
2685 public function testApiFriendshipsIncoming()
2687 $result = api_friendships_incoming('json');
2688 $this->assertArrayHasKey('id', $result);
2692 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2695 public function testApiFriendshipsIncomingWithUndefinedCursor()
2697 $_GET['cursor'] = 'undefined';
2698 $this->assertFalse(api_friendships_incoming('json'));
2702 * Test the api_statusnet_config() function.
2705 public function testApiStatusnetConfig()
2707 $result = api_statusnet_config('json');
2708 $this->assertEquals('localhost', $result['config']['site']['server']);
2709 $this->assertEquals('default', $result['config']['site']['theme']);
2710 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2711 $this->assertTrue($result['config']['site']['fancy']);
2712 $this->assertEquals('en', $result['config']['site']['language']);
2713 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2714 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2715 $this->assertEquals('false', $result['config']['site']['private']);
2716 $this->assertEquals('false', $result['config']['site']['ssl']);
2717 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2721 * Test the api_statusnet_version() function.
2724 public function testApiStatusnetVersion()
2726 $result = api_statusnet_version('json');
2727 $this->assertEquals('0.9.7', $result['version']);
2731 * Test the api_ff_ids() function.
2734 public function testApiFfIds()
2736 $result = api_ff_ids('json');
2737 $this->assertNull($result);
2741 * Test the api_ff_ids() function with a result.
2744 public function testApiFfIdsWithResult()
2746 $this->markTestIncomplete();
2750 * Test the api_ff_ids() function without an authenticated user.
2752 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2754 public function testApiFfIdsWithoutAuthenticatedUser()
2756 $_SESSION['authenticated'] = false;
2761 * Test the api_friends_ids() function.
2764 public function testApiFriendsIds()
2766 $result = api_friends_ids('json');
2767 $this->assertNull($result);
2771 * Test the api_followers_ids() function.
2774 public function testApiFollowersIds()
2776 $result = api_followers_ids('json');
2777 $this->assertNull($result);
2781 * Test the api_direct_messages_new() function.
2784 public function testApiDirectMessagesNew()
2786 $result = api_direct_messages_new('json');
2787 $this->assertNull($result);
2791 * Test the api_direct_messages_new() function without an authenticated user.
2793 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2795 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2797 $_SESSION['authenticated'] = false;
2798 api_direct_messages_new('json');
2802 * Test the api_direct_messages_new() function with an user ID.
2805 public function testApiDirectMessagesNewWithUserId()
2807 $_POST['text'] = 'message_text';
2808 $_POST['user_id'] = $this->otherUser['id'];
2809 $result = api_direct_messages_new('json');
2810 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2814 * Test the api_direct_messages_new() function with a screen name.
2817 public function testApiDirectMessagesNewWithScreenName()
2819 $_POST['text'] = 'message_text';
2820 $_POST['screen_name'] = $this->friendUser['nick'];
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->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2825 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2829 * Test the api_direct_messages_new() function with a title.
2832 public function testApiDirectMessagesNewWithTitle()
2834 $_POST['text'] = 'message_text';
2835 $_POST['screen_name'] = $this->friendUser['nick'];
2836 $_REQUEST['title'] = 'message_title';
2837 $result = api_direct_messages_new('json');
2838 $this->assertEquals(1, $result['direct_message']['id']);
2839 $this->assertContains('message_text', $result['direct_message']['text']);
2840 $this->assertContains('message_title', $result['direct_message']['text']);
2841 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2842 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2846 * Test the api_direct_messages_new() function with an RSS result.
2849 public function testApiDirectMessagesNewWithRss()
2851 $_POST['text'] = 'message_text';
2852 $_POST['screen_name'] = $this->friendUser['nick'];
2853 $result = api_direct_messages_new('rss');
2854 $this->assertXml($result, 'direct-messages');
2858 * Test the api_direct_messages_destroy() function.
2860 * @expectedException Friendica\Network\HTTPException\BadRequestException
2862 public function testApiDirectMessagesDestroy()
2864 api_direct_messages_destroy('json');
2868 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2871 public function testApiDirectMessagesDestroyWithVerbose()
2873 $_GET['friendica_verbose'] = 'true';
2874 $result = api_direct_messages_destroy('json');
2875 $this->assertEquals(
2878 'result' => 'error',
2879 'message' => 'message id or parenturi not specified'
2887 * Test the api_direct_messages_destroy() function without an authenticated user.
2889 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2891 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2893 $_SESSION['authenticated'] = false;
2894 api_direct_messages_destroy('json');
2898 * Test the api_direct_messages_destroy() function with a non-zero ID.
2900 * @expectedException Friendica\Network\HTTPException\BadRequestException
2902 public function testApiDirectMessagesDestroyWithId()
2904 $_REQUEST['id'] = 1;
2905 api_direct_messages_destroy('json');
2909 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2912 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2914 $_REQUEST['id'] = 1;
2915 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2916 $_GET['friendica_verbose'] = 'true';
2917 $result = api_direct_messages_destroy('json');
2918 $this->assertEquals(
2921 'result' => 'error',
2922 'message' => 'message id not in database'
2930 * Test the api_direct_messages_destroy() function with a non-zero ID.
2933 public function testApiDirectMessagesDestroyWithCorrectId()
2935 $this->markTestIncomplete('We need to add a dataset for this.');
2939 * Test the api_direct_messages_box() function.
2942 public function testApiDirectMessagesBoxWithSentbox()
2944 $_REQUEST['page'] = -1;
2945 $_REQUEST['max_id'] = 10;
2946 $result = api_direct_messages_box('json', 'sentbox', 'false');
2947 $this->assertArrayHasKey('direct_message', $result);
2951 * Test the api_direct_messages_box() function.
2954 public function testApiDirectMessagesBoxWithConversation()
2956 $result = api_direct_messages_box('json', 'conversation', 'false');
2957 $this->assertArrayHasKey('direct_message', $result);
2961 * Test the api_direct_messages_box() function.
2964 public function testApiDirectMessagesBoxWithAll()
2966 $result = api_direct_messages_box('json', 'all', 'false');
2967 $this->assertArrayHasKey('direct_message', $result);
2971 * Test the api_direct_messages_box() function.
2974 public function testApiDirectMessagesBoxWithInbox()
2976 $result = api_direct_messages_box('json', 'inbox', 'false');
2977 $this->assertArrayHasKey('direct_message', $result);
2981 * Test the api_direct_messages_box() function.
2984 public function testApiDirectMessagesBoxWithVerbose()
2986 $result = api_direct_messages_box('json', 'sentbox', 'true');
2987 $this->assertEquals(
2990 'result' => 'error',
2991 'message' => 'no mails available'
2999 * Test the api_direct_messages_box() function with a RSS result.
3002 public function testApiDirectMessagesBoxWithRss()
3004 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3005 $this->assertXml($result, 'direct-messages');
3009 * Test the api_direct_messages_box() function without an authenticated user.
3011 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3013 public function testApiDirectMessagesBoxWithUnallowedUser()
3015 $_SESSION['allow_api'] = false;
3016 $_GET['screen_name'] = $this->selfUser['nick'];
3017 api_direct_messages_box('json', 'sentbox', 'false');
3021 * Test the api_direct_messages_sentbox() function.
3024 public function testApiDirectMessagesSentbox()
3026 $result = api_direct_messages_sentbox('json');
3027 $this->assertArrayHasKey('direct_message', $result);
3031 * Test the api_direct_messages_inbox() function.
3034 public function testApiDirectMessagesInbox()
3036 $result = api_direct_messages_inbox('json');
3037 $this->assertArrayHasKey('direct_message', $result);
3041 * Test the api_direct_messages_all() function.
3044 public function testApiDirectMessagesAll()
3046 $result = api_direct_messages_all('json');
3047 $this->assertArrayHasKey('direct_message', $result);
3051 * Test the api_direct_messages_conversation() function.
3054 public function testApiDirectMessagesConversation()
3056 $result = api_direct_messages_conversation('json');
3057 $this->assertArrayHasKey('direct_message', $result);
3061 * Test the api_oauth_request_token() function.
3064 public function testApiOauthRequestToken()
3066 $this->markTestIncomplete('killme() kills phpunit as well');
3070 * Test the api_oauth_access_token() function.
3073 public function testApiOauthAccessToken()
3075 $this->markTestIncomplete('killme() kills phpunit as well');
3079 * Test the api_fr_photoalbum_delete() function.
3081 * @expectedException Friendica\Network\HTTPException\BadRequestException
3083 public function testApiFrPhotoalbumDelete()
3085 api_fr_photoalbum_delete('json');
3089 * Test the api_fr_photoalbum_delete() function with an album name.
3091 * @expectedException Friendica\Network\HTTPException\BadRequestException
3093 public function testApiFrPhotoalbumDeleteWithAlbum()
3095 $_REQUEST['album'] = 'album_name';
3096 api_fr_photoalbum_delete('json');
3100 * Test the api_fr_photoalbum_delete() function with an album name.
3103 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3105 $this->markTestIncomplete('We need to add a dataset for this.');
3109 * Test the api_fr_photoalbum_delete() function.
3111 * @expectedException Friendica\Network\HTTPException\BadRequestException
3113 public function testApiFrPhotoalbumUpdate()
3115 api_fr_photoalbum_update('json');
3119 * Test the api_fr_photoalbum_delete() function with an album name.
3121 * @expectedException Friendica\Network\HTTPException\BadRequestException
3123 public function testApiFrPhotoalbumUpdateWithAlbum()
3125 $_REQUEST['album'] = 'album_name';
3126 api_fr_photoalbum_update('json');
3130 * Test the api_fr_photoalbum_delete() function with an album name.
3132 * @expectedException Friendica\Network\HTTPException\BadRequestException
3134 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3136 $_REQUEST['album'] = 'album_name';
3137 $_REQUEST['album_new'] = 'album_name';
3138 api_fr_photoalbum_update('json');
3142 * Test the api_fr_photoalbum_update() function without an authenticated user.
3144 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3146 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3148 $_SESSION['authenticated'] = false;
3149 api_fr_photoalbum_update('json');
3153 * Test the api_fr_photoalbum_delete() function with an album name.
3156 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3158 $this->markTestIncomplete('We need to add a dataset for this.');
3162 * Test the api_fr_photos_list() function.
3165 public function testApiFrPhotosList()
3167 $result = api_fr_photos_list('json');
3168 $this->assertArrayHasKey('photo', $result);
3172 * Test the api_fr_photos_list() function without an authenticated user.
3174 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3176 public function testApiFrPhotosListWithoutAuthenticatedUser()
3178 $_SESSION['authenticated'] = false;
3179 api_fr_photos_list('json');
3183 * Test the api_fr_photo_create_update() function.
3185 * @expectedException Friendica\Network\HTTPException\BadRequestException
3187 public function testApiFrPhotoCreateUpdate()
3189 api_fr_photo_create_update('json');
3193 * Test the api_fr_photo_create_update() function without an authenticated user.
3195 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3197 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3199 $_SESSION['authenticated'] = false;
3200 api_fr_photo_create_update('json');
3204 * Test the api_fr_photo_create_update() function with an album name.
3206 * @expectedException Friendica\Network\HTTPException\BadRequestException
3208 public function testApiFrPhotoCreateUpdateWithAlbum()
3210 $_REQUEST['album'] = 'album_name';
3211 api_fr_photo_create_update('json');
3215 * Test the api_fr_photo_create_update() function with the update mode.
3218 public function testApiFrPhotoCreateUpdateWithUpdate()
3220 $this->markTestIncomplete('We need to create a dataset for this');
3224 * Test the api_fr_photo_create_update() function with an uploaded file.
3227 public function testApiFrPhotoCreateUpdateWithFile()
3229 $this->markTestIncomplete();
3233 * Test the api_fr_photo_delete() function.
3235 * @expectedException Friendica\Network\HTTPException\BadRequestException
3237 public function testApiFrPhotoDelete()
3239 api_fr_photo_delete('json');
3243 * Test the api_fr_photo_delete() function without an authenticated user.
3245 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3247 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3249 $_SESSION['authenticated'] = false;
3250 api_fr_photo_delete('json');
3254 * Test the api_fr_photo_delete() function with a photo ID.
3256 * @expectedException Friendica\Network\HTTPException\BadRequestException
3258 public function testApiFrPhotoDeleteWithPhotoId()
3260 $_REQUEST['photo_id'] = 1;
3261 api_fr_photo_delete('json');
3265 * Test the api_fr_photo_delete() function with a correct photo ID.
3268 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3270 $this->markTestIncomplete('We need to create a dataset for this.');
3274 * Test the api_fr_photo_detail() function.
3276 * @expectedException Friendica\Network\HTTPException\BadRequestException
3278 public function testApiFrPhotoDetail()
3280 api_fr_photo_detail('json');
3284 * Test the api_fr_photo_detail() function without an authenticated user.
3286 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3288 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3290 $_SESSION['authenticated'] = false;
3291 api_fr_photo_detail('json');
3295 * Test the api_fr_photo_detail() function with a photo ID.
3297 * @expectedException Friendica\Network\HTTPException\NotFoundException
3299 public function testApiFrPhotoDetailWithPhotoId()
3301 $_REQUEST['photo_id'] = 1;
3302 api_fr_photo_detail('json');
3306 * Test the api_fr_photo_detail() function with a correct photo ID.
3309 public function testApiFrPhotoDetailCorrectPhotoId()
3311 $this->markTestIncomplete('We need to create a dataset for this.');
3315 * Test the api_account_update_profile_image() function.
3317 * @expectedException Friendica\Network\HTTPException\BadRequestException
3319 public function testApiAccountUpdateProfileImage()
3321 api_account_update_profile_image('json');
3325 * Test the api_account_update_profile_image() function without an authenticated user.
3327 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3329 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3331 $_SESSION['authenticated'] = false;
3332 api_account_update_profile_image('json');
3336 * Test the api_account_update_profile_image() function with an uploaded file.
3338 * @expectedException Friendica\Network\HTTPException\BadRequestException
3340 public function testApiAccountUpdateProfileImageWithUpload()
3342 $this->markTestIncomplete();
3347 * Test the api_account_update_profile() function.
3350 public function testApiAccountUpdateProfile()
3352 $_POST['name'] = 'new_name';
3353 $_POST['description'] = 'new_description';
3354 $result = api_account_update_profile('json');
3355 // We can't use assertSelfUser() here because the user object is missing some properties.
3356 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3357 $this->assertEquals('DFRN', $result['user']['location']);
3358 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3359 $this->assertEquals('dfrn', $result['user']['network']);
3360 $this->assertEquals('new_name', $result['user']['name']);
3361 $this->assertEquals('new_description', $result['user']['description']);
3365 * Test the check_acl_input() function.
3368 public function testCheckAclInput()
3370 $result = check_acl_input('<aclstring>');
3371 // Where does this result come from?
3372 $this->assertEquals(1, $result);
3376 * Test the check_acl_input() function with an empty ACL string.
3379 public function testCheckAclInputWithEmptyAclString()
3381 $result = check_acl_input(' ');
3382 $this->assertFalse($result);
3386 * Test the save_media_to_database() function.
3389 public function testSaveMediaToDatabase()
3391 $this->markTestIncomplete();
3395 * Test the post_photo_item() function.
3398 public function testPostPhotoItem()
3400 $this->markTestIncomplete();
3404 * Test the prepare_photo_data() function.
3407 public function testPreparePhotoData()
3409 $this->markTestIncomplete();
3413 * Test the api_friendica_remoteauth() function.
3415 * @expectedException Friendica\Network\HTTPException\BadRequestException
3417 public function testApiFriendicaRemoteauth()
3419 api_friendica_remoteauth();
3423 * Test the api_friendica_remoteauth() function with an URL.
3425 * @expectedException Friendica\Network\HTTPException\BadRequestException
3427 public function testApiFriendicaRemoteauthWithUrl()
3429 $_GET['url'] = 'url';
3430 $_GET['c_url'] = 'url';
3431 api_friendica_remoteauth();
3435 * Test the api_friendica_remoteauth() function with a correct URL.
3438 public function testApiFriendicaRemoteauthWithCorrectUrl()
3440 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3441 $_GET['url'] = 'url';
3442 $_GET['c_url'] = $this->selfUser['nurl'];
3443 api_friendica_remoteauth();
3447 * Test the api_share_as_retweet() function.
3450 public function testApiShareAsRetweet()
3452 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3453 $result = api_share_as_retweet($item);
3454 $this->assertFalse($result);
3458 * Test the api_share_as_retweet() function with a valid item.
3461 public function testApiShareAsRetweetWithValidItem()
3463 $this->markTestIncomplete();
3467 * Test the api_get_nick() function.
3470 public function testApiGetNick()
3472 $result = api_get_nick($this->otherUser['nurl']);
3473 $this->assertEquals('othercontact', $result);
3477 * Test the api_get_nick() function with a wrong URL.
3480 public function testApiGetNickWithWrongUrl()
3482 $result = api_get_nick('wrong_url');
3483 $this->assertFalse($result);
3487 * Test the api_in_reply_to() function.
3490 public function testApiInReplyTo()
3492 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3493 $this->assertArrayHasKey('status_id', $result);
3494 $this->assertArrayHasKey('user_id', $result);
3495 $this->assertArrayHasKey('status_id_str', $result);
3496 $this->assertArrayHasKey('user_id_str', $result);
3497 $this->assertArrayHasKey('screen_name', $result);
3501 * Test the api_in_reply_to() function with a valid item.
3504 public function testApiInReplyToWithValidItem()
3506 $this->markTestIncomplete();
3510 * Test the api_clean_plain_items() function.
3513 public function testApiCleanPlainItems()
3515 $_REQUEST['include_entities'] = 'true';
3516 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3517 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3521 * Test the api_clean_attachments() function.
3524 public function testApiCleanAttachments()
3526 $this->markTestIncomplete();
3530 * Test the api_best_nickname() function.
3533 public function testApiBestNickname()
3536 $result = api_best_nickname($contacts);
3537 $this->assertNull($result);
3541 * Test the api_best_nickname() function with contacts.
3544 public function testApiBestNicknameWithContacts()
3546 $this->markTestIncomplete();
3550 * Test the api_friendica_group_show() function.
3553 public function testApiFriendicaGroupShow()
3555 $this->markTestIncomplete();
3559 * Test the api_friendica_group_delete() function.
3562 public function testApiFriendicaGroupDelete()
3564 $this->markTestIncomplete();
3568 * Test the api_lists_destroy() function.
3571 public function testApiListsDestroy()
3573 $this->markTestIncomplete();
3577 * Test the group_create() function.
3580 public function testGroupCreate()
3582 $this->markTestIncomplete();
3586 * Test the api_friendica_group_create() function.
3589 public function testApiFriendicaGroupCreate()
3591 $this->markTestIncomplete();
3595 * Test the api_lists_create() function.
3598 public function testApiListsCreate()
3600 $this->markTestIncomplete();
3604 * Test the api_friendica_group_update() function.
3607 public function testApiFriendicaGroupUpdate()
3609 $this->markTestIncomplete();
3613 * Test the api_lists_update() function.
3616 public function testApiListsUpdate()
3618 $this->markTestIncomplete();
3622 * Test the api_friendica_activity() function.
3625 public function testApiFriendicaActivity()
3627 $this->markTestIncomplete();
3631 * Test the api_friendica_notification() function.
3633 * @expectedException Friendica\Network\HTTPException\BadRequestException
3635 public function testApiFriendicaNotification()
3637 api_friendica_notification('json');
3641 * Test the api_friendica_notification() function without an authenticated user.
3643 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3645 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3647 $_SESSION['authenticated'] = false;
3648 api_friendica_notification('json');
3652 * Test the api_friendica_notification() function with an argument count.
3655 public function testApiFriendicaNotificationWithArgumentCount()
3657 $this->app->argv = ['api', 'friendica', 'notification'];
3658 $this->app->argc = count($this->app->argv);
3659 $result = api_friendica_notification('json');
3660 $this->assertEquals(['note' => false], $result);
3664 * Test the api_friendica_notification() function with an XML result.
3667 public function testApiFriendicaNotificationWithXmlResult()
3669 $this->app->argv = ['api', 'friendica', 'notification'];
3670 $this->app->argc = count($this->app->argv);
3671 $result = api_friendica_notification('xml');
3672 $this->assertXml($result, 'notes');
3676 * Test the api_friendica_notification_seen() function.
3679 public function testApiFriendicaNotificationSeen()
3681 $this->markTestIncomplete();
3685 * Test the api_friendica_direct_messages_setseen() function.
3688 public function testApiFriendicaDirectMessagesSetseen()
3690 $this->markTestIncomplete();
3694 * Test the api_friendica_direct_messages_search() function.
3697 public function testApiFriendicaDirectMessagesSearch()
3699 $this->markTestIncomplete();
3703 * Test the api_friendica_profile_show() function.
3706 public function testApiFriendicaProfileShow()
3708 $result = api_friendica_profile_show('json');
3709 // We can't use assertSelfUser() here because the user object is missing some properties.
3710 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3711 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3712 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3713 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3714 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3715 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3716 $this->assertFalse($result['$result']['multi_profiles']);
3720 * Test the api_friendica_profile_show() function with a profile ID.
3723 public function testApiFriendicaProfileShowWithProfileId()
3725 $this->markTestIncomplete('We need to add a dataset for this.');
3729 * Test the api_friendica_profile_show() function with a wrong profile ID.
3731 * @expectedException Friendica\Network\HTTPException\BadRequestException
3733 public function testApiFriendicaProfileShowWithWrongProfileId()
3735 $_REQUEST['profile_id'] = 666;
3736 api_friendica_profile_show('json');
3740 * Test the api_friendica_profile_show() function without an authenticated user.
3742 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3744 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3746 $_SESSION['authenticated'] = false;
3747 api_friendica_profile_show('json');
3751 * Test the api_saved_searches_list() function.
3754 public function testApiSavedSearchesList()
3756 $result = api_saved_searches_list('json');
3757 $this->assertEquals(1, $result['terms'][0]['id']);
3758 $this->assertEquals(1, $result['terms'][0]['id_str']);
3759 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3760 $this->assertEquals('Saved search', $result['terms'][0]['query']);