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\System;
15 use Friendica\Database\Database;
16 use Friendica\Model\Contact;
17 use Friendica\Network\HTTPException;
18 use Friendica\Test\Util\Database\StaticDatabase;
19 use Monolog\Handler\TestHandler;
21 require_once __DIR__ . '/../../include/api.php';
24 * Tests for the API functions.
26 * Functions that use header() need to be tested in a separate process.
27 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
29 class ApiTest extends DatabaseTest
32 * @var TestHandler Can handle log-outputs
39 protected $friendUser;
43 protected $wrongUserId;
48 /** @var Configuration */
55 * Create variables used by tests.
57 protected function setUp()
61 $this->dice = (new Dice())
62 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
63 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
64 BaseObject::setDependencyInjection($this->dice);
66 /** @var Database $dba */
67 $dba = $this->dice->create(Database::class);
69 /** @var Configuration $config */
70 $this->config = $this->dice->create(Configuration::class);
72 $this->config->set('system', 'url', 'http://localhost');
73 $this->config->set('system', 'hostname', 'localhost');
74 $this->config->set('system', 'worker_dont_fork', true);
77 $this->config->set('config', 'hostname', 'localhost');
78 $this->config->set('system', 'throttle_limit_day', 100);
79 $this->config->set('system', 'throttle_limit_week', 100);
80 $this->config->set('system', 'throttle_limit_month', 100);
81 $this->config->set('system', 'theme', 'system_theme');
83 // Load the API dataset for the whole API
84 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
87 $this->app = BaseObject::getApp();
90 $this->app->argv = ['home'];
92 // User data that the test database is populated with
95 'name' => 'Self contact',
96 'nick' => 'selfcontact',
97 'nurl' => 'http://localhost/profile/selfcontact'
101 'name' => 'Friend contact',
102 'nick' => 'friendcontact',
103 'nurl' => 'http://localhost/profile/friendcontact'
107 'name' => 'othercontact',
108 'nick' => 'othercontact',
109 'nurl' => 'http://localhost/profile/othercontact'
112 // User ID that we know is not in the database
113 $this->wrongUserId = 666;
115 // Most API require login so we force the session
118 'authenticated' => true,
119 'uid' => $this->selfUser['id']
128 * Assert that an user array contains expected keys.
130 * @param array $user User array
134 private function assertSelfUser(array $user)
136 $this->assertEquals($this->selfUser['id'], $user['uid']);
137 $this->assertEquals($this->selfUser['id'], $user['cid']);
138 $this->assertEquals(1, $user['self']);
139 $this->assertEquals('DFRN', $user['location']);
140 $this->assertEquals($this->selfUser['name'], $user['name']);
141 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
142 $this->assertEquals('dfrn', $user['network']);
143 $this->assertTrue($user['verified']);
147 * Assert that an user array contains expected keys.
149 * @param array $user User array
153 private function assertOtherUser(array $user)
155 $this->assertEquals($this->otherUser['id'], $user['id']);
156 $this->assertEquals($this->otherUser['id'], $user['id_str']);
157 $this->assertEquals(0, $user['self']);
158 $this->assertEquals($this->otherUser['name'], $user['name']);
159 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
160 $this->assertFalse($user['verified']);
164 * Assert that a status array contains expected keys.
166 * @param array $status Status array
170 private function assertStatus(array $status)
172 $this->assertInternalType('string', $status['text']);
173 $this->assertInternalType('int', $status['id']);
174 // We could probably do more checks here.
178 * Assert that a list array contains expected keys.
180 * @param array $list List array
184 private function assertList(array $list)
186 $this->assertInternalType('string', $list['name']);
187 $this->assertInternalType('int', $list['id']);
188 $this->assertInternalType('string', $list['id_str']);
189 $this->assertContains($list['mode'], ['public', 'private']);
190 // We could probably do more checks here.
194 * Assert that the string is XML and contain the root element.
196 * @param string $result XML string
197 * @param string $root_element Root element name
201 private function assertXml($result, $root_element)
203 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
204 $this->assertContains('<' . $root_element, $result);
205 // We could probably do more checks here.
209 * Get the path to a temporary empty PNG image.
211 * @return string Path
213 private function getTempImage()
215 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
219 // Empty 1x1 px PNG image
220 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
228 * Test the api_user() function.
232 public function testApiUser()
234 $this->assertEquals($this->selfUser['id'], api_user());
238 * Test the api_user() function with an unallowed user.
242 public function testApiUserWithUnallowedUser()
244 $_SESSION = ['allow_api' => false];
245 $this->assertEquals(false, api_user());
249 * Test the api_source() function.
253 public function testApiSource()
255 $this->assertEquals('api', api_source());
259 * Test the api_source() function with a Twidere user agent.
263 public function testApiSourceWithTwidere()
265 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
266 $this->assertEquals('Twidere', api_source());
270 * Test the api_source() function with a GET parameter.
274 public function testApiSourceWithGet()
276 $_GET['source'] = 'source_name';
277 $this->assertEquals('source_name', api_source());
281 * Test the api_date() function.
285 public function testApiDate()
287 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
291 * Test the api_register_func() function.
295 public function testApiRegisterFunc()
307 $this->assertTrue($API['api_path']['auth']);
308 $this->assertEquals('method', $API['api_path']['method']);
309 $this->assertTrue(is_callable($API['api_path']['func']));
313 * Test the api_login() function without any login.
316 * @runInSeparateProcess
317 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
319 public function testApiLoginWithoutLogin()
321 api_login($this->app);
325 * Test the api_login() function with a bad login.
328 * @runInSeparateProcess
329 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
331 public function testApiLoginWithBadLogin()
333 $_SERVER['PHP_AUTH_USER'] = 'user@server';
334 api_login($this->app);
338 * Test the api_login() function with oAuth.
342 public function testApiLoginWithOauth()
344 $this->markTestIncomplete('Can we test this easily?');
348 * Test the api_login() function with authentication provided by an addon.
352 public function testApiLoginWithAddonAuth()
354 $this->markTestIncomplete('Can we test this easily?');
358 * Test the api_login() function with a correct login.
361 * @runInSeparateProcess
363 public function testApiLoginWithCorrectLogin()
365 $_SERVER['PHP_AUTH_USER'] = 'Test user';
366 $_SERVER['PHP_AUTH_PW'] = 'password';
367 api_login($this->app);
371 * Test the api_login() function with a remote user.
374 * @runInSeparateProcess
375 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
377 public function testApiLoginWithRemoteUser()
379 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
380 api_login($this->app);
384 * Test the api_check_method() function.
388 public function testApiCheckMethod()
390 $this->assertFalse(api_check_method('method'));
394 * Test the api_check_method() function with a correct method.
398 public function testApiCheckMethodWithCorrectMethod()
400 $_SERVER['REQUEST_METHOD'] = 'method';
401 $this->assertTrue(api_check_method('method'));
405 * Test the api_check_method() function with a wildcard.
409 public function testApiCheckMethodWithWildcard()
411 $this->assertTrue(api_check_method('*'));
415 * Test the api_call() function.
418 * @runInSeparateProcess
420 public function testApiCall()
424 'method' => 'method',
425 'func' => function () {
426 return ['data' => ['some_data']];
429 $_SERVER['REQUEST_METHOD'] = 'method';
430 $_GET['callback'] = 'callback_name';
432 $this->app->query_string = 'api_path';
434 'callback_name(["some_data"])',
440 * Test the api_call() function with the profiled enabled.
443 * @runInSeparateProcess
445 public function testApiCallWithProfiler()
449 'method' => 'method',
450 'func' => function () {
451 return ['data' => ['some_data']];
454 $_SERVER['REQUEST_METHOD'] = 'method';
455 $this->config->set('system', 'profiler', true);
456 $this->config->set('rendertime', 'callstack', true);
457 $this->app->callstack = [
458 'database' => ['some_function' => 200],
459 'database_write' => ['some_function' => 200],
460 'cache' => ['some_function' => 200],
461 'cache_write' => ['some_function' => 200],
462 'network' => ['some_function' => 200]
465 $this->app->query_string = 'api_path';
473 * Test the api_call() function without any result.
476 * @runInSeparateProcess
478 public function testApiCallWithNoResult()
482 'method' => 'method',
483 'func' => function () {
487 $_SERVER['REQUEST_METHOD'] = 'method';
489 $this->app->query_string = 'api_path';
491 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
497 * Test the api_call() function with an unimplemented API.
500 * @runInSeparateProcess
502 public function testApiCallWithUninplementedApi()
505 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
511 * Test the api_call() function with a JSON result.
514 * @runInSeparateProcess
516 public function testApiCallWithJson()
520 'method' => 'method',
521 'func' => function () {
522 return ['data' => ['some_data']];
525 $_SERVER['REQUEST_METHOD'] = 'method';
527 $this->app->query_string = 'api_path.json';
535 * Test the api_call() function with an XML result.
538 * @runInSeparateProcess
540 public function testApiCallWithXml()
544 'method' => 'method',
545 'func' => function () {
549 $_SERVER['REQUEST_METHOD'] = 'method';
551 $this->app->query_string = 'api_path.xml';
559 * Test the api_call() function with an RSS result.
562 * @runInSeparateProcess
564 public function testApiCallWithRss()
568 'method' => 'method',
569 'func' => function () {
573 $_SERVER['REQUEST_METHOD'] = 'method';
575 $this->app->query_string = 'api_path.rss';
577 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
584 * Test the api_call() function with an Atom result.
587 * @runInSeparateProcess
589 public function testApiCallWithAtom()
593 'method' => 'method',
594 'func' => function () {
598 $_SERVER['REQUEST_METHOD'] = 'method';
600 $this->app->query_string = 'api_path.atom';
602 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
609 * Test the api_call() function with an unallowed method.
612 * @runInSeparateProcess
614 public function testApiCallWithWrongMethod()
617 $API['api_path'] = ['method' => 'method'];
619 $this->app->query_string = 'api_path';
621 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
627 * Test the api_call() function with an unauthorized user.
630 * @runInSeparateProcess
632 public function testApiCallWithWrongAuth()
636 'method' => 'method',
639 $_SERVER['REQUEST_METHOD'] = 'method';
640 $_SESSION['authenticated'] = false;
642 $this->app->query_string = 'api_path';
644 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
650 * Test the api_error() function with a JSON result.
653 * @runInSeparateProcess
655 public function testApiErrorWithJson()
658 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
659 api_error('json', new HTTPException\OKException('error_message'))
664 * Test the api_error() function with an XML result.
667 * @runInSeparateProcess
669 public function testApiErrorWithXml()
672 '<?xml version="1.0"?>' . "\n" .
673 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
674 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
675 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
676 ' <error>error_message</error>' . "\n" .
677 ' <code>200 OK</code>' . "\n" .
678 ' <request/>' . "\n" .
680 api_error('xml', new HTTPException\OKException('error_message'))
685 * Test the api_error() function with an RSS result.
688 * @runInSeparateProcess
690 public function testApiErrorWithRss()
693 '<?xml version="1.0"?>' . "\n" .
694 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
695 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
696 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
697 ' <error>error_message</error>' . "\n" .
698 ' <code>200 OK</code>' . "\n" .
699 ' <request/>' . "\n" .
701 api_error('rss', new HTTPException\OKException('error_message'))
706 * Test the api_error() function with an Atom result.
709 * @runInSeparateProcess
711 public function testApiErrorWithAtom()
714 '<?xml version="1.0"?>' . "\n" .
715 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
716 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
717 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
718 ' <error>error_message</error>' . "\n" .
719 ' <code>200 OK</code>' . "\n" .
720 ' <request/>' . "\n" .
722 api_error('atom', new HTTPException\OKException('error_message'))
727 * Test the api_rss_extra() function.
731 public function testApiRssExtra()
733 $user_info = ['url' => 'user_url', 'lang' => 'en'];
734 $result = api_rss_extra($this->app, [], $user_info);
735 $this->assertEquals($user_info, $result['$user']);
736 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
737 $this->assertArrayHasKey('self', $result['$rss']);
738 $this->assertArrayHasKey('base', $result['$rss']);
739 $this->assertArrayHasKey('updated', $result['$rss']);
740 $this->assertArrayHasKey('atom_updated', $result['$rss']);
741 $this->assertArrayHasKey('language', $result['$rss']);
742 $this->assertArrayHasKey('logo', $result['$rss']);
746 * Test the api_rss_extra() function without any user info.
750 public function testApiRssExtraWithoutUserInfo()
752 $result = api_rss_extra($this->app, [], null);
753 $this->assertInternalType('array', $result['$user']);
754 $this->assertArrayHasKey('alternate', $result['$rss']);
755 $this->assertArrayHasKey('self', $result['$rss']);
756 $this->assertArrayHasKey('base', $result['$rss']);
757 $this->assertArrayHasKey('updated', $result['$rss']);
758 $this->assertArrayHasKey('atom_updated', $result['$rss']);
759 $this->assertArrayHasKey('language', $result['$rss']);
760 $this->assertArrayHasKey('logo', $result['$rss']);
764 * Test the api_unique_id_to_nurl() function.
768 public function testApiUniqueIdToNurl()
770 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
774 * Test the api_unique_id_to_nurl() function with a correct ID.
778 public function testApiUniqueIdToNurlWithCorrectId()
780 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
784 * Test the api_get_user() function.
788 public function testApiGetUser()
790 $user = api_get_user($this->app);
791 $this->assertSelfUser($user);
792 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
793 $this->assertEquals('6fdbe8', $user['profile_link_color']);
794 $this->assertEquals('ededed', $user['profile_background_color']);
798 * Test the api_get_user() function with a Frio schema.
802 public function testApiGetUserWithFrioSchema()
804 $pConfig = $this->dice->create(PConfiguration::class);
805 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
806 $user = api_get_user($this->app);
807 $this->assertSelfUser($user);
808 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
809 $this->assertEquals('6fdbe8', $user['profile_link_color']);
810 $this->assertEquals('ededed', $user['profile_background_color']);
814 * Test the api_get_user() function with a custom Frio schema.
818 public function testApiGetUserWithCustomFrioSchema()
820 $pConfig = $this->dice->create(PConfiguration::class);
821 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
822 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
823 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
824 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
825 $user = api_get_user($this->app);
826 $this->assertSelfUser($user);
827 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
828 $this->assertEquals('123456', $user['profile_link_color']);
829 $this->assertEquals('123456', $user['profile_background_color']);
833 * Test the api_get_user() function with an empty Frio schema.
837 public function testApiGetUserWithEmptyFrioSchema()
839 $pConfig = $this->dice->create(PConfiguration::class);
840 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
841 $user = api_get_user($this->app);
842 $this->assertSelfUser($user);
843 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
844 $this->assertEquals('6fdbe8', $user['profile_link_color']);
845 $this->assertEquals('ededed', $user['profile_background_color']);
849 * Test the api_get_user() function with an user that is not allowed to use the API.
852 * @runInSeparateProcess
854 public function testApiGetUserWithoutApiUser()
856 $_SERVER['PHP_AUTH_USER'] = 'Test user';
857 $_SERVER['PHP_AUTH_PW'] = 'password';
858 $_SESSION['allow_api'] = false;
859 $this->assertFalse(api_get_user($this->app));
863 * Test the api_get_user() function with an user ID in a GET parameter.
867 public function testApiGetUserWithGetId()
869 $_GET['user_id'] = $this->otherUser['id'];
870 $this->assertOtherUser(api_get_user($this->app));
874 * Test the api_get_user() function with a wrong user ID in a GET parameter.
877 * @expectedException Friendica\Network\HTTPException\BadRequestException
879 public function testApiGetUserWithWrongGetId()
881 $_GET['user_id'] = $this->wrongUserId;
882 $this->assertOtherUser(api_get_user($this->app));
886 * Test the api_get_user() function with an user name in a GET parameter.
890 public function testApiGetUserWithGetName()
892 $_GET['screen_name'] = $this->selfUser['nick'];
893 $this->assertSelfUser(api_get_user($this->app));
897 * Test the api_get_user() function with a profile URL in a GET parameter.
901 public function testApiGetUserWithGetUrl()
903 $_GET['profileurl'] = $this->selfUser['nurl'];
904 $this->assertSelfUser(api_get_user($this->app));
908 * Test the api_get_user() function with an user ID in the API path.
912 public function testApiGetUserWithNumericCalledApi()
915 $called_api = ['api_path'];
916 $this->app->argv[1] = $this->otherUser['id'] . '.json';
917 $this->assertOtherUser(api_get_user($this->app));
921 * Test the api_get_user() function with the $called_api global variable.
925 public function testApiGetUserWithCalledApi()
928 $called_api = ['api', 'api_path'];
929 $this->assertSelfUser(api_get_user($this->app));
933 * Test the api_get_user() function with a valid user.
937 public function testApiGetUserWithCorrectUser()
939 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
943 * Test the api_get_user() function with a wrong user ID.
946 * @expectedException Friendica\Network\HTTPException\BadRequestException
948 public function testApiGetUserWithWrongUser()
950 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
954 * Test the api_get_user() function with a 0 user ID.
958 public function testApiGetUserWithZeroUser()
960 $this->assertSelfUser(api_get_user($this->app, 0));
964 * Test the api_item_get_user() function.
968 public function testApiItemGetUser()
970 $users = api_item_get_user($this->app, []);
971 $this->assertSelfUser($users[0]);
975 * Test the api_item_get_user() function with a different item parent.
979 public function testApiItemGetUserWithDifferentParent()
981 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
982 $this->assertSelfUser($users[0]);
983 $this->assertEquals($users[0], $users[1]);
987 * Test the api_walk_recursive() function.
991 public function testApiWalkRecursive()
999 // Should we test this with a callback that actually does something?
1007 * Test the api_walk_recursive() function with an array.
1011 public function testApiWalkRecursiveWithArray()
1013 $array = [['item1'], ['item2']];
1014 $this->assertEquals(
1019 // Should we test this with a callback that actually does something?
1027 * Test the api_reformat_xml() function.
1031 public function testApiReformatXml()
1035 $this->assertTrue(api_reformat_xml($item, $key));
1036 $this->assertEquals('true', $item);
1040 * Test the api_reformat_xml() function with a statusnet_api key.
1044 public function testApiReformatXmlWithStatusnetKey()
1047 $key = 'statusnet_api';
1048 $this->assertTrue(api_reformat_xml($item, $key));
1049 $this->assertEquals('statusnet:api', $key);
1053 * Test the api_reformat_xml() function with a friendica_api key.
1057 public function testApiReformatXmlWithFriendicaKey()
1060 $key = 'friendica_api';
1061 $this->assertTrue(api_reformat_xml($item, $key));
1062 $this->assertEquals('friendica:api', $key);
1066 * Test the api_create_xml() function.
1070 public function testApiCreateXml()
1072 $this->assertEquals(
1073 '<?xml version="1.0"?>' . "\n" .
1074 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1075 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1076 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1077 ' <data>some_data</data>' . "\n" .
1078 '</root_element>' . "\n",
1079 api_create_xml(['data' => ['some_data']], 'root_element')
1084 * Test the api_create_xml() function without any XML namespace.
1088 public function testApiCreateXmlWithoutNamespaces()
1090 $this->assertEquals(
1091 '<?xml version="1.0"?>' . "\n" .
1093 ' <data>some_data</data>' . "\n" .
1095 api_create_xml(['data' => ['some_data']], 'ok')
1100 * Test the api_format_data() function.
1104 public function testApiFormatData()
1106 $data = ['some_data'];
1107 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1111 * Test the api_format_data() function with an XML result.
1115 public function testApiFormatDataWithXml()
1117 $this->assertEquals(
1118 '<?xml version="1.0"?>' . "\n" .
1119 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1120 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1121 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1122 ' <data>some_data</data>' . "\n" .
1123 '</root_element>' . "\n",
1124 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1129 * Test the api_account_verify_credentials() function.
1133 public function testApiAccountVerifyCredentials()
1135 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1139 * Test the api_account_verify_credentials() function without an authenticated user.
1142 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1144 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1146 $_SESSION['authenticated'] = false;
1147 api_account_verify_credentials('json');
1151 * Test the requestdata() function.
1155 public function testRequestdata()
1157 $this->assertNull(requestdata('variable_name'));
1161 * Test the requestdata() function with a POST parameter.
1165 public function testRequestdataWithPost()
1167 $_POST['variable_name'] = 'variable_value';
1168 $this->assertEquals('variable_value', requestdata('variable_name'));
1172 * Test the requestdata() function with a GET parameter.
1176 public function testRequestdataWithGet()
1178 $_GET['variable_name'] = 'variable_value';
1179 $this->assertEquals('variable_value', requestdata('variable_name'));
1183 * Test the api_statuses_mediap() function.
1187 public function testApiStatusesMediap()
1189 $this->app->argc = 2;
1197 'tmp_name' => $this->getTempImage(),
1198 'name' => 'spacer.png',
1199 'type' => 'image/png'
1202 $_GET['status'] = '<b>Status content</b>';
1204 $result = api_statuses_mediap('json');
1205 $this->assertStatus($result['status']);
1209 * Test the api_statuses_mediap() function without an authenticated user.
1212 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1214 public function testApiStatusesMediapWithoutAuthenticatedUser()
1216 $_SESSION['authenticated'] = false;
1217 api_statuses_mediap('json');
1221 * Test the api_statuses_update() function.
1225 public function testApiStatusesUpdate()
1227 $_GET['status'] = 'Status content #friendica';
1228 $_GET['in_reply_to_status_id'] = -1;
1237 'tmp_name' => $this->getTempImage(),
1238 'name' => 'spacer.png',
1239 'type' => 'image/png'
1243 $result = api_statuses_update('json');
1244 $this->assertStatus($result['status']);
1248 * Test the api_statuses_update() function with an HTML status.
1252 public function testApiStatusesUpdateWithHtml()
1254 $_GET['htmlstatus'] = '<b>Status content</b>';
1256 $result = api_statuses_update('json');
1257 $this->assertStatus($result['status']);
1261 * Test the api_statuses_update() function without an authenticated user.
1264 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1266 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1268 $_SESSION['authenticated'] = false;
1269 api_statuses_update('json');
1273 * Test the api_statuses_update() function with a parent status.
1277 public function testApiStatusesUpdateWithParent()
1279 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1283 * Test the api_statuses_update() function with a media_ids parameter.
1287 public function testApiStatusesUpdateWithMediaIds()
1289 $this->markTestIncomplete();
1293 * Test the api_statuses_update() function with the throttle limit reached.
1297 public function testApiStatusesUpdateWithDayThrottleReached()
1299 $this->markTestIncomplete();
1303 * Test the api_media_upload() function.
1306 * @expectedException Friendica\Network\HTTPException\BadRequestException
1308 public function testApiMediaUpload()
1314 * Test the api_media_upload() function without an authenticated user.
1317 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1319 public function testApiMediaUploadWithoutAuthenticatedUser()
1321 $_SESSION['authenticated'] = false;
1326 * Test the api_media_upload() function with an invalid uploaded media.
1329 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1331 public function testApiMediaUploadWithMedia()
1336 'tmp_name' => 'tmp_name'
1343 * Test the api_media_upload() function with an valid uploaded media.
1347 public function testApiMediaUploadWithValidMedia()
1355 'tmp_name' => $this->getTempImage(),
1356 'name' => 'spacer.png',
1357 'type' => 'image/png'
1363 $result = api_media_upload();
1364 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1365 $this->assertEquals(1, $result['media']['image']['w']);
1366 $this->assertEquals(1, $result['media']['image']['h']);
1367 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1371 * Test the api_status_show() function.
1373 public function testApiStatusShowWithJson()
1375 $result = api_status_show('json', 1);
1376 $this->assertStatus($result['status']);
1380 * Test the api_status_show() function with an XML result.
1382 public function testApiStatusShowWithXml()
1384 $result = api_status_show('xml', 1);
1385 $this->assertXml($result, 'statuses');
1389 * Test the api_get_last_status() function
1391 public function testApiGetLastStatus()
1393 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1395 $this->assertNotNull($item);
1399 * Test the api_users_show() function.
1403 public function testApiUsersShow()
1405 $result = api_users_show('json');
1406 // We can't use assertSelfUser() here because the user object is missing some properties.
1407 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1408 $this->assertEquals('DFRN', $result['user']['location']);
1409 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1410 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1411 $this->assertEquals('dfrn', $result['user']['network']);
1412 $this->assertTrue($result['user']['verified']);
1416 * Test the api_users_show() function with an XML result.
1420 public function testApiUsersShowWithXml()
1422 $result = api_users_show('xml');
1423 $this->assertXml($result, 'statuses');
1427 * Test the api_users_search() function.
1431 public function testApiUsersSearch()
1433 $_GET['q'] = 'othercontact';
1434 $result = api_users_search('json');
1435 $this->assertOtherUser($result['users'][0]);
1439 * Test the api_users_search() function with an XML result.
1443 public function testApiUsersSearchWithXml()
1445 $_GET['q'] = 'othercontact';
1446 $result = api_users_search('xml');
1447 $this->assertXml($result, 'users');
1451 * Test the api_users_search() function without a GET q parameter.
1454 * @expectedException Friendica\Network\HTTPException\BadRequestException
1456 public function testApiUsersSearchWithoutQuery()
1458 api_users_search('json');
1462 * Test the api_users_lookup() function.
1465 * @expectedException Friendica\Network\HTTPException\NotFoundException
1467 public function testApiUsersLookup()
1469 api_users_lookup('json');
1473 * Test the api_users_lookup() function with an user ID.
1477 public function testApiUsersLookupWithUserId()
1479 $_REQUEST['user_id'] = $this->otherUser['id'];
1480 $result = api_users_lookup('json');
1481 $this->assertOtherUser($result['users'][0]);
1485 * Test the api_search() function.
1489 public function testApiSearch()
1491 $_REQUEST['q'] = 'reply';
1492 $_REQUEST['max_id'] = 10;
1493 $result = api_search('json');
1494 foreach ($result['status'] as $status) {
1495 $this->assertStatus($status);
1496 $this->assertContains('reply', $status['text'], null, true);
1501 * Test the api_search() function a count parameter.
1505 public function testApiSearchWithCount()
1507 $_REQUEST['q'] = 'reply';
1508 $_REQUEST['count'] = 20;
1509 $result = api_search('json');
1510 foreach ($result['status'] as $status) {
1511 $this->assertStatus($status);
1512 $this->assertContains('reply', $status['text'], null, true);
1517 * Test the api_search() function with an rpp parameter.
1521 public function testApiSearchWithRpp()
1523 $_REQUEST['q'] = 'reply';
1524 $_REQUEST['rpp'] = 20;
1525 $result = api_search('json');
1526 foreach ($result['status'] as $status) {
1527 $this->assertStatus($status);
1528 $this->assertContains('reply', $status['text'], null, true);
1533 * Test the api_search() function with an q parameter contains hashtag.
1537 public function testApiSearchWithHashtag()
1539 $_REQUEST['q'] = '%23friendica';
1540 $result = api_search('json');
1541 foreach ($result['status'] as $status) {
1542 $this->assertStatus($status);
1543 $this->assertContains('#friendica', $status['text'], null, true);
1548 * Test the api_search() function with an exclude_replies parameter.
1552 public function testApiSearchWithExcludeReplies()
1554 $_REQUEST['max_id'] = 10;
1555 $_REQUEST['exclude_replies'] = true;
1556 $_REQUEST['q'] = 'friendica';
1557 $result = api_search('json');
1558 foreach ($result['status'] as $status) {
1559 $this->assertStatus($status);
1564 * Test the api_search() function without an authenticated user.
1567 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1569 public function testApiSearchWithUnallowedUser()
1571 $_SESSION['allow_api'] = false;
1572 $_GET['screen_name'] = $this->selfUser['nick'];
1577 * Test the api_search() function without any GET query parameter.
1580 * @expectedException Friendica\Network\HTTPException\BadRequestException
1582 public function testApiSearchWithoutQuery()
1588 * Test the api_statuses_home_timeline() function.
1592 public function testApiStatusesHomeTimeline()
1594 $_REQUEST['max_id'] = 10;
1595 $_REQUEST['exclude_replies'] = true;
1596 $_REQUEST['conversation_id'] = 1;
1597 $result = api_statuses_home_timeline('json');
1598 $this->assertNotEmpty($result['status']);
1599 foreach ($result['status'] as $status) {
1600 $this->assertStatus($status);
1605 * Test the api_statuses_home_timeline() function with a negative page parameter.
1609 public function testApiStatusesHomeTimelineWithNegativePage()
1611 $_REQUEST['page'] = -2;
1612 $result = api_statuses_home_timeline('json');
1613 $this->assertNotEmpty($result['status']);
1614 foreach ($result['status'] as $status) {
1615 $this->assertStatus($status);
1620 * Test the api_statuses_home_timeline() with an unallowed user.
1623 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1625 public function testApiStatusesHomeTimelineWithUnallowedUser()
1627 $_SESSION['allow_api'] = false;
1628 $_GET['screen_name'] = $this->selfUser['nick'];
1629 api_statuses_home_timeline('json');
1633 * Test the api_statuses_home_timeline() function with an RSS result.
1637 public function testApiStatusesHomeTimelineWithRss()
1639 $result = api_statuses_home_timeline('rss');
1640 $this->assertXml($result, 'statuses');
1644 * Test the api_statuses_public_timeline() function.
1648 public function testApiStatusesPublicTimeline()
1650 $_REQUEST['max_id'] = 10;
1651 $_REQUEST['conversation_id'] = 1;
1652 $result = api_statuses_public_timeline('json');
1653 $this->assertNotEmpty($result['status']);
1654 foreach ($result['status'] as $status) {
1655 $this->assertStatus($status);
1660 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1664 public function testApiStatusesPublicTimelineWithExcludeReplies()
1666 $_REQUEST['max_id'] = 10;
1667 $_REQUEST['exclude_replies'] = true;
1668 $result = api_statuses_public_timeline('json');
1669 $this->assertNotEmpty($result['status']);
1670 foreach ($result['status'] as $status) {
1671 $this->assertStatus($status);
1676 * Test the api_statuses_public_timeline() function with a negative page parameter.
1680 public function testApiStatusesPublicTimelineWithNegativePage()
1682 $_REQUEST['page'] = -2;
1683 $result = api_statuses_public_timeline('json');
1684 $this->assertNotEmpty($result['status']);
1685 foreach ($result['status'] as $status) {
1686 $this->assertStatus($status);
1691 * Test the api_statuses_public_timeline() function with an unallowed user.
1694 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1696 public function testApiStatusesPublicTimelineWithUnallowedUser()
1698 $_SESSION['allow_api'] = false;
1699 $_GET['screen_name'] = $this->selfUser['nick'];
1700 api_statuses_public_timeline('json');
1704 * Test the api_statuses_public_timeline() function with an RSS result.
1708 public function testApiStatusesPublicTimelineWithRss()
1710 $result = api_statuses_public_timeline('rss');
1711 $this->assertXml($result, 'statuses');
1715 * Test the api_statuses_networkpublic_timeline() function.
1719 public function testApiStatusesNetworkpublicTimeline()
1721 $_REQUEST['max_id'] = 10;
1722 $result = api_statuses_networkpublic_timeline('json');
1723 $this->assertNotEmpty($result['status']);
1724 foreach ($result['status'] as $status) {
1725 $this->assertStatus($status);
1730 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1734 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1736 $_REQUEST['page'] = -2;
1737 $result = api_statuses_networkpublic_timeline('json');
1738 $this->assertNotEmpty($result['status']);
1739 foreach ($result['status'] as $status) {
1740 $this->assertStatus($status);
1745 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1748 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1750 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1752 $_SESSION['allow_api'] = false;
1753 $_GET['screen_name'] = $this->selfUser['nick'];
1754 api_statuses_networkpublic_timeline('json');
1758 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1762 public function testApiStatusesNetworkpublicTimelineWithRss()
1764 $result = api_statuses_networkpublic_timeline('rss');
1765 $this->assertXml($result, 'statuses');
1769 * Test the api_statuses_show() function.
1772 * @expectedException Friendica\Network\HTTPException\BadRequestException
1774 public function testApiStatusesShow()
1776 api_statuses_show('json');
1780 * Test the api_statuses_show() function with an ID.
1784 public function testApiStatusesShowWithId()
1786 $this->app->argv[3] = 1;
1787 $result = api_statuses_show('json');
1788 $this->assertStatus($result['status']);
1792 * Test the api_statuses_show() function with the conversation parameter.
1796 public function testApiStatusesShowWithConversation()
1798 $this->app->argv[3] = 1;
1799 $_REQUEST['conversation'] = 1;
1800 $result = api_statuses_show('json');
1801 $this->assertNotEmpty($result['status']);
1802 foreach ($result['status'] as $status) {
1803 $this->assertStatus($status);
1808 * Test the api_statuses_show() function with an unallowed user.
1811 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1813 public function testApiStatusesShowWithUnallowedUser()
1815 $_SESSION['allow_api'] = false;
1816 $_GET['screen_name'] = $this->selfUser['nick'];
1817 api_statuses_show('json');
1821 * Test the api_conversation_show() function.
1824 * @expectedException Friendica\Network\HTTPException\BadRequestException
1826 public function testApiConversationShow()
1828 api_conversation_show('json');
1832 * Test the api_conversation_show() function with an ID.
1836 public function testApiConversationShowWithId()
1838 $this->app->argv[3] = 1;
1839 $_REQUEST['max_id'] = 10;
1840 $_REQUEST['page'] = -2;
1841 $result = api_conversation_show('json');
1842 $this->assertNotEmpty($result['status']);
1843 foreach ($result['status'] as $status) {
1844 $this->assertStatus($status);
1849 * Test the api_conversation_show() function with an unallowed user.
1852 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1854 public function testApiConversationShowWithUnallowedUser()
1856 $_SESSION['allow_api'] = false;
1857 $_GET['screen_name'] = $this->selfUser['nick'];
1858 api_conversation_show('json');
1862 * Test the api_statuses_repeat() function.
1865 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1867 public function testApiStatusesRepeat()
1869 api_statuses_repeat('json');
1873 * Test the api_statuses_repeat() function without an authenticated user.
1876 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1878 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1880 $_SESSION['authenticated'] = false;
1881 api_statuses_repeat('json');
1885 * Test the api_statuses_repeat() function with an ID.
1889 public function testApiStatusesRepeatWithId()
1891 $this->app->argv[3] = 1;
1892 $result = api_statuses_repeat('json');
1893 $this->assertStatus($result['status']);
1895 // Also test with a shared status
1896 $this->app->argv[3] = 5;
1897 $result = api_statuses_repeat('json');
1898 $this->assertStatus($result['status']);
1902 * Test the api_statuses_destroy() function.
1905 * @expectedException Friendica\Network\HTTPException\BadRequestException
1907 public function testApiStatusesDestroy()
1909 api_statuses_destroy('json');
1913 * Test the api_statuses_destroy() function without an authenticated user.
1916 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1918 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1920 $_SESSION['authenticated'] = false;
1921 api_statuses_destroy('json');
1925 * Test the api_statuses_destroy() function with an ID.
1929 public function testApiStatusesDestroyWithId()
1931 $this->app->argv[3] = 1;
1932 $result = api_statuses_destroy('json');
1933 $this->assertStatus($result['status']);
1937 * Test the api_statuses_mentions() function.
1941 public function testApiStatusesMentions()
1943 $this->app->user = ['nickname' => $this->selfUser['nick']];
1944 $_REQUEST['max_id'] = 10;
1945 $result = api_statuses_mentions('json');
1946 $this->assertEmpty($result['status']);
1947 // We should test with mentions in the database.
1951 * Test the api_statuses_mentions() function with a negative page parameter.
1955 public function testApiStatusesMentionsWithNegativePage()
1957 $_REQUEST['page'] = -2;
1958 $result = api_statuses_mentions('json');
1959 $this->assertEmpty($result['status']);
1963 * Test the api_statuses_mentions() function with an unallowed user.
1966 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1968 public function testApiStatusesMentionsWithUnallowedUser()
1970 $_SESSION['allow_api'] = false;
1971 $_GET['screen_name'] = $this->selfUser['nick'];
1972 api_statuses_mentions('json');
1976 * Test the api_statuses_mentions() function with an RSS result.
1980 public function testApiStatusesMentionsWithRss()
1982 $result = api_statuses_mentions('rss');
1983 $this->assertXml($result, 'statuses');
1987 * Test the api_statuses_user_timeline() function.
1991 public function testApiStatusesUserTimeline()
1993 $_REQUEST['max_id'] = 10;
1994 $_REQUEST['exclude_replies'] = true;
1995 $_REQUEST['conversation_id'] = 1;
1996 $result = api_statuses_user_timeline('json');
1997 $this->assertNotEmpty($result['status']);
1998 foreach ($result['status'] as $status) {
1999 $this->assertStatus($status);
2004 * Test the api_statuses_user_timeline() function with a negative page parameter.
2008 public function testApiStatusesUserTimelineWithNegativePage()
2010 $_REQUEST['page'] = -2;
2011 $result = api_statuses_user_timeline('json');
2012 $this->assertNotEmpty($result['status']);
2013 foreach ($result['status'] as $status) {
2014 $this->assertStatus($status);
2019 * Test the api_statuses_user_timeline() function with an RSS result.
2023 public function testApiStatusesUserTimelineWithRss()
2025 $result = api_statuses_user_timeline('rss');
2026 $this->assertXml($result, 'statuses');
2030 * Test the api_statuses_user_timeline() function with an unallowed user.
2033 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2035 public function testApiStatusesUserTimelineWithUnallowedUser()
2037 $_SESSION['allow_api'] = false;
2038 $_GET['screen_name'] = $this->selfUser['nick'];
2039 api_statuses_user_timeline('json');
2043 * Test the api_favorites_create_destroy() function.
2046 * @expectedException Friendica\Network\HTTPException\BadRequestException
2048 public function testApiFavoritesCreateDestroy()
2050 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2051 $this->app->argc = count($this->app->argv);
2052 api_favorites_create_destroy('json');
2056 * Test the api_favorites_create_destroy() function with an invalid ID.
2059 * @expectedException Friendica\Network\HTTPException\BadRequestException
2061 public function testApiFavoritesCreateDestroyWithInvalidId()
2063 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2064 $this->app->argc = count($this->app->argv);
2065 api_favorites_create_destroy('json');
2069 * Test the api_favorites_create_destroy() function with an invalid action.
2072 * @expectedException Friendica\Network\HTTPException\BadRequestException
2074 public function testApiFavoritesCreateDestroyWithInvalidAction()
2076 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2077 $this->app->argc = count($this->app->argv);
2078 $_REQUEST['id'] = 1;
2079 api_favorites_create_destroy('json');
2083 * Test the api_favorites_create_destroy() function with the create action.
2087 public function testApiFavoritesCreateDestroyWithCreateAction()
2089 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2090 $this->app->argc = count($this->app->argv);
2091 $_REQUEST['id'] = 3;
2092 $result = api_favorites_create_destroy('json');
2093 $this->assertStatus($result['status']);
2097 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2101 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2103 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2104 $this->app->argc = count($this->app->argv);
2105 $_REQUEST['id'] = 3;
2106 $result = api_favorites_create_destroy('rss');
2107 $this->assertXml($result, 'status');
2111 * Test the api_favorites_create_destroy() function with the destroy action.
2115 public function testApiFavoritesCreateDestroyWithDestroyAction()
2117 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2118 $this->app->argc = count($this->app->argv);
2119 $_REQUEST['id'] = 3;
2120 $result = api_favorites_create_destroy('json');
2121 $this->assertStatus($result['status']);
2125 * Test the api_favorites_create_destroy() function without an authenticated user.
2128 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2130 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2132 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2133 $this->app->argc = count($this->app->argv);
2134 $_SESSION['authenticated'] = false;
2135 api_favorites_create_destroy('json');
2139 * Test the api_favorites() function.
2143 public function testApiFavorites()
2145 $_REQUEST['page'] = -1;
2146 $_REQUEST['max_id'] = 10;
2147 $result = api_favorites('json');
2148 foreach ($result['status'] as $status) {
2149 $this->assertStatus($status);
2154 * Test the api_favorites() function with an RSS result.
2158 public function testApiFavoritesWithRss()
2160 $result = api_favorites('rss');
2161 $this->assertXml($result, 'statuses');
2165 * Test the api_favorites() function with an unallowed user.
2168 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2170 public function testApiFavoritesWithUnallowedUser()
2172 $_SESSION['allow_api'] = false;
2173 $_GET['screen_name'] = $this->selfUser['nick'];
2174 api_favorites('json');
2178 * Test the api_format_messages() function.
2182 public function testApiFormatMessages()
2184 $result = api_format_messages(
2185 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2186 ['id' => 2, 'screen_name' => 'recipient_name'],
2187 ['id' => 3, 'screen_name' => 'sender_name']
2189 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2190 $this->assertEquals(1, $result['id']);
2191 $this->assertEquals(2, $result['recipient_id']);
2192 $this->assertEquals(3, $result['sender_id']);
2193 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2194 $this->assertEquals('sender_name', $result['sender_screen_name']);
2198 * Test the api_format_messages() function with HTML.
2202 public function testApiFormatMessagesWithHtmlText()
2204 $_GET['getText'] = 'html';
2205 $result = api_format_messages(
2206 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2207 ['id' => 2, 'screen_name' => 'recipient_name'],
2208 ['id' => 3, 'screen_name' => 'sender_name']
2210 $this->assertEquals('item_title', $result['title']);
2211 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2215 * Test the api_format_messages() function with plain text.
2219 public function testApiFormatMessagesWithPlainText()
2221 $_GET['getText'] = 'plain';
2222 $result = api_format_messages(
2223 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2224 ['id' => 2, 'screen_name' => 'recipient_name'],
2225 ['id' => 3, 'screen_name' => 'sender_name']
2227 $this->assertEquals('item_title', $result['title']);
2228 $this->assertEquals('item_body', $result['text']);
2232 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2236 public function testApiFormatMessagesWithoutUserObjects()
2238 $_GET['getUserObjects'] = 'false';
2239 $result = api_format_messages(
2240 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2241 ['id' => 2, 'screen_name' => 'recipient_name'],
2242 ['id' => 3, 'screen_name' => 'sender_name']
2244 $this->assertTrue(!isset($result['sender']));
2245 $this->assertTrue(!isset($result['recipient']));
2249 * Test the api_convert_item() function.
2253 public function testApiConvertItem()
2255 $result = api_convert_item(
2257 'network' => 'feed',
2258 'title' => 'item_title',
2259 // We need a long string to test that it is correctly cut
2260 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2261 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2262 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2263 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2264 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2265 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2266 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2267 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2268 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2269 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2270 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2271 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2272 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2273 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2274 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2275 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2276 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2277 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2278 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2279 'repellat officia illum quos impedit quam iste esse unde qui ' .
2280 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2281 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2282 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2283 'plink' => 'item_plink'
2286 $this->assertStringStartsWith('item_title', $result['text']);
2287 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2291 * Test the api_convert_item() function with an empty item body.
2295 public function testApiConvertItemWithoutBody()
2297 $result = api_convert_item(
2299 'network' => 'feed',
2300 'title' => 'item_title',
2302 'plink' => 'item_plink'
2305 $this->assertEquals('item_title', $result['text']);
2306 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2310 * Test the api_convert_item() function with the title in the body.
2314 public function testApiConvertItemWithTitleInBody()
2316 $result = api_convert_item(
2318 'title' => 'item_title',
2319 'body' => 'item_title item_body'
2322 $this->assertEquals('item_title item_body', $result['text']);
2323 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2327 * Test the api_get_attachments() function.
2331 public function testApiGetAttachments()
2334 $this->assertEmpty(api_get_attachments($body));
2338 * Test the api_get_attachments() function with an img tag.
2342 public function testApiGetAttachmentsWithImage()
2344 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2345 $this->assertInternalType('array', api_get_attachments($body));
2349 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2353 public function testApiGetAttachmentsWithImageAndAndStatus()
2355 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2356 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2357 $this->assertInternalType('array', api_get_attachments($body));
2361 * Test the api_get_entitities() function.
2365 public function testApiGetEntitities()
2368 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2372 * Test the api_get_entitities() function with the include_entities parameter.
2376 public function testApiGetEntititiesWithIncludeEntities()
2378 $_REQUEST['include_entities'] = 'true';
2380 $result = api_get_entitities($text, 'bbcode');
2381 $this->assertInternalType('array', $result['hashtags']);
2382 $this->assertInternalType('array', $result['symbols']);
2383 $this->assertInternalType('array', $result['urls']);
2384 $this->assertInternalType('array', $result['user_mentions']);
2388 * Test the api_format_items_embeded_images() function.
2392 public function testApiFormatItemsEmbededImages()
2394 $this->assertEquals(
2395 'text ' . System::baseUrl() . '/display/item_guid',
2396 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2401 * Test the api_contactlink_to_array() function.
2405 public function testApiContactlinkToArray()
2407 $this->assertEquals(
2412 api_contactlink_to_array('text')
2417 * Test the api_contactlink_to_array() function with an URL.
2421 public function testApiContactlinkToArrayWithUrl()
2423 $this->assertEquals(
2425 'name' => ['link_text'],
2428 api_contactlink_to_array('text <a href="url">link_text</a>')
2433 * Test the api_format_items_activities() function.
2437 public function testApiFormatItemsActivities()
2439 $item = ['uid' => 0, 'uri' => ''];
2440 $result = api_format_items_activities($item);
2441 $this->assertArrayHasKey('like', $result);
2442 $this->assertArrayHasKey('dislike', $result);
2443 $this->assertArrayHasKey('attendyes', $result);
2444 $this->assertArrayHasKey('attendno', $result);
2445 $this->assertArrayHasKey('attendmaybe', $result);
2449 * Test the api_format_items_activities() function with an XML result.
2453 public function testApiFormatItemsActivitiesWithXml()
2455 $item = ['uid' => 0, 'uri' => ''];
2456 $result = api_format_items_activities($item, 'xml');
2457 $this->assertArrayHasKey('friendica:like', $result);
2458 $this->assertArrayHasKey('friendica:dislike', $result);
2459 $this->assertArrayHasKey('friendica:attendyes', $result);
2460 $this->assertArrayHasKey('friendica:attendno', $result);
2461 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2465 * Test the api_format_items_profiles() function.
2469 public function testApiFormatItemsProfiles()
2472 'id' => 'profile_id',
2473 'profile-name' => 'profile_name',
2474 'is-default' => true,
2475 'hide-friends' => true,
2476 'photo' => 'profile_photo',
2477 'thumb' => 'profile_thumb',
2479 'net-publish' => true,
2480 'pdesc' => 'description',
2481 'dob' => 'date_of_birth',
2482 'address' => 'address',
2483 'locality' => 'city',
2484 'region' => 'region',
2485 'postal-code' => 'postal_code',
2486 'country-name' => 'country',
2487 'hometown' => 'hometown',
2488 'gender' => 'gender',
2489 'marital' => 'marital',
2490 'with' => 'marital_with',
2491 'howlong' => 'marital_since',
2492 'sexual' => 'sexual',
2493 'politic' => 'politic',
2494 'religion' => 'religion',
2495 'pub_keywords' => 'public_keywords',
2496 'prv_keywords' => 'private_keywords',
2499 'dislikes' => 'dislikes',
2505 'interest' => 'interest',
2506 'romance' => 'romance',
2508 'education' => 'education',
2509 'contact' => 'social_networks',
2510 'homepage' => 'homepage'
2512 $result = api_format_items_profiles($profile_row);
2513 $this->assertEquals(
2515 'profile_id' => 'profile_id',
2516 'profile_name' => 'profile_name',
2517 'is_default' => true,
2518 'hide_friends' => true,
2519 'profile_photo' => 'profile_photo',
2520 'profile_thumb' => 'profile_thumb',
2522 'net_publish' => true,
2523 'description' => 'description',
2524 'date_of_birth' => 'date_of_birth',
2525 'address' => 'address',
2527 'region' => 'region',
2528 'postal_code' => 'postal_code',
2529 'country' => 'country',
2530 'hometown' => 'hometown',
2531 'gender' => 'gender',
2532 'marital' => 'marital',
2533 'marital_with' => 'marital_with',
2534 'marital_since' => 'marital_since',
2535 'sexual' => 'sexual',
2536 'politic' => 'politic',
2537 'religion' => 'religion',
2538 'public_keywords' => 'public_keywords',
2539 'private_keywords' => 'private_keywords',
2542 'dislikes' => 'dislikes',
2548 'interest' => 'interest',
2549 'romance' => 'romance',
2551 'education' => 'education',
2552 'social_networks' => 'social_networks',
2553 'homepage' => 'homepage',
2561 * Test the api_format_items() function.
2565 public function testApiFormatItems()
2569 'item_network' => 'item_network',
2575 'author-network' => Protocol::DFRN,
2576 'author-link' => 'http://localhost/profile/othercontact',
2580 $result = api_format_items($items, ['id' => 0], true);
2581 foreach ($result as $status) {
2582 $this->assertStatus($status);
2587 * Test the api_format_items() function with an XML result.
2591 public function testApiFormatItemsWithXml()
2599 'author-network' => Protocol::DFRN,
2600 'author-link' => 'http://localhost/profile/othercontact',
2604 $result = api_format_items($items, ['id' => 0], true, 'xml');
2605 foreach ($result as $status) {
2606 $this->assertStatus($status);
2611 * Test the api_format_items() function.
2615 public function testApiAccountRateLimitStatus()
2617 $result = api_account_rate_limit_status('json');
2618 $this->assertEquals(150, $result['hash']['remaining_hits']);
2619 $this->assertEquals(150, $result['hash']['hourly_limit']);
2620 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2624 * Test the api_format_items() function with an XML result.
2628 public function testApiAccountRateLimitStatusWithXml()
2630 $result = api_account_rate_limit_status('xml');
2631 $this->assertXml($result, 'hash');
2635 * Test the api_help_test() function.
2639 public function testApiHelpTest()
2641 $result = api_help_test('json');
2642 $this->assertEquals(['ok' => 'ok'], $result);
2646 * Test the api_help_test() function with an XML result.
2650 public function testApiHelpTestWithXml()
2652 $result = api_help_test('xml');
2653 $this->assertXml($result, 'ok');
2657 * Test the api_lists_list() function.
2661 public function testApiListsList()
2663 $result = api_lists_list('json');
2664 $this->assertEquals(['lists_list' => []], $result);
2668 * Test the api_lists_ownerships() function.
2672 public function testApiListsOwnerships()
2674 $result = api_lists_ownerships('json');
2675 foreach ($result['lists']['lists'] as $list) {
2676 $this->assertList($list);
2681 * Test the api_lists_ownerships() function without an authenticated user.
2684 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2686 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2688 $_SESSION['authenticated'] = false;
2689 api_lists_ownerships('json');
2693 * Test the api_lists_statuses() function.
2695 * @expectedException Friendica\Network\HTTPException\BadRequestException
2698 public function testApiListsStatuses()
2700 api_lists_statuses('json');
2704 * Test the api_lists_statuses() function with a list ID.
2708 public function testApiListsStatusesWithListId()
2710 $_REQUEST['list_id'] = 1;
2711 $_REQUEST['page'] = -1;
2712 $_REQUEST['max_id'] = 10;
2713 $result = api_lists_statuses('json');
2714 foreach ($result['status'] as $status) {
2715 $this->assertStatus($status);
2720 * Test the api_lists_statuses() function with a list ID and a RSS result.
2724 public function testApiListsStatusesWithListIdAndRss()
2726 $_REQUEST['list_id'] = 1;
2727 $result = api_lists_statuses('rss');
2728 $this->assertXml($result, 'statuses');
2732 * Test the api_lists_statuses() function with an unallowed user.
2735 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2737 public function testApiListsStatusesWithUnallowedUser()
2739 $_SESSION['allow_api'] = false;
2740 $_GET['screen_name'] = $this->selfUser['nick'];
2741 api_lists_statuses('json');
2745 * Test the api_statuses_f() function.
2749 public function testApiStatusesFWithFriends()
2752 $result = api_statuses_f('friends');
2753 $this->assertArrayHasKey('user', $result);
2757 * Test the api_statuses_f() function.
2761 public function testApiStatusesFWithFollowers()
2763 $result = api_statuses_f('followers');
2764 $this->assertArrayHasKey('user', $result);
2768 * Test the api_statuses_f() function.
2772 public function testApiStatusesFWithBlocks()
2774 $result = api_statuses_f('blocks');
2775 $this->assertArrayHasKey('user', $result);
2779 * Test the api_statuses_f() function.
2783 public function testApiStatusesFWithIncoming()
2785 $result = api_statuses_f('incoming');
2786 $this->assertArrayHasKey('user', $result);
2790 * Test the api_statuses_f() function an undefined cursor GET variable.
2794 public function testApiStatusesFWithUndefinedCursor()
2796 $_GET['cursor'] = 'undefined';
2797 $this->assertFalse(api_statuses_f('friends'));
2801 * Test the api_statuses_friends() function.
2805 public function testApiStatusesFriends()
2807 $result = api_statuses_friends('json');
2808 $this->assertArrayHasKey('user', $result);
2812 * Test the api_statuses_friends() function an undefined cursor GET variable.
2816 public function testApiStatusesFriendsWithUndefinedCursor()
2818 $_GET['cursor'] = 'undefined';
2819 $this->assertFalse(api_statuses_friends('json'));
2823 * Test the api_statuses_followers() function.
2827 public function testApiStatusesFollowers()
2829 $result = api_statuses_followers('json');
2830 $this->assertArrayHasKey('user', $result);
2834 * Test the api_statuses_followers() function an undefined cursor GET variable.
2838 public function testApiStatusesFollowersWithUndefinedCursor()
2840 $_GET['cursor'] = 'undefined';
2841 $this->assertFalse(api_statuses_followers('json'));
2845 * Test the api_blocks_list() function.
2849 public function testApiBlocksList()
2851 $result = api_blocks_list('json');
2852 $this->assertArrayHasKey('user', $result);
2856 * Test the api_blocks_list() function an undefined cursor GET variable.
2860 public function testApiBlocksListWithUndefinedCursor()
2862 $_GET['cursor'] = 'undefined';
2863 $this->assertFalse(api_blocks_list('json'));
2867 * Test the api_friendships_incoming() function.
2871 public function testApiFriendshipsIncoming()
2873 $result = api_friendships_incoming('json');
2874 $this->assertArrayHasKey('id', $result);
2878 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2882 public function testApiFriendshipsIncomingWithUndefinedCursor()
2884 $_GET['cursor'] = 'undefined';
2885 $this->assertFalse(api_friendships_incoming('json'));
2889 * Test the api_statusnet_config() function.
2893 public function testApiStatusnetConfig()
2895 $result = api_statusnet_config('json');
2896 $this->assertEquals('localhost', $result['config']['site']['server']);
2897 $this->assertEquals('default', $result['config']['site']['theme']);
2898 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2899 $this->assertTrue($result['config']['site']['fancy']);
2900 $this->assertEquals('en', $result['config']['site']['language']);
2901 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2902 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2903 $this->assertEquals('false', $result['config']['site']['private']);
2904 $this->assertEquals('false', $result['config']['site']['ssl']);
2905 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2909 * Test the api_statusnet_version() function.
2913 public function testApiStatusnetVersion()
2915 $result = api_statusnet_version('json');
2916 $this->assertEquals('0.9.7', $result['version']);
2920 * Test the api_ff_ids() function.
2924 public function testApiFfIds()
2926 $result = api_ff_ids('json', Contact::FOLLOWER);
2927 $this->assertEquals(['id' => []], $result);
2931 * Test the api_ff_ids() function with a result.
2935 public function testApiFfIdsWithResult()
2937 $this->markTestIncomplete();
2941 * Test the api_ff_ids() function without an authenticated user.
2944 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2946 public function testApiFfIdsWithoutAuthenticatedUser()
2948 $_SESSION['authenticated'] = false;
2949 api_ff_ids('json', Contact::FOLLOWER);
2953 * Test the api_friends_ids() function.
2957 public function testApiFriendsIds()
2959 $result = api_friends_ids('json');
2960 $this->assertEquals(['id' => []], $result);
2964 * Test the api_followers_ids() function.
2968 public function testApiFollowersIds()
2970 $result = api_followers_ids('json');
2971 $this->assertEquals(['id' => []], $result);
2975 * Test the api_direct_messages_new() function.
2979 public function testApiDirectMessagesNew()
2981 $result = api_direct_messages_new('json');
2982 $this->assertNull($result);
2986 * Test the api_direct_messages_new() function without an authenticated user.
2989 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2991 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2993 $_SESSION['authenticated'] = false;
2994 api_direct_messages_new('json');
2998 * Test the api_direct_messages_new() function with an user ID.
3002 public function testApiDirectMessagesNewWithUserId()
3004 $_POST['text'] = 'message_text';
3005 $_POST['user_id'] = $this->otherUser['id'];
3006 $result = api_direct_messages_new('json');
3007 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3011 * Test the api_direct_messages_new() function with a screen name.
3015 public function testApiDirectMessagesNewWithScreenName()
3017 $_POST['text'] = 'message_text';
3018 $_POST['screen_name'] = $this->friendUser['nick'];
3019 $result = api_direct_messages_new('json');
3020 $this->assertContains('message_text', $result['direct_message']['text']);
3021 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3022 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3026 * Test the api_direct_messages_new() function with a title.
3030 public function testApiDirectMessagesNewWithTitle()
3032 $_POST['text'] = 'message_text';
3033 $_POST['screen_name'] = $this->friendUser['nick'];
3034 $_REQUEST['title'] = 'message_title';
3035 $result = api_direct_messages_new('json');
3036 $this->assertContains('message_text', $result['direct_message']['text']);
3037 $this->assertContains('message_title', $result['direct_message']['text']);
3038 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3039 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3043 * Test the api_direct_messages_new() function with an RSS result.
3047 public function testApiDirectMessagesNewWithRss()
3049 $_POST['text'] = 'message_text';
3050 $_POST['screen_name'] = $this->friendUser['nick'];
3051 $result = api_direct_messages_new('rss');
3052 $this->assertXml($result, 'direct-messages');
3056 * Test the api_direct_messages_destroy() function.
3059 * @expectedException Friendica\Network\HTTPException\BadRequestException
3061 public function testApiDirectMessagesDestroy()
3063 api_direct_messages_destroy('json');
3067 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3071 public function testApiDirectMessagesDestroyWithVerbose()
3073 $_GET['friendica_verbose'] = 'true';
3074 $result = api_direct_messages_destroy('json');
3075 $this->assertEquals(
3078 'result' => 'error',
3079 'message' => 'message id or parenturi not specified'
3087 * Test the api_direct_messages_destroy() function without an authenticated user.
3090 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3092 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3094 $_SESSION['authenticated'] = false;
3095 api_direct_messages_destroy('json');
3099 * Test the api_direct_messages_destroy() function with a non-zero ID.
3102 * @expectedException Friendica\Network\HTTPException\BadRequestException
3104 public function testApiDirectMessagesDestroyWithId()
3106 $_REQUEST['id'] = 1;
3107 api_direct_messages_destroy('json');
3111 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3115 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3117 $_REQUEST['id'] = 1;
3118 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3119 $_GET['friendica_verbose'] = 'true';
3120 $result = api_direct_messages_destroy('json');
3121 $this->assertEquals(
3124 'result' => 'error',
3125 'message' => 'message id not in database'
3133 * Test the api_direct_messages_destroy() function with a non-zero ID.
3137 public function testApiDirectMessagesDestroyWithCorrectId()
3139 $this->markTestIncomplete('We need to add a dataset for this.');
3143 * Test the api_direct_messages_box() function.
3147 public function testApiDirectMessagesBoxWithSentbox()
3149 $_REQUEST['page'] = -1;
3150 $_REQUEST['max_id'] = 10;
3151 $result = api_direct_messages_box('json', 'sentbox', 'false');
3152 $this->assertArrayHasKey('direct_message', $result);
3156 * Test the api_direct_messages_box() function.
3160 public function testApiDirectMessagesBoxWithConversation()
3162 $result = api_direct_messages_box('json', 'conversation', 'false');
3163 $this->assertArrayHasKey('direct_message', $result);
3167 * Test the api_direct_messages_box() function.
3171 public function testApiDirectMessagesBoxWithAll()
3173 $result = api_direct_messages_box('json', 'all', 'false');
3174 $this->assertArrayHasKey('direct_message', $result);
3178 * Test the api_direct_messages_box() function.
3182 public function testApiDirectMessagesBoxWithInbox()
3184 $result = api_direct_messages_box('json', 'inbox', 'false');
3185 $this->assertArrayHasKey('direct_message', $result);
3189 * Test the api_direct_messages_box() function.
3193 public function testApiDirectMessagesBoxWithVerbose()
3195 $result = api_direct_messages_box('json', 'sentbox', 'true');
3196 $this->assertEquals(
3199 'result' => 'error',
3200 'message' => 'no mails available'
3208 * Test the api_direct_messages_box() function with a RSS result.
3212 public function testApiDirectMessagesBoxWithRss()
3214 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3215 $this->assertXml($result, 'direct-messages');
3219 * Test the api_direct_messages_box() function without an authenticated user.
3222 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3224 public function testApiDirectMessagesBoxWithUnallowedUser()
3226 $_SESSION['allow_api'] = false;
3227 $_GET['screen_name'] = $this->selfUser['nick'];
3228 api_direct_messages_box('json', 'sentbox', 'false');
3232 * Test the api_direct_messages_sentbox() function.
3236 public function testApiDirectMessagesSentbox()
3238 $result = api_direct_messages_sentbox('json');
3239 $this->assertArrayHasKey('direct_message', $result);
3243 * Test the api_direct_messages_inbox() function.
3247 public function testApiDirectMessagesInbox()
3249 $result = api_direct_messages_inbox('json');
3250 $this->assertArrayHasKey('direct_message', $result);
3254 * Test the api_direct_messages_all() function.
3258 public function testApiDirectMessagesAll()
3260 $result = api_direct_messages_all('json');
3261 $this->assertArrayHasKey('direct_message', $result);
3265 * Test the api_direct_messages_conversation() function.
3269 public function testApiDirectMessagesConversation()
3271 $result = api_direct_messages_conversation('json');
3272 $this->assertArrayHasKey('direct_message', $result);
3276 * Test the api_oauth_request_token() function.
3280 public function testApiOauthRequestToken()
3282 $this->markTestIncomplete('killme() kills phpunit as well');
3286 * Test the api_oauth_access_token() function.
3290 public function testApiOauthAccessToken()
3292 $this->markTestIncomplete('killme() kills phpunit as well');
3296 * Test the api_fr_photoalbum_delete() function.
3299 * @expectedException Friendica\Network\HTTPException\BadRequestException
3301 public function testApiFrPhotoalbumDelete()
3303 api_fr_photoalbum_delete('json');
3307 * Test the api_fr_photoalbum_delete() function with an album name.
3310 * @expectedException Friendica\Network\HTTPException\BadRequestException
3312 public function testApiFrPhotoalbumDeleteWithAlbum()
3314 $_REQUEST['album'] = 'album_name';
3315 api_fr_photoalbum_delete('json');
3319 * Test the api_fr_photoalbum_delete() function with an album name.
3323 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3325 $this->markTestIncomplete('We need to add a dataset for this.');
3329 * Test the api_fr_photoalbum_delete() function.
3332 * @expectedException Friendica\Network\HTTPException\BadRequestException
3334 public function testApiFrPhotoalbumUpdate()
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 testApiFrPhotoalbumUpdateWithAlbum()
3347 $_REQUEST['album'] = 'album_name';
3348 api_fr_photoalbum_update('json');
3352 * Test the api_fr_photoalbum_delete() function with an album name.
3355 * @expectedException Friendica\Network\HTTPException\BadRequestException
3357 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3359 $_REQUEST['album'] = 'album_name';
3360 $_REQUEST['album_new'] = 'album_name';
3361 api_fr_photoalbum_update('json');
3365 * Test the api_fr_photoalbum_update() function without an authenticated user.
3368 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3370 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3372 $_SESSION['authenticated'] = false;
3373 api_fr_photoalbum_update('json');
3377 * Test the api_fr_photoalbum_delete() function with an album name.
3381 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3383 $this->markTestIncomplete('We need to add a dataset for this.');
3387 * Test the api_fr_photos_list() function.
3391 public function testApiFrPhotosList()
3393 $result = api_fr_photos_list('json');
3394 $this->assertArrayHasKey('photo', $result);
3398 * Test the api_fr_photos_list() function without an authenticated user.
3401 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3403 public function testApiFrPhotosListWithoutAuthenticatedUser()
3405 $_SESSION['authenticated'] = false;
3406 api_fr_photos_list('json');
3410 * Test the api_fr_photo_create_update() function.
3413 * @expectedException Friendica\Network\HTTPException\BadRequestException
3415 public function testApiFrPhotoCreateUpdate()
3417 api_fr_photo_create_update('json');
3421 * Test the api_fr_photo_create_update() function without an authenticated user.
3424 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3426 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3428 $_SESSION['authenticated'] = false;
3429 api_fr_photo_create_update('json');
3433 * Test the api_fr_photo_create_update() function with an album name.
3436 * @expectedException Friendica\Network\HTTPException\BadRequestException
3438 public function testApiFrPhotoCreateUpdateWithAlbum()
3440 $_REQUEST['album'] = 'album_name';
3441 api_fr_photo_create_update('json');
3445 * Test the api_fr_photo_create_update() function with the update mode.
3449 public function testApiFrPhotoCreateUpdateWithUpdate()
3451 $this->markTestIncomplete('We need to create a dataset for this');
3455 * Test the api_fr_photo_create_update() function with an uploaded file.
3459 public function testApiFrPhotoCreateUpdateWithFile()
3461 $this->markTestIncomplete();
3465 * Test the api_fr_photo_delete() function.
3468 * @expectedException Friendica\Network\HTTPException\BadRequestException
3470 public function testApiFrPhotoDelete()
3472 api_fr_photo_delete('json');
3476 * Test the api_fr_photo_delete() function without an authenticated user.
3479 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3481 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3483 $_SESSION['authenticated'] = false;
3484 api_fr_photo_delete('json');
3488 * Test the api_fr_photo_delete() function with a photo ID.
3491 * @expectedException Friendica\Network\HTTPException\BadRequestException
3493 public function testApiFrPhotoDeleteWithPhotoId()
3495 $_REQUEST['photo_id'] = 1;
3496 api_fr_photo_delete('json');
3500 * Test the api_fr_photo_delete() function with a correct photo ID.
3504 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3506 $this->markTestIncomplete('We need to create a dataset for this.');
3510 * Test the api_fr_photo_detail() function.
3513 * @expectedException Friendica\Network\HTTPException\BadRequestException
3515 public function testApiFrPhotoDetail()
3517 api_fr_photo_detail('json');
3521 * Test the api_fr_photo_detail() function without an authenticated user.
3524 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3526 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3528 $_SESSION['authenticated'] = false;
3529 api_fr_photo_detail('json');
3533 * Test the api_fr_photo_detail() function with a photo ID.
3536 * @expectedException Friendica\Network\HTTPException\NotFoundException
3538 public function testApiFrPhotoDetailWithPhotoId()
3540 $_REQUEST['photo_id'] = 1;
3541 api_fr_photo_detail('json');
3545 * Test the api_fr_photo_detail() function with a correct photo ID.
3549 public function testApiFrPhotoDetailCorrectPhotoId()
3551 $this->markTestIncomplete('We need to create a dataset for this.');
3555 * Test the api_account_update_profile_image() function.
3558 * @expectedException Friendica\Network\HTTPException\BadRequestException
3560 public function testApiAccountUpdateProfileImage()
3562 api_account_update_profile_image('json');
3566 * Test the api_account_update_profile_image() function without an authenticated user.
3569 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3571 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3573 $_SESSION['authenticated'] = false;
3574 api_account_update_profile_image('json');
3578 * Test the api_account_update_profile_image() function with an uploaded file.
3581 * @expectedException Friendica\Network\HTTPException\BadRequestException
3583 public function testApiAccountUpdateProfileImageWithUpload()
3585 $this->markTestIncomplete();
3590 * Test the api_account_update_profile() function.
3594 public function testApiAccountUpdateProfile()
3596 $_POST['name'] = 'new_name';
3597 $_POST['description'] = 'new_description';
3598 $result = api_account_update_profile('json');
3599 // We can't use assertSelfUser() here because the user object is missing some properties.
3600 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3601 $this->assertEquals('DFRN', $result['user']['location']);
3602 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3603 $this->assertEquals('dfrn', $result['user']['network']);
3604 $this->assertEquals('new_name', $result['user']['name']);
3605 $this->assertEquals('new_description', $result['user']['description']);
3609 * Test the check_acl_input() function.
3613 public function testCheckAclInput()
3615 $result = check_acl_input('<aclstring>');
3616 // Where does this result come from?
3617 $this->assertEquals(1, $result);
3621 * Test the check_acl_input() function with an empty ACL string.
3625 public function testCheckAclInputWithEmptyAclString()
3627 $result = check_acl_input(' ');
3628 $this->assertFalse($result);
3632 * Test the save_media_to_database() function.
3636 public function testSaveMediaToDatabase()
3638 $this->markTestIncomplete();
3642 * Test the post_photo_item() function.
3646 public function testPostPhotoItem()
3648 $this->markTestIncomplete();
3652 * Test the prepare_photo_data() function.
3656 public function testPreparePhotoData()
3658 $this->markTestIncomplete();
3662 * Test the api_friendica_remoteauth() function.
3665 * @expectedException Friendica\Network\HTTPException\BadRequestException
3667 public function testApiFriendicaRemoteauth()
3669 api_friendica_remoteauth();
3673 * Test the api_friendica_remoteauth() function with an URL.
3676 * @expectedException Friendica\Network\HTTPException\BadRequestException
3678 public function testApiFriendicaRemoteauthWithUrl()
3680 $_GET['url'] = 'url';
3681 $_GET['c_url'] = 'url';
3682 api_friendica_remoteauth();
3686 * Test the api_friendica_remoteauth() function with a correct URL.
3690 public function testApiFriendicaRemoteauthWithCorrectUrl()
3692 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3693 $_GET['url'] = 'url';
3694 $_GET['c_url'] = $this->selfUser['nurl'];
3695 api_friendica_remoteauth();
3699 * Test the api_share_as_retweet() function.
3703 public function testApiShareAsRetweet()
3705 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3706 $result = api_share_as_retweet($item);
3707 $this->assertFalse($result);
3711 * Test the api_share_as_retweet() function with a valid item.
3715 public function testApiShareAsRetweetWithValidItem()
3717 $this->markTestIncomplete();
3721 * Test the api_get_nick() function.
3725 public function testApiGetNick()
3727 $result = api_get_nick($this->otherUser['nurl']);
3728 $this->assertEquals('othercontact', $result);
3732 * Test the api_get_nick() function with a wrong URL.
3736 public function testApiGetNickWithWrongUrl()
3738 $result = api_get_nick('wrong_url');
3739 $this->assertFalse($result);
3743 * Test the api_in_reply_to() function.
3747 public function testApiInReplyTo()
3749 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3750 $this->assertArrayHasKey('status_id', $result);
3751 $this->assertArrayHasKey('user_id', $result);
3752 $this->assertArrayHasKey('status_id_str', $result);
3753 $this->assertArrayHasKey('user_id_str', $result);
3754 $this->assertArrayHasKey('screen_name', $result);
3758 * Test the api_in_reply_to() function with a valid item.
3762 public function testApiInReplyToWithValidItem()
3764 $this->markTestIncomplete();
3768 * Test the api_clean_plain_items() function.
3772 public function testApiCleanPlainItems()
3774 $_REQUEST['include_entities'] = 'true';
3775 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3776 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3780 * Test the api_best_nickname() function.
3784 public function testApiBestNickname()
3787 $result = api_best_nickname($contacts);
3788 $this->assertNull($result);
3792 * Test the api_best_nickname() function with contacts.
3796 public function testApiBestNicknameWithContacts()
3798 $this->markTestIncomplete();
3802 * Test the api_friendica_group_show() function.
3806 public function testApiFriendicaGroupShow()
3808 $this->markTestIncomplete();
3812 * Test the api_friendica_group_delete() function.
3816 public function testApiFriendicaGroupDelete()
3818 $this->markTestIncomplete();
3822 * Test the api_lists_destroy() function.
3826 public function testApiListsDestroy()
3828 $this->markTestIncomplete();
3832 * Test the group_create() function.
3836 public function testGroupCreate()
3838 $this->markTestIncomplete();
3842 * Test the api_friendica_group_create() function.
3846 public function testApiFriendicaGroupCreate()
3848 $this->markTestIncomplete();
3852 * Test the api_lists_create() function.
3856 public function testApiListsCreate()
3858 $this->markTestIncomplete();
3862 * Test the api_friendica_group_update() function.
3866 public function testApiFriendicaGroupUpdate()
3868 $this->markTestIncomplete();
3872 * Test the api_lists_update() function.
3876 public function testApiListsUpdate()
3878 $this->markTestIncomplete();
3882 * Test the api_friendica_activity() function.
3886 public function testApiFriendicaActivity()
3888 $this->markTestIncomplete();
3892 * Test the api_friendica_notification() function.
3895 * @expectedException Friendica\Network\HTTPException\BadRequestException
3897 public function testApiFriendicaNotification()
3899 api_friendica_notification('json');
3903 * Test the api_friendica_notification() function without an authenticated user.
3906 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3908 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3910 $_SESSION['authenticated'] = false;
3911 api_friendica_notification('json');
3915 * Test the api_friendica_notification() function with an argument count.
3919 public function testApiFriendicaNotificationWithArgumentCount()
3921 $this->app->argv = ['api', 'friendica', 'notification'];
3922 $this->app->argc = count($this->app->argv);
3923 $result = api_friendica_notification('json');
3924 $this->assertEquals(['note' => false], $result);
3928 * Test the api_friendica_notification() function with an XML result.
3932 public function testApiFriendicaNotificationWithXmlResult()
3934 $this->app->argv = ['api', 'friendica', 'notification'];
3935 $this->app->argc = count($this->app->argv);
3936 $result = api_friendica_notification('xml');
3937 $this->assertXml($result, 'notes');
3941 * Test the api_friendica_notification_seen() function.
3945 public function testApiFriendicaNotificationSeen()
3947 $this->markTestIncomplete();
3951 * Test the api_friendica_direct_messages_setseen() function.
3955 public function testApiFriendicaDirectMessagesSetseen()
3957 $this->markTestIncomplete();
3961 * Test the api_friendica_direct_messages_search() function.
3965 public function testApiFriendicaDirectMessagesSearch()
3967 $this->markTestIncomplete();
3971 * Test the api_friendica_profile_show() function.
3975 public function testApiFriendicaProfileShow()
3977 $result = api_friendica_profile_show('json');
3978 // We can't use assertSelfUser() here because the user object is missing some properties.
3979 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3980 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3981 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3982 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3983 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3984 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3985 $this->assertFalse($result['$result']['multi_profiles']);
3989 * Test the api_friendica_profile_show() function with a profile ID.
3993 public function testApiFriendicaProfileShowWithProfileId()
3995 $this->markTestIncomplete('We need to add a dataset for this.');
3999 * Test the api_friendica_profile_show() function with a wrong profile ID.
4002 * @expectedException Friendica\Network\HTTPException\BadRequestException
4004 public function testApiFriendicaProfileShowWithWrongProfileId()
4006 $_REQUEST['profile_id'] = 666;
4007 api_friendica_profile_show('json');
4011 * Test the api_friendica_profile_show() function without an authenticated user.
4014 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4016 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4018 $_SESSION['authenticated'] = false;
4019 api_friendica_profile_show('json');
4023 * Test the api_saved_searches_list() function.
4027 public function testApiSavedSearchesList()
4029 $result = api_saved_searches_list('json');
4030 $this->assertEquals(1, $result['terms'][0]['id']);
4031 $this->assertEquals(1, $result['terms'][0]['id_str']);
4032 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4033 $this->assertEquals('Saved search', $result['terms'][0]['query']);