6 namespace Friendica\Test;
10 use Friendica\Core\Config\Configuration;
11 use Friendica\Core\Config\PConfiguration;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Session;
14 use Friendica\Core\Session\ISession;
15 use Friendica\Core\System;
16 use Friendica\Database\Database;
18 use Friendica\Model\Contact;
19 use Friendica\Network\HTTPException;
20 use Friendica\Test\Util\Database\StaticDatabase;
21 use Monolog\Handler\TestHandler;
23 require_once __DIR__ . '/../../include/api.php';
26 * Tests for the API functions.
28 * Functions that use header() need to be tested in a separate process.
29 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
31 class ApiTest extends DatabaseTest
34 * @var TestHandler Can handle log-outputs
41 protected $friendUser;
45 protected $wrongUserId;
50 /** @var Configuration */
57 * Create variables used by tests.
59 protected function setUp()
63 $this->dice = (new Dice())
64 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
65 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
66 ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
67 DI::init($this->dice);
69 /** @var Database $dba */
70 $dba = $this->dice->create(Database::class);
72 /** @var Configuration $config */
73 $this->config = $this->dice->create(Configuration::class);
75 $this->config->set('system', 'url', 'http://localhost');
76 $this->config->set('system', 'hostname', 'localhost');
77 $this->config->set('system', 'worker_dont_fork', true);
80 $this->config->set('config', 'hostname', 'localhost');
81 $this->config->set('system', 'throttle_limit_day', 100);
82 $this->config->set('system', 'throttle_limit_week', 100);
83 $this->config->set('system', 'throttle_limit_month', 100);
84 $this->config->set('system', 'theme', 'system_theme');
86 // Load the API dataset for the whole API
87 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
90 $this->app = DI::app();
93 $this->app->argv = ['home'];
95 // User data that the test database is populated with
98 'name' => 'Self contact',
99 'nick' => 'selfcontact',
100 'nurl' => 'http://localhost/profile/selfcontact'
102 $this->friendUser = [
104 'name' => 'Friend contact',
105 'nick' => 'friendcontact',
106 'nurl' => 'http://localhost/profile/friendcontact'
110 'name' => 'othercontact',
111 'nick' => 'othercontact',
112 'nurl' => 'http://localhost/profile/othercontact'
115 // User ID that we know is not in the database
116 $this->wrongUserId = 666;
118 $session = DI::session();
121 // Most API require login so we force the session
124 'authenticated' => true,
125 'uid' => $this->selfUser['id']
134 * Assert that an user array contains expected keys.
136 * @param array $user User array
140 private function assertSelfUser(array $user)
142 $this->assertEquals($this->selfUser['id'], $user['uid']);
143 $this->assertEquals($this->selfUser['id'], $user['cid']);
144 $this->assertEquals(1, $user['self']);
145 $this->assertEquals('DFRN', $user['location']);
146 $this->assertEquals($this->selfUser['name'], $user['name']);
147 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
148 $this->assertEquals('dfrn', $user['network']);
149 $this->assertTrue($user['verified']);
153 * Assert that an user array contains expected keys.
155 * @param array $user User array
159 private function assertOtherUser(array $user)
161 $this->assertEquals($this->otherUser['id'], $user['id']);
162 $this->assertEquals($this->otherUser['id'], $user['id_str']);
163 $this->assertEquals(0, $user['self']);
164 $this->assertEquals($this->otherUser['name'], $user['name']);
165 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
166 $this->assertFalse($user['verified']);
170 * Assert that a status array contains expected keys.
172 * @param array $status Status array
176 private function assertStatus(array $status)
178 $this->assertInternalType('string', $status['text']);
179 $this->assertInternalType('int', $status['id']);
180 // We could probably do more checks here.
184 * Assert that a list array contains expected keys.
186 * @param array $list List array
190 private function assertList(array $list)
192 $this->assertInternalType('string', $list['name']);
193 $this->assertInternalType('int', $list['id']);
194 $this->assertInternalType('string', $list['id_str']);
195 $this->assertContains($list['mode'], ['public', 'private']);
196 // We could probably do more checks here.
200 * Assert that the string is XML and contain the root element.
202 * @param string $result XML string
203 * @param string $root_element Root element name
207 private function assertXml($result, $root_element)
209 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
210 $this->assertContains('<' . $root_element, $result);
211 // We could probably do more checks here.
215 * Get the path to a temporary empty PNG image.
217 * @return string Path
219 private function getTempImage()
221 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
225 // Empty 1x1 px PNG image
226 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
234 * Test the api_user() function.
238 public function testApiUser()
240 $this->assertEquals($this->selfUser['id'], api_user());
244 * Test the api_user() function with an unallowed user.
248 public function testApiUserWithUnallowedUser()
250 $_SESSION = ['allow_api' => false];
251 $this->assertEquals(false, api_user());
255 * Test the api_source() function.
259 public function testApiSource()
261 $this->assertEquals('api', api_source());
265 * Test the api_source() function with a Twidere user agent.
269 public function testApiSourceWithTwidere()
271 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
272 $this->assertEquals('Twidere', api_source());
276 * Test the api_source() function with a GET parameter.
280 public function testApiSourceWithGet()
282 $_GET['source'] = 'source_name';
283 $this->assertEquals('source_name', api_source());
287 * Test the api_date() function.
291 public function testApiDate()
293 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
297 * Test the api_register_func() function.
301 public function testApiRegisterFunc()
313 $this->assertTrue($API['api_path']['auth']);
314 $this->assertEquals('method', $API['api_path']['method']);
315 $this->assertTrue(is_callable($API['api_path']['func']));
319 * Test the api_login() function without any login.
322 * @runInSeparateProcess
323 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
325 public function testApiLoginWithoutLogin()
327 api_login($this->app);
331 * Test the api_login() function with a bad login.
334 * @runInSeparateProcess
335 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
337 public function testApiLoginWithBadLogin()
339 $_SERVER['PHP_AUTH_USER'] = 'user@server';
340 api_login($this->app);
344 * Test the api_login() function with oAuth.
348 public function testApiLoginWithOauth()
350 $this->markTestIncomplete('Can we test this easily?');
354 * Test the api_login() function with authentication provided by an addon.
358 public function testApiLoginWithAddonAuth()
360 $this->markTestIncomplete('Can we test this easily?');
364 * Test the api_login() function with a correct login.
367 * @runInSeparateProcess
369 public function testApiLoginWithCorrectLogin()
371 $_SERVER['PHP_AUTH_USER'] = 'Test user';
372 $_SERVER['PHP_AUTH_PW'] = 'password';
373 api_login($this->app);
377 * Test the api_login() function with a remote user.
380 * @runInSeparateProcess
381 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
383 public function testApiLoginWithRemoteUser()
385 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
386 api_login($this->app);
390 * Test the api_check_method() function.
394 public function testApiCheckMethod()
396 $this->assertFalse(api_check_method('method'));
400 * Test the api_check_method() function with a correct method.
404 public function testApiCheckMethodWithCorrectMethod()
406 $_SERVER['REQUEST_METHOD'] = 'method';
407 $this->assertTrue(api_check_method('method'));
411 * Test the api_check_method() function with a wildcard.
415 public function testApiCheckMethodWithWildcard()
417 $this->assertTrue(api_check_method('*'));
421 * Test the api_call() function.
424 * @runInSeparateProcess
426 public function testApiCall()
430 'method' => 'method',
431 'func' => function () {
432 return ['data' => ['some_data']];
435 $_SERVER['REQUEST_METHOD'] = 'method';
436 $_GET['callback'] = 'callback_name';
438 $this->app->query_string = 'api_path';
440 'callback_name(["some_data"])',
446 * Test the api_call() function with the profiled enabled.
449 * @runInSeparateProcess
451 public function testApiCallWithProfiler()
455 'method' => 'method',
456 'func' => function () {
457 return ['data' => ['some_data']];
460 $_SERVER['REQUEST_METHOD'] = 'method';
461 $this->config->set('system', 'profiler', true);
462 $this->config->set('rendertime', 'callstack', true);
463 $this->app->callstack = [
464 'database' => ['some_function' => 200],
465 'database_write' => ['some_function' => 200],
466 'cache' => ['some_function' => 200],
467 'cache_write' => ['some_function' => 200],
468 'network' => ['some_function' => 200]
471 $this->app->query_string = 'api_path';
479 * Test the api_call() function without any result.
482 * @runInSeparateProcess
484 public function testApiCallWithNoResult()
488 'method' => 'method',
489 'func' => function () {
493 $_SERVER['REQUEST_METHOD'] = 'method';
495 $this->app->query_string = 'api_path';
497 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
503 * Test the api_call() function with an unimplemented API.
506 * @runInSeparateProcess
508 public function testApiCallWithUninplementedApi()
511 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
517 * Test the api_call() function with a JSON result.
520 * @runInSeparateProcess
522 public function testApiCallWithJson()
526 'method' => 'method',
527 'func' => function () {
528 return ['data' => ['some_data']];
531 $_SERVER['REQUEST_METHOD'] = 'method';
533 $this->app->query_string = 'api_path.json';
541 * Test the api_call() function with an XML result.
544 * @runInSeparateProcess
546 public function testApiCallWithXml()
550 'method' => 'method',
551 'func' => function () {
555 $_SERVER['REQUEST_METHOD'] = 'method';
557 $this->app->query_string = 'api_path.xml';
565 * Test the api_call() function with an RSS result.
568 * @runInSeparateProcess
570 public function testApiCallWithRss()
574 'method' => 'method',
575 'func' => function () {
579 $_SERVER['REQUEST_METHOD'] = 'method';
581 $this->app->query_string = 'api_path.rss';
583 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
590 * Test the api_call() function with an Atom result.
593 * @runInSeparateProcess
595 public function testApiCallWithAtom()
599 'method' => 'method',
600 'func' => function () {
604 $_SERVER['REQUEST_METHOD'] = 'method';
606 $this->app->query_string = 'api_path.atom';
608 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
615 * Test the api_call() function with an unallowed method.
618 * @runInSeparateProcess
620 public function testApiCallWithWrongMethod()
623 $API['api_path'] = ['method' => 'method'];
625 $this->app->query_string = 'api_path';
627 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
633 * Test the api_call() function with an unauthorized user.
636 * @runInSeparateProcess
638 public function testApiCallWithWrongAuth()
642 'method' => 'method',
645 $_SERVER['REQUEST_METHOD'] = 'method';
646 $_SESSION['authenticated'] = false;
648 $this->app->query_string = 'api_path';
650 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
656 * Test the api_error() function with a JSON result.
659 * @runInSeparateProcess
661 public function testApiErrorWithJson()
664 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
665 api_error('json', new HTTPException\OKException('error_message'))
670 * Test the api_error() function with an XML result.
673 * @runInSeparateProcess
675 public function testApiErrorWithXml()
678 '<?xml version="1.0"?>' . "\n" .
679 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
680 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
681 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
682 ' <error>error_message</error>' . "\n" .
683 ' <code>200 OK</code>' . "\n" .
684 ' <request/>' . "\n" .
686 api_error('xml', new HTTPException\OKException('error_message'))
691 * Test the api_error() function with an RSS result.
694 * @runInSeparateProcess
696 public function testApiErrorWithRss()
699 '<?xml version="1.0"?>' . "\n" .
700 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
701 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
702 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
703 ' <error>error_message</error>' . "\n" .
704 ' <code>200 OK</code>' . "\n" .
705 ' <request/>' . "\n" .
707 api_error('rss', new HTTPException\OKException('error_message'))
712 * Test the api_error() function with an Atom result.
715 * @runInSeparateProcess
717 public function testApiErrorWithAtom()
720 '<?xml version="1.0"?>' . "\n" .
721 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
722 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
723 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
724 ' <error>error_message</error>' . "\n" .
725 ' <code>200 OK</code>' . "\n" .
726 ' <request/>' . "\n" .
728 api_error('atom', new HTTPException\OKException('error_message'))
733 * Test the api_rss_extra() function.
737 public function testApiRssExtra()
739 $user_info = ['url' => 'user_url', 'lang' => 'en'];
740 $result = api_rss_extra($this->app, [], $user_info);
741 $this->assertEquals($user_info, $result['$user']);
742 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
743 $this->assertArrayHasKey('self', $result['$rss']);
744 $this->assertArrayHasKey('base', $result['$rss']);
745 $this->assertArrayHasKey('updated', $result['$rss']);
746 $this->assertArrayHasKey('atom_updated', $result['$rss']);
747 $this->assertArrayHasKey('language', $result['$rss']);
748 $this->assertArrayHasKey('logo', $result['$rss']);
752 * Test the api_rss_extra() function without any user info.
756 public function testApiRssExtraWithoutUserInfo()
758 $result = api_rss_extra($this->app, [], null);
759 $this->assertInternalType('array', $result['$user']);
760 $this->assertArrayHasKey('alternate', $result['$rss']);
761 $this->assertArrayHasKey('self', $result['$rss']);
762 $this->assertArrayHasKey('base', $result['$rss']);
763 $this->assertArrayHasKey('updated', $result['$rss']);
764 $this->assertArrayHasKey('atom_updated', $result['$rss']);
765 $this->assertArrayHasKey('language', $result['$rss']);
766 $this->assertArrayHasKey('logo', $result['$rss']);
770 * Test the api_unique_id_to_nurl() function.
774 public function testApiUniqueIdToNurl()
776 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
780 * Test the api_unique_id_to_nurl() function with a correct ID.
784 public function testApiUniqueIdToNurlWithCorrectId()
786 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
790 * Test the api_get_user() function.
794 public function testApiGetUser()
796 $user = api_get_user($this->app);
797 $this->assertSelfUser($user);
798 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
799 $this->assertEquals('6fdbe8', $user['profile_link_color']);
800 $this->assertEquals('ededed', $user['profile_background_color']);
804 * Test the api_get_user() function with a Frio schema.
808 public function testApiGetUserWithFrioSchema()
810 $pConfig = $this->dice->create(PConfiguration::class);
811 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
812 $user = api_get_user($this->app);
813 $this->assertSelfUser($user);
814 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
815 $this->assertEquals('6fdbe8', $user['profile_link_color']);
816 $this->assertEquals('ededed', $user['profile_background_color']);
820 * Test the api_get_user() function with a custom Frio schema.
824 public function testApiGetUserWithCustomFrioSchema()
826 $pConfig = $this->dice->create(PConfiguration::class);
827 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
828 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
829 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
830 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
831 $user = api_get_user($this->app);
832 $this->assertSelfUser($user);
833 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
834 $this->assertEquals('123456', $user['profile_link_color']);
835 $this->assertEquals('123456', $user['profile_background_color']);
839 * Test the api_get_user() function with an empty Frio schema.
843 public function testApiGetUserWithEmptyFrioSchema()
845 $pConfig = $this->dice->create(PConfiguration::class);
846 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
847 $user = api_get_user($this->app);
848 $this->assertSelfUser($user);
849 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
850 $this->assertEquals('6fdbe8', $user['profile_link_color']);
851 $this->assertEquals('ededed', $user['profile_background_color']);
855 * Test the api_get_user() function with an user that is not allowed to use the API.
858 * @runInSeparateProcess
860 public function testApiGetUserWithoutApiUser()
862 $_SERVER['PHP_AUTH_USER'] = 'Test user';
863 $_SERVER['PHP_AUTH_PW'] = 'password';
864 $_SESSION['allow_api'] = false;
865 $this->assertFalse(api_get_user($this->app));
869 * Test the api_get_user() function with an user ID in a GET parameter.
873 public function testApiGetUserWithGetId()
875 $_GET['user_id'] = $this->otherUser['id'];
876 $this->assertOtherUser(api_get_user($this->app));
880 * Test the api_get_user() function with a wrong user ID in a GET parameter.
883 * @expectedException Friendica\Network\HTTPException\BadRequestException
885 public function testApiGetUserWithWrongGetId()
887 $_GET['user_id'] = $this->wrongUserId;
888 $this->assertOtherUser(api_get_user($this->app));
892 * Test the api_get_user() function with an user name in a GET parameter.
896 public function testApiGetUserWithGetName()
898 $_GET['screen_name'] = $this->selfUser['nick'];
899 $this->assertSelfUser(api_get_user($this->app));
903 * Test the api_get_user() function with a profile URL in a GET parameter.
907 public function testApiGetUserWithGetUrl()
909 $_GET['profileurl'] = $this->selfUser['nurl'];
910 $this->assertSelfUser(api_get_user($this->app));
914 * Test the api_get_user() function with an user ID in the API path.
918 public function testApiGetUserWithNumericCalledApi()
921 $called_api = ['api_path'];
922 $this->app->argv[1] = $this->otherUser['id'] . '.json';
923 $this->assertOtherUser(api_get_user($this->app));
927 * Test the api_get_user() function with the $called_api global variable.
931 public function testApiGetUserWithCalledApi()
934 $called_api = ['api', 'api_path'];
935 $this->assertSelfUser(api_get_user($this->app));
939 * Test the api_get_user() function with a valid user.
943 public function testApiGetUserWithCorrectUser()
945 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
949 * Test the api_get_user() function with a wrong user ID.
952 * @expectedException Friendica\Network\HTTPException\BadRequestException
954 public function testApiGetUserWithWrongUser()
956 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
960 * Test the api_get_user() function with a 0 user ID.
964 public function testApiGetUserWithZeroUser()
966 $this->assertSelfUser(api_get_user($this->app, 0));
970 * Test the api_item_get_user() function.
974 public function testApiItemGetUser()
976 $users = api_item_get_user($this->app, []);
977 $this->assertSelfUser($users[0]);
981 * Test the api_item_get_user() function with a different item parent.
985 public function testApiItemGetUserWithDifferentParent()
987 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
988 $this->assertSelfUser($users[0]);
989 $this->assertEquals($users[0], $users[1]);
993 * Test the api_walk_recursive() function.
997 public function testApiWalkRecursive()
1000 $this->assertEquals(
1005 // Should we test this with a callback that actually does something?
1013 * Test the api_walk_recursive() function with an array.
1017 public function testApiWalkRecursiveWithArray()
1019 $array = [['item1'], ['item2']];
1020 $this->assertEquals(
1025 // Should we test this with a callback that actually does something?
1033 * Test the api_reformat_xml() function.
1037 public function testApiReformatXml()
1041 $this->assertTrue(api_reformat_xml($item, $key));
1042 $this->assertEquals('true', $item);
1046 * Test the api_reformat_xml() function with a statusnet_api key.
1050 public function testApiReformatXmlWithStatusnetKey()
1053 $key = 'statusnet_api';
1054 $this->assertTrue(api_reformat_xml($item, $key));
1055 $this->assertEquals('statusnet:api', $key);
1059 * Test the api_reformat_xml() function with a friendica_api key.
1063 public function testApiReformatXmlWithFriendicaKey()
1066 $key = 'friendica_api';
1067 $this->assertTrue(api_reformat_xml($item, $key));
1068 $this->assertEquals('friendica:api', $key);
1072 * Test the api_create_xml() function.
1076 public function testApiCreateXml()
1078 $this->assertEquals(
1079 '<?xml version="1.0"?>' . "\n" .
1080 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1081 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1082 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1083 ' <data>some_data</data>' . "\n" .
1084 '</root_element>' . "\n",
1085 api_create_xml(['data' => ['some_data']], 'root_element')
1090 * Test the api_create_xml() function without any XML namespace.
1094 public function testApiCreateXmlWithoutNamespaces()
1096 $this->assertEquals(
1097 '<?xml version="1.0"?>' . "\n" .
1099 ' <data>some_data</data>' . "\n" .
1101 api_create_xml(['data' => ['some_data']], 'ok')
1106 * Test the api_format_data() function.
1110 public function testApiFormatData()
1112 $data = ['some_data'];
1113 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1117 * Test the api_format_data() function with an XML result.
1121 public function testApiFormatDataWithXml()
1123 $this->assertEquals(
1124 '<?xml version="1.0"?>' . "\n" .
1125 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1126 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1127 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1128 ' <data>some_data</data>' . "\n" .
1129 '</root_element>' . "\n",
1130 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1135 * Test the api_account_verify_credentials() function.
1139 public function testApiAccountVerifyCredentials()
1141 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1145 * Test the api_account_verify_credentials() function without an authenticated user.
1148 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1150 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1152 $_SESSION['authenticated'] = false;
1153 api_account_verify_credentials('json');
1157 * Test the requestdata() function.
1161 public function testRequestdata()
1163 $this->assertNull(requestdata('variable_name'));
1167 * Test the requestdata() function with a POST parameter.
1171 public function testRequestdataWithPost()
1173 $_POST['variable_name'] = 'variable_value';
1174 $this->assertEquals('variable_value', requestdata('variable_name'));
1178 * Test the requestdata() function with a GET parameter.
1182 public function testRequestdataWithGet()
1184 $_GET['variable_name'] = 'variable_value';
1185 $this->assertEquals('variable_value', requestdata('variable_name'));
1189 * Test the api_statuses_mediap() function.
1193 public function testApiStatusesMediap()
1195 $this->app->argc = 2;
1203 'tmp_name' => $this->getTempImage(),
1204 'name' => 'spacer.png',
1205 'type' => 'image/png'
1208 $_GET['status'] = '<b>Status content</b>';
1210 $result = api_statuses_mediap('json');
1211 $this->assertStatus($result['status']);
1215 * Test the api_statuses_mediap() function without an authenticated user.
1218 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1220 public function testApiStatusesMediapWithoutAuthenticatedUser()
1222 $_SESSION['authenticated'] = false;
1223 api_statuses_mediap('json');
1227 * Test the api_statuses_update() function.
1231 public function testApiStatusesUpdate()
1233 $_GET['status'] = 'Status content #friendica';
1234 $_GET['in_reply_to_status_id'] = -1;
1243 'tmp_name' => $this->getTempImage(),
1244 'name' => 'spacer.png',
1245 'type' => 'image/png'
1249 $result = api_statuses_update('json');
1250 $this->assertStatus($result['status']);
1254 * Test the api_statuses_update() function with an HTML status.
1258 public function testApiStatusesUpdateWithHtml()
1260 $_GET['htmlstatus'] = '<b>Status content</b>';
1262 $result = api_statuses_update('json');
1263 $this->assertStatus($result['status']);
1267 * Test the api_statuses_update() function without an authenticated user.
1270 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1272 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1274 $_SESSION['authenticated'] = false;
1275 api_statuses_update('json');
1279 * Test the api_statuses_update() function with a parent status.
1283 public function testApiStatusesUpdateWithParent()
1285 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1289 * Test the api_statuses_update() function with a media_ids parameter.
1293 public function testApiStatusesUpdateWithMediaIds()
1295 $this->markTestIncomplete();
1299 * Test the api_statuses_update() function with the throttle limit reached.
1303 public function testApiStatusesUpdateWithDayThrottleReached()
1305 $this->markTestIncomplete();
1309 * Test the api_media_upload() function.
1312 * @expectedException Friendica\Network\HTTPException\BadRequestException
1314 public function testApiMediaUpload()
1320 * Test the api_media_upload() function without an authenticated user.
1323 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1325 public function testApiMediaUploadWithoutAuthenticatedUser()
1327 $_SESSION['authenticated'] = false;
1332 * Test the api_media_upload() function with an invalid uploaded media.
1335 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1337 public function testApiMediaUploadWithMedia()
1342 'tmp_name' => 'tmp_name'
1349 * Test the api_media_upload() function with an valid uploaded media.
1353 public function testApiMediaUploadWithValidMedia()
1361 'tmp_name' => $this->getTempImage(),
1362 'name' => 'spacer.png',
1363 'type' => 'image/png'
1369 $result = api_media_upload();
1370 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1371 $this->assertEquals(1, $result['media']['image']['w']);
1372 $this->assertEquals(1, $result['media']['image']['h']);
1373 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1377 * Test the api_status_show() function.
1379 public function testApiStatusShowWithJson()
1381 $result = api_status_show('json', 1);
1382 $this->assertStatus($result['status']);
1386 * Test the api_status_show() function with an XML result.
1388 public function testApiStatusShowWithXml()
1390 $result = api_status_show('xml', 1);
1391 $this->assertXml($result, 'statuses');
1395 * Test the api_get_last_status() function
1397 public function testApiGetLastStatus()
1399 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1401 $this->assertNotNull($item);
1405 * Test the api_users_show() function.
1409 public function testApiUsersShow()
1411 $result = api_users_show('json');
1412 // We can't use assertSelfUser() here because the user object is missing some properties.
1413 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1414 $this->assertEquals('DFRN', $result['user']['location']);
1415 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1416 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1417 $this->assertEquals('dfrn', $result['user']['network']);
1418 $this->assertTrue($result['user']['verified']);
1422 * Test the api_users_show() function with an XML result.
1426 public function testApiUsersShowWithXml()
1428 $result = api_users_show('xml');
1429 $this->assertXml($result, 'statuses');
1433 * Test the api_users_search() function.
1437 public function testApiUsersSearch()
1439 $_GET['q'] = 'othercontact';
1440 $result = api_users_search('json');
1441 $this->assertOtherUser($result['users'][0]);
1445 * Test the api_users_search() function with an XML result.
1449 public function testApiUsersSearchWithXml()
1451 $_GET['q'] = 'othercontact';
1452 $result = api_users_search('xml');
1453 $this->assertXml($result, 'users');
1457 * Test the api_users_search() function without a GET q parameter.
1460 * @expectedException Friendica\Network\HTTPException\BadRequestException
1462 public function testApiUsersSearchWithoutQuery()
1464 api_users_search('json');
1468 * Test the api_users_lookup() function.
1471 * @expectedException Friendica\Network\HTTPException\NotFoundException
1473 public function testApiUsersLookup()
1475 api_users_lookup('json');
1479 * Test the api_users_lookup() function with an user ID.
1483 public function testApiUsersLookupWithUserId()
1485 $_REQUEST['user_id'] = $this->otherUser['id'];
1486 $result = api_users_lookup('json');
1487 $this->assertOtherUser($result['users'][0]);
1491 * Test the api_search() function.
1495 public function testApiSearch()
1497 $_REQUEST['q'] = 'reply';
1498 $_REQUEST['max_id'] = 10;
1499 $result = api_search('json');
1500 foreach ($result['status'] as $status) {
1501 $this->assertStatus($status);
1502 $this->assertContains('reply', $status['text'], null, true);
1507 * Test the api_search() function a count parameter.
1511 public function testApiSearchWithCount()
1513 $_REQUEST['q'] = 'reply';
1514 $_REQUEST['count'] = 20;
1515 $result = api_search('json');
1516 foreach ($result['status'] as $status) {
1517 $this->assertStatus($status);
1518 $this->assertContains('reply', $status['text'], null, true);
1523 * Test the api_search() function with an rpp parameter.
1527 public function testApiSearchWithRpp()
1529 $_REQUEST['q'] = 'reply';
1530 $_REQUEST['rpp'] = 20;
1531 $result = api_search('json');
1532 foreach ($result['status'] as $status) {
1533 $this->assertStatus($status);
1534 $this->assertContains('reply', $status['text'], null, true);
1539 * Test the api_search() function with an q parameter contains hashtag.
1543 public function testApiSearchWithHashtag()
1545 $_REQUEST['q'] = '%23friendica';
1546 $result = api_search('json');
1547 foreach ($result['status'] as $status) {
1548 $this->assertStatus($status);
1549 $this->assertContains('#friendica', $status['text'], null, true);
1554 * Test the api_search() function with an exclude_replies parameter.
1558 public function testApiSearchWithExcludeReplies()
1560 $_REQUEST['max_id'] = 10;
1561 $_REQUEST['exclude_replies'] = true;
1562 $_REQUEST['q'] = 'friendica';
1563 $result = api_search('json');
1564 foreach ($result['status'] as $status) {
1565 $this->assertStatus($status);
1570 * Test the api_search() function without an authenticated user.
1573 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1575 public function testApiSearchWithUnallowedUser()
1577 $_SESSION['allow_api'] = false;
1578 $_GET['screen_name'] = $this->selfUser['nick'];
1583 * Test the api_search() function without any GET query parameter.
1586 * @expectedException Friendica\Network\HTTPException\BadRequestException
1588 public function testApiSearchWithoutQuery()
1594 * Test the api_statuses_home_timeline() function.
1598 public function testApiStatusesHomeTimeline()
1600 $_REQUEST['max_id'] = 10;
1601 $_REQUEST['exclude_replies'] = true;
1602 $_REQUEST['conversation_id'] = 1;
1603 $result = api_statuses_home_timeline('json');
1604 $this->assertNotEmpty($result['status']);
1605 foreach ($result['status'] as $status) {
1606 $this->assertStatus($status);
1611 * Test the api_statuses_home_timeline() function with a negative page parameter.
1615 public function testApiStatusesHomeTimelineWithNegativePage()
1617 $_REQUEST['page'] = -2;
1618 $result = api_statuses_home_timeline('json');
1619 $this->assertNotEmpty($result['status']);
1620 foreach ($result['status'] as $status) {
1621 $this->assertStatus($status);
1626 * Test the api_statuses_home_timeline() with an unallowed user.
1629 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1631 public function testApiStatusesHomeTimelineWithUnallowedUser()
1633 $_SESSION['allow_api'] = false;
1634 $_GET['screen_name'] = $this->selfUser['nick'];
1635 api_statuses_home_timeline('json');
1639 * Test the api_statuses_home_timeline() function with an RSS result.
1643 public function testApiStatusesHomeTimelineWithRss()
1645 $result = api_statuses_home_timeline('rss');
1646 $this->assertXml($result, 'statuses');
1650 * Test the api_statuses_public_timeline() function.
1654 public function testApiStatusesPublicTimeline()
1656 $_REQUEST['max_id'] = 10;
1657 $_REQUEST['conversation_id'] = 1;
1658 $result = api_statuses_public_timeline('json');
1659 $this->assertNotEmpty($result['status']);
1660 foreach ($result['status'] as $status) {
1661 $this->assertStatus($status);
1666 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1670 public function testApiStatusesPublicTimelineWithExcludeReplies()
1672 $_REQUEST['max_id'] = 10;
1673 $_REQUEST['exclude_replies'] = true;
1674 $result = api_statuses_public_timeline('json');
1675 $this->assertNotEmpty($result['status']);
1676 foreach ($result['status'] as $status) {
1677 $this->assertStatus($status);
1682 * Test the api_statuses_public_timeline() function with a negative page parameter.
1686 public function testApiStatusesPublicTimelineWithNegativePage()
1688 $_REQUEST['page'] = -2;
1689 $result = api_statuses_public_timeline('json');
1690 $this->assertNotEmpty($result['status']);
1691 foreach ($result['status'] as $status) {
1692 $this->assertStatus($status);
1697 * Test the api_statuses_public_timeline() function with an unallowed user.
1700 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1702 public function testApiStatusesPublicTimelineWithUnallowedUser()
1704 $_SESSION['allow_api'] = false;
1705 $_GET['screen_name'] = $this->selfUser['nick'];
1706 api_statuses_public_timeline('json');
1710 * Test the api_statuses_public_timeline() function with an RSS result.
1714 public function testApiStatusesPublicTimelineWithRss()
1716 $result = api_statuses_public_timeline('rss');
1717 $this->assertXml($result, 'statuses');
1721 * Test the api_statuses_networkpublic_timeline() function.
1725 public function testApiStatusesNetworkpublicTimeline()
1727 $_REQUEST['max_id'] = 10;
1728 $result = api_statuses_networkpublic_timeline('json');
1729 $this->assertNotEmpty($result['status']);
1730 foreach ($result['status'] as $status) {
1731 $this->assertStatus($status);
1736 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1740 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1742 $_REQUEST['page'] = -2;
1743 $result = api_statuses_networkpublic_timeline('json');
1744 $this->assertNotEmpty($result['status']);
1745 foreach ($result['status'] as $status) {
1746 $this->assertStatus($status);
1751 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1754 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1756 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1758 $_SESSION['allow_api'] = false;
1759 $_GET['screen_name'] = $this->selfUser['nick'];
1760 api_statuses_networkpublic_timeline('json');
1764 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1768 public function testApiStatusesNetworkpublicTimelineWithRss()
1770 $result = api_statuses_networkpublic_timeline('rss');
1771 $this->assertXml($result, 'statuses');
1775 * Test the api_statuses_show() function.
1778 * @expectedException Friendica\Network\HTTPException\BadRequestException
1780 public function testApiStatusesShow()
1782 api_statuses_show('json');
1786 * Test the api_statuses_show() function with an ID.
1790 public function testApiStatusesShowWithId()
1792 $this->app->argv[3] = 1;
1793 $result = api_statuses_show('json');
1794 $this->assertStatus($result['status']);
1798 * Test the api_statuses_show() function with the conversation parameter.
1802 public function testApiStatusesShowWithConversation()
1804 $this->app->argv[3] = 1;
1805 $_REQUEST['conversation'] = 1;
1806 $result = api_statuses_show('json');
1807 $this->assertNotEmpty($result['status']);
1808 foreach ($result['status'] as $status) {
1809 $this->assertStatus($status);
1814 * Test the api_statuses_show() function with an unallowed user.
1817 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1819 public function testApiStatusesShowWithUnallowedUser()
1821 $_SESSION['allow_api'] = false;
1822 $_GET['screen_name'] = $this->selfUser['nick'];
1823 api_statuses_show('json');
1827 * Test the api_conversation_show() function.
1830 * @expectedException Friendica\Network\HTTPException\BadRequestException
1832 public function testApiConversationShow()
1834 api_conversation_show('json');
1838 * Test the api_conversation_show() function with an ID.
1842 public function testApiConversationShowWithId()
1844 $this->app->argv[3] = 1;
1845 $_REQUEST['max_id'] = 10;
1846 $_REQUEST['page'] = -2;
1847 $result = api_conversation_show('json');
1848 $this->assertNotEmpty($result['status']);
1849 foreach ($result['status'] as $status) {
1850 $this->assertStatus($status);
1855 * Test the api_conversation_show() function with an unallowed user.
1858 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1860 public function testApiConversationShowWithUnallowedUser()
1862 $_SESSION['allow_api'] = false;
1863 $_GET['screen_name'] = $this->selfUser['nick'];
1864 api_conversation_show('json');
1868 * Test the api_statuses_repeat() function.
1871 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1873 public function testApiStatusesRepeat()
1875 api_statuses_repeat('json');
1879 * Test the api_statuses_repeat() function without an authenticated user.
1882 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1884 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1886 $_SESSION['authenticated'] = false;
1887 api_statuses_repeat('json');
1891 * Test the api_statuses_repeat() function with an ID.
1895 public function testApiStatusesRepeatWithId()
1897 $this->app->argv[3] = 1;
1898 $result = api_statuses_repeat('json');
1899 $this->assertStatus($result['status']);
1901 // Also test with a shared status
1902 $this->app->argv[3] = 5;
1903 $result = api_statuses_repeat('json');
1904 $this->assertStatus($result['status']);
1908 * Test the api_statuses_destroy() function.
1911 * @expectedException Friendica\Network\HTTPException\BadRequestException
1913 public function testApiStatusesDestroy()
1915 api_statuses_destroy('json');
1919 * Test the api_statuses_destroy() function without an authenticated user.
1922 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1924 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1926 $_SESSION['authenticated'] = false;
1927 api_statuses_destroy('json');
1931 * Test the api_statuses_destroy() function with an ID.
1935 public function testApiStatusesDestroyWithId()
1937 $this->app->argv[3] = 1;
1938 $result = api_statuses_destroy('json');
1939 $this->assertStatus($result['status']);
1943 * Test the api_statuses_mentions() function.
1947 public function testApiStatusesMentions()
1949 $this->app->user = ['nickname' => $this->selfUser['nick']];
1950 $_REQUEST['max_id'] = 10;
1951 $result = api_statuses_mentions('json');
1952 $this->assertEmpty($result['status']);
1953 // We should test with mentions in the database.
1957 * Test the api_statuses_mentions() function with a negative page parameter.
1961 public function testApiStatusesMentionsWithNegativePage()
1963 $_REQUEST['page'] = -2;
1964 $result = api_statuses_mentions('json');
1965 $this->assertEmpty($result['status']);
1969 * Test the api_statuses_mentions() function with an unallowed user.
1972 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1974 public function testApiStatusesMentionsWithUnallowedUser()
1976 $_SESSION['allow_api'] = false;
1977 $_GET['screen_name'] = $this->selfUser['nick'];
1978 api_statuses_mentions('json');
1982 * Test the api_statuses_mentions() function with an RSS result.
1986 public function testApiStatusesMentionsWithRss()
1988 $result = api_statuses_mentions('rss');
1989 $this->assertXml($result, 'statuses');
1993 * Test the api_statuses_user_timeline() function.
1997 public function testApiStatusesUserTimeline()
1999 $_REQUEST['max_id'] = 10;
2000 $_REQUEST['exclude_replies'] = true;
2001 $_REQUEST['conversation_id'] = 1;
2002 $result = api_statuses_user_timeline('json');
2003 $this->assertNotEmpty($result['status']);
2004 foreach ($result['status'] as $status) {
2005 $this->assertStatus($status);
2010 * Test the api_statuses_user_timeline() function with a negative page parameter.
2014 public function testApiStatusesUserTimelineWithNegativePage()
2016 $_REQUEST['page'] = -2;
2017 $result = api_statuses_user_timeline('json');
2018 $this->assertNotEmpty($result['status']);
2019 foreach ($result['status'] as $status) {
2020 $this->assertStatus($status);
2025 * Test the api_statuses_user_timeline() function with an RSS result.
2029 public function testApiStatusesUserTimelineWithRss()
2031 $result = api_statuses_user_timeline('rss');
2032 $this->assertXml($result, 'statuses');
2036 * Test the api_statuses_user_timeline() function with an unallowed user.
2039 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2041 public function testApiStatusesUserTimelineWithUnallowedUser()
2043 $_SESSION['allow_api'] = false;
2044 $_GET['screen_name'] = $this->selfUser['nick'];
2045 api_statuses_user_timeline('json');
2049 * Test the api_favorites_create_destroy() function.
2052 * @expectedException Friendica\Network\HTTPException\BadRequestException
2054 public function testApiFavoritesCreateDestroy()
2056 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2057 $this->app->argc = count($this->app->argv);
2058 api_favorites_create_destroy('json');
2062 * Test the api_favorites_create_destroy() function with an invalid ID.
2065 * @expectedException Friendica\Network\HTTPException\BadRequestException
2067 public function testApiFavoritesCreateDestroyWithInvalidId()
2069 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2070 $this->app->argc = count($this->app->argv);
2071 api_favorites_create_destroy('json');
2075 * Test the api_favorites_create_destroy() function with an invalid action.
2078 * @expectedException Friendica\Network\HTTPException\BadRequestException
2080 public function testApiFavoritesCreateDestroyWithInvalidAction()
2082 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2083 $this->app->argc = count($this->app->argv);
2084 $_REQUEST['id'] = 1;
2085 api_favorites_create_destroy('json');
2089 * Test the api_favorites_create_destroy() function with the create action.
2093 public function testApiFavoritesCreateDestroyWithCreateAction()
2095 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2096 $this->app->argc = count($this->app->argv);
2097 $_REQUEST['id'] = 3;
2098 $result = api_favorites_create_destroy('json');
2099 $this->assertStatus($result['status']);
2103 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2107 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2109 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2110 $this->app->argc = count($this->app->argv);
2111 $_REQUEST['id'] = 3;
2112 $result = api_favorites_create_destroy('rss');
2113 $this->assertXml($result, 'status');
2117 * Test the api_favorites_create_destroy() function with the destroy action.
2121 public function testApiFavoritesCreateDestroyWithDestroyAction()
2123 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2124 $this->app->argc = count($this->app->argv);
2125 $_REQUEST['id'] = 3;
2126 $result = api_favorites_create_destroy('json');
2127 $this->assertStatus($result['status']);
2131 * Test the api_favorites_create_destroy() function without an authenticated user.
2134 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2136 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2138 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2139 $this->app->argc = count($this->app->argv);
2140 $_SESSION['authenticated'] = false;
2141 api_favorites_create_destroy('json');
2145 * Test the api_favorites() function.
2149 public function testApiFavorites()
2151 $_REQUEST['page'] = -1;
2152 $_REQUEST['max_id'] = 10;
2153 $result = api_favorites('json');
2154 foreach ($result['status'] as $status) {
2155 $this->assertStatus($status);
2160 * Test the api_favorites() function with an RSS result.
2164 public function testApiFavoritesWithRss()
2166 $result = api_favorites('rss');
2167 $this->assertXml($result, 'statuses');
2171 * Test the api_favorites() function with an unallowed user.
2174 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2176 public function testApiFavoritesWithUnallowedUser()
2178 $_SESSION['allow_api'] = false;
2179 $_GET['screen_name'] = $this->selfUser['nick'];
2180 api_favorites('json');
2184 * Test the api_format_messages() function.
2188 public function testApiFormatMessages()
2190 $result = api_format_messages(
2191 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2192 ['id' => 2, 'screen_name' => 'recipient_name'],
2193 ['id' => 3, 'screen_name' => 'sender_name']
2195 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2196 $this->assertEquals(1, $result['id']);
2197 $this->assertEquals(2, $result['recipient_id']);
2198 $this->assertEquals(3, $result['sender_id']);
2199 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2200 $this->assertEquals('sender_name', $result['sender_screen_name']);
2204 * Test the api_format_messages() function with HTML.
2208 public function testApiFormatMessagesWithHtmlText()
2210 $_GET['getText'] = 'html';
2211 $result = api_format_messages(
2212 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2213 ['id' => 2, 'screen_name' => 'recipient_name'],
2214 ['id' => 3, 'screen_name' => 'sender_name']
2216 $this->assertEquals('item_title', $result['title']);
2217 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2221 * Test the api_format_messages() function with plain text.
2225 public function testApiFormatMessagesWithPlainText()
2227 $_GET['getText'] = 'plain';
2228 $result = api_format_messages(
2229 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2230 ['id' => 2, 'screen_name' => 'recipient_name'],
2231 ['id' => 3, 'screen_name' => 'sender_name']
2233 $this->assertEquals('item_title', $result['title']);
2234 $this->assertEquals('item_body', $result['text']);
2238 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2242 public function testApiFormatMessagesWithoutUserObjects()
2244 $_GET['getUserObjects'] = 'false';
2245 $result = api_format_messages(
2246 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2247 ['id' => 2, 'screen_name' => 'recipient_name'],
2248 ['id' => 3, 'screen_name' => 'sender_name']
2250 $this->assertTrue(!isset($result['sender']));
2251 $this->assertTrue(!isset($result['recipient']));
2255 * Test the api_convert_item() function.
2259 public function testApiConvertItem()
2261 $result = api_convert_item(
2263 'network' => 'feed',
2264 'title' => 'item_title',
2265 // We need a long string to test that it is correctly cut
2266 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2267 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2268 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2269 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2270 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2271 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2272 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2273 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2274 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2275 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2276 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2277 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2278 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2279 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2280 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2281 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2282 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2283 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2284 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2285 'repellat officia illum quos impedit quam iste esse unde qui ' .
2286 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2287 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2288 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2289 'plink' => 'item_plink'
2292 $this->assertStringStartsWith('item_title', $result['text']);
2293 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2297 * Test the api_convert_item() function with an empty item body.
2301 public function testApiConvertItemWithoutBody()
2303 $result = api_convert_item(
2305 'network' => 'feed',
2306 'title' => 'item_title',
2308 'plink' => 'item_plink'
2311 $this->assertEquals('item_title', $result['text']);
2312 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2316 * Test the api_convert_item() function with the title in the body.
2320 public function testApiConvertItemWithTitleInBody()
2322 $result = api_convert_item(
2324 'title' => 'item_title',
2325 'body' => 'item_title item_body'
2328 $this->assertEquals('item_title item_body', $result['text']);
2329 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2333 * Test the api_get_attachments() function.
2337 public function testApiGetAttachments()
2340 $this->assertEmpty(api_get_attachments($body));
2344 * Test the api_get_attachments() function with an img tag.
2348 public function testApiGetAttachmentsWithImage()
2350 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2351 $this->assertInternalType('array', api_get_attachments($body));
2355 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2359 public function testApiGetAttachmentsWithImageAndAndStatus()
2361 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2362 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2363 $this->assertInternalType('array', api_get_attachments($body));
2367 * Test the api_get_entitities() function.
2371 public function testApiGetEntitities()
2374 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2378 * Test the api_get_entitities() function with the include_entities parameter.
2382 public function testApiGetEntititiesWithIncludeEntities()
2384 $_REQUEST['include_entities'] = 'true';
2386 $result = api_get_entitities($text, 'bbcode');
2387 $this->assertInternalType('array', $result['hashtags']);
2388 $this->assertInternalType('array', $result['symbols']);
2389 $this->assertInternalType('array', $result['urls']);
2390 $this->assertInternalType('array', $result['user_mentions']);
2394 * Test the api_format_items_embeded_images() function.
2398 public function testApiFormatItemsEmbededImages()
2400 $this->assertEquals(
2401 'text ' . System::baseUrl() . '/display/item_guid',
2402 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2407 * Test the api_contactlink_to_array() function.
2411 public function testApiContactlinkToArray()
2413 $this->assertEquals(
2418 api_contactlink_to_array('text')
2423 * Test the api_contactlink_to_array() function with an URL.
2427 public function testApiContactlinkToArrayWithUrl()
2429 $this->assertEquals(
2431 'name' => ['link_text'],
2434 api_contactlink_to_array('text <a href="url">link_text</a>')
2439 * Test the api_format_items_activities() function.
2443 public function testApiFormatItemsActivities()
2445 $item = ['uid' => 0, 'uri' => ''];
2446 $result = api_format_items_activities($item);
2447 $this->assertArrayHasKey('like', $result);
2448 $this->assertArrayHasKey('dislike', $result);
2449 $this->assertArrayHasKey('attendyes', $result);
2450 $this->assertArrayHasKey('attendno', $result);
2451 $this->assertArrayHasKey('attendmaybe', $result);
2455 * Test the api_format_items_activities() function with an XML result.
2459 public function testApiFormatItemsActivitiesWithXml()
2461 $item = ['uid' => 0, 'uri' => ''];
2462 $result = api_format_items_activities($item, 'xml');
2463 $this->assertArrayHasKey('friendica:like', $result);
2464 $this->assertArrayHasKey('friendica:dislike', $result);
2465 $this->assertArrayHasKey('friendica:attendyes', $result);
2466 $this->assertArrayHasKey('friendica:attendno', $result);
2467 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2471 * Test the api_format_items_profiles() function.
2475 public function testApiFormatItemsProfiles()
2478 'id' => 'profile_id',
2479 'profile-name' => 'profile_name',
2480 'is-default' => true,
2481 'hide-friends' => true,
2482 'photo' => 'profile_photo',
2483 'thumb' => 'profile_thumb',
2485 'net-publish' => true,
2486 'pdesc' => 'description',
2487 'dob' => 'date_of_birth',
2488 'address' => 'address',
2489 'locality' => 'city',
2490 'region' => 'region',
2491 'postal-code' => 'postal_code',
2492 'country-name' => 'country',
2493 'hometown' => 'hometown',
2494 'gender' => 'gender',
2495 'marital' => 'marital',
2496 'with' => 'marital_with',
2497 'howlong' => 'marital_since',
2498 'sexual' => 'sexual',
2499 'politic' => 'politic',
2500 'religion' => 'religion',
2501 'pub_keywords' => 'public_keywords',
2502 'prv_keywords' => 'private_keywords',
2505 'dislikes' => 'dislikes',
2511 'interest' => 'interest',
2512 'romance' => 'romance',
2514 'education' => 'education',
2515 'contact' => 'social_networks',
2516 'homepage' => 'homepage'
2518 $result = api_format_items_profiles($profile_row);
2519 $this->assertEquals(
2521 'profile_id' => 'profile_id',
2522 'profile_name' => 'profile_name',
2523 'is_default' => true,
2524 'hide_friends' => true,
2525 'profile_photo' => 'profile_photo',
2526 'profile_thumb' => 'profile_thumb',
2528 'net_publish' => true,
2529 'description' => 'description',
2530 'date_of_birth' => 'date_of_birth',
2531 'address' => 'address',
2533 'region' => 'region',
2534 'postal_code' => 'postal_code',
2535 'country' => 'country',
2536 'hometown' => 'hometown',
2537 'gender' => 'gender',
2538 'marital' => 'marital',
2539 'marital_with' => 'marital_with',
2540 'marital_since' => 'marital_since',
2541 'sexual' => 'sexual',
2542 'politic' => 'politic',
2543 'religion' => 'religion',
2544 'public_keywords' => 'public_keywords',
2545 'private_keywords' => 'private_keywords',
2548 'dislikes' => 'dislikes',
2554 'interest' => 'interest',
2555 'romance' => 'romance',
2557 'education' => 'education',
2558 'social_networks' => 'social_networks',
2559 'homepage' => 'homepage',
2567 * Test the api_format_items() function.
2571 public function testApiFormatItems()
2575 'item_network' => 'item_network',
2581 'author-network' => Protocol::DFRN,
2582 'author-link' => 'http://localhost/profile/othercontact',
2586 $result = api_format_items($items, ['id' => 0], true);
2587 foreach ($result as $status) {
2588 $this->assertStatus($status);
2593 * Test the api_format_items() function with an XML result.
2597 public function testApiFormatItemsWithXml()
2605 'author-network' => Protocol::DFRN,
2606 'author-link' => 'http://localhost/profile/othercontact',
2610 $result = api_format_items($items, ['id' => 0], true, 'xml');
2611 foreach ($result as $status) {
2612 $this->assertStatus($status);
2617 * Test the api_format_items() function.
2621 public function testApiAccountRateLimitStatus()
2623 $result = api_account_rate_limit_status('json');
2624 $this->assertEquals(150, $result['hash']['remaining_hits']);
2625 $this->assertEquals(150, $result['hash']['hourly_limit']);
2626 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2630 * Test the api_format_items() function with an XML result.
2634 public function testApiAccountRateLimitStatusWithXml()
2636 $result = api_account_rate_limit_status('xml');
2637 $this->assertXml($result, 'hash');
2641 * Test the api_help_test() function.
2645 public function testApiHelpTest()
2647 $result = api_help_test('json');
2648 $this->assertEquals(['ok' => 'ok'], $result);
2652 * Test the api_help_test() function with an XML result.
2656 public function testApiHelpTestWithXml()
2658 $result = api_help_test('xml');
2659 $this->assertXml($result, 'ok');
2663 * Test the api_lists_list() function.
2667 public function testApiListsList()
2669 $result = api_lists_list('json');
2670 $this->assertEquals(['lists_list' => []], $result);
2674 * Test the api_lists_ownerships() function.
2678 public function testApiListsOwnerships()
2680 $result = api_lists_ownerships('json');
2681 foreach ($result['lists']['lists'] as $list) {
2682 $this->assertList($list);
2687 * Test the api_lists_ownerships() function without an authenticated user.
2690 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2692 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2694 $_SESSION['authenticated'] = false;
2695 api_lists_ownerships('json');
2699 * Test the api_lists_statuses() function.
2701 * @expectedException Friendica\Network\HTTPException\BadRequestException
2704 public function testApiListsStatuses()
2706 api_lists_statuses('json');
2710 * Test the api_lists_statuses() function with a list ID.
2714 public function testApiListsStatusesWithListId()
2716 $_REQUEST['list_id'] = 1;
2717 $_REQUEST['page'] = -1;
2718 $_REQUEST['max_id'] = 10;
2719 $result = api_lists_statuses('json');
2720 foreach ($result['status'] as $status) {
2721 $this->assertStatus($status);
2726 * Test the api_lists_statuses() function with a list ID and a RSS result.
2730 public function testApiListsStatusesWithListIdAndRss()
2732 $_REQUEST['list_id'] = 1;
2733 $result = api_lists_statuses('rss');
2734 $this->assertXml($result, 'statuses');
2738 * Test the api_lists_statuses() function with an unallowed user.
2741 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2743 public function testApiListsStatusesWithUnallowedUser()
2745 $_SESSION['allow_api'] = false;
2746 $_GET['screen_name'] = $this->selfUser['nick'];
2747 api_lists_statuses('json');
2751 * Test the api_statuses_f() function.
2755 public function testApiStatusesFWithFriends()
2758 $result = api_statuses_f('friends');
2759 $this->assertArrayHasKey('user', $result);
2763 * Test the api_statuses_f() function.
2767 public function testApiStatusesFWithFollowers()
2769 $result = api_statuses_f('followers');
2770 $this->assertArrayHasKey('user', $result);
2774 * Test the api_statuses_f() function.
2778 public function testApiStatusesFWithBlocks()
2780 $result = api_statuses_f('blocks');
2781 $this->assertArrayHasKey('user', $result);
2785 * Test the api_statuses_f() function.
2789 public function testApiStatusesFWithIncoming()
2791 $result = api_statuses_f('incoming');
2792 $this->assertArrayHasKey('user', $result);
2796 * Test the api_statuses_f() function an undefined cursor GET variable.
2800 public function testApiStatusesFWithUndefinedCursor()
2802 $_GET['cursor'] = 'undefined';
2803 $this->assertFalse(api_statuses_f('friends'));
2807 * Test the api_statuses_friends() function.
2811 public function testApiStatusesFriends()
2813 $result = api_statuses_friends('json');
2814 $this->assertArrayHasKey('user', $result);
2818 * Test the api_statuses_friends() function an undefined cursor GET variable.
2822 public function testApiStatusesFriendsWithUndefinedCursor()
2824 $_GET['cursor'] = 'undefined';
2825 $this->assertFalse(api_statuses_friends('json'));
2829 * Test the api_statuses_followers() function.
2833 public function testApiStatusesFollowers()
2835 $result = api_statuses_followers('json');
2836 $this->assertArrayHasKey('user', $result);
2840 * Test the api_statuses_followers() function an undefined cursor GET variable.
2844 public function testApiStatusesFollowersWithUndefinedCursor()
2846 $_GET['cursor'] = 'undefined';
2847 $this->assertFalse(api_statuses_followers('json'));
2851 * Test the api_blocks_list() function.
2855 public function testApiBlocksList()
2857 $result = api_blocks_list('json');
2858 $this->assertArrayHasKey('user', $result);
2862 * Test the api_blocks_list() function an undefined cursor GET variable.
2866 public function testApiBlocksListWithUndefinedCursor()
2868 $_GET['cursor'] = 'undefined';
2869 $this->assertFalse(api_blocks_list('json'));
2873 * Test the api_friendships_incoming() function.
2877 public function testApiFriendshipsIncoming()
2879 $result = api_friendships_incoming('json');
2880 $this->assertArrayHasKey('id', $result);
2884 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2888 public function testApiFriendshipsIncomingWithUndefinedCursor()
2890 $_GET['cursor'] = 'undefined';
2891 $this->assertFalse(api_friendships_incoming('json'));
2895 * Test the api_statusnet_config() function.
2899 public function testApiStatusnetConfig()
2901 $result = api_statusnet_config('json');
2902 $this->assertEquals('localhost', $result['config']['site']['server']);
2903 $this->assertEquals('default', $result['config']['site']['theme']);
2904 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2905 $this->assertTrue($result['config']['site']['fancy']);
2906 $this->assertEquals('en', $result['config']['site']['language']);
2907 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2908 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2909 $this->assertEquals('false', $result['config']['site']['private']);
2910 $this->assertEquals('false', $result['config']['site']['ssl']);
2911 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2915 * Test the api_statusnet_version() function.
2919 public function testApiStatusnetVersion()
2921 $result = api_statusnet_version('json');
2922 $this->assertEquals('0.9.7', $result['version']);
2926 * Test the api_ff_ids() function.
2930 public function testApiFfIds()
2932 $result = api_ff_ids('json', Contact::FOLLOWER);
2933 $this->assertEquals(['id' => []], $result);
2937 * Test the api_ff_ids() function with a result.
2941 public function testApiFfIdsWithResult()
2943 $this->markTestIncomplete();
2947 * Test the api_ff_ids() function without an authenticated user.
2950 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2952 public function testApiFfIdsWithoutAuthenticatedUser()
2954 $_SESSION['authenticated'] = false;
2955 api_ff_ids('json', Contact::FOLLOWER);
2959 * Test the api_friends_ids() function.
2963 public function testApiFriendsIds()
2965 $result = api_friends_ids('json');
2966 $this->assertEquals(['id' => []], $result);
2970 * Test the api_followers_ids() function.
2974 public function testApiFollowersIds()
2976 $result = api_followers_ids('json');
2977 $this->assertEquals(['id' => []], $result);
2981 * Test the api_direct_messages_new() function.
2985 public function testApiDirectMessagesNew()
2987 $result = api_direct_messages_new('json');
2988 $this->assertNull($result);
2992 * Test the api_direct_messages_new() function without an authenticated user.
2995 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2997 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2999 $_SESSION['authenticated'] = false;
3000 api_direct_messages_new('json');
3004 * Test the api_direct_messages_new() function with an user ID.
3008 public function testApiDirectMessagesNewWithUserId()
3010 $_POST['text'] = 'message_text';
3011 $_POST['user_id'] = $this->otherUser['id'];
3012 $result = api_direct_messages_new('json');
3013 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3017 * Test the api_direct_messages_new() function with a screen name.
3021 public function testApiDirectMessagesNewWithScreenName()
3023 $_POST['text'] = 'message_text';
3024 $_POST['screen_name'] = $this->friendUser['nick'];
3025 $result = api_direct_messages_new('json');
3026 $this->assertContains('message_text', $result['direct_message']['text']);
3027 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3028 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3032 * Test the api_direct_messages_new() function with a title.
3036 public function testApiDirectMessagesNewWithTitle()
3038 $_POST['text'] = 'message_text';
3039 $_POST['screen_name'] = $this->friendUser['nick'];
3040 $_REQUEST['title'] = 'message_title';
3041 $result = api_direct_messages_new('json');
3042 $this->assertContains('message_text', $result['direct_message']['text']);
3043 $this->assertContains('message_title', $result['direct_message']['text']);
3044 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3045 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3049 * Test the api_direct_messages_new() function with an RSS result.
3053 public function testApiDirectMessagesNewWithRss()
3055 $_POST['text'] = 'message_text';
3056 $_POST['screen_name'] = $this->friendUser['nick'];
3057 $result = api_direct_messages_new('rss');
3058 $this->assertXml($result, 'direct-messages');
3062 * Test the api_direct_messages_destroy() function.
3065 * @expectedException Friendica\Network\HTTPException\BadRequestException
3067 public function testApiDirectMessagesDestroy()
3069 api_direct_messages_destroy('json');
3073 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3077 public function testApiDirectMessagesDestroyWithVerbose()
3079 $_GET['friendica_verbose'] = 'true';
3080 $result = api_direct_messages_destroy('json');
3081 $this->assertEquals(
3084 'result' => 'error',
3085 'message' => 'message id or parenturi not specified'
3093 * Test the api_direct_messages_destroy() function without an authenticated user.
3096 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3098 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3100 $_SESSION['authenticated'] = false;
3101 api_direct_messages_destroy('json');
3105 * Test the api_direct_messages_destroy() function with a non-zero ID.
3108 * @expectedException Friendica\Network\HTTPException\BadRequestException
3110 public function testApiDirectMessagesDestroyWithId()
3112 $_REQUEST['id'] = 1;
3113 api_direct_messages_destroy('json');
3117 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3121 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3123 $_REQUEST['id'] = 1;
3124 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3125 $_GET['friendica_verbose'] = 'true';
3126 $result = api_direct_messages_destroy('json');
3127 $this->assertEquals(
3130 'result' => 'error',
3131 'message' => 'message id not in database'
3139 * Test the api_direct_messages_destroy() function with a non-zero ID.
3143 public function testApiDirectMessagesDestroyWithCorrectId()
3145 $this->markTestIncomplete('We need to add a dataset for this.');
3149 * Test the api_direct_messages_box() function.
3153 public function testApiDirectMessagesBoxWithSentbox()
3155 $_REQUEST['page'] = -1;
3156 $_REQUEST['max_id'] = 10;
3157 $result = api_direct_messages_box('json', 'sentbox', 'false');
3158 $this->assertArrayHasKey('direct_message', $result);
3162 * Test the api_direct_messages_box() function.
3166 public function testApiDirectMessagesBoxWithConversation()
3168 $result = api_direct_messages_box('json', 'conversation', 'false');
3169 $this->assertArrayHasKey('direct_message', $result);
3173 * Test the api_direct_messages_box() function.
3177 public function testApiDirectMessagesBoxWithAll()
3179 $result = api_direct_messages_box('json', 'all', 'false');
3180 $this->assertArrayHasKey('direct_message', $result);
3184 * Test the api_direct_messages_box() function.
3188 public function testApiDirectMessagesBoxWithInbox()
3190 $result = api_direct_messages_box('json', 'inbox', 'false');
3191 $this->assertArrayHasKey('direct_message', $result);
3195 * Test the api_direct_messages_box() function.
3199 public function testApiDirectMessagesBoxWithVerbose()
3201 $result = api_direct_messages_box('json', 'sentbox', 'true');
3202 $this->assertEquals(
3205 'result' => 'error',
3206 'message' => 'no mails available'
3214 * Test the api_direct_messages_box() function with a RSS result.
3218 public function testApiDirectMessagesBoxWithRss()
3220 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3221 $this->assertXml($result, 'direct-messages');
3225 * Test the api_direct_messages_box() function without an authenticated user.
3228 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3230 public function testApiDirectMessagesBoxWithUnallowedUser()
3232 $_SESSION['allow_api'] = false;
3233 $_GET['screen_name'] = $this->selfUser['nick'];
3234 api_direct_messages_box('json', 'sentbox', 'false');
3238 * Test the api_direct_messages_sentbox() function.
3242 public function testApiDirectMessagesSentbox()
3244 $result = api_direct_messages_sentbox('json');
3245 $this->assertArrayHasKey('direct_message', $result);
3249 * Test the api_direct_messages_inbox() function.
3253 public function testApiDirectMessagesInbox()
3255 $result = api_direct_messages_inbox('json');
3256 $this->assertArrayHasKey('direct_message', $result);
3260 * Test the api_direct_messages_all() function.
3264 public function testApiDirectMessagesAll()
3266 $result = api_direct_messages_all('json');
3267 $this->assertArrayHasKey('direct_message', $result);
3271 * Test the api_direct_messages_conversation() function.
3275 public function testApiDirectMessagesConversation()
3277 $result = api_direct_messages_conversation('json');
3278 $this->assertArrayHasKey('direct_message', $result);
3282 * Test the api_oauth_request_token() function.
3286 public function testApiOauthRequestToken()
3288 $this->markTestIncomplete('killme() kills phpunit as well');
3292 * Test the api_oauth_access_token() function.
3296 public function testApiOauthAccessToken()
3298 $this->markTestIncomplete('killme() kills phpunit as well');
3302 * Test the api_fr_photoalbum_delete() function.
3305 * @expectedException Friendica\Network\HTTPException\BadRequestException
3307 public function testApiFrPhotoalbumDelete()
3309 api_fr_photoalbum_delete('json');
3313 * Test the api_fr_photoalbum_delete() function with an album name.
3316 * @expectedException Friendica\Network\HTTPException\BadRequestException
3318 public function testApiFrPhotoalbumDeleteWithAlbum()
3320 $_REQUEST['album'] = 'album_name';
3321 api_fr_photoalbum_delete('json');
3325 * Test the api_fr_photoalbum_delete() function with an album name.
3329 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3331 $this->markTestIncomplete('We need to add a dataset for this.');
3335 * Test the api_fr_photoalbum_delete() function.
3338 * @expectedException Friendica\Network\HTTPException\BadRequestException
3340 public function testApiFrPhotoalbumUpdate()
3342 api_fr_photoalbum_update('json');
3346 * Test the api_fr_photoalbum_delete() function with an album name.
3349 * @expectedException Friendica\Network\HTTPException\BadRequestException
3351 public function testApiFrPhotoalbumUpdateWithAlbum()
3353 $_REQUEST['album'] = 'album_name';
3354 api_fr_photoalbum_update('json');
3358 * Test the api_fr_photoalbum_delete() function with an album name.
3361 * @expectedException Friendica\Network\HTTPException\BadRequestException
3363 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3365 $_REQUEST['album'] = 'album_name';
3366 $_REQUEST['album_new'] = 'album_name';
3367 api_fr_photoalbum_update('json');
3371 * Test the api_fr_photoalbum_update() function without an authenticated user.
3374 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3376 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3378 $_SESSION['authenticated'] = false;
3379 api_fr_photoalbum_update('json');
3383 * Test the api_fr_photoalbum_delete() function with an album name.
3387 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3389 $this->markTestIncomplete('We need to add a dataset for this.');
3393 * Test the api_fr_photos_list() function.
3397 public function testApiFrPhotosList()
3399 $result = api_fr_photos_list('json');
3400 $this->assertArrayHasKey('photo', $result);
3404 * Test the api_fr_photos_list() function without an authenticated user.
3407 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3409 public function testApiFrPhotosListWithoutAuthenticatedUser()
3411 $_SESSION['authenticated'] = false;
3412 api_fr_photos_list('json');
3416 * Test the api_fr_photo_create_update() function.
3419 * @expectedException Friendica\Network\HTTPException\BadRequestException
3421 public function testApiFrPhotoCreateUpdate()
3423 api_fr_photo_create_update('json');
3427 * Test the api_fr_photo_create_update() function without an authenticated user.
3430 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3432 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3434 $_SESSION['authenticated'] = false;
3435 api_fr_photo_create_update('json');
3439 * Test the api_fr_photo_create_update() function with an album name.
3442 * @expectedException Friendica\Network\HTTPException\BadRequestException
3444 public function testApiFrPhotoCreateUpdateWithAlbum()
3446 $_REQUEST['album'] = 'album_name';
3447 api_fr_photo_create_update('json');
3451 * Test the api_fr_photo_create_update() function with the update mode.
3455 public function testApiFrPhotoCreateUpdateWithUpdate()
3457 $this->markTestIncomplete('We need to create a dataset for this');
3461 * Test the api_fr_photo_create_update() function with an uploaded file.
3465 public function testApiFrPhotoCreateUpdateWithFile()
3467 $this->markTestIncomplete();
3471 * Test the api_fr_photo_delete() function.
3474 * @expectedException Friendica\Network\HTTPException\BadRequestException
3476 public function testApiFrPhotoDelete()
3478 api_fr_photo_delete('json');
3482 * Test the api_fr_photo_delete() function without an authenticated user.
3485 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3487 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3489 $_SESSION['authenticated'] = false;
3490 api_fr_photo_delete('json');
3494 * Test the api_fr_photo_delete() function with a photo ID.
3497 * @expectedException Friendica\Network\HTTPException\BadRequestException
3499 public function testApiFrPhotoDeleteWithPhotoId()
3501 $_REQUEST['photo_id'] = 1;
3502 api_fr_photo_delete('json');
3506 * Test the api_fr_photo_delete() function with a correct photo ID.
3510 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3512 $this->markTestIncomplete('We need to create a dataset for this.');
3516 * Test the api_fr_photo_detail() function.
3519 * @expectedException Friendica\Network\HTTPException\BadRequestException
3521 public function testApiFrPhotoDetail()
3523 api_fr_photo_detail('json');
3527 * Test the api_fr_photo_detail() function without an authenticated user.
3530 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3532 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3534 $_SESSION['authenticated'] = false;
3535 api_fr_photo_detail('json');
3539 * Test the api_fr_photo_detail() function with a photo ID.
3542 * @expectedException Friendica\Network\HTTPException\NotFoundException
3544 public function testApiFrPhotoDetailWithPhotoId()
3546 $_REQUEST['photo_id'] = 1;
3547 api_fr_photo_detail('json');
3551 * Test the api_fr_photo_detail() function with a correct photo ID.
3555 public function testApiFrPhotoDetailCorrectPhotoId()
3557 $this->markTestIncomplete('We need to create a dataset for this.');
3561 * Test the api_account_update_profile_image() function.
3564 * @expectedException Friendica\Network\HTTPException\BadRequestException
3566 public function testApiAccountUpdateProfileImage()
3568 api_account_update_profile_image('json');
3572 * Test the api_account_update_profile_image() function without an authenticated user.
3575 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3577 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3579 $_SESSION['authenticated'] = false;
3580 api_account_update_profile_image('json');
3584 * Test the api_account_update_profile_image() function with an uploaded file.
3587 * @expectedException Friendica\Network\HTTPException\BadRequestException
3589 public function testApiAccountUpdateProfileImageWithUpload()
3591 $this->markTestIncomplete();
3596 * Test the api_account_update_profile() function.
3600 public function testApiAccountUpdateProfile()
3602 $_POST['name'] = 'new_name';
3603 $_POST['description'] = 'new_description';
3604 $result = api_account_update_profile('json');
3605 // We can't use assertSelfUser() here because the user object is missing some properties.
3606 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3607 $this->assertEquals('DFRN', $result['user']['location']);
3608 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3609 $this->assertEquals('dfrn', $result['user']['network']);
3610 $this->assertEquals('new_name', $result['user']['name']);
3611 $this->assertEquals('new_description', $result['user']['description']);
3615 * Test the check_acl_input() function.
3619 public function testCheckAclInput()
3621 $result = check_acl_input('<aclstring>');
3622 // Where does this result come from?
3623 $this->assertEquals(1, $result);
3627 * Test the check_acl_input() function with an empty ACL string.
3631 public function testCheckAclInputWithEmptyAclString()
3633 $result = check_acl_input(' ');
3634 $this->assertFalse($result);
3638 * Test the save_media_to_database() function.
3642 public function testSaveMediaToDatabase()
3644 $this->markTestIncomplete();
3648 * Test the post_photo_item() function.
3652 public function testPostPhotoItem()
3654 $this->markTestIncomplete();
3658 * Test the prepare_photo_data() function.
3662 public function testPreparePhotoData()
3664 $this->markTestIncomplete();
3668 * Test the api_friendica_remoteauth() function.
3671 * @expectedException Friendica\Network\HTTPException\BadRequestException
3673 public function testApiFriendicaRemoteauth()
3675 api_friendica_remoteauth();
3679 * Test the api_friendica_remoteauth() function with an URL.
3682 * @expectedException Friendica\Network\HTTPException\BadRequestException
3684 public function testApiFriendicaRemoteauthWithUrl()
3686 $_GET['url'] = 'url';
3687 $_GET['c_url'] = 'url';
3688 api_friendica_remoteauth();
3692 * Test the api_friendica_remoteauth() function with a correct URL.
3696 public function testApiFriendicaRemoteauthWithCorrectUrl()
3698 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3699 $_GET['url'] = 'url';
3700 $_GET['c_url'] = $this->selfUser['nurl'];
3701 api_friendica_remoteauth();
3705 * Test the api_share_as_retweet() function.
3709 public function testApiShareAsRetweet()
3711 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3712 $result = api_share_as_retweet($item);
3713 $this->assertFalse($result);
3717 * Test the api_share_as_retweet() function with a valid item.
3721 public function testApiShareAsRetweetWithValidItem()
3723 $this->markTestIncomplete();
3727 * Test the api_in_reply_to() function.
3731 public function testApiInReplyTo()
3733 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3734 $this->assertArrayHasKey('status_id', $result);
3735 $this->assertArrayHasKey('user_id', $result);
3736 $this->assertArrayHasKey('status_id_str', $result);
3737 $this->assertArrayHasKey('user_id_str', $result);
3738 $this->assertArrayHasKey('screen_name', $result);
3742 * Test the api_in_reply_to() function with a valid item.
3746 public function testApiInReplyToWithValidItem()
3748 $this->markTestIncomplete();
3752 * Test the api_clean_plain_items() function.
3756 public function testApiCleanPlainItems()
3758 $_REQUEST['include_entities'] = 'true';
3759 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3760 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3764 * Test the api_best_nickname() function.
3768 public function testApiBestNickname()
3771 $result = api_best_nickname($contacts);
3772 $this->assertNull($result);
3776 * Test the api_best_nickname() function with contacts.
3780 public function testApiBestNicknameWithContacts()
3782 $this->markTestIncomplete();
3786 * Test the api_friendica_group_show() function.
3790 public function testApiFriendicaGroupShow()
3792 $this->markTestIncomplete();
3796 * Test the api_friendica_group_delete() function.
3800 public function testApiFriendicaGroupDelete()
3802 $this->markTestIncomplete();
3806 * Test the api_lists_destroy() function.
3810 public function testApiListsDestroy()
3812 $this->markTestIncomplete();
3816 * Test the group_create() function.
3820 public function testGroupCreate()
3822 $this->markTestIncomplete();
3826 * Test the api_friendica_group_create() function.
3830 public function testApiFriendicaGroupCreate()
3832 $this->markTestIncomplete();
3836 * Test the api_lists_create() function.
3840 public function testApiListsCreate()
3842 $this->markTestIncomplete();
3846 * Test the api_friendica_group_update() function.
3850 public function testApiFriendicaGroupUpdate()
3852 $this->markTestIncomplete();
3856 * Test the api_lists_update() function.
3860 public function testApiListsUpdate()
3862 $this->markTestIncomplete();
3866 * Test the api_friendica_activity() function.
3870 public function testApiFriendicaActivity()
3872 $this->markTestIncomplete();
3876 * Test the api_friendica_notification() function.
3879 * @expectedException Friendica\Network\HTTPException\BadRequestException
3881 public function testApiFriendicaNotification()
3883 api_friendica_notification('json');
3887 * Test the api_friendica_notification() function without an authenticated user.
3890 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3892 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3894 $_SESSION['authenticated'] = false;
3895 api_friendica_notification('json');
3899 * Test the api_friendica_notification() function with an argument count.
3903 public function testApiFriendicaNotificationWithArgumentCount()
3905 $this->app->argv = ['api', 'friendica', 'notification'];
3906 $this->app->argc = count($this->app->argv);
3907 $result = api_friendica_notification('json');
3908 $this->assertEquals(['note' => false], $result);
3912 * Test the api_friendica_notification() function with an XML result.
3916 public function testApiFriendicaNotificationWithXmlResult()
3918 $this->app->argv = ['api', 'friendica', 'notification'];
3919 $this->app->argc = count($this->app->argv);
3920 $result = api_friendica_notification('xml');
3921 $this->assertXml($result, 'notes');
3925 * Test the api_friendica_notification_seen() function.
3929 public function testApiFriendicaNotificationSeen()
3931 $this->markTestIncomplete();
3935 * Test the api_friendica_direct_messages_setseen() function.
3939 public function testApiFriendicaDirectMessagesSetseen()
3941 $this->markTestIncomplete();
3945 * Test the api_friendica_direct_messages_search() function.
3949 public function testApiFriendicaDirectMessagesSearch()
3951 $this->markTestIncomplete();
3955 * Test the api_friendica_profile_show() function.
3959 public function testApiFriendicaProfileShow()
3961 $result = api_friendica_profile_show('json');
3962 // We can't use assertSelfUser() here because the user object is missing some properties.
3963 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3964 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3965 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3966 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3967 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3968 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3969 $this->assertFalse($result['$result']['multi_profiles']);
3973 * Test the api_friendica_profile_show() function with a profile ID.
3977 public function testApiFriendicaProfileShowWithProfileId()
3979 $this->markTestIncomplete('We need to add a dataset for this.');
3983 * Test the api_friendica_profile_show() function with a wrong profile ID.
3986 * @expectedException Friendica\Network\HTTPException\BadRequestException
3988 public function testApiFriendicaProfileShowWithWrongProfileId()
3990 $_REQUEST['profile_id'] = 666;
3991 api_friendica_profile_show('json');
3995 * Test the api_friendica_profile_show() function without an authenticated user.
3998 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4000 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4002 $_SESSION['authenticated'] = false;
4003 api_friendica_profile_show('json');
4007 * Test the api_saved_searches_list() function.
4011 public function testApiSavedSearchesList()
4013 $result = api_saved_searches_list('json');
4014 $this->assertEquals(1, $result['terms'][0]['id']);
4015 $this->assertEquals(1, $result['terms'][0]['id_str']);
4016 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4017 $this->assertEquals('Saved search', $result['terms'][0]['query']);