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;
15 use Friendica\Core\Session\ISession;
16 use Friendica\Core\System;
17 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 BaseObject::setDependencyInjection($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 = BaseObject::getApp();
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 /** @var ISession $session */
119 $session = BaseObject::getClass(ISession::class);
122 // Most API require login so we force the session
125 'authenticated' => true,
126 'uid' => $this->selfUser['id']
135 * Assert that an user array contains expected keys.
137 * @param array $user User array
141 private function assertSelfUser(array $user)
143 $this->assertEquals($this->selfUser['id'], $user['uid']);
144 $this->assertEquals($this->selfUser['id'], $user['cid']);
145 $this->assertEquals(1, $user['self']);
146 $this->assertEquals('DFRN', $user['location']);
147 $this->assertEquals($this->selfUser['name'], $user['name']);
148 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
149 $this->assertEquals('dfrn', $user['network']);
150 $this->assertTrue($user['verified']);
154 * Assert that an user array contains expected keys.
156 * @param array $user User array
160 private function assertOtherUser(array $user)
162 $this->assertEquals($this->otherUser['id'], $user['id']);
163 $this->assertEquals($this->otherUser['id'], $user['id_str']);
164 $this->assertEquals(0, $user['self']);
165 $this->assertEquals($this->otherUser['name'], $user['name']);
166 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
167 $this->assertFalse($user['verified']);
171 * Assert that a status array contains expected keys.
173 * @param array $status Status array
177 private function assertStatus(array $status)
179 $this->assertInternalType('string', $status['text']);
180 $this->assertInternalType('int', $status['id']);
181 // We could probably do more checks here.
185 * Assert that a list array contains expected keys.
187 * @param array $list List array
191 private function assertList(array $list)
193 $this->assertInternalType('string', $list['name']);
194 $this->assertInternalType('int', $list['id']);
195 $this->assertInternalType('string', $list['id_str']);
196 $this->assertContains($list['mode'], ['public', 'private']);
197 // We could probably do more checks here.
201 * Assert that the string is XML and contain the root element.
203 * @param string $result XML string
204 * @param string $root_element Root element name
208 private function assertXml($result, $root_element)
210 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
211 $this->assertContains('<' . $root_element, $result);
212 // We could probably do more checks here.
216 * Get the path to a temporary empty PNG image.
218 * @return string Path
220 private function getTempImage()
222 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
226 // Empty 1x1 px PNG image
227 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
235 * Test the api_user() function.
239 public function testApiUser()
241 $this->assertEquals($this->selfUser['id'], api_user());
245 * Test the api_user() function with an unallowed user.
249 public function testApiUserWithUnallowedUser()
251 $_SESSION = ['allow_api' => false];
252 $this->assertEquals(false, api_user());
256 * Test the api_source() function.
260 public function testApiSource()
262 $this->assertEquals('api', api_source());
266 * Test the api_source() function with a Twidere user agent.
270 public function testApiSourceWithTwidere()
272 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
273 $this->assertEquals('Twidere', api_source());
277 * Test the api_source() function with a GET parameter.
281 public function testApiSourceWithGet()
283 $_GET['source'] = 'source_name';
284 $this->assertEquals('source_name', api_source());
288 * Test the api_date() function.
292 public function testApiDate()
294 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
298 * Test the api_register_func() function.
302 public function testApiRegisterFunc()
314 $this->assertTrue($API['api_path']['auth']);
315 $this->assertEquals('method', $API['api_path']['method']);
316 $this->assertTrue(is_callable($API['api_path']['func']));
320 * Test the api_login() function without any login.
323 * @runInSeparateProcess
324 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
326 public function testApiLoginWithoutLogin()
328 api_login($this->app);
332 * Test the api_login() function with a bad login.
335 * @runInSeparateProcess
336 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
338 public function testApiLoginWithBadLogin()
340 $_SERVER['PHP_AUTH_USER'] = 'user@server';
341 api_login($this->app);
345 * Test the api_login() function with oAuth.
349 public function testApiLoginWithOauth()
351 $this->markTestIncomplete('Can we test this easily?');
355 * Test the api_login() function with authentication provided by an addon.
359 public function testApiLoginWithAddonAuth()
361 $this->markTestIncomplete('Can we test this easily?');
365 * Test the api_login() function with a correct login.
368 * @runInSeparateProcess
370 public function testApiLoginWithCorrectLogin()
372 $_SERVER['PHP_AUTH_USER'] = 'Test user';
373 $_SERVER['PHP_AUTH_PW'] = 'password';
374 api_login($this->app);
378 * Test the api_login() function with a remote user.
381 * @runInSeparateProcess
382 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
384 public function testApiLoginWithRemoteUser()
386 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
387 api_login($this->app);
391 * Test the api_check_method() function.
395 public function testApiCheckMethod()
397 $this->assertFalse(api_check_method('method'));
401 * Test the api_check_method() function with a correct method.
405 public function testApiCheckMethodWithCorrectMethod()
407 $_SERVER['REQUEST_METHOD'] = 'method';
408 $this->assertTrue(api_check_method('method'));
412 * Test the api_check_method() function with a wildcard.
416 public function testApiCheckMethodWithWildcard()
418 $this->assertTrue(api_check_method('*'));
422 * Test the api_call() function.
425 * @runInSeparateProcess
427 public function testApiCall()
431 'method' => 'method',
432 'func' => function () {
433 return ['data' => ['some_data']];
436 $_SERVER['REQUEST_METHOD'] = 'method';
437 $_GET['callback'] = 'callback_name';
439 $this->app->query_string = 'api_path';
441 'callback_name(["some_data"])',
447 * Test the api_call() function with the profiled enabled.
450 * @runInSeparateProcess
452 public function testApiCallWithProfiler()
456 'method' => 'method',
457 'func' => function () {
458 return ['data' => ['some_data']];
461 $_SERVER['REQUEST_METHOD'] = 'method';
462 $this->config->set('system', 'profiler', true);
463 $this->config->set('rendertime', 'callstack', true);
464 $this->app->callstack = [
465 'database' => ['some_function' => 200],
466 'database_write' => ['some_function' => 200],
467 'cache' => ['some_function' => 200],
468 'cache_write' => ['some_function' => 200],
469 'network' => ['some_function' => 200]
472 $this->app->query_string = 'api_path';
480 * Test the api_call() function without any result.
483 * @runInSeparateProcess
485 public function testApiCallWithNoResult()
489 'method' => 'method',
490 'func' => function () {
494 $_SERVER['REQUEST_METHOD'] = 'method';
496 $this->app->query_string = 'api_path';
498 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
504 * Test the api_call() function with an unimplemented API.
507 * @runInSeparateProcess
509 public function testApiCallWithUninplementedApi()
512 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
518 * Test the api_call() function with a JSON result.
521 * @runInSeparateProcess
523 public function testApiCallWithJson()
527 'method' => 'method',
528 'func' => function () {
529 return ['data' => ['some_data']];
532 $_SERVER['REQUEST_METHOD'] = 'method';
534 $this->app->query_string = 'api_path.json';
542 * Test the api_call() function with an XML result.
545 * @runInSeparateProcess
547 public function testApiCallWithXml()
551 'method' => 'method',
552 'func' => function () {
556 $_SERVER['REQUEST_METHOD'] = 'method';
558 $this->app->query_string = 'api_path.xml';
566 * Test the api_call() function with an RSS result.
569 * @runInSeparateProcess
571 public function testApiCallWithRss()
575 'method' => 'method',
576 'func' => function () {
580 $_SERVER['REQUEST_METHOD'] = 'method';
582 $this->app->query_string = 'api_path.rss';
584 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
591 * Test the api_call() function with an Atom result.
594 * @runInSeparateProcess
596 public function testApiCallWithAtom()
600 'method' => 'method',
601 'func' => function () {
605 $_SERVER['REQUEST_METHOD'] = 'method';
607 $this->app->query_string = 'api_path.atom';
609 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
616 * Test the api_call() function with an unallowed method.
619 * @runInSeparateProcess
621 public function testApiCallWithWrongMethod()
624 $API['api_path'] = ['method' => 'method'];
626 $this->app->query_string = 'api_path';
628 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
634 * Test the api_call() function with an unauthorized user.
637 * @runInSeparateProcess
639 public function testApiCallWithWrongAuth()
643 'method' => 'method',
646 $_SERVER['REQUEST_METHOD'] = 'method';
647 $_SESSION['authenticated'] = false;
649 $this->app->query_string = 'api_path';
651 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
657 * Test the api_error() function with a JSON result.
660 * @runInSeparateProcess
662 public function testApiErrorWithJson()
665 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
666 api_error('json', new HTTPException\OKException('error_message'))
671 * Test the api_error() function with an XML result.
674 * @runInSeparateProcess
676 public function testApiErrorWithXml()
679 '<?xml version="1.0"?>' . "\n" .
680 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
681 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
682 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
683 ' <error>error_message</error>' . "\n" .
684 ' <code>200 OK</code>' . "\n" .
685 ' <request/>' . "\n" .
687 api_error('xml', new HTTPException\OKException('error_message'))
692 * Test the api_error() function with an RSS result.
695 * @runInSeparateProcess
697 public function testApiErrorWithRss()
700 '<?xml version="1.0"?>' . "\n" .
701 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
702 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
703 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
704 ' <error>error_message</error>' . "\n" .
705 ' <code>200 OK</code>' . "\n" .
706 ' <request/>' . "\n" .
708 api_error('rss', new HTTPException\OKException('error_message'))
713 * Test the api_error() function with an Atom result.
716 * @runInSeparateProcess
718 public function testApiErrorWithAtom()
721 '<?xml version="1.0"?>' . "\n" .
722 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
723 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
724 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
725 ' <error>error_message</error>' . "\n" .
726 ' <code>200 OK</code>' . "\n" .
727 ' <request/>' . "\n" .
729 api_error('atom', new HTTPException\OKException('error_message'))
734 * Test the api_rss_extra() function.
738 public function testApiRssExtra()
740 $user_info = ['url' => 'user_url', 'lang' => 'en'];
741 $result = api_rss_extra($this->app, [], $user_info);
742 $this->assertEquals($user_info, $result['$user']);
743 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
744 $this->assertArrayHasKey('self', $result['$rss']);
745 $this->assertArrayHasKey('base', $result['$rss']);
746 $this->assertArrayHasKey('updated', $result['$rss']);
747 $this->assertArrayHasKey('atom_updated', $result['$rss']);
748 $this->assertArrayHasKey('language', $result['$rss']);
749 $this->assertArrayHasKey('logo', $result['$rss']);
753 * Test the api_rss_extra() function without any user info.
757 public function testApiRssExtraWithoutUserInfo()
759 $result = api_rss_extra($this->app, [], null);
760 $this->assertInternalType('array', $result['$user']);
761 $this->assertArrayHasKey('alternate', $result['$rss']);
762 $this->assertArrayHasKey('self', $result['$rss']);
763 $this->assertArrayHasKey('base', $result['$rss']);
764 $this->assertArrayHasKey('updated', $result['$rss']);
765 $this->assertArrayHasKey('atom_updated', $result['$rss']);
766 $this->assertArrayHasKey('language', $result['$rss']);
767 $this->assertArrayHasKey('logo', $result['$rss']);
771 * Test the api_unique_id_to_nurl() function.
775 public function testApiUniqueIdToNurl()
777 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
781 * Test the api_unique_id_to_nurl() function with a correct ID.
785 public function testApiUniqueIdToNurlWithCorrectId()
787 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
791 * Test the api_get_user() function.
795 public function testApiGetUser()
797 $user = api_get_user($this->app);
798 $this->assertSelfUser($user);
799 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
800 $this->assertEquals('6fdbe8', $user['profile_link_color']);
801 $this->assertEquals('ededed', $user['profile_background_color']);
805 * Test the api_get_user() function with a Frio schema.
809 public function testApiGetUserWithFrioSchema()
811 $pConfig = $this->dice->create(PConfiguration::class);
812 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
813 $user = api_get_user($this->app);
814 $this->assertSelfUser($user);
815 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
816 $this->assertEquals('6fdbe8', $user['profile_link_color']);
817 $this->assertEquals('ededed', $user['profile_background_color']);
821 * Test the api_get_user() function with a custom Frio schema.
825 public function testApiGetUserWithCustomFrioSchema()
827 $pConfig = $this->dice->create(PConfiguration::class);
828 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
829 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
830 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
831 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
832 $user = api_get_user($this->app);
833 $this->assertSelfUser($user);
834 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
835 $this->assertEquals('123456', $user['profile_link_color']);
836 $this->assertEquals('123456', $user['profile_background_color']);
840 * Test the api_get_user() function with an empty Frio schema.
844 public function testApiGetUserWithEmptyFrioSchema()
846 $pConfig = $this->dice->create(PConfiguration::class);
847 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
848 $user = api_get_user($this->app);
849 $this->assertSelfUser($user);
850 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
851 $this->assertEquals('6fdbe8', $user['profile_link_color']);
852 $this->assertEquals('ededed', $user['profile_background_color']);
856 * Test the api_get_user() function with an user that is not allowed to use the API.
859 * @runInSeparateProcess
861 public function testApiGetUserWithoutApiUser()
863 $_SERVER['PHP_AUTH_USER'] = 'Test user';
864 $_SERVER['PHP_AUTH_PW'] = 'password';
865 $_SESSION['allow_api'] = false;
866 $this->assertFalse(api_get_user($this->app));
870 * Test the api_get_user() function with an user ID in a GET parameter.
874 public function testApiGetUserWithGetId()
876 $_GET['user_id'] = $this->otherUser['id'];
877 $this->assertOtherUser(api_get_user($this->app));
881 * Test the api_get_user() function with a wrong user ID in a GET parameter.
884 * @expectedException Friendica\Network\HTTPException\BadRequestException
886 public function testApiGetUserWithWrongGetId()
888 $_GET['user_id'] = $this->wrongUserId;
889 $this->assertOtherUser(api_get_user($this->app));
893 * Test the api_get_user() function with an user name in a GET parameter.
897 public function testApiGetUserWithGetName()
899 $_GET['screen_name'] = $this->selfUser['nick'];
900 $this->assertSelfUser(api_get_user($this->app));
904 * Test the api_get_user() function with a profile URL in a GET parameter.
908 public function testApiGetUserWithGetUrl()
910 $_GET['profileurl'] = $this->selfUser['nurl'];
911 $this->assertSelfUser(api_get_user($this->app));
915 * Test the api_get_user() function with an user ID in the API path.
919 public function testApiGetUserWithNumericCalledApi()
922 $called_api = ['api_path'];
923 $this->app->argv[1] = $this->otherUser['id'] . '.json';
924 $this->assertOtherUser(api_get_user($this->app));
928 * Test the api_get_user() function with the $called_api global variable.
932 public function testApiGetUserWithCalledApi()
935 $called_api = ['api', 'api_path'];
936 $this->assertSelfUser(api_get_user($this->app));
940 * Test the api_get_user() function with a valid user.
944 public function testApiGetUserWithCorrectUser()
946 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
950 * Test the api_get_user() function with a wrong user ID.
953 * @expectedException Friendica\Network\HTTPException\BadRequestException
955 public function testApiGetUserWithWrongUser()
957 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
961 * Test the api_get_user() function with a 0 user ID.
965 public function testApiGetUserWithZeroUser()
967 $this->assertSelfUser(api_get_user($this->app, 0));
971 * Test the api_item_get_user() function.
975 public function testApiItemGetUser()
977 $users = api_item_get_user($this->app, []);
978 $this->assertSelfUser($users[0]);
982 * Test the api_item_get_user() function with a different item parent.
986 public function testApiItemGetUserWithDifferentParent()
988 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
989 $this->assertSelfUser($users[0]);
990 $this->assertEquals($users[0], $users[1]);
994 * Test the api_walk_recursive() function.
998 public function testApiWalkRecursive()
1001 $this->assertEquals(
1006 // Should we test this with a callback that actually does something?
1014 * Test the api_walk_recursive() function with an array.
1018 public function testApiWalkRecursiveWithArray()
1020 $array = [['item1'], ['item2']];
1021 $this->assertEquals(
1026 // Should we test this with a callback that actually does something?
1034 * Test the api_reformat_xml() function.
1038 public function testApiReformatXml()
1042 $this->assertTrue(api_reformat_xml($item, $key));
1043 $this->assertEquals('true', $item);
1047 * Test the api_reformat_xml() function with a statusnet_api key.
1051 public function testApiReformatXmlWithStatusnetKey()
1054 $key = 'statusnet_api';
1055 $this->assertTrue(api_reformat_xml($item, $key));
1056 $this->assertEquals('statusnet:api', $key);
1060 * Test the api_reformat_xml() function with a friendica_api key.
1064 public function testApiReformatXmlWithFriendicaKey()
1067 $key = 'friendica_api';
1068 $this->assertTrue(api_reformat_xml($item, $key));
1069 $this->assertEquals('friendica:api', $key);
1073 * Test the api_create_xml() function.
1077 public function testApiCreateXml()
1079 $this->assertEquals(
1080 '<?xml version="1.0"?>' . "\n" .
1081 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1082 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1083 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1084 ' <data>some_data</data>' . "\n" .
1085 '</root_element>' . "\n",
1086 api_create_xml(['data' => ['some_data']], 'root_element')
1091 * Test the api_create_xml() function without any XML namespace.
1095 public function testApiCreateXmlWithoutNamespaces()
1097 $this->assertEquals(
1098 '<?xml version="1.0"?>' . "\n" .
1100 ' <data>some_data</data>' . "\n" .
1102 api_create_xml(['data' => ['some_data']], 'ok')
1107 * Test the api_format_data() function.
1111 public function testApiFormatData()
1113 $data = ['some_data'];
1114 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1118 * Test the api_format_data() function with an XML result.
1122 public function testApiFormatDataWithXml()
1124 $this->assertEquals(
1125 '<?xml version="1.0"?>' . "\n" .
1126 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1127 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1128 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1129 ' <data>some_data</data>' . "\n" .
1130 '</root_element>' . "\n",
1131 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1136 * Test the api_account_verify_credentials() function.
1140 public function testApiAccountVerifyCredentials()
1142 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1146 * Test the api_account_verify_credentials() function without an authenticated user.
1149 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1151 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1153 $_SESSION['authenticated'] = false;
1154 api_account_verify_credentials('json');
1158 * Test the requestdata() function.
1162 public function testRequestdata()
1164 $this->assertNull(requestdata('variable_name'));
1168 * Test the requestdata() function with a POST parameter.
1172 public function testRequestdataWithPost()
1174 $_POST['variable_name'] = 'variable_value';
1175 $this->assertEquals('variable_value', requestdata('variable_name'));
1179 * Test the requestdata() function with a GET parameter.
1183 public function testRequestdataWithGet()
1185 $_GET['variable_name'] = 'variable_value';
1186 $this->assertEquals('variable_value', requestdata('variable_name'));
1190 * Test the api_statuses_mediap() function.
1194 public function testApiStatusesMediap()
1196 $this->app->argc = 2;
1204 'tmp_name' => $this->getTempImage(),
1205 'name' => 'spacer.png',
1206 'type' => 'image/png'
1209 $_GET['status'] = '<b>Status content</b>';
1211 $result = api_statuses_mediap('json');
1212 $this->assertStatus($result['status']);
1216 * Test the api_statuses_mediap() function without an authenticated user.
1219 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1221 public function testApiStatusesMediapWithoutAuthenticatedUser()
1223 $_SESSION['authenticated'] = false;
1224 api_statuses_mediap('json');
1228 * Test the api_statuses_update() function.
1232 public function testApiStatusesUpdate()
1234 $_GET['status'] = 'Status content #friendica';
1235 $_GET['in_reply_to_status_id'] = -1;
1244 'tmp_name' => $this->getTempImage(),
1245 'name' => 'spacer.png',
1246 'type' => 'image/png'
1250 $result = api_statuses_update('json');
1251 $this->assertStatus($result['status']);
1255 * Test the api_statuses_update() function with an HTML status.
1259 public function testApiStatusesUpdateWithHtml()
1261 $_GET['htmlstatus'] = '<b>Status content</b>';
1263 $result = api_statuses_update('json');
1264 $this->assertStatus($result['status']);
1268 * Test the api_statuses_update() function without an authenticated user.
1271 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1273 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1275 $_SESSION['authenticated'] = false;
1276 api_statuses_update('json');
1280 * Test the api_statuses_update() function with a parent status.
1284 public function testApiStatusesUpdateWithParent()
1286 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1290 * Test the api_statuses_update() function with a media_ids parameter.
1294 public function testApiStatusesUpdateWithMediaIds()
1296 $this->markTestIncomplete();
1300 * Test the api_statuses_update() function with the throttle limit reached.
1304 public function testApiStatusesUpdateWithDayThrottleReached()
1306 $this->markTestIncomplete();
1310 * Test the api_media_upload() function.
1313 * @expectedException Friendica\Network\HTTPException\BadRequestException
1315 public function testApiMediaUpload()
1321 * Test the api_media_upload() function without an authenticated user.
1324 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1326 public function testApiMediaUploadWithoutAuthenticatedUser()
1328 $_SESSION['authenticated'] = false;
1333 * Test the api_media_upload() function with an invalid uploaded media.
1336 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1338 public function testApiMediaUploadWithMedia()
1343 'tmp_name' => 'tmp_name'
1350 * Test the api_media_upload() function with an valid uploaded media.
1354 public function testApiMediaUploadWithValidMedia()
1362 'tmp_name' => $this->getTempImage(),
1363 'name' => 'spacer.png',
1364 'type' => 'image/png'
1370 $result = api_media_upload();
1371 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1372 $this->assertEquals(1, $result['media']['image']['w']);
1373 $this->assertEquals(1, $result['media']['image']['h']);
1374 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1378 * Test the api_status_show() function.
1380 public function testApiStatusShowWithJson()
1382 $result = api_status_show('json', 1);
1383 $this->assertStatus($result['status']);
1387 * Test the api_status_show() function with an XML result.
1389 public function testApiStatusShowWithXml()
1391 $result = api_status_show('xml', 1);
1392 $this->assertXml($result, 'statuses');
1396 * Test the api_get_last_status() function
1398 public function testApiGetLastStatus()
1400 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1402 $this->assertNotNull($item);
1406 * Test the api_users_show() function.
1410 public function testApiUsersShow()
1412 $result = api_users_show('json');
1413 // We can't use assertSelfUser() here because the user object is missing some properties.
1414 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1415 $this->assertEquals('DFRN', $result['user']['location']);
1416 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1417 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1418 $this->assertEquals('dfrn', $result['user']['network']);
1419 $this->assertTrue($result['user']['verified']);
1423 * Test the api_users_show() function with an XML result.
1427 public function testApiUsersShowWithXml()
1429 $result = api_users_show('xml');
1430 $this->assertXml($result, 'statuses');
1434 * Test the api_users_search() function.
1438 public function testApiUsersSearch()
1440 $_GET['q'] = 'othercontact';
1441 $result = api_users_search('json');
1442 $this->assertOtherUser($result['users'][0]);
1446 * Test the api_users_search() function with an XML result.
1450 public function testApiUsersSearchWithXml()
1452 $_GET['q'] = 'othercontact';
1453 $result = api_users_search('xml');
1454 $this->assertXml($result, 'users');
1458 * Test the api_users_search() function without a GET q parameter.
1461 * @expectedException Friendica\Network\HTTPException\BadRequestException
1463 public function testApiUsersSearchWithoutQuery()
1465 api_users_search('json');
1469 * Test the api_users_lookup() function.
1472 * @expectedException Friendica\Network\HTTPException\NotFoundException
1474 public function testApiUsersLookup()
1476 api_users_lookup('json');
1480 * Test the api_users_lookup() function with an user ID.
1484 public function testApiUsersLookupWithUserId()
1486 $_REQUEST['user_id'] = $this->otherUser['id'];
1487 $result = api_users_lookup('json');
1488 $this->assertOtherUser($result['users'][0]);
1492 * Test the api_search() function.
1496 public function testApiSearch()
1498 $_REQUEST['q'] = 'reply';
1499 $_REQUEST['max_id'] = 10;
1500 $result = api_search('json');
1501 foreach ($result['status'] as $status) {
1502 $this->assertStatus($status);
1503 $this->assertContains('reply', $status['text'], null, true);
1508 * Test the api_search() function a count parameter.
1512 public function testApiSearchWithCount()
1514 $_REQUEST['q'] = 'reply';
1515 $_REQUEST['count'] = 20;
1516 $result = api_search('json');
1517 foreach ($result['status'] as $status) {
1518 $this->assertStatus($status);
1519 $this->assertContains('reply', $status['text'], null, true);
1524 * Test the api_search() function with an rpp parameter.
1528 public function testApiSearchWithRpp()
1530 $_REQUEST['q'] = 'reply';
1531 $_REQUEST['rpp'] = 20;
1532 $result = api_search('json');
1533 foreach ($result['status'] as $status) {
1534 $this->assertStatus($status);
1535 $this->assertContains('reply', $status['text'], null, true);
1540 * Test the api_search() function with an q parameter contains hashtag.
1544 public function testApiSearchWithHashtag()
1546 $_REQUEST['q'] = '%23friendica';
1547 $result = api_search('json');
1548 foreach ($result['status'] as $status) {
1549 $this->assertStatus($status);
1550 $this->assertContains('#friendica', $status['text'], null, true);
1555 * Test the api_search() function with an exclude_replies parameter.
1559 public function testApiSearchWithExcludeReplies()
1561 $_REQUEST['max_id'] = 10;
1562 $_REQUEST['exclude_replies'] = true;
1563 $_REQUEST['q'] = 'friendica';
1564 $result = api_search('json');
1565 foreach ($result['status'] as $status) {
1566 $this->assertStatus($status);
1571 * Test the api_search() function without an authenticated user.
1574 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1576 public function testApiSearchWithUnallowedUser()
1578 $_SESSION['allow_api'] = false;
1579 $_GET['screen_name'] = $this->selfUser['nick'];
1584 * Test the api_search() function without any GET query parameter.
1587 * @expectedException Friendica\Network\HTTPException\BadRequestException
1589 public function testApiSearchWithoutQuery()
1595 * Test the api_statuses_home_timeline() function.
1599 public function testApiStatusesHomeTimeline()
1601 $_REQUEST['max_id'] = 10;
1602 $_REQUEST['exclude_replies'] = true;
1603 $_REQUEST['conversation_id'] = 1;
1604 $result = api_statuses_home_timeline('json');
1605 $this->assertNotEmpty($result['status']);
1606 foreach ($result['status'] as $status) {
1607 $this->assertStatus($status);
1612 * Test the api_statuses_home_timeline() function with a negative page parameter.
1616 public function testApiStatusesHomeTimelineWithNegativePage()
1618 $_REQUEST['page'] = -2;
1619 $result = api_statuses_home_timeline('json');
1620 $this->assertNotEmpty($result['status']);
1621 foreach ($result['status'] as $status) {
1622 $this->assertStatus($status);
1627 * Test the api_statuses_home_timeline() with an unallowed user.
1630 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1632 public function testApiStatusesHomeTimelineWithUnallowedUser()
1634 $_SESSION['allow_api'] = false;
1635 $_GET['screen_name'] = $this->selfUser['nick'];
1636 api_statuses_home_timeline('json');
1640 * Test the api_statuses_home_timeline() function with an RSS result.
1644 public function testApiStatusesHomeTimelineWithRss()
1646 $result = api_statuses_home_timeline('rss');
1647 $this->assertXml($result, 'statuses');
1651 * Test the api_statuses_public_timeline() function.
1655 public function testApiStatusesPublicTimeline()
1657 $_REQUEST['max_id'] = 10;
1658 $_REQUEST['conversation_id'] = 1;
1659 $result = api_statuses_public_timeline('json');
1660 $this->assertNotEmpty($result['status']);
1661 foreach ($result['status'] as $status) {
1662 $this->assertStatus($status);
1667 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1671 public function testApiStatusesPublicTimelineWithExcludeReplies()
1673 $_REQUEST['max_id'] = 10;
1674 $_REQUEST['exclude_replies'] = true;
1675 $result = api_statuses_public_timeline('json');
1676 $this->assertNotEmpty($result['status']);
1677 foreach ($result['status'] as $status) {
1678 $this->assertStatus($status);
1683 * Test the api_statuses_public_timeline() function with a negative page parameter.
1687 public function testApiStatusesPublicTimelineWithNegativePage()
1689 $_REQUEST['page'] = -2;
1690 $result = api_statuses_public_timeline('json');
1691 $this->assertNotEmpty($result['status']);
1692 foreach ($result['status'] as $status) {
1693 $this->assertStatus($status);
1698 * Test the api_statuses_public_timeline() function with an unallowed user.
1701 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1703 public function testApiStatusesPublicTimelineWithUnallowedUser()
1705 $_SESSION['allow_api'] = false;
1706 $_GET['screen_name'] = $this->selfUser['nick'];
1707 api_statuses_public_timeline('json');
1711 * Test the api_statuses_public_timeline() function with an RSS result.
1715 public function testApiStatusesPublicTimelineWithRss()
1717 $result = api_statuses_public_timeline('rss');
1718 $this->assertXml($result, 'statuses');
1722 * Test the api_statuses_networkpublic_timeline() function.
1726 public function testApiStatusesNetworkpublicTimeline()
1728 $_REQUEST['max_id'] = 10;
1729 $result = api_statuses_networkpublic_timeline('json');
1730 $this->assertNotEmpty($result['status']);
1731 foreach ($result['status'] as $status) {
1732 $this->assertStatus($status);
1737 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1741 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1743 $_REQUEST['page'] = -2;
1744 $result = api_statuses_networkpublic_timeline('json');
1745 $this->assertNotEmpty($result['status']);
1746 foreach ($result['status'] as $status) {
1747 $this->assertStatus($status);
1752 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1755 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1757 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1759 $_SESSION['allow_api'] = false;
1760 $_GET['screen_name'] = $this->selfUser['nick'];
1761 api_statuses_networkpublic_timeline('json');
1765 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1769 public function testApiStatusesNetworkpublicTimelineWithRss()
1771 $result = api_statuses_networkpublic_timeline('rss');
1772 $this->assertXml($result, 'statuses');
1776 * Test the api_statuses_show() function.
1779 * @expectedException Friendica\Network\HTTPException\BadRequestException
1781 public function testApiStatusesShow()
1783 api_statuses_show('json');
1787 * Test the api_statuses_show() function with an ID.
1791 public function testApiStatusesShowWithId()
1793 $this->app->argv[3] = 1;
1794 $result = api_statuses_show('json');
1795 $this->assertStatus($result['status']);
1799 * Test the api_statuses_show() function with the conversation parameter.
1803 public function testApiStatusesShowWithConversation()
1805 $this->app->argv[3] = 1;
1806 $_REQUEST['conversation'] = 1;
1807 $result = api_statuses_show('json');
1808 $this->assertNotEmpty($result['status']);
1809 foreach ($result['status'] as $status) {
1810 $this->assertStatus($status);
1815 * Test the api_statuses_show() function with an unallowed user.
1818 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1820 public function testApiStatusesShowWithUnallowedUser()
1822 $_SESSION['allow_api'] = false;
1823 $_GET['screen_name'] = $this->selfUser['nick'];
1824 api_statuses_show('json');
1828 * Test the api_conversation_show() function.
1831 * @expectedException Friendica\Network\HTTPException\BadRequestException
1833 public function testApiConversationShow()
1835 api_conversation_show('json');
1839 * Test the api_conversation_show() function with an ID.
1843 public function testApiConversationShowWithId()
1845 $this->app->argv[3] = 1;
1846 $_REQUEST['max_id'] = 10;
1847 $_REQUEST['page'] = -2;
1848 $result = api_conversation_show('json');
1849 $this->assertNotEmpty($result['status']);
1850 foreach ($result['status'] as $status) {
1851 $this->assertStatus($status);
1856 * Test the api_conversation_show() function with an unallowed user.
1859 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1861 public function testApiConversationShowWithUnallowedUser()
1863 $_SESSION['allow_api'] = false;
1864 $_GET['screen_name'] = $this->selfUser['nick'];
1865 api_conversation_show('json');
1869 * Test the api_statuses_repeat() function.
1872 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1874 public function testApiStatusesRepeat()
1876 api_statuses_repeat('json');
1880 * Test the api_statuses_repeat() function without an authenticated user.
1883 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1885 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1887 $_SESSION['authenticated'] = false;
1888 api_statuses_repeat('json');
1892 * Test the api_statuses_repeat() function with an ID.
1896 public function testApiStatusesRepeatWithId()
1898 $this->app->argv[3] = 1;
1899 $result = api_statuses_repeat('json');
1900 $this->assertStatus($result['status']);
1902 // Also test with a shared status
1903 $this->app->argv[3] = 5;
1904 $result = api_statuses_repeat('json');
1905 $this->assertStatus($result['status']);
1909 * Test the api_statuses_destroy() function.
1912 * @expectedException Friendica\Network\HTTPException\BadRequestException
1914 public function testApiStatusesDestroy()
1916 api_statuses_destroy('json');
1920 * Test the api_statuses_destroy() function without an authenticated user.
1923 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1925 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1927 $_SESSION['authenticated'] = false;
1928 api_statuses_destroy('json');
1932 * Test the api_statuses_destroy() function with an ID.
1936 public function testApiStatusesDestroyWithId()
1938 $this->app->argv[3] = 1;
1939 $result = api_statuses_destroy('json');
1940 $this->assertStatus($result['status']);
1944 * Test the api_statuses_mentions() function.
1948 public function testApiStatusesMentions()
1950 $this->app->user = ['nickname' => $this->selfUser['nick']];
1951 $_REQUEST['max_id'] = 10;
1952 $result = api_statuses_mentions('json');
1953 $this->assertEmpty($result['status']);
1954 // We should test with mentions in the database.
1958 * Test the api_statuses_mentions() function with a negative page parameter.
1962 public function testApiStatusesMentionsWithNegativePage()
1964 $_REQUEST['page'] = -2;
1965 $result = api_statuses_mentions('json');
1966 $this->assertEmpty($result['status']);
1970 * Test the api_statuses_mentions() function with an unallowed user.
1973 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1975 public function testApiStatusesMentionsWithUnallowedUser()
1977 $_SESSION['allow_api'] = false;
1978 $_GET['screen_name'] = $this->selfUser['nick'];
1979 api_statuses_mentions('json');
1983 * Test the api_statuses_mentions() function with an RSS result.
1987 public function testApiStatusesMentionsWithRss()
1989 $result = api_statuses_mentions('rss');
1990 $this->assertXml($result, 'statuses');
1994 * Test the api_statuses_user_timeline() function.
1998 public function testApiStatusesUserTimeline()
2000 $_REQUEST['max_id'] = 10;
2001 $_REQUEST['exclude_replies'] = true;
2002 $_REQUEST['conversation_id'] = 1;
2003 $result = api_statuses_user_timeline('json');
2004 $this->assertNotEmpty($result['status']);
2005 foreach ($result['status'] as $status) {
2006 $this->assertStatus($status);
2011 * Test the api_statuses_user_timeline() function with a negative page parameter.
2015 public function testApiStatusesUserTimelineWithNegativePage()
2017 $_REQUEST['page'] = -2;
2018 $result = api_statuses_user_timeline('json');
2019 $this->assertNotEmpty($result['status']);
2020 foreach ($result['status'] as $status) {
2021 $this->assertStatus($status);
2026 * Test the api_statuses_user_timeline() function with an RSS result.
2030 public function testApiStatusesUserTimelineWithRss()
2032 $result = api_statuses_user_timeline('rss');
2033 $this->assertXml($result, 'statuses');
2037 * Test the api_statuses_user_timeline() function with an unallowed user.
2040 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2042 public function testApiStatusesUserTimelineWithUnallowedUser()
2044 $_SESSION['allow_api'] = false;
2045 $_GET['screen_name'] = $this->selfUser['nick'];
2046 api_statuses_user_timeline('json');
2050 * Test the api_favorites_create_destroy() function.
2053 * @expectedException Friendica\Network\HTTPException\BadRequestException
2055 public function testApiFavoritesCreateDestroy()
2057 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2058 $this->app->argc = count($this->app->argv);
2059 api_favorites_create_destroy('json');
2063 * Test the api_favorites_create_destroy() function with an invalid ID.
2066 * @expectedException Friendica\Network\HTTPException\BadRequestException
2068 public function testApiFavoritesCreateDestroyWithInvalidId()
2070 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2071 $this->app->argc = count($this->app->argv);
2072 api_favorites_create_destroy('json');
2076 * Test the api_favorites_create_destroy() function with an invalid action.
2079 * @expectedException Friendica\Network\HTTPException\BadRequestException
2081 public function testApiFavoritesCreateDestroyWithInvalidAction()
2083 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2084 $this->app->argc = count($this->app->argv);
2085 $_REQUEST['id'] = 1;
2086 api_favorites_create_destroy('json');
2090 * Test the api_favorites_create_destroy() function with the create action.
2094 public function testApiFavoritesCreateDestroyWithCreateAction()
2096 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2097 $this->app->argc = count($this->app->argv);
2098 $_REQUEST['id'] = 3;
2099 $result = api_favorites_create_destroy('json');
2100 $this->assertStatus($result['status']);
2104 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2108 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2110 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2111 $this->app->argc = count($this->app->argv);
2112 $_REQUEST['id'] = 3;
2113 $result = api_favorites_create_destroy('rss');
2114 $this->assertXml($result, 'status');
2118 * Test the api_favorites_create_destroy() function with the destroy action.
2122 public function testApiFavoritesCreateDestroyWithDestroyAction()
2124 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2125 $this->app->argc = count($this->app->argv);
2126 $_REQUEST['id'] = 3;
2127 $result = api_favorites_create_destroy('json');
2128 $this->assertStatus($result['status']);
2132 * Test the api_favorites_create_destroy() function without an authenticated user.
2135 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2137 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2139 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2140 $this->app->argc = count($this->app->argv);
2141 $_SESSION['authenticated'] = false;
2142 api_favorites_create_destroy('json');
2146 * Test the api_favorites() function.
2150 public function testApiFavorites()
2152 $_REQUEST['page'] = -1;
2153 $_REQUEST['max_id'] = 10;
2154 $result = api_favorites('json');
2155 foreach ($result['status'] as $status) {
2156 $this->assertStatus($status);
2161 * Test the api_favorites() function with an RSS result.
2165 public function testApiFavoritesWithRss()
2167 $result = api_favorites('rss');
2168 $this->assertXml($result, 'statuses');
2172 * Test the api_favorites() function with an unallowed user.
2175 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2177 public function testApiFavoritesWithUnallowedUser()
2179 $_SESSION['allow_api'] = false;
2180 $_GET['screen_name'] = $this->selfUser['nick'];
2181 api_favorites('json');
2185 * Test the api_format_messages() function.
2189 public function testApiFormatMessages()
2191 $result = api_format_messages(
2192 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2193 ['id' => 2, 'screen_name' => 'recipient_name'],
2194 ['id' => 3, 'screen_name' => 'sender_name']
2196 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2197 $this->assertEquals(1, $result['id']);
2198 $this->assertEquals(2, $result['recipient_id']);
2199 $this->assertEquals(3, $result['sender_id']);
2200 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2201 $this->assertEquals('sender_name', $result['sender_screen_name']);
2205 * Test the api_format_messages() function with HTML.
2209 public function testApiFormatMessagesWithHtmlText()
2211 $_GET['getText'] = 'html';
2212 $result = api_format_messages(
2213 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2214 ['id' => 2, 'screen_name' => 'recipient_name'],
2215 ['id' => 3, 'screen_name' => 'sender_name']
2217 $this->assertEquals('item_title', $result['title']);
2218 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2222 * Test the api_format_messages() function with plain text.
2226 public function testApiFormatMessagesWithPlainText()
2228 $_GET['getText'] = 'plain';
2229 $result = api_format_messages(
2230 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2231 ['id' => 2, 'screen_name' => 'recipient_name'],
2232 ['id' => 3, 'screen_name' => 'sender_name']
2234 $this->assertEquals('item_title', $result['title']);
2235 $this->assertEquals('item_body', $result['text']);
2239 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2243 public function testApiFormatMessagesWithoutUserObjects()
2245 $_GET['getUserObjects'] = 'false';
2246 $result = api_format_messages(
2247 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2248 ['id' => 2, 'screen_name' => 'recipient_name'],
2249 ['id' => 3, 'screen_name' => 'sender_name']
2251 $this->assertTrue(!isset($result['sender']));
2252 $this->assertTrue(!isset($result['recipient']));
2256 * Test the api_convert_item() function.
2260 public function testApiConvertItem()
2262 $result = api_convert_item(
2264 'network' => 'feed',
2265 'title' => 'item_title',
2266 // We need a long string to test that it is correctly cut
2267 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2268 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2269 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2270 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2271 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2272 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2273 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2274 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2275 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2276 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2277 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2278 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2279 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2280 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2281 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2282 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2283 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2284 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2285 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2286 'repellat officia illum quos impedit quam iste esse unde qui ' .
2287 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2288 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2289 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2290 'plink' => 'item_plink'
2293 $this->assertStringStartsWith('item_title', $result['text']);
2294 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2298 * Test the api_convert_item() function with an empty item body.
2302 public function testApiConvertItemWithoutBody()
2304 $result = api_convert_item(
2306 'network' => 'feed',
2307 'title' => 'item_title',
2309 'plink' => 'item_plink'
2312 $this->assertEquals('item_title', $result['text']);
2313 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2317 * Test the api_convert_item() function with the title in the body.
2321 public function testApiConvertItemWithTitleInBody()
2323 $result = api_convert_item(
2325 'title' => 'item_title',
2326 'body' => 'item_title item_body'
2329 $this->assertEquals('item_title item_body', $result['text']);
2330 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2334 * Test the api_get_attachments() function.
2338 public function testApiGetAttachments()
2341 $this->assertEmpty(api_get_attachments($body));
2345 * Test the api_get_attachments() function with an img tag.
2349 public function testApiGetAttachmentsWithImage()
2351 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2352 $this->assertInternalType('array', api_get_attachments($body));
2356 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2360 public function testApiGetAttachmentsWithImageAndAndStatus()
2362 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2363 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2364 $this->assertInternalType('array', api_get_attachments($body));
2368 * Test the api_get_entitities() function.
2372 public function testApiGetEntitities()
2375 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2379 * Test the api_get_entitities() function with the include_entities parameter.
2383 public function testApiGetEntititiesWithIncludeEntities()
2385 $_REQUEST['include_entities'] = 'true';
2387 $result = api_get_entitities($text, 'bbcode');
2388 $this->assertInternalType('array', $result['hashtags']);
2389 $this->assertInternalType('array', $result['symbols']);
2390 $this->assertInternalType('array', $result['urls']);
2391 $this->assertInternalType('array', $result['user_mentions']);
2395 * Test the api_format_items_embeded_images() function.
2399 public function testApiFormatItemsEmbededImages()
2401 $this->assertEquals(
2402 'text ' . System::baseUrl() . '/display/item_guid',
2403 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2408 * Test the api_contactlink_to_array() function.
2412 public function testApiContactlinkToArray()
2414 $this->assertEquals(
2419 api_contactlink_to_array('text')
2424 * Test the api_contactlink_to_array() function with an URL.
2428 public function testApiContactlinkToArrayWithUrl()
2430 $this->assertEquals(
2432 'name' => ['link_text'],
2435 api_contactlink_to_array('text <a href="url">link_text</a>')
2440 * Test the api_format_items_activities() function.
2444 public function testApiFormatItemsActivities()
2446 $item = ['uid' => 0, 'uri' => ''];
2447 $result = api_format_items_activities($item);
2448 $this->assertArrayHasKey('like', $result);
2449 $this->assertArrayHasKey('dislike', $result);
2450 $this->assertArrayHasKey('attendyes', $result);
2451 $this->assertArrayHasKey('attendno', $result);
2452 $this->assertArrayHasKey('attendmaybe', $result);
2456 * Test the api_format_items_activities() function with an XML result.
2460 public function testApiFormatItemsActivitiesWithXml()
2462 $item = ['uid' => 0, 'uri' => ''];
2463 $result = api_format_items_activities($item, 'xml');
2464 $this->assertArrayHasKey('friendica:like', $result);
2465 $this->assertArrayHasKey('friendica:dislike', $result);
2466 $this->assertArrayHasKey('friendica:attendyes', $result);
2467 $this->assertArrayHasKey('friendica:attendno', $result);
2468 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2472 * Test the api_format_items_profiles() function.
2476 public function testApiFormatItemsProfiles()
2479 'id' => 'profile_id',
2480 'profile-name' => 'profile_name',
2481 'is-default' => true,
2482 'hide-friends' => true,
2483 'photo' => 'profile_photo',
2484 'thumb' => 'profile_thumb',
2486 'net-publish' => true,
2487 'pdesc' => 'description',
2488 'dob' => 'date_of_birth',
2489 'address' => 'address',
2490 'locality' => 'city',
2491 'region' => 'region',
2492 'postal-code' => 'postal_code',
2493 'country-name' => 'country',
2494 'hometown' => 'hometown',
2495 'gender' => 'gender',
2496 'marital' => 'marital',
2497 'with' => 'marital_with',
2498 'howlong' => 'marital_since',
2499 'sexual' => 'sexual',
2500 'politic' => 'politic',
2501 'religion' => 'religion',
2502 'pub_keywords' => 'public_keywords',
2503 'prv_keywords' => 'private_keywords',
2506 'dislikes' => 'dislikes',
2512 'interest' => 'interest',
2513 'romance' => 'romance',
2515 'education' => 'education',
2516 'contact' => 'social_networks',
2517 'homepage' => 'homepage'
2519 $result = api_format_items_profiles($profile_row);
2520 $this->assertEquals(
2522 'profile_id' => 'profile_id',
2523 'profile_name' => 'profile_name',
2524 'is_default' => true,
2525 'hide_friends' => true,
2526 'profile_photo' => 'profile_photo',
2527 'profile_thumb' => 'profile_thumb',
2529 'net_publish' => true,
2530 'description' => 'description',
2531 'date_of_birth' => 'date_of_birth',
2532 'address' => 'address',
2534 'region' => 'region',
2535 'postal_code' => 'postal_code',
2536 'country' => 'country',
2537 'hometown' => 'hometown',
2538 'gender' => 'gender',
2539 'marital' => 'marital',
2540 'marital_with' => 'marital_with',
2541 'marital_since' => 'marital_since',
2542 'sexual' => 'sexual',
2543 'politic' => 'politic',
2544 'religion' => 'religion',
2545 'public_keywords' => 'public_keywords',
2546 'private_keywords' => 'private_keywords',
2549 'dislikes' => 'dislikes',
2555 'interest' => 'interest',
2556 'romance' => 'romance',
2558 'education' => 'education',
2559 'social_networks' => 'social_networks',
2560 'homepage' => 'homepage',
2568 * Test the api_format_items() function.
2572 public function testApiFormatItems()
2576 'item_network' => 'item_network',
2582 'author-network' => Protocol::DFRN,
2583 'author-link' => 'http://localhost/profile/othercontact',
2587 $result = api_format_items($items, ['id' => 0], true);
2588 foreach ($result as $status) {
2589 $this->assertStatus($status);
2594 * Test the api_format_items() function with an XML result.
2598 public function testApiFormatItemsWithXml()
2606 'author-network' => Protocol::DFRN,
2607 'author-link' => 'http://localhost/profile/othercontact',
2611 $result = api_format_items($items, ['id' => 0], true, 'xml');
2612 foreach ($result as $status) {
2613 $this->assertStatus($status);
2618 * Test the api_format_items() function.
2622 public function testApiAccountRateLimitStatus()
2624 $result = api_account_rate_limit_status('json');
2625 $this->assertEquals(150, $result['hash']['remaining_hits']);
2626 $this->assertEquals(150, $result['hash']['hourly_limit']);
2627 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2631 * Test the api_format_items() function with an XML result.
2635 public function testApiAccountRateLimitStatusWithXml()
2637 $result = api_account_rate_limit_status('xml');
2638 $this->assertXml($result, 'hash');
2642 * Test the api_help_test() function.
2646 public function testApiHelpTest()
2648 $result = api_help_test('json');
2649 $this->assertEquals(['ok' => 'ok'], $result);
2653 * Test the api_help_test() function with an XML result.
2657 public function testApiHelpTestWithXml()
2659 $result = api_help_test('xml');
2660 $this->assertXml($result, 'ok');
2664 * Test the api_lists_list() function.
2668 public function testApiListsList()
2670 $result = api_lists_list('json');
2671 $this->assertEquals(['lists_list' => []], $result);
2675 * Test the api_lists_ownerships() function.
2679 public function testApiListsOwnerships()
2681 $result = api_lists_ownerships('json');
2682 foreach ($result['lists']['lists'] as $list) {
2683 $this->assertList($list);
2688 * Test the api_lists_ownerships() function without an authenticated user.
2691 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2693 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2695 $_SESSION['authenticated'] = false;
2696 api_lists_ownerships('json');
2700 * Test the api_lists_statuses() function.
2702 * @expectedException Friendica\Network\HTTPException\BadRequestException
2705 public function testApiListsStatuses()
2707 api_lists_statuses('json');
2711 * Test the api_lists_statuses() function with a list ID.
2715 public function testApiListsStatusesWithListId()
2717 $_REQUEST['list_id'] = 1;
2718 $_REQUEST['page'] = -1;
2719 $_REQUEST['max_id'] = 10;
2720 $result = api_lists_statuses('json');
2721 foreach ($result['status'] as $status) {
2722 $this->assertStatus($status);
2727 * Test the api_lists_statuses() function with a list ID and a RSS result.
2731 public function testApiListsStatusesWithListIdAndRss()
2733 $_REQUEST['list_id'] = 1;
2734 $result = api_lists_statuses('rss');
2735 $this->assertXml($result, 'statuses');
2739 * Test the api_lists_statuses() function with an unallowed user.
2742 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2744 public function testApiListsStatusesWithUnallowedUser()
2746 $_SESSION['allow_api'] = false;
2747 $_GET['screen_name'] = $this->selfUser['nick'];
2748 api_lists_statuses('json');
2752 * Test the api_statuses_f() function.
2756 public function testApiStatusesFWithFriends()
2759 $result = api_statuses_f('friends');
2760 $this->assertArrayHasKey('user', $result);
2764 * Test the api_statuses_f() function.
2768 public function testApiStatusesFWithFollowers()
2770 $result = api_statuses_f('followers');
2771 $this->assertArrayHasKey('user', $result);
2775 * Test the api_statuses_f() function.
2779 public function testApiStatusesFWithBlocks()
2781 $result = api_statuses_f('blocks');
2782 $this->assertArrayHasKey('user', $result);
2786 * Test the api_statuses_f() function.
2790 public function testApiStatusesFWithIncoming()
2792 $result = api_statuses_f('incoming');
2793 $this->assertArrayHasKey('user', $result);
2797 * Test the api_statuses_f() function an undefined cursor GET variable.
2801 public function testApiStatusesFWithUndefinedCursor()
2803 $_GET['cursor'] = 'undefined';
2804 $this->assertFalse(api_statuses_f('friends'));
2808 * Test the api_statuses_friends() function.
2812 public function testApiStatusesFriends()
2814 $result = api_statuses_friends('json');
2815 $this->assertArrayHasKey('user', $result);
2819 * Test the api_statuses_friends() function an undefined cursor GET variable.
2823 public function testApiStatusesFriendsWithUndefinedCursor()
2825 $_GET['cursor'] = 'undefined';
2826 $this->assertFalse(api_statuses_friends('json'));
2830 * Test the api_statuses_followers() function.
2834 public function testApiStatusesFollowers()
2836 $result = api_statuses_followers('json');
2837 $this->assertArrayHasKey('user', $result);
2841 * Test the api_statuses_followers() function an undefined cursor GET variable.
2845 public function testApiStatusesFollowersWithUndefinedCursor()
2847 $_GET['cursor'] = 'undefined';
2848 $this->assertFalse(api_statuses_followers('json'));
2852 * Test the api_blocks_list() function.
2856 public function testApiBlocksList()
2858 $result = api_blocks_list('json');
2859 $this->assertArrayHasKey('user', $result);
2863 * Test the api_blocks_list() function an undefined cursor GET variable.
2867 public function testApiBlocksListWithUndefinedCursor()
2869 $_GET['cursor'] = 'undefined';
2870 $this->assertFalse(api_blocks_list('json'));
2874 * Test the api_friendships_incoming() function.
2878 public function testApiFriendshipsIncoming()
2880 $result = api_friendships_incoming('json');
2881 $this->assertArrayHasKey('id', $result);
2885 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2889 public function testApiFriendshipsIncomingWithUndefinedCursor()
2891 $_GET['cursor'] = 'undefined';
2892 $this->assertFalse(api_friendships_incoming('json'));
2896 * Test the api_statusnet_config() function.
2900 public function testApiStatusnetConfig()
2902 $result = api_statusnet_config('json');
2903 $this->assertEquals('localhost', $result['config']['site']['server']);
2904 $this->assertEquals('default', $result['config']['site']['theme']);
2905 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2906 $this->assertTrue($result['config']['site']['fancy']);
2907 $this->assertEquals('en', $result['config']['site']['language']);
2908 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2909 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2910 $this->assertEquals('false', $result['config']['site']['private']);
2911 $this->assertEquals('false', $result['config']['site']['ssl']);
2912 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2916 * Test the api_statusnet_version() function.
2920 public function testApiStatusnetVersion()
2922 $result = api_statusnet_version('json');
2923 $this->assertEquals('0.9.7', $result['version']);
2927 * Test the api_ff_ids() function.
2931 public function testApiFfIds()
2933 $result = api_ff_ids('json', Contact::FOLLOWER);
2934 $this->assertEquals(['id' => []], $result);
2938 * Test the api_ff_ids() function with a result.
2942 public function testApiFfIdsWithResult()
2944 $this->markTestIncomplete();
2948 * Test the api_ff_ids() function without an authenticated user.
2951 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2953 public function testApiFfIdsWithoutAuthenticatedUser()
2955 $_SESSION['authenticated'] = false;
2956 api_ff_ids('json', Contact::FOLLOWER);
2960 * Test the api_friends_ids() function.
2964 public function testApiFriendsIds()
2966 $result = api_friends_ids('json');
2967 $this->assertEquals(['id' => []], $result);
2971 * Test the api_followers_ids() function.
2975 public function testApiFollowersIds()
2977 $result = api_followers_ids('json');
2978 $this->assertEquals(['id' => []], $result);
2982 * Test the api_direct_messages_new() function.
2986 public function testApiDirectMessagesNew()
2988 $result = api_direct_messages_new('json');
2989 $this->assertNull($result);
2993 * Test the api_direct_messages_new() function without an authenticated user.
2996 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2998 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
3000 $_SESSION['authenticated'] = false;
3001 api_direct_messages_new('json');
3005 * Test the api_direct_messages_new() function with an user ID.
3009 public function testApiDirectMessagesNewWithUserId()
3011 $_POST['text'] = 'message_text';
3012 $_POST['user_id'] = $this->otherUser['id'];
3013 $result = api_direct_messages_new('json');
3014 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3018 * Test the api_direct_messages_new() function with a screen name.
3022 public function testApiDirectMessagesNewWithScreenName()
3024 $_POST['text'] = 'message_text';
3025 $_POST['screen_name'] = $this->friendUser['nick'];
3026 $result = api_direct_messages_new('json');
3027 $this->assertContains('message_text', $result['direct_message']['text']);
3028 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3029 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3033 * Test the api_direct_messages_new() function with a title.
3037 public function testApiDirectMessagesNewWithTitle()
3039 $_POST['text'] = 'message_text';
3040 $_POST['screen_name'] = $this->friendUser['nick'];
3041 $_REQUEST['title'] = 'message_title';
3042 $result = api_direct_messages_new('json');
3043 $this->assertContains('message_text', $result['direct_message']['text']);
3044 $this->assertContains('message_title', $result['direct_message']['text']);
3045 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3046 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3050 * Test the api_direct_messages_new() function with an RSS result.
3054 public function testApiDirectMessagesNewWithRss()
3056 $_POST['text'] = 'message_text';
3057 $_POST['screen_name'] = $this->friendUser['nick'];
3058 $result = api_direct_messages_new('rss');
3059 $this->assertXml($result, 'direct-messages');
3063 * Test the api_direct_messages_destroy() function.
3066 * @expectedException Friendica\Network\HTTPException\BadRequestException
3068 public function testApiDirectMessagesDestroy()
3070 api_direct_messages_destroy('json');
3074 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3078 public function testApiDirectMessagesDestroyWithVerbose()
3080 $_GET['friendica_verbose'] = 'true';
3081 $result = api_direct_messages_destroy('json');
3082 $this->assertEquals(
3085 'result' => 'error',
3086 'message' => 'message id or parenturi not specified'
3094 * Test the api_direct_messages_destroy() function without an authenticated user.
3097 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3099 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3101 $_SESSION['authenticated'] = false;
3102 api_direct_messages_destroy('json');
3106 * Test the api_direct_messages_destroy() function with a non-zero ID.
3109 * @expectedException Friendica\Network\HTTPException\BadRequestException
3111 public function testApiDirectMessagesDestroyWithId()
3113 $_REQUEST['id'] = 1;
3114 api_direct_messages_destroy('json');
3118 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3122 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3124 $_REQUEST['id'] = 1;
3125 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3126 $_GET['friendica_verbose'] = 'true';
3127 $result = api_direct_messages_destroy('json');
3128 $this->assertEquals(
3131 'result' => 'error',
3132 'message' => 'message id not in database'
3140 * Test the api_direct_messages_destroy() function with a non-zero ID.
3144 public function testApiDirectMessagesDestroyWithCorrectId()
3146 $this->markTestIncomplete('We need to add a dataset for this.');
3150 * Test the api_direct_messages_box() function.
3154 public function testApiDirectMessagesBoxWithSentbox()
3156 $_REQUEST['page'] = -1;
3157 $_REQUEST['max_id'] = 10;
3158 $result = api_direct_messages_box('json', 'sentbox', 'false');
3159 $this->assertArrayHasKey('direct_message', $result);
3163 * Test the api_direct_messages_box() function.
3167 public function testApiDirectMessagesBoxWithConversation()
3169 $result = api_direct_messages_box('json', 'conversation', 'false');
3170 $this->assertArrayHasKey('direct_message', $result);
3174 * Test the api_direct_messages_box() function.
3178 public function testApiDirectMessagesBoxWithAll()
3180 $result = api_direct_messages_box('json', 'all', 'false');
3181 $this->assertArrayHasKey('direct_message', $result);
3185 * Test the api_direct_messages_box() function.
3189 public function testApiDirectMessagesBoxWithInbox()
3191 $result = api_direct_messages_box('json', 'inbox', 'false');
3192 $this->assertArrayHasKey('direct_message', $result);
3196 * Test the api_direct_messages_box() function.
3200 public function testApiDirectMessagesBoxWithVerbose()
3202 $result = api_direct_messages_box('json', 'sentbox', 'true');
3203 $this->assertEquals(
3206 'result' => 'error',
3207 'message' => 'no mails available'
3215 * Test the api_direct_messages_box() function with a RSS result.
3219 public function testApiDirectMessagesBoxWithRss()
3221 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3222 $this->assertXml($result, 'direct-messages');
3226 * Test the api_direct_messages_box() function without an authenticated user.
3229 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3231 public function testApiDirectMessagesBoxWithUnallowedUser()
3233 $_SESSION['allow_api'] = false;
3234 $_GET['screen_name'] = $this->selfUser['nick'];
3235 api_direct_messages_box('json', 'sentbox', 'false');
3239 * Test the api_direct_messages_sentbox() function.
3243 public function testApiDirectMessagesSentbox()
3245 $result = api_direct_messages_sentbox('json');
3246 $this->assertArrayHasKey('direct_message', $result);
3250 * Test the api_direct_messages_inbox() function.
3254 public function testApiDirectMessagesInbox()
3256 $result = api_direct_messages_inbox('json');
3257 $this->assertArrayHasKey('direct_message', $result);
3261 * Test the api_direct_messages_all() function.
3265 public function testApiDirectMessagesAll()
3267 $result = api_direct_messages_all('json');
3268 $this->assertArrayHasKey('direct_message', $result);
3272 * Test the api_direct_messages_conversation() function.
3276 public function testApiDirectMessagesConversation()
3278 $result = api_direct_messages_conversation('json');
3279 $this->assertArrayHasKey('direct_message', $result);
3283 * Test the api_oauth_request_token() function.
3287 public function testApiOauthRequestToken()
3289 $this->markTestIncomplete('killme() kills phpunit as well');
3293 * Test the api_oauth_access_token() function.
3297 public function testApiOauthAccessToken()
3299 $this->markTestIncomplete('killme() kills phpunit as well');
3303 * Test the api_fr_photoalbum_delete() function.
3306 * @expectedException Friendica\Network\HTTPException\BadRequestException
3308 public function testApiFrPhotoalbumDelete()
3310 api_fr_photoalbum_delete('json');
3314 * Test the api_fr_photoalbum_delete() function with an album name.
3317 * @expectedException Friendica\Network\HTTPException\BadRequestException
3319 public function testApiFrPhotoalbumDeleteWithAlbum()
3321 $_REQUEST['album'] = 'album_name';
3322 api_fr_photoalbum_delete('json');
3326 * Test the api_fr_photoalbum_delete() function with an album name.
3330 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3332 $this->markTestIncomplete('We need to add a dataset for this.');
3336 * Test the api_fr_photoalbum_delete() function.
3339 * @expectedException Friendica\Network\HTTPException\BadRequestException
3341 public function testApiFrPhotoalbumUpdate()
3343 api_fr_photoalbum_update('json');
3347 * Test the api_fr_photoalbum_delete() function with an album name.
3350 * @expectedException Friendica\Network\HTTPException\BadRequestException
3352 public function testApiFrPhotoalbumUpdateWithAlbum()
3354 $_REQUEST['album'] = 'album_name';
3355 api_fr_photoalbum_update('json');
3359 * Test the api_fr_photoalbum_delete() function with an album name.
3362 * @expectedException Friendica\Network\HTTPException\BadRequestException
3364 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3366 $_REQUEST['album'] = 'album_name';
3367 $_REQUEST['album_new'] = 'album_name';
3368 api_fr_photoalbum_update('json');
3372 * Test the api_fr_photoalbum_update() function without an authenticated user.
3375 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3377 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3379 $_SESSION['authenticated'] = false;
3380 api_fr_photoalbum_update('json');
3384 * Test the api_fr_photoalbum_delete() function with an album name.
3388 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3390 $this->markTestIncomplete('We need to add a dataset for this.');
3394 * Test the api_fr_photos_list() function.
3398 public function testApiFrPhotosList()
3400 $result = api_fr_photos_list('json');
3401 $this->assertArrayHasKey('photo', $result);
3405 * Test the api_fr_photos_list() function without an authenticated user.
3408 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3410 public function testApiFrPhotosListWithoutAuthenticatedUser()
3412 $_SESSION['authenticated'] = false;
3413 api_fr_photos_list('json');
3417 * Test the api_fr_photo_create_update() function.
3420 * @expectedException Friendica\Network\HTTPException\BadRequestException
3422 public function testApiFrPhotoCreateUpdate()
3424 api_fr_photo_create_update('json');
3428 * Test the api_fr_photo_create_update() function without an authenticated user.
3431 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3433 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3435 $_SESSION['authenticated'] = false;
3436 api_fr_photo_create_update('json');
3440 * Test the api_fr_photo_create_update() function with an album name.
3443 * @expectedException Friendica\Network\HTTPException\BadRequestException
3445 public function testApiFrPhotoCreateUpdateWithAlbum()
3447 $_REQUEST['album'] = 'album_name';
3448 api_fr_photo_create_update('json');
3452 * Test the api_fr_photo_create_update() function with the update mode.
3456 public function testApiFrPhotoCreateUpdateWithUpdate()
3458 $this->markTestIncomplete('We need to create a dataset for this');
3462 * Test the api_fr_photo_create_update() function with an uploaded file.
3466 public function testApiFrPhotoCreateUpdateWithFile()
3468 $this->markTestIncomplete();
3472 * Test the api_fr_photo_delete() function.
3475 * @expectedException Friendica\Network\HTTPException\BadRequestException
3477 public function testApiFrPhotoDelete()
3479 api_fr_photo_delete('json');
3483 * Test the api_fr_photo_delete() function without an authenticated user.
3486 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3488 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3490 $_SESSION['authenticated'] = false;
3491 api_fr_photo_delete('json');
3495 * Test the api_fr_photo_delete() function with a photo ID.
3498 * @expectedException Friendica\Network\HTTPException\BadRequestException
3500 public function testApiFrPhotoDeleteWithPhotoId()
3502 $_REQUEST['photo_id'] = 1;
3503 api_fr_photo_delete('json');
3507 * Test the api_fr_photo_delete() function with a correct photo ID.
3511 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3513 $this->markTestIncomplete('We need to create a dataset for this.');
3517 * Test the api_fr_photo_detail() function.
3520 * @expectedException Friendica\Network\HTTPException\BadRequestException
3522 public function testApiFrPhotoDetail()
3524 api_fr_photo_detail('json');
3528 * Test the api_fr_photo_detail() function without an authenticated user.
3531 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3533 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3535 $_SESSION['authenticated'] = false;
3536 api_fr_photo_detail('json');
3540 * Test the api_fr_photo_detail() function with a photo ID.
3543 * @expectedException Friendica\Network\HTTPException\NotFoundException
3545 public function testApiFrPhotoDetailWithPhotoId()
3547 $_REQUEST['photo_id'] = 1;
3548 api_fr_photo_detail('json');
3552 * Test the api_fr_photo_detail() function with a correct photo ID.
3556 public function testApiFrPhotoDetailCorrectPhotoId()
3558 $this->markTestIncomplete('We need to create a dataset for this.');
3562 * Test the api_account_update_profile_image() function.
3565 * @expectedException Friendica\Network\HTTPException\BadRequestException
3567 public function testApiAccountUpdateProfileImage()
3569 api_account_update_profile_image('json');
3573 * Test the api_account_update_profile_image() function without an authenticated user.
3576 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3578 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3580 $_SESSION['authenticated'] = false;
3581 api_account_update_profile_image('json');
3585 * Test the api_account_update_profile_image() function with an uploaded file.
3588 * @expectedException Friendica\Network\HTTPException\BadRequestException
3590 public function testApiAccountUpdateProfileImageWithUpload()
3592 $this->markTestIncomplete();
3597 * Test the api_account_update_profile() function.
3601 public function testApiAccountUpdateProfile()
3603 $_POST['name'] = 'new_name';
3604 $_POST['description'] = 'new_description';
3605 $result = api_account_update_profile('json');
3606 // We can't use assertSelfUser() here because the user object is missing some properties.
3607 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3608 $this->assertEquals('DFRN', $result['user']['location']);
3609 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3610 $this->assertEquals('dfrn', $result['user']['network']);
3611 $this->assertEquals('new_name', $result['user']['name']);
3612 $this->assertEquals('new_description', $result['user']['description']);
3616 * Test the check_acl_input() function.
3620 public function testCheckAclInput()
3622 $result = check_acl_input('<aclstring>');
3623 // Where does this result come from?
3624 $this->assertEquals(1, $result);
3628 * Test the check_acl_input() function with an empty ACL string.
3632 public function testCheckAclInputWithEmptyAclString()
3634 $result = check_acl_input(' ');
3635 $this->assertFalse($result);
3639 * Test the save_media_to_database() function.
3643 public function testSaveMediaToDatabase()
3645 $this->markTestIncomplete();
3649 * Test the post_photo_item() function.
3653 public function testPostPhotoItem()
3655 $this->markTestIncomplete();
3659 * Test the prepare_photo_data() function.
3663 public function testPreparePhotoData()
3665 $this->markTestIncomplete();
3669 * Test the api_friendica_remoteauth() function.
3672 * @expectedException Friendica\Network\HTTPException\BadRequestException
3674 public function testApiFriendicaRemoteauth()
3676 api_friendica_remoteauth();
3680 * Test the api_friendica_remoteauth() function with an URL.
3683 * @expectedException Friendica\Network\HTTPException\BadRequestException
3685 public function testApiFriendicaRemoteauthWithUrl()
3687 $_GET['url'] = 'url';
3688 $_GET['c_url'] = 'url';
3689 api_friendica_remoteauth();
3693 * Test the api_friendica_remoteauth() function with a correct URL.
3697 public function testApiFriendicaRemoteauthWithCorrectUrl()
3699 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3700 $_GET['url'] = 'url';
3701 $_GET['c_url'] = $this->selfUser['nurl'];
3702 api_friendica_remoteauth();
3706 * Test the api_share_as_retweet() function.
3710 public function testApiShareAsRetweet()
3712 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3713 $result = api_share_as_retweet($item);
3714 $this->assertFalse($result);
3718 * Test the api_share_as_retweet() function with a valid item.
3722 public function testApiShareAsRetweetWithValidItem()
3724 $this->markTestIncomplete();
3728 * Test the api_in_reply_to() function.
3732 public function testApiInReplyTo()
3734 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3735 $this->assertArrayHasKey('status_id', $result);
3736 $this->assertArrayHasKey('user_id', $result);
3737 $this->assertArrayHasKey('status_id_str', $result);
3738 $this->assertArrayHasKey('user_id_str', $result);
3739 $this->assertArrayHasKey('screen_name', $result);
3743 * Test the api_in_reply_to() function with a valid item.
3747 public function testApiInReplyToWithValidItem()
3749 $this->markTestIncomplete();
3753 * Test the api_clean_plain_items() function.
3757 public function testApiCleanPlainItems()
3759 $_REQUEST['include_entities'] = 'true';
3760 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3761 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3765 * Test the api_best_nickname() function.
3769 public function testApiBestNickname()
3772 $result = api_best_nickname($contacts);
3773 $this->assertNull($result);
3777 * Test the api_best_nickname() function with contacts.
3781 public function testApiBestNicknameWithContacts()
3783 $this->markTestIncomplete();
3787 * Test the api_friendica_group_show() function.
3791 public function testApiFriendicaGroupShow()
3793 $this->markTestIncomplete();
3797 * Test the api_friendica_group_delete() function.
3801 public function testApiFriendicaGroupDelete()
3803 $this->markTestIncomplete();
3807 * Test the api_lists_destroy() function.
3811 public function testApiListsDestroy()
3813 $this->markTestIncomplete();
3817 * Test the group_create() function.
3821 public function testGroupCreate()
3823 $this->markTestIncomplete();
3827 * Test the api_friendica_group_create() function.
3831 public function testApiFriendicaGroupCreate()
3833 $this->markTestIncomplete();
3837 * Test the api_lists_create() function.
3841 public function testApiListsCreate()
3843 $this->markTestIncomplete();
3847 * Test the api_friendica_group_update() function.
3851 public function testApiFriendicaGroupUpdate()
3853 $this->markTestIncomplete();
3857 * Test the api_lists_update() function.
3861 public function testApiListsUpdate()
3863 $this->markTestIncomplete();
3867 * Test the api_friendica_activity() function.
3871 public function testApiFriendicaActivity()
3873 $this->markTestIncomplete();
3877 * Test the api_friendica_notification() function.
3880 * @expectedException Friendica\Network\HTTPException\BadRequestException
3882 public function testApiFriendicaNotification()
3884 api_friendica_notification('json');
3888 * Test the api_friendica_notification() function without an authenticated user.
3891 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3893 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3895 $_SESSION['authenticated'] = false;
3896 api_friendica_notification('json');
3900 * Test the api_friendica_notification() function with an argument count.
3904 public function testApiFriendicaNotificationWithArgumentCount()
3906 $this->app->argv = ['api', 'friendica', 'notification'];
3907 $this->app->argc = count($this->app->argv);
3908 $result = api_friendica_notification('json');
3909 $this->assertEquals(['note' => false], $result);
3913 * Test the api_friendica_notification() function with an XML result.
3917 public function testApiFriendicaNotificationWithXmlResult()
3919 $this->app->argv = ['api', 'friendica', 'notification'];
3920 $this->app->argc = count($this->app->argv);
3921 $result = api_friendica_notification('xml');
3922 $this->assertXml($result, 'notes');
3926 * Test the api_friendica_notification_seen() function.
3930 public function testApiFriendicaNotificationSeen()
3932 $this->markTestIncomplete();
3936 * Test the api_friendica_direct_messages_setseen() function.
3940 public function testApiFriendicaDirectMessagesSetseen()
3942 $this->markTestIncomplete();
3946 * Test the api_friendica_direct_messages_search() function.
3950 public function testApiFriendicaDirectMessagesSearch()
3952 $this->markTestIncomplete();
3956 * Test the api_friendica_profile_show() function.
3960 public function testApiFriendicaProfileShow()
3962 $result = api_friendica_profile_show('json');
3963 // We can't use assertSelfUser() here because the user object is missing some properties.
3964 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3965 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3966 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3967 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3968 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3969 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3970 $this->assertFalse($result['$result']['multi_profiles']);
3974 * Test the api_friendica_profile_show() function with a profile ID.
3978 public function testApiFriendicaProfileShowWithProfileId()
3980 $this->markTestIncomplete('We need to add a dataset for this.');
3984 * Test the api_friendica_profile_show() function with a wrong profile ID.
3987 * @expectedException Friendica\Network\HTTPException\BadRequestException
3989 public function testApiFriendicaProfileShowWithWrongProfileId()
3991 $_REQUEST['profile_id'] = 666;
3992 api_friendica_profile_show('json');
3996 * Test the api_friendica_profile_show() function without an authenticated user.
3999 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4001 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4003 $_SESSION['authenticated'] = false;
4004 api_friendica_profile_show('json');
4008 * Test the api_saved_searches_list() function.
4012 public function testApiSavedSearchesList()
4014 $result = api_saved_searches_list('json');
4015 $this->assertEquals(1, $result['terms'][0]['id']);
4016 $this->assertEquals(1, $result['terms'][0]['id_str']);
4017 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4018 $this->assertEquals('Saved search', $result['terms'][0]['query']);