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 $dba->setTestmode(true);
76 /** @var IConfig $config */
77 $this->config = $this->dice->create(IConfig::class);
79 $this->config->set('system', 'url', 'http://localhost');
80 $this->config->set('system', 'hostname', 'localhost');
81 $this->config->set('system', 'worker_dont_fork', true);
84 $this->config->set('config', 'hostname', 'localhost');
85 $this->config->set('system', 'throttle_limit_day', 100);
86 $this->config->set('system', 'throttle_limit_week', 100);
87 $this->config->set('system', 'throttle_limit_month', 100);
88 $this->config->set('system', 'theme', 'system_theme');
90 // Load the API dataset for the whole API
91 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
94 $this->app = DI::app();
97 $this->app->argv = ['home'];
99 // User data that the test database is populated with
102 'name' => 'Self contact',
103 'nick' => 'selfcontact',
104 'nurl' => 'http://localhost/profile/selfcontact'
106 $this->friendUser = [
108 'name' => 'Friend contact',
109 'nick' => 'friendcontact',
110 'nurl' => 'http://localhost/profile/friendcontact'
114 'name' => 'othercontact',
115 'nick' => 'othercontact',
116 'nurl' => 'http://localhost/profile/othercontact'
119 // User ID that we know is not in the database
120 $this->wrongUserId = 666;
122 DI::session()->start();
124 // Most API require login so we force the session
127 'authenticated' => true,
128 'uid' => $this->selfUser['id']
137 * Assert that an user array contains expected keys.
139 * @param array $user User array
143 private function assertSelfUser(array $user)
145 $this->assertEquals($this->selfUser['id'], $user['uid']);
146 $this->assertEquals($this->selfUser['id'], $user['cid']);
147 $this->assertEquals(1, $user['self']);
148 $this->assertEquals('DFRN', $user['location']);
149 $this->assertEquals($this->selfUser['name'], $user['name']);
150 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
151 $this->assertEquals('dfrn', $user['network']);
152 $this->assertTrue($user['verified']);
156 * Assert that an user array contains expected keys.
158 * @param array $user User array
162 private function assertOtherUser(array $user)
164 $this->assertEquals($this->otherUser['id'], $user['id']);
165 $this->assertEquals($this->otherUser['id'], $user['id_str']);
166 $this->assertEquals(0, $user['self']);
167 $this->assertEquals($this->otherUser['name'], $user['name']);
168 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
169 $this->assertFalse($user['verified']);
173 * Assert that a status array contains expected keys.
175 * @param array $status Status array
179 private function assertStatus(array $status)
181 $this->assertInternalType('string', $status['text']);
182 $this->assertInternalType('int', $status['id']);
183 // We could probably do more checks here.
187 * Assert that a list array contains expected keys.
189 * @param array $list List array
193 private function assertList(array $list)
195 $this->assertInternalType('string', $list['name']);
196 $this->assertInternalType('int', $list['id']);
197 $this->assertInternalType('string', $list['id_str']);
198 $this->assertContains($list['mode'], ['public', 'private']);
199 // We could probably do more checks here.
203 * Assert that the string is XML and contain the root element.
205 * @param string $result XML string
206 * @param string $root_element Root element name
210 private function assertXml($result, $root_element)
212 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
213 $this->assertContains('<' . $root_element, $result);
214 // We could probably do more checks here.
218 * Get the path to a temporary empty PNG image.
220 * @return string Path
222 private function getTempImage()
224 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
228 // Empty 1x1 px PNG image
229 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
237 * Test the api_user() function.
241 public function testApiUser()
243 $this->assertEquals($this->selfUser['id'], api_user());
247 * Test the api_user() function with an unallowed user.
251 public function testApiUserWithUnallowedUser()
253 $_SESSION = ['allow_api' => false];
254 $this->assertEquals(false, api_user());
258 * Test the api_source() function.
262 public function testApiSource()
264 $this->assertEquals('api', api_source());
268 * Test the api_source() function with a Twidere user agent.
272 public function testApiSourceWithTwidere()
274 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
275 $this->assertEquals('Twidere', api_source());
279 * Test the api_source() function with a GET parameter.
283 public function testApiSourceWithGet()
285 $_GET['source'] = 'source_name';
286 $this->assertEquals('source_name', api_source());
290 * Test the api_date() function.
294 public function testApiDate()
296 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
300 * Test the api_register_func() function.
304 public function testApiRegisterFunc()
316 $this->assertTrue($API['api_path']['auth']);
317 $this->assertEquals('method', $API['api_path']['method']);
318 $this->assertTrue(is_callable($API['api_path']['func']));
322 * Test the api_login() function without any login.
325 * @runInSeparateProcess
326 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
328 public function testApiLoginWithoutLogin()
330 api_login($this->app);
334 * Test the api_login() function with a bad login.
337 * @runInSeparateProcess
338 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
340 public function testApiLoginWithBadLogin()
342 $_SERVER['PHP_AUTH_USER'] = 'user@server';
343 api_login($this->app);
347 * Test the api_login() function with oAuth.
351 public function testApiLoginWithOauth()
353 $this->markTestIncomplete('Can we test this easily?');
357 * Test the api_login() function with authentication provided by an addon.
361 public function testApiLoginWithAddonAuth()
363 $this->markTestIncomplete('Can we test this easily?');
367 * Test the api_login() function with a correct login.
370 * @runInSeparateProcess
372 public function testApiLoginWithCorrectLogin()
374 $_SERVER['PHP_AUTH_USER'] = 'Test user';
375 $_SERVER['PHP_AUTH_PW'] = 'password';
376 api_login($this->app);
380 * Test the api_login() function with a remote user.
383 * @runInSeparateProcess
384 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
386 public function testApiLoginWithRemoteUser()
388 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
389 api_login($this->app);
393 * Test the api_check_method() function.
397 public function testApiCheckMethod()
399 $this->assertFalse(api_check_method('method'));
403 * Test the api_check_method() function with a correct method.
407 public function testApiCheckMethodWithCorrectMethod()
409 $_SERVER['REQUEST_METHOD'] = 'method';
410 $this->assertTrue(api_check_method('method'));
414 * Test the api_check_method() function with a wildcard.
418 public function testApiCheckMethodWithWildcard()
420 $this->assertTrue(api_check_method('*'));
424 * Test the api_call() function.
427 * @runInSeparateProcess
429 public function testApiCall()
433 'method' => 'method',
434 'func' => function () {
435 return ['data' => ['some_data']];
438 $_SERVER['REQUEST_METHOD'] = 'method';
439 $_SERVER['QUERY_STRING'] = 'q=api_path';
440 $_GET['callback'] = 'callback_name';
442 $args = DI::args()->determine($_SERVER, $_GET);
445 'callback_name(["some_data"])',
446 api_call($this->app, $args)
451 * Test the api_call() function with the profiled enabled.
454 * @runInSeparateProcess
456 public function testApiCallWithProfiler()
460 'method' => 'method',
461 'func' => function () {
462 return ['data' => ['some_data']];
466 $_SERVER['REQUEST_METHOD'] = 'method';
467 $_SERVER['QUERY_STRING'] = 'q=api_path';
469 $args = DI::args()->determine($_SERVER, $_GET);
471 $this->config->set('system', 'profiler', true);
472 $this->config->set('rendertime', 'callstack', true);
473 $this->app->callstack = [
474 'database' => ['some_function' => 200],
475 'database_write' => ['some_function' => 200],
476 'cache' => ['some_function' => 200],
477 'cache_write' => ['some_function' => 200],
478 'network' => ['some_function' => 200]
483 api_call($this->app, $args)
488 * Test the api_call() function without any result.
491 * @runInSeparateProcess
493 public function testApiCallWithNoResult()
497 'method' => 'method',
498 'func' => function () {
502 $_SERVER['REQUEST_METHOD'] = 'method';
503 $_SERVER['QUERY_STRING'] = 'q=api_path';
505 $args = DI::args()->determine($_SERVER, $_GET);
508 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
509 api_call($this->app, $args)
514 * Test the api_call() function with an unimplemented API.
517 * @runInSeparateProcess
519 public function testApiCallWithUninplementedApi()
522 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
528 * Test the api_call() function with a JSON result.
531 * @runInSeparateProcess
533 public function testApiCallWithJson()
537 'method' => 'method',
538 'func' => function () {
539 return ['data' => ['some_data']];
542 $_SERVER['REQUEST_METHOD'] = 'method';
543 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
545 $args = DI::args()->determine($_SERVER, $_GET);
549 api_call($this->app, $args)
554 * Test the api_call() function with an XML result.
557 * @runInSeparateProcess
559 public function testApiCallWithXml()
563 'method' => 'method',
564 'func' => function () {
568 $_SERVER['REQUEST_METHOD'] = 'method';
569 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
571 $args = DI::args()->determine($_SERVER, $_GET);
575 api_call($this->app, $args)
580 * Test the api_call() function with an RSS result.
583 * @runInSeparateProcess
585 public function testApiCallWithRss()
589 'method' => 'method',
590 'func' => function () {
594 $_SERVER['REQUEST_METHOD'] = 'method';
595 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
597 $args = DI::args()->determine($_SERVER, $_GET);
600 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
602 api_call($this->app, $args)
607 * Test the api_call() function with an Atom result.
610 * @runInSeparateProcess
612 public function testApiCallWithAtom()
616 'method' => 'method',
617 'func' => function () {
621 $_SERVER['REQUEST_METHOD'] = 'method';
622 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
624 $args = DI::args()->determine($_SERVER, $_GET);
627 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
629 api_call($this->app, $args)
634 * Test the api_call() function with an unallowed method.
637 * @runInSeparateProcess
639 public function testApiCallWithWrongMethod()
642 $API['api_path'] = ['method' => 'method'];
644 $_SERVER['QUERY_STRING'] = 'q=api_path';
646 $args = DI::args()->determine($_SERVER, $_GET);
649 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
650 api_call($this->app, $args)
655 * Test the api_call() function with an unauthorized user.
658 * @runInSeparateProcess
660 public function testApiCallWithWrongAuth()
664 'method' => 'method',
667 $_SESSION['authenticated'] = false;
668 $_SERVER['REQUEST_METHOD'] = 'method';
669 $_SERVER['QUERY_STRING'] = 'q=api_path';
671 $args = DI::args()->determine($_SERVER, $_GET);
674 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
675 api_call($this->app, $args)
680 * Test the api_error() function with a JSON result.
683 * @runInSeparateProcess
685 public function testApiErrorWithJson()
688 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
689 api_error('json', new HTTPException\OKException('error_message'), DI::args())
694 * Test the api_error() function with an XML result.
697 * @runInSeparateProcess
699 public function testApiErrorWithXml()
702 '<?xml version="1.0"?>' . "\n" .
703 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
704 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
705 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
706 ' <error>error_message</error>' . "\n" .
707 ' <code>200 OK</code>' . "\n" .
708 ' <request/>' . "\n" .
710 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
715 * Test the api_error() function with an RSS result.
718 * @runInSeparateProcess
720 public function testApiErrorWithRss()
723 '<?xml version="1.0"?>' . "\n" .
724 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
725 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
726 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
727 ' <error>error_message</error>' . "\n" .
728 ' <code>200 OK</code>' . "\n" .
729 ' <request/>' . "\n" .
731 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
736 * Test the api_error() function with an Atom result.
739 * @runInSeparateProcess
741 public function testApiErrorWithAtom()
744 '<?xml version="1.0"?>' . "\n" .
745 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
746 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
747 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
748 ' <error>error_message</error>' . "\n" .
749 ' <code>200 OK</code>' . "\n" .
750 ' <request/>' . "\n" .
752 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
757 * Test the api_rss_extra() function.
761 public function testApiRssExtra()
763 $user_info = ['url' => 'user_url', 'lang' => 'en'];
764 $result = api_rss_extra($this->app, [], $user_info);
765 $this->assertEquals($user_info, $result['$user']);
766 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
767 $this->assertArrayHasKey('self', $result['$rss']);
768 $this->assertArrayHasKey('base', $result['$rss']);
769 $this->assertArrayHasKey('updated', $result['$rss']);
770 $this->assertArrayHasKey('atom_updated', $result['$rss']);
771 $this->assertArrayHasKey('language', $result['$rss']);
772 $this->assertArrayHasKey('logo', $result['$rss']);
776 * Test the api_rss_extra() function without any user info.
780 public function testApiRssExtraWithoutUserInfo()
782 $result = api_rss_extra($this->app, [], null);
783 $this->assertInternalType('array', $result['$user']);
784 $this->assertArrayHasKey('alternate', $result['$rss']);
785 $this->assertArrayHasKey('self', $result['$rss']);
786 $this->assertArrayHasKey('base', $result['$rss']);
787 $this->assertArrayHasKey('updated', $result['$rss']);
788 $this->assertArrayHasKey('atom_updated', $result['$rss']);
789 $this->assertArrayHasKey('language', $result['$rss']);
790 $this->assertArrayHasKey('logo', $result['$rss']);
794 * Test the api_unique_id_to_nurl() function.
798 public function testApiUniqueIdToNurl()
800 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
804 * Test the api_unique_id_to_nurl() function with a correct ID.
808 public function testApiUniqueIdToNurlWithCorrectId()
810 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
814 * Test the api_get_user() function.
818 public function testApiGetUser()
820 $user = api_get_user($this->app);
821 $this->assertSelfUser($user);
822 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
823 $this->assertEquals('6fdbe8', $user['profile_link_color']);
824 $this->assertEquals('ededed', $user['profile_background_color']);
828 * Test the api_get_user() function with a Frio schema.
832 public function testApiGetUserWithFrioSchema()
834 $pConfig = $this->dice->create(IPConfig::class);
835 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
836 $user = api_get_user($this->app);
837 $this->assertSelfUser($user);
838 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
839 $this->assertEquals('6fdbe8', $user['profile_link_color']);
840 $this->assertEquals('ededed', $user['profile_background_color']);
844 * Test the api_get_user() function with a custom Frio schema.
848 public function testApiGetUserWithCustomFrioSchema()
850 $pConfig = $this->dice->create(IPConfig::class);
851 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
852 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
853 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
854 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
855 $user = api_get_user($this->app);
856 $this->assertSelfUser($user);
857 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
858 $this->assertEquals('123456', $user['profile_link_color']);
859 $this->assertEquals('123456', $user['profile_background_color']);
863 * Test the api_get_user() function with an empty Frio schema.
867 public function testApiGetUserWithEmptyFrioSchema()
869 $pConfig = $this->dice->create(IPConfig::class);
870 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
871 $user = api_get_user($this->app);
872 $this->assertSelfUser($user);
873 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
874 $this->assertEquals('6fdbe8', $user['profile_link_color']);
875 $this->assertEquals('ededed', $user['profile_background_color']);
879 * Test the api_get_user() function with an user that is not allowed to use the API.
882 * @runInSeparateProcess
884 public function testApiGetUserWithoutApiUser()
886 $_SERVER['PHP_AUTH_USER'] = 'Test user';
887 $_SERVER['PHP_AUTH_PW'] = 'password';
888 $_SESSION['allow_api'] = false;
889 $this->assertFalse(api_get_user($this->app));
893 * Test the api_get_user() function with an user ID in a GET parameter.
897 public function testApiGetUserWithGetId()
899 $_GET['user_id'] = $this->otherUser['id'];
900 $this->assertOtherUser(api_get_user($this->app));
904 * Test the api_get_user() function with a wrong user ID in a GET parameter.
907 * @expectedException Friendica\Network\HTTPException\BadRequestException
909 public function testApiGetUserWithWrongGetId()
911 $_GET['user_id'] = $this->wrongUserId;
912 $this->assertOtherUser(api_get_user($this->app));
916 * Test the api_get_user() function with an user name in a GET parameter.
920 public function testApiGetUserWithGetName()
922 $_GET['screen_name'] = $this->selfUser['nick'];
923 $this->assertSelfUser(api_get_user($this->app));
927 * Test the api_get_user() function with a profile URL in a GET parameter.
931 public function testApiGetUserWithGetUrl()
933 $_GET['profileurl'] = $this->selfUser['nurl'];
934 $this->assertSelfUser(api_get_user($this->app));
938 * Test the api_get_user() function with an user ID in the API path.
942 public function testApiGetUserWithNumericCalledApi()
945 $called_api = ['api_path'];
946 $this->app->argv[1] = $this->otherUser['id'] . '.json';
947 $this->assertOtherUser(api_get_user($this->app));
951 * Test the api_get_user() function with the $called_api global variable.
955 public function testApiGetUserWithCalledApi()
958 $called_api = ['api', 'api_path'];
959 $this->assertSelfUser(api_get_user($this->app));
963 * Test the api_get_user() function with a valid user.
967 public function testApiGetUserWithCorrectUser()
969 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
973 * Test the api_get_user() function with a wrong user ID.
976 * @expectedException Friendica\Network\HTTPException\BadRequestException
978 public function testApiGetUserWithWrongUser()
980 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
984 * Test the api_get_user() function with a 0 user ID.
988 public function testApiGetUserWithZeroUser()
990 $this->assertSelfUser(api_get_user($this->app, 0));
994 * Test the api_item_get_user() function.
998 public function testApiItemGetUser()
1000 $users = api_item_get_user($this->app, []);
1001 $this->assertSelfUser($users[0]);
1005 * Test the api_item_get_user() function with a different item parent.
1009 public function testApiItemGetUserWithDifferentParent()
1011 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
1012 $this->assertSelfUser($users[0]);
1013 $this->assertEquals($users[0], $users[1]);
1017 * Test the api_walk_recursive() function.
1021 public function testApiWalkRecursive()
1024 $this->assertEquals(
1029 // Should we test this with a callback that actually does something?
1037 * Test the api_walk_recursive() function with an array.
1041 public function testApiWalkRecursiveWithArray()
1043 $array = [['item1'], ['item2']];
1044 $this->assertEquals(
1049 // Should we test this with a callback that actually does something?
1057 * Test the api_reformat_xml() function.
1061 public function testApiReformatXml()
1065 $this->assertTrue(api_reformat_xml($item, $key));
1066 $this->assertEquals('true', $item);
1070 * Test the api_reformat_xml() function with a statusnet_api key.
1074 public function testApiReformatXmlWithStatusnetKey()
1077 $key = 'statusnet_api';
1078 $this->assertTrue(api_reformat_xml($item, $key));
1079 $this->assertEquals('statusnet:api', $key);
1083 * Test the api_reformat_xml() function with a friendica_api key.
1087 public function testApiReformatXmlWithFriendicaKey()
1090 $key = 'friendica_api';
1091 $this->assertTrue(api_reformat_xml($item, $key));
1092 $this->assertEquals('friendica:api', $key);
1096 * Test the api_create_xml() function.
1100 public function testApiCreateXml()
1102 $this->assertEquals(
1103 '<?xml version="1.0"?>' . "\n" .
1104 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1105 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1106 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1107 ' <data>some_data</data>' . "\n" .
1108 '</root_element>' . "\n",
1109 api_create_xml(['data' => ['some_data']], 'root_element')
1114 * Test the api_create_xml() function without any XML namespace.
1118 public function testApiCreateXmlWithoutNamespaces()
1120 $this->assertEquals(
1121 '<?xml version="1.0"?>' . "\n" .
1123 ' <data>some_data</data>' . "\n" .
1125 api_create_xml(['data' => ['some_data']], 'ok')
1130 * Test the api_format_data() function.
1134 public function testApiFormatData()
1136 $data = ['some_data'];
1137 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1141 * Test the api_format_data() function with an XML result.
1145 public function testApiFormatDataWithXml()
1147 $this->assertEquals(
1148 '<?xml version="1.0"?>' . "\n" .
1149 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1150 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1151 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1152 ' <data>some_data</data>' . "\n" .
1153 '</root_element>' . "\n",
1154 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1159 * Test the api_account_verify_credentials() function.
1163 public function testApiAccountVerifyCredentials()
1165 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1169 * Test the api_account_verify_credentials() function without an authenticated user.
1172 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1174 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1176 $_SESSION['authenticated'] = false;
1177 api_account_verify_credentials('json');
1181 * Test the requestdata() function.
1185 public function testRequestdata()
1187 $this->assertNull(requestdata('variable_name'));
1191 * Test the requestdata() function with a POST parameter.
1195 public function testRequestdataWithPost()
1197 $_POST['variable_name'] = 'variable_value';
1198 $this->assertEquals('variable_value', requestdata('variable_name'));
1202 * Test the requestdata() function with a GET parameter.
1206 public function testRequestdataWithGet()
1208 $_GET['variable_name'] = 'variable_value';
1209 $this->assertEquals('variable_value', requestdata('variable_name'));
1213 * Test the api_statuses_mediap() function.
1217 public function testApiStatusesMediap()
1219 $this->app->argc = 2;
1227 'tmp_name' => $this->getTempImage(),
1228 'name' => 'spacer.png',
1229 'type' => 'image/png'
1232 $_GET['status'] = '<b>Status content</b>';
1234 $result = api_statuses_mediap('json');
1235 $this->assertStatus($result['status']);
1239 * Test the api_statuses_mediap() function without an authenticated user.
1242 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1244 public function testApiStatusesMediapWithoutAuthenticatedUser()
1246 $_SESSION['authenticated'] = false;
1247 api_statuses_mediap('json');
1251 * Test the api_statuses_update() function.
1255 public function testApiStatusesUpdate()
1257 $_GET['status'] = 'Status content #friendica';
1258 $_GET['in_reply_to_status_id'] = -1;
1267 'tmp_name' => $this->getTempImage(),
1268 'name' => 'spacer.png',
1269 'type' => 'image/png'
1273 $result = api_statuses_update('json');
1274 $this->assertStatus($result['status']);
1278 * Test the api_statuses_update() function with an HTML status.
1282 public function testApiStatusesUpdateWithHtml()
1284 $_GET['htmlstatus'] = '<b>Status content</b>';
1286 $result = api_statuses_update('json');
1287 $this->assertStatus($result['status']);
1291 * Test the api_statuses_update() function without an authenticated user.
1294 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1296 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1298 $_SESSION['authenticated'] = false;
1299 api_statuses_update('json');
1303 * Test the api_statuses_update() function with a parent status.
1307 public function testApiStatusesUpdateWithParent()
1309 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1313 * Test the api_statuses_update() function with a media_ids parameter.
1317 public function testApiStatusesUpdateWithMediaIds()
1319 $this->markTestIncomplete();
1323 * Test the api_statuses_update() function with the throttle limit reached.
1327 public function testApiStatusesUpdateWithDayThrottleReached()
1329 $this->markTestIncomplete();
1333 * Test the api_media_upload() function.
1336 * @expectedException Friendica\Network\HTTPException\BadRequestException
1338 public function testApiMediaUpload()
1344 * Test the api_media_upload() function without an authenticated user.
1347 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1349 public function testApiMediaUploadWithoutAuthenticatedUser()
1351 $_SESSION['authenticated'] = false;
1356 * Test the api_media_upload() function with an invalid uploaded media.
1359 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1361 public function testApiMediaUploadWithMedia()
1366 'tmp_name' => 'tmp_name'
1373 * Test the api_media_upload() function with an valid uploaded media.
1377 public function testApiMediaUploadWithValidMedia()
1385 'tmp_name' => $this->getTempImage(),
1386 'name' => 'spacer.png',
1387 'type' => 'image/png'
1393 $result = api_media_upload();
1394 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1395 $this->assertEquals(1, $result['media']['image']['w']);
1396 $this->assertEquals(1, $result['media']['image']['h']);
1397 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1401 * Test the api_status_show() function.
1403 public function testApiStatusShowWithJson()
1405 $result = api_status_show('json', 1);
1406 $this->assertStatus($result['status']);
1410 * Test the api_status_show() function with an XML result.
1412 public function testApiStatusShowWithXml()
1414 $result = api_status_show('xml', 1);
1415 $this->assertXml($result, 'statuses');
1419 * Test the api_get_last_status() function
1421 public function testApiGetLastStatus()
1423 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1425 $this->assertNotNull($item);
1429 * Test the api_users_show() function.
1433 public function testApiUsersShow()
1435 $result = api_users_show('json');
1436 // We can't use assertSelfUser() here because the user object is missing some properties.
1437 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1438 $this->assertEquals('DFRN', $result['user']['location']);
1439 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1440 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1441 $this->assertEquals('dfrn', $result['user']['network']);
1442 $this->assertTrue($result['user']['verified']);
1446 * Test the api_users_show() function with an XML result.
1450 public function testApiUsersShowWithXml()
1452 $result = api_users_show('xml');
1453 $this->assertXml($result, 'statuses');
1457 * Test the api_users_search() function.
1461 public function testApiUsersSearch()
1463 $_GET['q'] = 'othercontact';
1464 $result = api_users_search('json');
1465 $this->assertOtherUser($result['users'][0]);
1469 * Test the api_users_search() function with an XML result.
1473 public function testApiUsersSearchWithXml()
1475 $_GET['q'] = 'othercontact';
1476 $result = api_users_search('xml');
1477 $this->assertXml($result, 'users');
1481 * Test the api_users_search() function without a GET q parameter.
1484 * @expectedException Friendica\Network\HTTPException\BadRequestException
1486 public function testApiUsersSearchWithoutQuery()
1488 api_users_search('json');
1492 * Test the api_users_lookup() function.
1495 * @expectedException Friendica\Network\HTTPException\NotFoundException
1497 public function testApiUsersLookup()
1499 api_users_lookup('json');
1503 * Test the api_users_lookup() function with an user ID.
1507 public function testApiUsersLookupWithUserId()
1509 $_REQUEST['user_id'] = $this->otherUser['id'];
1510 $result = api_users_lookup('json');
1511 $this->assertOtherUser($result['users'][0]);
1515 * Test the api_search() function.
1519 public function testApiSearch()
1521 $_REQUEST['q'] = 'reply';
1522 $_REQUEST['max_id'] = 10;
1523 $result = api_search('json');
1524 foreach ($result['status'] as $status) {
1525 $this->assertStatus($status);
1526 $this->assertContains('reply', $status['text'], null, true);
1531 * Test the api_search() function a count parameter.
1535 public function testApiSearchWithCount()
1537 $_REQUEST['q'] = 'reply';
1538 $_REQUEST['count'] = 20;
1539 $result = api_search('json');
1540 foreach ($result['status'] as $status) {
1541 $this->assertStatus($status);
1542 $this->assertContains('reply', $status['text'], null, true);
1547 * Test the api_search() function with an rpp parameter.
1551 public function testApiSearchWithRpp()
1553 $_REQUEST['q'] = 'reply';
1554 $_REQUEST['rpp'] = 20;
1555 $result = api_search('json');
1556 foreach ($result['status'] as $status) {
1557 $this->assertStatus($status);
1558 $this->assertContains('reply', $status['text'], null, true);
1563 * Test the api_search() function with an q parameter contains hashtag.
1567 public function testApiSearchWithHashtag()
1569 $_REQUEST['q'] = '%23friendica';
1570 $result = api_search('json');
1571 foreach ($result['status'] as $status) {
1572 $this->assertStatus($status);
1573 $this->assertContains('#friendica', $status['text'], null, true);
1578 * Test the api_search() function with an exclude_replies parameter.
1582 public function testApiSearchWithExcludeReplies()
1584 $_REQUEST['max_id'] = 10;
1585 $_REQUEST['exclude_replies'] = true;
1586 $_REQUEST['q'] = 'friendica';
1587 $result = api_search('json');
1588 foreach ($result['status'] as $status) {
1589 $this->assertStatus($status);
1594 * Test the api_search() function without an authenticated user.
1597 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1599 public function testApiSearchWithUnallowedUser()
1601 $_SESSION['allow_api'] = false;
1602 $_GET['screen_name'] = $this->selfUser['nick'];
1607 * Test the api_search() function without any GET query parameter.
1610 * @expectedException Friendica\Network\HTTPException\BadRequestException
1612 public function testApiSearchWithoutQuery()
1618 * Test the api_statuses_home_timeline() function.
1622 public function testApiStatusesHomeTimeline()
1624 $_REQUEST['max_id'] = 10;
1625 $_REQUEST['exclude_replies'] = true;
1626 $_REQUEST['conversation_id'] = 1;
1627 $result = api_statuses_home_timeline('json');
1628 $this->assertNotEmpty($result['status']);
1629 foreach ($result['status'] as $status) {
1630 $this->assertStatus($status);
1635 * Test the api_statuses_home_timeline() function with a negative page parameter.
1639 public function testApiStatusesHomeTimelineWithNegativePage()
1641 $_REQUEST['page'] = -2;
1642 $result = api_statuses_home_timeline('json');
1643 $this->assertNotEmpty($result['status']);
1644 foreach ($result['status'] as $status) {
1645 $this->assertStatus($status);
1650 * Test the api_statuses_home_timeline() with an unallowed user.
1653 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1655 public function testApiStatusesHomeTimelineWithUnallowedUser()
1657 $_SESSION['allow_api'] = false;
1658 $_GET['screen_name'] = $this->selfUser['nick'];
1659 api_statuses_home_timeline('json');
1663 * Test the api_statuses_home_timeline() function with an RSS result.
1667 public function testApiStatusesHomeTimelineWithRss()
1669 $result = api_statuses_home_timeline('rss');
1670 $this->assertXml($result, 'statuses');
1674 * Test the api_statuses_public_timeline() function.
1678 public function testApiStatusesPublicTimeline()
1680 $_REQUEST['max_id'] = 10;
1681 $_REQUEST['conversation_id'] = 1;
1682 $result = api_statuses_public_timeline('json');
1683 $this->assertNotEmpty($result['status']);
1684 foreach ($result['status'] as $status) {
1685 $this->assertStatus($status);
1690 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1694 public function testApiStatusesPublicTimelineWithExcludeReplies()
1696 $_REQUEST['max_id'] = 10;
1697 $_REQUEST['exclude_replies'] = true;
1698 $result = api_statuses_public_timeline('json');
1699 $this->assertNotEmpty($result['status']);
1700 foreach ($result['status'] as $status) {
1701 $this->assertStatus($status);
1706 * Test the api_statuses_public_timeline() function with a negative page parameter.
1710 public function testApiStatusesPublicTimelineWithNegativePage()
1712 $_REQUEST['page'] = -2;
1713 $result = api_statuses_public_timeline('json');
1714 $this->assertNotEmpty($result['status']);
1715 foreach ($result['status'] as $status) {
1716 $this->assertStatus($status);
1721 * Test the api_statuses_public_timeline() function with an unallowed user.
1724 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1726 public function testApiStatusesPublicTimelineWithUnallowedUser()
1728 $_SESSION['allow_api'] = false;
1729 $_GET['screen_name'] = $this->selfUser['nick'];
1730 api_statuses_public_timeline('json');
1734 * Test the api_statuses_public_timeline() function with an RSS result.
1738 public function testApiStatusesPublicTimelineWithRss()
1740 $result = api_statuses_public_timeline('rss');
1741 $this->assertXml($result, 'statuses');
1745 * Test the api_statuses_networkpublic_timeline() function.
1749 public function testApiStatusesNetworkpublicTimeline()
1751 $_REQUEST['max_id'] = 10;
1752 $result = api_statuses_networkpublic_timeline('json');
1753 $this->assertNotEmpty($result['status']);
1754 foreach ($result['status'] as $status) {
1755 $this->assertStatus($status);
1760 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1764 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1766 $_REQUEST['page'] = -2;
1767 $result = api_statuses_networkpublic_timeline('json');
1768 $this->assertNotEmpty($result['status']);
1769 foreach ($result['status'] as $status) {
1770 $this->assertStatus($status);
1775 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1778 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1780 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1782 $_SESSION['allow_api'] = false;
1783 $_GET['screen_name'] = $this->selfUser['nick'];
1784 api_statuses_networkpublic_timeline('json');
1788 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1792 public function testApiStatusesNetworkpublicTimelineWithRss()
1794 $result = api_statuses_networkpublic_timeline('rss');
1795 $this->assertXml($result, 'statuses');
1799 * Test the api_statuses_show() function.
1802 * @expectedException Friendica\Network\HTTPException\BadRequestException
1804 public function testApiStatusesShow()
1806 api_statuses_show('json');
1810 * Test the api_statuses_show() function with an ID.
1814 public function testApiStatusesShowWithId()
1816 $this->app->argv[3] = 1;
1817 $result = api_statuses_show('json');
1818 $this->assertStatus($result['status']);
1822 * Test the api_statuses_show() function with the conversation parameter.
1826 public function testApiStatusesShowWithConversation()
1828 $this->app->argv[3] = 1;
1829 $_REQUEST['conversation'] = 1;
1830 $result = api_statuses_show('json');
1831 $this->assertNotEmpty($result['status']);
1832 foreach ($result['status'] as $status) {
1833 $this->assertStatus($status);
1838 * Test the api_statuses_show() function with an unallowed user.
1841 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1843 public function testApiStatusesShowWithUnallowedUser()
1845 $_SESSION['allow_api'] = false;
1846 $_GET['screen_name'] = $this->selfUser['nick'];
1847 api_statuses_show('json');
1851 * Test the api_conversation_show() function.
1854 * @expectedException Friendica\Network\HTTPException\BadRequestException
1856 public function testApiConversationShow()
1858 api_conversation_show('json');
1862 * Test the api_conversation_show() function with an ID.
1866 public function testApiConversationShowWithId()
1868 $this->app->argv[3] = 1;
1869 $_REQUEST['max_id'] = 10;
1870 $_REQUEST['page'] = -2;
1871 $result = api_conversation_show('json');
1872 $this->assertNotEmpty($result['status']);
1873 foreach ($result['status'] as $status) {
1874 $this->assertStatus($status);
1879 * Test the api_conversation_show() function with an unallowed user.
1882 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1884 public function testApiConversationShowWithUnallowedUser()
1886 $_SESSION['allow_api'] = false;
1887 $_GET['screen_name'] = $this->selfUser['nick'];
1888 api_conversation_show('json');
1892 * Test the api_statuses_repeat() function.
1895 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1897 public function testApiStatusesRepeat()
1899 api_statuses_repeat('json');
1903 * Test the api_statuses_repeat() function without an authenticated user.
1906 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1908 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1910 $_SESSION['authenticated'] = false;
1911 api_statuses_repeat('json');
1915 * Test the api_statuses_repeat() function with an ID.
1919 public function testApiStatusesRepeatWithId()
1921 $this->app->argv[3] = 1;
1922 $result = api_statuses_repeat('json');
1923 $this->assertStatus($result['status']);
1925 // Also test with a shared status
1926 $this->app->argv[3] = 5;
1927 $result = api_statuses_repeat('json');
1928 $this->assertStatus($result['status']);
1932 * Test the api_statuses_destroy() function.
1935 * @expectedException Friendica\Network\HTTPException\BadRequestException
1937 public function testApiStatusesDestroy()
1939 api_statuses_destroy('json');
1943 * Test the api_statuses_destroy() function without an authenticated user.
1946 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1948 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1950 $_SESSION['authenticated'] = false;
1951 api_statuses_destroy('json');
1955 * Test the api_statuses_destroy() function with an ID.
1959 public function testApiStatusesDestroyWithId()
1961 $this->app->argv[3] = 1;
1962 $result = api_statuses_destroy('json');
1963 $this->assertStatus($result['status']);
1967 * Test the api_statuses_mentions() function.
1971 public function testApiStatusesMentions()
1973 $this->app->user = ['nickname' => $this->selfUser['nick']];
1974 $_REQUEST['max_id'] = 10;
1975 $result = api_statuses_mentions('json');
1976 $this->assertEmpty($result['status']);
1977 // We should test with mentions in the database.
1981 * Test the api_statuses_mentions() function with a negative page parameter.
1985 public function testApiStatusesMentionsWithNegativePage()
1987 $_REQUEST['page'] = -2;
1988 $result = api_statuses_mentions('json');
1989 $this->assertEmpty($result['status']);
1993 * Test the api_statuses_mentions() function with an unallowed user.
1996 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1998 public function testApiStatusesMentionsWithUnallowedUser()
2000 $_SESSION['allow_api'] = false;
2001 $_GET['screen_name'] = $this->selfUser['nick'];
2002 api_statuses_mentions('json');
2006 * Test the api_statuses_mentions() function with an RSS result.
2010 public function testApiStatusesMentionsWithRss()
2012 $result = api_statuses_mentions('rss');
2013 $this->assertXml($result, 'statuses');
2017 * Test the api_statuses_user_timeline() function.
2021 public function testApiStatusesUserTimeline()
2023 $_REQUEST['max_id'] = 10;
2024 $_REQUEST['exclude_replies'] = true;
2025 $_REQUEST['conversation_id'] = 1;
2026 $result = api_statuses_user_timeline('json');
2027 $this->assertNotEmpty($result['status']);
2028 foreach ($result['status'] as $status) {
2029 $this->assertStatus($status);
2034 * Test the api_statuses_user_timeline() function with a negative page parameter.
2038 public function testApiStatusesUserTimelineWithNegativePage()
2040 $_REQUEST['page'] = -2;
2041 $result = api_statuses_user_timeline('json');
2042 $this->assertNotEmpty($result['status']);
2043 foreach ($result['status'] as $status) {
2044 $this->assertStatus($status);
2049 * Test the api_statuses_user_timeline() function with an RSS result.
2053 public function testApiStatusesUserTimelineWithRss()
2055 $result = api_statuses_user_timeline('rss');
2056 $this->assertXml($result, 'statuses');
2060 * Test the api_statuses_user_timeline() function with an unallowed user.
2063 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2065 public function testApiStatusesUserTimelineWithUnallowedUser()
2067 $_SESSION['allow_api'] = false;
2068 $_GET['screen_name'] = $this->selfUser['nick'];
2069 api_statuses_user_timeline('json');
2073 * Test the api_favorites_create_destroy() function.
2076 * @expectedException Friendica\Network\HTTPException\BadRequestException
2078 public function testApiFavoritesCreateDestroy()
2080 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2081 $this->app->argc = count($this->app->argv);
2082 api_favorites_create_destroy('json');
2086 * Test the api_favorites_create_destroy() function with an invalid ID.
2089 * @expectedException Friendica\Network\HTTPException\BadRequestException
2091 public function testApiFavoritesCreateDestroyWithInvalidId()
2093 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2094 $this->app->argc = count($this->app->argv);
2095 api_favorites_create_destroy('json');
2099 * Test the api_favorites_create_destroy() function with an invalid action.
2102 * @expectedException Friendica\Network\HTTPException\BadRequestException
2104 public function testApiFavoritesCreateDestroyWithInvalidAction()
2106 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2107 $this->app->argc = count($this->app->argv);
2108 $_REQUEST['id'] = 1;
2109 api_favorites_create_destroy('json');
2113 * Test the api_favorites_create_destroy() function with the create action.
2117 public function testApiFavoritesCreateDestroyWithCreateAction()
2119 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2120 $this->app->argc = count($this->app->argv);
2121 $_REQUEST['id'] = 3;
2122 $result = api_favorites_create_destroy('json');
2123 $this->assertStatus($result['status']);
2127 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2131 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2133 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2134 $this->app->argc = count($this->app->argv);
2135 $_REQUEST['id'] = 3;
2136 $result = api_favorites_create_destroy('rss');
2137 $this->assertXml($result, 'status');
2141 * Test the api_favorites_create_destroy() function with the destroy action.
2145 public function testApiFavoritesCreateDestroyWithDestroyAction()
2147 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2148 $this->app->argc = count($this->app->argv);
2149 $_REQUEST['id'] = 3;
2150 $result = api_favorites_create_destroy('json');
2151 $this->assertStatus($result['status']);
2155 * Test the api_favorites_create_destroy() function without an authenticated user.
2158 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2160 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2162 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2163 $this->app->argc = count($this->app->argv);
2164 $_SESSION['authenticated'] = false;
2165 api_favorites_create_destroy('json');
2169 * Test the api_favorites() function.
2173 public function testApiFavorites()
2175 $_REQUEST['page'] = -1;
2176 $_REQUEST['max_id'] = 10;
2177 $result = api_favorites('json');
2178 foreach ($result['status'] as $status) {
2179 $this->assertStatus($status);
2184 * Test the api_favorites() function with an RSS result.
2188 public function testApiFavoritesWithRss()
2190 $result = api_favorites('rss');
2191 $this->assertXml($result, 'statuses');
2195 * Test the api_favorites() function with an unallowed user.
2198 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2200 public function testApiFavoritesWithUnallowedUser()
2202 $_SESSION['allow_api'] = false;
2203 $_GET['screen_name'] = $this->selfUser['nick'];
2204 api_favorites('json');
2208 * Test the api_format_messages() function.
2212 public function testApiFormatMessages()
2214 $result = api_format_messages(
2215 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2216 ['id' => 2, 'screen_name' => 'recipient_name'],
2217 ['id' => 3, 'screen_name' => 'sender_name']
2219 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2220 $this->assertEquals(1, $result['id']);
2221 $this->assertEquals(2, $result['recipient_id']);
2222 $this->assertEquals(3, $result['sender_id']);
2223 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2224 $this->assertEquals('sender_name', $result['sender_screen_name']);
2228 * Test the api_format_messages() function with HTML.
2232 public function testApiFormatMessagesWithHtmlText()
2234 $_GET['getText'] = 'html';
2235 $result = api_format_messages(
2236 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2237 ['id' => 2, 'screen_name' => 'recipient_name'],
2238 ['id' => 3, 'screen_name' => 'sender_name']
2240 $this->assertEquals('item_title', $result['title']);
2241 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2245 * Test the api_format_messages() function with plain text.
2249 public function testApiFormatMessagesWithPlainText()
2251 $_GET['getText'] = 'plain';
2252 $result = api_format_messages(
2253 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2254 ['id' => 2, 'screen_name' => 'recipient_name'],
2255 ['id' => 3, 'screen_name' => 'sender_name']
2257 $this->assertEquals('item_title', $result['title']);
2258 $this->assertEquals('item_body', $result['text']);
2262 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2266 public function testApiFormatMessagesWithoutUserObjects()
2268 $_GET['getUserObjects'] = 'false';
2269 $result = api_format_messages(
2270 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2271 ['id' => 2, 'screen_name' => 'recipient_name'],
2272 ['id' => 3, 'screen_name' => 'sender_name']
2274 $this->assertTrue(!isset($result['sender']));
2275 $this->assertTrue(!isset($result['recipient']));
2279 * Test the api_convert_item() function.
2283 public function testApiConvertItem()
2285 $result = api_convert_item(
2287 'network' => 'feed',
2288 'title' => 'item_title',
2289 // We need a long string to test that it is correctly cut
2290 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2291 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2292 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2293 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2294 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2295 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2296 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2297 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2298 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2299 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2300 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2301 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2302 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2303 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2304 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2305 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2306 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2307 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2308 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2309 'repellat officia illum quos impedit quam iste esse unde qui ' .
2310 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2311 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2312 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2313 'plink' => 'item_plink'
2316 $this->assertStringStartsWith('item_title', $result['text']);
2317 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2321 * Test the api_convert_item() function with an empty item body.
2325 public function testApiConvertItemWithoutBody()
2327 $result = api_convert_item(
2329 'network' => 'feed',
2330 'title' => 'item_title',
2332 'plink' => 'item_plink'
2335 $this->assertEquals('item_title', $result['text']);
2336 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2340 * Test the api_convert_item() function with the title in the body.
2344 public function testApiConvertItemWithTitleInBody()
2346 $result = api_convert_item(
2348 'title' => 'item_title',
2349 'body' => 'item_title item_body'
2352 $this->assertEquals('item_title item_body', $result['text']);
2353 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2357 * Test the api_get_attachments() function.
2361 public function testApiGetAttachments()
2364 $this->assertEmpty(api_get_attachments($body));
2368 * Test the api_get_attachments() function with an img tag.
2372 public function testApiGetAttachmentsWithImage()
2374 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2375 $this->assertInternalType('array', api_get_attachments($body));
2379 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2383 public function testApiGetAttachmentsWithImageAndAndStatus()
2385 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2386 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2387 $this->assertInternalType('array', api_get_attachments($body));
2391 * Test the api_get_entitities() function.
2395 public function testApiGetEntitities()
2398 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2402 * Test the api_get_entitities() function with the include_entities parameter.
2406 public function testApiGetEntititiesWithIncludeEntities()
2408 $_REQUEST['include_entities'] = 'true';
2410 $result = api_get_entitities($text, 'bbcode');
2411 $this->assertInternalType('array', $result['hashtags']);
2412 $this->assertInternalType('array', $result['symbols']);
2413 $this->assertInternalType('array', $result['urls']);
2414 $this->assertInternalType('array', $result['user_mentions']);
2418 * Test the api_format_items_embeded_images() function.
2422 public function testApiFormatItemsEmbededImages()
2424 $this->assertEquals(
2425 'text ' . DI::baseUrl() . '/display/item_guid',
2426 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2431 * Test the api_contactlink_to_array() function.
2435 public function testApiContactlinkToArray()
2437 $this->assertEquals(
2442 api_contactlink_to_array('text')
2447 * Test the api_contactlink_to_array() function with an URL.
2451 public function testApiContactlinkToArrayWithUrl()
2453 $this->assertEquals(
2455 'name' => ['link_text'],
2458 api_contactlink_to_array('text <a href="url">link_text</a>')
2463 * Test the api_format_items_activities() function.
2467 public function testApiFormatItemsActivities()
2469 $item = ['uid' => 0, 'uri' => ''];
2470 $result = api_format_items_activities($item);
2471 $this->assertArrayHasKey('like', $result);
2472 $this->assertArrayHasKey('dislike', $result);
2473 $this->assertArrayHasKey('attendyes', $result);
2474 $this->assertArrayHasKey('attendno', $result);
2475 $this->assertArrayHasKey('attendmaybe', $result);
2479 * Test the api_format_items_activities() function with an XML result.
2483 public function testApiFormatItemsActivitiesWithXml()
2485 $item = ['uid' => 0, 'uri' => ''];
2486 $result = api_format_items_activities($item, 'xml');
2487 $this->assertArrayHasKey('friendica:like', $result);
2488 $this->assertArrayHasKey('friendica:dislike', $result);
2489 $this->assertArrayHasKey('friendica:attendyes', $result);
2490 $this->assertArrayHasKey('friendica:attendno', $result);
2491 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2495 * Test the api_format_items() function.
2499 public function testApiFormatItems()
2503 'item_network' => 'item_network',
2509 'author-network' => Protocol::DFRN,
2510 'author-link' => 'http://localhost/profile/othercontact',
2514 $result = api_format_items($items, ['id' => 0], true);
2515 foreach ($result as $status) {
2516 $this->assertStatus($status);
2521 * Test the api_format_items() function with an XML result.
2525 public function testApiFormatItemsWithXml()
2533 'author-network' => Protocol::DFRN,
2534 'author-link' => 'http://localhost/profile/othercontact',
2538 $result = api_format_items($items, ['id' => 0], true, 'xml');
2539 foreach ($result as $status) {
2540 $this->assertStatus($status);
2545 * Test the api_format_items() function.
2549 public function testApiAccountRateLimitStatus()
2551 $result = api_account_rate_limit_status('json');
2552 $this->assertEquals(150, $result['hash']['remaining_hits']);
2553 $this->assertEquals(150, $result['hash']['hourly_limit']);
2554 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2558 * Test the api_format_items() function with an XML result.
2562 public function testApiAccountRateLimitStatusWithXml()
2564 $result = api_account_rate_limit_status('xml');
2565 $this->assertXml($result, 'hash');
2569 * Test the api_help_test() function.
2573 public function testApiHelpTest()
2575 $result = api_help_test('json');
2576 $this->assertEquals(['ok' => 'ok'], $result);
2580 * Test the api_help_test() function with an XML result.
2584 public function testApiHelpTestWithXml()
2586 $result = api_help_test('xml');
2587 $this->assertXml($result, 'ok');
2591 * Test the api_lists_list() function.
2595 public function testApiListsList()
2597 $result = api_lists_list('json');
2598 $this->assertEquals(['lists_list' => []], $result);
2602 * Test the api_lists_ownerships() function.
2606 public function testApiListsOwnerships()
2608 $result = api_lists_ownerships('json');
2609 foreach ($result['lists']['lists'] as $list) {
2610 $this->assertList($list);
2615 * Test the api_lists_ownerships() function without an authenticated user.
2618 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2620 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2622 $_SESSION['authenticated'] = false;
2623 api_lists_ownerships('json');
2627 * Test the api_lists_statuses() function.
2629 * @expectedException Friendica\Network\HTTPException\BadRequestException
2632 public function testApiListsStatuses()
2634 api_lists_statuses('json');
2638 * Test the api_lists_statuses() function with a list ID.
2642 public function testApiListsStatusesWithListId()
2644 $_REQUEST['list_id'] = 1;
2645 $_REQUEST['page'] = -1;
2646 $_REQUEST['max_id'] = 10;
2647 $result = api_lists_statuses('json');
2648 foreach ($result['status'] as $status) {
2649 $this->assertStatus($status);
2654 * Test the api_lists_statuses() function with a list ID and a RSS result.
2658 public function testApiListsStatusesWithListIdAndRss()
2660 $_REQUEST['list_id'] = 1;
2661 $result = api_lists_statuses('rss');
2662 $this->assertXml($result, 'statuses');
2666 * Test the api_lists_statuses() function with an unallowed user.
2669 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2671 public function testApiListsStatusesWithUnallowedUser()
2673 $_SESSION['allow_api'] = false;
2674 $_GET['screen_name'] = $this->selfUser['nick'];
2675 api_lists_statuses('json');
2679 * Test the api_statuses_f() function.
2683 public function testApiStatusesFWithFriends()
2686 $result = api_statuses_f('friends');
2687 $this->assertArrayHasKey('user', $result);
2691 * Test the api_statuses_f() function.
2695 public function testApiStatusesFWithFollowers()
2697 $result = api_statuses_f('followers');
2698 $this->assertArrayHasKey('user', $result);
2702 * Test the api_statuses_f() function.
2706 public function testApiStatusesFWithBlocks()
2708 $result = api_statuses_f('blocks');
2709 $this->assertArrayHasKey('user', $result);
2713 * Test the api_statuses_f() function.
2717 public function testApiStatusesFWithIncoming()
2719 $result = api_statuses_f('incoming');
2720 $this->assertArrayHasKey('user', $result);
2724 * Test the api_statuses_f() function an undefined cursor GET variable.
2728 public function testApiStatusesFWithUndefinedCursor()
2730 $_GET['cursor'] = 'undefined';
2731 $this->assertFalse(api_statuses_f('friends'));
2735 * Test the api_statuses_friends() function.
2739 public function testApiStatusesFriends()
2741 $result = api_statuses_friends('json');
2742 $this->assertArrayHasKey('user', $result);
2746 * Test the api_statuses_friends() function an undefined cursor GET variable.
2750 public function testApiStatusesFriendsWithUndefinedCursor()
2752 $_GET['cursor'] = 'undefined';
2753 $this->assertFalse(api_statuses_friends('json'));
2757 * Test the api_statuses_followers() function.
2761 public function testApiStatusesFollowers()
2763 $result = api_statuses_followers('json');
2764 $this->assertArrayHasKey('user', $result);
2768 * Test the api_statuses_followers() function an undefined cursor GET variable.
2772 public function testApiStatusesFollowersWithUndefinedCursor()
2774 $_GET['cursor'] = 'undefined';
2775 $this->assertFalse(api_statuses_followers('json'));
2779 * Test the api_blocks_list() function.
2783 public function testApiBlocksList()
2785 $result = api_blocks_list('json');
2786 $this->assertArrayHasKey('user', $result);
2790 * Test the api_blocks_list() function an undefined cursor GET variable.
2794 public function testApiBlocksListWithUndefinedCursor()
2796 $_GET['cursor'] = 'undefined';
2797 $this->assertFalse(api_blocks_list('json'));
2801 * Test the api_friendships_incoming() function.
2805 public function testApiFriendshipsIncoming()
2807 $result = api_friendships_incoming('json');
2808 $this->assertArrayHasKey('id', $result);
2812 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2816 public function testApiFriendshipsIncomingWithUndefinedCursor()
2818 $_GET['cursor'] = 'undefined';
2819 $this->assertFalse(api_friendships_incoming('json'));
2823 * Test the api_statusnet_config() function.
2827 public function testApiStatusnetConfig()
2829 $result = api_statusnet_config('json');
2830 $this->assertEquals('localhost', $result['config']['site']['server']);
2831 $this->assertEquals('default', $result['config']['site']['theme']);
2832 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2833 $this->assertTrue($result['config']['site']['fancy']);
2834 $this->assertEquals('en', $result['config']['site']['language']);
2835 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2836 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2837 $this->assertEquals('false', $result['config']['site']['private']);
2838 $this->assertEquals('false', $result['config']['site']['ssl']);
2839 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2843 * Test the api_statusnet_version() function.
2847 public function testApiStatusnetVersion()
2849 $result = api_statusnet_version('json');
2850 $this->assertEquals('0.9.7', $result['version']);
2854 * Test the api_ff_ids() function.
2858 public function testApiFfIds()
2860 $result = api_ff_ids('json', Contact::FOLLOWER);
2861 $this->assertEquals(['id' => []], $result);
2865 * Test the api_ff_ids() function with a result.
2869 public function testApiFfIdsWithResult()
2871 $this->markTestIncomplete();
2875 * Test the api_ff_ids() function without an authenticated user.
2878 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2880 public function testApiFfIdsWithoutAuthenticatedUser()
2882 $_SESSION['authenticated'] = false;
2883 api_ff_ids('json', Contact::FOLLOWER);
2887 * Test the api_friends_ids() function.
2891 public function testApiFriendsIds()
2893 $result = api_friends_ids('json');
2894 $this->assertEquals(['id' => []], $result);
2898 * Test the api_followers_ids() function.
2902 public function testApiFollowersIds()
2904 $result = api_followers_ids('json');
2905 $this->assertEquals(['id' => []], $result);
2909 * Test the api_direct_messages_new() function.
2913 public function testApiDirectMessagesNew()
2915 $result = api_direct_messages_new('json');
2916 $this->assertNull($result);
2920 * Test the api_direct_messages_new() function without an authenticated user.
2923 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2925 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2927 $_SESSION['authenticated'] = false;
2928 api_direct_messages_new('json');
2932 * Test the api_direct_messages_new() function with an user ID.
2936 public function testApiDirectMessagesNewWithUserId()
2938 $_POST['text'] = 'message_text';
2939 $_POST['user_id'] = $this->otherUser['id'];
2940 $result = api_direct_messages_new('json');
2941 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2945 * Test the api_direct_messages_new() function with a screen name.
2949 public function testApiDirectMessagesNewWithScreenName()
2951 $_POST['text'] = 'message_text';
2952 $_POST['screen_name'] = $this->friendUser['nick'];
2953 $result = api_direct_messages_new('json');
2954 $this->assertContains('message_text', $result['direct_message']['text']);
2955 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2956 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2960 * Test the api_direct_messages_new() function with a title.
2964 public function testApiDirectMessagesNewWithTitle()
2966 $_POST['text'] = 'message_text';
2967 $_POST['screen_name'] = $this->friendUser['nick'];
2968 $_REQUEST['title'] = 'message_title';
2969 $result = api_direct_messages_new('json');
2970 $this->assertContains('message_text', $result['direct_message']['text']);
2971 $this->assertContains('message_title', $result['direct_message']['text']);
2972 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2973 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2977 * Test the api_direct_messages_new() function with an RSS result.
2981 public function testApiDirectMessagesNewWithRss()
2983 $_POST['text'] = 'message_text';
2984 $_POST['screen_name'] = $this->friendUser['nick'];
2985 $result = api_direct_messages_new('rss');
2986 $this->assertXml($result, 'direct-messages');
2990 * Test the api_direct_messages_destroy() function.
2993 * @expectedException Friendica\Network\HTTPException\BadRequestException
2995 public function testApiDirectMessagesDestroy()
2997 api_direct_messages_destroy('json');
3001 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3005 public function testApiDirectMessagesDestroyWithVerbose()
3007 $_GET['friendica_verbose'] = 'true';
3008 $result = api_direct_messages_destroy('json');
3009 $this->assertEquals(
3012 'result' => 'error',
3013 'message' => 'message id or parenturi not specified'
3021 * Test the api_direct_messages_destroy() function without an authenticated user.
3024 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3026 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3028 $_SESSION['authenticated'] = false;
3029 api_direct_messages_destroy('json');
3033 * Test the api_direct_messages_destroy() function with a non-zero ID.
3036 * @expectedException Friendica\Network\HTTPException\BadRequestException
3038 public function testApiDirectMessagesDestroyWithId()
3040 $_REQUEST['id'] = 1;
3041 api_direct_messages_destroy('json');
3045 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3049 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3051 $_REQUEST['id'] = 1;
3052 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3053 $_GET['friendica_verbose'] = 'true';
3054 $result = api_direct_messages_destroy('json');
3055 $this->assertEquals(
3058 'result' => 'error',
3059 'message' => 'message id not in database'
3067 * Test the api_direct_messages_destroy() function with a non-zero ID.
3071 public function testApiDirectMessagesDestroyWithCorrectId()
3073 $this->markTestIncomplete('We need to add a dataset for this.');
3077 * Test the api_direct_messages_box() function.
3081 public function testApiDirectMessagesBoxWithSentbox()
3083 $_REQUEST['page'] = -1;
3084 $_REQUEST['max_id'] = 10;
3085 $result = api_direct_messages_box('json', 'sentbox', 'false');
3086 $this->assertArrayHasKey('direct_message', $result);
3090 * Test the api_direct_messages_box() function.
3094 public function testApiDirectMessagesBoxWithConversation()
3096 $result = api_direct_messages_box('json', 'conversation', 'false');
3097 $this->assertArrayHasKey('direct_message', $result);
3101 * Test the api_direct_messages_box() function.
3105 public function testApiDirectMessagesBoxWithAll()
3107 $result = api_direct_messages_box('json', 'all', 'false');
3108 $this->assertArrayHasKey('direct_message', $result);
3112 * Test the api_direct_messages_box() function.
3116 public function testApiDirectMessagesBoxWithInbox()
3118 $result = api_direct_messages_box('json', 'inbox', 'false');
3119 $this->assertArrayHasKey('direct_message', $result);
3123 * Test the api_direct_messages_box() function.
3127 public function testApiDirectMessagesBoxWithVerbose()
3129 $result = api_direct_messages_box('json', 'sentbox', 'true');
3130 $this->assertEquals(
3133 'result' => 'error',
3134 'message' => 'no mails available'
3142 * Test the api_direct_messages_box() function with a RSS result.
3146 public function testApiDirectMessagesBoxWithRss()
3148 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3149 $this->assertXml($result, 'direct-messages');
3153 * Test the api_direct_messages_box() function without an authenticated user.
3156 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3158 public function testApiDirectMessagesBoxWithUnallowedUser()
3160 $_SESSION['allow_api'] = false;
3161 $_GET['screen_name'] = $this->selfUser['nick'];
3162 api_direct_messages_box('json', 'sentbox', 'false');
3166 * Test the api_direct_messages_sentbox() function.
3170 public function testApiDirectMessagesSentbox()
3172 $result = api_direct_messages_sentbox('json');
3173 $this->assertArrayHasKey('direct_message', $result);
3177 * Test the api_direct_messages_inbox() function.
3181 public function testApiDirectMessagesInbox()
3183 $result = api_direct_messages_inbox('json');
3184 $this->assertArrayHasKey('direct_message', $result);
3188 * Test the api_direct_messages_all() function.
3192 public function testApiDirectMessagesAll()
3194 $result = api_direct_messages_all('json');
3195 $this->assertArrayHasKey('direct_message', $result);
3199 * Test the api_direct_messages_conversation() function.
3203 public function testApiDirectMessagesConversation()
3205 $result = api_direct_messages_conversation('json');
3206 $this->assertArrayHasKey('direct_message', $result);
3210 * Test the api_oauth_request_token() function.
3214 public function testApiOauthRequestToken()
3216 $this->markTestIncomplete('exit() kills phpunit as well');
3220 * Test the api_oauth_access_token() function.
3224 public function testApiOauthAccessToken()
3226 $this->markTestIncomplete('exit() kills phpunit as well');
3230 * Test the api_fr_photoalbum_delete() function.
3233 * @expectedException Friendica\Network\HTTPException\BadRequestException
3235 public function testApiFrPhotoalbumDelete()
3237 api_fr_photoalbum_delete('json');
3241 * Test the api_fr_photoalbum_delete() function with an album name.
3244 * @expectedException Friendica\Network\HTTPException\BadRequestException
3246 public function testApiFrPhotoalbumDeleteWithAlbum()
3248 $_REQUEST['album'] = 'album_name';
3249 api_fr_photoalbum_delete('json');
3253 * Test the api_fr_photoalbum_delete() function with an album name.
3257 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3259 $this->markTestIncomplete('We need to add a dataset for this.');
3263 * Test the api_fr_photoalbum_delete() function.
3266 * @expectedException Friendica\Network\HTTPException\BadRequestException
3268 public function testApiFrPhotoalbumUpdate()
3270 api_fr_photoalbum_update('json');
3274 * Test the api_fr_photoalbum_delete() function with an album name.
3277 * @expectedException Friendica\Network\HTTPException\BadRequestException
3279 public function testApiFrPhotoalbumUpdateWithAlbum()
3281 $_REQUEST['album'] = 'album_name';
3282 api_fr_photoalbum_update('json');
3286 * Test the api_fr_photoalbum_delete() function with an album name.
3289 * @expectedException Friendica\Network\HTTPException\BadRequestException
3291 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3293 $_REQUEST['album'] = 'album_name';
3294 $_REQUEST['album_new'] = 'album_name';
3295 api_fr_photoalbum_update('json');
3299 * Test the api_fr_photoalbum_update() function without an authenticated user.
3302 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3304 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3306 $_SESSION['authenticated'] = false;
3307 api_fr_photoalbum_update('json');
3311 * Test the api_fr_photoalbum_delete() function with an album name.
3315 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3317 $this->markTestIncomplete('We need to add a dataset for this.');
3321 * Test the api_fr_photos_list() function.
3325 public function testApiFrPhotosList()
3327 $result = api_fr_photos_list('json');
3328 $this->assertArrayHasKey('photo', $result);
3332 * Test the api_fr_photos_list() function without an authenticated user.
3335 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3337 public function testApiFrPhotosListWithoutAuthenticatedUser()
3339 $_SESSION['authenticated'] = false;
3340 api_fr_photos_list('json');
3344 * Test the api_fr_photo_create_update() function.
3347 * @expectedException Friendica\Network\HTTPException\BadRequestException
3349 public function testApiFrPhotoCreateUpdate()
3351 api_fr_photo_create_update('json');
3355 * Test the api_fr_photo_create_update() function without an authenticated user.
3358 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3360 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3362 $_SESSION['authenticated'] = false;
3363 api_fr_photo_create_update('json');
3367 * Test the api_fr_photo_create_update() function with an album name.
3370 * @expectedException Friendica\Network\HTTPException\BadRequestException
3372 public function testApiFrPhotoCreateUpdateWithAlbum()
3374 $_REQUEST['album'] = 'album_name';
3375 api_fr_photo_create_update('json');
3379 * Test the api_fr_photo_create_update() function with the update mode.
3383 public function testApiFrPhotoCreateUpdateWithUpdate()
3385 $this->markTestIncomplete('We need to create a dataset for this');
3389 * Test the api_fr_photo_create_update() function with an uploaded file.
3393 public function testApiFrPhotoCreateUpdateWithFile()
3395 $this->markTestIncomplete();
3399 * Test the api_fr_photo_delete() function.
3402 * @expectedException Friendica\Network\HTTPException\BadRequestException
3404 public function testApiFrPhotoDelete()
3406 api_fr_photo_delete('json');
3410 * Test the api_fr_photo_delete() function without an authenticated user.
3413 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3415 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3417 $_SESSION['authenticated'] = false;
3418 api_fr_photo_delete('json');
3422 * Test the api_fr_photo_delete() function with a photo ID.
3425 * @expectedException Friendica\Network\HTTPException\BadRequestException
3427 public function testApiFrPhotoDeleteWithPhotoId()
3429 $_REQUEST['photo_id'] = 1;
3430 api_fr_photo_delete('json');
3434 * Test the api_fr_photo_delete() function with a correct photo ID.
3438 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3440 $this->markTestIncomplete('We need to create a dataset for this.');
3444 * Test the api_fr_photo_detail() function.
3447 * @expectedException Friendica\Network\HTTPException\BadRequestException
3449 public function testApiFrPhotoDetail()
3451 api_fr_photo_detail('json');
3455 * Test the api_fr_photo_detail() function without an authenticated user.
3458 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3460 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3462 $_SESSION['authenticated'] = false;
3463 api_fr_photo_detail('json');
3467 * Test the api_fr_photo_detail() function with a photo ID.
3470 * @expectedException Friendica\Network\HTTPException\NotFoundException
3472 public function testApiFrPhotoDetailWithPhotoId()
3474 $_REQUEST['photo_id'] = 1;
3475 api_fr_photo_detail('json');
3479 * Test the api_fr_photo_detail() function with a correct photo ID.
3483 public function testApiFrPhotoDetailCorrectPhotoId()
3485 $this->markTestIncomplete('We need to create a dataset for this.');
3489 * Test the api_account_update_profile_image() function.
3492 * @expectedException Friendica\Network\HTTPException\BadRequestException
3494 public function testApiAccountUpdateProfileImage()
3496 api_account_update_profile_image('json');
3500 * Test the api_account_update_profile_image() function without an authenticated user.
3503 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3505 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3507 $_SESSION['authenticated'] = false;
3508 api_account_update_profile_image('json');
3512 * Test the api_account_update_profile_image() function with an uploaded file.
3515 * @expectedException Friendica\Network\HTTPException\BadRequestException
3517 public function testApiAccountUpdateProfileImageWithUpload()
3519 $this->markTestIncomplete();
3524 * Test the api_account_update_profile() function.
3528 public function testApiAccountUpdateProfile()
3530 $_POST['name'] = 'new_name';
3531 $_POST['description'] = 'new_description';
3532 $result = api_account_update_profile('json');
3533 // We can't use assertSelfUser() here because the user object is missing some properties.
3534 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3535 $this->assertEquals('DFRN', $result['user']['location']);
3536 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3537 $this->assertEquals('dfrn', $result['user']['network']);
3538 $this->assertEquals('new_name', $result['user']['name']);
3539 $this->assertEquals('new_description', $result['user']['description']);
3543 * Test the check_acl_input() function.
3547 public function testCheckAclInput()
3549 $result = check_acl_input('<aclstring>');
3550 // Where does this result come from?
3551 $this->assertEquals(1, $result);
3555 * Test the check_acl_input() function with an empty ACL string.
3559 public function testCheckAclInputWithEmptyAclString()
3561 $result = check_acl_input(' ');
3562 $this->assertFalse($result);
3566 * Test the save_media_to_database() function.
3570 public function testSaveMediaToDatabase()
3572 $this->markTestIncomplete();
3576 * Test the post_photo_item() function.
3580 public function testPostPhotoItem()
3582 $this->markTestIncomplete();
3586 * Test the prepare_photo_data() function.
3590 public function testPreparePhotoData()
3592 $this->markTestIncomplete();
3596 * Test the api_friendica_remoteauth() function.
3599 * @expectedException Friendica\Network\HTTPException\BadRequestException
3601 public function testApiFriendicaRemoteauth()
3603 api_friendica_remoteauth();
3607 * Test the api_friendica_remoteauth() function with an URL.
3610 * @expectedException Friendica\Network\HTTPException\BadRequestException
3612 public function testApiFriendicaRemoteauthWithUrl()
3614 $_GET['url'] = 'url';
3615 $_GET['c_url'] = 'url';
3616 api_friendica_remoteauth();
3620 * Test the api_friendica_remoteauth() function with a correct URL.
3624 public function testApiFriendicaRemoteauthWithCorrectUrl()
3626 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3627 $_GET['url'] = 'url';
3628 $_GET['c_url'] = $this->selfUser['nurl'];
3629 api_friendica_remoteauth();
3633 * Test the api_share_as_retweet() function.
3637 public function testApiShareAsRetweet()
3639 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3640 $result = api_share_as_retweet($item);
3641 $this->assertFalse($result);
3645 * Test the api_share_as_retweet() function with a valid item.
3649 public function testApiShareAsRetweetWithValidItem()
3651 $this->markTestIncomplete();
3655 * Test the api_in_reply_to() function.
3659 public function testApiInReplyTo()
3661 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3662 $this->assertArrayHasKey('status_id', $result);
3663 $this->assertArrayHasKey('user_id', $result);
3664 $this->assertArrayHasKey('status_id_str', $result);
3665 $this->assertArrayHasKey('user_id_str', $result);
3666 $this->assertArrayHasKey('screen_name', $result);
3670 * Test the api_in_reply_to() function with a valid item.
3674 public function testApiInReplyToWithValidItem()
3676 $this->markTestIncomplete();
3680 * Test the api_clean_plain_items() function.
3684 public function testApiCleanPlainItems()
3686 $_REQUEST['include_entities'] = 'true';
3687 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3688 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3692 * Test the api_best_nickname() function.
3696 public function testApiBestNickname()
3699 $result = api_best_nickname($contacts);
3700 $this->assertNull($result);
3704 * Test the api_best_nickname() function with contacts.
3708 public function testApiBestNicknameWithContacts()
3710 $this->markTestIncomplete();
3714 * Test the api_friendica_group_show() function.
3718 public function testApiFriendicaGroupShow()
3720 $this->markTestIncomplete();
3724 * Test the api_friendica_group_delete() function.
3728 public function testApiFriendicaGroupDelete()
3730 $this->markTestIncomplete();
3734 * Test the api_lists_destroy() function.
3738 public function testApiListsDestroy()
3740 $this->markTestIncomplete();
3744 * Test the group_create() function.
3748 public function testGroupCreate()
3750 $this->markTestIncomplete();
3754 * Test the api_friendica_group_create() function.
3758 public function testApiFriendicaGroupCreate()
3760 $this->markTestIncomplete();
3764 * Test the api_lists_create() function.
3768 public function testApiListsCreate()
3770 $this->markTestIncomplete();
3774 * Test the api_friendica_group_update() function.
3778 public function testApiFriendicaGroupUpdate()
3780 $this->markTestIncomplete();
3784 * Test the api_lists_update() function.
3788 public function testApiListsUpdate()
3790 $this->markTestIncomplete();
3794 * Test the api_friendica_activity() function.
3798 public function testApiFriendicaActivity()
3800 $this->markTestIncomplete();
3804 * Test the api_friendica_notification() function.
3807 * @expectedException Friendica\Network\HTTPException\BadRequestException
3809 public function testApiFriendicaNotification()
3811 api_friendica_notification('json');
3815 * Test the api_friendica_notification() function without an authenticated user.
3818 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3820 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3822 $_SESSION['authenticated'] = false;
3823 api_friendica_notification('json');
3827 * Test the api_friendica_notification() function with empty result
3831 public function testApiFriendicaNotificationWithEmptyResult()
3833 $this->app->argv = ['api', 'friendica', 'notification'];
3834 $this->app->argc = count($this->app->argv);
3835 $_SESSION['uid'] = 41;
3836 $result = api_friendica_notification('json');
3837 $this->assertEquals(['note' => false], $result);
3841 * Test the api_friendica_notification() function with an XML result.
3845 public function testApiFriendicaNotificationWithXmlResult()
3847 $this->app->argv = ['api', 'friendica', 'notification'];
3848 $this->app->argc = count($this->app->argv);
3849 $result = api_friendica_notification('xml');
3850 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3852 <?xml version="1.0"?>
3854 <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" parent-uri-id="" 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"/>
3857 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3861 * Test the api_friendica_notification() function with an JSON result.
3865 public function testApiFriendicaNotificationWithJsonResult()
3867 $this->app->argv = ['api', 'friendica', 'notification'];
3868 $this->app->argc = count($this->app->argv);
3869 $result = json_encode(api_friendica_notification('json'));
3870 $this->assertJson($result);
3874 * Test the api_friendica_notification_seen() function.
3878 public function testApiFriendicaNotificationSeen()
3880 $this->markTestIncomplete();
3884 * Test the api_friendica_direct_messages_setseen() function.
3888 public function testApiFriendicaDirectMessagesSetseen()
3890 $this->markTestIncomplete();
3894 * Test the api_friendica_direct_messages_search() function.
3898 public function testApiFriendicaDirectMessagesSearch()
3900 $this->markTestIncomplete();
3904 * Test the api_saved_searches_list() function.
3908 public function testApiSavedSearchesList()
3910 $result = api_saved_searches_list('json');
3911 $this->assertEquals(1, $result['terms'][0]['id']);
3912 $this->assertEquals(1, $result['terms'][0]['id_str']);
3913 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3914 $this->assertEquals('Saved search', $result['terms'][0]['query']);