6 namespace Friendica\Test;
10 use Friendica\BaseObject;
11 use Friendica\Core\Config;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\System;
15 use Friendica\Database\Database;
16 use Friendica\Network\HTTPException;
17 use Friendica\Test\Util\Database\StaticDatabase;
18 use Friendica\Test\Util\Database\YamlDataSet;
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;
49 * Create variables used by tests.
51 protected function setUp()
56 $dice = $dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
57 $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
58 BaseObject::setDependencyInjection($dice);
60 /** @var Database $dba */
61 $dba = $dice->create(Database::class);
63 // Load the API dataset for the whole API
64 $ymlTester = new YamlDataSet(__DIR__ . '/../datasets/api.yml');
65 $ymlTester->load($dba);
67 $this->app = BaseObject::getApp();
70 $this->app->argv = ['home'];
72 // User data that the test database is populated with
75 'name' => 'Self contact',
76 'nick' => 'selfcontact',
77 'nurl' => 'http://localhost/profile/selfcontact'
81 'name' => 'Friend contact',
82 'nick' => 'friendcontact',
83 'nurl' => 'http://localhost/profile/friendcontact'
87 'name' => 'othercontact',
88 'nick' => 'othercontact',
89 'nurl' => 'http://localhost/profile/othercontact'
92 // User ID that we know is not in the database
93 $this->wrongUserId = 666;
95 // Most API require login so we force the session
98 'authenticated' => true,
99 'uid' => $this->selfUser['id']
106 Config::set('system', 'url', 'http://localhost');
107 Config::set('system', 'hostname', 'localhost');
108 Config::set('system', 'worker_dont_fork', true);
111 Config::set('config', 'hostname', 'localhost');
112 Config::set('system', 'throttle_limit_day', 100);
113 Config::set('system', 'throttle_limit_week', 100);
114 Config::set('system', 'throttle_limit_month', 100);
115 Config::set('system', 'theme', 'system_theme');
119 * Assert that an user array contains expected keys.
121 * @param array $user User array
125 private function assertSelfUser(array $user)
127 $this->assertEquals($this->selfUser['id'], $user['uid']);
128 $this->assertEquals($this->selfUser['id'], $user['cid']);
129 $this->assertEquals(1, $user['self']);
130 $this->assertEquals('DFRN', $user['location']);
131 $this->assertEquals($this->selfUser['name'], $user['name']);
132 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
133 $this->assertEquals('dfrn', $user['network']);
134 $this->assertTrue($user['verified']);
138 * Assert that an user array contains expected keys.
140 * @param array $user User array
144 private function assertOtherUser(array $user)
146 $this->assertEquals($this->otherUser['id'], $user['id']);
147 $this->assertEquals($this->otherUser['id'], $user['id_str']);
148 $this->assertEquals(0, $user['self']);
149 $this->assertEquals($this->otherUser['name'], $user['name']);
150 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
151 $this->assertFalse($user['verified']);
155 * Assert that a status array contains expected keys.
157 * @param array $status Status array
161 private function assertStatus(array $status)
163 $this->assertInternalType('string', $status['text']);
164 $this->assertInternalType('int', $status['id']);
165 // We could probably do more checks here.
169 * Assert that a list array contains expected keys.
171 * @param array $list List array
175 private function assertList(array $list)
177 $this->assertInternalType('string', $list['name']);
178 $this->assertInternalType('int', $list['id']);
179 $this->assertInternalType('string', $list['id_str']);
180 $this->assertContains($list['mode'], ['public', 'private']);
181 // We could probably do more checks here.
185 * Assert that the string is XML and contain the root element.
187 * @param string $result XML string
188 * @param string $root_element Root element name
192 private function assertXml($result, $root_element)
194 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
195 $this->assertContains('<' . $root_element, $result);
196 // We could probably do more checks here.
200 * Get the path to a temporary empty PNG image.
202 * @return string Path
204 private function getTempImage()
206 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
210 // Empty 1x1 px PNG image
211 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
219 * Test the api_user() function.
223 public function testApiUser()
225 $this->assertEquals($this->selfUser['id'], api_user());
229 * Test the api_user() function with an unallowed user.
233 public function testApiUserWithUnallowedUser()
235 $_SESSION = ['allow_api' => false];
236 $this->assertEquals(false, api_user());
240 * Test the api_source() function.
244 public function testApiSource()
246 $this->assertEquals('api', api_source());
250 * Test the api_source() function with a Twidere user agent.
254 public function testApiSourceWithTwidere()
256 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
257 $this->assertEquals('Twidere', api_source());
261 * Test the api_source() function with a GET parameter.
265 public function testApiSourceWithGet()
267 $_GET['source'] = 'source_name';
268 $this->assertEquals('source_name', api_source());
272 * Test the api_date() function.
276 public function testApiDate()
278 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
282 * Test the api_register_func() function.
286 public function testApiRegisterFunc()
298 $this->assertTrue($API['api_path']['auth']);
299 $this->assertEquals('method', $API['api_path']['method']);
300 $this->assertTrue(is_callable($API['api_path']['func']));
304 * Test the api_login() function without any login.
307 * @runInSeparateProcess
308 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
310 public function testApiLoginWithoutLogin()
312 api_login($this->app);
316 * Test the api_login() function with a bad login.
319 * @runInSeparateProcess
320 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
322 public function testApiLoginWithBadLogin()
324 $_SERVER['PHP_AUTH_USER'] = 'user@server';
325 api_login($this->app);
329 * Test the api_login() function with oAuth.
333 public function testApiLoginWithOauth()
335 $this->markTestIncomplete('Can we test this easily?');
339 * Test the api_login() function with authentication provided by an addon.
343 public function testApiLoginWithAddonAuth()
345 $this->markTestIncomplete('Can we test this easily?');
349 * Test the api_login() function with a correct login.
352 * @runInSeparateProcess
354 public function testApiLoginWithCorrectLogin()
356 $_SERVER['PHP_AUTH_USER'] = 'Test user';
357 $_SERVER['PHP_AUTH_PW'] = 'password';
358 api_login($this->app);
362 * Test the api_login() function with a remote user.
365 * @runInSeparateProcess
366 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
368 public function testApiLoginWithRemoteUser()
370 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
371 api_login($this->app);
375 * Test the api_check_method() function.
379 public function testApiCheckMethod()
381 $this->assertFalse(api_check_method('method'));
385 * Test the api_check_method() function with a correct method.
389 public function testApiCheckMethodWithCorrectMethod()
391 $_SERVER['REQUEST_METHOD'] = 'method';
392 $this->assertTrue(api_check_method('method'));
396 * Test the api_check_method() function with a wildcard.
400 public function testApiCheckMethodWithWildcard()
402 $this->assertTrue(api_check_method('*'));
406 * Test the api_call() function.
409 * @runInSeparateProcess
411 public function testApiCall()
415 'method' => 'method',
416 'func' => function () {
417 return ['data' => ['some_data']];
420 $_SERVER['REQUEST_METHOD'] = 'method';
421 $_GET['callback'] = 'callback_name';
423 $this->app->query_string = 'api_path';
425 'callback_name(["some_data"])',
431 * Test the api_call() function with the profiled enabled.
434 * @runInSeparateProcess
436 public function testApiCallWithProfiler()
440 'method' => 'method',
441 'func' => function () {
442 return ['data' => ['some_data']];
445 $_SERVER['REQUEST_METHOD'] = 'method';
446 Config::set('system', 'profiler', true);
447 Config::set('rendertime', 'callstack', true);
448 $this->app->callstack = [
449 'database' => ['some_function' => 200],
450 'database_write' => ['some_function' => 200],
451 'cache' => ['some_function' => 200],
452 'cache_write' => ['some_function' => 200],
453 'network' => ['some_function' => 200]
456 $this->app->query_string = 'api_path';
464 * Test the api_call() function without any result.
467 * @runInSeparateProcess
469 public function testApiCallWithNoResult()
473 'method' => 'method',
474 'func' => function () {
478 $_SERVER['REQUEST_METHOD'] = 'method';
480 $this->app->query_string = 'api_path';
482 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
488 * Test the api_call() function with an unimplemented API.
491 * @runInSeparateProcess
493 public function testApiCallWithUninplementedApi()
496 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
502 * Test the api_call() function with a JSON result.
505 * @runInSeparateProcess
507 public function testApiCallWithJson()
511 'method' => 'method',
512 'func' => function () {
513 return ['data' => ['some_data']];
516 $_SERVER['REQUEST_METHOD'] = 'method';
518 $this->app->query_string = 'api_path.json';
526 * Test the api_call() function with an XML result.
529 * @runInSeparateProcess
531 public function testApiCallWithXml()
535 'method' => 'method',
536 'func' => function () {
540 $_SERVER['REQUEST_METHOD'] = 'method';
542 $this->app->query_string = 'api_path.xml';
550 * Test the api_call() function with an RSS result.
553 * @runInSeparateProcess
555 public function testApiCallWithRss()
559 'method' => 'method',
560 'func' => function () {
564 $_SERVER['REQUEST_METHOD'] = 'method';
566 $this->app->query_string = 'api_path.rss';
568 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
575 * Test the api_call() function with an Atom result.
578 * @runInSeparateProcess
580 public function testApiCallWithAtom()
584 'method' => 'method',
585 'func' => function () {
589 $_SERVER['REQUEST_METHOD'] = 'method';
591 $this->app->query_string = 'api_path.atom';
593 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
600 * Test the api_call() function with an unallowed method.
603 * @runInSeparateProcess
605 public function testApiCallWithWrongMethod()
608 $API['api_path'] = ['method' => 'method'];
610 $this->app->query_string = 'api_path';
612 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
618 * Test the api_call() function with an unauthorized user.
621 * @runInSeparateProcess
623 public function testApiCallWithWrongAuth()
627 'method' => 'method',
630 $_SERVER['REQUEST_METHOD'] = 'method';
631 $_SESSION['authenticated'] = false;
633 $this->app->query_string = 'api_path';
635 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
641 * Test the api_error() function with a JSON result.
644 * @runInSeparateProcess
646 public function testApiErrorWithJson()
649 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
650 api_error('json', new HTTPException\OKException('error_message'))
655 * Test the api_error() function with an XML result.
658 * @runInSeparateProcess
660 public function testApiErrorWithXml()
663 '<?xml version="1.0"?>' . "\n" .
664 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
665 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
666 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
667 ' <error>error_message</error>' . "\n" .
668 ' <code>200 OK</code>' . "\n" .
669 ' <request/>' . "\n" .
671 api_error('xml', new HTTPException\OKException('error_message'))
676 * Test the api_error() function with an RSS result.
679 * @runInSeparateProcess
681 public function testApiErrorWithRss()
684 '<?xml version="1.0"?>' . "\n" .
685 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
686 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
687 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
688 ' <error>error_message</error>' . "\n" .
689 ' <code>200 OK</code>' . "\n" .
690 ' <request/>' . "\n" .
692 api_error('rss', new HTTPException\OKException('error_message'))
697 * Test the api_error() function with an Atom result.
700 * @runInSeparateProcess
702 public function testApiErrorWithAtom()
705 '<?xml version="1.0"?>' . "\n" .
706 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
707 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
708 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
709 ' <error>error_message</error>' . "\n" .
710 ' <code>200 OK</code>' . "\n" .
711 ' <request/>' . "\n" .
713 api_error('atom', new HTTPException\OKException('error_message'))
718 * Test the api_rss_extra() function.
722 public function testApiRssExtra()
724 $user_info = ['url' => 'user_url', 'lang' => 'en'];
725 $result = api_rss_extra($this->app, [], $user_info);
726 $this->assertEquals($user_info, $result['$user']);
727 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
728 $this->assertArrayHasKey('self', $result['$rss']);
729 $this->assertArrayHasKey('base', $result['$rss']);
730 $this->assertArrayHasKey('updated', $result['$rss']);
731 $this->assertArrayHasKey('atom_updated', $result['$rss']);
732 $this->assertArrayHasKey('language', $result['$rss']);
733 $this->assertArrayHasKey('logo', $result['$rss']);
737 * Test the api_rss_extra() function without any user info.
741 public function testApiRssExtraWithoutUserInfo()
743 $result = api_rss_extra($this->app, [], null);
744 $this->assertInternalType('array', $result['$user']);
745 $this->assertArrayHasKey('alternate', $result['$rss']);
746 $this->assertArrayHasKey('self', $result['$rss']);
747 $this->assertArrayHasKey('base', $result['$rss']);
748 $this->assertArrayHasKey('updated', $result['$rss']);
749 $this->assertArrayHasKey('atom_updated', $result['$rss']);
750 $this->assertArrayHasKey('language', $result['$rss']);
751 $this->assertArrayHasKey('logo', $result['$rss']);
755 * Test the api_unique_id_to_nurl() function.
759 public function testApiUniqueIdToNurl()
761 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
765 * Test the api_unique_id_to_nurl() function with a correct ID.
769 public function testApiUniqueIdToNurlWithCorrectId()
771 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
775 * Test the api_get_user() function.
779 public function testApiGetUser()
781 $user = api_get_user($this->app);
782 $this->assertSelfUser($user);
783 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
784 $this->assertEquals('6fdbe8', $user['profile_link_color']);
785 $this->assertEquals('ededed', $user['profile_background_color']);
789 * Test the api_get_user() function with a Frio schema.
793 public function testApiGetUserWithFrioSchema()
795 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
796 $user = api_get_user($this->app);
797 $this->assertSelfUser($user);
798 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
799 $this->assertEquals('6fdbe8', $user['profile_link_color']);
800 $this->assertEquals('ededed', $user['profile_background_color']);
804 * Test the api_get_user() function with a custom Frio schema.
808 public function testApiGetUserWithCustomFrioSchema()
810 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
811 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
812 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
813 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
814 $user = api_get_user($this->app);
815 $this->assertSelfUser($user);
816 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
817 $this->assertEquals('123456', $user['profile_link_color']);
818 $this->assertEquals('123456', $user['profile_background_color']);
822 * Test the api_get_user() function with an empty Frio schema.
826 public function testApiGetUserWithEmptyFrioSchema()
828 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
829 $user = api_get_user($this->app);
830 $this->assertSelfUser($user);
831 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
832 $this->assertEquals('6fdbe8', $user['profile_link_color']);
833 $this->assertEquals('ededed', $user['profile_background_color']);
837 * Test the api_get_user() function with an user that is not allowed to use the API.
840 * @runInSeparateProcess
842 public function testApiGetUserWithoutApiUser()
844 $_SERVER['PHP_AUTH_USER'] = 'Test user';
845 $_SERVER['PHP_AUTH_PW'] = 'password';
846 $_SESSION['allow_api'] = false;
847 $this->assertFalse(api_get_user($this->app));
851 * Test the api_get_user() function with an user ID in a GET parameter.
855 public function testApiGetUserWithGetId()
857 $_GET['user_id'] = $this->otherUser['id'];
858 $this->assertOtherUser(api_get_user($this->app));
862 * Test the api_get_user() function with a wrong user ID in a GET parameter.
865 * @expectedException Friendica\Network\HTTPException\BadRequestException
867 public function testApiGetUserWithWrongGetId()
869 $_GET['user_id'] = $this->wrongUserId;
870 $this->assertOtherUser(api_get_user($this->app));
874 * Test the api_get_user() function with an user name in a GET parameter.
878 public function testApiGetUserWithGetName()
880 $_GET['screen_name'] = $this->selfUser['nick'];
881 $this->assertSelfUser(api_get_user($this->app));
885 * Test the api_get_user() function with a profile URL in a GET parameter.
889 public function testApiGetUserWithGetUrl()
891 $_GET['profileurl'] = $this->selfUser['nurl'];
892 $this->assertSelfUser(api_get_user($this->app));
896 * Test the api_get_user() function with an user ID in the API path.
900 public function testApiGetUserWithNumericCalledApi()
903 $called_api = ['api_path'];
904 $this->app->argv[1] = $this->otherUser['id'] . '.json';
905 $this->assertOtherUser(api_get_user($this->app));
909 * Test the api_get_user() function with the $called_api global variable.
913 public function testApiGetUserWithCalledApi()
916 $called_api = ['api', 'api_path'];
917 $this->assertSelfUser(api_get_user($this->app));
921 * Test the api_get_user() function with a valid user.
925 public function testApiGetUserWithCorrectUser()
927 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
931 * Test the api_get_user() function with a wrong user ID.
934 * @expectedException Friendica\Network\HTTPException\BadRequestException
936 public function testApiGetUserWithWrongUser()
938 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
942 * Test the api_get_user() function with a 0 user ID.
946 public function testApiGetUserWithZeroUser()
948 $this->assertSelfUser(api_get_user($this->app, 0));
952 * Test the api_item_get_user() function.
956 public function testApiItemGetUser()
958 $users = api_item_get_user($this->app, []);
959 $this->assertSelfUser($users[0]);
963 * Test the api_item_get_user() function with a different item parent.
967 public function testApiItemGetUserWithDifferentParent()
969 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
970 $this->assertSelfUser($users[0]);
971 $this->assertEquals($users[0], $users[1]);
975 * Test the api_walk_recursive() function.
979 public function testApiWalkRecursive()
987 // Should we test this with a callback that actually does something?
995 * Test the api_walk_recursive() function with an array.
999 public function testApiWalkRecursiveWithArray()
1001 $array = [['item1'], ['item2']];
1002 $this->assertEquals(
1007 // Should we test this with a callback that actually does something?
1015 * Test the api_reformat_xml() function.
1019 public function testApiReformatXml()
1023 $this->assertTrue(api_reformat_xml($item, $key));
1024 $this->assertEquals('true', $item);
1028 * Test the api_reformat_xml() function with a statusnet_api key.
1032 public function testApiReformatXmlWithStatusnetKey()
1035 $key = 'statusnet_api';
1036 $this->assertTrue(api_reformat_xml($item, $key));
1037 $this->assertEquals('statusnet:api', $key);
1041 * Test the api_reformat_xml() function with a friendica_api key.
1045 public function testApiReformatXmlWithFriendicaKey()
1048 $key = 'friendica_api';
1049 $this->assertTrue(api_reformat_xml($item, $key));
1050 $this->assertEquals('friendica:api', $key);
1054 * Test the api_create_xml() function.
1058 public function testApiCreateXml()
1060 $this->assertEquals(
1061 '<?xml version="1.0"?>' . "\n" .
1062 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1063 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1064 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1065 ' <data>some_data</data>' . "\n" .
1066 '</root_element>' . "\n",
1067 api_create_xml(['data' => ['some_data']], 'root_element')
1072 * Test the api_create_xml() function without any XML namespace.
1076 public function testApiCreateXmlWithoutNamespaces()
1078 $this->assertEquals(
1079 '<?xml version="1.0"?>' . "\n" .
1081 ' <data>some_data</data>' . "\n" .
1083 api_create_xml(['data' => ['some_data']], 'ok')
1088 * Test the api_format_data() function.
1092 public function testApiFormatData()
1094 $data = ['some_data'];
1095 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1099 * Test the api_format_data() function with an XML result.
1103 public function testApiFormatDataWithXml()
1105 $this->assertEquals(
1106 '<?xml version="1.0"?>' . "\n" .
1107 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1108 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1109 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1110 ' <data>some_data</data>' . "\n" .
1111 '</root_element>' . "\n",
1112 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1117 * Test the api_account_verify_credentials() function.
1121 public function testApiAccountVerifyCredentials()
1123 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1127 * Test the api_account_verify_credentials() function without an authenticated user.
1130 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1132 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1134 $_SESSION['authenticated'] = false;
1135 api_account_verify_credentials('json');
1139 * Test the requestdata() function.
1143 public function testRequestdata()
1145 $this->assertNull(requestdata('variable_name'));
1149 * Test the requestdata() function with a POST parameter.
1153 public function testRequestdataWithPost()
1155 $_POST['variable_name'] = 'variable_value';
1156 $this->assertEquals('variable_value', requestdata('variable_name'));
1160 * Test the requestdata() function with a GET parameter.
1164 public function testRequestdataWithGet()
1166 $_GET['variable_name'] = 'variable_value';
1167 $this->assertEquals('variable_value', requestdata('variable_name'));
1171 * Test the api_statuses_mediap() function.
1175 public function testApiStatusesMediap()
1177 $this->app->argc = 2;
1185 'tmp_name' => $this->getTempImage(),
1186 'name' => 'spacer.png',
1187 'type' => 'image/png'
1190 $_GET['status'] = '<b>Status content</b>';
1192 $result = api_statuses_mediap('json');
1193 $this->assertStatus($result['status']);
1197 * Test the api_statuses_mediap() function without an authenticated user.
1200 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1202 public function testApiStatusesMediapWithoutAuthenticatedUser()
1204 $_SESSION['authenticated'] = false;
1205 api_statuses_mediap('json');
1209 * Test the api_statuses_update() function.
1213 public function testApiStatusesUpdate()
1215 $_GET['status'] = 'Status content #friendica';
1216 $_GET['in_reply_to_status_id'] = -1;
1225 'tmp_name' => $this->getTempImage(),
1226 'name' => 'spacer.png',
1227 'type' => 'image/png'
1231 $result = api_statuses_update('json');
1232 $this->assertStatus($result['status']);
1236 * Test the api_statuses_update() function with an HTML status.
1240 public function testApiStatusesUpdateWithHtml()
1242 $_GET['htmlstatus'] = '<b>Status content</b>';
1244 $result = api_statuses_update('json');
1245 $this->assertStatus($result['status']);
1249 * Test the api_statuses_update() function without an authenticated user.
1252 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1254 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1256 $_SESSION['authenticated'] = false;
1257 api_statuses_update('json');
1261 * Test the api_statuses_update() function with a parent status.
1265 public function testApiStatusesUpdateWithParent()
1267 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1271 * Test the api_statuses_update() function with a media_ids parameter.
1275 public function testApiStatusesUpdateWithMediaIds()
1277 $this->markTestIncomplete();
1281 * Test the api_statuses_update() function with the throttle limit reached.
1285 public function testApiStatusesUpdateWithDayThrottleReached()
1287 $this->markTestIncomplete();
1291 * Test the api_media_upload() function.
1294 * @expectedException Friendica\Network\HTTPException\BadRequestException
1296 public function testApiMediaUpload()
1302 * Test the api_media_upload() function without an authenticated user.
1305 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1307 public function testApiMediaUploadWithoutAuthenticatedUser()
1309 $_SESSION['authenticated'] = false;
1314 * Test the api_media_upload() function with an invalid uploaded media.
1317 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1319 public function testApiMediaUploadWithMedia()
1324 'tmp_name' => 'tmp_name'
1331 * Test the api_media_upload() function with an valid uploaded media.
1335 public function testApiMediaUploadWithValidMedia()
1343 'tmp_name' => $this->getTempImage(),
1344 'name' => 'spacer.png',
1345 'type' => 'image/png'
1351 $result = api_media_upload();
1352 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1353 $this->assertEquals(1, $result['media']['image']['w']);
1354 $this->assertEquals(1, $result['media']['image']['h']);
1355 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1359 * Test the api_status_show() function.
1361 public function testApiStatusShowWithJson()
1363 $result = api_status_show('json', 1);
1364 $this->assertStatus($result['status']);
1368 * Test the api_status_show() function with an XML result.
1370 public function testApiStatusShowWithXml()
1372 $result = api_status_show('xml', 1);
1373 $this->assertXml($result, 'statuses');
1377 * Test the api_get_last_status() function
1379 public function testApiGetLastStatus()
1381 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1383 $this->assertNotNull($item);
1387 * Test the api_users_show() function.
1391 public function testApiUsersShow()
1393 $result = api_users_show('json');
1394 // We can't use assertSelfUser() here because the user object is missing some properties.
1395 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1396 $this->assertEquals('DFRN', $result['user']['location']);
1397 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1398 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1399 $this->assertEquals('dfrn', $result['user']['network']);
1400 $this->assertTrue($result['user']['verified']);
1404 * Test the api_users_show() function with an XML result.
1408 public function testApiUsersShowWithXml()
1410 $result = api_users_show('xml');
1411 $this->assertXml($result, 'statuses');
1415 * Test the api_users_search() function.
1419 public function testApiUsersSearch()
1421 $_GET['q'] = 'othercontact';
1422 $result = api_users_search('json');
1423 $this->assertOtherUser($result['users'][0]);
1427 * Test the api_users_search() function with an XML result.
1431 public function testApiUsersSearchWithXml()
1433 $_GET['q'] = 'othercontact';
1434 $result = api_users_search('xml');
1435 $this->assertXml($result, 'users');
1439 * Test the api_users_search() function without a GET q parameter.
1442 * @expectedException Friendica\Network\HTTPException\BadRequestException
1444 public function testApiUsersSearchWithoutQuery()
1446 api_users_search('json');
1450 * Test the api_users_lookup() function.
1453 * @expectedException Friendica\Network\HTTPException\NotFoundException
1455 public function testApiUsersLookup()
1457 api_users_lookup('json');
1461 * Test the api_users_lookup() function with an user ID.
1465 public function testApiUsersLookupWithUserId()
1467 $_REQUEST['user_id'] = $this->otherUser['id'];
1468 $result = api_users_lookup('json');
1469 $this->assertOtherUser($result['users'][0]);
1473 * Test the api_search() function.
1477 public function testApiSearch()
1479 $_REQUEST['q'] = 'reply';
1480 $_REQUEST['max_id'] = 10;
1481 $result = api_search('json');
1482 foreach ($result['status'] as $status) {
1483 $this->assertStatus($status);
1484 $this->assertContains('reply', $status['text'], null, true);
1489 * Test the api_search() function a count parameter.
1493 public function testApiSearchWithCount()
1495 $_REQUEST['q'] = 'reply';
1496 $_REQUEST['count'] = 20;
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 with an rpp parameter.
1509 public function testApiSearchWithRpp()
1511 $_REQUEST['q'] = 'reply';
1512 $_REQUEST['rpp'] = 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 q parameter contains hashtag.
1525 public function testApiSearchWithHashtag()
1527 $_REQUEST['q'] = '%23friendica';
1528 $result = api_search('json');
1529 foreach ($result['status'] as $status) {
1530 $this->assertStatus($status);
1531 $this->assertContains('#friendica', $status['text'], null, true);
1536 * Test the api_search() function with an exclude_replies parameter.
1540 public function testApiSearchWithExcludeReplies()
1542 $_REQUEST['max_id'] = 10;
1543 $_REQUEST['exclude_replies'] = true;
1544 $_REQUEST['q'] = 'friendica';
1545 $result = api_search('json');
1546 foreach ($result['status'] as $status) {
1547 $this->assertStatus($status);
1552 * Test the api_search() function without an authenticated user.
1555 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1557 public function testApiSearchWithUnallowedUser()
1559 $_SESSION['allow_api'] = false;
1560 $_GET['screen_name'] = $this->selfUser['nick'];
1565 * Test the api_search() function without any GET query parameter.
1568 * @expectedException Friendica\Network\HTTPException\BadRequestException
1570 public function testApiSearchWithoutQuery()
1576 * Test the api_statuses_home_timeline() function.
1580 public function testApiStatusesHomeTimeline()
1582 $_REQUEST['max_id'] = 10;
1583 $_REQUEST['exclude_replies'] = true;
1584 $_REQUEST['conversation_id'] = 1;
1585 $result = api_statuses_home_timeline('json');
1586 $this->assertNotEmpty($result['status']);
1587 foreach ($result['status'] as $status) {
1588 $this->assertStatus($status);
1593 * Test the api_statuses_home_timeline() function with a negative page parameter.
1597 public function testApiStatusesHomeTimelineWithNegativePage()
1599 $_REQUEST['page'] = -2;
1600 $result = api_statuses_home_timeline('json');
1601 $this->assertNotEmpty($result['status']);
1602 foreach ($result['status'] as $status) {
1603 $this->assertStatus($status);
1608 * Test the api_statuses_home_timeline() with an unallowed user.
1611 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1613 public function testApiStatusesHomeTimelineWithUnallowedUser()
1615 $_SESSION['allow_api'] = false;
1616 $_GET['screen_name'] = $this->selfUser['nick'];
1617 api_statuses_home_timeline('json');
1621 * Test the api_statuses_home_timeline() function with an RSS result.
1625 public function testApiStatusesHomeTimelineWithRss()
1627 $result = api_statuses_home_timeline('rss');
1628 $this->assertXml($result, 'statuses');
1632 * Test the api_statuses_public_timeline() function.
1636 public function testApiStatusesPublicTimeline()
1638 $_REQUEST['max_id'] = 10;
1639 $_REQUEST['conversation_id'] = 1;
1640 $result = api_statuses_public_timeline('json');
1641 $this->assertNotEmpty($result['status']);
1642 foreach ($result['status'] as $status) {
1643 $this->assertStatus($status);
1648 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1652 public function testApiStatusesPublicTimelineWithExcludeReplies()
1654 $_REQUEST['max_id'] = 10;
1655 $_REQUEST['exclude_replies'] = true;
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 a negative page parameter.
1668 public function testApiStatusesPublicTimelineWithNegativePage()
1670 $_REQUEST['page'] = -2;
1671 $result = api_statuses_public_timeline('json');
1672 $this->assertNotEmpty($result['status']);
1673 foreach ($result['status'] as $status) {
1674 $this->assertStatus($status);
1679 * Test the api_statuses_public_timeline() function with an unallowed user.
1682 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1684 public function testApiStatusesPublicTimelineWithUnallowedUser()
1686 $_SESSION['allow_api'] = false;
1687 $_GET['screen_name'] = $this->selfUser['nick'];
1688 api_statuses_public_timeline('json');
1692 * Test the api_statuses_public_timeline() function with an RSS result.
1696 public function testApiStatusesPublicTimelineWithRss()
1698 $result = api_statuses_public_timeline('rss');
1699 $this->assertXml($result, 'statuses');
1703 * Test the api_statuses_networkpublic_timeline() function.
1707 public function testApiStatusesNetworkpublicTimeline()
1709 $_REQUEST['max_id'] = 10;
1710 $result = api_statuses_networkpublic_timeline('json');
1711 $this->assertNotEmpty($result['status']);
1712 foreach ($result['status'] as $status) {
1713 $this->assertStatus($status);
1718 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1722 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1724 $_REQUEST['page'] = -2;
1725 $result = api_statuses_networkpublic_timeline('json');
1726 $this->assertNotEmpty($result['status']);
1727 foreach ($result['status'] as $status) {
1728 $this->assertStatus($status);
1733 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1736 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1738 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1740 $_SESSION['allow_api'] = false;
1741 $_GET['screen_name'] = $this->selfUser['nick'];
1742 api_statuses_networkpublic_timeline('json');
1746 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1750 public function testApiStatusesNetworkpublicTimelineWithRss()
1752 $result = api_statuses_networkpublic_timeline('rss');
1753 $this->assertXml($result, 'statuses');
1757 * Test the api_statuses_show() function.
1760 * @expectedException Friendica\Network\HTTPException\BadRequestException
1762 public function testApiStatusesShow()
1764 api_statuses_show('json');
1768 * Test the api_statuses_show() function with an ID.
1772 public function testApiStatusesShowWithId()
1774 $this->app->argv[3] = 1;
1775 $result = api_statuses_show('json');
1776 $this->assertStatus($result['status']);
1780 * Test the api_statuses_show() function with the conversation parameter.
1784 public function testApiStatusesShowWithConversation()
1786 $this->app->argv[3] = 1;
1787 $_REQUEST['conversation'] = 1;
1788 $result = api_statuses_show('json');
1789 $this->assertNotEmpty($result['status']);
1790 foreach ($result['status'] as $status) {
1791 $this->assertStatus($status);
1796 * Test the api_statuses_show() function with an unallowed user.
1799 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1801 public function testApiStatusesShowWithUnallowedUser()
1803 $_SESSION['allow_api'] = false;
1804 $_GET['screen_name'] = $this->selfUser['nick'];
1805 api_statuses_show('json');
1809 * Test the api_conversation_show() function.
1812 * @expectedException Friendica\Network\HTTPException\BadRequestException
1814 public function testApiConversationShow()
1816 api_conversation_show('json');
1820 * Test the api_conversation_show() function with an ID.
1824 public function testApiConversationShowWithId()
1826 $this->app->argv[3] = 1;
1827 $_REQUEST['max_id'] = 10;
1828 $_REQUEST['page'] = -2;
1829 $result = api_conversation_show('json');
1830 $this->assertNotEmpty($result['status']);
1831 foreach ($result['status'] as $status) {
1832 $this->assertStatus($status);
1837 * Test the api_conversation_show() function with an unallowed user.
1840 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1842 public function testApiConversationShowWithUnallowedUser()
1844 $_SESSION['allow_api'] = false;
1845 $_GET['screen_name'] = $this->selfUser['nick'];
1846 api_conversation_show('json');
1850 * Test the api_statuses_repeat() function.
1853 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1855 public function testApiStatusesRepeat()
1857 api_statuses_repeat('json');
1861 * Test the api_statuses_repeat() function without an authenticated user.
1864 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1866 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1868 $_SESSION['authenticated'] = false;
1869 api_statuses_repeat('json');
1873 * Test the api_statuses_repeat() function with an ID.
1877 public function testApiStatusesRepeatWithId()
1879 $this->app->argv[3] = 1;
1880 $result = api_statuses_repeat('json');
1881 $this->assertStatus($result['status']);
1883 // Also test with a shared status
1884 $this->app->argv[3] = 5;
1885 $result = api_statuses_repeat('json');
1886 $this->assertStatus($result['status']);
1890 * Test the api_statuses_destroy() function.
1893 * @expectedException Friendica\Network\HTTPException\BadRequestException
1895 public function testApiStatusesDestroy()
1897 api_statuses_destroy('json');
1901 * Test the api_statuses_destroy() function without an authenticated user.
1904 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1906 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1908 $_SESSION['authenticated'] = false;
1909 api_statuses_destroy('json');
1913 * Test the api_statuses_destroy() function with an ID.
1917 public function testApiStatusesDestroyWithId()
1919 $this->app->argv[3] = 1;
1920 $result = api_statuses_destroy('json');
1921 $this->assertStatus($result['status']);
1925 * Test the api_statuses_mentions() function.
1929 public function testApiStatusesMentions()
1931 $this->app->user = ['nickname' => $this->selfUser['nick']];
1932 $_REQUEST['max_id'] = 10;
1933 $result = api_statuses_mentions('json');
1934 $this->assertEmpty($result['status']);
1935 // We should test with mentions in the database.
1939 * Test the api_statuses_mentions() function with a negative page parameter.
1943 public function testApiStatusesMentionsWithNegativePage()
1945 $_REQUEST['page'] = -2;
1946 $result = api_statuses_mentions('json');
1947 $this->assertEmpty($result['status']);
1951 * Test the api_statuses_mentions() function with an unallowed user.
1954 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1956 public function testApiStatusesMentionsWithUnallowedUser()
1958 $_SESSION['allow_api'] = false;
1959 $_GET['screen_name'] = $this->selfUser['nick'];
1960 api_statuses_mentions('json');
1964 * Test the api_statuses_mentions() function with an RSS result.
1968 public function testApiStatusesMentionsWithRss()
1970 $result = api_statuses_mentions('rss');
1971 $this->assertXml($result, 'statuses');
1975 * Test the api_statuses_user_timeline() function.
1979 public function testApiStatusesUserTimeline()
1981 $_REQUEST['max_id'] = 10;
1982 $_REQUEST['exclude_replies'] = true;
1983 $_REQUEST['conversation_id'] = 1;
1984 $result = api_statuses_user_timeline('json');
1985 $this->assertNotEmpty($result['status']);
1986 foreach ($result['status'] as $status) {
1987 $this->assertStatus($status);
1992 * Test the api_statuses_user_timeline() function with a negative page parameter.
1996 public function testApiStatusesUserTimelineWithNegativePage()
1998 $_REQUEST['page'] = -2;
1999 $result = api_statuses_user_timeline('json');
2000 $this->assertNotEmpty($result['status']);
2001 foreach ($result['status'] as $status) {
2002 $this->assertStatus($status);
2007 * Test the api_statuses_user_timeline() function with an RSS result.
2011 public function testApiStatusesUserTimelineWithRss()
2013 $result = api_statuses_user_timeline('rss');
2014 $this->assertXml($result, 'statuses');
2018 * Test the api_statuses_user_timeline() function with an unallowed user.
2021 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2023 public function testApiStatusesUserTimelineWithUnallowedUser()
2025 $_SESSION['allow_api'] = false;
2026 $_GET['screen_name'] = $this->selfUser['nick'];
2027 api_statuses_user_timeline('json');
2031 * Test the api_favorites_create_destroy() function.
2034 * @expectedException Friendica\Network\HTTPException\BadRequestException
2036 public function testApiFavoritesCreateDestroy()
2038 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2039 $this->app->argc = count($this->app->argv);
2040 api_favorites_create_destroy('json');
2044 * Test the api_favorites_create_destroy() function with an invalid ID.
2047 * @expectedException Friendica\Network\HTTPException\BadRequestException
2049 public function testApiFavoritesCreateDestroyWithInvalidId()
2051 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2052 $this->app->argc = count($this->app->argv);
2053 api_favorites_create_destroy('json');
2057 * Test the api_favorites_create_destroy() function with an invalid action.
2060 * @expectedException Friendica\Network\HTTPException\BadRequestException
2062 public function testApiFavoritesCreateDestroyWithInvalidAction()
2064 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2065 $this->app->argc = count($this->app->argv);
2066 $_REQUEST['id'] = 1;
2067 api_favorites_create_destroy('json');
2071 * Test the api_favorites_create_destroy() function with the create action.
2075 public function testApiFavoritesCreateDestroyWithCreateAction()
2077 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2078 $this->app->argc = count($this->app->argv);
2079 $_REQUEST['id'] = 3;
2080 $result = api_favorites_create_destroy('json');
2081 $this->assertStatus($result['status']);
2085 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2089 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2091 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2092 $this->app->argc = count($this->app->argv);
2093 $_REQUEST['id'] = 3;
2094 $result = api_favorites_create_destroy('rss');
2095 $this->assertXml($result, 'status');
2099 * Test the api_favorites_create_destroy() function with the destroy action.
2103 public function testApiFavoritesCreateDestroyWithDestroyAction()
2105 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2106 $this->app->argc = count($this->app->argv);
2107 $_REQUEST['id'] = 3;
2108 $result = api_favorites_create_destroy('json');
2109 $this->assertStatus($result['status']);
2113 * Test the api_favorites_create_destroy() function without an authenticated user.
2116 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2118 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2120 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2121 $this->app->argc = count($this->app->argv);
2122 $_SESSION['authenticated'] = false;
2123 api_favorites_create_destroy('json');
2127 * Test the api_favorites() function.
2131 public function testApiFavorites()
2133 $_REQUEST['page'] = -1;
2134 $_REQUEST['max_id'] = 10;
2135 $result = api_favorites('json');
2136 foreach ($result['status'] as $status) {
2137 $this->assertStatus($status);
2142 * Test the api_favorites() function with an RSS result.
2146 public function testApiFavoritesWithRss()
2148 $result = api_favorites('rss');
2149 $this->assertXml($result, 'statuses');
2153 * Test the api_favorites() function with an unallowed user.
2156 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2158 public function testApiFavoritesWithUnallowedUser()
2160 $_SESSION['allow_api'] = false;
2161 $_GET['screen_name'] = $this->selfUser['nick'];
2162 api_favorites('json');
2166 * Test the api_format_messages() function.
2170 public function testApiFormatMessages()
2172 $result = api_format_messages(
2173 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2174 ['id' => 2, 'screen_name' => 'recipient_name'],
2175 ['id' => 3, 'screen_name' => 'sender_name']
2177 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2178 $this->assertEquals(1, $result['id']);
2179 $this->assertEquals(2, $result['recipient_id']);
2180 $this->assertEquals(3, $result['sender_id']);
2181 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2182 $this->assertEquals('sender_name', $result['sender_screen_name']);
2186 * Test the api_format_messages() function with HTML.
2190 public function testApiFormatMessagesWithHtmlText()
2192 $_GET['getText'] = 'html';
2193 $result = api_format_messages(
2194 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2195 ['id' => 2, 'screen_name' => 'recipient_name'],
2196 ['id' => 3, 'screen_name' => 'sender_name']
2198 $this->assertEquals('item_title', $result['title']);
2199 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2203 * Test the api_format_messages() function with plain text.
2207 public function testApiFormatMessagesWithPlainText()
2209 $_GET['getText'] = 'plain';
2210 $result = api_format_messages(
2211 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2212 ['id' => 2, 'screen_name' => 'recipient_name'],
2213 ['id' => 3, 'screen_name' => 'sender_name']
2215 $this->assertEquals('item_title', $result['title']);
2216 $this->assertEquals('item_body', $result['text']);
2220 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2224 public function testApiFormatMessagesWithoutUserObjects()
2226 $_GET['getUserObjects'] = 'false';
2227 $result = api_format_messages(
2228 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2229 ['id' => 2, 'screen_name' => 'recipient_name'],
2230 ['id' => 3, 'screen_name' => 'sender_name']
2232 $this->assertTrue(!isset($result['sender']));
2233 $this->assertTrue(!isset($result['recipient']));
2237 * Test the api_convert_item() function.
2241 public function testApiConvertItem()
2243 $result = api_convert_item(
2245 'network' => 'feed',
2246 'title' => 'item_title',
2247 // We need a long string to test that it is correctly cut
2248 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2249 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2250 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2251 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2252 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2253 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2254 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2255 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2256 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2257 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2258 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2259 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2260 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2261 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2262 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2263 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2264 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2265 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2266 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2267 'repellat officia illum quos impedit quam iste esse unde qui ' .
2268 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2269 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2270 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2271 'plink' => 'item_plink'
2274 $this->assertStringStartsWith('item_title', $result['text']);
2275 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2279 * Test the api_convert_item() function with an empty item body.
2283 public function testApiConvertItemWithoutBody()
2285 $result = api_convert_item(
2287 'network' => 'feed',
2288 'title' => 'item_title',
2290 'plink' => 'item_plink'
2293 $this->assertEquals('item_title', $result['text']);
2294 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2298 * Test the api_convert_item() function with the title in the body.
2302 public function testApiConvertItemWithTitleInBody()
2304 $result = api_convert_item(
2306 'title' => 'item_title',
2307 'body' => 'item_title item_body'
2310 $this->assertEquals('item_title item_body', $result['text']);
2311 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2315 * Test the api_get_attachments() function.
2319 public function testApiGetAttachments()
2322 $this->assertEmpty(api_get_attachments($body));
2326 * Test the api_get_attachments() function with an img tag.
2330 public function testApiGetAttachmentsWithImage()
2332 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2333 $this->assertInternalType('array', api_get_attachments($body));
2337 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2341 public function testApiGetAttachmentsWithImageAndAndStatus()
2343 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2344 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2345 $this->assertInternalType('array', api_get_attachments($body));
2349 * Test the api_get_entitities() function.
2353 public function testApiGetEntitities()
2356 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2360 * Test the api_get_entitities() function with the include_entities parameter.
2364 public function testApiGetEntititiesWithIncludeEntities()
2366 $_REQUEST['include_entities'] = 'true';
2368 $result = api_get_entitities($text, 'bbcode');
2369 $this->assertInternalType('array', $result['hashtags']);
2370 $this->assertInternalType('array', $result['symbols']);
2371 $this->assertInternalType('array', $result['urls']);
2372 $this->assertInternalType('array', $result['user_mentions']);
2376 * Test the api_format_items_embeded_images() function.
2380 public function testApiFormatItemsEmbededImages()
2382 $this->assertEquals(
2383 'text ' . System::baseUrl() . '/display/item_guid',
2384 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2389 * Test the api_contactlink_to_array() function.
2393 public function testApiContactlinkToArray()
2395 $this->assertEquals(
2400 api_contactlink_to_array('text')
2405 * Test the api_contactlink_to_array() function with an URL.
2409 public function testApiContactlinkToArrayWithUrl()
2411 $this->assertEquals(
2413 'name' => ['link_text'],
2416 api_contactlink_to_array('text <a href="url">link_text</a>')
2421 * Test the api_format_items_activities() function.
2425 public function testApiFormatItemsActivities()
2427 $item = ['uid' => 0, 'uri' => ''];
2428 $result = api_format_items_activities($item);
2429 $this->assertArrayHasKey('like', $result);
2430 $this->assertArrayHasKey('dislike', $result);
2431 $this->assertArrayHasKey('attendyes', $result);
2432 $this->assertArrayHasKey('attendno', $result);
2433 $this->assertArrayHasKey('attendmaybe', $result);
2437 * Test the api_format_items_activities() function with an XML result.
2441 public function testApiFormatItemsActivitiesWithXml()
2443 $item = ['uid' => 0, 'uri' => ''];
2444 $result = api_format_items_activities($item, 'xml');
2445 $this->assertArrayHasKey('friendica:like', $result);
2446 $this->assertArrayHasKey('friendica:dislike', $result);
2447 $this->assertArrayHasKey('friendica:attendyes', $result);
2448 $this->assertArrayHasKey('friendica:attendno', $result);
2449 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2453 * Test the api_format_items_profiles() function.
2457 public function testApiFormatItemsProfiles()
2460 'id' => 'profile_id',
2461 'profile-name' => 'profile_name',
2462 'is-default' => true,
2463 'hide-friends' => true,
2464 'photo' => 'profile_photo',
2465 'thumb' => 'profile_thumb',
2467 'net-publish' => true,
2468 'pdesc' => 'description',
2469 'dob' => 'date_of_birth',
2470 'address' => 'address',
2471 'locality' => 'city',
2472 'region' => 'region',
2473 'postal-code' => 'postal_code',
2474 'country-name' => 'country',
2475 'hometown' => 'hometown',
2476 'gender' => 'gender',
2477 'marital' => 'marital',
2478 'with' => 'marital_with',
2479 'howlong' => 'marital_since',
2480 'sexual' => 'sexual',
2481 'politic' => 'politic',
2482 'religion' => 'religion',
2483 'pub_keywords' => 'public_keywords',
2484 'prv_keywords' => 'private_keywords',
2487 'dislikes' => 'dislikes',
2493 'interest' => 'interest',
2494 'romance' => 'romance',
2496 'education' => 'education',
2497 'contact' => 'social_networks',
2498 'homepage' => 'homepage'
2500 $result = api_format_items_profiles($profile_row);
2501 $this->assertEquals(
2503 'profile_id' => 'profile_id',
2504 'profile_name' => 'profile_name',
2505 'is_default' => true,
2506 'hide_friends' => true,
2507 'profile_photo' => 'profile_photo',
2508 'profile_thumb' => 'profile_thumb',
2510 'net_publish' => true,
2511 'description' => 'description',
2512 'date_of_birth' => 'date_of_birth',
2513 'address' => 'address',
2515 'region' => 'region',
2516 'postal_code' => 'postal_code',
2517 'country' => 'country',
2518 'hometown' => 'hometown',
2519 'gender' => 'gender',
2520 'marital' => 'marital',
2521 'marital_with' => 'marital_with',
2522 'marital_since' => 'marital_since',
2523 'sexual' => 'sexual',
2524 'politic' => 'politic',
2525 'religion' => 'religion',
2526 'public_keywords' => 'public_keywords',
2527 'private_keywords' => 'private_keywords',
2530 'dislikes' => 'dislikes',
2536 'interest' => 'interest',
2537 'romance' => 'romance',
2539 'education' => 'education',
2540 'social_networks' => 'social_networks',
2541 'homepage' => 'homepage',
2549 * Test the api_format_items() function.
2553 public function testApiFormatItems()
2557 'item_network' => 'item_network',
2563 'author-network' => Protocol::DFRN,
2564 'author-link' => 'http://localhost/profile/othercontact',
2568 $result = api_format_items($items, ['id' => 0], true);
2569 foreach ($result as $status) {
2570 $this->assertStatus($status);
2575 * Test the api_format_items() function with an XML result.
2579 public function testApiFormatItemsWithXml()
2587 'author-network' => Protocol::DFRN,
2588 'author-link' => 'http://localhost/profile/othercontact',
2592 $result = api_format_items($items, ['id' => 0], true, 'xml');
2593 foreach ($result as $status) {
2594 $this->assertStatus($status);
2599 * Test the api_format_items() function.
2603 public function testApiAccountRateLimitStatus()
2605 $result = api_account_rate_limit_status('json');
2606 $this->assertEquals(150, $result['hash']['remaining_hits']);
2607 $this->assertEquals(150, $result['hash']['hourly_limit']);
2608 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2612 * Test the api_format_items() function with an XML result.
2616 public function testApiAccountRateLimitStatusWithXml()
2618 $result = api_account_rate_limit_status('xml');
2619 $this->assertXml($result, 'hash');
2623 * Test the api_help_test() function.
2627 public function testApiHelpTest()
2629 $result = api_help_test('json');
2630 $this->assertEquals(['ok' => 'ok'], $result);
2634 * Test the api_help_test() function with an XML result.
2638 public function testApiHelpTestWithXml()
2640 $result = api_help_test('xml');
2641 $this->assertXml($result, 'ok');
2645 * Test the api_lists_list() function.
2649 public function testApiListsList()
2651 $result = api_lists_list('json');
2652 $this->assertEquals(['lists_list' => []], $result);
2656 * Test the api_lists_ownerships() function.
2660 public function testApiListsOwnerships()
2662 $result = api_lists_ownerships('json');
2663 foreach ($result['lists']['lists'] as $list) {
2664 $this->assertList($list);
2669 * Test the api_lists_ownerships() function without an authenticated user.
2672 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2674 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2676 $_SESSION['authenticated'] = false;
2677 api_lists_ownerships('json');
2681 * Test the api_lists_statuses() function.
2683 * @expectedException Friendica\Network\HTTPException\BadRequestException
2686 public function testApiListsStatuses()
2688 api_lists_statuses('json');
2692 * Test the api_lists_statuses() function with a list ID.
2696 public function testApiListsStatusesWithListId()
2698 $_REQUEST['list_id'] = 1;
2699 $_REQUEST['page'] = -1;
2700 $_REQUEST['max_id'] = 10;
2701 $result = api_lists_statuses('json');
2702 foreach ($result['status'] as $status) {
2703 $this->assertStatus($status);
2708 * Test the api_lists_statuses() function with a list ID and a RSS result.
2712 public function testApiListsStatusesWithListIdAndRss()
2714 $_REQUEST['list_id'] = 1;
2715 $result = api_lists_statuses('rss');
2716 $this->assertXml($result, 'statuses');
2720 * Test the api_lists_statuses() function with an unallowed user.
2723 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2725 public function testApiListsStatusesWithUnallowedUser()
2727 $_SESSION['allow_api'] = false;
2728 $_GET['screen_name'] = $this->selfUser['nick'];
2729 api_lists_statuses('json');
2733 * Test the api_statuses_f() function.
2737 public function testApiStatusesFWithFriends()
2740 $result = api_statuses_f('friends');
2741 $this->assertArrayHasKey('user', $result);
2745 * Test the api_statuses_f() function.
2749 public function testApiStatusesFWithFollowers()
2751 $result = api_statuses_f('followers');
2752 $this->assertArrayHasKey('user', $result);
2756 * Test the api_statuses_f() function.
2760 public function testApiStatusesFWithBlocks()
2762 $result = api_statuses_f('blocks');
2763 $this->assertArrayHasKey('user', $result);
2767 * Test the api_statuses_f() function.
2771 public function testApiStatusesFWithIncoming()
2773 $result = api_statuses_f('incoming');
2774 $this->assertArrayHasKey('user', $result);
2778 * Test the api_statuses_f() function an undefined cursor GET variable.
2782 public function testApiStatusesFWithUndefinedCursor()
2784 $_GET['cursor'] = 'undefined';
2785 $this->assertFalse(api_statuses_f('friends'));
2789 * Test the api_statuses_friends() function.
2793 public function testApiStatusesFriends()
2795 $result = api_statuses_friends('json');
2796 $this->assertArrayHasKey('user', $result);
2800 * Test the api_statuses_friends() function an undefined cursor GET variable.
2804 public function testApiStatusesFriendsWithUndefinedCursor()
2806 $_GET['cursor'] = 'undefined';
2807 $this->assertFalse(api_statuses_friends('json'));
2811 * Test the api_statuses_followers() function.
2815 public function testApiStatusesFollowers()
2817 $result = api_statuses_followers('json');
2818 $this->assertArrayHasKey('user', $result);
2822 * Test the api_statuses_followers() function an undefined cursor GET variable.
2826 public function testApiStatusesFollowersWithUndefinedCursor()
2828 $_GET['cursor'] = 'undefined';
2829 $this->assertFalse(api_statuses_followers('json'));
2833 * Test the api_blocks_list() function.
2837 public function testApiBlocksList()
2839 $result = api_blocks_list('json');
2840 $this->assertArrayHasKey('user', $result);
2844 * Test the api_blocks_list() function an undefined cursor GET variable.
2848 public function testApiBlocksListWithUndefinedCursor()
2850 $_GET['cursor'] = 'undefined';
2851 $this->assertFalse(api_blocks_list('json'));
2855 * Test the api_friendships_incoming() function.
2859 public function testApiFriendshipsIncoming()
2861 $result = api_friendships_incoming('json');
2862 $this->assertArrayHasKey('id', $result);
2866 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2870 public function testApiFriendshipsIncomingWithUndefinedCursor()
2872 $_GET['cursor'] = 'undefined';
2873 $this->assertFalse(api_friendships_incoming('json'));
2877 * Test the api_statusnet_config() function.
2881 public function testApiStatusnetConfig()
2883 $result = api_statusnet_config('json');
2884 $this->assertEquals('localhost', $result['config']['site']['server']);
2885 $this->assertEquals('default', $result['config']['site']['theme']);
2886 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2887 $this->assertTrue($result['config']['site']['fancy']);
2888 $this->assertEquals('en', $result['config']['site']['language']);
2889 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2890 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2891 $this->assertEquals('false', $result['config']['site']['private']);
2892 $this->assertEquals('false', $result['config']['site']['ssl']);
2893 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2897 * Test the api_statusnet_version() function.
2901 public function testApiStatusnetVersion()
2903 $result = api_statusnet_version('json');
2904 $this->assertEquals('0.9.7', $result['version']);
2908 * Test the api_ff_ids() function.
2912 public function testApiFfIds()
2914 $result = api_ff_ids('json');
2915 $this->assertNull($result);
2919 * Test the api_ff_ids() function with a result.
2923 public function testApiFfIdsWithResult()
2925 $this->markTestIncomplete();
2929 * Test the api_ff_ids() function without an authenticated user.
2932 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2934 public function testApiFfIdsWithoutAuthenticatedUser()
2936 $_SESSION['authenticated'] = false;
2941 * Test the api_friends_ids() function.
2945 public function testApiFriendsIds()
2947 $result = api_friends_ids('json');
2948 $this->assertNull($result);
2952 * Test the api_followers_ids() function.
2956 public function testApiFollowersIds()
2958 $result = api_followers_ids('json');
2959 $this->assertNull($result);
2963 * Test the api_direct_messages_new() function.
2967 public function testApiDirectMessagesNew()
2969 $result = api_direct_messages_new('json');
2970 $this->assertNull($result);
2974 * Test the api_direct_messages_new() function without an authenticated user.
2977 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2979 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2981 $_SESSION['authenticated'] = false;
2982 api_direct_messages_new('json');
2986 * Test the api_direct_messages_new() function with an user ID.
2990 public function testApiDirectMessagesNewWithUserId()
2992 $_POST['text'] = 'message_text';
2993 $_POST['user_id'] = $this->otherUser['id'];
2994 $result = api_direct_messages_new('json');
2995 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2999 * Test the api_direct_messages_new() function with a screen name.
3003 public function testApiDirectMessagesNewWithScreenName()
3005 $_POST['text'] = 'message_text';
3006 $_POST['screen_name'] = $this->friendUser['nick'];
3007 $result = api_direct_messages_new('json');
3008 $this->assertContains('message_text', $result['direct_message']['text']);
3009 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3010 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3014 * Test the api_direct_messages_new() function with a title.
3018 public function testApiDirectMessagesNewWithTitle()
3020 $_POST['text'] = 'message_text';
3021 $_POST['screen_name'] = $this->friendUser['nick'];
3022 $_REQUEST['title'] = 'message_title';
3023 $result = api_direct_messages_new('json');
3024 $this->assertContains('message_text', $result['direct_message']['text']);
3025 $this->assertContains('message_title', $result['direct_message']['text']);
3026 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3027 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3031 * Test the api_direct_messages_new() function with an RSS result.
3035 public function testApiDirectMessagesNewWithRss()
3037 $_POST['text'] = 'message_text';
3038 $_POST['screen_name'] = $this->friendUser['nick'];
3039 $result = api_direct_messages_new('rss');
3040 $this->assertXml($result, 'direct-messages');
3044 * Test the api_direct_messages_destroy() function.
3047 * @expectedException Friendica\Network\HTTPException\BadRequestException
3049 public function testApiDirectMessagesDestroy()
3051 api_direct_messages_destroy('json');
3055 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3059 public function testApiDirectMessagesDestroyWithVerbose()
3061 $_GET['friendica_verbose'] = 'true';
3062 $result = api_direct_messages_destroy('json');
3063 $this->assertEquals(
3066 'result' => 'error',
3067 'message' => 'message id or parenturi not specified'
3075 * Test the api_direct_messages_destroy() function without an authenticated user.
3078 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3080 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3082 $_SESSION['authenticated'] = false;
3083 api_direct_messages_destroy('json');
3087 * Test the api_direct_messages_destroy() function with a non-zero ID.
3090 * @expectedException Friendica\Network\HTTPException\BadRequestException
3092 public function testApiDirectMessagesDestroyWithId()
3094 $_REQUEST['id'] = 1;
3095 api_direct_messages_destroy('json');
3099 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3103 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3105 $_REQUEST['id'] = 1;
3106 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3107 $_GET['friendica_verbose'] = 'true';
3108 $result = api_direct_messages_destroy('json');
3109 $this->assertEquals(
3112 'result' => 'error',
3113 'message' => 'message id not in database'
3121 * Test the api_direct_messages_destroy() function with a non-zero ID.
3125 public function testApiDirectMessagesDestroyWithCorrectId()
3127 $this->markTestIncomplete('We need to add a dataset for this.');
3131 * Test the api_direct_messages_box() function.
3135 public function testApiDirectMessagesBoxWithSentbox()
3137 $_REQUEST['page'] = -1;
3138 $_REQUEST['max_id'] = 10;
3139 $result = api_direct_messages_box('json', 'sentbox', 'false');
3140 $this->assertArrayHasKey('direct_message', $result);
3144 * Test the api_direct_messages_box() function.
3148 public function testApiDirectMessagesBoxWithConversation()
3150 $result = api_direct_messages_box('json', 'conversation', 'false');
3151 $this->assertArrayHasKey('direct_message', $result);
3155 * Test the api_direct_messages_box() function.
3159 public function testApiDirectMessagesBoxWithAll()
3161 $result = api_direct_messages_box('json', 'all', 'false');
3162 $this->assertArrayHasKey('direct_message', $result);
3166 * Test the api_direct_messages_box() function.
3170 public function testApiDirectMessagesBoxWithInbox()
3172 $result = api_direct_messages_box('json', 'inbox', 'false');
3173 $this->assertArrayHasKey('direct_message', $result);
3177 * Test the api_direct_messages_box() function.
3181 public function testApiDirectMessagesBoxWithVerbose()
3183 $result = api_direct_messages_box('json', 'sentbox', 'true');
3184 $this->assertEquals(
3187 'result' => 'error',
3188 'message' => 'no mails available'
3196 * Test the api_direct_messages_box() function with a RSS result.
3200 public function testApiDirectMessagesBoxWithRss()
3202 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3203 $this->assertXml($result, 'direct-messages');
3207 * Test the api_direct_messages_box() function without an authenticated user.
3210 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3212 public function testApiDirectMessagesBoxWithUnallowedUser()
3214 $_SESSION['allow_api'] = false;
3215 $_GET['screen_name'] = $this->selfUser['nick'];
3216 api_direct_messages_box('json', 'sentbox', 'false');
3220 * Test the api_direct_messages_sentbox() function.
3224 public function testApiDirectMessagesSentbox()
3226 $result = api_direct_messages_sentbox('json');
3227 $this->assertArrayHasKey('direct_message', $result);
3231 * Test the api_direct_messages_inbox() function.
3235 public function testApiDirectMessagesInbox()
3237 $result = api_direct_messages_inbox('json');
3238 $this->assertArrayHasKey('direct_message', $result);
3242 * Test the api_direct_messages_all() function.
3246 public function testApiDirectMessagesAll()
3248 $result = api_direct_messages_all('json');
3249 $this->assertArrayHasKey('direct_message', $result);
3253 * Test the api_direct_messages_conversation() function.
3257 public function testApiDirectMessagesConversation()
3259 $result = api_direct_messages_conversation('json');
3260 $this->assertArrayHasKey('direct_message', $result);
3264 * Test the api_oauth_request_token() function.
3268 public function testApiOauthRequestToken()
3270 $this->markTestIncomplete('killme() kills phpunit as well');
3274 * Test the api_oauth_access_token() function.
3278 public function testApiOauthAccessToken()
3280 $this->markTestIncomplete('killme() kills phpunit as well');
3284 * Test the api_fr_photoalbum_delete() function.
3287 * @expectedException Friendica\Network\HTTPException\BadRequestException
3289 public function testApiFrPhotoalbumDelete()
3291 api_fr_photoalbum_delete('json');
3295 * Test the api_fr_photoalbum_delete() function with an album name.
3298 * @expectedException Friendica\Network\HTTPException\BadRequestException
3300 public function testApiFrPhotoalbumDeleteWithAlbum()
3302 $_REQUEST['album'] = 'album_name';
3303 api_fr_photoalbum_delete('json');
3307 * Test the api_fr_photoalbum_delete() function with an album name.
3311 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3313 $this->markTestIncomplete('We need to add a dataset for this.');
3317 * Test the api_fr_photoalbum_delete() function.
3320 * @expectedException Friendica\Network\HTTPException\BadRequestException
3322 public function testApiFrPhotoalbumUpdate()
3324 api_fr_photoalbum_update('json');
3328 * Test the api_fr_photoalbum_delete() function with an album name.
3331 * @expectedException Friendica\Network\HTTPException\BadRequestException
3333 public function testApiFrPhotoalbumUpdateWithAlbum()
3335 $_REQUEST['album'] = 'album_name';
3336 api_fr_photoalbum_update('json');
3340 * Test the api_fr_photoalbum_delete() function with an album name.
3343 * @expectedException Friendica\Network\HTTPException\BadRequestException
3345 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3347 $_REQUEST['album'] = 'album_name';
3348 $_REQUEST['album_new'] = 'album_name';
3349 api_fr_photoalbum_update('json');
3353 * Test the api_fr_photoalbum_update() function without an authenticated user.
3356 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3358 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3360 $_SESSION['authenticated'] = false;
3361 api_fr_photoalbum_update('json');
3365 * Test the api_fr_photoalbum_delete() function with an album name.
3369 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3371 $this->markTestIncomplete('We need to add a dataset for this.');
3375 * Test the api_fr_photos_list() function.
3379 public function testApiFrPhotosList()
3381 $result = api_fr_photos_list('json');
3382 $this->assertArrayHasKey('photo', $result);
3386 * Test the api_fr_photos_list() function without an authenticated user.
3389 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3391 public function testApiFrPhotosListWithoutAuthenticatedUser()
3393 $_SESSION['authenticated'] = false;
3394 api_fr_photos_list('json');
3398 * Test the api_fr_photo_create_update() function.
3401 * @expectedException Friendica\Network\HTTPException\BadRequestException
3403 public function testApiFrPhotoCreateUpdate()
3405 api_fr_photo_create_update('json');
3409 * Test the api_fr_photo_create_update() function without an authenticated user.
3412 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3414 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3416 $_SESSION['authenticated'] = false;
3417 api_fr_photo_create_update('json');
3421 * Test the api_fr_photo_create_update() function with an album name.
3424 * @expectedException Friendica\Network\HTTPException\BadRequestException
3426 public function testApiFrPhotoCreateUpdateWithAlbum()
3428 $_REQUEST['album'] = 'album_name';
3429 api_fr_photo_create_update('json');
3433 * Test the api_fr_photo_create_update() function with the update mode.
3437 public function testApiFrPhotoCreateUpdateWithUpdate()
3439 $this->markTestIncomplete('We need to create a dataset for this');
3443 * Test the api_fr_photo_create_update() function with an uploaded file.
3447 public function testApiFrPhotoCreateUpdateWithFile()
3449 $this->markTestIncomplete();
3453 * Test the api_fr_photo_delete() function.
3456 * @expectedException Friendica\Network\HTTPException\BadRequestException
3458 public function testApiFrPhotoDelete()
3460 api_fr_photo_delete('json');
3464 * Test the api_fr_photo_delete() function without an authenticated user.
3467 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3469 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3471 $_SESSION['authenticated'] = false;
3472 api_fr_photo_delete('json');
3476 * Test the api_fr_photo_delete() function with a photo ID.
3479 * @expectedException Friendica\Network\HTTPException\BadRequestException
3481 public function testApiFrPhotoDeleteWithPhotoId()
3483 $_REQUEST['photo_id'] = 1;
3484 api_fr_photo_delete('json');
3488 * Test the api_fr_photo_delete() function with a correct photo ID.
3492 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3494 $this->markTestIncomplete('We need to create a dataset for this.');
3498 * Test the api_fr_photo_detail() function.
3501 * @expectedException Friendica\Network\HTTPException\BadRequestException
3503 public function testApiFrPhotoDetail()
3505 api_fr_photo_detail('json');
3509 * Test the api_fr_photo_detail() function without an authenticated user.
3512 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3514 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3516 $_SESSION['authenticated'] = false;
3517 api_fr_photo_detail('json');
3521 * Test the api_fr_photo_detail() function with a photo ID.
3524 * @expectedException Friendica\Network\HTTPException\NotFoundException
3526 public function testApiFrPhotoDetailWithPhotoId()
3528 $_REQUEST['photo_id'] = 1;
3529 api_fr_photo_detail('json');
3533 * Test the api_fr_photo_detail() function with a correct photo ID.
3537 public function testApiFrPhotoDetailCorrectPhotoId()
3539 $this->markTestIncomplete('We need to create a dataset for this.');
3543 * Test the api_account_update_profile_image() function.
3546 * @expectedException Friendica\Network\HTTPException\BadRequestException
3548 public function testApiAccountUpdateProfileImage()
3550 api_account_update_profile_image('json');
3554 * Test the api_account_update_profile_image() function without an authenticated user.
3557 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3559 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3561 $_SESSION['authenticated'] = false;
3562 api_account_update_profile_image('json');
3566 * Test the api_account_update_profile_image() function with an uploaded file.
3569 * @expectedException Friendica\Network\HTTPException\BadRequestException
3571 public function testApiAccountUpdateProfileImageWithUpload()
3573 $this->markTestIncomplete();
3578 * Test the api_account_update_profile() function.
3582 public function testApiAccountUpdateProfile()
3584 $_POST['name'] = 'new_name';
3585 $_POST['description'] = 'new_description';
3586 $result = api_account_update_profile('json');
3587 // We can't use assertSelfUser() here because the user object is missing some properties.
3588 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3589 $this->assertEquals('DFRN', $result['user']['location']);
3590 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3591 $this->assertEquals('dfrn', $result['user']['network']);
3592 $this->assertEquals('new_name', $result['user']['name']);
3593 $this->assertEquals('new_description', $result['user']['description']);
3597 * Test the check_acl_input() function.
3601 public function testCheckAclInput()
3603 $result = check_acl_input('<aclstring>');
3604 // Where does this result come from?
3605 $this->assertEquals(1, $result);
3609 * Test the check_acl_input() function with an empty ACL string.
3613 public function testCheckAclInputWithEmptyAclString()
3615 $result = check_acl_input(' ');
3616 $this->assertFalse($result);
3620 * Test the save_media_to_database() function.
3624 public function testSaveMediaToDatabase()
3626 $this->markTestIncomplete();
3630 * Test the post_photo_item() function.
3634 public function testPostPhotoItem()
3636 $this->markTestIncomplete();
3640 * Test the prepare_photo_data() function.
3644 public function testPreparePhotoData()
3646 $this->markTestIncomplete();
3650 * Test the api_friendica_remoteauth() function.
3653 * @expectedException Friendica\Network\HTTPException\BadRequestException
3655 public function testApiFriendicaRemoteauth()
3657 api_friendica_remoteauth();
3661 * Test the api_friendica_remoteauth() function with an URL.
3664 * @expectedException Friendica\Network\HTTPException\BadRequestException
3666 public function testApiFriendicaRemoteauthWithUrl()
3668 $_GET['url'] = 'url';
3669 $_GET['c_url'] = 'url';
3670 api_friendica_remoteauth();
3674 * Test the api_friendica_remoteauth() function with a correct URL.
3678 public function testApiFriendicaRemoteauthWithCorrectUrl()
3680 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3681 $_GET['url'] = 'url';
3682 $_GET['c_url'] = $this->selfUser['nurl'];
3683 api_friendica_remoteauth();
3687 * Test the api_share_as_retweet() function.
3691 public function testApiShareAsRetweet()
3693 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3694 $result = api_share_as_retweet($item);
3695 $this->assertFalse($result);
3699 * Test the api_share_as_retweet() function with a valid item.
3703 public function testApiShareAsRetweetWithValidItem()
3705 $this->markTestIncomplete();
3709 * Test the api_get_nick() function.
3713 public function testApiGetNick()
3715 $result = api_get_nick($this->otherUser['nurl']);
3716 $this->assertEquals('othercontact', $result);
3720 * Test the api_get_nick() function with a wrong URL.
3724 public function testApiGetNickWithWrongUrl()
3726 $result = api_get_nick('wrong_url');
3727 $this->assertFalse($result);
3731 * Test the api_in_reply_to() function.
3735 public function testApiInReplyTo()
3737 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3738 $this->assertArrayHasKey('status_id', $result);
3739 $this->assertArrayHasKey('user_id', $result);
3740 $this->assertArrayHasKey('status_id_str', $result);
3741 $this->assertArrayHasKey('user_id_str', $result);
3742 $this->assertArrayHasKey('screen_name', $result);
3746 * Test the api_in_reply_to() function with a valid item.
3750 public function testApiInReplyToWithValidItem()
3752 $this->markTestIncomplete();
3756 * Test the api_clean_plain_items() function.
3760 public function testApiCleanPlainItems()
3762 $_REQUEST['include_entities'] = 'true';
3763 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3764 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3768 * Test the api_clean_attachments() function.
3772 public function testApiCleanAttachments()
3774 $this->markTestIncomplete();
3778 * Test the api_best_nickname() function.
3782 public function testApiBestNickname()
3785 $result = api_best_nickname($contacts);
3786 $this->assertNull($result);
3790 * Test the api_best_nickname() function with contacts.
3794 public function testApiBestNicknameWithContacts()
3796 $this->markTestIncomplete();
3800 * Test the api_friendica_group_show() function.
3804 public function testApiFriendicaGroupShow()
3806 $this->markTestIncomplete();
3810 * Test the api_friendica_group_delete() function.
3814 public function testApiFriendicaGroupDelete()
3816 $this->markTestIncomplete();
3820 * Test the api_lists_destroy() function.
3824 public function testApiListsDestroy()
3826 $this->markTestIncomplete();
3830 * Test the group_create() function.
3834 public function testGroupCreate()
3836 $this->markTestIncomplete();
3840 * Test the api_friendica_group_create() function.
3844 public function testApiFriendicaGroupCreate()
3846 $this->markTestIncomplete();
3850 * Test the api_lists_create() function.
3854 public function testApiListsCreate()
3856 $this->markTestIncomplete();
3860 * Test the api_friendica_group_update() function.
3864 public function testApiFriendicaGroupUpdate()
3866 $this->markTestIncomplete();
3870 * Test the api_lists_update() function.
3874 public function testApiListsUpdate()
3876 $this->markTestIncomplete();
3880 * Test the api_friendica_activity() function.
3884 public function testApiFriendicaActivity()
3886 $this->markTestIncomplete();
3890 * Test the api_friendica_notification() function.
3893 * @expectedException Friendica\Network\HTTPException\BadRequestException
3895 public function testApiFriendicaNotification()
3897 api_friendica_notification('json');
3901 * Test the api_friendica_notification() function without an authenticated user.
3904 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3906 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3908 $_SESSION['authenticated'] = false;
3909 api_friendica_notification('json');
3913 * Test the api_friendica_notification() function with an argument count.
3917 public function testApiFriendicaNotificationWithArgumentCount()
3919 $this->app->argv = ['api', 'friendica', 'notification'];
3920 $this->app->argc = count($this->app->argv);
3921 $result = api_friendica_notification('json');
3922 $this->assertEquals(['note' => false], $result);
3926 * Test the api_friendica_notification() function with an XML result.
3930 public function testApiFriendicaNotificationWithXmlResult()
3932 $this->app->argv = ['api', 'friendica', 'notification'];
3933 $this->app->argc = count($this->app->argv);
3934 $result = api_friendica_notification('xml');
3935 $this->assertXml($result, 'notes');
3939 * Test the api_friendica_notification_seen() function.
3943 public function testApiFriendicaNotificationSeen()
3945 $this->markTestIncomplete();
3949 * Test the api_friendica_direct_messages_setseen() function.
3953 public function testApiFriendicaDirectMessagesSetseen()
3955 $this->markTestIncomplete();
3959 * Test the api_friendica_direct_messages_search() function.
3963 public function testApiFriendicaDirectMessagesSearch()
3965 $this->markTestIncomplete();
3969 * Test the api_friendica_profile_show() function.
3973 public function testApiFriendicaProfileShow()
3975 $result = api_friendica_profile_show('json');
3976 // We can't use assertSelfUser() here because the user object is missing some properties.
3977 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3978 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3979 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3980 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3981 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3982 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3983 $this->assertFalse($result['$result']['multi_profiles']);
3987 * Test the api_friendica_profile_show() function with a profile ID.
3991 public function testApiFriendicaProfileShowWithProfileId()
3993 $this->markTestIncomplete('We need to add a dataset for this.');
3997 * Test the api_friendica_profile_show() function with a wrong profile ID.
4000 * @expectedException Friendica\Network\HTTPException\BadRequestException
4002 public function testApiFriendicaProfileShowWithWrongProfileId()
4004 $_REQUEST['profile_id'] = 666;
4005 api_friendica_profile_show('json');
4009 * Test the api_friendica_profile_show() function without an authenticated user.
4012 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4014 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4016 $_SESSION['authenticated'] = false;
4017 api_friendica_profile_show('json');
4021 * Test the api_saved_searches_list() function.
4025 public function testApiSavedSearchesList()
4027 $result = api_saved_searches_list('json');
4028 $this->assertEquals(1, $result['terms'][0]['id']);
4029 $this->assertEquals(1, $result['terms'][0]['id_str']);
4030 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4031 $this->assertEquals('Saved search', $result['terms'][0]['query']);