6 namespace Friendica\Test;
10 use Friendica\Core\Config\IConfig;
11 use Friendica\Core\PConfig\IPConfig;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Session;
14 use Friendica\Core\Session\ISession;
15 use Friendica\Core\System;
16 use Friendica\Database\Database;
17 use Friendica\Database\DBA;
19 use Friendica\Model\Contact;
20 use Friendica\Network\HTTPException;
21 use Friendica\Test\Util\Database\StaticDatabase;
22 use Friendica\Util\Temporal;
23 use Monolog\Handler\TestHandler;
25 require_once __DIR__ . '/../../include/api.php';
28 * Tests for the API functions.
30 * Functions that use header() need to be tested in a separate process.
31 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
33 class ApiTest extends DatabaseTest
36 * @var TestHandler Can handle log-outputs
43 protected $friendUser;
47 protected $wrongUserId;
59 * Create variables used by tests.
61 protected function setUp()
65 $this->dice = (new Dice())
66 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
67 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
68 ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
69 DI::init($this->dice);
71 /** @var Database $dba */
72 $dba = $this->dice->create(Database::class);
74 /** @var IConfig $config */
75 $this->config = $this->dice->create(IConfig::class);
77 $this->config->set('system', 'url', 'http://localhost');
78 $this->config->set('system', 'hostname', 'localhost');
79 $this->config->set('system', 'worker_dont_fork', true);
82 $this->config->set('config', 'hostname', 'localhost');
83 $this->config->set('system', 'throttle_limit_day', 100);
84 $this->config->set('system', 'throttle_limit_week', 100);
85 $this->config->set('system', 'throttle_limit_month', 100);
86 $this->config->set('system', 'theme', 'system_theme');
88 // Load the API dataset for the whole API
89 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
92 $this->app = DI::app();
95 $this->app->argv = ['home'];
97 // User data that the test database is populated with
100 'name' => 'Self contact',
101 'nick' => 'selfcontact',
102 'nurl' => 'http://localhost/profile/selfcontact'
104 $this->friendUser = [
106 'name' => 'Friend contact',
107 'nick' => 'friendcontact',
108 'nurl' => 'http://localhost/profile/friendcontact'
112 'name' => 'othercontact',
113 'nick' => 'othercontact',
114 'nurl' => 'http://localhost/profile/othercontact'
117 // User ID that we know is not in the database
118 $this->wrongUserId = 666;
120 DI::session()->start();
122 // Most API require login so we force the session
125 'authenticated' => true,
126 'uid' => $this->selfUser['id']
135 * Assert that an user array contains expected keys.
137 * @param array $user User array
141 private function assertSelfUser(array $user)
143 $this->assertEquals($this->selfUser['id'], $user['uid']);
144 $this->assertEquals($this->selfUser['id'], $user['cid']);
145 $this->assertEquals(1, $user['self']);
146 $this->assertEquals('DFRN', $user['location']);
147 $this->assertEquals($this->selfUser['name'], $user['name']);
148 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
149 $this->assertEquals('dfrn', $user['network']);
150 $this->assertTrue($user['verified']);
154 * Assert that an user array contains expected keys.
156 * @param array $user User array
160 private function assertOtherUser(array $user)
162 $this->assertEquals($this->otherUser['id'], $user['id']);
163 $this->assertEquals($this->otherUser['id'], $user['id_str']);
164 $this->assertEquals(0, $user['self']);
165 $this->assertEquals($this->otherUser['name'], $user['name']);
166 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
167 $this->assertFalse($user['verified']);
171 * Assert that a status array contains expected keys.
173 * @param array $status Status array
177 private function assertStatus(array $status)
179 $this->assertInternalType('string', $status['text']);
180 $this->assertInternalType('int', $status['id']);
181 // We could probably do more checks here.
185 * Assert that a list array contains expected keys.
187 * @param array $list List array
191 private function assertList(array $list)
193 $this->assertInternalType('string', $list['name']);
194 $this->assertInternalType('int', $list['id']);
195 $this->assertInternalType('string', $list['id_str']);
196 $this->assertContains($list['mode'], ['public', 'private']);
197 // We could probably do more checks here.
201 * Assert that the string is XML and contain the root element.
203 * @param string $result XML string
204 * @param string $root_element Root element name
208 private function assertXml($result, $root_element)
210 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
211 $this->assertContains('<' . $root_element, $result);
212 // We could probably do more checks here.
216 * Get the path to a temporary empty PNG image.
218 * @return string Path
220 private function getTempImage()
222 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
226 // Empty 1x1 px PNG image
227 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
235 * Test the api_user() function.
239 public function testApiUser()
241 $this->assertEquals($this->selfUser['id'], api_user());
245 * Test the api_user() function with an unallowed user.
249 public function testApiUserWithUnallowedUser()
251 $_SESSION = ['allow_api' => false];
252 $this->assertEquals(false, api_user());
256 * Test the api_source() function.
260 public function testApiSource()
262 $this->assertEquals('api', api_source());
266 * Test the api_source() function with a Twidere user agent.
270 public function testApiSourceWithTwidere()
272 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
273 $this->assertEquals('Twidere', api_source());
277 * Test the api_source() function with a GET parameter.
281 public function testApiSourceWithGet()
283 $_GET['source'] = 'source_name';
284 $this->assertEquals('source_name', api_source());
288 * Test the api_date() function.
292 public function testApiDate()
294 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
298 * Test the api_register_func() function.
302 public function testApiRegisterFunc()
314 $this->assertTrue($API['api_path']['auth']);
315 $this->assertEquals('method', $API['api_path']['method']);
316 $this->assertTrue(is_callable($API['api_path']['func']));
320 * Test the api_login() function without any login.
323 * @runInSeparateProcess
324 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
326 public function testApiLoginWithoutLogin()
328 api_login($this->app);
332 * Test the api_login() function with a bad login.
335 * @runInSeparateProcess
336 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
338 public function testApiLoginWithBadLogin()
340 $_SERVER['PHP_AUTH_USER'] = 'user@server';
341 api_login($this->app);
345 * Test the api_login() function with oAuth.
349 public function testApiLoginWithOauth()
351 $this->markTestIncomplete('Can we test this easily?');
355 * Test the api_login() function with authentication provided by an addon.
359 public function testApiLoginWithAddonAuth()
361 $this->markTestIncomplete('Can we test this easily?');
365 * Test the api_login() function with a correct login.
368 * @runInSeparateProcess
370 public function testApiLoginWithCorrectLogin()
372 $_SERVER['PHP_AUTH_USER'] = 'Test user';
373 $_SERVER['PHP_AUTH_PW'] = 'password';
374 api_login($this->app);
378 * Test the api_login() function with a remote user.
381 * @runInSeparateProcess
382 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
384 public function testApiLoginWithRemoteUser()
386 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
387 api_login($this->app);
391 * Test the api_check_method() function.
395 public function testApiCheckMethod()
397 $this->assertFalse(api_check_method('method'));
401 * Test the api_check_method() function with a correct method.
405 public function testApiCheckMethodWithCorrectMethod()
407 $_SERVER['REQUEST_METHOD'] = 'method';
408 $this->assertTrue(api_check_method('method'));
412 * Test the api_check_method() function with a wildcard.
416 public function testApiCheckMethodWithWildcard()
418 $this->assertTrue(api_check_method('*'));
422 * Test the api_call() function.
425 * @runInSeparateProcess
427 public function testApiCall()
431 'method' => 'method',
432 'func' => function () {
433 return ['data' => ['some_data']];
436 $_SERVER['REQUEST_METHOD'] = 'method';
437 $_SERVER['QUERY_STRING'] = 'q=api_path';
438 $_GET['callback'] = 'callback_name';
440 $args = DI::args()->determine($_SERVER, $_GET);
443 'callback_name(["some_data"])',
444 api_call($this->app, $args)
449 * Test the api_call() function with the profiled enabled.
452 * @runInSeparateProcess
454 public function testApiCallWithProfiler()
458 'method' => 'method',
459 'func' => function () {
460 return ['data' => ['some_data']];
464 $_SERVER['REQUEST_METHOD'] = 'method';
465 $_SERVER['QUERY_STRING'] = 'q=api_path';
467 $args = DI::args()->determine($_SERVER, $_GET);
469 $this->config->set('system', 'profiler', true);
470 $this->config->set('rendertime', 'callstack', true);
471 $this->app->callstack = [
472 'database' => ['some_function' => 200],
473 'database_write' => ['some_function' => 200],
474 'cache' => ['some_function' => 200],
475 'cache_write' => ['some_function' => 200],
476 'network' => ['some_function' => 200]
481 api_call($this->app, $args)
486 * Test the api_call() function without any result.
489 * @runInSeparateProcess
491 public function testApiCallWithNoResult()
495 'method' => 'method',
496 'func' => function () {
500 $_SERVER['REQUEST_METHOD'] = 'method';
501 $_SERVER['QUERY_STRING'] = 'q=api_path';
503 $args = DI::args()->determine($_SERVER, $_GET);
506 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
507 api_call($this->app, $args)
512 * Test the api_call() function with an unimplemented API.
515 * @runInSeparateProcess
517 public function testApiCallWithUninplementedApi()
520 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
526 * Test the api_call() function with a JSON result.
529 * @runInSeparateProcess
531 public function testApiCallWithJson()
535 'method' => 'method',
536 'func' => function () {
537 return ['data' => ['some_data']];
540 $_SERVER['REQUEST_METHOD'] = 'method';
541 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
543 $args = DI::args()->determine($_SERVER, $_GET);
547 api_call($this->app, $args)
552 * Test the api_call() function with an XML result.
555 * @runInSeparateProcess
557 public function testApiCallWithXml()
561 'method' => 'method',
562 'func' => function () {
566 $_SERVER['REQUEST_METHOD'] = 'method';
567 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
569 $args = DI::args()->determine($_SERVER, $_GET);
573 api_call($this->app, $args)
578 * Test the api_call() function with an RSS result.
581 * @runInSeparateProcess
583 public function testApiCallWithRss()
587 'method' => 'method',
588 'func' => function () {
592 $_SERVER['REQUEST_METHOD'] = 'method';
593 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
595 $args = DI::args()->determine($_SERVER, $_GET);
598 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
600 api_call($this->app, $args)
605 * Test the api_call() function with an Atom result.
608 * @runInSeparateProcess
610 public function testApiCallWithAtom()
614 'method' => 'method',
615 'func' => function () {
619 $_SERVER['REQUEST_METHOD'] = 'method';
620 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
622 $args = DI::args()->determine($_SERVER, $_GET);
625 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
627 api_call($this->app, $args)
632 * Test the api_call() function with an unallowed method.
635 * @runInSeparateProcess
637 public function testApiCallWithWrongMethod()
640 $API['api_path'] = ['method' => 'method'];
642 $_SERVER['QUERY_STRING'] = 'q=api_path';
644 $args = DI::args()->determine($_SERVER, $_GET);
647 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
648 api_call($this->app, $args)
653 * Test the api_call() function with an unauthorized user.
656 * @runInSeparateProcess
658 public function testApiCallWithWrongAuth()
662 'method' => 'method',
665 $_SESSION['authenticated'] = false;
666 $_SERVER['REQUEST_METHOD'] = 'method';
667 $_SERVER['QUERY_STRING'] = 'q=api_path';
669 $args = DI::args()->determine($_SERVER, $_GET);
672 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
673 api_call($this->app, $args)
678 * Test the api_error() function with a JSON result.
681 * @runInSeparateProcess
683 public function testApiErrorWithJson()
686 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
687 api_error('json', new HTTPException\OKException('error_message'), DI::args())
692 * Test the api_error() function with an XML result.
695 * @runInSeparateProcess
697 public function testApiErrorWithXml()
700 '<?xml version="1.0"?>' . "\n" .
701 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
702 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
703 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
704 ' <error>error_message</error>' . "\n" .
705 ' <code>200 OK</code>' . "\n" .
706 ' <request/>' . "\n" .
708 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
713 * Test the api_error() function with an RSS result.
716 * @runInSeparateProcess
718 public function testApiErrorWithRss()
721 '<?xml version="1.0"?>' . "\n" .
722 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
723 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
724 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
725 ' <error>error_message</error>' . "\n" .
726 ' <code>200 OK</code>' . "\n" .
727 ' <request/>' . "\n" .
729 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
734 * Test the api_error() function with an Atom result.
737 * @runInSeparateProcess
739 public function testApiErrorWithAtom()
742 '<?xml version="1.0"?>' . "\n" .
743 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
744 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
745 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
746 ' <error>error_message</error>' . "\n" .
747 ' <code>200 OK</code>' . "\n" .
748 ' <request/>' . "\n" .
750 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
755 * Test the api_rss_extra() function.
759 public function testApiRssExtra()
761 $user_info = ['url' => 'user_url', 'lang' => 'en'];
762 $result = api_rss_extra($this->app, [], $user_info);
763 $this->assertEquals($user_info, $result['$user']);
764 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
765 $this->assertArrayHasKey('self', $result['$rss']);
766 $this->assertArrayHasKey('base', $result['$rss']);
767 $this->assertArrayHasKey('updated', $result['$rss']);
768 $this->assertArrayHasKey('atom_updated', $result['$rss']);
769 $this->assertArrayHasKey('language', $result['$rss']);
770 $this->assertArrayHasKey('logo', $result['$rss']);
774 * Test the api_rss_extra() function without any user info.
778 public function testApiRssExtraWithoutUserInfo()
780 $result = api_rss_extra($this->app, [], null);
781 $this->assertInternalType('array', $result['$user']);
782 $this->assertArrayHasKey('alternate', $result['$rss']);
783 $this->assertArrayHasKey('self', $result['$rss']);
784 $this->assertArrayHasKey('base', $result['$rss']);
785 $this->assertArrayHasKey('updated', $result['$rss']);
786 $this->assertArrayHasKey('atom_updated', $result['$rss']);
787 $this->assertArrayHasKey('language', $result['$rss']);
788 $this->assertArrayHasKey('logo', $result['$rss']);
792 * Test the api_unique_id_to_nurl() function.
796 public function testApiUniqueIdToNurl()
798 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
802 * Test the api_unique_id_to_nurl() function with a correct ID.
806 public function testApiUniqueIdToNurlWithCorrectId()
808 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
812 * Test the api_get_user() function.
816 public function testApiGetUser()
818 $user = api_get_user($this->app);
819 $this->assertSelfUser($user);
820 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
821 $this->assertEquals('6fdbe8', $user['profile_link_color']);
822 $this->assertEquals('ededed', $user['profile_background_color']);
826 * Test the api_get_user() function with a Frio schema.
830 public function testApiGetUserWithFrioSchema()
832 $pConfig = $this->dice->create(IPConfig::class);
833 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
834 $user = api_get_user($this->app);
835 $this->assertSelfUser($user);
836 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
837 $this->assertEquals('6fdbe8', $user['profile_link_color']);
838 $this->assertEquals('ededed', $user['profile_background_color']);
842 * Test the api_get_user() function with a custom Frio schema.
846 public function testApiGetUserWithCustomFrioSchema()
848 $pConfig = $this->dice->create(IPConfig::class);
849 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
850 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
851 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
852 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
853 $user = api_get_user($this->app);
854 $this->assertSelfUser($user);
855 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
856 $this->assertEquals('123456', $user['profile_link_color']);
857 $this->assertEquals('123456', $user['profile_background_color']);
861 * Test the api_get_user() function with an empty Frio schema.
865 public function testApiGetUserWithEmptyFrioSchema()
867 $pConfig = $this->dice->create(IPConfig::class);
868 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
869 $user = api_get_user($this->app);
870 $this->assertSelfUser($user);
871 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
872 $this->assertEquals('6fdbe8', $user['profile_link_color']);
873 $this->assertEquals('ededed', $user['profile_background_color']);
877 * Test the api_get_user() function with an user that is not allowed to use the API.
880 * @runInSeparateProcess
882 public function testApiGetUserWithoutApiUser()
884 $_SERVER['PHP_AUTH_USER'] = 'Test user';
885 $_SERVER['PHP_AUTH_PW'] = 'password';
886 $_SESSION['allow_api'] = false;
887 $this->assertFalse(api_get_user($this->app));
891 * Test the api_get_user() function with an user ID in a GET parameter.
895 public function testApiGetUserWithGetId()
897 $_GET['user_id'] = $this->otherUser['id'];
898 $this->assertOtherUser(api_get_user($this->app));
902 * Test the api_get_user() function with a wrong user ID in a GET parameter.
905 * @expectedException Friendica\Network\HTTPException\BadRequestException
907 public function testApiGetUserWithWrongGetId()
909 $_GET['user_id'] = $this->wrongUserId;
910 $this->assertOtherUser(api_get_user($this->app));
914 * Test the api_get_user() function with an user name in a GET parameter.
918 public function testApiGetUserWithGetName()
920 $_GET['screen_name'] = $this->selfUser['nick'];
921 $this->assertSelfUser(api_get_user($this->app));
925 * Test the api_get_user() function with a profile URL in a GET parameter.
929 public function testApiGetUserWithGetUrl()
931 $_GET['profileurl'] = $this->selfUser['nurl'];
932 $this->assertSelfUser(api_get_user($this->app));
936 * Test the api_get_user() function with an user ID in the API path.
940 public function testApiGetUserWithNumericCalledApi()
943 $called_api = ['api_path'];
944 $this->app->argv[1] = $this->otherUser['id'] . '.json';
945 $this->assertOtherUser(api_get_user($this->app));
949 * Test the api_get_user() function with the $called_api global variable.
953 public function testApiGetUserWithCalledApi()
956 $called_api = ['api', 'api_path'];
957 $this->assertSelfUser(api_get_user($this->app));
961 * Test the api_get_user() function with a valid user.
965 public function testApiGetUserWithCorrectUser()
967 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
971 * Test the api_get_user() function with a wrong user ID.
974 * @expectedException Friendica\Network\HTTPException\BadRequestException
976 public function testApiGetUserWithWrongUser()
978 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
982 * Test the api_get_user() function with a 0 user ID.
986 public function testApiGetUserWithZeroUser()
988 $this->assertSelfUser(api_get_user($this->app, 0));
992 * Test the api_item_get_user() function.
996 public function testApiItemGetUser()
998 $users = api_item_get_user($this->app, []);
999 $this->assertSelfUser($users[0]);
1003 * Test the api_item_get_user() function with a different item parent.
1007 public function testApiItemGetUserWithDifferentParent()
1009 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
1010 $this->assertSelfUser($users[0]);
1011 $this->assertEquals($users[0], $users[1]);
1015 * Test the api_walk_recursive() function.
1019 public function testApiWalkRecursive()
1022 $this->assertEquals(
1027 // Should we test this with a callback that actually does something?
1035 * Test the api_walk_recursive() function with an array.
1039 public function testApiWalkRecursiveWithArray()
1041 $array = [['item1'], ['item2']];
1042 $this->assertEquals(
1047 // Should we test this with a callback that actually does something?
1055 * Test the api_reformat_xml() function.
1059 public function testApiReformatXml()
1063 $this->assertTrue(api_reformat_xml($item, $key));
1064 $this->assertEquals('true', $item);
1068 * Test the api_reformat_xml() function with a statusnet_api key.
1072 public function testApiReformatXmlWithStatusnetKey()
1075 $key = 'statusnet_api';
1076 $this->assertTrue(api_reformat_xml($item, $key));
1077 $this->assertEquals('statusnet:api', $key);
1081 * Test the api_reformat_xml() function with a friendica_api key.
1085 public function testApiReformatXmlWithFriendicaKey()
1088 $key = 'friendica_api';
1089 $this->assertTrue(api_reformat_xml($item, $key));
1090 $this->assertEquals('friendica:api', $key);
1094 * Test the api_create_xml() function.
1098 public function testApiCreateXml()
1100 $this->assertEquals(
1101 '<?xml version="1.0"?>' . "\n" .
1102 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1103 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1104 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1105 ' <data>some_data</data>' . "\n" .
1106 '</root_element>' . "\n",
1107 api_create_xml(['data' => ['some_data']], 'root_element')
1112 * Test the api_create_xml() function without any XML namespace.
1116 public function testApiCreateXmlWithoutNamespaces()
1118 $this->assertEquals(
1119 '<?xml version="1.0"?>' . "\n" .
1121 ' <data>some_data</data>' . "\n" .
1123 api_create_xml(['data' => ['some_data']], 'ok')
1128 * Test the api_format_data() function.
1132 public function testApiFormatData()
1134 $data = ['some_data'];
1135 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1139 * Test the api_format_data() function with an XML result.
1143 public function testApiFormatDataWithXml()
1145 $this->assertEquals(
1146 '<?xml version="1.0"?>' . "\n" .
1147 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1148 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1149 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1150 ' <data>some_data</data>' . "\n" .
1151 '</root_element>' . "\n",
1152 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1157 * Test the api_account_verify_credentials() function.
1161 public function testApiAccountVerifyCredentials()
1163 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1167 * Test the api_account_verify_credentials() function without an authenticated user.
1170 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1172 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1174 $_SESSION['authenticated'] = false;
1175 api_account_verify_credentials('json');
1179 * Test the requestdata() function.
1183 public function testRequestdata()
1185 $this->assertNull(requestdata('variable_name'));
1189 * Test the requestdata() function with a POST parameter.
1193 public function testRequestdataWithPost()
1195 $_POST['variable_name'] = 'variable_value';
1196 $this->assertEquals('variable_value', requestdata('variable_name'));
1200 * Test the requestdata() function with a GET parameter.
1204 public function testRequestdataWithGet()
1206 $_GET['variable_name'] = 'variable_value';
1207 $this->assertEquals('variable_value', requestdata('variable_name'));
1211 * Test the api_statuses_mediap() function.
1215 public function testApiStatusesMediap()
1217 $this->app->argc = 2;
1225 'tmp_name' => $this->getTempImage(),
1226 'name' => 'spacer.png',
1227 'type' => 'image/png'
1230 $_GET['status'] = '<b>Status content</b>';
1232 $result = api_statuses_mediap('json');
1233 $this->assertStatus($result['status']);
1237 * Test the api_statuses_mediap() function without an authenticated user.
1240 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1242 public function testApiStatusesMediapWithoutAuthenticatedUser()
1244 $_SESSION['authenticated'] = false;
1245 api_statuses_mediap('json');
1249 * Test the api_statuses_update() function.
1253 public function testApiStatusesUpdate()
1255 $_GET['status'] = 'Status content #friendica';
1256 $_GET['in_reply_to_status_id'] = -1;
1265 'tmp_name' => $this->getTempImage(),
1266 'name' => 'spacer.png',
1267 'type' => 'image/png'
1271 $result = api_statuses_update('json');
1272 $this->assertStatus($result['status']);
1276 * Test the api_statuses_update() function with an HTML status.
1280 public function testApiStatusesUpdateWithHtml()
1282 $_GET['htmlstatus'] = '<b>Status content</b>';
1284 $result = api_statuses_update('json');
1285 $this->assertStatus($result['status']);
1289 * Test the api_statuses_update() function without an authenticated user.
1292 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1294 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1296 $_SESSION['authenticated'] = false;
1297 api_statuses_update('json');
1301 * Test the api_statuses_update() function with a parent status.
1305 public function testApiStatusesUpdateWithParent()
1307 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1311 * Test the api_statuses_update() function with a media_ids parameter.
1315 public function testApiStatusesUpdateWithMediaIds()
1317 $this->markTestIncomplete();
1321 * Test the api_statuses_update() function with the throttle limit reached.
1325 public function testApiStatusesUpdateWithDayThrottleReached()
1327 $this->markTestIncomplete();
1331 * Test the api_media_upload() function.
1334 * @expectedException Friendica\Network\HTTPException\BadRequestException
1336 public function testApiMediaUpload()
1342 * Test the api_media_upload() function without an authenticated user.
1345 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1347 public function testApiMediaUploadWithoutAuthenticatedUser()
1349 $_SESSION['authenticated'] = false;
1354 * Test the api_media_upload() function with an invalid uploaded media.
1357 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1359 public function testApiMediaUploadWithMedia()
1364 'tmp_name' => 'tmp_name'
1371 * Test the api_media_upload() function with an valid uploaded media.
1375 public function testApiMediaUploadWithValidMedia()
1383 'tmp_name' => $this->getTempImage(),
1384 'name' => 'spacer.png',
1385 'type' => 'image/png'
1391 $result = api_media_upload();
1392 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1393 $this->assertEquals(1, $result['media']['image']['w']);
1394 $this->assertEquals(1, $result['media']['image']['h']);
1395 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1399 * Test the api_status_show() function.
1401 public function testApiStatusShowWithJson()
1403 $result = api_status_show('json', 1);
1404 $this->assertStatus($result['status']);
1408 * Test the api_status_show() function with an XML result.
1410 public function testApiStatusShowWithXml()
1412 $result = api_status_show('xml', 1);
1413 $this->assertXml($result, 'statuses');
1417 * Test the api_get_last_status() function
1419 public function testApiGetLastStatus()
1421 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1423 $this->assertNotNull($item);
1427 * Test the api_users_show() function.
1431 public function testApiUsersShow()
1433 $result = api_users_show('json');
1434 // We can't use assertSelfUser() here because the user object is missing some properties.
1435 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1436 $this->assertEquals('DFRN', $result['user']['location']);
1437 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1438 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1439 $this->assertEquals('dfrn', $result['user']['network']);
1440 $this->assertTrue($result['user']['verified']);
1444 * Test the api_users_show() function with an XML result.
1448 public function testApiUsersShowWithXml()
1450 $result = api_users_show('xml');
1451 $this->assertXml($result, 'statuses');
1455 * Test the api_users_search() function.
1459 public function testApiUsersSearch()
1461 $_GET['q'] = 'othercontact';
1462 $result = api_users_search('json');
1463 $this->assertOtherUser($result['users'][0]);
1467 * Test the api_users_search() function with an XML result.
1471 public function testApiUsersSearchWithXml()
1473 $_GET['q'] = 'othercontact';
1474 $result = api_users_search('xml');
1475 $this->assertXml($result, 'users');
1479 * Test the api_users_search() function without a GET q parameter.
1482 * @expectedException Friendica\Network\HTTPException\BadRequestException
1484 public function testApiUsersSearchWithoutQuery()
1486 api_users_search('json');
1490 * Test the api_users_lookup() function.
1493 * @expectedException Friendica\Network\HTTPException\NotFoundException
1495 public function testApiUsersLookup()
1497 api_users_lookup('json');
1501 * Test the api_users_lookup() function with an user ID.
1505 public function testApiUsersLookupWithUserId()
1507 $_REQUEST['user_id'] = $this->otherUser['id'];
1508 $result = api_users_lookup('json');
1509 $this->assertOtherUser($result['users'][0]);
1513 * Test the api_search() function.
1517 public function testApiSearch()
1519 $_REQUEST['q'] = 'reply';
1520 $_REQUEST['max_id'] = 10;
1521 $result = api_search('json');
1522 foreach ($result['status'] as $status) {
1523 $this->assertStatus($status);
1524 $this->assertContains('reply', $status['text'], null, true);
1529 * Test the api_search() function a count parameter.
1533 public function testApiSearchWithCount()
1535 $_REQUEST['q'] = 'reply';
1536 $_REQUEST['count'] = 20;
1537 $result = api_search('json');
1538 foreach ($result['status'] as $status) {
1539 $this->assertStatus($status);
1540 $this->assertContains('reply', $status['text'], null, true);
1545 * Test the api_search() function with an rpp parameter.
1549 public function testApiSearchWithRpp()
1551 $_REQUEST['q'] = 'reply';
1552 $_REQUEST['rpp'] = 20;
1553 $result = api_search('json');
1554 foreach ($result['status'] as $status) {
1555 $this->assertStatus($status);
1556 $this->assertContains('reply', $status['text'], null, true);
1561 * Test the api_search() function with an q parameter contains hashtag.
1565 public function testApiSearchWithHashtag()
1567 $_REQUEST['q'] = '%23friendica';
1568 $result = api_search('json');
1569 foreach ($result['status'] as $status) {
1570 $this->assertStatus($status);
1571 $this->assertContains('#friendica', $status['text'], null, true);
1576 * Test the api_search() function with an exclude_replies parameter.
1580 public function testApiSearchWithExcludeReplies()
1582 $_REQUEST['max_id'] = 10;
1583 $_REQUEST['exclude_replies'] = true;
1584 $_REQUEST['q'] = 'friendica';
1585 $result = api_search('json');
1586 foreach ($result['status'] as $status) {
1587 $this->assertStatus($status);
1592 * Test the api_search() function without an authenticated user.
1595 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1597 public function testApiSearchWithUnallowedUser()
1599 $_SESSION['allow_api'] = false;
1600 $_GET['screen_name'] = $this->selfUser['nick'];
1605 * Test the api_search() function without any GET query parameter.
1608 * @expectedException Friendica\Network\HTTPException\BadRequestException
1610 public function testApiSearchWithoutQuery()
1616 * Test the api_statuses_home_timeline() function.
1620 public function testApiStatusesHomeTimeline()
1622 $_REQUEST['max_id'] = 10;
1623 $_REQUEST['exclude_replies'] = true;
1624 $_REQUEST['conversation_id'] = 1;
1625 $result = api_statuses_home_timeline('json');
1626 $this->assertNotEmpty($result['status']);
1627 foreach ($result['status'] as $status) {
1628 $this->assertStatus($status);
1633 * Test the api_statuses_home_timeline() function with a negative page parameter.
1637 public function testApiStatusesHomeTimelineWithNegativePage()
1639 $_REQUEST['page'] = -2;
1640 $result = api_statuses_home_timeline('json');
1641 $this->assertNotEmpty($result['status']);
1642 foreach ($result['status'] as $status) {
1643 $this->assertStatus($status);
1648 * Test the api_statuses_home_timeline() with an unallowed user.
1651 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1653 public function testApiStatusesHomeTimelineWithUnallowedUser()
1655 $_SESSION['allow_api'] = false;
1656 $_GET['screen_name'] = $this->selfUser['nick'];
1657 api_statuses_home_timeline('json');
1661 * Test the api_statuses_home_timeline() function with an RSS result.
1665 public function testApiStatusesHomeTimelineWithRss()
1667 $result = api_statuses_home_timeline('rss');
1668 $this->assertXml($result, 'statuses');
1672 * Test the api_statuses_public_timeline() function.
1676 public function testApiStatusesPublicTimeline()
1678 $_REQUEST['max_id'] = 10;
1679 $_REQUEST['conversation_id'] = 1;
1680 $result = api_statuses_public_timeline('json');
1681 $this->assertNotEmpty($result['status']);
1682 foreach ($result['status'] as $status) {
1683 $this->assertStatus($status);
1688 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1692 public function testApiStatusesPublicTimelineWithExcludeReplies()
1694 $_REQUEST['max_id'] = 10;
1695 $_REQUEST['exclude_replies'] = true;
1696 $result = api_statuses_public_timeline('json');
1697 $this->assertNotEmpty($result['status']);
1698 foreach ($result['status'] as $status) {
1699 $this->assertStatus($status);
1704 * Test the api_statuses_public_timeline() function with a negative page parameter.
1708 public function testApiStatusesPublicTimelineWithNegativePage()
1710 $_REQUEST['page'] = -2;
1711 $result = api_statuses_public_timeline('json');
1712 $this->assertNotEmpty($result['status']);
1713 foreach ($result['status'] as $status) {
1714 $this->assertStatus($status);
1719 * Test the api_statuses_public_timeline() function with an unallowed user.
1722 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1724 public function testApiStatusesPublicTimelineWithUnallowedUser()
1726 $_SESSION['allow_api'] = false;
1727 $_GET['screen_name'] = $this->selfUser['nick'];
1728 api_statuses_public_timeline('json');
1732 * Test the api_statuses_public_timeline() function with an RSS result.
1736 public function testApiStatusesPublicTimelineWithRss()
1738 $result = api_statuses_public_timeline('rss');
1739 $this->assertXml($result, 'statuses');
1743 * Test the api_statuses_networkpublic_timeline() function.
1747 public function testApiStatusesNetworkpublicTimeline()
1749 $_REQUEST['max_id'] = 10;
1750 $result = api_statuses_networkpublic_timeline('json');
1751 $this->assertNotEmpty($result['status']);
1752 foreach ($result['status'] as $status) {
1753 $this->assertStatus($status);
1758 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1762 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1764 $_REQUEST['page'] = -2;
1765 $result = api_statuses_networkpublic_timeline('json');
1766 $this->assertNotEmpty($result['status']);
1767 foreach ($result['status'] as $status) {
1768 $this->assertStatus($status);
1773 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1776 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1778 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1780 $_SESSION['allow_api'] = false;
1781 $_GET['screen_name'] = $this->selfUser['nick'];
1782 api_statuses_networkpublic_timeline('json');
1786 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1790 public function testApiStatusesNetworkpublicTimelineWithRss()
1792 $result = api_statuses_networkpublic_timeline('rss');
1793 $this->assertXml($result, 'statuses');
1797 * Test the api_statuses_show() function.
1800 * @expectedException Friendica\Network\HTTPException\BadRequestException
1802 public function testApiStatusesShow()
1804 api_statuses_show('json');
1808 * Test the api_statuses_show() function with an ID.
1812 public function testApiStatusesShowWithId()
1814 $this->app->argv[3] = 1;
1815 $result = api_statuses_show('json');
1816 $this->assertStatus($result['status']);
1820 * Test the api_statuses_show() function with the conversation parameter.
1824 public function testApiStatusesShowWithConversation()
1826 $this->app->argv[3] = 1;
1827 $_REQUEST['conversation'] = 1;
1828 $result = api_statuses_show('json');
1829 $this->assertNotEmpty($result['status']);
1830 foreach ($result['status'] as $status) {
1831 $this->assertStatus($status);
1836 * Test the api_statuses_show() function with an unallowed user.
1839 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1841 public function testApiStatusesShowWithUnallowedUser()
1843 $_SESSION['allow_api'] = false;
1844 $_GET['screen_name'] = $this->selfUser['nick'];
1845 api_statuses_show('json');
1849 * Test the api_conversation_show() function.
1852 * @expectedException Friendica\Network\HTTPException\BadRequestException
1854 public function testApiConversationShow()
1856 api_conversation_show('json');
1860 * Test the api_conversation_show() function with an ID.
1864 public function testApiConversationShowWithId()
1866 $this->app->argv[3] = 1;
1867 $_REQUEST['max_id'] = 10;
1868 $_REQUEST['page'] = -2;
1869 $result = api_conversation_show('json');
1870 $this->assertNotEmpty($result['status']);
1871 foreach ($result['status'] as $status) {
1872 $this->assertStatus($status);
1877 * Test the api_conversation_show() function with an unallowed user.
1880 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1882 public function testApiConversationShowWithUnallowedUser()
1884 $_SESSION['allow_api'] = false;
1885 $_GET['screen_name'] = $this->selfUser['nick'];
1886 api_conversation_show('json');
1890 * Test the api_statuses_repeat() function.
1893 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1895 public function testApiStatusesRepeat()
1897 api_statuses_repeat('json');
1901 * Test the api_statuses_repeat() function without an authenticated user.
1904 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1906 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1908 $_SESSION['authenticated'] = false;
1909 api_statuses_repeat('json');
1913 * Test the api_statuses_repeat() function with an ID.
1917 public function testApiStatusesRepeatWithId()
1919 $this->app->argv[3] = 1;
1920 $result = api_statuses_repeat('json');
1921 $this->assertStatus($result['status']);
1923 // Also test with a shared status
1924 $this->app->argv[3] = 5;
1925 $result = api_statuses_repeat('json');
1926 $this->assertStatus($result['status']);
1930 * Test the api_statuses_destroy() function.
1933 * @expectedException Friendica\Network\HTTPException\BadRequestException
1935 public function testApiStatusesDestroy()
1937 api_statuses_destroy('json');
1941 * Test the api_statuses_destroy() function without an authenticated user.
1944 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1946 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1948 $_SESSION['authenticated'] = false;
1949 api_statuses_destroy('json');
1953 * Test the api_statuses_destroy() function with an ID.
1957 public function testApiStatusesDestroyWithId()
1959 $this->app->argv[3] = 1;
1960 $result = api_statuses_destroy('json');
1961 $this->assertStatus($result['status']);
1965 * Test the api_statuses_mentions() function.
1969 public function testApiStatusesMentions()
1971 $this->app->user = ['nickname' => $this->selfUser['nick']];
1972 $_REQUEST['max_id'] = 10;
1973 $result = api_statuses_mentions('json');
1974 $this->assertEmpty($result['status']);
1975 // We should test with mentions in the database.
1979 * Test the api_statuses_mentions() function with a negative page parameter.
1983 public function testApiStatusesMentionsWithNegativePage()
1985 $_REQUEST['page'] = -2;
1986 $result = api_statuses_mentions('json');
1987 $this->assertEmpty($result['status']);
1991 * Test the api_statuses_mentions() function with an unallowed user.
1994 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1996 public function testApiStatusesMentionsWithUnallowedUser()
1998 $_SESSION['allow_api'] = false;
1999 $_GET['screen_name'] = $this->selfUser['nick'];
2000 api_statuses_mentions('json');
2004 * Test the api_statuses_mentions() function with an RSS result.
2008 public function testApiStatusesMentionsWithRss()
2010 $result = api_statuses_mentions('rss');
2011 $this->assertXml($result, 'statuses');
2015 * Test the api_statuses_user_timeline() function.
2019 public function testApiStatusesUserTimeline()
2021 $_REQUEST['max_id'] = 10;
2022 $_REQUEST['exclude_replies'] = true;
2023 $_REQUEST['conversation_id'] = 1;
2024 $result = api_statuses_user_timeline('json');
2025 $this->assertNotEmpty($result['status']);
2026 foreach ($result['status'] as $status) {
2027 $this->assertStatus($status);
2032 * Test the api_statuses_user_timeline() function with a negative page parameter.
2036 public function testApiStatusesUserTimelineWithNegativePage()
2038 $_REQUEST['page'] = -2;
2039 $result = api_statuses_user_timeline('json');
2040 $this->assertNotEmpty($result['status']);
2041 foreach ($result['status'] as $status) {
2042 $this->assertStatus($status);
2047 * Test the api_statuses_user_timeline() function with an RSS result.
2051 public function testApiStatusesUserTimelineWithRss()
2053 $result = api_statuses_user_timeline('rss');
2054 $this->assertXml($result, 'statuses');
2058 * Test the api_statuses_user_timeline() function with an unallowed user.
2061 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2063 public function testApiStatusesUserTimelineWithUnallowedUser()
2065 $_SESSION['allow_api'] = false;
2066 $_GET['screen_name'] = $this->selfUser['nick'];
2067 api_statuses_user_timeline('json');
2071 * Test the api_favorites_create_destroy() function.
2074 * @expectedException Friendica\Network\HTTPException\BadRequestException
2076 public function testApiFavoritesCreateDestroy()
2078 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2079 $this->app->argc = count($this->app->argv);
2080 api_favorites_create_destroy('json');
2084 * Test the api_favorites_create_destroy() function with an invalid ID.
2087 * @expectedException Friendica\Network\HTTPException\BadRequestException
2089 public function testApiFavoritesCreateDestroyWithInvalidId()
2091 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2092 $this->app->argc = count($this->app->argv);
2093 api_favorites_create_destroy('json');
2097 * Test the api_favorites_create_destroy() function with an invalid action.
2100 * @expectedException Friendica\Network\HTTPException\BadRequestException
2102 public function testApiFavoritesCreateDestroyWithInvalidAction()
2104 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2105 $this->app->argc = count($this->app->argv);
2106 $_REQUEST['id'] = 1;
2107 api_favorites_create_destroy('json');
2111 * Test the api_favorites_create_destroy() function with the create action.
2115 public function testApiFavoritesCreateDestroyWithCreateAction()
2117 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2118 $this->app->argc = count($this->app->argv);
2119 $_REQUEST['id'] = 3;
2120 $result = api_favorites_create_destroy('json');
2121 $this->assertStatus($result['status']);
2125 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2129 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2131 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2132 $this->app->argc = count($this->app->argv);
2133 $_REQUEST['id'] = 3;
2134 $result = api_favorites_create_destroy('rss');
2135 $this->assertXml($result, 'status');
2139 * Test the api_favorites_create_destroy() function with the destroy action.
2143 public function testApiFavoritesCreateDestroyWithDestroyAction()
2145 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2146 $this->app->argc = count($this->app->argv);
2147 $_REQUEST['id'] = 3;
2148 $result = api_favorites_create_destroy('json');
2149 $this->assertStatus($result['status']);
2153 * Test the api_favorites_create_destroy() function without an authenticated user.
2156 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2158 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2160 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2161 $this->app->argc = count($this->app->argv);
2162 $_SESSION['authenticated'] = false;
2163 api_favorites_create_destroy('json');
2167 * Test the api_favorites() function.
2171 public function testApiFavorites()
2173 $_REQUEST['page'] = -1;
2174 $_REQUEST['max_id'] = 10;
2175 $result = api_favorites('json');
2176 foreach ($result['status'] as $status) {
2177 $this->assertStatus($status);
2182 * Test the api_favorites() function with an RSS result.
2186 public function testApiFavoritesWithRss()
2188 $result = api_favorites('rss');
2189 $this->assertXml($result, 'statuses');
2193 * Test the api_favorites() function with an unallowed user.
2196 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2198 public function testApiFavoritesWithUnallowedUser()
2200 $_SESSION['allow_api'] = false;
2201 $_GET['screen_name'] = $this->selfUser['nick'];
2202 api_favorites('json');
2206 * Test the api_format_messages() function.
2210 public function testApiFormatMessages()
2212 $result = api_format_messages(
2213 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2214 ['id' => 2, 'screen_name' => 'recipient_name'],
2215 ['id' => 3, 'screen_name' => 'sender_name']
2217 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2218 $this->assertEquals(1, $result['id']);
2219 $this->assertEquals(2, $result['recipient_id']);
2220 $this->assertEquals(3, $result['sender_id']);
2221 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2222 $this->assertEquals('sender_name', $result['sender_screen_name']);
2226 * Test the api_format_messages() function with HTML.
2230 public function testApiFormatMessagesWithHtmlText()
2232 $_GET['getText'] = 'html';
2233 $result = api_format_messages(
2234 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2235 ['id' => 2, 'screen_name' => 'recipient_name'],
2236 ['id' => 3, 'screen_name' => 'sender_name']
2238 $this->assertEquals('item_title', $result['title']);
2239 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2243 * Test the api_format_messages() function with plain text.
2247 public function testApiFormatMessagesWithPlainText()
2249 $_GET['getText'] = 'plain';
2250 $result = api_format_messages(
2251 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2252 ['id' => 2, 'screen_name' => 'recipient_name'],
2253 ['id' => 3, 'screen_name' => 'sender_name']
2255 $this->assertEquals('item_title', $result['title']);
2256 $this->assertEquals('item_body', $result['text']);
2260 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2264 public function testApiFormatMessagesWithoutUserObjects()
2266 $_GET['getUserObjects'] = 'false';
2267 $result = api_format_messages(
2268 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2269 ['id' => 2, 'screen_name' => 'recipient_name'],
2270 ['id' => 3, 'screen_name' => 'sender_name']
2272 $this->assertTrue(!isset($result['sender']));
2273 $this->assertTrue(!isset($result['recipient']));
2277 * Test the api_convert_item() function.
2281 public function testApiConvertItem()
2283 $result = api_convert_item(
2285 'network' => 'feed',
2286 'title' => 'item_title',
2287 // We need a long string to test that it is correctly cut
2288 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2289 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2290 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2291 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2292 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2293 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2294 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2295 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2296 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2297 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2298 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2299 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2300 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2301 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2302 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2303 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2304 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2305 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2306 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2307 'repellat officia illum quos impedit quam iste esse unde qui ' .
2308 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2309 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2310 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2311 'plink' => 'item_plink'
2314 $this->assertStringStartsWith('item_title', $result['text']);
2315 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2319 * Test the api_convert_item() function with an empty item body.
2323 public function testApiConvertItemWithoutBody()
2325 $result = api_convert_item(
2327 'network' => 'feed',
2328 'title' => 'item_title',
2330 'plink' => 'item_plink'
2333 $this->assertEquals('item_title', $result['text']);
2334 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2338 * Test the api_convert_item() function with the title in the body.
2342 public function testApiConvertItemWithTitleInBody()
2344 $result = api_convert_item(
2346 'title' => 'item_title',
2347 'body' => 'item_title item_body'
2350 $this->assertEquals('item_title item_body', $result['text']);
2351 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2355 * Test the api_get_attachments() function.
2359 public function testApiGetAttachments()
2362 $this->assertEmpty(api_get_attachments($body));
2366 * Test the api_get_attachments() function with an img tag.
2370 public function testApiGetAttachmentsWithImage()
2372 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2373 $this->assertInternalType('array', api_get_attachments($body));
2377 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2381 public function testApiGetAttachmentsWithImageAndAndStatus()
2383 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2384 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2385 $this->assertInternalType('array', api_get_attachments($body));
2389 * Test the api_get_entitities() function.
2393 public function testApiGetEntitities()
2396 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2400 * Test the api_get_entitities() function with the include_entities parameter.
2404 public function testApiGetEntititiesWithIncludeEntities()
2406 $_REQUEST['include_entities'] = 'true';
2408 $result = api_get_entitities($text, 'bbcode');
2409 $this->assertInternalType('array', $result['hashtags']);
2410 $this->assertInternalType('array', $result['symbols']);
2411 $this->assertInternalType('array', $result['urls']);
2412 $this->assertInternalType('array', $result['user_mentions']);
2416 * Test the api_format_items_embeded_images() function.
2420 public function testApiFormatItemsEmbededImages()
2422 $this->assertEquals(
2423 'text ' . DI::baseUrl() . '/display/item_guid',
2424 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2429 * Test the api_contactlink_to_array() function.
2433 public function testApiContactlinkToArray()
2435 $this->assertEquals(
2440 api_contactlink_to_array('text')
2445 * Test the api_contactlink_to_array() function with an URL.
2449 public function testApiContactlinkToArrayWithUrl()
2451 $this->assertEquals(
2453 'name' => ['link_text'],
2456 api_contactlink_to_array('text <a href="url">link_text</a>')
2461 * Test the api_format_items_activities() function.
2465 public function testApiFormatItemsActivities()
2467 $item = ['uid' => 0, 'uri' => ''];
2468 $result = api_format_items_activities($item);
2469 $this->assertArrayHasKey('like', $result);
2470 $this->assertArrayHasKey('dislike', $result);
2471 $this->assertArrayHasKey('attendyes', $result);
2472 $this->assertArrayHasKey('attendno', $result);
2473 $this->assertArrayHasKey('attendmaybe', $result);
2477 * Test the api_format_items_activities() function with an XML result.
2481 public function testApiFormatItemsActivitiesWithXml()
2483 $item = ['uid' => 0, 'uri' => ''];
2484 $result = api_format_items_activities($item, 'xml');
2485 $this->assertArrayHasKey('friendica:like', $result);
2486 $this->assertArrayHasKey('friendica:dislike', $result);
2487 $this->assertArrayHasKey('friendica:attendyes', $result);
2488 $this->assertArrayHasKey('friendica:attendno', $result);
2489 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2493 * Test the api_format_items() function.
2497 public function testApiFormatItems()
2501 'item_network' => 'item_network',
2507 'author-network' => Protocol::DFRN,
2508 'author-link' => 'http://localhost/profile/othercontact',
2512 $result = api_format_items($items, ['id' => 0], true);
2513 foreach ($result as $status) {
2514 $this->assertStatus($status);
2519 * Test the api_format_items() function with an XML result.
2523 public function testApiFormatItemsWithXml()
2531 'author-network' => Protocol::DFRN,
2532 'author-link' => 'http://localhost/profile/othercontact',
2536 $result = api_format_items($items, ['id' => 0], true, 'xml');
2537 foreach ($result as $status) {
2538 $this->assertStatus($status);
2543 * Test the api_format_items() function.
2547 public function testApiAccountRateLimitStatus()
2549 $result = api_account_rate_limit_status('json');
2550 $this->assertEquals(150, $result['hash']['remaining_hits']);
2551 $this->assertEquals(150, $result['hash']['hourly_limit']);
2552 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2556 * Test the api_format_items() function with an XML result.
2560 public function testApiAccountRateLimitStatusWithXml()
2562 $result = api_account_rate_limit_status('xml');
2563 $this->assertXml($result, 'hash');
2567 * Test the api_help_test() function.
2571 public function testApiHelpTest()
2573 $result = api_help_test('json');
2574 $this->assertEquals(['ok' => 'ok'], $result);
2578 * Test the api_help_test() function with an XML result.
2582 public function testApiHelpTestWithXml()
2584 $result = api_help_test('xml');
2585 $this->assertXml($result, 'ok');
2589 * Test the api_lists_list() function.
2593 public function testApiListsList()
2595 $result = api_lists_list('json');
2596 $this->assertEquals(['lists_list' => []], $result);
2600 * Test the api_lists_ownerships() function.
2604 public function testApiListsOwnerships()
2606 $result = api_lists_ownerships('json');
2607 foreach ($result['lists']['lists'] as $list) {
2608 $this->assertList($list);
2613 * Test the api_lists_ownerships() function without an authenticated user.
2616 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2618 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2620 $_SESSION['authenticated'] = false;
2621 api_lists_ownerships('json');
2625 * Test the api_lists_statuses() function.
2627 * @expectedException Friendica\Network\HTTPException\BadRequestException
2630 public function testApiListsStatuses()
2632 api_lists_statuses('json');
2636 * Test the api_lists_statuses() function with a list ID.
2640 public function testApiListsStatusesWithListId()
2642 $_REQUEST['list_id'] = 1;
2643 $_REQUEST['page'] = -1;
2644 $_REQUEST['max_id'] = 10;
2645 $result = api_lists_statuses('json');
2646 foreach ($result['status'] as $status) {
2647 $this->assertStatus($status);
2652 * Test the api_lists_statuses() function with a list ID and a RSS result.
2656 public function testApiListsStatusesWithListIdAndRss()
2658 $_REQUEST['list_id'] = 1;
2659 $result = api_lists_statuses('rss');
2660 $this->assertXml($result, 'statuses');
2664 * Test the api_lists_statuses() function with an unallowed user.
2667 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2669 public function testApiListsStatusesWithUnallowedUser()
2671 $_SESSION['allow_api'] = false;
2672 $_GET['screen_name'] = $this->selfUser['nick'];
2673 api_lists_statuses('json');
2677 * Test the api_statuses_f() function.
2681 public function testApiStatusesFWithFriends()
2684 $result = api_statuses_f('friends');
2685 $this->assertArrayHasKey('user', $result);
2689 * Test the api_statuses_f() function.
2693 public function testApiStatusesFWithFollowers()
2695 $result = api_statuses_f('followers');
2696 $this->assertArrayHasKey('user', $result);
2700 * Test the api_statuses_f() function.
2704 public function testApiStatusesFWithBlocks()
2706 $result = api_statuses_f('blocks');
2707 $this->assertArrayHasKey('user', $result);
2711 * Test the api_statuses_f() function.
2715 public function testApiStatusesFWithIncoming()
2717 $result = api_statuses_f('incoming');
2718 $this->assertArrayHasKey('user', $result);
2722 * Test the api_statuses_f() function an undefined cursor GET variable.
2726 public function testApiStatusesFWithUndefinedCursor()
2728 $_GET['cursor'] = 'undefined';
2729 $this->assertFalse(api_statuses_f('friends'));
2733 * Test the api_statuses_friends() function.
2737 public function testApiStatusesFriends()
2739 $result = api_statuses_friends('json');
2740 $this->assertArrayHasKey('user', $result);
2744 * Test the api_statuses_friends() function an undefined cursor GET variable.
2748 public function testApiStatusesFriendsWithUndefinedCursor()
2750 $_GET['cursor'] = 'undefined';
2751 $this->assertFalse(api_statuses_friends('json'));
2755 * Test the api_statuses_followers() function.
2759 public function testApiStatusesFollowers()
2761 $result = api_statuses_followers('json');
2762 $this->assertArrayHasKey('user', $result);
2766 * Test the api_statuses_followers() function an undefined cursor GET variable.
2770 public function testApiStatusesFollowersWithUndefinedCursor()
2772 $_GET['cursor'] = 'undefined';
2773 $this->assertFalse(api_statuses_followers('json'));
2777 * Test the api_blocks_list() function.
2781 public function testApiBlocksList()
2783 $result = api_blocks_list('json');
2784 $this->assertArrayHasKey('user', $result);
2788 * Test the api_blocks_list() function an undefined cursor GET variable.
2792 public function testApiBlocksListWithUndefinedCursor()
2794 $_GET['cursor'] = 'undefined';
2795 $this->assertFalse(api_blocks_list('json'));
2799 * Test the api_friendships_incoming() function.
2803 public function testApiFriendshipsIncoming()
2805 $result = api_friendships_incoming('json');
2806 $this->assertArrayHasKey('id', $result);
2810 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2814 public function testApiFriendshipsIncomingWithUndefinedCursor()
2816 $_GET['cursor'] = 'undefined';
2817 $this->assertFalse(api_friendships_incoming('json'));
2821 * Test the api_statusnet_config() function.
2825 public function testApiStatusnetConfig()
2827 $result = api_statusnet_config('json');
2828 $this->assertEquals('localhost', $result['config']['site']['server']);
2829 $this->assertEquals('default', $result['config']['site']['theme']);
2830 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2831 $this->assertTrue($result['config']['site']['fancy']);
2832 $this->assertEquals('en', $result['config']['site']['language']);
2833 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2834 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2835 $this->assertEquals('false', $result['config']['site']['private']);
2836 $this->assertEquals('false', $result['config']['site']['ssl']);
2837 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2841 * Test the api_statusnet_version() function.
2845 public function testApiStatusnetVersion()
2847 $result = api_statusnet_version('json');
2848 $this->assertEquals('0.9.7', $result['version']);
2852 * Test the api_ff_ids() function.
2856 public function testApiFfIds()
2858 $result = api_ff_ids('json', Contact::FOLLOWER);
2859 $this->assertEquals(['id' => []], $result);
2863 * Test the api_ff_ids() function with a result.
2867 public function testApiFfIdsWithResult()
2869 $this->markTestIncomplete();
2873 * Test the api_ff_ids() function without an authenticated user.
2876 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2878 public function testApiFfIdsWithoutAuthenticatedUser()
2880 $_SESSION['authenticated'] = false;
2881 api_ff_ids('json', Contact::FOLLOWER);
2885 * Test the api_friends_ids() function.
2889 public function testApiFriendsIds()
2891 $result = api_friends_ids('json');
2892 $this->assertEquals(['id' => []], $result);
2896 * Test the api_followers_ids() function.
2900 public function testApiFollowersIds()
2902 $result = api_followers_ids('json');
2903 $this->assertEquals(['id' => []], $result);
2907 * Test the api_direct_messages_new() function.
2911 public function testApiDirectMessagesNew()
2913 $result = api_direct_messages_new('json');
2914 $this->assertNull($result);
2918 * Test the api_direct_messages_new() function without an authenticated user.
2921 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2923 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2925 $_SESSION['authenticated'] = false;
2926 api_direct_messages_new('json');
2930 * Test the api_direct_messages_new() function with an user ID.
2934 public function testApiDirectMessagesNewWithUserId()
2936 $_POST['text'] = 'message_text';
2937 $_POST['user_id'] = $this->otherUser['id'];
2938 $result = api_direct_messages_new('json');
2939 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2943 * Test the api_direct_messages_new() function with a screen name.
2947 public function testApiDirectMessagesNewWithScreenName()
2949 $_POST['text'] = 'message_text';
2950 $_POST['screen_name'] = $this->friendUser['nick'];
2951 $result = api_direct_messages_new('json');
2952 $this->assertContains('message_text', $result['direct_message']['text']);
2953 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2954 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2958 * Test the api_direct_messages_new() function with a title.
2962 public function testApiDirectMessagesNewWithTitle()
2964 $_POST['text'] = 'message_text';
2965 $_POST['screen_name'] = $this->friendUser['nick'];
2966 $_REQUEST['title'] = 'message_title';
2967 $result = api_direct_messages_new('json');
2968 $this->assertContains('message_text', $result['direct_message']['text']);
2969 $this->assertContains('message_title', $result['direct_message']['text']);
2970 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2971 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2975 * Test the api_direct_messages_new() function with an RSS result.
2979 public function testApiDirectMessagesNewWithRss()
2981 $_POST['text'] = 'message_text';
2982 $_POST['screen_name'] = $this->friendUser['nick'];
2983 $result = api_direct_messages_new('rss');
2984 $this->assertXml($result, 'direct-messages');
2988 * Test the api_direct_messages_destroy() function.
2991 * @expectedException Friendica\Network\HTTPException\BadRequestException
2993 public function testApiDirectMessagesDestroy()
2995 api_direct_messages_destroy('json');
2999 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3003 public function testApiDirectMessagesDestroyWithVerbose()
3005 $_GET['friendica_verbose'] = 'true';
3006 $result = api_direct_messages_destroy('json');
3007 $this->assertEquals(
3010 'result' => 'error',
3011 'message' => 'message id or parenturi not specified'
3019 * Test the api_direct_messages_destroy() function without an authenticated user.
3022 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3024 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3026 $_SESSION['authenticated'] = false;
3027 api_direct_messages_destroy('json');
3031 * Test the api_direct_messages_destroy() function with a non-zero ID.
3034 * @expectedException Friendica\Network\HTTPException\BadRequestException
3036 public function testApiDirectMessagesDestroyWithId()
3038 $_REQUEST['id'] = 1;
3039 api_direct_messages_destroy('json');
3043 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3047 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3049 $_REQUEST['id'] = 1;
3050 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3051 $_GET['friendica_verbose'] = 'true';
3052 $result = api_direct_messages_destroy('json');
3053 $this->assertEquals(
3056 'result' => 'error',
3057 'message' => 'message id not in database'
3065 * Test the api_direct_messages_destroy() function with a non-zero ID.
3069 public function testApiDirectMessagesDestroyWithCorrectId()
3071 $this->markTestIncomplete('We need to add a dataset for this.');
3075 * Test the api_direct_messages_box() function.
3079 public function testApiDirectMessagesBoxWithSentbox()
3081 $_REQUEST['page'] = -1;
3082 $_REQUEST['max_id'] = 10;
3083 $result = api_direct_messages_box('json', 'sentbox', 'false');
3084 $this->assertArrayHasKey('direct_message', $result);
3088 * Test the api_direct_messages_box() function.
3092 public function testApiDirectMessagesBoxWithConversation()
3094 $result = api_direct_messages_box('json', 'conversation', 'false');
3095 $this->assertArrayHasKey('direct_message', $result);
3099 * Test the api_direct_messages_box() function.
3103 public function testApiDirectMessagesBoxWithAll()
3105 $result = api_direct_messages_box('json', 'all', 'false');
3106 $this->assertArrayHasKey('direct_message', $result);
3110 * Test the api_direct_messages_box() function.
3114 public function testApiDirectMessagesBoxWithInbox()
3116 $result = api_direct_messages_box('json', 'inbox', 'false');
3117 $this->assertArrayHasKey('direct_message', $result);
3121 * Test the api_direct_messages_box() function.
3125 public function testApiDirectMessagesBoxWithVerbose()
3127 $result = api_direct_messages_box('json', 'sentbox', 'true');
3128 $this->assertEquals(
3131 'result' => 'error',
3132 'message' => 'no mails available'
3140 * Test the api_direct_messages_box() function with a RSS result.
3144 public function testApiDirectMessagesBoxWithRss()
3146 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3147 $this->assertXml($result, 'direct-messages');
3151 * Test the api_direct_messages_box() function without an authenticated user.
3154 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3156 public function testApiDirectMessagesBoxWithUnallowedUser()
3158 $_SESSION['allow_api'] = false;
3159 $_GET['screen_name'] = $this->selfUser['nick'];
3160 api_direct_messages_box('json', 'sentbox', 'false');
3164 * Test the api_direct_messages_sentbox() function.
3168 public function testApiDirectMessagesSentbox()
3170 $result = api_direct_messages_sentbox('json');
3171 $this->assertArrayHasKey('direct_message', $result);
3175 * Test the api_direct_messages_inbox() function.
3179 public function testApiDirectMessagesInbox()
3181 $result = api_direct_messages_inbox('json');
3182 $this->assertArrayHasKey('direct_message', $result);
3186 * Test the api_direct_messages_all() function.
3190 public function testApiDirectMessagesAll()
3192 $result = api_direct_messages_all('json');
3193 $this->assertArrayHasKey('direct_message', $result);
3197 * Test the api_direct_messages_conversation() function.
3201 public function testApiDirectMessagesConversation()
3203 $result = api_direct_messages_conversation('json');
3204 $this->assertArrayHasKey('direct_message', $result);
3208 * Test the api_oauth_request_token() function.
3212 public function testApiOauthRequestToken()
3214 $this->markTestIncomplete('exit() kills phpunit as well');
3218 * Test the api_oauth_access_token() function.
3222 public function testApiOauthAccessToken()
3224 $this->markTestIncomplete('exit() kills phpunit as well');
3228 * Test the api_fr_photoalbum_delete() function.
3231 * @expectedException Friendica\Network\HTTPException\BadRequestException
3233 public function testApiFrPhotoalbumDelete()
3235 api_fr_photoalbum_delete('json');
3239 * Test the api_fr_photoalbum_delete() function with an album name.
3242 * @expectedException Friendica\Network\HTTPException\BadRequestException
3244 public function testApiFrPhotoalbumDeleteWithAlbum()
3246 $_REQUEST['album'] = 'album_name';
3247 api_fr_photoalbum_delete('json');
3251 * Test the api_fr_photoalbum_delete() function with an album name.
3255 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3257 $this->markTestIncomplete('We need to add a dataset for this.');
3261 * Test the api_fr_photoalbum_delete() function.
3264 * @expectedException Friendica\Network\HTTPException\BadRequestException
3266 public function testApiFrPhotoalbumUpdate()
3268 api_fr_photoalbum_update('json');
3272 * Test the api_fr_photoalbum_delete() function with an album name.
3275 * @expectedException Friendica\Network\HTTPException\BadRequestException
3277 public function testApiFrPhotoalbumUpdateWithAlbum()
3279 $_REQUEST['album'] = 'album_name';
3280 api_fr_photoalbum_update('json');
3284 * Test the api_fr_photoalbum_delete() function with an album name.
3287 * @expectedException Friendica\Network\HTTPException\BadRequestException
3289 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3291 $_REQUEST['album'] = 'album_name';
3292 $_REQUEST['album_new'] = 'album_name';
3293 api_fr_photoalbum_update('json');
3297 * Test the api_fr_photoalbum_update() function without an authenticated user.
3300 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3302 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3304 $_SESSION['authenticated'] = false;
3305 api_fr_photoalbum_update('json');
3309 * Test the api_fr_photoalbum_delete() function with an album name.
3313 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3315 $this->markTestIncomplete('We need to add a dataset for this.');
3319 * Test the api_fr_photos_list() function.
3323 public function testApiFrPhotosList()
3325 $result = api_fr_photos_list('json');
3326 $this->assertArrayHasKey('photo', $result);
3330 * Test the api_fr_photos_list() function without an authenticated user.
3333 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3335 public function testApiFrPhotosListWithoutAuthenticatedUser()
3337 $_SESSION['authenticated'] = false;
3338 api_fr_photos_list('json');
3342 * Test the api_fr_photo_create_update() function.
3345 * @expectedException Friendica\Network\HTTPException\BadRequestException
3347 public function testApiFrPhotoCreateUpdate()
3349 api_fr_photo_create_update('json');
3353 * Test the api_fr_photo_create_update() function without an authenticated user.
3356 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3358 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3360 $_SESSION['authenticated'] = false;
3361 api_fr_photo_create_update('json');
3365 * Test the api_fr_photo_create_update() function with an album name.
3368 * @expectedException Friendica\Network\HTTPException\BadRequestException
3370 public function testApiFrPhotoCreateUpdateWithAlbum()
3372 $_REQUEST['album'] = 'album_name';
3373 api_fr_photo_create_update('json');
3377 * Test the api_fr_photo_create_update() function with the update mode.
3381 public function testApiFrPhotoCreateUpdateWithUpdate()
3383 $this->markTestIncomplete('We need to create a dataset for this');
3387 * Test the api_fr_photo_create_update() function with an uploaded file.
3391 public function testApiFrPhotoCreateUpdateWithFile()
3393 $this->markTestIncomplete();
3397 * Test the api_fr_photo_delete() function.
3400 * @expectedException Friendica\Network\HTTPException\BadRequestException
3402 public function testApiFrPhotoDelete()
3404 api_fr_photo_delete('json');
3408 * Test the api_fr_photo_delete() function without an authenticated user.
3411 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3413 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3415 $_SESSION['authenticated'] = false;
3416 api_fr_photo_delete('json');
3420 * Test the api_fr_photo_delete() function with a photo ID.
3423 * @expectedException Friendica\Network\HTTPException\BadRequestException
3425 public function testApiFrPhotoDeleteWithPhotoId()
3427 $_REQUEST['photo_id'] = 1;
3428 api_fr_photo_delete('json');
3432 * Test the api_fr_photo_delete() function with a correct photo ID.
3436 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3438 $this->markTestIncomplete('We need to create a dataset for this.');
3442 * Test the api_fr_photo_detail() function.
3445 * @expectedException Friendica\Network\HTTPException\BadRequestException
3447 public function testApiFrPhotoDetail()
3449 api_fr_photo_detail('json');
3453 * Test the api_fr_photo_detail() function without an authenticated user.
3456 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3458 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3460 $_SESSION['authenticated'] = false;
3461 api_fr_photo_detail('json');
3465 * Test the api_fr_photo_detail() function with a photo ID.
3468 * @expectedException Friendica\Network\HTTPException\NotFoundException
3470 public function testApiFrPhotoDetailWithPhotoId()
3472 $_REQUEST['photo_id'] = 1;
3473 api_fr_photo_detail('json');
3477 * Test the api_fr_photo_detail() function with a correct photo ID.
3481 public function testApiFrPhotoDetailCorrectPhotoId()
3483 $this->markTestIncomplete('We need to create a dataset for this.');
3487 * Test the api_account_update_profile_image() function.
3490 * @expectedException Friendica\Network\HTTPException\BadRequestException
3492 public function testApiAccountUpdateProfileImage()
3494 api_account_update_profile_image('json');
3498 * Test the api_account_update_profile_image() function without an authenticated user.
3501 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3503 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3505 $_SESSION['authenticated'] = false;
3506 api_account_update_profile_image('json');
3510 * Test the api_account_update_profile_image() function with an uploaded file.
3513 * @expectedException Friendica\Network\HTTPException\BadRequestException
3515 public function testApiAccountUpdateProfileImageWithUpload()
3517 $this->markTestIncomplete();
3522 * Test the api_account_update_profile() function.
3526 public function testApiAccountUpdateProfile()
3528 $_POST['name'] = 'new_name';
3529 $_POST['description'] = 'new_description';
3530 $result = api_account_update_profile('json');
3531 // We can't use assertSelfUser() here because the user object is missing some properties.
3532 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3533 $this->assertEquals('DFRN', $result['user']['location']);
3534 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3535 $this->assertEquals('dfrn', $result['user']['network']);
3536 $this->assertEquals('new_name', $result['user']['name']);
3537 $this->assertEquals('new_description', $result['user']['description']);
3541 * Test the check_acl_input() function.
3545 public function testCheckAclInput()
3547 $result = check_acl_input('<aclstring>');
3548 // Where does this result come from?
3549 $this->assertEquals(1, $result);
3553 * Test the check_acl_input() function with an empty ACL string.
3557 public function testCheckAclInputWithEmptyAclString()
3559 $result = check_acl_input(' ');
3560 $this->assertFalse($result);
3564 * Test the save_media_to_database() function.
3568 public function testSaveMediaToDatabase()
3570 $this->markTestIncomplete();
3574 * Test the post_photo_item() function.
3578 public function testPostPhotoItem()
3580 $this->markTestIncomplete();
3584 * Test the prepare_photo_data() function.
3588 public function testPreparePhotoData()
3590 $this->markTestIncomplete();
3594 * Test the api_friendica_remoteauth() function.
3597 * @expectedException Friendica\Network\HTTPException\BadRequestException
3599 public function testApiFriendicaRemoteauth()
3601 api_friendica_remoteauth();
3605 * Test the api_friendica_remoteauth() function with an URL.
3608 * @expectedException Friendica\Network\HTTPException\BadRequestException
3610 public function testApiFriendicaRemoteauthWithUrl()
3612 $_GET['url'] = 'url';
3613 $_GET['c_url'] = 'url';
3614 api_friendica_remoteauth();
3618 * Test the api_friendica_remoteauth() function with a correct URL.
3622 public function testApiFriendicaRemoteauthWithCorrectUrl()
3624 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3625 $_GET['url'] = 'url';
3626 $_GET['c_url'] = $this->selfUser['nurl'];
3627 api_friendica_remoteauth();
3631 * Test the api_share_as_retweet() function.
3635 public function testApiShareAsRetweet()
3637 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3638 $result = api_share_as_retweet($item);
3639 $this->assertFalse($result);
3643 * Test the api_share_as_retweet() function with a valid item.
3647 public function testApiShareAsRetweetWithValidItem()
3649 $this->markTestIncomplete();
3653 * Test the api_in_reply_to() function.
3657 public function testApiInReplyTo()
3659 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3660 $this->assertArrayHasKey('status_id', $result);
3661 $this->assertArrayHasKey('user_id', $result);
3662 $this->assertArrayHasKey('status_id_str', $result);
3663 $this->assertArrayHasKey('user_id_str', $result);
3664 $this->assertArrayHasKey('screen_name', $result);
3668 * Test the api_in_reply_to() function with a valid item.
3672 public function testApiInReplyToWithValidItem()
3674 $this->markTestIncomplete();
3678 * Test the api_clean_plain_items() function.
3682 public function testApiCleanPlainItems()
3684 $_REQUEST['include_entities'] = 'true';
3685 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3686 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3690 * Test the api_best_nickname() function.
3694 public function testApiBestNickname()
3697 $result = api_best_nickname($contacts);
3698 $this->assertNull($result);
3702 * Test the api_best_nickname() function with contacts.
3706 public function testApiBestNicknameWithContacts()
3708 $this->markTestIncomplete();
3712 * Test the api_friendica_group_show() function.
3716 public function testApiFriendicaGroupShow()
3718 $this->markTestIncomplete();
3722 * Test the api_friendica_group_delete() function.
3726 public function testApiFriendicaGroupDelete()
3728 $this->markTestIncomplete();
3732 * Test the api_lists_destroy() function.
3736 public function testApiListsDestroy()
3738 $this->markTestIncomplete();
3742 * Test the group_create() function.
3746 public function testGroupCreate()
3748 $this->markTestIncomplete();
3752 * Test the api_friendica_group_create() function.
3756 public function testApiFriendicaGroupCreate()
3758 $this->markTestIncomplete();
3762 * Test the api_lists_create() function.
3766 public function testApiListsCreate()
3768 $this->markTestIncomplete();
3772 * Test the api_friendica_group_update() function.
3776 public function testApiFriendicaGroupUpdate()
3778 $this->markTestIncomplete();
3782 * Test the api_lists_update() function.
3786 public function testApiListsUpdate()
3788 $this->markTestIncomplete();
3792 * Test the api_friendica_activity() function.
3796 public function testApiFriendicaActivity()
3798 $this->markTestIncomplete();
3802 * Test the api_friendica_notification() function.
3805 * @expectedException Friendica\Network\HTTPException\BadRequestException
3807 public function testApiFriendicaNotification()
3809 api_friendica_notification('json');
3813 * Test the api_friendica_notification() function without an authenticated user.
3816 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3818 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3820 $_SESSION['authenticated'] = false;
3821 api_friendica_notification('json');
3825 * Test the api_friendica_notification() function with empty result
3829 public function testApiFriendicaNotificationWithEmptyResult()
3831 $this->app->argv = ['api', 'friendica', 'notification'];
3832 $this->app->argc = count($this->app->argv);
3833 $_SESSION['uid'] = 41;
3834 $result = api_friendica_notification('json');
3835 $this->assertEquals(['note' => false], $result);
3839 * Test the api_friendica_notification() function with an XML result.
3843 public function testApiFriendicaNotificationWithXmlResult()
3845 $this->app->argv = ['api', 'friendica', 'notification'];
3846 $this->app->argc = count($this->app->argv);
3847 $result = api_friendica_notification('xml');
3848 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3850 <?xml version="1.0"?>
3852 <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" uri-id="" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
3855 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3859 * Test the api_friendica_notification() function with an JSON result.
3863 public function testApiFriendicaNotificationWithJsonResult()
3865 $this->app->argv = ['api', 'friendica', 'notification'];
3866 $this->app->argc = count($this->app->argv);
3867 $result = json_encode(api_friendica_notification('json'));
3868 $this->assertJson($result);
3872 * Test the api_friendica_notification_seen() function.
3876 public function testApiFriendicaNotificationSeen()
3878 $this->markTestIncomplete();
3882 * Test the api_friendica_direct_messages_setseen() function.
3886 public function testApiFriendicaDirectMessagesSetseen()
3888 $this->markTestIncomplete();
3892 * Test the api_friendica_direct_messages_search() function.
3896 public function testApiFriendicaDirectMessagesSearch()
3898 $this->markTestIncomplete();
3902 * Test the api_saved_searches_list() function.
3906 public function testApiSavedSearchesList()
3908 $result = api_saved_searches_list('json');
3909 $this->assertEquals(1, $result['terms'][0]['id']);
3910 $this->assertEquals(1, $result['terms'][0]['id_str']);
3911 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3912 $this->assertEquals('Saved search', $result['terms'][0]['query']);