6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\System;
13 use Friendica\Factory;
14 use Friendica\Network\HTTPException;
15 use Friendica\Util\BasePath;
16 use Friendica\Util\BaseURL;
17 use Friendica\Util\Config\ConfigFileLoader;
18 use Monolog\Handler\TestHandler;
20 require_once __DIR__ . '/../../include/api.php';
23 * Tests for the API functions.
25 * Functions that use header() need to be tested in a separate process.
26 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
28 class ApiTest extends DatabaseTest
31 * @var TestHandler Can handle log-outputs
41 protected $friendUser;
45 protected $wrongUserId;
48 * Create variables used by tests.
50 public function setUp()
52 $basePath = BasePath::create(dirname(__DIR__) . '/../');
53 $mode = new App\Mode($basePath);
54 $router = new App\Router();
55 $configLoader = new ConfigFileLoader($basePath, $mode);
56 $configCache = Factory\ConfigFactory::createCache($configLoader);
57 $profiler = Factory\ProfilerFactory::create($configCache);
58 Factory\DBFactory::init($configCache, $profiler, $_SERVER);
59 $config = Factory\ConfigFactory::createConfig($configCache);
60 Factory\ConfigFactory::createPConfig($configCache);
61 $logger = Factory\LoggerFactory::create('test', $config, $profiler);
62 $baseUrl = new BaseURL($config, $_SERVER);
63 $this->app = new App($config, $mode, $router, $baseUrl, $logger, $profiler, false);
67 // User data that the test database is populated with
70 'name' => 'Self contact',
71 'nick' => 'selfcontact',
72 'nurl' => 'http://localhost/profile/selfcontact'
76 'name' => 'Friend contact',
77 'nick' => 'friendcontact',
78 'nurl' => 'http://localhost/profile/friendcontact'
82 'name' => 'othercontact',
83 'nick' => 'othercontact',
84 'nurl' => 'http://localhost/profile/othercontact'
87 // User ID that we know is not in the database
88 $this->wrongUserId = 666;
90 // Most API require login so we force the session
93 'authenticated' => true,
94 'uid' => $this->selfUser['id']
97 Config::set('system', 'url', 'http://localhost');
98 Config::set('system', 'hostname', 'localhost');
99 Config::set('system', 'worker_dont_fork', true);
102 Config::set('config', 'hostname', 'localhost');
103 Config::set('system', 'throttle_limit_day', 100);
104 Config::set('system', 'throttle_limit_week', 100);
105 Config::set('system', 'throttle_limit_month', 100);
106 Config::set('system', 'theme', 'system_theme');
110 * Cleanup variables used by tests.
112 protected function tearDown()
116 $this->app->argc = 1;
117 $this->app->argv = ['home'];
121 * Assert that an user array contains expected keys.
122 * @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.
139 * @param array $user User array
142 private function assertOtherUser(array $user)
144 $this->assertEquals($this->otherUser['id'], $user['id']);
145 $this->assertEquals($this->otherUser['id'], $user['id_str']);
146 $this->assertEquals(0, $user['self']);
147 $this->assertEquals($this->otherUser['name'], $user['name']);
148 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
149 $this->assertFalse($user['verified']);
153 * Assert that a status array contains expected keys.
154 * @param array $status Status array
157 private function assertStatus(array $status)
159 $this->assertInternalType('string', $status['text']);
160 $this->assertInternalType('int', $status['id']);
161 // We could probably do more checks here.
165 * Assert that a list array contains expected keys.
166 * @param array $list List array
169 private function assertList(array $list)
171 $this->assertInternalType('string', $list['name']);
172 $this->assertInternalType('int', $list['id']);
173 $this->assertInternalType('string', $list['id_str']);
174 $this->assertContains($list['mode'], ['public', 'private']);
175 // We could probably do more checks here.
179 * Assert that the string is XML and contain the root element.
180 * @param string $result XML string
181 * @param string $root_element Root element name
184 private function assertXml($result, $root_element)
186 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
187 $this->assertContains('<'.$root_element, $result);
188 // We could probably do more checks here.
192 * Get the path to a temporary empty PNG image.
193 * @return string Path
195 private function getTempImage()
197 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
201 // Empty 1x1 px PNG image
202 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
210 * Test the api_user() function.
213 public function testApiUser()
215 $this->assertEquals($this->selfUser['id'], api_user());
219 * Test the api_user() function with an unallowed user.
222 public function testApiUserWithUnallowedUser()
224 $_SESSION = ['allow_api' => false];
225 $this->assertEquals(false, api_user());
229 * Test the api_source() function.
232 public function testApiSource()
234 $this->assertEquals('api', api_source());
238 * Test the api_source() function with a Twidere user agent.
241 public function testApiSourceWithTwidere()
243 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
244 $this->assertEquals('Twidere', api_source());
248 * Test the api_source() function with a GET parameter.
251 public function testApiSourceWithGet()
253 $_GET['source'] = 'source_name';
254 $this->assertEquals('source_name', api_source());
258 * Test the api_date() function.
261 public function testApiDate()
263 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
267 * Test the api_register_func() function.
270 public function testApiRegisterFunc()
282 $this->assertTrue($API['api_path']['auth']);
283 $this->assertEquals('method', $API['api_path']['method']);
284 $this->assertTrue(is_callable($API['api_path']['func']));
288 * Test the api_login() function without any login.
290 * @runInSeparateProcess
291 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
293 public function testApiLoginWithoutLogin()
295 api_login($this->app);
299 * Test the api_login() function with a bad login.
301 * @runInSeparateProcess
302 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
304 public function testApiLoginWithBadLogin()
306 $_SERVER['PHP_AUTH_USER'] = 'user@server';
307 api_login($this->app);
311 * Test the api_login() function with oAuth.
314 public function testApiLoginWithOauth()
316 $this->markTestIncomplete('Can we test this easily?');
320 * Test the api_login() function with authentication provided by an addon.
323 public function testApiLoginWithAddonAuth()
325 $this->markTestIncomplete('Can we test this easily?');
329 * Test the api_login() function with a correct login.
331 * @runInSeparateProcess
333 public function testApiLoginWithCorrectLogin()
335 $_SERVER['PHP_AUTH_USER'] = 'Test user';
336 $_SERVER['PHP_AUTH_PW'] = 'password';
337 api_login($this->app);
341 * Test the api_login() function with a remote user.
343 * @runInSeparateProcess
344 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
346 public function testApiLoginWithRemoteUser()
348 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
349 api_login($this->app);
353 * Test the api_check_method() function.
356 public function testApiCheckMethod()
358 $this->assertFalse(api_check_method('method'));
362 * Test the api_check_method() function with a correct method.
365 public function testApiCheckMethodWithCorrectMethod()
367 $_SERVER['REQUEST_METHOD'] = 'method';
368 $this->assertTrue(api_check_method('method'));
372 * Test the api_check_method() function with a wildcard.
375 public function testApiCheckMethodWithWildcard()
377 $this->assertTrue(api_check_method('*'));
381 * Test the api_call() function.
383 * @runInSeparateProcess
385 public function testApiCall()
389 'method' => 'method',
390 'func' => function () {
391 return ['data' => ['some_data']];
394 $_SERVER['REQUEST_METHOD'] = 'method';
395 $_GET['callback'] = 'callback_name';
397 $this->app->query_string = 'api_path';
399 'callback_name(["some_data"])',
405 * Test the api_call() function with the profiled enabled.
407 * @runInSeparateProcess
409 public function testApiCallWithProfiler()
413 'method' => 'method',
414 'func' => function () {
415 return ['data' => ['some_data']];
418 $_SERVER['REQUEST_METHOD'] = 'method';
419 Config::set('system', 'profiler', true);
420 Config::set('rendertime', 'callstack', true);
421 $this->app->callstack = [
422 'database' => ['some_function' => 200],
423 'database_write' => ['some_function' => 200],
424 'cache' => ['some_function' => 200],
425 'cache_write' => ['some_function' => 200],
426 'network' => ['some_function' => 200]
429 $this->app->query_string = 'api_path';
437 * Test the api_call() function without any result.
439 * @runInSeparateProcess
441 public function testApiCallWithNoResult()
445 'method' => 'method',
446 'func' => function () {
450 $_SERVER['REQUEST_METHOD'] = 'method';
452 $this->app->query_string = 'api_path';
454 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
460 * Test the api_call() function with an unimplemented API.
462 * @runInSeparateProcess
464 public function testApiCallWithUninplementedApi()
467 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
473 * Test the api_call() function with a JSON result.
475 * @runInSeparateProcess
477 public function testApiCallWithJson()
481 'method' => 'method',
482 'func' => function () {
483 return ['data' => ['some_data']];
486 $_SERVER['REQUEST_METHOD'] = 'method';
488 $this->app->query_string = 'api_path.json';
496 * Test the api_call() function with an XML result.
498 * @runInSeparateProcess
500 public function testApiCallWithXml()
504 'method' => 'method',
505 'func' => function () {
509 $_SERVER['REQUEST_METHOD'] = 'method';
511 $this->app->query_string = 'api_path.xml';
519 * Test the api_call() function with an RSS result.
521 * @runInSeparateProcess
523 public function testApiCallWithRss()
527 'method' => 'method',
528 'func' => function () {
532 $_SERVER['REQUEST_METHOD'] = 'method';
534 $this->app->query_string = 'api_path.rss';
536 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
543 * Test the api_call() function with an Atom result.
545 * @runInSeparateProcess
547 public function testApiCallWithAtom()
551 'method' => 'method',
552 'func' => function () {
556 $_SERVER['REQUEST_METHOD'] = 'method';
558 $this->app->query_string = 'api_path.atom';
560 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
567 * Test the api_call() function with an unallowed method.
569 * @runInSeparateProcess
571 public function testApiCallWithWrongMethod()
574 $API['api_path'] = ['method' => 'method'];
576 $this->app->query_string = 'api_path';
578 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
584 * Test the api_call() function with an unauthorized user.
586 * @runInSeparateProcess
588 public function testApiCallWithWrongAuth()
592 'method' => 'method',
595 $_SERVER['REQUEST_METHOD'] = 'method';
596 $_SESSION['authenticated'] = false;
598 $this->app->query_string = 'api_path';
600 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
606 * Test the api_error() function with a JSON result.
608 * @runInSeparateProcess
610 public function testApiErrorWithJson()
613 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
614 api_error('json', new HTTPException\OKException('error_message'))
619 * Test the api_error() function with an XML result.
621 * @runInSeparateProcess
623 public function testApiErrorWithXml()
626 '<?xml version="1.0"?>'."\n".
627 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
628 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
629 'xmlns:georss="http://www.georss.org/georss">'."\n".
630 ' <error>error_message</error>'."\n".
631 ' <code>200 OK</code>'."\n".
634 api_error('xml', new HTTPException\OKException('error_message'))
639 * Test the api_error() function with an RSS result.
641 * @runInSeparateProcess
643 public function testApiErrorWithRss()
646 '<?xml version="1.0"?>'."\n".
647 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
648 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
649 'xmlns:georss="http://www.georss.org/georss">'."\n".
650 ' <error>error_message</error>'."\n".
651 ' <code>200 OK</code>'."\n".
654 api_error('rss', new HTTPException\OKException('error_message'))
659 * Test the api_error() function with an Atom result.
661 * @runInSeparateProcess
663 public function testApiErrorWithAtom()
666 '<?xml version="1.0"?>'."\n".
667 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
668 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
669 'xmlns:georss="http://www.georss.org/georss">'."\n".
670 ' <error>error_message</error>'."\n".
671 ' <code>200 OK</code>'."\n".
674 api_error('atom', new HTTPException\OKException('error_message'))
679 * Test the api_rss_extra() function.
682 public function testApiRssExtra()
684 $user_info = ['url' => 'user_url', 'lang' => 'en'];
685 $result = api_rss_extra($this->app, [], $user_info);
686 $this->assertEquals($user_info, $result['$user']);
687 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
688 $this->assertArrayHasKey('self', $result['$rss']);
689 $this->assertArrayHasKey('base', $result['$rss']);
690 $this->assertArrayHasKey('updated', $result['$rss']);
691 $this->assertArrayHasKey('atom_updated', $result['$rss']);
692 $this->assertArrayHasKey('language', $result['$rss']);
693 $this->assertArrayHasKey('logo', $result['$rss']);
697 * Test the api_rss_extra() function without any user info.
699 * @runInSeparateProcess
701 public function testApiRssExtraWithoutUserInfo()
703 $result = api_rss_extra($this->app, [], null);
704 $this->assertInternalType('array', $result['$user']);
705 $this->assertArrayHasKey('alternate', $result['$rss']);
706 $this->assertArrayHasKey('self', $result['$rss']);
707 $this->assertArrayHasKey('base', $result['$rss']);
708 $this->assertArrayHasKey('updated', $result['$rss']);
709 $this->assertArrayHasKey('atom_updated', $result['$rss']);
710 $this->assertArrayHasKey('language', $result['$rss']);
711 $this->assertArrayHasKey('logo', $result['$rss']);
715 * Test the api_unique_id_to_nurl() function.
718 public function testApiUniqueIdToNurl()
720 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
724 * Test the api_unique_id_to_nurl() function with a correct ID.
727 public function testApiUniqueIdToNurlWithCorrectId()
729 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
733 * Test the api_get_user() function.
735 * @runInSeparateProcess
737 public function testApiGetUser()
739 $user = api_get_user($this->app);
740 $this->assertSelfUser($user);
741 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
742 $this->assertEquals('6fdbe8', $user['profile_link_color']);
743 $this->assertEquals('ededed', $user['profile_background_color']);
747 * Test the api_get_user() function with a Frio schema.
749 * @runInSeparateProcess
751 public function testApiGetUserWithFrioSchema()
753 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
754 $user = api_get_user($this->app);
755 $this->assertSelfUser($user);
756 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
757 $this->assertEquals('6fdbe8', $user['profile_link_color']);
758 $this->assertEquals('ededed', $user['profile_background_color']);
762 * Test the api_get_user() function with a custom Frio schema.
764 * @runInSeparateProcess
766 public function testApiGetUserWithCustomFrioSchema()
768 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
769 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
770 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
771 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
772 $user = api_get_user($this->app);
773 $this->assertSelfUser($user);
774 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
775 $this->assertEquals('123456', $user['profile_link_color']);
776 $this->assertEquals('123456', $user['profile_background_color']);
780 * Test the api_get_user() function with an empty Frio schema.
782 * @runInSeparateProcess
784 public function testApiGetUserWithEmptyFrioSchema()
786 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
787 $user = api_get_user($this->app);
788 $this->assertSelfUser($user);
789 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
790 $this->assertEquals('6fdbe8', $user['profile_link_color']);
791 $this->assertEquals('ededed', $user['profile_background_color']);
795 * Test the api_get_user() function with an user that is not allowed to use the API.
797 * @runInSeparateProcess
799 public function testApiGetUserWithoutApiUser()
801 $_SERVER['PHP_AUTH_USER'] = 'Test user';
802 $_SERVER['PHP_AUTH_PW'] = 'password';
803 $_SESSION['allow_api'] = false;
804 $this->assertFalse(api_get_user($this->app));
808 * Test the api_get_user() function with an user ID in a GET parameter.
810 * @runInSeparateProcess
812 public function testApiGetUserWithGetId()
814 $_GET['user_id'] = $this->otherUser['id'];
815 $this->assertOtherUser(api_get_user($this->app));
819 * Test the api_get_user() function with a wrong user ID in a GET parameter.
821 * @runInSeparateProcess
822 * @expectedException Friendica\Network\HTTPException\BadRequestException
824 public function testApiGetUserWithWrongGetId()
826 $_GET['user_id'] = $this->wrongUserId;
827 $this->assertOtherUser(api_get_user($this->app));
831 * Test the api_get_user() function with an user name in a GET parameter.
833 * @runInSeparateProcess
835 public function testApiGetUserWithGetName()
837 $_GET['screen_name'] = $this->selfUser['nick'];
838 $this->assertSelfUser(api_get_user($this->app));
842 * Test the api_get_user() function with a profile URL in a GET parameter.
844 * @runInSeparateProcess
846 public function testApiGetUserWithGetUrl()
848 $_GET['profileurl'] = $this->selfUser['nurl'];
849 $this->assertSelfUser(api_get_user($this->app));
853 * Test the api_get_user() function with an user ID in the API path.
855 * @runInSeparateProcess
857 public function testApiGetUserWithNumericCalledApi()
860 $called_api = ['api_path'];
861 $this->app->argv[1] = $this->otherUser['id'].'.json';
862 $this->assertOtherUser(api_get_user($this->app));
866 * Test the api_get_user() function with the $called_api global variable.
868 * @runInSeparateProcess
870 public function testApiGetUserWithCalledApi()
873 $called_api = ['api', 'api_path'];
874 $this->assertSelfUser(api_get_user($this->app));
878 * Test the api_get_user() function with a valid user.
880 * @runInSeparateProcess
882 public function testApiGetUserWithCorrectUser()
884 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
888 * Test the api_get_user() function with a wrong user ID.
890 * @runInSeparateProcess
891 * @expectedException Friendica\Network\HTTPException\BadRequestException
893 public function testApiGetUserWithWrongUser()
895 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
899 * Test the api_get_user() function with a 0 user ID.
901 * @runInSeparateProcess
903 public function testApiGetUserWithZeroUser()
905 $this->assertSelfUser(api_get_user($this->app, 0));
909 * Test the api_item_get_user() function.
911 * @runInSeparateProcess
913 public function testApiItemGetUser()
915 $users = api_item_get_user($this->app, []);
916 $this->assertSelfUser($users[0]);
920 * Test the api_item_get_user() function with a different item parent.
923 public function testApiItemGetUserWithDifferentParent()
925 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
926 $this->assertSelfUser($users[0]);
927 $this->assertEquals($users[0], $users[1]);
931 * Test the api_walk_recursive() function.
934 public function testApiWalkRecursive()
942 // Should we test this with a callback that actually does something?
950 * Test the api_walk_recursive() function with an array.
953 public function testApiWalkRecursiveWithArray()
955 $array = [['item1'], ['item2']];
961 // Should we test this with a callback that actually does something?
969 * Test the api_reformat_xml() function.
972 public function testApiReformatXml()
976 $this->assertTrue(api_reformat_xml($item, $key));
977 $this->assertEquals('true', $item);
981 * Test the api_reformat_xml() function with a statusnet_api key.
984 public function testApiReformatXmlWithStatusnetKey()
987 $key = 'statusnet_api';
988 $this->assertTrue(api_reformat_xml($item, $key));
989 $this->assertEquals('statusnet:api', $key);
993 * Test the api_reformat_xml() function with a friendica_api key.
996 public function testApiReformatXmlWithFriendicaKey()
999 $key = 'friendica_api';
1000 $this->assertTrue(api_reformat_xml($item, $key));
1001 $this->assertEquals('friendica:api', $key);
1005 * Test the api_create_xml() function.
1008 public function testApiCreateXml()
1010 $this->assertEquals(
1011 '<?xml version="1.0"?>'."\n".
1012 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1013 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1014 'xmlns:georss="http://www.georss.org/georss">'."\n".
1015 ' <data>some_data</data>'."\n".
1016 '</root_element>'."\n",
1017 api_create_xml(['data' => ['some_data']], 'root_element')
1022 * Test the api_create_xml() function without any XML namespace.
1025 public function testApiCreateXmlWithoutNamespaces()
1027 $this->assertEquals(
1028 '<?xml version="1.0"?>'."\n".
1030 ' <data>some_data</data>'."\n".
1032 api_create_xml(['data' => ['some_data']], 'ok')
1037 * Test the api_format_data() function.
1040 public function testApiFormatData()
1042 $data = ['some_data'];
1043 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1047 * Test the api_format_data() function with an XML result.
1050 public function testApiFormatDataWithXml()
1052 $this->assertEquals(
1053 '<?xml version="1.0"?>'."\n".
1054 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1055 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1056 'xmlns:georss="http://www.georss.org/georss">'."\n".
1057 ' <data>some_data</data>'."\n".
1058 '</root_element>'."\n",
1059 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1064 * Test the api_account_verify_credentials() function.
1067 public function testApiAccountVerifyCredentials()
1069 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1073 * Test the api_account_verify_credentials() function without an authenticated user.
1075 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1077 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1079 $_SESSION['authenticated'] = false;
1080 api_account_verify_credentials('json');
1084 * Test the requestdata() function.
1087 public function testRequestdata()
1089 $this->assertNull(requestdata('variable_name'));
1093 * Test the requestdata() function with a POST parameter.
1096 public function testRequestdataWithPost()
1098 $_POST['variable_name'] = 'variable_value';
1099 $this->assertEquals('variable_value', requestdata('variable_name'));
1103 * Test the requestdata() function with a GET parameter.
1106 public function testRequestdataWithGet()
1108 $_GET['variable_name'] = 'variable_value';
1109 $this->assertEquals('variable_value', requestdata('variable_name'));
1113 * Test the api_statuses_mediap() function.
1116 public function testApiStatusesMediap()
1118 $this->app->argc = 2;
1126 'tmp_name' => $this->getTempImage(),
1127 'name' => 'spacer.png',
1128 'type' => 'image/png'
1131 $_GET['status'] = '<b>Status content</b>';
1133 $result = api_statuses_mediap('json');
1134 $this->assertStatus($result['status']);
1138 * Test the api_statuses_mediap() function without an authenticated user.
1140 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1142 public function testApiStatusesMediapWithoutAuthenticatedUser()
1144 $_SESSION['authenticated'] = false;
1145 api_statuses_mediap('json');
1149 * Test the api_statuses_update() function.
1152 public function testApiStatusesUpdate()
1154 $_GET['status'] = 'Status content #friendica';
1155 $_GET['in_reply_to_status_id'] = -1;
1164 'tmp_name' => $this->getTempImage(),
1165 'name' => 'spacer.png',
1166 'type' => 'image/png'
1170 $result = api_statuses_update('json');
1171 $this->assertStatus($result['status']);
1175 * Test the api_statuses_update() function with an HTML status.
1178 public function testApiStatusesUpdateWithHtml()
1180 $_GET['htmlstatus'] = '<b>Status content</b>';
1182 $result = api_statuses_update('json');
1183 $this->assertStatus($result['status']);
1187 * Test the api_statuses_update() function without an authenticated user.
1189 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1191 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1193 $_SESSION['authenticated'] = false;
1194 api_statuses_update('json');
1198 * Test the api_statuses_update() function with a parent status.
1201 public function testApiStatusesUpdateWithParent()
1203 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1207 * Test the api_statuses_update() function with a media_ids parameter.
1210 public function testApiStatusesUpdateWithMediaIds()
1212 $this->markTestIncomplete();
1216 * Test the api_statuses_update() function with the throttle limit reached.
1219 public function testApiStatusesUpdateWithDayThrottleReached()
1221 $this->markTestIncomplete();
1225 * Test the api_media_upload() function.
1227 * @expectedException Friendica\Network\HTTPException\BadRequestException
1229 public function testApiMediaUpload()
1235 * Test the api_media_upload() function without an authenticated user.
1237 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1239 public function testApiMediaUploadWithoutAuthenticatedUser()
1241 $_SESSION['authenticated'] = false;
1246 * Test the api_media_upload() function with an invalid uploaded media.
1248 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1250 public function testApiMediaUploadWithMedia()
1255 'tmp_name' => 'tmp_name'
1262 * Test the api_media_upload() function with an valid uploaded media.
1265 public function testApiMediaUploadWithValidMedia()
1273 'tmp_name' => $this->getTempImage(),
1274 'name' => 'spacer.png',
1275 'type' => 'image/png'
1281 $result = api_media_upload();
1282 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1283 $this->assertEquals(1, $result['media']['image']['w']);
1284 $this->assertEquals(1, $result['media']['image']['h']);
1285 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1289 * Test the api_status_show() function.
1291 public function testApiStatusShowWithJson()
1293 $result = api_status_show('json', 1);
1294 $this->assertStatus($result['status']);
1298 * Test the api_status_show() function with an XML result.
1300 public function testApiStatusShowWithXml()
1302 $result = api_status_show('xml', 1);
1303 $this->assertXml($result, 'statuses');
1307 * Test the api_get_last_status() function
1309 public function testApiGetLastStatus()
1311 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1313 $this->assertNotNull($item);
1317 * Test the api_users_show() function.
1320 public function testApiUsersShow()
1322 $result = api_users_show('json');
1323 // We can't use assertSelfUser() here because the user object is missing some properties.
1324 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1325 $this->assertEquals('DFRN', $result['user']['location']);
1326 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1327 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1328 $this->assertEquals('dfrn', $result['user']['network']);
1329 $this->assertTrue($result['user']['verified']);
1333 * Test the api_users_show() function with an XML result.
1336 public function testApiUsersShowWithXml()
1338 $result = api_users_show('xml');
1339 $this->assertXml($result, 'statuses');
1343 * Test the api_users_search() function.
1346 public function testApiUsersSearch()
1348 $_GET['q'] = 'othercontact';
1349 $result = api_users_search('json');
1350 $this->assertOtherUser($result['users'][0]);
1354 * Test the api_users_search() function with an XML result.
1357 public function testApiUsersSearchWithXml()
1359 $_GET['q'] = 'othercontact';
1360 $result = api_users_search('xml');
1361 $this->assertXml($result, 'users');
1365 * Test the api_users_search() function without a GET q parameter.
1367 * @expectedException Friendica\Network\HTTPException\BadRequestException
1369 public function testApiUsersSearchWithoutQuery()
1371 api_users_search('json');
1375 * Test the api_users_lookup() function.
1377 * @expectedException Friendica\Network\HTTPException\NotFoundException
1379 public function testApiUsersLookup()
1381 api_users_lookup('json');
1385 * Test the api_users_lookup() function with an user ID.
1388 public function testApiUsersLookupWithUserId()
1390 $_REQUEST['user_id'] = $this->otherUser['id'];
1391 $result = api_users_lookup('json');
1392 $this->assertOtherUser($result['users'][0]);
1396 * Test the api_search() function.
1399 public function testApiSearch()
1401 $_REQUEST['q'] = 'reply';
1402 $_REQUEST['max_id'] = 10;
1403 $result = api_search('json');
1404 foreach ($result['status'] as $status) {
1405 $this->assertStatus($status);
1406 $this->assertContains('reply', $status['text'], null, true);
1411 * Test the api_search() function a count parameter.
1414 public function testApiSearchWithCount()
1416 $_REQUEST['q'] = 'reply';
1417 $_REQUEST['count'] = 20;
1418 $result = api_search('json');
1419 foreach ($result['status'] as $status) {
1420 $this->assertStatus($status);
1421 $this->assertContains('reply', $status['text'], null, true);
1426 * Test the api_search() function with an rpp parameter.
1429 public function testApiSearchWithRpp()
1431 $_REQUEST['q'] = 'reply';
1432 $_REQUEST['rpp'] = 20;
1433 $result = api_search('json');
1434 foreach ($result['status'] as $status) {
1435 $this->assertStatus($status);
1436 $this->assertContains('reply', $status['text'], null, true);
1441 * Test the api_search() function with an q parameter contains hashtag.
1444 public function testApiSearchWithHashtag()
1446 $_REQUEST['q'] = '%23friendica';
1447 $result = api_search('json');
1448 foreach ($result['status'] as $status) {
1449 $this->assertStatus($status);
1450 $this->assertContains('#friendica', $status['text'], null, true);
1455 * Test the api_search() function with an exclude_replies parameter.
1458 public function testApiSearchWithExcludeReplies()
1460 $_REQUEST['max_id'] = 10;
1461 $_REQUEST['exclude_replies'] = true;
1462 $_REQUEST['q'] = 'friendica';
1463 $result = api_search('json');
1464 foreach ($result['status'] as $status) {
1465 $this->assertStatus($status);
1470 * Test the api_search() function without an authenticated user.
1472 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1474 public function testApiSearchWithUnallowedUser()
1476 $_SESSION['allow_api'] = false;
1477 $_GET['screen_name'] = $this->selfUser['nick'];
1482 * Test the api_search() function without any GET query parameter.
1484 * @expectedException Friendica\Network\HTTPException\BadRequestException
1486 public function testApiSearchWithoutQuery()
1492 * Test the api_statuses_home_timeline() function.
1495 public function testApiStatusesHomeTimeline()
1497 $_REQUEST['max_id'] = 10;
1498 $_REQUEST['exclude_replies'] = true;
1499 $_REQUEST['conversation_id'] = 1;
1500 $result = api_statuses_home_timeline('json');
1501 $this->assertNotEmpty($result['status']);
1502 foreach ($result['status'] as $status) {
1503 $this->assertStatus($status);
1508 * Test the api_statuses_home_timeline() function with a negative page parameter.
1511 public function testApiStatusesHomeTimelineWithNegativePage()
1513 $_REQUEST['page'] = -2;
1514 $result = api_statuses_home_timeline('json');
1515 $this->assertNotEmpty($result['status']);
1516 foreach ($result['status'] as $status) {
1517 $this->assertStatus($status);
1522 * Test the api_statuses_home_timeline() with an unallowed user.
1524 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1526 public function testApiStatusesHomeTimelineWithUnallowedUser()
1528 $_SESSION['allow_api'] = false;
1529 $_GET['screen_name'] = $this->selfUser['nick'];
1530 api_statuses_home_timeline('json');
1534 * Test the api_statuses_home_timeline() function with an RSS result.
1537 public function testApiStatusesHomeTimelineWithRss()
1539 $result = api_statuses_home_timeline('rss');
1540 $this->assertXml($result, 'statuses');
1544 * Test the api_statuses_public_timeline() function.
1547 public function testApiStatusesPublicTimeline()
1549 $_REQUEST['max_id'] = 10;
1550 $_REQUEST['conversation_id'] = 1;
1551 $result = api_statuses_public_timeline('json');
1552 $this->assertNotEmpty($result['status']);
1553 foreach ($result['status'] as $status) {
1554 $this->assertStatus($status);
1559 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1562 public function testApiStatusesPublicTimelineWithExcludeReplies()
1564 $_REQUEST['max_id'] = 10;
1565 $_REQUEST['exclude_replies'] = true;
1566 $result = api_statuses_public_timeline('json');
1567 $this->assertNotEmpty($result['status']);
1568 foreach ($result['status'] as $status) {
1569 $this->assertStatus($status);
1574 * Test the api_statuses_public_timeline() function with a negative page parameter.
1577 public function testApiStatusesPublicTimelineWithNegativePage()
1579 $_REQUEST['page'] = -2;
1580 $result = api_statuses_public_timeline('json');
1581 $this->assertNotEmpty($result['status']);
1582 foreach ($result['status'] as $status) {
1583 $this->assertStatus($status);
1588 * Test the api_statuses_public_timeline() function with an unallowed user.
1590 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1592 public function testApiStatusesPublicTimelineWithUnallowedUser()
1594 $_SESSION['allow_api'] = false;
1595 $_GET['screen_name'] = $this->selfUser['nick'];
1596 api_statuses_public_timeline('json');
1600 * Test the api_statuses_public_timeline() function with an RSS result.
1603 public function testApiStatusesPublicTimelineWithRss()
1605 $result = api_statuses_public_timeline('rss');
1606 $this->assertXml($result, 'statuses');
1610 * Test the api_statuses_networkpublic_timeline() function.
1613 public function testApiStatusesNetworkpublicTimeline()
1615 $_REQUEST['max_id'] = 10;
1616 $result = api_statuses_networkpublic_timeline('json');
1617 $this->assertNotEmpty($result['status']);
1618 foreach ($result['status'] as $status) {
1619 $this->assertStatus($status);
1624 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1627 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1629 $_REQUEST['page'] = -2;
1630 $result = api_statuses_networkpublic_timeline('json');
1631 $this->assertNotEmpty($result['status']);
1632 foreach ($result['status'] as $status) {
1633 $this->assertStatus($status);
1638 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1640 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1642 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1644 $_SESSION['allow_api'] = false;
1645 $_GET['screen_name'] = $this->selfUser['nick'];
1646 api_statuses_networkpublic_timeline('json');
1650 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1653 public function testApiStatusesNetworkpublicTimelineWithRss()
1655 $result = api_statuses_networkpublic_timeline('rss');
1656 $this->assertXml($result, 'statuses');
1660 * Test the api_statuses_show() function.
1662 * @expectedException Friendica\Network\HTTPException\BadRequestException
1664 public function testApiStatusesShow()
1666 api_statuses_show('json');
1670 * Test the api_statuses_show() function with an ID.
1673 public function testApiStatusesShowWithId()
1675 $this->app->argv[3] = 1;
1676 $result = api_statuses_show('json');
1677 $this->assertStatus($result['status']);
1681 * Test the api_statuses_show() function with the conversation parameter.
1684 public function testApiStatusesShowWithConversation()
1686 $this->app->argv[3] = 1;
1687 $_REQUEST['conversation'] = 1;
1688 $result = api_statuses_show('json');
1689 $this->assertNotEmpty($result['status']);
1690 foreach ($result['status'] as $status) {
1691 $this->assertStatus($status);
1696 * Test the api_statuses_show() function with an unallowed user.
1698 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1700 public function testApiStatusesShowWithUnallowedUser()
1702 $_SESSION['allow_api'] = false;
1703 $_GET['screen_name'] = $this->selfUser['nick'];
1704 api_statuses_show('json');
1708 * Test the api_conversation_show() function.
1710 * @expectedException Friendica\Network\HTTPException\BadRequestException
1712 public function testApiConversationShow()
1714 api_conversation_show('json');
1718 * Test the api_conversation_show() function with an ID.
1721 public function testApiConversationShowWithId()
1723 $this->app->argv[3] = 1;
1724 $_REQUEST['max_id'] = 10;
1725 $_REQUEST['page'] = -2;
1726 $result = api_conversation_show('json');
1727 $this->assertNotEmpty($result['status']);
1728 foreach ($result['status'] as $status) {
1729 $this->assertStatus($status);
1734 * Test the api_conversation_show() function with an unallowed user.
1736 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1738 public function testApiConversationShowWithUnallowedUser()
1740 $_SESSION['allow_api'] = false;
1741 $_GET['screen_name'] = $this->selfUser['nick'];
1742 api_conversation_show('json');
1746 * Test the api_statuses_repeat() function.
1748 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1750 public function testApiStatusesRepeat()
1752 api_statuses_repeat('json');
1756 * Test the api_statuses_repeat() function without an authenticated user.
1758 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1760 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1762 $_SESSION['authenticated'] = false;
1763 api_statuses_repeat('json');
1767 * Test the api_statuses_repeat() function with an ID.
1770 public function testApiStatusesRepeatWithId()
1772 $this->app->argv[3] = 1;
1773 $result = api_statuses_repeat('json');
1774 $this->assertStatus($result['status']);
1776 // Also test with a shared status
1777 $this->app->argv[3] = 5;
1778 $result = api_statuses_repeat('json');
1779 $this->assertStatus($result['status']);
1783 * Test the api_statuses_destroy() function.
1785 * @expectedException Friendica\Network\HTTPException\BadRequestException
1787 public function testApiStatusesDestroy()
1789 api_statuses_destroy('json');
1793 * Test the api_statuses_destroy() function without an authenticated user.
1795 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1797 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1799 $_SESSION['authenticated'] = false;
1800 api_statuses_destroy('json');
1804 * Test the api_statuses_destroy() function with an ID.
1807 public function testApiStatusesDestroyWithId()
1809 $this->app->argv[3] = 1;
1810 $result = api_statuses_destroy('json');
1811 $this->assertStatus($result['status']);
1815 * Test the api_statuses_mentions() function.
1818 public function testApiStatusesMentions()
1820 $this->app->user = ['nickname' => $this->selfUser['nick']];
1821 $_REQUEST['max_id'] = 10;
1822 $result = api_statuses_mentions('json');
1823 $this->assertEmpty($result['status']);
1824 // We should test with mentions in the database.
1828 * Test the api_statuses_mentions() function with a negative page parameter.
1831 public function testApiStatusesMentionsWithNegativePage()
1833 $_REQUEST['page'] = -2;
1834 $result = api_statuses_mentions('json');
1835 $this->assertEmpty($result['status']);
1839 * Test the api_statuses_mentions() function with an unallowed user.
1841 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1843 public function testApiStatusesMentionsWithUnallowedUser()
1845 $_SESSION['allow_api'] = false;
1846 $_GET['screen_name'] = $this->selfUser['nick'];
1847 api_statuses_mentions('json');
1851 * Test the api_statuses_mentions() function with an RSS result.
1854 public function testApiStatusesMentionsWithRss()
1856 $result = api_statuses_mentions('rss');
1857 $this->assertXml($result, 'statuses');
1861 * Test the api_statuses_user_timeline() function.
1864 public function testApiStatusesUserTimeline()
1866 $_REQUEST['max_id'] = 10;
1867 $_REQUEST['exclude_replies'] = true;
1868 $_REQUEST['conversation_id'] = 1;
1869 $result = api_statuses_user_timeline('json');
1870 $this->assertNotEmpty($result['status']);
1871 foreach ($result['status'] as $status) {
1872 $this->assertStatus($status);
1877 * Test the api_statuses_user_timeline() function with a negative page parameter.
1880 public function testApiStatusesUserTimelineWithNegativePage()
1882 $_REQUEST['page'] = -2;
1883 $result = api_statuses_user_timeline('json');
1884 $this->assertNotEmpty($result['status']);
1885 foreach ($result['status'] as $status) {
1886 $this->assertStatus($status);
1891 * Test the api_statuses_user_timeline() function with an RSS result.
1894 public function testApiStatusesUserTimelineWithRss()
1896 $result = api_statuses_user_timeline('rss');
1897 $this->assertXml($result, 'statuses');
1901 * Test the api_statuses_user_timeline() function with an unallowed user.
1903 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1905 public function testApiStatusesUserTimelineWithUnallowedUser()
1907 $_SESSION['allow_api'] = false;
1908 $_GET['screen_name'] = $this->selfUser['nick'];
1909 api_statuses_user_timeline('json');
1913 * Test the api_favorites_create_destroy() function.
1915 * @expectedException Friendica\Network\HTTPException\BadRequestException
1917 public function testApiFavoritesCreateDestroy()
1919 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1920 $this->app->argc = count($this->app->argv);
1921 api_favorites_create_destroy('json');
1925 * Test the api_favorites_create_destroy() function with an invalid ID.
1927 * @expectedException Friendica\Network\HTTPException\BadRequestException
1929 public function testApiFavoritesCreateDestroyWithInvalidId()
1931 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1932 $this->app->argc = count($this->app->argv);
1933 api_favorites_create_destroy('json');
1937 * Test the api_favorites_create_destroy() function with an invalid action.
1939 * @expectedException Friendica\Network\HTTPException\BadRequestException
1941 public function testApiFavoritesCreateDestroyWithInvalidAction()
1943 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1944 $this->app->argc = count($this->app->argv);
1945 $_REQUEST['id'] = 1;
1946 api_favorites_create_destroy('json');
1950 * Test the api_favorites_create_destroy() function with the create action.
1953 public function testApiFavoritesCreateDestroyWithCreateAction()
1955 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1956 $this->app->argc = count($this->app->argv);
1957 $_REQUEST['id'] = 3;
1958 $result = api_favorites_create_destroy('json');
1959 $this->assertStatus($result['status']);
1963 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1966 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1968 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1969 $this->app->argc = count($this->app->argv);
1970 $_REQUEST['id'] = 3;
1971 $result = api_favorites_create_destroy('rss');
1972 $this->assertXml($result, 'status');
1976 * Test the api_favorites_create_destroy() function with the destroy action.
1979 public function testApiFavoritesCreateDestroyWithDestroyAction()
1981 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1982 $this->app->argc = count($this->app->argv);
1983 $_REQUEST['id'] = 3;
1984 $result = api_favorites_create_destroy('json');
1985 $this->assertStatus($result['status']);
1989 * Test the api_favorites_create_destroy() function without an authenticated user.
1991 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1993 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1995 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1996 $this->app->argc = count($this->app->argv);
1997 $_SESSION['authenticated'] = false;
1998 api_favorites_create_destroy('json');
2002 * Test the api_favorites() function.
2005 public function testApiFavorites()
2007 $_REQUEST['page'] = -1;
2008 $_REQUEST['max_id'] = 10;
2009 $result = api_favorites('json');
2010 foreach ($result['status'] as $status) {
2011 $this->assertStatus($status);
2016 * Test the api_favorites() function with an RSS result.
2019 public function testApiFavoritesWithRss()
2021 $result = api_favorites('rss');
2022 $this->assertXml($result, 'statuses');
2026 * Test the api_favorites() function with an unallowed user.
2028 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2030 public function testApiFavoritesWithUnallowedUser()
2032 $_SESSION['allow_api'] = false;
2033 $_GET['screen_name'] = $this->selfUser['nick'];
2034 api_favorites('json');
2038 * Test the api_format_messages() function.
2041 public function testApiFormatMessages()
2043 $result = api_format_messages(
2044 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2045 ['id' => 2, 'screen_name' => 'recipient_name'],
2046 ['id' => 3, 'screen_name' => 'sender_name']
2048 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2049 $this->assertEquals(1, $result['id']);
2050 $this->assertEquals(2, $result['recipient_id']);
2051 $this->assertEquals(3, $result['sender_id']);
2052 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2053 $this->assertEquals('sender_name', $result['sender_screen_name']);
2057 * Test the api_format_messages() function with HTML.
2060 public function testApiFormatMessagesWithHtmlText()
2062 $_GET['getText'] = 'html';
2063 $result = api_format_messages(
2064 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2065 ['id' => 2, 'screen_name' => 'recipient_name'],
2066 ['id' => 3, 'screen_name' => 'sender_name']
2068 $this->assertEquals('item_title', $result['title']);
2069 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2073 * Test the api_format_messages() function with plain text.
2076 public function testApiFormatMessagesWithPlainText()
2078 $_GET['getText'] = 'plain';
2079 $result = api_format_messages(
2080 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2081 ['id' => 2, 'screen_name' => 'recipient_name'],
2082 ['id' => 3, 'screen_name' => 'sender_name']
2084 $this->assertEquals('item_title', $result['title']);
2085 $this->assertEquals('item_body', $result['text']);
2089 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2092 public function testApiFormatMessagesWithoutUserObjects()
2094 $_GET['getUserObjects'] = 'false';
2095 $result = api_format_messages(
2096 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2097 ['id' => 2, 'screen_name' => 'recipient_name'],
2098 ['id' => 3, 'screen_name' => 'sender_name']
2100 $this->assertTrue(!isset($result['sender']));
2101 $this->assertTrue(!isset($result['recipient']));
2105 * Test the api_convert_item() function.
2108 public function testApiConvertItem()
2110 $result = api_convert_item(
2112 'network' => 'feed',
2113 'title' => 'item_title',
2114 // We need a long string to test that it is correctly cut
2115 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2116 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2117 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2118 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2119 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2120 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2121 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2122 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2123 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2124 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2125 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2126 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2127 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2128 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2129 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2130 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2131 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2132 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2133 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2134 'repellat officia illum quos impedit quam iste esse unde qui '.
2135 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2136 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2137 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2138 'plink' => 'item_plink'
2141 $this->assertStringStartsWith('item_title', $result['text']);
2142 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2146 * Test the api_convert_item() function with an empty item body.
2149 public function testApiConvertItemWithoutBody()
2151 $result = api_convert_item(
2153 'network' => 'feed',
2154 'title' => 'item_title',
2156 'plink' => 'item_plink'
2159 $this->assertEquals('item_title', $result['text']);
2160 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2164 * Test the api_convert_item() function with the title in the body.
2167 public function testApiConvertItemWithTitleInBody()
2169 $result = api_convert_item(
2171 'title' => 'item_title',
2172 'body' => 'item_title item_body'
2175 $this->assertEquals('item_title item_body', $result['text']);
2176 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2180 * Test the api_get_attachments() function.
2183 public function testApiGetAttachments()
2186 $this->assertEmpty(api_get_attachments($body));
2190 * Test the api_get_attachments() function with an img tag.
2193 public function testApiGetAttachmentsWithImage()
2195 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2196 $this->assertInternalType('array', api_get_attachments($body));
2200 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2203 public function testApiGetAttachmentsWithImageAndAndStatus()
2205 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2206 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2207 $this->assertInternalType('array', api_get_attachments($body));
2211 * Test the api_get_entitities() function.
2214 public function testApiGetEntitities()
2217 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2221 * Test the api_get_entitities() function with the include_entities parameter.
2224 public function testApiGetEntititiesWithIncludeEntities()
2226 $_REQUEST['include_entities'] = 'true';
2228 $result = api_get_entitities($text, 'bbcode');
2229 $this->assertInternalType('array', $result['hashtags']);
2230 $this->assertInternalType('array', $result['symbols']);
2231 $this->assertInternalType('array', $result['urls']);
2232 $this->assertInternalType('array', $result['user_mentions']);
2236 * Test the api_format_items_embeded_images() function.
2239 public function testApiFormatItemsEmbededImages()
2241 $this->assertEquals(
2242 'text ' . System::baseUrl() . '/display/item_guid',
2243 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2248 * Test the api_contactlink_to_array() function.
2251 public function testApiContactlinkToArray()
2253 $this->assertEquals(
2258 api_contactlink_to_array('text')
2263 * Test the api_contactlink_to_array() function with an URL.
2266 public function testApiContactlinkToArrayWithUrl()
2268 $this->assertEquals(
2270 'name' => ['link_text'],
2273 api_contactlink_to_array('text <a href="url">link_text</a>')
2278 * Test the api_format_items_activities() function.
2281 public function testApiFormatItemsActivities()
2283 $item = ['uid' => 0, 'uri' => ''];
2284 $result = api_format_items_activities($item);
2285 $this->assertArrayHasKey('like', $result);
2286 $this->assertArrayHasKey('dislike', $result);
2287 $this->assertArrayHasKey('attendyes', $result);
2288 $this->assertArrayHasKey('attendno', $result);
2289 $this->assertArrayHasKey('attendmaybe', $result);
2293 * Test the api_format_items_activities() function with an XML result.
2296 public function testApiFormatItemsActivitiesWithXml()
2298 $item = ['uid' => 0, 'uri' => ''];
2299 $result = api_format_items_activities($item, 'xml');
2300 $this->assertArrayHasKey('friendica:like', $result);
2301 $this->assertArrayHasKey('friendica:dislike', $result);
2302 $this->assertArrayHasKey('friendica:attendyes', $result);
2303 $this->assertArrayHasKey('friendica:attendno', $result);
2304 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2308 * Test the api_format_items_profiles() function.
2311 public function testApiFormatItemsProfiles()
2314 'id' => 'profile_id',
2315 'profile-name' => 'profile_name',
2316 'is-default' => true,
2317 'hide-friends' => true,
2318 'photo' => 'profile_photo',
2319 'thumb' => 'profile_thumb',
2321 'net-publish' => true,
2322 'pdesc' => 'description',
2323 'dob' => 'date_of_birth',
2324 'address' => 'address',
2325 'locality' => 'city',
2326 'region' => 'region',
2327 'postal-code' => 'postal_code',
2328 'country-name' => 'country',
2329 'hometown' => 'hometown',
2330 'gender' => 'gender',
2331 'marital' => 'marital',
2332 'with' => 'marital_with',
2333 'howlong' => 'marital_since',
2334 'sexual' => 'sexual',
2335 'politic' => 'politic',
2336 'religion' => 'religion',
2337 'pub_keywords' => 'public_keywords',
2338 'prv_keywords' => 'private_keywords',
2341 'dislikes' => 'dislikes',
2347 'interest' => 'interest',
2348 'romance' => 'romance',
2350 'education' => 'education',
2351 'contact' => 'social_networks',
2352 'homepage' => 'homepage'
2354 $result = api_format_items_profiles($profile_row);
2355 $this->assertEquals(
2357 'profile_id' => 'profile_id',
2358 'profile_name' => 'profile_name',
2359 'is_default' => true,
2360 'hide_friends' => true,
2361 'profile_photo' => 'profile_photo',
2362 'profile_thumb' => 'profile_thumb',
2364 'net_publish' => true,
2365 'description' => 'description',
2366 'date_of_birth' => 'date_of_birth',
2367 'address' => 'address',
2369 'region' => 'region',
2370 'postal_code' => 'postal_code',
2371 'country' => 'country',
2372 'hometown' => 'hometown',
2373 'gender' => 'gender',
2374 'marital' => 'marital',
2375 'marital_with' => 'marital_with',
2376 'marital_since' => 'marital_since',
2377 'sexual' => 'sexual',
2378 'politic' => 'politic',
2379 'religion' => 'religion',
2380 'public_keywords' => 'public_keywords',
2381 'private_keywords' => 'private_keywords',
2384 'dislikes' => 'dislikes',
2390 'interest' => 'interest',
2391 'romance' => 'romance',
2393 'education' => 'education',
2394 'social_networks' => 'social_networks',
2395 'homepage' => 'homepage',
2403 * Test the api_format_items() function.
2406 public function testApiFormatItems()
2410 'item_network' => 'item_network',
2416 'author-network' => Protocol::DFRN,
2417 'author-link' => 'http://localhost/profile/othercontact',
2421 $result = api_format_items($items, ['id' => 0], true);
2422 foreach ($result as $status) {
2423 $this->assertStatus($status);
2428 * Test the api_format_items() function with an XML result.
2431 public function testApiFormatItemsWithXml()
2439 'author-network' => Protocol::DFRN,
2440 'author-link' => 'http://localhost/profile/othercontact',
2444 $result = api_format_items($items, ['id' => 0], true, 'xml');
2445 foreach ($result as $status) {
2446 $this->assertStatus($status);
2451 * Test the api_format_items() function.
2454 public function testApiAccountRateLimitStatus()
2456 $result = api_account_rate_limit_status('json');
2457 $this->assertEquals(150, $result['hash']['remaining_hits']);
2458 $this->assertEquals(150, $result['hash']['hourly_limit']);
2459 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2463 * Test the api_format_items() function with an XML result.
2466 public function testApiAccountRateLimitStatusWithXml()
2468 $result = api_account_rate_limit_status('xml');
2469 $this->assertXml($result, 'hash');
2473 * Test the api_help_test() function.
2476 public function testApiHelpTest()
2478 $result = api_help_test('json');
2479 $this->assertEquals(['ok' => 'ok'], $result);
2483 * Test the api_help_test() function with an XML result.
2486 public function testApiHelpTestWithXml()
2488 $result = api_help_test('xml');
2489 $this->assertXml($result, 'ok');
2493 * Test the api_lists_list() function.
2496 public function testApiListsList()
2498 $result = api_lists_list('json');
2499 $this->assertEquals(['lists_list' => []], $result);
2503 * Test the api_lists_ownerships() function.
2506 public function testApiListsOwnerships()
2508 $result = api_lists_ownerships('json');
2509 foreach ($result['lists']['lists'] as $list) {
2510 $this->assertList($list);
2515 * Test the api_lists_ownerships() function without an authenticated user.
2517 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2519 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2521 $_SESSION['authenticated'] = false;
2522 api_lists_ownerships('json');
2526 * Test the api_lists_statuses() function.
2527 * @expectedException Friendica\Network\HTTPException\BadRequestException
2530 public function testApiListsStatuses()
2532 api_lists_statuses('json');
2536 * Test the api_lists_statuses() function with a list ID.
2539 public function testApiListsStatusesWithListId()
2541 $_REQUEST['list_id'] = 1;
2542 $_REQUEST['page'] = -1;
2543 $_REQUEST['max_id'] = 10;
2544 $result = api_lists_statuses('json');
2545 foreach ($result['status'] as $status) {
2546 $this->assertStatus($status);
2551 * Test the api_lists_statuses() function with a list ID and a RSS result.
2554 public function testApiListsStatusesWithListIdAndRss()
2556 $_REQUEST['list_id'] = 1;
2557 $result = api_lists_statuses('rss');
2558 $this->assertXml($result, 'statuses');
2562 * Test the api_lists_statuses() function with an unallowed user.
2564 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2566 public function testApiListsStatusesWithUnallowedUser()
2568 $_SESSION['allow_api'] = false;
2569 $_GET['screen_name'] = $this->selfUser['nick'];
2570 api_lists_statuses('json');
2574 * Test the api_statuses_f() function.
2577 public function testApiStatusesFWithFriends()
2580 $result = api_statuses_f('friends');
2581 $this->assertArrayHasKey('user', $result);
2585 * Test the api_statuses_f() function.
2588 public function testApiStatusesFWithFollowers()
2590 $result = api_statuses_f('followers');
2591 $this->assertArrayHasKey('user', $result);
2595 * Test the api_statuses_f() function.
2598 public function testApiStatusesFWithBlocks()
2600 $result = api_statuses_f('blocks');
2601 $this->assertArrayHasKey('user', $result);
2605 * Test the api_statuses_f() function.
2608 public function testApiStatusesFWithIncoming()
2610 $result = api_statuses_f('incoming');
2611 $this->assertArrayHasKey('user', $result);
2615 * Test the api_statuses_f() function an undefined cursor GET variable.
2618 public function testApiStatusesFWithUndefinedCursor()
2620 $_GET['cursor'] = 'undefined';
2621 $this->assertFalse(api_statuses_f('friends'));
2625 * Test the api_statuses_friends() function.
2628 public function testApiStatusesFriends()
2630 $result = api_statuses_friends('json');
2631 $this->assertArrayHasKey('user', $result);
2635 * Test the api_statuses_friends() function an undefined cursor GET variable.
2638 public function testApiStatusesFriendsWithUndefinedCursor()
2640 $_GET['cursor'] = 'undefined';
2641 $this->assertFalse(api_statuses_friends('json'));
2645 * Test the api_statuses_followers() function.
2648 public function testApiStatusesFollowers()
2650 $result = api_statuses_followers('json');
2651 $this->assertArrayHasKey('user', $result);
2655 * Test the api_statuses_followers() function an undefined cursor GET variable.
2658 public function testApiStatusesFollowersWithUndefinedCursor()
2660 $_GET['cursor'] = 'undefined';
2661 $this->assertFalse(api_statuses_followers('json'));
2665 * Test the api_blocks_list() function.
2668 public function testApiBlocksList()
2670 $result = api_blocks_list('json');
2671 $this->assertArrayHasKey('user', $result);
2675 * Test the api_blocks_list() function an undefined cursor GET variable.
2678 public function testApiBlocksListWithUndefinedCursor()
2680 $_GET['cursor'] = 'undefined';
2681 $this->assertFalse(api_blocks_list('json'));
2685 * Test the api_friendships_incoming() function.
2688 public function testApiFriendshipsIncoming()
2690 $result = api_friendships_incoming('json');
2691 $this->assertArrayHasKey('id', $result);
2695 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2698 public function testApiFriendshipsIncomingWithUndefinedCursor()
2700 $_GET['cursor'] = 'undefined';
2701 $this->assertFalse(api_friendships_incoming('json'));
2705 * Test the api_statusnet_config() function.
2708 public function testApiStatusnetConfig()
2710 $result = api_statusnet_config('json');
2711 $this->assertEquals('localhost', $result['config']['site']['server']);
2712 $this->assertEquals('default', $result['config']['site']['theme']);
2713 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2714 $this->assertTrue($result['config']['site']['fancy']);
2715 $this->assertEquals('en', $result['config']['site']['language']);
2716 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2717 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2718 $this->assertEquals('false', $result['config']['site']['private']);
2719 $this->assertEquals('false', $result['config']['site']['ssl']);
2720 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2724 * Test the api_statusnet_version() function.
2727 public function testApiStatusnetVersion()
2729 $result = api_statusnet_version('json');
2730 $this->assertEquals('0.9.7', $result['version']);
2734 * Test the api_ff_ids() function.
2737 public function testApiFfIds()
2739 $result = api_ff_ids('json');
2740 $this->assertNull($result);
2744 * Test the api_ff_ids() function with a result.
2747 public function testApiFfIdsWithResult()
2749 $this->markTestIncomplete();
2753 * Test the api_ff_ids() function without an authenticated user.
2755 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2757 public function testApiFfIdsWithoutAuthenticatedUser()
2759 $_SESSION['authenticated'] = false;
2764 * Test the api_friends_ids() function.
2767 public function testApiFriendsIds()
2769 $result = api_friends_ids('json');
2770 $this->assertNull($result);
2774 * Test the api_followers_ids() function.
2777 public function testApiFollowersIds()
2779 $result = api_followers_ids('json');
2780 $this->assertNull($result);
2784 * Test the api_direct_messages_new() function.
2787 public function testApiDirectMessagesNew()
2789 $result = api_direct_messages_new('json');
2790 $this->assertNull($result);
2794 * Test the api_direct_messages_new() function without an authenticated user.
2796 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2798 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2800 $_SESSION['authenticated'] = false;
2801 api_direct_messages_new('json');
2805 * Test the api_direct_messages_new() function with an user ID.
2808 public function testApiDirectMessagesNewWithUserId()
2810 $_POST['text'] = 'message_text';
2811 $_POST['user_id'] = $this->otherUser['id'];
2812 $result = api_direct_messages_new('json');
2813 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2817 * Test the api_direct_messages_new() function with a screen name.
2820 public function testApiDirectMessagesNewWithScreenName()
2822 $_POST['text'] = 'message_text';
2823 $_POST['screen_name'] = $this->friendUser['nick'];
2824 $result = api_direct_messages_new('json');
2825 $this->assertEquals(1, $result['direct_message']['id']);
2826 $this->assertContains('message_text', $result['direct_message']['text']);
2827 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2828 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2832 * Test the api_direct_messages_new() function with a title.
2835 public function testApiDirectMessagesNewWithTitle()
2837 $_POST['text'] = 'message_text';
2838 $_POST['screen_name'] = $this->friendUser['nick'];
2839 $_REQUEST['title'] = 'message_title';
2840 $result = api_direct_messages_new('json');
2841 $this->assertEquals(1, $result['direct_message']['id']);
2842 $this->assertContains('message_text', $result['direct_message']['text']);
2843 $this->assertContains('message_title', $result['direct_message']['text']);
2844 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2845 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2849 * Test the api_direct_messages_new() function with an RSS result.
2852 public function testApiDirectMessagesNewWithRss()
2854 $_POST['text'] = 'message_text';
2855 $_POST['screen_name'] = $this->friendUser['nick'];
2856 $result = api_direct_messages_new('rss');
2857 $this->assertXml($result, 'direct-messages');
2861 * Test the api_direct_messages_destroy() function.
2863 * @expectedException Friendica\Network\HTTPException\BadRequestException
2865 public function testApiDirectMessagesDestroy()
2867 api_direct_messages_destroy('json');
2871 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2874 public function testApiDirectMessagesDestroyWithVerbose()
2876 $_GET['friendica_verbose'] = 'true';
2877 $result = api_direct_messages_destroy('json');
2878 $this->assertEquals(
2881 'result' => 'error',
2882 'message' => 'message id or parenturi not specified'
2890 * Test the api_direct_messages_destroy() function without an authenticated user.
2892 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2894 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2896 $_SESSION['authenticated'] = false;
2897 api_direct_messages_destroy('json');
2901 * Test the api_direct_messages_destroy() function with a non-zero ID.
2903 * @expectedException Friendica\Network\HTTPException\BadRequestException
2905 public function testApiDirectMessagesDestroyWithId()
2907 $_REQUEST['id'] = 1;
2908 api_direct_messages_destroy('json');
2912 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2915 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2917 $_REQUEST['id'] = 1;
2918 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2919 $_GET['friendica_verbose'] = 'true';
2920 $result = api_direct_messages_destroy('json');
2921 $this->assertEquals(
2924 'result' => 'error',
2925 'message' => 'message id not in database'
2933 * Test the api_direct_messages_destroy() function with a non-zero ID.
2936 public function testApiDirectMessagesDestroyWithCorrectId()
2938 $this->markTestIncomplete('We need to add a dataset for this.');
2942 * Test the api_direct_messages_box() function.
2945 public function testApiDirectMessagesBoxWithSentbox()
2947 $_REQUEST['page'] = -1;
2948 $_REQUEST['max_id'] = 10;
2949 $result = api_direct_messages_box('json', 'sentbox', 'false');
2950 $this->assertArrayHasKey('direct_message', $result);
2954 * Test the api_direct_messages_box() function.
2957 public function testApiDirectMessagesBoxWithConversation()
2959 $result = api_direct_messages_box('json', 'conversation', 'false');
2960 $this->assertArrayHasKey('direct_message', $result);
2964 * Test the api_direct_messages_box() function.
2967 public function testApiDirectMessagesBoxWithAll()
2969 $result = api_direct_messages_box('json', 'all', 'false');
2970 $this->assertArrayHasKey('direct_message', $result);
2974 * Test the api_direct_messages_box() function.
2977 public function testApiDirectMessagesBoxWithInbox()
2979 $result = api_direct_messages_box('json', 'inbox', 'false');
2980 $this->assertArrayHasKey('direct_message', $result);
2984 * Test the api_direct_messages_box() function.
2987 public function testApiDirectMessagesBoxWithVerbose()
2989 $result = api_direct_messages_box('json', 'sentbox', 'true');
2990 $this->assertEquals(
2993 'result' => 'error',
2994 'message' => 'no mails available'
3002 * Test the api_direct_messages_box() function with a RSS result.
3005 public function testApiDirectMessagesBoxWithRss()
3007 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3008 $this->assertXml($result, 'direct-messages');
3012 * Test the api_direct_messages_box() function without an authenticated user.
3014 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3016 public function testApiDirectMessagesBoxWithUnallowedUser()
3018 $_SESSION['allow_api'] = false;
3019 $_GET['screen_name'] = $this->selfUser['nick'];
3020 api_direct_messages_box('json', 'sentbox', 'false');
3024 * Test the api_direct_messages_sentbox() function.
3027 public function testApiDirectMessagesSentbox()
3029 $result = api_direct_messages_sentbox('json');
3030 $this->assertArrayHasKey('direct_message', $result);
3034 * Test the api_direct_messages_inbox() function.
3037 public function testApiDirectMessagesInbox()
3039 $result = api_direct_messages_inbox('json');
3040 $this->assertArrayHasKey('direct_message', $result);
3044 * Test the api_direct_messages_all() function.
3047 public function testApiDirectMessagesAll()
3049 $result = api_direct_messages_all('json');
3050 $this->assertArrayHasKey('direct_message', $result);
3054 * Test the api_direct_messages_conversation() function.
3057 public function testApiDirectMessagesConversation()
3059 $result = api_direct_messages_conversation('json');
3060 $this->assertArrayHasKey('direct_message', $result);
3064 * Test the api_oauth_request_token() function.
3067 public function testApiOauthRequestToken()
3069 $this->markTestIncomplete('killme() kills phpunit as well');
3073 * Test the api_oauth_access_token() function.
3076 public function testApiOauthAccessToken()
3078 $this->markTestIncomplete('killme() kills phpunit as well');
3082 * Test the api_fr_photoalbum_delete() function.
3084 * @expectedException Friendica\Network\HTTPException\BadRequestException
3086 public function testApiFrPhotoalbumDelete()
3088 api_fr_photoalbum_delete('json');
3092 * Test the api_fr_photoalbum_delete() function with an album name.
3094 * @expectedException Friendica\Network\HTTPException\BadRequestException
3096 public function testApiFrPhotoalbumDeleteWithAlbum()
3098 $_REQUEST['album'] = 'album_name';
3099 api_fr_photoalbum_delete('json');
3103 * Test the api_fr_photoalbum_delete() function with an album name.
3106 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3108 $this->markTestIncomplete('We need to add a dataset for this.');
3112 * Test the api_fr_photoalbum_delete() function.
3114 * @expectedException Friendica\Network\HTTPException\BadRequestException
3116 public function testApiFrPhotoalbumUpdate()
3118 api_fr_photoalbum_update('json');
3122 * Test the api_fr_photoalbum_delete() function with an album name.
3124 * @expectedException Friendica\Network\HTTPException\BadRequestException
3126 public function testApiFrPhotoalbumUpdateWithAlbum()
3128 $_REQUEST['album'] = 'album_name';
3129 api_fr_photoalbum_update('json');
3133 * Test the api_fr_photoalbum_delete() function with an album name.
3135 * @expectedException Friendica\Network\HTTPException\BadRequestException
3137 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3139 $_REQUEST['album'] = 'album_name';
3140 $_REQUEST['album_new'] = 'album_name';
3141 api_fr_photoalbum_update('json');
3145 * Test the api_fr_photoalbum_update() function without an authenticated user.
3147 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3149 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3151 $_SESSION['authenticated'] = false;
3152 api_fr_photoalbum_update('json');
3156 * Test the api_fr_photoalbum_delete() function with an album name.
3159 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3161 $this->markTestIncomplete('We need to add a dataset for this.');
3165 * Test the api_fr_photos_list() function.
3168 public function testApiFrPhotosList()
3170 $result = api_fr_photos_list('json');
3171 $this->assertArrayHasKey('photo', $result);
3175 * Test the api_fr_photos_list() function without an authenticated user.
3177 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3179 public function testApiFrPhotosListWithoutAuthenticatedUser()
3181 $_SESSION['authenticated'] = false;
3182 api_fr_photos_list('json');
3186 * Test the api_fr_photo_create_update() function.
3188 * @expectedException Friendica\Network\HTTPException\BadRequestException
3190 public function testApiFrPhotoCreateUpdate()
3192 api_fr_photo_create_update('json');
3196 * Test the api_fr_photo_create_update() function without an authenticated user.
3198 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3200 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3202 $_SESSION['authenticated'] = false;
3203 api_fr_photo_create_update('json');
3207 * Test the api_fr_photo_create_update() function with an album name.
3209 * @expectedException Friendica\Network\HTTPException\BadRequestException
3211 public function testApiFrPhotoCreateUpdateWithAlbum()
3213 $_REQUEST['album'] = 'album_name';
3214 api_fr_photo_create_update('json');
3218 * Test the api_fr_photo_create_update() function with the update mode.
3221 public function testApiFrPhotoCreateUpdateWithUpdate()
3223 $this->markTestIncomplete('We need to create a dataset for this');
3227 * Test the api_fr_photo_create_update() function with an uploaded file.
3230 public function testApiFrPhotoCreateUpdateWithFile()
3232 $this->markTestIncomplete();
3236 * Test the api_fr_photo_delete() function.
3238 * @expectedException Friendica\Network\HTTPException\BadRequestException
3240 public function testApiFrPhotoDelete()
3242 api_fr_photo_delete('json');
3246 * Test the api_fr_photo_delete() function without an authenticated user.
3248 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3250 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3252 $_SESSION['authenticated'] = false;
3253 api_fr_photo_delete('json');
3257 * Test the api_fr_photo_delete() function with a photo ID.
3259 * @expectedException Friendica\Network\HTTPException\BadRequestException
3261 public function testApiFrPhotoDeleteWithPhotoId()
3263 $_REQUEST['photo_id'] = 1;
3264 api_fr_photo_delete('json');
3268 * Test the api_fr_photo_delete() function with a correct photo ID.
3271 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3273 $this->markTestIncomplete('We need to create a dataset for this.');
3277 * Test the api_fr_photo_detail() function.
3279 * @expectedException Friendica\Network\HTTPException\BadRequestException
3281 public function testApiFrPhotoDetail()
3283 api_fr_photo_detail('json');
3287 * Test the api_fr_photo_detail() function without an authenticated user.
3289 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3291 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3293 $_SESSION['authenticated'] = false;
3294 api_fr_photo_detail('json');
3298 * Test the api_fr_photo_detail() function with a photo ID.
3300 * @expectedException Friendica\Network\HTTPException\NotFoundException
3302 public function testApiFrPhotoDetailWithPhotoId()
3304 $_REQUEST['photo_id'] = 1;
3305 api_fr_photo_detail('json');
3309 * Test the api_fr_photo_detail() function with a correct photo ID.
3312 public function testApiFrPhotoDetailCorrectPhotoId()
3314 $this->markTestIncomplete('We need to create a dataset for this.');
3318 * Test the api_account_update_profile_image() function.
3320 * @expectedException Friendica\Network\HTTPException\BadRequestException
3322 public function testApiAccountUpdateProfileImage()
3324 api_account_update_profile_image('json');
3328 * Test the api_account_update_profile_image() function without an authenticated user.
3330 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3332 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3334 $_SESSION['authenticated'] = false;
3335 api_account_update_profile_image('json');
3339 * Test the api_account_update_profile_image() function with an uploaded file.
3341 * @expectedException Friendica\Network\HTTPException\BadRequestException
3343 public function testApiAccountUpdateProfileImageWithUpload()
3345 $this->markTestIncomplete();
3350 * Test the api_account_update_profile() function.
3353 public function testApiAccountUpdateProfile()
3355 $_POST['name'] = 'new_name';
3356 $_POST['description'] = 'new_description';
3357 $result = api_account_update_profile('json');
3358 // We can't use assertSelfUser() here because the user object is missing some properties.
3359 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3360 $this->assertEquals('DFRN', $result['user']['location']);
3361 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3362 $this->assertEquals('dfrn', $result['user']['network']);
3363 $this->assertEquals('new_name', $result['user']['name']);
3364 $this->assertEquals('new_description', $result['user']['description']);
3368 * Test the check_acl_input() function.
3371 public function testCheckAclInput()
3373 $result = check_acl_input('<aclstring>');
3374 // Where does this result come from?
3375 $this->assertEquals(1, $result);
3379 * Test the check_acl_input() function with an empty ACL string.
3382 public function testCheckAclInputWithEmptyAclString()
3384 $result = check_acl_input(' ');
3385 $this->assertFalse($result);
3389 * Test the save_media_to_database() function.
3392 public function testSaveMediaToDatabase()
3394 $this->markTestIncomplete();
3398 * Test the post_photo_item() function.
3401 public function testPostPhotoItem()
3403 $this->markTestIncomplete();
3407 * Test the prepare_photo_data() function.
3410 public function testPreparePhotoData()
3412 $this->markTestIncomplete();
3416 * Test the api_friendica_remoteauth() function.
3418 * @expectedException Friendica\Network\HTTPException\BadRequestException
3420 public function testApiFriendicaRemoteauth()
3422 api_friendica_remoteauth();
3426 * Test the api_friendica_remoteauth() function with an URL.
3428 * @expectedException Friendica\Network\HTTPException\BadRequestException
3430 public function testApiFriendicaRemoteauthWithUrl()
3432 $_GET['url'] = 'url';
3433 $_GET['c_url'] = 'url';
3434 api_friendica_remoteauth();
3438 * Test the api_friendica_remoteauth() function with a correct URL.
3441 public function testApiFriendicaRemoteauthWithCorrectUrl()
3443 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3444 $_GET['url'] = 'url';
3445 $_GET['c_url'] = $this->selfUser['nurl'];
3446 api_friendica_remoteauth();
3450 * Test the api_share_as_retweet() function.
3453 public function testApiShareAsRetweet()
3455 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3456 $result = api_share_as_retweet($item);
3457 $this->assertFalse($result);
3461 * Test the api_share_as_retweet() function with a valid item.
3464 public function testApiShareAsRetweetWithValidItem()
3466 $this->markTestIncomplete();
3470 * Test the api_get_nick() function.
3473 public function testApiGetNick()
3475 $result = api_get_nick($this->otherUser['nurl']);
3476 $this->assertEquals('othercontact', $result);
3480 * Test the api_get_nick() function with a wrong URL.
3483 public function testApiGetNickWithWrongUrl()
3485 $result = api_get_nick('wrong_url');
3486 $this->assertFalse($result);
3490 * Test the api_in_reply_to() function.
3493 public function testApiInReplyTo()
3495 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3496 $this->assertArrayHasKey('status_id', $result);
3497 $this->assertArrayHasKey('user_id', $result);
3498 $this->assertArrayHasKey('status_id_str', $result);
3499 $this->assertArrayHasKey('user_id_str', $result);
3500 $this->assertArrayHasKey('screen_name', $result);
3504 * Test the api_in_reply_to() function with a valid item.
3507 public function testApiInReplyToWithValidItem()
3509 $this->markTestIncomplete();
3513 * Test the api_clean_plain_items() function.
3516 public function testApiCleanPlainItems()
3518 $_REQUEST['include_entities'] = 'true';
3519 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3520 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3524 * Test the api_clean_attachments() function.
3527 public function testApiCleanAttachments()
3529 $this->markTestIncomplete();
3533 * Test the api_best_nickname() function.
3536 public function testApiBestNickname()
3539 $result = api_best_nickname($contacts);
3540 $this->assertNull($result);
3544 * Test the api_best_nickname() function with contacts.
3547 public function testApiBestNicknameWithContacts()
3549 $this->markTestIncomplete();
3553 * Test the api_friendica_group_show() function.
3556 public function testApiFriendicaGroupShow()
3558 $this->markTestIncomplete();
3562 * Test the api_friendica_group_delete() function.
3565 public function testApiFriendicaGroupDelete()
3567 $this->markTestIncomplete();
3571 * Test the api_lists_destroy() function.
3574 public function testApiListsDestroy()
3576 $this->markTestIncomplete();
3580 * Test the group_create() function.
3583 public function testGroupCreate()
3585 $this->markTestIncomplete();
3589 * Test the api_friendica_group_create() function.
3592 public function testApiFriendicaGroupCreate()
3594 $this->markTestIncomplete();
3598 * Test the api_lists_create() function.
3601 public function testApiListsCreate()
3603 $this->markTestIncomplete();
3607 * Test the api_friendica_group_update() function.
3610 public function testApiFriendicaGroupUpdate()
3612 $this->markTestIncomplete();
3616 * Test the api_lists_update() function.
3619 public function testApiListsUpdate()
3621 $this->markTestIncomplete();
3625 * Test the api_friendica_activity() function.
3628 public function testApiFriendicaActivity()
3630 $this->markTestIncomplete();
3634 * Test the api_friendica_notification() function.
3636 * @expectedException Friendica\Network\HTTPException\BadRequestException
3638 public function testApiFriendicaNotification()
3640 api_friendica_notification('json');
3644 * Test the api_friendica_notification() function without an authenticated user.
3646 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3648 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3650 $_SESSION['authenticated'] = false;
3651 api_friendica_notification('json');
3655 * Test the api_friendica_notification() function with an argument count.
3658 public function testApiFriendicaNotificationWithArgumentCount()
3660 $this->app->argv = ['api', 'friendica', 'notification'];
3661 $this->app->argc = count($this->app->argv);
3662 $result = api_friendica_notification('json');
3663 $this->assertEquals(['note' => false], $result);
3667 * Test the api_friendica_notification() function with an XML result.
3670 public function testApiFriendicaNotificationWithXmlResult()
3672 $this->app->argv = ['api', 'friendica', 'notification'];
3673 $this->app->argc = count($this->app->argv);
3674 $result = api_friendica_notification('xml');
3675 $this->assertXml($result, 'notes');
3679 * Test the api_friendica_notification_seen() function.
3682 public function testApiFriendicaNotificationSeen()
3684 $this->markTestIncomplete();
3688 * Test the api_friendica_direct_messages_setseen() function.
3691 public function testApiFriendicaDirectMessagesSetseen()
3693 $this->markTestIncomplete();
3697 * Test the api_friendica_direct_messages_search() function.
3700 public function testApiFriendicaDirectMessagesSearch()
3702 $this->markTestIncomplete();
3706 * Test the api_friendica_profile_show() function.
3709 public function testApiFriendicaProfileShow()
3711 $result = api_friendica_profile_show('json');
3712 // We can't use assertSelfUser() here because the user object is missing some properties.
3713 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3714 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3715 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3716 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3717 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3718 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3719 $this->assertFalse($result['$result']['multi_profiles']);
3723 * Test the api_friendica_profile_show() function with a profile ID.
3726 public function testApiFriendicaProfileShowWithProfileId()
3728 $this->markTestIncomplete('We need to add a dataset for this.');
3732 * Test the api_friendica_profile_show() function with a wrong profile ID.
3734 * @expectedException Friendica\Network\HTTPException\BadRequestException
3736 public function testApiFriendicaProfileShowWithWrongProfileId()
3738 $_REQUEST['profile_id'] = 666;
3739 api_friendica_profile_show('json');
3743 * Test the api_friendica_profile_show() function without an authenticated user.
3745 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3747 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3749 $_SESSION['authenticated'] = false;
3750 api_friendica_profile_show('json');
3754 * Test the api_saved_searches_list() function.
3757 public function testApiSavedSearchesList()
3759 $result = api_saved_searches_list('json');
3760 $this->assertEquals(1, $result['terms'][0]['id']);
3761 $this->assertEquals(1, $result['terms'][0]['id_str']);
3762 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3763 $this->assertEquals('Saved search', $result['terms'][0]['query']);