6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\Config\Cache\PConfigCache;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\System;
14 use Friendica\Factory;
15 use Friendica\Network\HTTPException;
16 use Friendica\Util\BaseURL;
17 use Monolog\Handler\TestHandler;
19 require_once __DIR__ . '/../../include/api.php';
22 * Tests for the API functions.
24 * Functions that use header() need to be tested in a separate process.
25 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
27 class ApiTest extends DatabaseTest
30 * @var TestHandler Can handle log-outputs
40 protected $friendUser;
44 protected $wrongUserId;
47 * Create variables used by tests.
49 public function setUp()
51 $configModel = new \Friendica\Model\Config\Config(self::$dba);
52 $config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
53 $pconfigModel = new \Friendica\Model\Config\PConfig(self::$dba);
54 Factory\ConfigFactory::createPConfig(self::$configCache, new PConfigCache(), $pconfigModel);
55 $logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
56 $baseUrl = new BaseURL($config, $_SERVER);
57 $router = new App\Router();
58 $this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
62 // User data that the test database is populated with
65 'name' => 'Self contact',
66 'nick' => 'selfcontact',
67 'nurl' => 'http://localhost/profile/selfcontact'
71 'name' => 'Friend contact',
72 'nick' => 'friendcontact',
73 'nurl' => 'http://localhost/profile/friendcontact'
77 'name' => 'othercontact',
78 'nick' => 'othercontact',
79 'nurl' => 'http://localhost/profile/othercontact'
82 // User ID that we know is not in the database
83 $this->wrongUserId = 666;
85 // Most API require login so we force the session
88 'authenticated' => true,
89 'uid' => $this->selfUser['id']
92 Config::set('system', 'url', 'http://localhost');
93 Config::set('system', 'hostname', 'localhost');
94 Config::set('system', 'worker_dont_fork', true);
97 Config::set('config', 'hostname', 'localhost');
98 Config::set('system', 'throttle_limit_day', 100);
99 Config::set('system', 'throttle_limit_week', 100);
100 Config::set('system', 'throttle_limit_month', 100);
101 Config::set('system', 'theme', 'system_theme');
105 * Cleanup variables used by tests.
107 protected function tearDown()
111 $this->app->argc = 1;
112 $this->app->argv = ['home'];
116 * Assert that an user array contains expected keys.
117 * @param array $user User array
120 private function assertSelfUser(array $user)
122 $this->assertEquals($this->selfUser['id'], $user['uid']);
123 $this->assertEquals($this->selfUser['id'], $user['cid']);
124 $this->assertEquals(1, $user['self']);
125 $this->assertEquals('DFRN', $user['location']);
126 $this->assertEquals($this->selfUser['name'], $user['name']);
127 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
128 $this->assertEquals('dfrn', $user['network']);
129 $this->assertTrue($user['verified']);
133 * Assert that an user array contains expected keys.
134 * @param array $user User array
137 private function assertOtherUser(array $user)
139 $this->assertEquals($this->otherUser['id'], $user['id']);
140 $this->assertEquals($this->otherUser['id'], $user['id_str']);
141 $this->assertEquals(0, $user['self']);
142 $this->assertEquals($this->otherUser['name'], $user['name']);
143 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
144 $this->assertFalse($user['verified']);
148 * Assert that a status array contains expected keys.
149 * @param array $status Status array
152 private function assertStatus(array $status)
154 $this->assertInternalType('string', $status['text']);
155 $this->assertInternalType('int', $status['id']);
156 // We could probably do more checks here.
160 * Assert that a list array contains expected keys.
161 * @param array $list List array
164 private function assertList(array $list)
166 $this->assertInternalType('string', $list['name']);
167 $this->assertInternalType('int', $list['id']);
168 $this->assertInternalType('string', $list['id_str']);
169 $this->assertContains($list['mode'], ['public', 'private']);
170 // We could probably do more checks here.
174 * Assert that the string is XML and contain the root element.
175 * @param string $result XML string
176 * @param string $root_element Root element name
179 private function assertXml($result, $root_element)
181 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
182 $this->assertContains('<'.$root_element, $result);
183 // We could probably do more checks here.
187 * Get the path to a temporary empty PNG image.
188 * @return string Path
190 private function getTempImage()
192 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
196 // Empty 1x1 px PNG image
197 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
205 * Test the api_user() function.
208 public function testApiUser()
210 $this->assertEquals($this->selfUser['id'], api_user());
214 * Test the api_user() function with an unallowed user.
217 public function testApiUserWithUnallowedUser()
219 $_SESSION = ['allow_api' => false];
220 $this->assertEquals(false, api_user());
224 * Test the api_source() function.
227 public function testApiSource()
229 $this->assertEquals('api', api_source());
233 * Test the api_source() function with a Twidere user agent.
236 public function testApiSourceWithTwidere()
238 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
239 $this->assertEquals('Twidere', api_source());
243 * Test the api_source() function with a GET parameter.
246 public function testApiSourceWithGet()
248 $_GET['source'] = 'source_name';
249 $this->assertEquals('source_name', api_source());
253 * Test the api_date() function.
256 public function testApiDate()
258 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
262 * Test the api_register_func() function.
265 public function testApiRegisterFunc()
277 $this->assertTrue($API['api_path']['auth']);
278 $this->assertEquals('method', $API['api_path']['method']);
279 $this->assertTrue(is_callable($API['api_path']['func']));
283 * Test the api_login() function without any login.
285 * @runInSeparateProcess
286 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
288 public function testApiLoginWithoutLogin()
290 api_login($this->app);
294 * Test the api_login() function with a bad login.
296 * @runInSeparateProcess
297 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
299 public function testApiLoginWithBadLogin()
301 $_SERVER['PHP_AUTH_USER'] = 'user@server';
302 api_login($this->app);
306 * Test the api_login() function with oAuth.
309 public function testApiLoginWithOauth()
311 $this->markTestIncomplete('Can we test this easily?');
315 * Test the api_login() function with authentication provided by an addon.
318 public function testApiLoginWithAddonAuth()
320 $this->markTestIncomplete('Can we test this easily?');
324 * Test the api_login() function with a correct login.
326 * @runInSeparateProcess
328 public function testApiLoginWithCorrectLogin()
330 $_SERVER['PHP_AUTH_USER'] = 'Test user';
331 $_SERVER['PHP_AUTH_PW'] = 'password';
332 api_login($this->app);
336 * Test the api_login() function with a remote user.
338 * @runInSeparateProcess
339 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
341 public function testApiLoginWithRemoteUser()
343 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
344 api_login($this->app);
348 * Test the api_check_method() function.
351 public function testApiCheckMethod()
353 $this->assertFalse(api_check_method('method'));
357 * Test the api_check_method() function with a correct method.
360 public function testApiCheckMethodWithCorrectMethod()
362 $_SERVER['REQUEST_METHOD'] = 'method';
363 $this->assertTrue(api_check_method('method'));
367 * Test the api_check_method() function with a wildcard.
370 public function testApiCheckMethodWithWildcard()
372 $this->assertTrue(api_check_method('*'));
376 * Test the api_call() function.
378 * @runInSeparateProcess
380 public function testApiCall()
384 'method' => 'method',
385 'func' => function () {
386 return ['data' => ['some_data']];
389 $_SERVER['REQUEST_METHOD'] = 'method';
390 $_GET['callback'] = 'callback_name';
392 $this->app->query_string = 'api_path';
394 'callback_name(["some_data"])',
400 * Test the api_call() function with the profiled enabled.
402 * @runInSeparateProcess
404 public function testApiCallWithProfiler()
408 'method' => 'method',
409 'func' => function () {
410 return ['data' => ['some_data']];
413 $_SERVER['REQUEST_METHOD'] = 'method';
414 Config::set('system', 'profiler', true);
415 Config::set('rendertime', 'callstack', true);
416 $this->app->callstack = [
417 'database' => ['some_function' => 200],
418 'database_write' => ['some_function' => 200],
419 'cache' => ['some_function' => 200],
420 'cache_write' => ['some_function' => 200],
421 'network' => ['some_function' => 200]
424 $this->app->query_string = 'api_path';
432 * Test the api_call() function without any result.
434 * @runInSeparateProcess
436 public function testApiCallWithNoResult()
440 'method' => 'method',
441 'func' => function () {
445 $_SERVER['REQUEST_METHOD'] = 'method';
447 $this->app->query_string = 'api_path';
449 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
455 * Test the api_call() function with an unimplemented API.
457 * @runInSeparateProcess
459 public function testApiCallWithUninplementedApi()
462 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
468 * Test the api_call() function with a JSON result.
470 * @runInSeparateProcess
472 public function testApiCallWithJson()
476 'method' => 'method',
477 'func' => function () {
478 return ['data' => ['some_data']];
481 $_SERVER['REQUEST_METHOD'] = 'method';
483 $this->app->query_string = 'api_path.json';
491 * Test the api_call() function with an XML result.
493 * @runInSeparateProcess
495 public function testApiCallWithXml()
499 'method' => 'method',
500 'func' => function () {
504 $_SERVER['REQUEST_METHOD'] = 'method';
506 $this->app->query_string = 'api_path.xml';
514 * Test the api_call() function with an RSS result.
516 * @runInSeparateProcess
518 public function testApiCallWithRss()
522 'method' => 'method',
523 'func' => function () {
527 $_SERVER['REQUEST_METHOD'] = 'method';
529 $this->app->query_string = 'api_path.rss';
531 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
538 * Test the api_call() function with an Atom result.
540 * @runInSeparateProcess
542 public function testApiCallWithAtom()
546 'method' => 'method',
547 'func' => function () {
551 $_SERVER['REQUEST_METHOD'] = 'method';
553 $this->app->query_string = 'api_path.atom';
555 '<?xml version="1.0" encoding="UTF-8"?>'."\n".
562 * Test the api_call() function with an unallowed method.
564 * @runInSeparateProcess
566 public function testApiCallWithWrongMethod()
569 $API['api_path'] = ['method' => 'method'];
571 $this->app->query_string = 'api_path';
573 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
579 * Test the api_call() function with an unauthorized user.
581 * @runInSeparateProcess
583 public function testApiCallWithWrongAuth()
587 'method' => 'method',
590 $_SERVER['REQUEST_METHOD'] = 'method';
591 $_SESSION['authenticated'] = false;
593 $this->app->query_string = 'api_path';
595 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
601 * Test the api_error() function with a JSON result.
603 * @runInSeparateProcess
605 public function testApiErrorWithJson()
608 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
609 api_error('json', new HTTPException\OKException('error_message'))
614 * Test the api_error() function with an XML result.
616 * @runInSeparateProcess
618 public function testApiErrorWithXml()
621 '<?xml version="1.0"?>'."\n".
622 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
623 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
624 'xmlns:georss="http://www.georss.org/georss">'."\n".
625 ' <error>error_message</error>'."\n".
626 ' <code>200 OK</code>'."\n".
629 api_error('xml', new HTTPException\OKException('error_message'))
634 * Test the api_error() function with an RSS result.
636 * @runInSeparateProcess
638 public function testApiErrorWithRss()
641 '<?xml version="1.0"?>'."\n".
642 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
643 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
644 'xmlns:georss="http://www.georss.org/georss">'."\n".
645 ' <error>error_message</error>'."\n".
646 ' <code>200 OK</code>'."\n".
649 api_error('rss', new HTTPException\OKException('error_message'))
654 * Test the api_error() function with an Atom result.
656 * @runInSeparateProcess
658 public function testApiErrorWithAtom()
661 '<?xml version="1.0"?>'."\n".
662 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
663 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
664 'xmlns:georss="http://www.georss.org/georss">'."\n".
665 ' <error>error_message</error>'."\n".
666 ' <code>200 OK</code>'."\n".
669 api_error('atom', new HTTPException\OKException('error_message'))
674 * Test the api_rss_extra() function.
677 public function testApiRssExtra()
679 $user_info = ['url' => 'user_url', 'lang' => 'en'];
680 $result = api_rss_extra($this->app, [], $user_info);
681 $this->assertEquals($user_info, $result['$user']);
682 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
683 $this->assertArrayHasKey('self', $result['$rss']);
684 $this->assertArrayHasKey('base', $result['$rss']);
685 $this->assertArrayHasKey('updated', $result['$rss']);
686 $this->assertArrayHasKey('atom_updated', $result['$rss']);
687 $this->assertArrayHasKey('language', $result['$rss']);
688 $this->assertArrayHasKey('logo', $result['$rss']);
692 * Test the api_rss_extra() function without any user info.
694 * @runInSeparateProcess
696 public function testApiRssExtraWithoutUserInfo()
698 $result = api_rss_extra($this->app, [], null);
699 $this->assertInternalType('array', $result['$user']);
700 $this->assertArrayHasKey('alternate', $result['$rss']);
701 $this->assertArrayHasKey('self', $result['$rss']);
702 $this->assertArrayHasKey('base', $result['$rss']);
703 $this->assertArrayHasKey('updated', $result['$rss']);
704 $this->assertArrayHasKey('atom_updated', $result['$rss']);
705 $this->assertArrayHasKey('language', $result['$rss']);
706 $this->assertArrayHasKey('logo', $result['$rss']);
710 * Test the api_unique_id_to_nurl() function.
713 public function testApiUniqueIdToNurl()
715 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
719 * Test the api_unique_id_to_nurl() function with a correct ID.
722 public function testApiUniqueIdToNurlWithCorrectId()
724 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
728 * Test the api_get_user() function.
730 * @runInSeparateProcess
732 public function testApiGetUser()
734 $user = api_get_user($this->app);
735 $this->assertSelfUser($user);
736 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
737 $this->assertEquals('6fdbe8', $user['profile_link_color']);
738 $this->assertEquals('ededed', $user['profile_background_color']);
742 * Test the api_get_user() function with a Frio schema.
744 * @runInSeparateProcess
746 public function testApiGetUserWithFrioSchema()
748 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
749 $user = api_get_user($this->app);
750 $this->assertSelfUser($user);
751 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
752 $this->assertEquals('6fdbe8', $user['profile_link_color']);
753 $this->assertEquals('ededed', $user['profile_background_color']);
757 * Test the api_get_user() function with a custom Frio schema.
759 * @runInSeparateProcess
761 public function testApiGetUserWithCustomFrioSchema()
763 $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
764 $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
765 $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
766 $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
767 $user = api_get_user($this->app);
768 $this->assertSelfUser($user);
769 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
770 $this->assertEquals('123456', $user['profile_link_color']);
771 $this->assertEquals('123456', $user['profile_background_color']);
775 * Test the api_get_user() function with an empty Frio schema.
777 * @runInSeparateProcess
779 public function testApiGetUserWithEmptyFrioSchema()
781 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
782 $user = api_get_user($this->app);
783 $this->assertSelfUser($user);
784 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
785 $this->assertEquals('6fdbe8', $user['profile_link_color']);
786 $this->assertEquals('ededed', $user['profile_background_color']);
790 * Test the api_get_user() function with an user that is not allowed to use the API.
792 * @runInSeparateProcess
794 public function testApiGetUserWithoutApiUser()
796 $_SERVER['PHP_AUTH_USER'] = 'Test user';
797 $_SERVER['PHP_AUTH_PW'] = 'password';
798 $_SESSION['allow_api'] = false;
799 $this->assertFalse(api_get_user($this->app));
803 * Test the api_get_user() function with an user ID in a GET parameter.
805 * @runInSeparateProcess
807 public function testApiGetUserWithGetId()
809 $_GET['user_id'] = $this->otherUser['id'];
810 $this->assertOtherUser(api_get_user($this->app));
814 * Test the api_get_user() function with a wrong user ID in a GET parameter.
816 * @runInSeparateProcess
817 * @expectedException Friendica\Network\HTTPException\BadRequestException
819 public function testApiGetUserWithWrongGetId()
821 $_GET['user_id'] = $this->wrongUserId;
822 $this->assertOtherUser(api_get_user($this->app));
826 * Test the api_get_user() function with an user name in a GET parameter.
828 * @runInSeparateProcess
830 public function testApiGetUserWithGetName()
832 $_GET['screen_name'] = $this->selfUser['nick'];
833 $this->assertSelfUser(api_get_user($this->app));
837 * Test the api_get_user() function with a profile URL in a GET parameter.
839 * @runInSeparateProcess
841 public function testApiGetUserWithGetUrl()
843 $_GET['profileurl'] = $this->selfUser['nurl'];
844 $this->assertSelfUser(api_get_user($this->app));
848 * Test the api_get_user() function with an user ID in the API path.
850 * @runInSeparateProcess
852 public function testApiGetUserWithNumericCalledApi()
855 $called_api = ['api_path'];
856 $this->app->argv[1] = $this->otherUser['id'].'.json';
857 $this->assertOtherUser(api_get_user($this->app));
861 * Test the api_get_user() function with the $called_api global variable.
863 * @runInSeparateProcess
865 public function testApiGetUserWithCalledApi()
868 $called_api = ['api', 'api_path'];
869 $this->assertSelfUser(api_get_user($this->app));
873 * Test the api_get_user() function with a valid user.
875 * @runInSeparateProcess
877 public function testApiGetUserWithCorrectUser()
879 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
883 * Test the api_get_user() function with a wrong user ID.
885 * @runInSeparateProcess
886 * @expectedException Friendica\Network\HTTPException\BadRequestException
888 public function testApiGetUserWithWrongUser()
890 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
894 * Test the api_get_user() function with a 0 user ID.
896 * @runInSeparateProcess
898 public function testApiGetUserWithZeroUser()
900 $this->assertSelfUser(api_get_user($this->app, 0));
904 * Test the api_item_get_user() function.
906 * @runInSeparateProcess
908 public function testApiItemGetUser()
910 $users = api_item_get_user($this->app, []);
911 $this->assertSelfUser($users[0]);
915 * Test the api_item_get_user() function with a different item parent.
918 public function testApiItemGetUserWithDifferentParent()
920 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
921 $this->assertSelfUser($users[0]);
922 $this->assertEquals($users[0], $users[1]);
926 * Test the api_walk_recursive() function.
929 public function testApiWalkRecursive()
937 // Should we test this with a callback that actually does something?
945 * Test the api_walk_recursive() function with an array.
948 public function testApiWalkRecursiveWithArray()
950 $array = [['item1'], ['item2']];
956 // Should we test this with a callback that actually does something?
964 * Test the api_reformat_xml() function.
967 public function testApiReformatXml()
971 $this->assertTrue(api_reformat_xml($item, $key));
972 $this->assertEquals('true', $item);
976 * Test the api_reformat_xml() function with a statusnet_api key.
979 public function testApiReformatXmlWithStatusnetKey()
982 $key = 'statusnet_api';
983 $this->assertTrue(api_reformat_xml($item, $key));
984 $this->assertEquals('statusnet:api', $key);
988 * Test the api_reformat_xml() function with a friendica_api key.
991 public function testApiReformatXmlWithFriendicaKey()
994 $key = 'friendica_api';
995 $this->assertTrue(api_reformat_xml($item, $key));
996 $this->assertEquals('friendica:api', $key);
1000 * Test the api_create_xml() function.
1003 public function testApiCreateXml()
1005 $this->assertEquals(
1006 '<?xml version="1.0"?>'."\n".
1007 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1008 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1009 'xmlns:georss="http://www.georss.org/georss">'."\n".
1010 ' <data>some_data</data>'."\n".
1011 '</root_element>'."\n",
1012 api_create_xml(['data' => ['some_data']], 'root_element')
1017 * Test the api_create_xml() function without any XML namespace.
1020 public function testApiCreateXmlWithoutNamespaces()
1022 $this->assertEquals(
1023 '<?xml version="1.0"?>'."\n".
1025 ' <data>some_data</data>'."\n".
1027 api_create_xml(['data' => ['some_data']], 'ok')
1032 * Test the api_format_data() function.
1035 public function testApiFormatData()
1037 $data = ['some_data'];
1038 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1042 * Test the api_format_data() function with an XML result.
1045 public function testApiFormatDataWithXml()
1047 $this->assertEquals(
1048 '<?xml version="1.0"?>'."\n".
1049 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1050 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1051 'xmlns:georss="http://www.georss.org/georss">'."\n".
1052 ' <data>some_data</data>'."\n".
1053 '</root_element>'."\n",
1054 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1059 * Test the api_account_verify_credentials() function.
1062 public function testApiAccountVerifyCredentials()
1064 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1068 * Test the api_account_verify_credentials() function without an authenticated user.
1070 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1072 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1074 $_SESSION['authenticated'] = false;
1075 api_account_verify_credentials('json');
1079 * Test the requestdata() function.
1082 public function testRequestdata()
1084 $this->assertNull(requestdata('variable_name'));
1088 * Test the requestdata() function with a POST parameter.
1091 public function testRequestdataWithPost()
1093 $_POST['variable_name'] = 'variable_value';
1094 $this->assertEquals('variable_value', requestdata('variable_name'));
1098 * Test the requestdata() function with a GET parameter.
1101 public function testRequestdataWithGet()
1103 $_GET['variable_name'] = 'variable_value';
1104 $this->assertEquals('variable_value', requestdata('variable_name'));
1108 * Test the api_statuses_mediap() function.
1111 public function testApiStatusesMediap()
1113 $this->app->argc = 2;
1121 'tmp_name' => $this->getTempImage(),
1122 'name' => 'spacer.png',
1123 'type' => 'image/png'
1126 $_GET['status'] = '<b>Status content</b>';
1128 $result = api_statuses_mediap('json');
1129 $this->assertStatus($result['status']);
1133 * Test the api_statuses_mediap() function without an authenticated user.
1135 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1137 public function testApiStatusesMediapWithoutAuthenticatedUser()
1139 $_SESSION['authenticated'] = false;
1140 api_statuses_mediap('json');
1144 * Test the api_statuses_update() function.
1147 public function testApiStatusesUpdate()
1149 $_GET['status'] = 'Status content #friendica';
1150 $_GET['in_reply_to_status_id'] = -1;
1159 'tmp_name' => $this->getTempImage(),
1160 'name' => 'spacer.png',
1161 'type' => 'image/png'
1165 $result = api_statuses_update('json');
1166 $this->assertStatus($result['status']);
1170 * Test the api_statuses_update() function with an HTML status.
1173 public function testApiStatusesUpdateWithHtml()
1175 $_GET['htmlstatus'] = '<b>Status content</b>';
1177 $result = api_statuses_update('json');
1178 $this->assertStatus($result['status']);
1182 * Test the api_statuses_update() function without an authenticated user.
1184 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1186 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1188 $_SESSION['authenticated'] = false;
1189 api_statuses_update('json');
1193 * Test the api_statuses_update() function with a parent status.
1196 public function testApiStatusesUpdateWithParent()
1198 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1202 * Test the api_statuses_update() function with a media_ids parameter.
1205 public function testApiStatusesUpdateWithMediaIds()
1207 $this->markTestIncomplete();
1211 * Test the api_statuses_update() function with the throttle limit reached.
1214 public function testApiStatusesUpdateWithDayThrottleReached()
1216 $this->markTestIncomplete();
1220 * Test the api_media_upload() function.
1222 * @expectedException Friendica\Network\HTTPException\BadRequestException
1224 public function testApiMediaUpload()
1230 * Test the api_media_upload() function without an authenticated user.
1232 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1234 public function testApiMediaUploadWithoutAuthenticatedUser()
1236 $_SESSION['authenticated'] = false;
1241 * Test the api_media_upload() function with an invalid uploaded media.
1243 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1245 public function testApiMediaUploadWithMedia()
1250 'tmp_name' => 'tmp_name'
1257 * Test the api_media_upload() function with an valid uploaded media.
1260 public function testApiMediaUploadWithValidMedia()
1268 'tmp_name' => $this->getTempImage(),
1269 'name' => 'spacer.png',
1270 'type' => 'image/png'
1276 $result = api_media_upload();
1277 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1278 $this->assertEquals(1, $result['media']['image']['w']);
1279 $this->assertEquals(1, $result['media']['image']['h']);
1280 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1284 * Test the api_status_show() function.
1286 public function testApiStatusShowWithJson()
1288 $result = api_status_show('json', 1);
1289 $this->assertStatus($result['status']);
1293 * Test the api_status_show() function with an XML result.
1295 public function testApiStatusShowWithXml()
1297 $result = api_status_show('xml', 1);
1298 $this->assertXml($result, 'statuses');
1302 * Test the api_get_last_status() function
1304 public function testApiGetLastStatus()
1306 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1308 $this->assertNotNull($item);
1312 * Test the api_users_show() function.
1315 public function testApiUsersShow()
1317 $result = api_users_show('json');
1318 // We can't use assertSelfUser() here because the user object is missing some properties.
1319 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1320 $this->assertEquals('DFRN', $result['user']['location']);
1321 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1322 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1323 $this->assertEquals('dfrn', $result['user']['network']);
1324 $this->assertTrue($result['user']['verified']);
1328 * Test the api_users_show() function with an XML result.
1331 public function testApiUsersShowWithXml()
1333 $result = api_users_show('xml');
1334 $this->assertXml($result, 'statuses');
1338 * Test the api_users_search() function.
1341 public function testApiUsersSearch()
1343 $_GET['q'] = 'othercontact';
1344 $result = api_users_search('json');
1345 $this->assertOtherUser($result['users'][0]);
1349 * Test the api_users_search() function with an XML result.
1352 public function testApiUsersSearchWithXml()
1354 $_GET['q'] = 'othercontact';
1355 $result = api_users_search('xml');
1356 $this->assertXml($result, 'users');
1360 * Test the api_users_search() function without a GET q parameter.
1362 * @expectedException Friendica\Network\HTTPException\BadRequestException
1364 public function testApiUsersSearchWithoutQuery()
1366 api_users_search('json');
1370 * Test the api_users_lookup() function.
1372 * @expectedException Friendica\Network\HTTPException\NotFoundException
1374 public function testApiUsersLookup()
1376 api_users_lookup('json');
1380 * Test the api_users_lookup() function with an user ID.
1383 public function testApiUsersLookupWithUserId()
1385 $_REQUEST['user_id'] = $this->otherUser['id'];
1386 $result = api_users_lookup('json');
1387 $this->assertOtherUser($result['users'][0]);
1391 * Test the api_search() function.
1394 public function testApiSearch()
1396 $_REQUEST['q'] = 'reply';
1397 $_REQUEST['max_id'] = 10;
1398 $result = api_search('json');
1399 foreach ($result['status'] as $status) {
1400 $this->assertStatus($status);
1401 $this->assertContains('reply', $status['text'], null, true);
1406 * Test the api_search() function a count parameter.
1409 public function testApiSearchWithCount()
1411 $_REQUEST['q'] = 'reply';
1412 $_REQUEST['count'] = 20;
1413 $result = api_search('json');
1414 foreach ($result['status'] as $status) {
1415 $this->assertStatus($status);
1416 $this->assertContains('reply', $status['text'], null, true);
1421 * Test the api_search() function with an rpp parameter.
1424 public function testApiSearchWithRpp()
1426 $_REQUEST['q'] = 'reply';
1427 $_REQUEST['rpp'] = 20;
1428 $result = api_search('json');
1429 foreach ($result['status'] as $status) {
1430 $this->assertStatus($status);
1431 $this->assertContains('reply', $status['text'], null, true);
1436 * Test the api_search() function with an q parameter contains hashtag.
1439 public function testApiSearchWithHashtag()
1441 $_REQUEST['q'] = '%23friendica';
1442 $result = api_search('json');
1443 foreach ($result['status'] as $status) {
1444 $this->assertStatus($status);
1445 $this->assertContains('#friendica', $status['text'], null, true);
1450 * Test the api_search() function with an exclude_replies parameter.
1453 public function testApiSearchWithExcludeReplies()
1455 $_REQUEST['max_id'] = 10;
1456 $_REQUEST['exclude_replies'] = true;
1457 $_REQUEST['q'] = 'friendica';
1458 $result = api_search('json');
1459 foreach ($result['status'] as $status) {
1460 $this->assertStatus($status);
1465 * Test the api_search() function without an authenticated user.
1467 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1469 public function testApiSearchWithUnallowedUser()
1471 $_SESSION['allow_api'] = false;
1472 $_GET['screen_name'] = $this->selfUser['nick'];
1477 * Test the api_search() function without any GET query parameter.
1479 * @expectedException Friendica\Network\HTTPException\BadRequestException
1481 public function testApiSearchWithoutQuery()
1487 * Test the api_statuses_home_timeline() function.
1490 public function testApiStatusesHomeTimeline()
1492 $_REQUEST['max_id'] = 10;
1493 $_REQUEST['exclude_replies'] = true;
1494 $_REQUEST['conversation_id'] = 1;
1495 $result = api_statuses_home_timeline('json');
1496 $this->assertNotEmpty($result['status']);
1497 foreach ($result['status'] as $status) {
1498 $this->assertStatus($status);
1503 * Test the api_statuses_home_timeline() function with a negative page parameter.
1506 public function testApiStatusesHomeTimelineWithNegativePage()
1508 $_REQUEST['page'] = -2;
1509 $result = api_statuses_home_timeline('json');
1510 $this->assertNotEmpty($result['status']);
1511 foreach ($result['status'] as $status) {
1512 $this->assertStatus($status);
1517 * Test the api_statuses_home_timeline() with an unallowed user.
1519 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1521 public function testApiStatusesHomeTimelineWithUnallowedUser()
1523 $_SESSION['allow_api'] = false;
1524 $_GET['screen_name'] = $this->selfUser['nick'];
1525 api_statuses_home_timeline('json');
1529 * Test the api_statuses_home_timeline() function with an RSS result.
1532 public function testApiStatusesHomeTimelineWithRss()
1534 $result = api_statuses_home_timeline('rss');
1535 $this->assertXml($result, 'statuses');
1539 * Test the api_statuses_public_timeline() function.
1542 public function testApiStatusesPublicTimeline()
1544 $_REQUEST['max_id'] = 10;
1545 $_REQUEST['conversation_id'] = 1;
1546 $result = api_statuses_public_timeline('json');
1547 $this->assertNotEmpty($result['status']);
1548 foreach ($result['status'] as $status) {
1549 $this->assertStatus($status);
1554 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1557 public function testApiStatusesPublicTimelineWithExcludeReplies()
1559 $_REQUEST['max_id'] = 10;
1560 $_REQUEST['exclude_replies'] = true;
1561 $result = api_statuses_public_timeline('json');
1562 $this->assertNotEmpty($result['status']);
1563 foreach ($result['status'] as $status) {
1564 $this->assertStatus($status);
1569 * Test the api_statuses_public_timeline() function with a negative page parameter.
1572 public function testApiStatusesPublicTimelineWithNegativePage()
1574 $_REQUEST['page'] = -2;
1575 $result = api_statuses_public_timeline('json');
1576 $this->assertNotEmpty($result['status']);
1577 foreach ($result['status'] as $status) {
1578 $this->assertStatus($status);
1583 * Test the api_statuses_public_timeline() function with an unallowed user.
1585 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1587 public function testApiStatusesPublicTimelineWithUnallowedUser()
1589 $_SESSION['allow_api'] = false;
1590 $_GET['screen_name'] = $this->selfUser['nick'];
1591 api_statuses_public_timeline('json');
1595 * Test the api_statuses_public_timeline() function with an RSS result.
1598 public function testApiStatusesPublicTimelineWithRss()
1600 $result = api_statuses_public_timeline('rss');
1601 $this->assertXml($result, 'statuses');
1605 * Test the api_statuses_networkpublic_timeline() function.
1608 public function testApiStatusesNetworkpublicTimeline()
1610 $_REQUEST['max_id'] = 10;
1611 $result = api_statuses_networkpublic_timeline('json');
1612 $this->assertNotEmpty($result['status']);
1613 foreach ($result['status'] as $status) {
1614 $this->assertStatus($status);
1619 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1622 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1624 $_REQUEST['page'] = -2;
1625 $result = api_statuses_networkpublic_timeline('json');
1626 $this->assertNotEmpty($result['status']);
1627 foreach ($result['status'] as $status) {
1628 $this->assertStatus($status);
1633 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1635 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1637 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1639 $_SESSION['allow_api'] = false;
1640 $_GET['screen_name'] = $this->selfUser['nick'];
1641 api_statuses_networkpublic_timeline('json');
1645 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1648 public function testApiStatusesNetworkpublicTimelineWithRss()
1650 $result = api_statuses_networkpublic_timeline('rss');
1651 $this->assertXml($result, 'statuses');
1655 * Test the api_statuses_show() function.
1657 * @expectedException Friendica\Network\HTTPException\BadRequestException
1659 public function testApiStatusesShow()
1661 api_statuses_show('json');
1665 * Test the api_statuses_show() function with an ID.
1668 public function testApiStatusesShowWithId()
1670 $this->app->argv[3] = 1;
1671 $result = api_statuses_show('json');
1672 $this->assertStatus($result['status']);
1676 * Test the api_statuses_show() function with the conversation parameter.
1679 public function testApiStatusesShowWithConversation()
1681 $this->app->argv[3] = 1;
1682 $_REQUEST['conversation'] = 1;
1683 $result = api_statuses_show('json');
1684 $this->assertNotEmpty($result['status']);
1685 foreach ($result['status'] as $status) {
1686 $this->assertStatus($status);
1691 * Test the api_statuses_show() function with an unallowed user.
1693 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1695 public function testApiStatusesShowWithUnallowedUser()
1697 $_SESSION['allow_api'] = false;
1698 $_GET['screen_name'] = $this->selfUser['nick'];
1699 api_statuses_show('json');
1703 * Test the api_conversation_show() function.
1705 * @expectedException Friendica\Network\HTTPException\BadRequestException
1707 public function testApiConversationShow()
1709 api_conversation_show('json');
1713 * Test the api_conversation_show() function with an ID.
1716 public function testApiConversationShowWithId()
1718 $this->app->argv[3] = 1;
1719 $_REQUEST['max_id'] = 10;
1720 $_REQUEST['page'] = -2;
1721 $result = api_conversation_show('json');
1722 $this->assertNotEmpty($result['status']);
1723 foreach ($result['status'] as $status) {
1724 $this->assertStatus($status);
1729 * Test the api_conversation_show() function with an unallowed user.
1731 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1733 public function testApiConversationShowWithUnallowedUser()
1735 $_SESSION['allow_api'] = false;
1736 $_GET['screen_name'] = $this->selfUser['nick'];
1737 api_conversation_show('json');
1741 * Test the api_statuses_repeat() function.
1743 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1745 public function testApiStatusesRepeat()
1747 api_statuses_repeat('json');
1751 * Test the api_statuses_repeat() function without an authenticated user.
1753 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1755 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1757 $_SESSION['authenticated'] = false;
1758 api_statuses_repeat('json');
1762 * Test the api_statuses_repeat() function with an ID.
1765 public function testApiStatusesRepeatWithId()
1767 $this->app->argv[3] = 1;
1768 $result = api_statuses_repeat('json');
1769 $this->assertStatus($result['status']);
1771 // Also test with a shared status
1772 $this->app->argv[3] = 5;
1773 $result = api_statuses_repeat('json');
1774 $this->assertStatus($result['status']);
1778 * Test the api_statuses_destroy() function.
1780 * @expectedException Friendica\Network\HTTPException\BadRequestException
1782 public function testApiStatusesDestroy()
1784 api_statuses_destroy('json');
1788 * Test the api_statuses_destroy() function without an authenticated user.
1790 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1792 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1794 $_SESSION['authenticated'] = false;
1795 api_statuses_destroy('json');
1799 * Test the api_statuses_destroy() function with an ID.
1802 public function testApiStatusesDestroyWithId()
1804 $this->app->argv[3] = 1;
1805 $result = api_statuses_destroy('json');
1806 $this->assertStatus($result['status']);
1810 * Test the api_statuses_mentions() function.
1813 public function testApiStatusesMentions()
1815 $this->app->user = ['nickname' => $this->selfUser['nick']];
1816 $_REQUEST['max_id'] = 10;
1817 $result = api_statuses_mentions('json');
1818 $this->assertEmpty($result['status']);
1819 // We should test with mentions in the database.
1823 * Test the api_statuses_mentions() function with a negative page parameter.
1826 public function testApiStatusesMentionsWithNegativePage()
1828 $_REQUEST['page'] = -2;
1829 $result = api_statuses_mentions('json');
1830 $this->assertEmpty($result['status']);
1834 * Test the api_statuses_mentions() function with an unallowed user.
1836 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1838 public function testApiStatusesMentionsWithUnallowedUser()
1840 $_SESSION['allow_api'] = false;
1841 $_GET['screen_name'] = $this->selfUser['nick'];
1842 api_statuses_mentions('json');
1846 * Test the api_statuses_mentions() function with an RSS result.
1849 public function testApiStatusesMentionsWithRss()
1851 $result = api_statuses_mentions('rss');
1852 $this->assertXml($result, 'statuses');
1856 * Test the api_statuses_user_timeline() function.
1859 public function testApiStatusesUserTimeline()
1861 $_REQUEST['max_id'] = 10;
1862 $_REQUEST['exclude_replies'] = true;
1863 $_REQUEST['conversation_id'] = 1;
1864 $result = api_statuses_user_timeline('json');
1865 $this->assertNotEmpty($result['status']);
1866 foreach ($result['status'] as $status) {
1867 $this->assertStatus($status);
1872 * Test the api_statuses_user_timeline() function with a negative page parameter.
1875 public function testApiStatusesUserTimelineWithNegativePage()
1877 $_REQUEST['page'] = -2;
1878 $result = api_statuses_user_timeline('json');
1879 $this->assertNotEmpty($result['status']);
1880 foreach ($result['status'] as $status) {
1881 $this->assertStatus($status);
1886 * Test the api_statuses_user_timeline() function with an RSS result.
1889 public function testApiStatusesUserTimelineWithRss()
1891 $result = api_statuses_user_timeline('rss');
1892 $this->assertXml($result, 'statuses');
1896 * Test the api_statuses_user_timeline() function with an unallowed user.
1898 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1900 public function testApiStatusesUserTimelineWithUnallowedUser()
1902 $_SESSION['allow_api'] = false;
1903 $_GET['screen_name'] = $this->selfUser['nick'];
1904 api_statuses_user_timeline('json');
1908 * Test the api_favorites_create_destroy() function.
1910 * @expectedException Friendica\Network\HTTPException\BadRequestException
1912 public function testApiFavoritesCreateDestroy()
1914 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
1915 $this->app->argc = count($this->app->argv);
1916 api_favorites_create_destroy('json');
1920 * Test the api_favorites_create_destroy() function with an invalid ID.
1922 * @expectedException Friendica\Network\HTTPException\BadRequestException
1924 public function testApiFavoritesCreateDestroyWithInvalidId()
1926 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
1927 $this->app->argc = count($this->app->argv);
1928 api_favorites_create_destroy('json');
1932 * Test the api_favorites_create_destroy() function with an invalid action.
1934 * @expectedException Friendica\Network\HTTPException\BadRequestException
1936 public function testApiFavoritesCreateDestroyWithInvalidAction()
1938 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
1939 $this->app->argc = count($this->app->argv);
1940 $_REQUEST['id'] = 1;
1941 api_favorites_create_destroy('json');
1945 * Test the api_favorites_create_destroy() function with the create action.
1948 public function testApiFavoritesCreateDestroyWithCreateAction()
1950 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1951 $this->app->argc = count($this->app->argv);
1952 $_REQUEST['id'] = 3;
1953 $result = api_favorites_create_destroy('json');
1954 $this->assertStatus($result['status']);
1958 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1961 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1963 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
1964 $this->app->argc = count($this->app->argv);
1965 $_REQUEST['id'] = 3;
1966 $result = api_favorites_create_destroy('rss');
1967 $this->assertXml($result, 'status');
1971 * Test the api_favorites_create_destroy() function with the destroy action.
1974 public function testApiFavoritesCreateDestroyWithDestroyAction()
1976 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
1977 $this->app->argc = count($this->app->argv);
1978 $_REQUEST['id'] = 3;
1979 $result = api_favorites_create_destroy('json');
1980 $this->assertStatus($result['status']);
1984 * Test the api_favorites_create_destroy() function without an authenticated user.
1986 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1988 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1990 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
1991 $this->app->argc = count($this->app->argv);
1992 $_SESSION['authenticated'] = false;
1993 api_favorites_create_destroy('json');
1997 * Test the api_favorites() function.
2000 public function testApiFavorites()
2002 $_REQUEST['page'] = -1;
2003 $_REQUEST['max_id'] = 10;
2004 $result = api_favorites('json');
2005 foreach ($result['status'] as $status) {
2006 $this->assertStatus($status);
2011 * Test the api_favorites() function with an RSS result.
2014 public function testApiFavoritesWithRss()
2016 $result = api_favorites('rss');
2017 $this->assertXml($result, 'statuses');
2021 * Test the api_favorites() function with an unallowed user.
2023 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2025 public function testApiFavoritesWithUnallowedUser()
2027 $_SESSION['allow_api'] = false;
2028 $_GET['screen_name'] = $this->selfUser['nick'];
2029 api_favorites('json');
2033 * Test the api_format_messages() function.
2036 public function testApiFormatMessages()
2038 $result = api_format_messages(
2039 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2040 ['id' => 2, 'screen_name' => 'recipient_name'],
2041 ['id' => 3, 'screen_name' => 'sender_name']
2043 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
2044 $this->assertEquals(1, $result['id']);
2045 $this->assertEquals(2, $result['recipient_id']);
2046 $this->assertEquals(3, $result['sender_id']);
2047 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2048 $this->assertEquals('sender_name', $result['sender_screen_name']);
2052 * Test the api_format_messages() function with HTML.
2055 public function testApiFormatMessagesWithHtmlText()
2057 $_GET['getText'] = 'html';
2058 $result = api_format_messages(
2059 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2060 ['id' => 2, 'screen_name' => 'recipient_name'],
2061 ['id' => 3, 'screen_name' => 'sender_name']
2063 $this->assertEquals('item_title', $result['title']);
2064 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2068 * Test the api_format_messages() function with plain text.
2071 public function testApiFormatMessagesWithPlainText()
2073 $_GET['getText'] = 'plain';
2074 $result = api_format_messages(
2075 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2076 ['id' => 2, 'screen_name' => 'recipient_name'],
2077 ['id' => 3, 'screen_name' => 'sender_name']
2079 $this->assertEquals('item_title', $result['title']);
2080 $this->assertEquals('item_body', $result['text']);
2084 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2087 public function testApiFormatMessagesWithoutUserObjects()
2089 $_GET['getUserObjects'] = 'false';
2090 $result = api_format_messages(
2091 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2092 ['id' => 2, 'screen_name' => 'recipient_name'],
2093 ['id' => 3, 'screen_name' => 'sender_name']
2095 $this->assertTrue(!isset($result['sender']));
2096 $this->assertTrue(!isset($result['recipient']));
2100 * Test the api_convert_item() function.
2103 public function testApiConvertItem()
2105 $result = api_convert_item(
2107 'network' => 'feed',
2108 'title' => 'item_title',
2109 // We need a long string to test that it is correctly cut
2110 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2111 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2112 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2113 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2114 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2115 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2116 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2117 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2118 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2119 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2120 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2121 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2122 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2123 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2124 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2125 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2126 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2127 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2128 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2129 'repellat officia illum quos impedit quam iste esse unde qui '.
2130 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2131 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2132 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2133 'plink' => 'item_plink'
2136 $this->assertStringStartsWith('item_title', $result['text']);
2137 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2141 * Test the api_convert_item() function with an empty item body.
2144 public function testApiConvertItemWithoutBody()
2146 $result = api_convert_item(
2148 'network' => 'feed',
2149 'title' => 'item_title',
2151 'plink' => 'item_plink'
2154 $this->assertEquals('item_title', $result['text']);
2155 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2159 * Test the api_convert_item() function with the title in the body.
2162 public function testApiConvertItemWithTitleInBody()
2164 $result = api_convert_item(
2166 'title' => 'item_title',
2167 'body' => 'item_title item_body'
2170 $this->assertEquals('item_title item_body', $result['text']);
2171 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2175 * Test the api_get_attachments() function.
2178 public function testApiGetAttachments()
2181 $this->assertEmpty(api_get_attachments($body));
2185 * Test the api_get_attachments() function with an img tag.
2188 public function testApiGetAttachmentsWithImage()
2190 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2191 $this->assertInternalType('array', api_get_attachments($body));
2195 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2198 public function testApiGetAttachmentsWithImageAndAndStatus()
2200 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2201 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2202 $this->assertInternalType('array', api_get_attachments($body));
2206 * Test the api_get_entitities() function.
2209 public function testApiGetEntitities()
2212 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2216 * Test the api_get_entitities() function with the include_entities parameter.
2219 public function testApiGetEntititiesWithIncludeEntities()
2221 $_REQUEST['include_entities'] = 'true';
2223 $result = api_get_entitities($text, 'bbcode');
2224 $this->assertInternalType('array', $result['hashtags']);
2225 $this->assertInternalType('array', $result['symbols']);
2226 $this->assertInternalType('array', $result['urls']);
2227 $this->assertInternalType('array', $result['user_mentions']);
2231 * Test the api_format_items_embeded_images() function.
2234 public function testApiFormatItemsEmbededImages()
2236 $this->assertEquals(
2237 'text ' . System::baseUrl() . '/display/item_guid',
2238 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2243 * Test the api_contactlink_to_array() function.
2246 public function testApiContactlinkToArray()
2248 $this->assertEquals(
2253 api_contactlink_to_array('text')
2258 * Test the api_contactlink_to_array() function with an URL.
2261 public function testApiContactlinkToArrayWithUrl()
2263 $this->assertEquals(
2265 'name' => ['link_text'],
2268 api_contactlink_to_array('text <a href="url">link_text</a>')
2273 * Test the api_format_items_activities() function.
2276 public function testApiFormatItemsActivities()
2278 $item = ['uid' => 0, 'uri' => ''];
2279 $result = api_format_items_activities($item);
2280 $this->assertArrayHasKey('like', $result);
2281 $this->assertArrayHasKey('dislike', $result);
2282 $this->assertArrayHasKey('attendyes', $result);
2283 $this->assertArrayHasKey('attendno', $result);
2284 $this->assertArrayHasKey('attendmaybe', $result);
2288 * Test the api_format_items_activities() function with an XML result.
2291 public function testApiFormatItemsActivitiesWithXml()
2293 $item = ['uid' => 0, 'uri' => ''];
2294 $result = api_format_items_activities($item, 'xml');
2295 $this->assertArrayHasKey('friendica:like', $result);
2296 $this->assertArrayHasKey('friendica:dislike', $result);
2297 $this->assertArrayHasKey('friendica:attendyes', $result);
2298 $this->assertArrayHasKey('friendica:attendno', $result);
2299 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2303 * Test the api_format_items_profiles() function.
2306 public function testApiFormatItemsProfiles()
2309 'id' => 'profile_id',
2310 'profile-name' => 'profile_name',
2311 'is-default' => true,
2312 'hide-friends' => true,
2313 'photo' => 'profile_photo',
2314 'thumb' => 'profile_thumb',
2316 'net-publish' => true,
2317 'pdesc' => 'description',
2318 'dob' => 'date_of_birth',
2319 'address' => 'address',
2320 'locality' => 'city',
2321 'region' => 'region',
2322 'postal-code' => 'postal_code',
2323 'country-name' => 'country',
2324 'hometown' => 'hometown',
2325 'gender' => 'gender',
2326 'marital' => 'marital',
2327 'with' => 'marital_with',
2328 'howlong' => 'marital_since',
2329 'sexual' => 'sexual',
2330 'politic' => 'politic',
2331 'religion' => 'religion',
2332 'pub_keywords' => 'public_keywords',
2333 'prv_keywords' => 'private_keywords',
2336 'dislikes' => 'dislikes',
2342 'interest' => 'interest',
2343 'romance' => 'romance',
2345 'education' => 'education',
2346 'contact' => 'social_networks',
2347 'homepage' => 'homepage'
2349 $result = api_format_items_profiles($profile_row);
2350 $this->assertEquals(
2352 'profile_id' => 'profile_id',
2353 'profile_name' => 'profile_name',
2354 'is_default' => true,
2355 'hide_friends' => true,
2356 'profile_photo' => 'profile_photo',
2357 'profile_thumb' => 'profile_thumb',
2359 'net_publish' => true,
2360 'description' => 'description',
2361 'date_of_birth' => 'date_of_birth',
2362 'address' => 'address',
2364 'region' => 'region',
2365 'postal_code' => 'postal_code',
2366 'country' => 'country',
2367 'hometown' => 'hometown',
2368 'gender' => 'gender',
2369 'marital' => 'marital',
2370 'marital_with' => 'marital_with',
2371 'marital_since' => 'marital_since',
2372 'sexual' => 'sexual',
2373 'politic' => 'politic',
2374 'religion' => 'religion',
2375 'public_keywords' => 'public_keywords',
2376 'private_keywords' => 'private_keywords',
2379 'dislikes' => 'dislikes',
2385 'interest' => 'interest',
2386 'romance' => 'romance',
2388 'education' => 'education',
2389 'social_networks' => 'social_networks',
2390 'homepage' => 'homepage',
2398 * Test the api_format_items() function.
2401 public function testApiFormatItems()
2405 'item_network' => 'item_network',
2411 'author-network' => Protocol::DFRN,
2412 'author-link' => 'http://localhost/profile/othercontact',
2416 $result = api_format_items($items, ['id' => 0], true);
2417 foreach ($result as $status) {
2418 $this->assertStatus($status);
2423 * Test the api_format_items() function with an XML result.
2426 public function testApiFormatItemsWithXml()
2434 'author-network' => Protocol::DFRN,
2435 'author-link' => 'http://localhost/profile/othercontact',
2439 $result = api_format_items($items, ['id' => 0], true, 'xml');
2440 foreach ($result as $status) {
2441 $this->assertStatus($status);
2446 * Test the api_format_items() function.
2449 public function testApiAccountRateLimitStatus()
2451 $result = api_account_rate_limit_status('json');
2452 $this->assertEquals(150, $result['hash']['remaining_hits']);
2453 $this->assertEquals(150, $result['hash']['hourly_limit']);
2454 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2458 * Test the api_format_items() function with an XML result.
2461 public function testApiAccountRateLimitStatusWithXml()
2463 $result = api_account_rate_limit_status('xml');
2464 $this->assertXml($result, 'hash');
2468 * Test the api_help_test() function.
2471 public function testApiHelpTest()
2473 $result = api_help_test('json');
2474 $this->assertEquals(['ok' => 'ok'], $result);
2478 * Test the api_help_test() function with an XML result.
2481 public function testApiHelpTestWithXml()
2483 $result = api_help_test('xml');
2484 $this->assertXml($result, 'ok');
2488 * Test the api_lists_list() function.
2491 public function testApiListsList()
2493 $result = api_lists_list('json');
2494 $this->assertEquals(['lists_list' => []], $result);
2498 * Test the api_lists_ownerships() function.
2501 public function testApiListsOwnerships()
2503 $result = api_lists_ownerships('json');
2504 foreach ($result['lists']['lists'] as $list) {
2505 $this->assertList($list);
2510 * Test the api_lists_ownerships() function without an authenticated user.
2512 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2514 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2516 $_SESSION['authenticated'] = false;
2517 api_lists_ownerships('json');
2521 * Test the api_lists_statuses() function.
2522 * @expectedException Friendica\Network\HTTPException\BadRequestException
2525 public function testApiListsStatuses()
2527 api_lists_statuses('json');
2531 * Test the api_lists_statuses() function with a list ID.
2534 public function testApiListsStatusesWithListId()
2536 $_REQUEST['list_id'] = 1;
2537 $_REQUEST['page'] = -1;
2538 $_REQUEST['max_id'] = 10;
2539 $result = api_lists_statuses('json');
2540 foreach ($result['status'] as $status) {
2541 $this->assertStatus($status);
2546 * Test the api_lists_statuses() function with a list ID and a RSS result.
2549 public function testApiListsStatusesWithListIdAndRss()
2551 $_REQUEST['list_id'] = 1;
2552 $result = api_lists_statuses('rss');
2553 $this->assertXml($result, 'statuses');
2557 * Test the api_lists_statuses() function with an unallowed user.
2559 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2561 public function testApiListsStatusesWithUnallowedUser()
2563 $_SESSION['allow_api'] = false;
2564 $_GET['screen_name'] = $this->selfUser['nick'];
2565 api_lists_statuses('json');
2569 * Test the api_statuses_f() function.
2572 public function testApiStatusesFWithFriends()
2575 $result = api_statuses_f('friends');
2576 $this->assertArrayHasKey('user', $result);
2580 * Test the api_statuses_f() function.
2583 public function testApiStatusesFWithFollowers()
2585 $result = api_statuses_f('followers');
2586 $this->assertArrayHasKey('user', $result);
2590 * Test the api_statuses_f() function.
2593 public function testApiStatusesFWithBlocks()
2595 $result = api_statuses_f('blocks');
2596 $this->assertArrayHasKey('user', $result);
2600 * Test the api_statuses_f() function.
2603 public function testApiStatusesFWithIncoming()
2605 $result = api_statuses_f('incoming');
2606 $this->assertArrayHasKey('user', $result);
2610 * Test the api_statuses_f() function an undefined cursor GET variable.
2613 public function testApiStatusesFWithUndefinedCursor()
2615 $_GET['cursor'] = 'undefined';
2616 $this->assertFalse(api_statuses_f('friends'));
2620 * Test the api_statuses_friends() function.
2623 public function testApiStatusesFriends()
2625 $result = api_statuses_friends('json');
2626 $this->assertArrayHasKey('user', $result);
2630 * Test the api_statuses_friends() function an undefined cursor GET variable.
2633 public function testApiStatusesFriendsWithUndefinedCursor()
2635 $_GET['cursor'] = 'undefined';
2636 $this->assertFalse(api_statuses_friends('json'));
2640 * Test the api_statuses_followers() function.
2643 public function testApiStatusesFollowers()
2645 $result = api_statuses_followers('json');
2646 $this->assertArrayHasKey('user', $result);
2650 * Test the api_statuses_followers() function an undefined cursor GET variable.
2653 public function testApiStatusesFollowersWithUndefinedCursor()
2655 $_GET['cursor'] = 'undefined';
2656 $this->assertFalse(api_statuses_followers('json'));
2660 * Test the api_blocks_list() function.
2663 public function testApiBlocksList()
2665 $result = api_blocks_list('json');
2666 $this->assertArrayHasKey('user', $result);
2670 * Test the api_blocks_list() function an undefined cursor GET variable.
2673 public function testApiBlocksListWithUndefinedCursor()
2675 $_GET['cursor'] = 'undefined';
2676 $this->assertFalse(api_blocks_list('json'));
2680 * Test the api_friendships_incoming() function.
2683 public function testApiFriendshipsIncoming()
2685 $result = api_friendships_incoming('json');
2686 $this->assertArrayHasKey('id', $result);
2690 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2693 public function testApiFriendshipsIncomingWithUndefinedCursor()
2695 $_GET['cursor'] = 'undefined';
2696 $this->assertFalse(api_friendships_incoming('json'));
2700 * Test the api_statusnet_config() function.
2703 public function testApiStatusnetConfig()
2705 $result = api_statusnet_config('json');
2706 $this->assertEquals('localhost', $result['config']['site']['server']);
2707 $this->assertEquals('default', $result['config']['site']['theme']);
2708 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2709 $this->assertTrue($result['config']['site']['fancy']);
2710 $this->assertEquals('en', $result['config']['site']['language']);
2711 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2712 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2713 $this->assertEquals('false', $result['config']['site']['private']);
2714 $this->assertEquals('false', $result['config']['site']['ssl']);
2715 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2719 * Test the api_statusnet_version() function.
2722 public function testApiStatusnetVersion()
2724 $result = api_statusnet_version('json');
2725 $this->assertEquals('0.9.7', $result['version']);
2729 * Test the api_ff_ids() function.
2732 public function testApiFfIds()
2734 $result = api_ff_ids('json');
2735 $this->assertNull($result);
2739 * Test the api_ff_ids() function with a result.
2742 public function testApiFfIdsWithResult()
2744 $this->markTestIncomplete();
2748 * Test the api_ff_ids() function without an authenticated user.
2750 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2752 public function testApiFfIdsWithoutAuthenticatedUser()
2754 $_SESSION['authenticated'] = false;
2759 * Test the api_friends_ids() function.
2762 public function testApiFriendsIds()
2764 $result = api_friends_ids('json');
2765 $this->assertNull($result);
2769 * Test the api_followers_ids() function.
2772 public function testApiFollowersIds()
2774 $result = api_followers_ids('json');
2775 $this->assertNull($result);
2779 * Test the api_direct_messages_new() function.
2782 public function testApiDirectMessagesNew()
2784 $result = api_direct_messages_new('json');
2785 $this->assertNull($result);
2789 * Test the api_direct_messages_new() function without an authenticated user.
2791 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2793 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2795 $_SESSION['authenticated'] = false;
2796 api_direct_messages_new('json');
2800 * Test the api_direct_messages_new() function with an user ID.
2803 public function testApiDirectMessagesNewWithUserId()
2805 $_POST['text'] = 'message_text';
2806 $_POST['user_id'] = $this->otherUser['id'];
2807 $result = api_direct_messages_new('json');
2808 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2812 * Test the api_direct_messages_new() function with a screen name.
2815 public function testApiDirectMessagesNewWithScreenName()
2817 $_POST['text'] = 'message_text';
2818 $_POST['screen_name'] = $this->friendUser['nick'];
2819 $result = api_direct_messages_new('json');
2820 $this->assertEquals(1, $result['direct_message']['id']);
2821 $this->assertContains('message_text', $result['direct_message']['text']);
2822 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2823 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2827 * Test the api_direct_messages_new() function with a title.
2830 public function testApiDirectMessagesNewWithTitle()
2832 $_POST['text'] = 'message_text';
2833 $_POST['screen_name'] = $this->friendUser['nick'];
2834 $_REQUEST['title'] = 'message_title';
2835 $result = api_direct_messages_new('json');
2836 $this->assertEquals(1, $result['direct_message']['id']);
2837 $this->assertContains('message_text', $result['direct_message']['text']);
2838 $this->assertContains('message_title', $result['direct_message']['text']);
2839 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2840 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2844 * Test the api_direct_messages_new() function with an RSS result.
2847 public function testApiDirectMessagesNewWithRss()
2849 $_POST['text'] = 'message_text';
2850 $_POST['screen_name'] = $this->friendUser['nick'];
2851 $result = api_direct_messages_new('rss');
2852 $this->assertXml($result, 'direct-messages');
2856 * Test the api_direct_messages_destroy() function.
2858 * @expectedException Friendica\Network\HTTPException\BadRequestException
2860 public function testApiDirectMessagesDestroy()
2862 api_direct_messages_destroy('json');
2866 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2869 public function testApiDirectMessagesDestroyWithVerbose()
2871 $_GET['friendica_verbose'] = 'true';
2872 $result = api_direct_messages_destroy('json');
2873 $this->assertEquals(
2876 'result' => 'error',
2877 'message' => 'message id or parenturi not specified'
2885 * Test the api_direct_messages_destroy() function without an authenticated user.
2887 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2889 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2891 $_SESSION['authenticated'] = false;
2892 api_direct_messages_destroy('json');
2896 * Test the api_direct_messages_destroy() function with a non-zero ID.
2898 * @expectedException Friendica\Network\HTTPException\BadRequestException
2900 public function testApiDirectMessagesDestroyWithId()
2902 $_REQUEST['id'] = 1;
2903 api_direct_messages_destroy('json');
2907 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2910 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2912 $_REQUEST['id'] = 1;
2913 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2914 $_GET['friendica_verbose'] = 'true';
2915 $result = api_direct_messages_destroy('json');
2916 $this->assertEquals(
2919 'result' => 'error',
2920 'message' => 'message id not in database'
2928 * Test the api_direct_messages_destroy() function with a non-zero ID.
2931 public function testApiDirectMessagesDestroyWithCorrectId()
2933 $this->markTestIncomplete('We need to add a dataset for this.');
2937 * Test the api_direct_messages_box() function.
2940 public function testApiDirectMessagesBoxWithSentbox()
2942 $_REQUEST['page'] = -1;
2943 $_REQUEST['max_id'] = 10;
2944 $result = api_direct_messages_box('json', 'sentbox', 'false');
2945 $this->assertArrayHasKey('direct_message', $result);
2949 * Test the api_direct_messages_box() function.
2952 public function testApiDirectMessagesBoxWithConversation()
2954 $result = api_direct_messages_box('json', 'conversation', 'false');
2955 $this->assertArrayHasKey('direct_message', $result);
2959 * Test the api_direct_messages_box() function.
2962 public function testApiDirectMessagesBoxWithAll()
2964 $result = api_direct_messages_box('json', 'all', 'false');
2965 $this->assertArrayHasKey('direct_message', $result);
2969 * Test the api_direct_messages_box() function.
2972 public function testApiDirectMessagesBoxWithInbox()
2974 $result = api_direct_messages_box('json', 'inbox', 'false');
2975 $this->assertArrayHasKey('direct_message', $result);
2979 * Test the api_direct_messages_box() function.
2982 public function testApiDirectMessagesBoxWithVerbose()
2984 $result = api_direct_messages_box('json', 'sentbox', 'true');
2985 $this->assertEquals(
2988 'result' => 'error',
2989 'message' => 'no mails available'
2997 * Test the api_direct_messages_box() function with a RSS result.
3000 public function testApiDirectMessagesBoxWithRss()
3002 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3003 $this->assertXml($result, 'direct-messages');
3007 * Test the api_direct_messages_box() function without an authenticated user.
3009 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3011 public function testApiDirectMessagesBoxWithUnallowedUser()
3013 $_SESSION['allow_api'] = false;
3014 $_GET['screen_name'] = $this->selfUser['nick'];
3015 api_direct_messages_box('json', 'sentbox', 'false');
3019 * Test the api_direct_messages_sentbox() function.
3022 public function testApiDirectMessagesSentbox()
3024 $result = api_direct_messages_sentbox('json');
3025 $this->assertArrayHasKey('direct_message', $result);
3029 * Test the api_direct_messages_inbox() function.
3032 public function testApiDirectMessagesInbox()
3034 $result = api_direct_messages_inbox('json');
3035 $this->assertArrayHasKey('direct_message', $result);
3039 * Test the api_direct_messages_all() function.
3042 public function testApiDirectMessagesAll()
3044 $result = api_direct_messages_all('json');
3045 $this->assertArrayHasKey('direct_message', $result);
3049 * Test the api_direct_messages_conversation() function.
3052 public function testApiDirectMessagesConversation()
3054 $result = api_direct_messages_conversation('json');
3055 $this->assertArrayHasKey('direct_message', $result);
3059 * Test the api_oauth_request_token() function.
3062 public function testApiOauthRequestToken()
3064 $this->markTestIncomplete('killme() kills phpunit as well');
3068 * Test the api_oauth_access_token() function.
3071 public function testApiOauthAccessToken()
3073 $this->markTestIncomplete('killme() kills phpunit as well');
3077 * Test the api_fr_photoalbum_delete() function.
3079 * @expectedException Friendica\Network\HTTPException\BadRequestException
3081 public function testApiFrPhotoalbumDelete()
3083 api_fr_photoalbum_delete('json');
3087 * Test the api_fr_photoalbum_delete() function with an album name.
3089 * @expectedException Friendica\Network\HTTPException\BadRequestException
3091 public function testApiFrPhotoalbumDeleteWithAlbum()
3093 $_REQUEST['album'] = 'album_name';
3094 api_fr_photoalbum_delete('json');
3098 * Test the api_fr_photoalbum_delete() function with an album name.
3101 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3103 $this->markTestIncomplete('We need to add a dataset for this.');
3107 * Test the api_fr_photoalbum_delete() function.
3109 * @expectedException Friendica\Network\HTTPException\BadRequestException
3111 public function testApiFrPhotoalbumUpdate()
3113 api_fr_photoalbum_update('json');
3117 * Test the api_fr_photoalbum_delete() function with an album name.
3119 * @expectedException Friendica\Network\HTTPException\BadRequestException
3121 public function testApiFrPhotoalbumUpdateWithAlbum()
3123 $_REQUEST['album'] = 'album_name';
3124 api_fr_photoalbum_update('json');
3128 * Test the api_fr_photoalbum_delete() function with an album name.
3130 * @expectedException Friendica\Network\HTTPException\BadRequestException
3132 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3134 $_REQUEST['album'] = 'album_name';
3135 $_REQUEST['album_new'] = 'album_name';
3136 api_fr_photoalbum_update('json');
3140 * Test the api_fr_photoalbum_update() function without an authenticated user.
3142 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3144 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3146 $_SESSION['authenticated'] = false;
3147 api_fr_photoalbum_update('json');
3151 * Test the api_fr_photoalbum_delete() function with an album name.
3154 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3156 $this->markTestIncomplete('We need to add a dataset for this.');
3160 * Test the api_fr_photos_list() function.
3163 public function testApiFrPhotosList()
3165 $result = api_fr_photos_list('json');
3166 $this->assertArrayHasKey('photo', $result);
3170 * Test the api_fr_photos_list() function without an authenticated user.
3172 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3174 public function testApiFrPhotosListWithoutAuthenticatedUser()
3176 $_SESSION['authenticated'] = false;
3177 api_fr_photos_list('json');
3181 * Test the api_fr_photo_create_update() function.
3183 * @expectedException Friendica\Network\HTTPException\BadRequestException
3185 public function testApiFrPhotoCreateUpdate()
3187 api_fr_photo_create_update('json');
3191 * Test the api_fr_photo_create_update() function without an authenticated user.
3193 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3195 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3197 $_SESSION['authenticated'] = false;
3198 api_fr_photo_create_update('json');
3202 * Test the api_fr_photo_create_update() function with an album name.
3204 * @expectedException Friendica\Network\HTTPException\BadRequestException
3206 public function testApiFrPhotoCreateUpdateWithAlbum()
3208 $_REQUEST['album'] = 'album_name';
3209 api_fr_photo_create_update('json');
3213 * Test the api_fr_photo_create_update() function with the update mode.
3216 public function testApiFrPhotoCreateUpdateWithUpdate()
3218 $this->markTestIncomplete('We need to create a dataset for this');
3222 * Test the api_fr_photo_create_update() function with an uploaded file.
3225 public function testApiFrPhotoCreateUpdateWithFile()
3227 $this->markTestIncomplete();
3231 * Test the api_fr_photo_delete() function.
3233 * @expectedException Friendica\Network\HTTPException\BadRequestException
3235 public function testApiFrPhotoDelete()
3237 api_fr_photo_delete('json');
3241 * Test the api_fr_photo_delete() function without an authenticated user.
3243 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3245 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3247 $_SESSION['authenticated'] = false;
3248 api_fr_photo_delete('json');
3252 * Test the api_fr_photo_delete() function with a photo ID.
3254 * @expectedException Friendica\Network\HTTPException\BadRequestException
3256 public function testApiFrPhotoDeleteWithPhotoId()
3258 $_REQUEST['photo_id'] = 1;
3259 api_fr_photo_delete('json');
3263 * Test the api_fr_photo_delete() function with a correct photo ID.
3266 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3268 $this->markTestIncomplete('We need to create a dataset for this.');
3272 * Test the api_fr_photo_detail() function.
3274 * @expectedException Friendica\Network\HTTPException\BadRequestException
3276 public function testApiFrPhotoDetail()
3278 api_fr_photo_detail('json');
3282 * Test the api_fr_photo_detail() function without an authenticated user.
3284 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3286 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3288 $_SESSION['authenticated'] = false;
3289 api_fr_photo_detail('json');
3293 * Test the api_fr_photo_detail() function with a photo ID.
3295 * @expectedException Friendica\Network\HTTPException\NotFoundException
3297 public function testApiFrPhotoDetailWithPhotoId()
3299 $_REQUEST['photo_id'] = 1;
3300 api_fr_photo_detail('json');
3304 * Test the api_fr_photo_detail() function with a correct photo ID.
3307 public function testApiFrPhotoDetailCorrectPhotoId()
3309 $this->markTestIncomplete('We need to create a dataset for this.');
3313 * Test the api_account_update_profile_image() function.
3315 * @expectedException Friendica\Network\HTTPException\BadRequestException
3317 public function testApiAccountUpdateProfileImage()
3319 api_account_update_profile_image('json');
3323 * Test the api_account_update_profile_image() function without an authenticated user.
3325 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3327 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3329 $_SESSION['authenticated'] = false;
3330 api_account_update_profile_image('json');
3334 * Test the api_account_update_profile_image() function with an uploaded file.
3336 * @expectedException Friendica\Network\HTTPException\BadRequestException
3338 public function testApiAccountUpdateProfileImageWithUpload()
3340 $this->markTestIncomplete();
3345 * Test the api_account_update_profile() function.
3348 public function testApiAccountUpdateProfile()
3350 $_POST['name'] = 'new_name';
3351 $_POST['description'] = 'new_description';
3352 $result = api_account_update_profile('json');
3353 // We can't use assertSelfUser() here because the user object is missing some properties.
3354 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3355 $this->assertEquals('DFRN', $result['user']['location']);
3356 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3357 $this->assertEquals('dfrn', $result['user']['network']);
3358 $this->assertEquals('new_name', $result['user']['name']);
3359 $this->assertEquals('new_description', $result['user']['description']);
3363 * Test the check_acl_input() function.
3366 public function testCheckAclInput()
3368 $result = check_acl_input('<aclstring>');
3369 // Where does this result come from?
3370 $this->assertEquals(1, $result);
3374 * Test the check_acl_input() function with an empty ACL string.
3377 public function testCheckAclInputWithEmptyAclString()
3379 $result = check_acl_input(' ');
3380 $this->assertFalse($result);
3384 * Test the save_media_to_database() function.
3387 public function testSaveMediaToDatabase()
3389 $this->markTestIncomplete();
3393 * Test the post_photo_item() function.
3396 public function testPostPhotoItem()
3398 $this->markTestIncomplete();
3402 * Test the prepare_photo_data() function.
3405 public function testPreparePhotoData()
3407 $this->markTestIncomplete();
3411 * Test the api_friendica_remoteauth() function.
3413 * @expectedException Friendica\Network\HTTPException\BadRequestException
3415 public function testApiFriendicaRemoteauth()
3417 api_friendica_remoteauth();
3421 * Test the api_friendica_remoteauth() function with an URL.
3423 * @expectedException Friendica\Network\HTTPException\BadRequestException
3425 public function testApiFriendicaRemoteauthWithUrl()
3427 $_GET['url'] = 'url';
3428 $_GET['c_url'] = 'url';
3429 api_friendica_remoteauth();
3433 * Test the api_friendica_remoteauth() function with a correct URL.
3436 public function testApiFriendicaRemoteauthWithCorrectUrl()
3438 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3439 $_GET['url'] = 'url';
3440 $_GET['c_url'] = $this->selfUser['nurl'];
3441 api_friendica_remoteauth();
3445 * Test the api_share_as_retweet() function.
3448 public function testApiShareAsRetweet()
3450 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3451 $result = api_share_as_retweet($item);
3452 $this->assertFalse($result);
3456 * Test the api_share_as_retweet() function with a valid item.
3459 public function testApiShareAsRetweetWithValidItem()
3461 $this->markTestIncomplete();
3465 * Test the api_get_nick() function.
3468 public function testApiGetNick()
3470 $result = api_get_nick($this->otherUser['nurl']);
3471 $this->assertEquals('othercontact', $result);
3475 * Test the api_get_nick() function with a wrong URL.
3478 public function testApiGetNickWithWrongUrl()
3480 $result = api_get_nick('wrong_url');
3481 $this->assertFalse($result);
3485 * Test the api_in_reply_to() function.
3488 public function testApiInReplyTo()
3490 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3491 $this->assertArrayHasKey('status_id', $result);
3492 $this->assertArrayHasKey('user_id', $result);
3493 $this->assertArrayHasKey('status_id_str', $result);
3494 $this->assertArrayHasKey('user_id_str', $result);
3495 $this->assertArrayHasKey('screen_name', $result);
3499 * Test the api_in_reply_to() function with a valid item.
3502 public function testApiInReplyToWithValidItem()
3504 $this->markTestIncomplete();
3508 * Test the api_clean_plain_items() function.
3511 public function testApiCleanPlainItems()
3513 $_REQUEST['include_entities'] = 'true';
3514 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3515 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3519 * Test the api_clean_attachments() function.
3522 public function testApiCleanAttachments()
3524 $this->markTestIncomplete();
3528 * Test the api_best_nickname() function.
3531 public function testApiBestNickname()
3534 $result = api_best_nickname($contacts);
3535 $this->assertNull($result);
3539 * Test the api_best_nickname() function with contacts.
3542 public function testApiBestNicknameWithContacts()
3544 $this->markTestIncomplete();
3548 * Test the api_friendica_group_show() function.
3551 public function testApiFriendicaGroupShow()
3553 $this->markTestIncomplete();
3557 * Test the api_friendica_group_delete() function.
3560 public function testApiFriendicaGroupDelete()
3562 $this->markTestIncomplete();
3566 * Test the api_lists_destroy() function.
3569 public function testApiListsDestroy()
3571 $this->markTestIncomplete();
3575 * Test the group_create() function.
3578 public function testGroupCreate()
3580 $this->markTestIncomplete();
3584 * Test the api_friendica_group_create() function.
3587 public function testApiFriendicaGroupCreate()
3589 $this->markTestIncomplete();
3593 * Test the api_lists_create() function.
3596 public function testApiListsCreate()
3598 $this->markTestIncomplete();
3602 * Test the api_friendica_group_update() function.
3605 public function testApiFriendicaGroupUpdate()
3607 $this->markTestIncomplete();
3611 * Test the api_lists_update() function.
3614 public function testApiListsUpdate()
3616 $this->markTestIncomplete();
3620 * Test the api_friendica_activity() function.
3623 public function testApiFriendicaActivity()
3625 $this->markTestIncomplete();
3629 * Test the api_friendica_notification() function.
3631 * @expectedException Friendica\Network\HTTPException\BadRequestException
3633 public function testApiFriendicaNotification()
3635 api_friendica_notification('json');
3639 * Test the api_friendica_notification() function without an authenticated user.
3641 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3643 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3645 $_SESSION['authenticated'] = false;
3646 api_friendica_notification('json');
3650 * Test the api_friendica_notification() function with an argument count.
3653 public function testApiFriendicaNotificationWithArgumentCount()
3655 $this->app->argv = ['api', 'friendica', 'notification'];
3656 $this->app->argc = count($this->app->argv);
3657 $result = api_friendica_notification('json');
3658 $this->assertEquals(['note' => false], $result);
3662 * Test the api_friendica_notification() function with an XML result.
3665 public function testApiFriendicaNotificationWithXmlResult()
3667 $this->app->argv = ['api', 'friendica', 'notification'];
3668 $this->app->argc = count($this->app->argv);
3669 $result = api_friendica_notification('xml');
3670 $this->assertXml($result, 'notes');
3674 * Test the api_friendica_notification_seen() function.
3677 public function testApiFriendicaNotificationSeen()
3679 $this->markTestIncomplete();
3683 * Test the api_friendica_direct_messages_setseen() function.
3686 public function testApiFriendicaDirectMessagesSetseen()
3688 $this->markTestIncomplete();
3692 * Test the api_friendica_direct_messages_search() function.
3695 public function testApiFriendicaDirectMessagesSearch()
3697 $this->markTestIncomplete();
3701 * Test the api_friendica_profile_show() function.
3704 public function testApiFriendicaProfileShow()
3706 $result = api_friendica_profile_show('json');
3707 // We can't use assertSelfUser() here because the user object is missing some properties.
3708 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3709 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3710 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3711 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3712 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3713 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3714 $this->assertFalse($result['$result']['multi_profiles']);
3718 * Test the api_friendica_profile_show() function with a profile ID.
3721 public function testApiFriendicaProfileShowWithProfileId()
3723 $this->markTestIncomplete('We need to add a dataset for this.');
3727 * Test the api_friendica_profile_show() function with a wrong profile ID.
3729 * @expectedException Friendica\Network\HTTPException\BadRequestException
3731 public function testApiFriendicaProfileShowWithWrongProfileId()
3733 $_REQUEST['profile_id'] = 666;
3734 api_friendica_profile_show('json');
3738 * Test the api_friendica_profile_show() function without an authenticated user.
3740 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3742 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3744 $_SESSION['authenticated'] = false;
3745 api_friendica_profile_show('json');
3749 * Test the api_saved_searches_list() function.
3752 public function testApiSavedSearchesList()
3754 $result = api_saved_searches_list('json');
3755 $this->assertEquals(1, $result['terms'][0]['id']);
3756 $this->assertEquals(1, $result['terms'][0]['id_str']);
3757 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3758 $this->assertEquals('Saved search', $result['terms'][0]['query']);