6 namespace Friendica\Test;
10 use Friendica\BaseObject;
11 use Friendica\Core\Config\Configuration;
12 use Friendica\Core\Config\PConfiguration;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\Session\ISession;
15 use Friendica\Core\System;
16 use Friendica\Database\Database;
17 use Friendica\Network\HTTPException;
18 use Friendica\Test\Util\Database\StaticDatabase;
19 use Monolog\Handler\TestHandler;
21 require_once __DIR__ . '/../../include/api.php';
24 * Tests for the API functions.
26 * Functions that use header() need to be tested in a separate process.
27 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
29 class ApiTest extends DatabaseTest
32 * @var TestHandler Can handle log-outputs
39 protected $friendUser;
43 protected $wrongUserId;
48 /** @var Configuration */
55 * Create variables used by tests.
57 protected function setUp()
61 $this->dice = (new Dice())
62 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
63 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
64 BaseObject::setDependencyInjection($this->dice);
66 /** @var Database $dba */
67 $dba = $this->dice->create(Database::class);
69 /** @var Configuration $config */
70 $this->config = $this->dice->create(Configuration::class);
72 $this->config->set('system', 'url', 'http://localhost');
73 $this->config->set('system', 'hostname', 'localhost');
74 $this->config->set('system', 'worker_dont_fork', true);
77 $this->config->set('config', 'hostname', 'localhost');
78 $this->config->set('system', 'throttle_limit_day', 100);
79 $this->config->set('system', 'throttle_limit_week', 100);
80 $this->config->set('system', 'throttle_limit_month', 100);
81 $this->config->set('system', 'theme', 'system_theme');
83 // Load the API dataset for the whole API
84 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
87 $this->app = BaseObject::getApp();
90 $this->app->argv = ['home'];
92 // User data that the test database is populated with
95 'name' => 'Self contact',
96 'nick' => 'selfcontact',
97 'nurl' => 'http://localhost/profile/selfcontact'
101 'name' => 'Friend contact',
102 'nick' => 'friendcontact',
103 'nurl' => 'http://localhost/profile/friendcontact'
107 'name' => 'othercontact',
108 'nick' => 'othercontact',
109 'nurl' => 'http://localhost/profile/othercontact'
112 // User ID that we know is not in the database
113 $this->wrongUserId = 666;
115 /** @var ISession $session */
116 $session = BaseObject::getClass(ISession::class);
119 // Most API require login so we force the session
122 'authenticated' => true,
123 'uid' => $this->selfUser['id']
132 * Assert that an user array contains expected keys.
134 * @param array $user User array
138 private function assertSelfUser(array $user)
140 $this->assertEquals($this->selfUser['id'], $user['uid']);
141 $this->assertEquals($this->selfUser['id'], $user['cid']);
142 $this->assertEquals(1, $user['self']);
143 $this->assertEquals('DFRN', $user['location']);
144 $this->assertEquals($this->selfUser['name'], $user['name']);
145 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
146 $this->assertEquals('dfrn', $user['network']);
147 $this->assertTrue($user['verified']);
151 * Assert that an user array contains expected keys.
153 * @param array $user User array
157 private function assertOtherUser(array $user)
159 $this->assertEquals($this->otherUser['id'], $user['id']);
160 $this->assertEquals($this->otherUser['id'], $user['id_str']);
161 $this->assertEquals(0, $user['self']);
162 $this->assertEquals($this->otherUser['name'], $user['name']);
163 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
164 $this->assertFalse($user['verified']);
168 * Assert that a status array contains expected keys.
170 * @param array $status Status array
174 private function assertStatus(array $status)
176 $this->assertInternalType('string', $status['text']);
177 $this->assertInternalType('int', $status['id']);
178 // We could probably do more checks here.
182 * Assert that a list array contains expected keys.
184 * @param array $list List array
188 private function assertList(array $list)
190 $this->assertInternalType('string', $list['name']);
191 $this->assertInternalType('int', $list['id']);
192 $this->assertInternalType('string', $list['id_str']);
193 $this->assertContains($list['mode'], ['public', 'private']);
194 // We could probably do more checks here.
198 * Assert that the string is XML and contain the root element.
200 * @param string $result XML string
201 * @param string $root_element Root element name
205 private function assertXml($result, $root_element)
207 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
208 $this->assertContains('<' . $root_element, $result);
209 // We could probably do more checks here.
213 * Get the path to a temporary empty PNG image.
215 * @return string Path
217 private function getTempImage()
219 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
223 // Empty 1x1 px PNG image
224 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
232 * Test the api_user() function.
236 public function testApiUser()
238 $this->assertEquals($this->selfUser['id'], api_user());
242 * Test the api_user() function with an unallowed user.
246 public function testApiUserWithUnallowedUser()
248 $_SESSION = ['allow_api' => false];
249 $this->assertEquals(false, api_user());
253 * Test the api_source() function.
257 public function testApiSource()
259 $this->assertEquals('api', api_source());
263 * Test the api_source() function with a Twidere user agent.
267 public function testApiSourceWithTwidere()
269 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
270 $this->assertEquals('Twidere', api_source());
274 * Test the api_source() function with a GET parameter.
278 public function testApiSourceWithGet()
280 $_GET['source'] = 'source_name';
281 $this->assertEquals('source_name', api_source());
285 * Test the api_date() function.
289 public function testApiDate()
291 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
295 * Test the api_register_func() function.
299 public function testApiRegisterFunc()
311 $this->assertTrue($API['api_path']['auth']);
312 $this->assertEquals('method', $API['api_path']['method']);
313 $this->assertTrue(is_callable($API['api_path']['func']));
317 * Test the api_login() function without any login.
320 * @runInSeparateProcess
321 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
323 public function testApiLoginWithoutLogin()
325 api_login($this->app);
329 * Test the api_login() function with a bad login.
332 * @runInSeparateProcess
333 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
335 public function testApiLoginWithBadLogin()
337 $_SERVER['PHP_AUTH_USER'] = 'user@server';
338 api_login($this->app);
342 * Test the api_login() function with oAuth.
346 public function testApiLoginWithOauth()
348 $this->markTestIncomplete('Can we test this easily?');
352 * Test the api_login() function with authentication provided by an addon.
356 public function testApiLoginWithAddonAuth()
358 $this->markTestIncomplete('Can we test this easily?');
362 * Test the api_login() function with a correct login.
365 * @runInSeparateProcess
367 public function testApiLoginWithCorrectLogin()
369 $_SERVER['PHP_AUTH_USER'] = 'Test user';
370 $_SERVER['PHP_AUTH_PW'] = 'password';
371 api_login($this->app);
375 * Test the api_login() function with a remote user.
378 * @runInSeparateProcess
379 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
381 public function testApiLoginWithRemoteUser()
383 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
384 api_login($this->app);
388 * Test the api_check_method() function.
392 public function testApiCheckMethod()
394 $this->assertFalse(api_check_method('method'));
398 * Test the api_check_method() function with a correct method.
402 public function testApiCheckMethodWithCorrectMethod()
404 $_SERVER['REQUEST_METHOD'] = 'method';
405 $this->assertTrue(api_check_method('method'));
409 * Test the api_check_method() function with a wildcard.
413 public function testApiCheckMethodWithWildcard()
415 $this->assertTrue(api_check_method('*'));
419 * Test the api_call() function.
422 * @runInSeparateProcess
424 public function testApiCall()
428 'method' => 'method',
429 'func' => function () {
430 return ['data' => ['some_data']];
433 $_SERVER['REQUEST_METHOD'] = 'method';
434 $_GET['callback'] = 'callback_name';
436 $this->app->query_string = 'api_path';
438 'callback_name(["some_data"])',
444 * Test the api_call() function with the profiled enabled.
447 * @runInSeparateProcess
449 public function testApiCallWithProfiler()
453 'method' => 'method',
454 'func' => function () {
455 return ['data' => ['some_data']];
458 $_SERVER['REQUEST_METHOD'] = 'method';
459 $this->config->set('system', 'profiler', true);
460 $this->config->set('rendertime', 'callstack', true);
461 $this->app->callstack = [
462 'database' => ['some_function' => 200],
463 'database_write' => ['some_function' => 200],
464 'cache' => ['some_function' => 200],
465 'cache_write' => ['some_function' => 200],
466 'network' => ['some_function' => 200]
469 $this->app->query_string = 'api_path';
477 * Test the api_call() function without any result.
480 * @runInSeparateProcess
482 public function testApiCallWithNoResult()
486 'method' => 'method',
487 'func' => function () {
491 $_SERVER['REQUEST_METHOD'] = 'method';
493 $this->app->query_string = 'api_path';
495 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
501 * Test the api_call() function with an unimplemented API.
504 * @runInSeparateProcess
506 public function testApiCallWithUninplementedApi()
509 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
515 * Test the api_call() function with a JSON result.
518 * @runInSeparateProcess
520 public function testApiCallWithJson()
524 'method' => 'method',
525 'func' => function () {
526 return ['data' => ['some_data']];
529 $_SERVER['REQUEST_METHOD'] = 'method';
531 $this->app->query_string = 'api_path.json';
539 * Test the api_call() function with an XML result.
542 * @runInSeparateProcess
544 public function testApiCallWithXml()
548 'method' => 'method',
549 'func' => function () {
553 $_SERVER['REQUEST_METHOD'] = 'method';
555 $this->app->query_string = 'api_path.xml';
563 * Test the api_call() function with an RSS result.
566 * @runInSeparateProcess
568 public function testApiCallWithRss()
572 'method' => 'method',
573 'func' => function () {
577 $_SERVER['REQUEST_METHOD'] = 'method';
579 $this->app->query_string = 'api_path.rss';
581 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
588 * Test the api_call() function with an Atom result.
591 * @runInSeparateProcess
593 public function testApiCallWithAtom()
597 'method' => 'method',
598 'func' => function () {
602 $_SERVER['REQUEST_METHOD'] = 'method';
604 $this->app->query_string = 'api_path.atom';
606 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
613 * Test the api_call() function with an unallowed method.
616 * @runInSeparateProcess
618 public function testApiCallWithWrongMethod()
621 $API['api_path'] = ['method' => 'method'];
623 $this->app->query_string = 'api_path';
625 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
631 * Test the api_call() function with an unauthorized user.
634 * @runInSeparateProcess
636 public function testApiCallWithWrongAuth()
640 'method' => 'method',
643 $_SERVER['REQUEST_METHOD'] = 'method';
644 $_SESSION['authenticated'] = false;
646 $this->app->query_string = 'api_path';
648 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
654 * Test the api_error() function with a JSON result.
657 * @runInSeparateProcess
659 public function testApiErrorWithJson()
662 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
663 api_error('json', new HTTPException\OKException('error_message'))
668 * Test the api_error() function with an XML result.
671 * @runInSeparateProcess
673 public function testApiErrorWithXml()
676 '<?xml version="1.0"?>' . "\n" .
677 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
678 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
679 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
680 ' <error>error_message</error>' . "\n" .
681 ' <code>200 OK</code>' . "\n" .
682 ' <request/>' . "\n" .
684 api_error('xml', new HTTPException\OKException('error_message'))
689 * Test the api_error() function with an RSS result.
692 * @runInSeparateProcess
694 public function testApiErrorWithRss()
697 '<?xml version="1.0"?>' . "\n" .
698 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
699 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
700 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
701 ' <error>error_message</error>' . "\n" .
702 ' <code>200 OK</code>' . "\n" .
703 ' <request/>' . "\n" .
705 api_error('rss', new HTTPException\OKException('error_message'))
710 * Test the api_error() function with an Atom result.
713 * @runInSeparateProcess
715 public function testApiErrorWithAtom()
718 '<?xml version="1.0"?>' . "\n" .
719 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
720 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
721 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
722 ' <error>error_message</error>' . "\n" .
723 ' <code>200 OK</code>' . "\n" .
724 ' <request/>' . "\n" .
726 api_error('atom', new HTTPException\OKException('error_message'))
731 * Test the api_rss_extra() function.
735 public function testApiRssExtra()
737 $user_info = ['url' => 'user_url', 'lang' => 'en'];
738 $result = api_rss_extra($this->app, [], $user_info);
739 $this->assertEquals($user_info, $result['$user']);
740 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
741 $this->assertArrayHasKey('self', $result['$rss']);
742 $this->assertArrayHasKey('base', $result['$rss']);
743 $this->assertArrayHasKey('updated', $result['$rss']);
744 $this->assertArrayHasKey('atom_updated', $result['$rss']);
745 $this->assertArrayHasKey('language', $result['$rss']);
746 $this->assertArrayHasKey('logo', $result['$rss']);
750 * Test the api_rss_extra() function without any user info.
754 public function testApiRssExtraWithoutUserInfo()
756 $result = api_rss_extra($this->app, [], null);
757 $this->assertInternalType('array', $result['$user']);
758 $this->assertArrayHasKey('alternate', $result['$rss']);
759 $this->assertArrayHasKey('self', $result['$rss']);
760 $this->assertArrayHasKey('base', $result['$rss']);
761 $this->assertArrayHasKey('updated', $result['$rss']);
762 $this->assertArrayHasKey('atom_updated', $result['$rss']);
763 $this->assertArrayHasKey('language', $result['$rss']);
764 $this->assertArrayHasKey('logo', $result['$rss']);
768 * Test the api_unique_id_to_nurl() function.
772 public function testApiUniqueIdToNurl()
774 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
778 * Test the api_unique_id_to_nurl() function with a correct ID.
782 public function testApiUniqueIdToNurlWithCorrectId()
784 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
788 * Test the api_get_user() function.
792 public function testApiGetUser()
794 $user = api_get_user($this->app);
795 $this->assertSelfUser($user);
796 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
797 $this->assertEquals('6fdbe8', $user['profile_link_color']);
798 $this->assertEquals('ededed', $user['profile_background_color']);
802 * Test the api_get_user() function with a Frio schema.
806 public function testApiGetUserWithFrioSchema()
808 $pConfig = $this->dice->create(PConfiguration::class);
809 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
810 $user = api_get_user($this->app);
811 $this->assertSelfUser($user);
812 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
813 $this->assertEquals('6fdbe8', $user['profile_link_color']);
814 $this->assertEquals('ededed', $user['profile_background_color']);
818 * Test the api_get_user() function with a custom Frio schema.
822 public function testApiGetUserWithCustomFrioSchema()
824 $pConfig = $this->dice->create(PConfiguration::class);
825 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
826 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
827 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
828 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
829 $user = api_get_user($this->app);
830 $this->assertSelfUser($user);
831 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
832 $this->assertEquals('123456', $user['profile_link_color']);
833 $this->assertEquals('123456', $user['profile_background_color']);
837 * Test the api_get_user() function with an empty Frio schema.
841 public function testApiGetUserWithEmptyFrioSchema()
843 $pConfig = $this->dice->create(PConfiguration::class);
844 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
845 $user = api_get_user($this->app);
846 $this->assertSelfUser($user);
847 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
848 $this->assertEquals('6fdbe8', $user['profile_link_color']);
849 $this->assertEquals('ededed', $user['profile_background_color']);
853 * Test the api_get_user() function with an user that is not allowed to use the API.
856 * @runInSeparateProcess
858 public function testApiGetUserWithoutApiUser()
860 $_SERVER['PHP_AUTH_USER'] = 'Test user';
861 $_SERVER['PHP_AUTH_PW'] = 'password';
862 $_SESSION['allow_api'] = false;
863 $this->assertFalse(api_get_user($this->app));
867 * Test the api_get_user() function with an user ID in a GET parameter.
871 public function testApiGetUserWithGetId()
873 $_GET['user_id'] = $this->otherUser['id'];
874 $this->assertOtherUser(api_get_user($this->app));
878 * Test the api_get_user() function with a wrong user ID in a GET parameter.
881 * @expectedException Friendica\Network\HTTPException\BadRequestException
883 public function testApiGetUserWithWrongGetId()
885 $_GET['user_id'] = $this->wrongUserId;
886 $this->assertOtherUser(api_get_user($this->app));
890 * Test the api_get_user() function with an user name in a GET parameter.
894 public function testApiGetUserWithGetName()
896 $_GET['screen_name'] = $this->selfUser['nick'];
897 $this->assertSelfUser(api_get_user($this->app));
901 * Test the api_get_user() function with a profile URL in a GET parameter.
905 public function testApiGetUserWithGetUrl()
907 $_GET['profileurl'] = $this->selfUser['nurl'];
908 $this->assertSelfUser(api_get_user($this->app));
912 * Test the api_get_user() function with an user ID in the API path.
916 public function testApiGetUserWithNumericCalledApi()
919 $called_api = ['api_path'];
920 $this->app->argv[1] = $this->otherUser['id'] . '.json';
921 $this->assertOtherUser(api_get_user($this->app));
925 * Test the api_get_user() function with the $called_api global variable.
929 public function testApiGetUserWithCalledApi()
932 $called_api = ['api', 'api_path'];
933 $this->assertSelfUser(api_get_user($this->app));
937 * Test the api_get_user() function with a valid user.
941 public function testApiGetUserWithCorrectUser()
943 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
947 * Test the api_get_user() function with a wrong user ID.
950 * @expectedException Friendica\Network\HTTPException\BadRequestException
952 public function testApiGetUserWithWrongUser()
954 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
958 * Test the api_get_user() function with a 0 user ID.
962 public function testApiGetUserWithZeroUser()
964 $this->assertSelfUser(api_get_user($this->app, 0));
968 * Test the api_item_get_user() function.
972 public function testApiItemGetUser()
974 $users = api_item_get_user($this->app, []);
975 $this->assertSelfUser($users[0]);
979 * Test the api_item_get_user() function with a different item parent.
983 public function testApiItemGetUserWithDifferentParent()
985 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
986 $this->assertSelfUser($users[0]);
987 $this->assertEquals($users[0], $users[1]);
991 * Test the api_walk_recursive() function.
995 public function testApiWalkRecursive()
1003 // Should we test this with a callback that actually does something?
1011 * Test the api_walk_recursive() function with an array.
1015 public function testApiWalkRecursiveWithArray()
1017 $array = [['item1'], ['item2']];
1018 $this->assertEquals(
1023 // Should we test this with a callback that actually does something?
1031 * Test the api_reformat_xml() function.
1035 public function testApiReformatXml()
1039 $this->assertTrue(api_reformat_xml($item, $key));
1040 $this->assertEquals('true', $item);
1044 * Test the api_reformat_xml() function with a statusnet_api key.
1048 public function testApiReformatXmlWithStatusnetKey()
1051 $key = 'statusnet_api';
1052 $this->assertTrue(api_reformat_xml($item, $key));
1053 $this->assertEquals('statusnet:api', $key);
1057 * Test the api_reformat_xml() function with a friendica_api key.
1061 public function testApiReformatXmlWithFriendicaKey()
1064 $key = 'friendica_api';
1065 $this->assertTrue(api_reformat_xml($item, $key));
1066 $this->assertEquals('friendica:api', $key);
1070 * Test the api_create_xml() function.
1074 public function testApiCreateXml()
1076 $this->assertEquals(
1077 '<?xml version="1.0"?>' . "\n" .
1078 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1079 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1080 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1081 ' <data>some_data</data>' . "\n" .
1082 '</root_element>' . "\n",
1083 api_create_xml(['data' => ['some_data']], 'root_element')
1088 * Test the api_create_xml() function without any XML namespace.
1092 public function testApiCreateXmlWithoutNamespaces()
1094 $this->assertEquals(
1095 '<?xml version="1.0"?>' . "\n" .
1097 ' <data>some_data</data>' . "\n" .
1099 api_create_xml(['data' => ['some_data']], 'ok')
1104 * Test the api_format_data() function.
1108 public function testApiFormatData()
1110 $data = ['some_data'];
1111 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1115 * Test the api_format_data() function with an XML result.
1119 public function testApiFormatDataWithXml()
1121 $this->assertEquals(
1122 '<?xml version="1.0"?>' . "\n" .
1123 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1124 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1125 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1126 ' <data>some_data</data>' . "\n" .
1127 '</root_element>' . "\n",
1128 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1133 * Test the api_account_verify_credentials() function.
1137 public function testApiAccountVerifyCredentials()
1139 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1143 * Test the api_account_verify_credentials() function without an authenticated user.
1146 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1148 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1150 $_SESSION['authenticated'] = false;
1151 api_account_verify_credentials('json');
1155 * Test the requestdata() function.
1159 public function testRequestdata()
1161 $this->assertNull(requestdata('variable_name'));
1165 * Test the requestdata() function with a POST parameter.
1169 public function testRequestdataWithPost()
1171 $_POST['variable_name'] = 'variable_value';
1172 $this->assertEquals('variable_value', requestdata('variable_name'));
1176 * Test the requestdata() function with a GET parameter.
1180 public function testRequestdataWithGet()
1182 $_GET['variable_name'] = 'variable_value';
1183 $this->assertEquals('variable_value', requestdata('variable_name'));
1187 * Test the api_statuses_mediap() function.
1191 public function testApiStatusesMediap()
1193 $this->app->argc = 2;
1201 'tmp_name' => $this->getTempImage(),
1202 'name' => 'spacer.png',
1203 'type' => 'image/png'
1206 $_GET['status'] = '<b>Status content</b>';
1208 $result = api_statuses_mediap('json');
1209 $this->assertStatus($result['status']);
1213 * Test the api_statuses_mediap() function without an authenticated user.
1216 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1218 public function testApiStatusesMediapWithoutAuthenticatedUser()
1220 $_SESSION['authenticated'] = false;
1221 api_statuses_mediap('json');
1225 * Test the api_statuses_update() function.
1229 public function testApiStatusesUpdate()
1231 $_GET['status'] = 'Status content #friendica';
1232 $_GET['in_reply_to_status_id'] = -1;
1241 'tmp_name' => $this->getTempImage(),
1242 'name' => 'spacer.png',
1243 'type' => 'image/png'
1247 $result = api_statuses_update('json');
1248 $this->assertStatus($result['status']);
1252 * Test the api_statuses_update() function with an HTML status.
1256 public function testApiStatusesUpdateWithHtml()
1258 $_GET['htmlstatus'] = '<b>Status content</b>';
1260 $result = api_statuses_update('json');
1261 $this->assertStatus($result['status']);
1265 * Test the api_statuses_update() function without an authenticated user.
1268 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1270 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1272 $_SESSION['authenticated'] = false;
1273 api_statuses_update('json');
1277 * Test the api_statuses_update() function with a parent status.
1281 public function testApiStatusesUpdateWithParent()
1283 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1287 * Test the api_statuses_update() function with a media_ids parameter.
1291 public function testApiStatusesUpdateWithMediaIds()
1293 $this->markTestIncomplete();
1297 * Test the api_statuses_update() function with the throttle limit reached.
1301 public function testApiStatusesUpdateWithDayThrottleReached()
1303 $this->markTestIncomplete();
1307 * Test the api_media_upload() function.
1310 * @expectedException Friendica\Network\HTTPException\BadRequestException
1312 public function testApiMediaUpload()
1318 * Test the api_media_upload() function without an authenticated user.
1321 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1323 public function testApiMediaUploadWithoutAuthenticatedUser()
1325 $_SESSION['authenticated'] = false;
1330 * Test the api_media_upload() function with an invalid uploaded media.
1333 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1335 public function testApiMediaUploadWithMedia()
1340 'tmp_name' => 'tmp_name'
1347 * Test the api_media_upload() function with an valid uploaded media.
1351 public function testApiMediaUploadWithValidMedia()
1359 'tmp_name' => $this->getTempImage(),
1360 'name' => 'spacer.png',
1361 'type' => 'image/png'
1367 $result = api_media_upload();
1368 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1369 $this->assertEquals(1, $result['media']['image']['w']);
1370 $this->assertEquals(1, $result['media']['image']['h']);
1371 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1375 * Test the api_status_show() function.
1377 public function testApiStatusShowWithJson()
1379 $result = api_status_show('json', 1);
1380 $this->assertStatus($result['status']);
1384 * Test the api_status_show() function with an XML result.
1386 public function testApiStatusShowWithXml()
1388 $result = api_status_show('xml', 1);
1389 $this->assertXml($result, 'statuses');
1393 * Test the api_get_last_status() function
1395 public function testApiGetLastStatus()
1397 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1399 $this->assertNotNull($item);
1403 * Test the api_users_show() function.
1407 public function testApiUsersShow()
1409 $result = api_users_show('json');
1410 // We can't use assertSelfUser() here because the user object is missing some properties.
1411 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1412 $this->assertEquals('DFRN', $result['user']['location']);
1413 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1414 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1415 $this->assertEquals('dfrn', $result['user']['network']);
1416 $this->assertTrue($result['user']['verified']);
1420 * Test the api_users_show() function with an XML result.
1424 public function testApiUsersShowWithXml()
1426 $result = api_users_show('xml');
1427 $this->assertXml($result, 'statuses');
1431 * Test the api_users_search() function.
1435 public function testApiUsersSearch()
1437 $_GET['q'] = 'othercontact';
1438 $result = api_users_search('json');
1439 $this->assertOtherUser($result['users'][0]);
1443 * Test the api_users_search() function with an XML result.
1447 public function testApiUsersSearchWithXml()
1449 $_GET['q'] = 'othercontact';
1450 $result = api_users_search('xml');
1451 $this->assertXml($result, 'users');
1455 * Test the api_users_search() function without a GET q parameter.
1458 * @expectedException Friendica\Network\HTTPException\BadRequestException
1460 public function testApiUsersSearchWithoutQuery()
1462 api_users_search('json');
1466 * Test the api_users_lookup() function.
1469 * @expectedException Friendica\Network\HTTPException\NotFoundException
1471 public function testApiUsersLookup()
1473 api_users_lookup('json');
1477 * Test the api_users_lookup() function with an user ID.
1481 public function testApiUsersLookupWithUserId()
1483 $_REQUEST['user_id'] = $this->otherUser['id'];
1484 $result = api_users_lookup('json');
1485 $this->assertOtherUser($result['users'][0]);
1489 * Test the api_search() function.
1493 public function testApiSearch()
1495 $_REQUEST['q'] = 'reply';
1496 $_REQUEST['max_id'] = 10;
1497 $result = api_search('json');
1498 foreach ($result['status'] as $status) {
1499 $this->assertStatus($status);
1500 $this->assertContains('reply', $status['text'], null, true);
1505 * Test the api_search() function a count parameter.
1509 public function testApiSearchWithCount()
1511 $_REQUEST['q'] = 'reply';
1512 $_REQUEST['count'] = 20;
1513 $result = api_search('json');
1514 foreach ($result['status'] as $status) {
1515 $this->assertStatus($status);
1516 $this->assertContains('reply', $status['text'], null, true);
1521 * Test the api_search() function with an rpp parameter.
1525 public function testApiSearchWithRpp()
1527 $_REQUEST['q'] = 'reply';
1528 $_REQUEST['rpp'] = 20;
1529 $result = api_search('json');
1530 foreach ($result['status'] as $status) {
1531 $this->assertStatus($status);
1532 $this->assertContains('reply', $status['text'], null, true);
1537 * Test the api_search() function with an q parameter contains hashtag.
1541 public function testApiSearchWithHashtag()
1543 $_REQUEST['q'] = '%23friendica';
1544 $result = api_search('json');
1545 foreach ($result['status'] as $status) {
1546 $this->assertStatus($status);
1547 $this->assertContains('#friendica', $status['text'], null, true);
1552 * Test the api_search() function with an exclude_replies parameter.
1556 public function testApiSearchWithExcludeReplies()
1558 $_REQUEST['max_id'] = 10;
1559 $_REQUEST['exclude_replies'] = true;
1560 $_REQUEST['q'] = 'friendica';
1561 $result = api_search('json');
1562 foreach ($result['status'] as $status) {
1563 $this->assertStatus($status);
1568 * Test the api_search() function without an authenticated user.
1571 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1573 public function testApiSearchWithUnallowedUser()
1575 $_SESSION['allow_api'] = false;
1576 $_GET['screen_name'] = $this->selfUser['nick'];
1581 * Test the api_search() function without any GET query parameter.
1584 * @expectedException Friendica\Network\HTTPException\BadRequestException
1586 public function testApiSearchWithoutQuery()
1592 * Test the api_statuses_home_timeline() function.
1596 public function testApiStatusesHomeTimeline()
1598 $_REQUEST['max_id'] = 10;
1599 $_REQUEST['exclude_replies'] = true;
1600 $_REQUEST['conversation_id'] = 1;
1601 $result = api_statuses_home_timeline('json');
1602 $this->assertNotEmpty($result['status']);
1603 foreach ($result['status'] as $status) {
1604 $this->assertStatus($status);
1609 * Test the api_statuses_home_timeline() function with a negative page parameter.
1613 public function testApiStatusesHomeTimelineWithNegativePage()
1615 $_REQUEST['page'] = -2;
1616 $result = api_statuses_home_timeline('json');
1617 $this->assertNotEmpty($result['status']);
1618 foreach ($result['status'] as $status) {
1619 $this->assertStatus($status);
1624 * Test the api_statuses_home_timeline() with an unallowed user.
1627 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1629 public function testApiStatusesHomeTimelineWithUnallowedUser()
1631 $_SESSION['allow_api'] = false;
1632 $_GET['screen_name'] = $this->selfUser['nick'];
1633 api_statuses_home_timeline('json');
1637 * Test the api_statuses_home_timeline() function with an RSS result.
1641 public function testApiStatusesHomeTimelineWithRss()
1643 $result = api_statuses_home_timeline('rss');
1644 $this->assertXml($result, 'statuses');
1648 * Test the api_statuses_public_timeline() function.
1652 public function testApiStatusesPublicTimeline()
1654 $_REQUEST['max_id'] = 10;
1655 $_REQUEST['conversation_id'] = 1;
1656 $result = api_statuses_public_timeline('json');
1657 $this->assertNotEmpty($result['status']);
1658 foreach ($result['status'] as $status) {
1659 $this->assertStatus($status);
1664 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1668 public function testApiStatusesPublicTimelineWithExcludeReplies()
1670 $_REQUEST['max_id'] = 10;
1671 $_REQUEST['exclude_replies'] = true;
1672 $result = api_statuses_public_timeline('json');
1673 $this->assertNotEmpty($result['status']);
1674 foreach ($result['status'] as $status) {
1675 $this->assertStatus($status);
1680 * Test the api_statuses_public_timeline() function with a negative page parameter.
1684 public function testApiStatusesPublicTimelineWithNegativePage()
1686 $_REQUEST['page'] = -2;
1687 $result = api_statuses_public_timeline('json');
1688 $this->assertNotEmpty($result['status']);
1689 foreach ($result['status'] as $status) {
1690 $this->assertStatus($status);
1695 * Test the api_statuses_public_timeline() function with an unallowed user.
1698 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1700 public function testApiStatusesPublicTimelineWithUnallowedUser()
1702 $_SESSION['allow_api'] = false;
1703 $_GET['screen_name'] = $this->selfUser['nick'];
1704 api_statuses_public_timeline('json');
1708 * Test the api_statuses_public_timeline() function with an RSS result.
1712 public function testApiStatusesPublicTimelineWithRss()
1714 $result = api_statuses_public_timeline('rss');
1715 $this->assertXml($result, 'statuses');
1719 * Test the api_statuses_networkpublic_timeline() function.
1723 public function testApiStatusesNetworkpublicTimeline()
1725 $_REQUEST['max_id'] = 10;
1726 $result = api_statuses_networkpublic_timeline('json');
1727 $this->assertNotEmpty($result['status']);
1728 foreach ($result['status'] as $status) {
1729 $this->assertStatus($status);
1734 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1738 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1740 $_REQUEST['page'] = -2;
1741 $result = api_statuses_networkpublic_timeline('json');
1742 $this->assertNotEmpty($result['status']);
1743 foreach ($result['status'] as $status) {
1744 $this->assertStatus($status);
1749 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1752 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1754 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1756 $_SESSION['allow_api'] = false;
1757 $_GET['screen_name'] = $this->selfUser['nick'];
1758 api_statuses_networkpublic_timeline('json');
1762 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1766 public function testApiStatusesNetworkpublicTimelineWithRss()
1768 $result = api_statuses_networkpublic_timeline('rss');
1769 $this->assertXml($result, 'statuses');
1773 * Test the api_statuses_show() function.
1776 * @expectedException Friendica\Network\HTTPException\BadRequestException
1778 public function testApiStatusesShow()
1780 api_statuses_show('json');
1784 * Test the api_statuses_show() function with an ID.
1788 public function testApiStatusesShowWithId()
1790 $this->app->argv[3] = 1;
1791 $result = api_statuses_show('json');
1792 $this->assertStatus($result['status']);
1796 * Test the api_statuses_show() function with the conversation parameter.
1800 public function testApiStatusesShowWithConversation()
1802 $this->app->argv[3] = 1;
1803 $_REQUEST['conversation'] = 1;
1804 $result = api_statuses_show('json');
1805 $this->assertNotEmpty($result['status']);
1806 foreach ($result['status'] as $status) {
1807 $this->assertStatus($status);
1812 * Test the api_statuses_show() function with an unallowed user.
1815 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1817 public function testApiStatusesShowWithUnallowedUser()
1819 $_SESSION['allow_api'] = false;
1820 $_GET['screen_name'] = $this->selfUser['nick'];
1821 api_statuses_show('json');
1825 * Test the api_conversation_show() function.
1828 * @expectedException Friendica\Network\HTTPException\BadRequestException
1830 public function testApiConversationShow()
1832 api_conversation_show('json');
1836 * Test the api_conversation_show() function with an ID.
1840 public function testApiConversationShowWithId()
1842 $this->app->argv[3] = 1;
1843 $_REQUEST['max_id'] = 10;
1844 $_REQUEST['page'] = -2;
1845 $result = api_conversation_show('json');
1846 $this->assertNotEmpty($result['status']);
1847 foreach ($result['status'] as $status) {
1848 $this->assertStatus($status);
1853 * Test the api_conversation_show() function with an unallowed user.
1856 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1858 public function testApiConversationShowWithUnallowedUser()
1860 $_SESSION['allow_api'] = false;
1861 $_GET['screen_name'] = $this->selfUser['nick'];
1862 api_conversation_show('json');
1866 * Test the api_statuses_repeat() function.
1869 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1871 public function testApiStatusesRepeat()
1873 api_statuses_repeat('json');
1877 * Test the api_statuses_repeat() function without an authenticated user.
1880 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1882 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1884 $_SESSION['authenticated'] = false;
1885 api_statuses_repeat('json');
1889 * Test the api_statuses_repeat() function with an ID.
1893 public function testApiStatusesRepeatWithId()
1895 $this->app->argv[3] = 1;
1896 $result = api_statuses_repeat('json');
1897 $this->assertStatus($result['status']);
1899 // Also test with a shared status
1900 $this->app->argv[3] = 5;
1901 $result = api_statuses_repeat('json');
1902 $this->assertStatus($result['status']);
1906 * Test the api_statuses_destroy() function.
1909 * @expectedException Friendica\Network\HTTPException\BadRequestException
1911 public function testApiStatusesDestroy()
1913 api_statuses_destroy('json');
1917 * Test the api_statuses_destroy() function without an authenticated user.
1920 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1922 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1924 $_SESSION['authenticated'] = false;
1925 api_statuses_destroy('json');
1929 * Test the api_statuses_destroy() function with an ID.
1933 public function testApiStatusesDestroyWithId()
1935 $this->app->argv[3] = 1;
1936 $result = api_statuses_destroy('json');
1937 $this->assertStatus($result['status']);
1941 * Test the api_statuses_mentions() function.
1945 public function testApiStatusesMentions()
1947 $this->app->user = ['nickname' => $this->selfUser['nick']];
1948 $_REQUEST['max_id'] = 10;
1949 $result = api_statuses_mentions('json');
1950 $this->assertEmpty($result['status']);
1951 // We should test with mentions in the database.
1955 * Test the api_statuses_mentions() function with a negative page parameter.
1959 public function testApiStatusesMentionsWithNegativePage()
1961 $_REQUEST['page'] = -2;
1962 $result = api_statuses_mentions('json');
1963 $this->assertEmpty($result['status']);
1967 * Test the api_statuses_mentions() function with an unallowed user.
1970 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1972 public function testApiStatusesMentionsWithUnallowedUser()
1974 $_SESSION['allow_api'] = false;
1975 $_GET['screen_name'] = $this->selfUser['nick'];
1976 api_statuses_mentions('json');
1980 * Test the api_statuses_mentions() function with an RSS result.
1984 public function testApiStatusesMentionsWithRss()
1986 $result = api_statuses_mentions('rss');
1987 $this->assertXml($result, 'statuses');
1991 * Test the api_statuses_user_timeline() function.
1995 public function testApiStatusesUserTimeline()
1997 $_REQUEST['max_id'] = 10;
1998 $_REQUEST['exclude_replies'] = true;
1999 $_REQUEST['conversation_id'] = 1;
2000 $result = api_statuses_user_timeline('json');
2001 $this->assertNotEmpty($result['status']);
2002 foreach ($result['status'] as $status) {
2003 $this->assertStatus($status);
2008 * Test the api_statuses_user_timeline() function with a negative page parameter.
2012 public function testApiStatusesUserTimelineWithNegativePage()
2014 $_REQUEST['page'] = -2;
2015 $result = api_statuses_user_timeline('json');
2016 $this->assertNotEmpty($result['status']);
2017 foreach ($result['status'] as $status) {
2018 $this->assertStatus($status);
2023 * Test the api_statuses_user_timeline() function with an RSS result.
2027 public function testApiStatusesUserTimelineWithRss()
2029 $result = api_statuses_user_timeline('rss');
2030 $this->assertXml($result, 'statuses');
2034 * Test the api_statuses_user_timeline() function with an unallowed user.
2037 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2039 public function testApiStatusesUserTimelineWithUnallowedUser()
2041 $_SESSION['allow_api'] = false;
2042 $_GET['screen_name'] = $this->selfUser['nick'];
2043 api_statuses_user_timeline('json');
2047 * Test the api_favorites_create_destroy() function.
2050 * @expectedException Friendica\Network\HTTPException\BadRequestException
2052 public function testApiFavoritesCreateDestroy()
2054 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2055 $this->app->argc = count($this->app->argv);
2056 api_favorites_create_destroy('json');
2060 * Test the api_favorites_create_destroy() function with an invalid ID.
2063 * @expectedException Friendica\Network\HTTPException\BadRequestException
2065 public function testApiFavoritesCreateDestroyWithInvalidId()
2067 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2068 $this->app->argc = count($this->app->argv);
2069 api_favorites_create_destroy('json');
2073 * Test the api_favorites_create_destroy() function with an invalid action.
2076 * @expectedException Friendica\Network\HTTPException\BadRequestException
2078 public function testApiFavoritesCreateDestroyWithInvalidAction()
2080 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2081 $this->app->argc = count($this->app->argv);
2082 $_REQUEST['id'] = 1;
2083 api_favorites_create_destroy('json');
2087 * Test the api_favorites_create_destroy() function with the create action.
2091 public function testApiFavoritesCreateDestroyWithCreateAction()
2093 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2094 $this->app->argc = count($this->app->argv);
2095 $_REQUEST['id'] = 3;
2096 $result = api_favorites_create_destroy('json');
2097 $this->assertStatus($result['status']);
2101 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2105 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2107 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2108 $this->app->argc = count($this->app->argv);
2109 $_REQUEST['id'] = 3;
2110 $result = api_favorites_create_destroy('rss');
2111 $this->assertXml($result, 'status');
2115 * Test the api_favorites_create_destroy() function with the destroy action.
2119 public function testApiFavoritesCreateDestroyWithDestroyAction()
2121 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2122 $this->app->argc = count($this->app->argv);
2123 $_REQUEST['id'] = 3;
2124 $result = api_favorites_create_destroy('json');
2125 $this->assertStatus($result['status']);
2129 * Test the api_favorites_create_destroy() function without an authenticated user.
2132 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2134 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2136 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2137 $this->app->argc = count($this->app->argv);
2138 $_SESSION['authenticated'] = false;
2139 api_favorites_create_destroy('json');
2143 * Test the api_favorites() function.
2147 public function testApiFavorites()
2149 $_REQUEST['page'] = -1;
2150 $_REQUEST['max_id'] = 10;
2151 $result = api_favorites('json');
2152 foreach ($result['status'] as $status) {
2153 $this->assertStatus($status);
2158 * Test the api_favorites() function with an RSS result.
2162 public function testApiFavoritesWithRss()
2164 $result = api_favorites('rss');
2165 $this->assertXml($result, 'statuses');
2169 * Test the api_favorites() function with an unallowed user.
2172 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2174 public function testApiFavoritesWithUnallowedUser()
2176 $_SESSION['allow_api'] = false;
2177 $_GET['screen_name'] = $this->selfUser['nick'];
2178 api_favorites('json');
2182 * Test the api_format_messages() function.
2186 public function testApiFormatMessages()
2188 $result = api_format_messages(
2189 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2190 ['id' => 2, 'screen_name' => 'recipient_name'],
2191 ['id' => 3, 'screen_name' => 'sender_name']
2193 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2194 $this->assertEquals(1, $result['id']);
2195 $this->assertEquals(2, $result['recipient_id']);
2196 $this->assertEquals(3, $result['sender_id']);
2197 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2198 $this->assertEquals('sender_name', $result['sender_screen_name']);
2202 * Test the api_format_messages() function with HTML.
2206 public function testApiFormatMessagesWithHtmlText()
2208 $_GET['getText'] = 'html';
2209 $result = api_format_messages(
2210 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2211 ['id' => 2, 'screen_name' => 'recipient_name'],
2212 ['id' => 3, 'screen_name' => 'sender_name']
2214 $this->assertEquals('item_title', $result['title']);
2215 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2219 * Test the api_format_messages() function with plain text.
2223 public function testApiFormatMessagesWithPlainText()
2225 $_GET['getText'] = 'plain';
2226 $result = api_format_messages(
2227 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2228 ['id' => 2, 'screen_name' => 'recipient_name'],
2229 ['id' => 3, 'screen_name' => 'sender_name']
2231 $this->assertEquals('item_title', $result['title']);
2232 $this->assertEquals('item_body', $result['text']);
2236 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2240 public function testApiFormatMessagesWithoutUserObjects()
2242 $_GET['getUserObjects'] = 'false';
2243 $result = api_format_messages(
2244 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2245 ['id' => 2, 'screen_name' => 'recipient_name'],
2246 ['id' => 3, 'screen_name' => 'sender_name']
2248 $this->assertTrue(!isset($result['sender']));
2249 $this->assertTrue(!isset($result['recipient']));
2253 * Test the api_convert_item() function.
2257 public function testApiConvertItem()
2259 $result = api_convert_item(
2261 'network' => 'feed',
2262 'title' => 'item_title',
2263 // We need a long string to test that it is correctly cut
2264 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2265 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2266 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2267 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2268 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2269 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2270 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2271 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2272 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2273 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2274 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2275 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2276 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2277 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2278 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2279 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2280 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2281 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2282 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2283 'repellat officia illum quos impedit quam iste esse unde qui ' .
2284 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2285 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2286 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2287 'plink' => 'item_plink'
2290 $this->assertStringStartsWith('item_title', $result['text']);
2291 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2295 * Test the api_convert_item() function with an empty item body.
2299 public function testApiConvertItemWithoutBody()
2301 $result = api_convert_item(
2303 'network' => 'feed',
2304 'title' => 'item_title',
2306 'plink' => 'item_plink'
2309 $this->assertEquals('item_title', $result['text']);
2310 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2314 * Test the api_convert_item() function with the title in the body.
2318 public function testApiConvertItemWithTitleInBody()
2320 $result = api_convert_item(
2322 'title' => 'item_title',
2323 'body' => 'item_title item_body'
2326 $this->assertEquals('item_title item_body', $result['text']);
2327 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2331 * Test the api_get_attachments() function.
2335 public function testApiGetAttachments()
2338 $this->assertEmpty(api_get_attachments($body));
2342 * Test the api_get_attachments() function with an img tag.
2346 public function testApiGetAttachmentsWithImage()
2348 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2349 $this->assertInternalType('array', api_get_attachments($body));
2353 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2357 public function testApiGetAttachmentsWithImageAndAndStatus()
2359 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2360 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2361 $this->assertInternalType('array', api_get_attachments($body));
2365 * Test the api_get_entitities() function.
2369 public function testApiGetEntitities()
2372 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2376 * Test the api_get_entitities() function with the include_entities parameter.
2380 public function testApiGetEntititiesWithIncludeEntities()
2382 $_REQUEST['include_entities'] = 'true';
2384 $result = api_get_entitities($text, 'bbcode');
2385 $this->assertInternalType('array', $result['hashtags']);
2386 $this->assertInternalType('array', $result['symbols']);
2387 $this->assertInternalType('array', $result['urls']);
2388 $this->assertInternalType('array', $result['user_mentions']);
2392 * Test the api_format_items_embeded_images() function.
2396 public function testApiFormatItemsEmbededImages()
2398 $this->assertEquals(
2399 'text ' . System::baseUrl() . '/display/item_guid',
2400 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2405 * Test the api_contactlink_to_array() function.
2409 public function testApiContactlinkToArray()
2411 $this->assertEquals(
2416 api_contactlink_to_array('text')
2421 * Test the api_contactlink_to_array() function with an URL.
2425 public function testApiContactlinkToArrayWithUrl()
2427 $this->assertEquals(
2429 'name' => ['link_text'],
2432 api_contactlink_to_array('text <a href="url">link_text</a>')
2437 * Test the api_format_items_activities() function.
2441 public function testApiFormatItemsActivities()
2443 $item = ['uid' => 0, 'uri' => ''];
2444 $result = api_format_items_activities($item);
2445 $this->assertArrayHasKey('like', $result);
2446 $this->assertArrayHasKey('dislike', $result);
2447 $this->assertArrayHasKey('attendyes', $result);
2448 $this->assertArrayHasKey('attendno', $result);
2449 $this->assertArrayHasKey('attendmaybe', $result);
2453 * Test the api_format_items_activities() function with an XML result.
2457 public function testApiFormatItemsActivitiesWithXml()
2459 $item = ['uid' => 0, 'uri' => ''];
2460 $result = api_format_items_activities($item, 'xml');
2461 $this->assertArrayHasKey('friendica:like', $result);
2462 $this->assertArrayHasKey('friendica:dislike', $result);
2463 $this->assertArrayHasKey('friendica:attendyes', $result);
2464 $this->assertArrayHasKey('friendica:attendno', $result);
2465 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2469 * Test the api_format_items_profiles() function.
2473 public function testApiFormatItemsProfiles()
2476 'id' => 'profile_id',
2477 'profile-name' => 'profile_name',
2478 'is-default' => true,
2479 'hide-friends' => true,
2480 'photo' => 'profile_photo',
2481 'thumb' => 'profile_thumb',
2483 'net-publish' => true,
2484 'pdesc' => 'description',
2485 'dob' => 'date_of_birth',
2486 'address' => 'address',
2487 'locality' => 'city',
2488 'region' => 'region',
2489 'postal-code' => 'postal_code',
2490 'country-name' => 'country',
2491 'hometown' => 'hometown',
2492 'gender' => 'gender',
2493 'marital' => 'marital',
2494 'with' => 'marital_with',
2495 'howlong' => 'marital_since',
2496 'sexual' => 'sexual',
2497 'politic' => 'politic',
2498 'religion' => 'religion',
2499 'pub_keywords' => 'public_keywords',
2500 'prv_keywords' => 'private_keywords',
2503 'dislikes' => 'dislikes',
2509 'interest' => 'interest',
2510 'romance' => 'romance',
2512 'education' => 'education',
2513 'contact' => 'social_networks',
2514 'homepage' => 'homepage'
2516 $result = api_format_items_profiles($profile_row);
2517 $this->assertEquals(
2519 'profile_id' => 'profile_id',
2520 'profile_name' => 'profile_name',
2521 'is_default' => true,
2522 'hide_friends' => true,
2523 'profile_photo' => 'profile_photo',
2524 'profile_thumb' => 'profile_thumb',
2526 'net_publish' => true,
2527 'description' => 'description',
2528 'date_of_birth' => 'date_of_birth',
2529 'address' => 'address',
2531 'region' => 'region',
2532 'postal_code' => 'postal_code',
2533 'country' => 'country',
2534 'hometown' => 'hometown',
2535 'gender' => 'gender',
2536 'marital' => 'marital',
2537 'marital_with' => 'marital_with',
2538 'marital_since' => 'marital_since',
2539 'sexual' => 'sexual',
2540 'politic' => 'politic',
2541 'religion' => 'religion',
2542 'public_keywords' => 'public_keywords',
2543 'private_keywords' => 'private_keywords',
2546 'dislikes' => 'dislikes',
2552 'interest' => 'interest',
2553 'romance' => 'romance',
2555 'education' => 'education',
2556 'social_networks' => 'social_networks',
2557 'homepage' => 'homepage',
2565 * Test the api_format_items() function.
2569 public function testApiFormatItems()
2573 'item_network' => 'item_network',
2579 'author-network' => Protocol::DFRN,
2580 'author-link' => 'http://localhost/profile/othercontact',
2584 $result = api_format_items($items, ['id' => 0], true);
2585 foreach ($result as $status) {
2586 $this->assertStatus($status);
2591 * Test the api_format_items() function with an XML result.
2595 public function testApiFormatItemsWithXml()
2603 'author-network' => Protocol::DFRN,
2604 'author-link' => 'http://localhost/profile/othercontact',
2608 $result = api_format_items($items, ['id' => 0], true, 'xml');
2609 foreach ($result as $status) {
2610 $this->assertStatus($status);
2615 * Test the api_format_items() function.
2619 public function testApiAccountRateLimitStatus()
2621 $result = api_account_rate_limit_status('json');
2622 $this->assertEquals(150, $result['hash']['remaining_hits']);
2623 $this->assertEquals(150, $result['hash']['hourly_limit']);
2624 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2628 * Test the api_format_items() function with an XML result.
2632 public function testApiAccountRateLimitStatusWithXml()
2634 $result = api_account_rate_limit_status('xml');
2635 $this->assertXml($result, 'hash');
2639 * Test the api_help_test() function.
2643 public function testApiHelpTest()
2645 $result = api_help_test('json');
2646 $this->assertEquals(['ok' => 'ok'], $result);
2650 * Test the api_help_test() function with an XML result.
2654 public function testApiHelpTestWithXml()
2656 $result = api_help_test('xml');
2657 $this->assertXml($result, 'ok');
2661 * Test the api_lists_list() function.
2665 public function testApiListsList()
2667 $result = api_lists_list('json');
2668 $this->assertEquals(['lists_list' => []], $result);
2672 * Test the api_lists_ownerships() function.
2676 public function testApiListsOwnerships()
2678 $result = api_lists_ownerships('json');
2679 foreach ($result['lists']['lists'] as $list) {
2680 $this->assertList($list);
2685 * Test the api_lists_ownerships() function without an authenticated user.
2688 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2690 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2692 $_SESSION['authenticated'] = false;
2693 api_lists_ownerships('json');
2697 * Test the api_lists_statuses() function.
2699 * @expectedException Friendica\Network\HTTPException\BadRequestException
2702 public function testApiListsStatuses()
2704 api_lists_statuses('json');
2708 * Test the api_lists_statuses() function with a list ID.
2712 public function testApiListsStatusesWithListId()
2714 $_REQUEST['list_id'] = 1;
2715 $_REQUEST['page'] = -1;
2716 $_REQUEST['max_id'] = 10;
2717 $result = api_lists_statuses('json');
2718 foreach ($result['status'] as $status) {
2719 $this->assertStatus($status);
2724 * Test the api_lists_statuses() function with a list ID and a RSS result.
2728 public function testApiListsStatusesWithListIdAndRss()
2730 $_REQUEST['list_id'] = 1;
2731 $result = api_lists_statuses('rss');
2732 $this->assertXml($result, 'statuses');
2736 * Test the api_lists_statuses() function with an unallowed user.
2739 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2741 public function testApiListsStatusesWithUnallowedUser()
2743 $_SESSION['allow_api'] = false;
2744 $_GET['screen_name'] = $this->selfUser['nick'];
2745 api_lists_statuses('json');
2749 * Test the api_statuses_f() function.
2753 public function testApiStatusesFWithFriends()
2756 $result = api_statuses_f('friends');
2757 $this->assertArrayHasKey('user', $result);
2761 * Test the api_statuses_f() function.
2765 public function testApiStatusesFWithFollowers()
2767 $result = api_statuses_f('followers');
2768 $this->assertArrayHasKey('user', $result);
2772 * Test the api_statuses_f() function.
2776 public function testApiStatusesFWithBlocks()
2778 $result = api_statuses_f('blocks');
2779 $this->assertArrayHasKey('user', $result);
2783 * Test the api_statuses_f() function.
2787 public function testApiStatusesFWithIncoming()
2789 $result = api_statuses_f('incoming');
2790 $this->assertArrayHasKey('user', $result);
2794 * Test the api_statuses_f() function an undefined cursor GET variable.
2798 public function testApiStatusesFWithUndefinedCursor()
2800 $_GET['cursor'] = 'undefined';
2801 $this->assertFalse(api_statuses_f('friends'));
2805 * Test the api_statuses_friends() function.
2809 public function testApiStatusesFriends()
2811 $result = api_statuses_friends('json');
2812 $this->assertArrayHasKey('user', $result);
2816 * Test the api_statuses_friends() function an undefined cursor GET variable.
2820 public function testApiStatusesFriendsWithUndefinedCursor()
2822 $_GET['cursor'] = 'undefined';
2823 $this->assertFalse(api_statuses_friends('json'));
2827 * Test the api_statuses_followers() function.
2831 public function testApiStatusesFollowers()
2833 $result = api_statuses_followers('json');
2834 $this->assertArrayHasKey('user', $result);
2838 * Test the api_statuses_followers() function an undefined cursor GET variable.
2842 public function testApiStatusesFollowersWithUndefinedCursor()
2844 $_GET['cursor'] = 'undefined';
2845 $this->assertFalse(api_statuses_followers('json'));
2849 * Test the api_blocks_list() function.
2853 public function testApiBlocksList()
2855 $result = api_blocks_list('json');
2856 $this->assertArrayHasKey('user', $result);
2860 * Test the api_blocks_list() function an undefined cursor GET variable.
2864 public function testApiBlocksListWithUndefinedCursor()
2866 $_GET['cursor'] = 'undefined';
2867 $this->assertFalse(api_blocks_list('json'));
2871 * Test the api_friendships_incoming() function.
2875 public function testApiFriendshipsIncoming()
2877 $result = api_friendships_incoming('json');
2878 $this->assertArrayHasKey('id', $result);
2882 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2886 public function testApiFriendshipsIncomingWithUndefinedCursor()
2888 $_GET['cursor'] = 'undefined';
2889 $this->assertFalse(api_friendships_incoming('json'));
2893 * Test the api_statusnet_config() function.
2897 public function testApiStatusnetConfig()
2899 $result = api_statusnet_config('json');
2900 $this->assertEquals('localhost', $result['config']['site']['server']);
2901 $this->assertEquals('default', $result['config']['site']['theme']);
2902 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2903 $this->assertTrue($result['config']['site']['fancy']);
2904 $this->assertEquals('en', $result['config']['site']['language']);
2905 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2906 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2907 $this->assertEquals('false', $result['config']['site']['private']);
2908 $this->assertEquals('false', $result['config']['site']['ssl']);
2909 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2913 * Test the api_statusnet_version() function.
2917 public function testApiStatusnetVersion()
2919 $result = api_statusnet_version('json');
2920 $this->assertEquals('0.9.7', $result['version']);
2924 * Test the api_ff_ids() function.
2928 public function testApiFfIds()
2930 $result = api_ff_ids('json');
2931 $this->assertNull($result);
2935 * Test the api_ff_ids() function with a result.
2939 public function testApiFfIdsWithResult()
2941 $this->markTestIncomplete();
2945 * Test the api_ff_ids() function without an authenticated user.
2948 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2950 public function testApiFfIdsWithoutAuthenticatedUser()
2952 $_SESSION['authenticated'] = false;
2957 * Test the api_friends_ids() function.
2961 public function testApiFriendsIds()
2963 $result = api_friends_ids('json');
2964 $this->assertNull($result);
2968 * Test the api_followers_ids() function.
2972 public function testApiFollowersIds()
2974 $result = api_followers_ids('json');
2975 $this->assertNull($result);
2979 * Test the api_direct_messages_new() function.
2983 public function testApiDirectMessagesNew()
2985 $result = api_direct_messages_new('json');
2986 $this->assertNull($result);
2990 * Test the api_direct_messages_new() function without an authenticated user.
2993 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2995 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2997 $_SESSION['authenticated'] = false;
2998 api_direct_messages_new('json');
3002 * Test the api_direct_messages_new() function with an user ID.
3006 public function testApiDirectMessagesNewWithUserId()
3008 $_POST['text'] = 'message_text';
3009 $_POST['user_id'] = $this->otherUser['id'];
3010 $result = api_direct_messages_new('json');
3011 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3015 * Test the api_direct_messages_new() function with a screen name.
3019 public function testApiDirectMessagesNewWithScreenName()
3021 $_POST['text'] = 'message_text';
3022 $_POST['screen_name'] = $this->friendUser['nick'];
3023 $result = api_direct_messages_new('json');
3024 $this->assertContains('message_text', $result['direct_message']['text']);
3025 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3026 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3030 * Test the api_direct_messages_new() function with a title.
3034 public function testApiDirectMessagesNewWithTitle()
3036 $_POST['text'] = 'message_text';
3037 $_POST['screen_name'] = $this->friendUser['nick'];
3038 $_REQUEST['title'] = 'message_title';
3039 $result = api_direct_messages_new('json');
3040 $this->assertContains('message_text', $result['direct_message']['text']);
3041 $this->assertContains('message_title', $result['direct_message']['text']);
3042 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3043 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3047 * Test the api_direct_messages_new() function with an RSS result.
3051 public function testApiDirectMessagesNewWithRss()
3053 $_POST['text'] = 'message_text';
3054 $_POST['screen_name'] = $this->friendUser['nick'];
3055 $result = api_direct_messages_new('rss');
3056 $this->assertXml($result, 'direct-messages');
3060 * Test the api_direct_messages_destroy() function.
3063 * @expectedException Friendica\Network\HTTPException\BadRequestException
3065 public function testApiDirectMessagesDestroy()
3067 api_direct_messages_destroy('json');
3071 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3075 public function testApiDirectMessagesDestroyWithVerbose()
3077 $_GET['friendica_verbose'] = 'true';
3078 $result = api_direct_messages_destroy('json');
3079 $this->assertEquals(
3082 'result' => 'error',
3083 'message' => 'message id or parenturi not specified'
3091 * Test the api_direct_messages_destroy() function without an authenticated user.
3094 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3096 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3098 $_SESSION['authenticated'] = false;
3099 api_direct_messages_destroy('json');
3103 * Test the api_direct_messages_destroy() function with a non-zero ID.
3106 * @expectedException Friendica\Network\HTTPException\BadRequestException
3108 public function testApiDirectMessagesDestroyWithId()
3110 $_REQUEST['id'] = 1;
3111 api_direct_messages_destroy('json');
3115 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3119 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3121 $_REQUEST['id'] = 1;
3122 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3123 $_GET['friendica_verbose'] = 'true';
3124 $result = api_direct_messages_destroy('json');
3125 $this->assertEquals(
3128 'result' => 'error',
3129 'message' => 'message id not in database'
3137 * Test the api_direct_messages_destroy() function with a non-zero ID.
3141 public function testApiDirectMessagesDestroyWithCorrectId()
3143 $this->markTestIncomplete('We need to add a dataset for this.');
3147 * Test the api_direct_messages_box() function.
3151 public function testApiDirectMessagesBoxWithSentbox()
3153 $_REQUEST['page'] = -1;
3154 $_REQUEST['max_id'] = 10;
3155 $result = api_direct_messages_box('json', 'sentbox', 'false');
3156 $this->assertArrayHasKey('direct_message', $result);
3160 * Test the api_direct_messages_box() function.
3164 public function testApiDirectMessagesBoxWithConversation()
3166 $result = api_direct_messages_box('json', 'conversation', 'false');
3167 $this->assertArrayHasKey('direct_message', $result);
3171 * Test the api_direct_messages_box() function.
3175 public function testApiDirectMessagesBoxWithAll()
3177 $result = api_direct_messages_box('json', 'all', 'false');
3178 $this->assertArrayHasKey('direct_message', $result);
3182 * Test the api_direct_messages_box() function.
3186 public function testApiDirectMessagesBoxWithInbox()
3188 $result = api_direct_messages_box('json', 'inbox', 'false');
3189 $this->assertArrayHasKey('direct_message', $result);
3193 * Test the api_direct_messages_box() function.
3197 public function testApiDirectMessagesBoxWithVerbose()
3199 $result = api_direct_messages_box('json', 'sentbox', 'true');
3200 $this->assertEquals(
3203 'result' => 'error',
3204 'message' => 'no mails available'
3212 * Test the api_direct_messages_box() function with a RSS result.
3216 public function testApiDirectMessagesBoxWithRss()
3218 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3219 $this->assertXml($result, 'direct-messages');
3223 * Test the api_direct_messages_box() function without an authenticated user.
3226 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3228 public function testApiDirectMessagesBoxWithUnallowedUser()
3230 $_SESSION['allow_api'] = false;
3231 $_GET['screen_name'] = $this->selfUser['nick'];
3232 api_direct_messages_box('json', 'sentbox', 'false');
3236 * Test the api_direct_messages_sentbox() function.
3240 public function testApiDirectMessagesSentbox()
3242 $result = api_direct_messages_sentbox('json');
3243 $this->assertArrayHasKey('direct_message', $result);
3247 * Test the api_direct_messages_inbox() function.
3251 public function testApiDirectMessagesInbox()
3253 $result = api_direct_messages_inbox('json');
3254 $this->assertArrayHasKey('direct_message', $result);
3258 * Test the api_direct_messages_all() function.
3262 public function testApiDirectMessagesAll()
3264 $result = api_direct_messages_all('json');
3265 $this->assertArrayHasKey('direct_message', $result);
3269 * Test the api_direct_messages_conversation() function.
3273 public function testApiDirectMessagesConversation()
3275 $result = api_direct_messages_conversation('json');
3276 $this->assertArrayHasKey('direct_message', $result);
3280 * Test the api_oauth_request_token() function.
3284 public function testApiOauthRequestToken()
3286 $this->markTestIncomplete('killme() kills phpunit as well');
3290 * Test the api_oauth_access_token() function.
3294 public function testApiOauthAccessToken()
3296 $this->markTestIncomplete('killme() kills phpunit as well');
3300 * Test the api_fr_photoalbum_delete() function.
3303 * @expectedException Friendica\Network\HTTPException\BadRequestException
3305 public function testApiFrPhotoalbumDelete()
3307 api_fr_photoalbum_delete('json');
3311 * Test the api_fr_photoalbum_delete() function with an album name.
3314 * @expectedException Friendica\Network\HTTPException\BadRequestException
3316 public function testApiFrPhotoalbumDeleteWithAlbum()
3318 $_REQUEST['album'] = 'album_name';
3319 api_fr_photoalbum_delete('json');
3323 * Test the api_fr_photoalbum_delete() function with an album name.
3327 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3329 $this->markTestIncomplete('We need to add a dataset for this.');
3333 * Test the api_fr_photoalbum_delete() function.
3336 * @expectedException Friendica\Network\HTTPException\BadRequestException
3338 public function testApiFrPhotoalbumUpdate()
3340 api_fr_photoalbum_update('json');
3344 * Test the api_fr_photoalbum_delete() function with an album name.
3347 * @expectedException Friendica\Network\HTTPException\BadRequestException
3349 public function testApiFrPhotoalbumUpdateWithAlbum()
3351 $_REQUEST['album'] = 'album_name';
3352 api_fr_photoalbum_update('json');
3356 * Test the api_fr_photoalbum_delete() function with an album name.
3359 * @expectedException Friendica\Network\HTTPException\BadRequestException
3361 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3363 $_REQUEST['album'] = 'album_name';
3364 $_REQUEST['album_new'] = 'album_name';
3365 api_fr_photoalbum_update('json');
3369 * Test the api_fr_photoalbum_update() function without an authenticated user.
3372 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3374 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3376 $_SESSION['authenticated'] = false;
3377 api_fr_photoalbum_update('json');
3381 * Test the api_fr_photoalbum_delete() function with an album name.
3385 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3387 $this->markTestIncomplete('We need to add a dataset for this.');
3391 * Test the api_fr_photos_list() function.
3395 public function testApiFrPhotosList()
3397 $result = api_fr_photos_list('json');
3398 $this->assertArrayHasKey('photo', $result);
3402 * Test the api_fr_photos_list() function without an authenticated user.
3405 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3407 public function testApiFrPhotosListWithoutAuthenticatedUser()
3409 $_SESSION['authenticated'] = false;
3410 api_fr_photos_list('json');
3414 * Test the api_fr_photo_create_update() function.
3417 * @expectedException Friendica\Network\HTTPException\BadRequestException
3419 public function testApiFrPhotoCreateUpdate()
3421 api_fr_photo_create_update('json');
3425 * Test the api_fr_photo_create_update() function without an authenticated user.
3428 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3430 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3432 $_SESSION['authenticated'] = false;
3433 api_fr_photo_create_update('json');
3437 * Test the api_fr_photo_create_update() function with an album name.
3440 * @expectedException Friendica\Network\HTTPException\BadRequestException
3442 public function testApiFrPhotoCreateUpdateWithAlbum()
3444 $_REQUEST['album'] = 'album_name';
3445 api_fr_photo_create_update('json');
3449 * Test the api_fr_photo_create_update() function with the update mode.
3453 public function testApiFrPhotoCreateUpdateWithUpdate()
3455 $this->markTestIncomplete('We need to create a dataset for this');
3459 * Test the api_fr_photo_create_update() function with an uploaded file.
3463 public function testApiFrPhotoCreateUpdateWithFile()
3465 $this->markTestIncomplete();
3469 * Test the api_fr_photo_delete() function.
3472 * @expectedException Friendica\Network\HTTPException\BadRequestException
3474 public function testApiFrPhotoDelete()
3476 api_fr_photo_delete('json');
3480 * Test the api_fr_photo_delete() function without an authenticated user.
3483 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3485 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3487 $_SESSION['authenticated'] = false;
3488 api_fr_photo_delete('json');
3492 * Test the api_fr_photo_delete() function with a photo ID.
3495 * @expectedException Friendica\Network\HTTPException\BadRequestException
3497 public function testApiFrPhotoDeleteWithPhotoId()
3499 $_REQUEST['photo_id'] = 1;
3500 api_fr_photo_delete('json');
3504 * Test the api_fr_photo_delete() function with a correct photo ID.
3508 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3510 $this->markTestIncomplete('We need to create a dataset for this.');
3514 * Test the api_fr_photo_detail() function.
3517 * @expectedException Friendica\Network\HTTPException\BadRequestException
3519 public function testApiFrPhotoDetail()
3521 api_fr_photo_detail('json');
3525 * Test the api_fr_photo_detail() function without an authenticated user.
3528 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3530 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3532 $_SESSION['authenticated'] = false;
3533 api_fr_photo_detail('json');
3537 * Test the api_fr_photo_detail() function with a photo ID.
3540 * @expectedException Friendica\Network\HTTPException\NotFoundException
3542 public function testApiFrPhotoDetailWithPhotoId()
3544 $_REQUEST['photo_id'] = 1;
3545 api_fr_photo_detail('json');
3549 * Test the api_fr_photo_detail() function with a correct photo ID.
3553 public function testApiFrPhotoDetailCorrectPhotoId()
3555 $this->markTestIncomplete('We need to create a dataset for this.');
3559 * Test the api_account_update_profile_image() function.
3562 * @expectedException Friendica\Network\HTTPException\BadRequestException
3564 public function testApiAccountUpdateProfileImage()
3566 api_account_update_profile_image('json');
3570 * Test the api_account_update_profile_image() function without an authenticated user.
3573 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3575 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3577 $_SESSION['authenticated'] = false;
3578 api_account_update_profile_image('json');
3582 * Test the api_account_update_profile_image() function with an uploaded file.
3585 * @expectedException Friendica\Network\HTTPException\BadRequestException
3587 public function testApiAccountUpdateProfileImageWithUpload()
3589 $this->markTestIncomplete();
3594 * Test the api_account_update_profile() function.
3598 public function testApiAccountUpdateProfile()
3600 $_POST['name'] = 'new_name';
3601 $_POST['description'] = 'new_description';
3602 $result = api_account_update_profile('json');
3603 // We can't use assertSelfUser() here because the user object is missing some properties.
3604 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3605 $this->assertEquals('DFRN', $result['user']['location']);
3606 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3607 $this->assertEquals('dfrn', $result['user']['network']);
3608 $this->assertEquals('new_name', $result['user']['name']);
3609 $this->assertEquals('new_description', $result['user']['description']);
3613 * Test the check_acl_input() function.
3617 public function testCheckAclInput()
3619 $result = check_acl_input('<aclstring>');
3620 // Where does this result come from?
3621 $this->assertEquals(1, $result);
3625 * Test the check_acl_input() function with an empty ACL string.
3629 public function testCheckAclInputWithEmptyAclString()
3631 $result = check_acl_input(' ');
3632 $this->assertFalse($result);
3636 * Test the save_media_to_database() function.
3640 public function testSaveMediaToDatabase()
3642 $this->markTestIncomplete();
3646 * Test the post_photo_item() function.
3650 public function testPostPhotoItem()
3652 $this->markTestIncomplete();
3656 * Test the prepare_photo_data() function.
3660 public function testPreparePhotoData()
3662 $this->markTestIncomplete();
3666 * Test the api_friendica_remoteauth() function.
3669 * @expectedException Friendica\Network\HTTPException\BadRequestException
3671 public function testApiFriendicaRemoteauth()
3673 api_friendica_remoteauth();
3677 * Test the api_friendica_remoteauth() function with an URL.
3680 * @expectedException Friendica\Network\HTTPException\BadRequestException
3682 public function testApiFriendicaRemoteauthWithUrl()
3684 $_GET['url'] = 'url';
3685 $_GET['c_url'] = 'url';
3686 api_friendica_remoteauth();
3690 * Test the api_friendica_remoteauth() function with a correct URL.
3694 public function testApiFriendicaRemoteauthWithCorrectUrl()
3696 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3697 $_GET['url'] = 'url';
3698 $_GET['c_url'] = $this->selfUser['nurl'];
3699 api_friendica_remoteauth();
3703 * Test the api_share_as_retweet() function.
3707 public function testApiShareAsRetweet()
3709 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3710 $result = api_share_as_retweet($item);
3711 $this->assertFalse($result);
3715 * Test the api_share_as_retweet() function with a valid item.
3719 public function testApiShareAsRetweetWithValidItem()
3721 $this->markTestIncomplete();
3725 * Test the api_get_nick() function.
3729 public function testApiGetNick()
3731 $result = api_get_nick($this->otherUser['nurl']);
3732 $this->assertEquals('othercontact', $result);
3736 * Test the api_get_nick() function with a wrong URL.
3740 public function testApiGetNickWithWrongUrl()
3742 $result = api_get_nick('wrong_url');
3743 $this->assertFalse($result);
3747 * Test the api_in_reply_to() function.
3751 public function testApiInReplyTo()
3753 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3754 $this->assertArrayHasKey('status_id', $result);
3755 $this->assertArrayHasKey('user_id', $result);
3756 $this->assertArrayHasKey('status_id_str', $result);
3757 $this->assertArrayHasKey('user_id_str', $result);
3758 $this->assertArrayHasKey('screen_name', $result);
3762 * Test the api_in_reply_to() function with a valid item.
3766 public function testApiInReplyToWithValidItem()
3768 $this->markTestIncomplete();
3772 * Test the api_clean_plain_items() function.
3776 public function testApiCleanPlainItems()
3778 $_REQUEST['include_entities'] = 'true';
3779 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3780 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3784 * Test the api_best_nickname() function.
3788 public function testApiBestNickname()
3791 $result = api_best_nickname($contacts);
3792 $this->assertNull($result);
3796 * Test the api_best_nickname() function with contacts.
3800 public function testApiBestNicknameWithContacts()
3802 $this->markTestIncomplete();
3806 * Test the api_friendica_group_show() function.
3810 public function testApiFriendicaGroupShow()
3812 $this->markTestIncomplete();
3816 * Test the api_friendica_group_delete() function.
3820 public function testApiFriendicaGroupDelete()
3822 $this->markTestIncomplete();
3826 * Test the api_lists_destroy() function.
3830 public function testApiListsDestroy()
3832 $this->markTestIncomplete();
3836 * Test the group_create() function.
3840 public function testGroupCreate()
3842 $this->markTestIncomplete();
3846 * Test the api_friendica_group_create() function.
3850 public function testApiFriendicaGroupCreate()
3852 $this->markTestIncomplete();
3856 * Test the api_lists_create() function.
3860 public function testApiListsCreate()
3862 $this->markTestIncomplete();
3866 * Test the api_friendica_group_update() function.
3870 public function testApiFriendicaGroupUpdate()
3872 $this->markTestIncomplete();
3876 * Test the api_lists_update() function.
3880 public function testApiListsUpdate()
3882 $this->markTestIncomplete();
3886 * Test the api_friendica_activity() function.
3890 public function testApiFriendicaActivity()
3892 $this->markTestIncomplete();
3896 * Test the api_friendica_notification() function.
3899 * @expectedException Friendica\Network\HTTPException\BadRequestException
3901 public function testApiFriendicaNotification()
3903 api_friendica_notification('json');
3907 * Test the api_friendica_notification() function without an authenticated user.
3910 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3912 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3914 $_SESSION['authenticated'] = false;
3915 api_friendica_notification('json');
3919 * Test the api_friendica_notification() function with an argument count.
3923 public function testApiFriendicaNotificationWithArgumentCount()
3925 $this->app->argv = ['api', 'friendica', 'notification'];
3926 $this->app->argc = count($this->app->argv);
3927 $result = api_friendica_notification('json');
3928 $this->assertEquals(['note' => false], $result);
3932 * Test the api_friendica_notification() function with an XML result.
3936 public function testApiFriendicaNotificationWithXmlResult()
3938 $this->app->argv = ['api', 'friendica', 'notification'];
3939 $this->app->argc = count($this->app->argv);
3940 $result = api_friendica_notification('xml');
3941 $this->assertXml($result, 'notes');
3945 * Test the api_friendica_notification_seen() function.
3949 public function testApiFriendicaNotificationSeen()
3951 $this->markTestIncomplete();
3955 * Test the api_friendica_direct_messages_setseen() function.
3959 public function testApiFriendicaDirectMessagesSetseen()
3961 $this->markTestIncomplete();
3965 * Test the api_friendica_direct_messages_search() function.
3969 public function testApiFriendicaDirectMessagesSearch()
3971 $this->markTestIncomplete();
3975 * Test the api_friendica_profile_show() function.
3979 public function testApiFriendicaProfileShow()
3981 $result = api_friendica_profile_show('json');
3982 // We can't use assertSelfUser() here because the user object is missing some properties.
3983 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3984 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3985 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3986 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3987 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3988 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3989 $this->assertFalse($result['$result']['multi_profiles']);
3993 * Test the api_friendica_profile_show() function with a profile ID.
3997 public function testApiFriendicaProfileShowWithProfileId()
3999 $this->markTestIncomplete('We need to add a dataset for this.');
4003 * Test the api_friendica_profile_show() function with a wrong profile ID.
4006 * @expectedException Friendica\Network\HTTPException\BadRequestException
4008 public function testApiFriendicaProfileShowWithWrongProfileId()
4010 $_REQUEST['profile_id'] = 666;
4011 api_friendica_profile_show('json');
4015 * Test the api_friendica_profile_show() function without an authenticated user.
4018 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4020 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4022 $_SESSION['authenticated'] = false;
4023 api_friendica_profile_show('json');
4027 * Test the api_saved_searches_list() function.
4031 public function testApiSavedSearchesList()
4033 $result = api_saved_searches_list('json');
4034 $this->assertEquals(1, $result['terms'][0]['id']);
4035 $this->assertEquals(1, $result['terms'][0]['id_str']);
4036 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4037 $this->assertEquals('Saved search', $result['terms'][0]['query']);