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\Database\Database;
16 use Friendica\Database\DBStructure;
18 use Friendica\Model\Contact;
19 use Friendica\Network\HTTPException;
20 use Friendica\Test\Util\Database\StaticDatabase;
21 use Friendica\Util\Temporal;
22 use Monolog\Handler\TestHandler;
24 require_once __DIR__ . '/../../include/api.php';
27 * Tests for the API functions.
29 * Functions that use header() need to be tested in a separate process.
30 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
32 class ApiTest extends DatabaseTest
35 * @var TestHandler Can handle log-outputs
42 protected $friendUser;
46 protected $wrongUserId;
58 * Create variables used by tests.
60 protected function setUp()
64 $this->dice = (new Dice())
65 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
66 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
67 ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
68 DI::init($this->dice);
70 /** @var Database $dba */
71 $dba = $this->dice->create(Database::class);
73 $dba->setTestmode(true);
75 DBStructure::checkInitialValues();
77 /** @var IConfig $config */
78 $this->config = $this->dice->create(IConfig::class);
80 $this->config->set('system', 'url', 'http://localhost');
81 $this->config->set('system', 'hostname', 'localhost');
82 $this->config->set('system', 'worker_dont_fork', true);
85 $this->config->set('config', 'hostname', 'localhost');
86 $this->config->set('system', 'throttle_limit_day', 100);
87 $this->config->set('system', 'throttle_limit_week', 100);
88 $this->config->set('system', 'throttle_limit_month', 100);
89 $this->config->set('system', 'theme', 'system_theme');
91 // Load the API dataset for the whole API
92 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
95 $this->app = DI::app();
98 $this->app->argv = ['home'];
100 // User data that the test database is populated with
103 'name' => 'Self contact',
104 'nick' => 'selfcontact',
105 'nurl' => 'http://localhost/profile/selfcontact'
107 $this->friendUser = [
109 'name' => 'Friend contact',
110 'nick' => 'friendcontact',
111 'nurl' => 'http://localhost/profile/friendcontact'
115 'name' => 'othercontact',
116 'nick' => 'othercontact',
117 'nurl' => 'http://localhost/profile/othercontact'
120 // User ID that we know is not in the database
121 $this->wrongUserId = 666;
123 DI::session()->start();
125 // Most API require login so we force the session
128 'authenticated' => true,
129 'uid' => $this->selfUser['id']
138 * Assert that an user array contains expected keys.
140 * @param array $user User array
144 private function assertSelfUser(array $user)
146 $this->assertEquals($this->selfUser['id'], $user['uid']);
147 $this->assertEquals($this->selfUser['id'], $user['cid']);
148 $this->assertEquals(1, $user['self']);
149 $this->assertEquals('DFRN', $user['location']);
150 $this->assertEquals($this->selfUser['name'], $user['name']);
151 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
152 $this->assertEquals('dfrn', $user['network']);
153 $this->assertTrue($user['verified']);
157 * Assert that an user array contains expected keys.
159 * @param array $user User array
163 private function assertOtherUser(array $user)
165 $this->assertEquals($this->otherUser['id'], $user['id']);
166 $this->assertEquals($this->otherUser['id'], $user['id_str']);
167 $this->assertEquals(0, $user['self']);
168 $this->assertEquals($this->otherUser['name'], $user['name']);
169 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
170 $this->assertFalse($user['verified']);
174 * Assert that a status array contains expected keys.
176 * @param array $status Status array
180 private function assertStatus(array $status)
182 $this->assertInternalType('string', $status['text']);
183 $this->assertInternalType('int', $status['id']);
184 // We could probably do more checks here.
188 * Assert that a list array contains expected keys.
190 * @param array $list List array
194 private function assertList(array $list)
196 $this->assertInternalType('string', $list['name']);
197 $this->assertInternalType('int', $list['id']);
198 $this->assertInternalType('string', $list['id_str']);
199 $this->assertContains($list['mode'], ['public', 'private']);
200 // We could probably do more checks here.
204 * Assert that the string is XML and contain the root element.
206 * @param string $result XML string
207 * @param string $root_element Root element name
211 private function assertXml($result, $root_element)
213 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
214 $this->assertContains('<' . $root_element, $result);
215 // We could probably do more checks here.
219 * Get the path to a temporary empty PNG image.
221 * @return string Path
223 private function getTempImage()
225 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
229 // Empty 1x1 px PNG image
230 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
238 * Test the api_user() function.
242 public function testApiUser()
244 $this->assertEquals($this->selfUser['id'], api_user());
248 * Test the api_user() function with an unallowed user.
252 public function testApiUserWithUnallowedUser()
254 $_SESSION = ['allow_api' => false];
255 $this->assertEquals(false, api_user());
259 * Test the api_source() function.
263 public function testApiSource()
265 $this->assertEquals('api', api_source());
269 * Test the api_source() function with a Twidere user agent.
273 public function testApiSourceWithTwidere()
275 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
276 $this->assertEquals('Twidere', api_source());
280 * Test the api_source() function with a GET parameter.
284 public function testApiSourceWithGet()
286 $_GET['source'] = 'source_name';
287 $this->assertEquals('source_name', api_source());
291 * Test the api_date() function.
295 public function testApiDate()
297 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
301 * Test the api_register_func() function.
305 public function testApiRegisterFunc()
317 $this->assertTrue($API['api_path']['auth']);
318 $this->assertEquals('method', $API['api_path']['method']);
319 $this->assertTrue(is_callable($API['api_path']['func']));
323 * Test the api_login() function without any login.
326 * @runInSeparateProcess
327 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
329 public function testApiLoginWithoutLogin()
331 api_login($this->app);
335 * Test the api_login() function with a bad login.
338 * @runInSeparateProcess
339 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
341 public function testApiLoginWithBadLogin()
343 $_SERVER['PHP_AUTH_USER'] = 'user@server';
344 api_login($this->app);
348 * Test the api_login() function with oAuth.
352 public function testApiLoginWithOauth()
354 $this->markTestIncomplete('Can we test this easily?');
358 * Test the api_login() function with authentication provided by an addon.
362 public function testApiLoginWithAddonAuth()
364 $this->markTestIncomplete('Can we test this easily?');
368 * Test the api_login() function with a correct login.
371 * @runInSeparateProcess
373 public function testApiLoginWithCorrectLogin()
375 $_SERVER['PHP_AUTH_USER'] = 'Test user';
376 $_SERVER['PHP_AUTH_PW'] = 'password';
377 api_login($this->app);
381 * Test the api_login() function with a remote user.
384 * @runInSeparateProcess
385 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
387 public function testApiLoginWithRemoteUser()
389 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
390 api_login($this->app);
394 * Test the api_check_method() function.
398 public function testApiCheckMethod()
400 $this->assertFalse(api_check_method('method'));
404 * Test the api_check_method() function with a correct method.
408 public function testApiCheckMethodWithCorrectMethod()
410 $_SERVER['REQUEST_METHOD'] = 'method';
411 $this->assertTrue(api_check_method('method'));
415 * Test the api_check_method() function with a wildcard.
419 public function testApiCheckMethodWithWildcard()
421 $this->assertTrue(api_check_method('*'));
425 * Test the api_call() function.
428 * @runInSeparateProcess
430 public function testApiCall()
434 'method' => 'method',
435 'func' => function () {
436 return ['data' => ['some_data']];
439 $_SERVER['REQUEST_METHOD'] = 'method';
440 $_SERVER['QUERY_STRING'] = 'q=api_path';
441 $_GET['callback'] = 'callback_name';
443 $args = DI::args()->determine($_SERVER, $_GET);
446 'callback_name(["some_data"])',
447 api_call($this->app, $args)
452 * Test the api_call() function with the profiled enabled.
455 * @runInSeparateProcess
457 public function testApiCallWithProfiler()
461 'method' => 'method',
462 'func' => function () {
463 return ['data' => ['some_data']];
467 $_SERVER['REQUEST_METHOD'] = 'method';
468 $_SERVER['QUERY_STRING'] = 'q=api_path';
470 $args = DI::args()->determine($_SERVER, $_GET);
472 $this->config->set('system', 'profiler', true);
473 $this->config->set('rendertime', 'callstack', true);
474 $this->app->callstack = [
475 'database' => ['some_function' => 200],
476 'database_write' => ['some_function' => 200],
477 'cache' => ['some_function' => 200],
478 'cache_write' => ['some_function' => 200],
479 'network' => ['some_function' => 200]
484 api_call($this->app, $args)
489 * Test the api_call() function without any result.
492 * @runInSeparateProcess
494 public function testApiCallWithNoResult()
498 'method' => 'method',
499 'func' => function () {
503 $_SERVER['REQUEST_METHOD'] = 'method';
504 $_SERVER['QUERY_STRING'] = 'q=api_path';
506 $args = DI::args()->determine($_SERVER, $_GET);
509 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
510 api_call($this->app, $args)
515 * Test the api_call() function with an unimplemented API.
518 * @runInSeparateProcess
520 public function testApiCallWithUninplementedApi()
523 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
529 * Test the api_call() function with a JSON result.
532 * @runInSeparateProcess
534 public function testApiCallWithJson()
538 'method' => 'method',
539 'func' => function () {
540 return ['data' => ['some_data']];
543 $_SERVER['REQUEST_METHOD'] = 'method';
544 $_SERVER['QUERY_STRING'] = 'q=api_path.json';
546 $args = DI::args()->determine($_SERVER, $_GET);
550 api_call($this->app, $args)
555 * Test the api_call() function with an XML result.
558 * @runInSeparateProcess
560 public function testApiCallWithXml()
564 'method' => 'method',
565 'func' => function () {
569 $_SERVER['REQUEST_METHOD'] = 'method';
570 $_SERVER['QUERY_STRING'] = 'q=api_path.xml';
572 $args = DI::args()->determine($_SERVER, $_GET);
576 api_call($this->app, $args)
581 * Test the api_call() function with an RSS result.
584 * @runInSeparateProcess
586 public function testApiCallWithRss()
590 'method' => 'method',
591 'func' => function () {
595 $_SERVER['REQUEST_METHOD'] = 'method';
596 $_SERVER['QUERY_STRING'] = 'q=api_path.rss';
598 $args = DI::args()->determine($_SERVER, $_GET);
601 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
603 api_call($this->app, $args)
608 * Test the api_call() function with an Atom result.
611 * @runInSeparateProcess
613 public function testApiCallWithAtom()
617 'method' => 'method',
618 'func' => function () {
622 $_SERVER['REQUEST_METHOD'] = 'method';
623 $_SERVER['QUERY_STRING'] = 'q=api_path.atom';
625 $args = DI::args()->determine($_SERVER, $_GET);
628 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
630 api_call($this->app, $args)
635 * Test the api_call() function with an unallowed method.
638 * @runInSeparateProcess
640 public function testApiCallWithWrongMethod()
643 $API['api_path'] = ['method' => 'method'];
645 $_SERVER['QUERY_STRING'] = 'q=api_path';
647 $args = DI::args()->determine($_SERVER, $_GET);
650 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
651 api_call($this->app, $args)
656 * Test the api_call() function with an unauthorized user.
659 * @runInSeparateProcess
661 public function testApiCallWithWrongAuth()
665 'method' => 'method',
668 $_SESSION['authenticated'] = false;
669 $_SERVER['REQUEST_METHOD'] = 'method';
670 $_SERVER['QUERY_STRING'] = 'q=api_path';
672 $args = DI::args()->determine($_SERVER, $_GET);
675 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
676 api_call($this->app, $args)
681 * Test the api_error() function with a JSON result.
684 * @runInSeparateProcess
686 public function testApiErrorWithJson()
689 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
690 api_error('json', new HTTPException\OKException('error_message'), DI::args())
695 * Test the api_error() function with an XML result.
698 * @runInSeparateProcess
700 public function testApiErrorWithXml()
703 '<?xml version="1.0"?>' . "\n" .
704 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
705 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
706 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
707 ' <error>error_message</error>' . "\n" .
708 ' <code>200 OK</code>' . "\n" .
709 ' <request/>' . "\n" .
711 api_error('xml', new HTTPException\OKException('error_message'), DI::args())
716 * Test the api_error() function with an RSS result.
719 * @runInSeparateProcess
721 public function testApiErrorWithRss()
724 '<?xml version="1.0"?>' . "\n" .
725 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
726 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
727 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
728 ' <error>error_message</error>' . "\n" .
729 ' <code>200 OK</code>' . "\n" .
730 ' <request/>' . "\n" .
732 api_error('rss', new HTTPException\OKException('error_message'), DI::args())
737 * Test the api_error() function with an Atom result.
740 * @runInSeparateProcess
742 public function testApiErrorWithAtom()
745 '<?xml version="1.0"?>' . "\n" .
746 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
747 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
748 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
749 ' <error>error_message</error>' . "\n" .
750 ' <code>200 OK</code>' . "\n" .
751 ' <request/>' . "\n" .
753 api_error('atom', new HTTPException\OKException('error_message'), DI::args())
758 * Test the api_rss_extra() function.
762 public function testApiRssExtra()
764 $user_info = ['url' => 'user_url', 'lang' => 'en'];
765 $result = api_rss_extra($this->app, [], $user_info);
766 $this->assertEquals($user_info, $result['$user']);
767 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
768 $this->assertArrayHasKey('self', $result['$rss']);
769 $this->assertArrayHasKey('base', $result['$rss']);
770 $this->assertArrayHasKey('updated', $result['$rss']);
771 $this->assertArrayHasKey('atom_updated', $result['$rss']);
772 $this->assertArrayHasKey('language', $result['$rss']);
773 $this->assertArrayHasKey('logo', $result['$rss']);
777 * Test the api_rss_extra() function without any user info.
781 public function testApiRssExtraWithoutUserInfo()
783 $result = api_rss_extra($this->app, [], null);
784 $this->assertInternalType('array', $result['$user']);
785 $this->assertArrayHasKey('alternate', $result['$rss']);
786 $this->assertArrayHasKey('self', $result['$rss']);
787 $this->assertArrayHasKey('base', $result['$rss']);
788 $this->assertArrayHasKey('updated', $result['$rss']);
789 $this->assertArrayHasKey('atom_updated', $result['$rss']);
790 $this->assertArrayHasKey('language', $result['$rss']);
791 $this->assertArrayHasKey('logo', $result['$rss']);
795 * Test the api_unique_id_to_nurl() function.
799 public function testApiUniqueIdToNurl()
801 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
805 * Test the api_unique_id_to_nurl() function with a correct ID.
809 public function testApiUniqueIdToNurlWithCorrectId()
811 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
815 * Test the api_get_user() function.
819 public function testApiGetUser()
821 $user = api_get_user($this->app);
822 $this->assertSelfUser($user);
823 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
824 $this->assertEquals('6fdbe8', $user['profile_link_color']);
825 $this->assertEquals('ededed', $user['profile_background_color']);
829 * Test the api_get_user() function with a Frio schema.
833 public function testApiGetUserWithFrioSchema()
835 $pConfig = $this->dice->create(IPConfig::class);
836 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
837 $user = api_get_user($this->app);
838 $this->assertSelfUser($user);
839 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
840 $this->assertEquals('6fdbe8', $user['profile_link_color']);
841 $this->assertEquals('ededed', $user['profile_background_color']);
845 * Test the api_get_user() function with a custom Frio schema.
849 public function testApiGetUserWithCustomFrioSchema()
851 $pConfig = $this->dice->create(IPConfig::class);
852 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
853 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
854 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
855 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
856 $user = api_get_user($this->app);
857 $this->assertSelfUser($user);
858 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
859 $this->assertEquals('123456', $user['profile_link_color']);
860 $this->assertEquals('123456', $user['profile_background_color']);
864 * Test the api_get_user() function with an empty Frio schema.
868 public function testApiGetUserWithEmptyFrioSchema()
870 $pConfig = $this->dice->create(IPConfig::class);
871 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
872 $user = api_get_user($this->app);
873 $this->assertSelfUser($user);
874 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
875 $this->assertEquals('6fdbe8', $user['profile_link_color']);
876 $this->assertEquals('ededed', $user['profile_background_color']);
880 * Test the api_get_user() function with an user that is not allowed to use the API.
883 * @runInSeparateProcess
885 public function testApiGetUserWithoutApiUser()
887 $_SERVER['PHP_AUTH_USER'] = 'Test user';
888 $_SERVER['PHP_AUTH_PW'] = 'password';
889 $_SESSION['allow_api'] = false;
890 $this->assertFalse(api_get_user($this->app));
894 * Test the api_get_user() function with an user ID in a GET parameter.
898 public function testApiGetUserWithGetId()
900 $_GET['user_id'] = $this->otherUser['id'];
901 $this->assertOtherUser(api_get_user($this->app));
905 * Test the api_get_user() function with a wrong user ID in a GET parameter.
908 * @expectedException Friendica\Network\HTTPException\BadRequestException
910 public function testApiGetUserWithWrongGetId()
912 $_GET['user_id'] = $this->wrongUserId;
913 $this->assertOtherUser(api_get_user($this->app));
917 * Test the api_get_user() function with an user name in a GET parameter.
921 public function testApiGetUserWithGetName()
923 $_GET['screen_name'] = $this->selfUser['nick'];
924 $this->assertSelfUser(api_get_user($this->app));
928 * Test the api_get_user() function with a profile URL in a GET parameter.
932 public function testApiGetUserWithGetUrl()
934 $_GET['profileurl'] = $this->selfUser['nurl'];
935 $this->assertSelfUser(api_get_user($this->app));
939 * Test the api_get_user() function with an user ID in the API path.
943 public function testApiGetUserWithNumericCalledApi()
946 $called_api = ['api_path'];
947 $this->app->argv[1] = $this->otherUser['id'] . '.json';
948 $this->assertOtherUser(api_get_user($this->app));
952 * Test the api_get_user() function with the $called_api global variable.
956 public function testApiGetUserWithCalledApi()
959 $called_api = ['api', 'api_path'];
960 $this->assertSelfUser(api_get_user($this->app));
964 * Test the api_get_user() function with a valid user.
968 public function testApiGetUserWithCorrectUser()
970 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
974 * Test the api_get_user() function with a wrong user ID.
977 * @expectedException Friendica\Network\HTTPException\BadRequestException
979 public function testApiGetUserWithWrongUser()
981 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
985 * Test the api_get_user() function with a 0 user ID.
989 public function testApiGetUserWithZeroUser()
991 $this->assertSelfUser(api_get_user($this->app, 0));
995 * Test the api_item_get_user() function.
999 public function testApiItemGetUser()
1001 $users = api_item_get_user($this->app, []);
1002 $this->assertSelfUser($users[0]);
1006 * Test the api_item_get_user() function with a different item parent.
1010 public function testApiItemGetUserWithDifferentParent()
1012 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
1013 $this->assertSelfUser($users[0]);
1014 $this->assertEquals($users[0], $users[1]);
1018 * Test the api_walk_recursive() function.
1022 public function testApiWalkRecursive()
1025 $this->assertEquals(
1030 // Should we test this with a callback that actually does something?
1038 * Test the api_walk_recursive() function with an array.
1042 public function testApiWalkRecursiveWithArray()
1044 $array = [['item1'], ['item2']];
1045 $this->assertEquals(
1050 // Should we test this with a callback that actually does something?
1058 * Test the api_reformat_xml() function.
1062 public function testApiReformatXml()
1066 $this->assertTrue(api_reformat_xml($item, $key));
1067 $this->assertEquals('true', $item);
1071 * Test the api_reformat_xml() function with a statusnet_api key.
1075 public function testApiReformatXmlWithStatusnetKey()
1078 $key = 'statusnet_api';
1079 $this->assertTrue(api_reformat_xml($item, $key));
1080 $this->assertEquals('statusnet:api', $key);
1084 * Test the api_reformat_xml() function with a friendica_api key.
1088 public function testApiReformatXmlWithFriendicaKey()
1091 $key = 'friendica_api';
1092 $this->assertTrue(api_reformat_xml($item, $key));
1093 $this->assertEquals('friendica:api', $key);
1097 * Test the api_create_xml() function.
1101 public function testApiCreateXml()
1103 $this->assertEquals(
1104 '<?xml version="1.0"?>' . "\n" .
1105 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1106 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1107 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1108 ' <data>some_data</data>' . "\n" .
1109 '</root_element>' . "\n",
1110 api_create_xml(['data' => ['some_data']], 'root_element')
1115 * Test the api_create_xml() function without any XML namespace.
1119 public function testApiCreateXmlWithoutNamespaces()
1121 $this->assertEquals(
1122 '<?xml version="1.0"?>' . "\n" .
1124 ' <data>some_data</data>' . "\n" .
1126 api_create_xml(['data' => ['some_data']], 'ok')
1131 * Test the api_format_data() function.
1135 public function testApiFormatData()
1137 $data = ['some_data'];
1138 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1142 * Test the api_format_data() function with an XML result.
1146 public function testApiFormatDataWithXml()
1148 $this->assertEquals(
1149 '<?xml version="1.0"?>' . "\n" .
1150 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1151 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1152 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1153 ' <data>some_data</data>' . "\n" .
1154 '</root_element>' . "\n",
1155 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1160 * Test the api_account_verify_credentials() function.
1164 public function testApiAccountVerifyCredentials()
1166 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1170 * Test the api_account_verify_credentials() function without an authenticated user.
1173 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1175 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1177 $_SESSION['authenticated'] = false;
1178 api_account_verify_credentials('json');
1182 * Test the requestdata() function.
1186 public function testRequestdata()
1188 $this->assertNull(requestdata('variable_name'));
1192 * Test the requestdata() function with a POST parameter.
1196 public function testRequestdataWithPost()
1198 $_POST['variable_name'] = 'variable_value';
1199 $this->assertEquals('variable_value', requestdata('variable_name'));
1203 * Test the requestdata() function with a GET parameter.
1207 public function testRequestdataWithGet()
1209 $_GET['variable_name'] = 'variable_value';
1210 $this->assertEquals('variable_value', requestdata('variable_name'));
1214 * Test the api_statuses_mediap() function.
1218 public function testApiStatusesMediap()
1220 $this->app->argc = 2;
1228 'tmp_name' => $this->getTempImage(),
1229 'name' => 'spacer.png',
1230 'type' => 'image/png'
1233 $_GET['status'] = '<b>Status content</b>';
1235 $result = api_statuses_mediap('json');
1236 $this->assertStatus($result['status']);
1240 * Test the api_statuses_mediap() function without an authenticated user.
1243 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1245 public function testApiStatusesMediapWithoutAuthenticatedUser()
1247 $_SESSION['authenticated'] = false;
1248 api_statuses_mediap('json');
1252 * Test the api_statuses_update() function.
1256 public function testApiStatusesUpdate()
1258 $_GET['status'] = 'Status content #friendica';
1259 $_GET['in_reply_to_status_id'] = -1;
1268 'tmp_name' => $this->getTempImage(),
1269 'name' => 'spacer.png',
1270 'type' => 'image/png'
1274 $result = api_statuses_update('json');
1275 $this->assertStatus($result['status']);
1279 * Test the api_statuses_update() function with an HTML status.
1283 public function testApiStatusesUpdateWithHtml()
1285 $_GET['htmlstatus'] = '<b>Status content</b>';
1287 $result = api_statuses_update('json');
1288 $this->assertStatus($result['status']);
1292 * Test the api_statuses_update() function without an authenticated user.
1295 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1297 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1299 $_SESSION['authenticated'] = false;
1300 api_statuses_update('json');
1304 * Test the api_statuses_update() function with a parent status.
1308 public function testApiStatusesUpdateWithParent()
1310 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1314 * Test the api_statuses_update() function with a media_ids parameter.
1318 public function testApiStatusesUpdateWithMediaIds()
1320 $this->markTestIncomplete();
1324 * Test the api_statuses_update() function with the throttle limit reached.
1328 public function testApiStatusesUpdateWithDayThrottleReached()
1330 $this->markTestIncomplete();
1334 * Test the api_media_upload() function.
1337 * @expectedException Friendica\Network\HTTPException\BadRequestException
1339 public function testApiMediaUpload()
1345 * Test the api_media_upload() function without an authenticated user.
1348 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1350 public function testApiMediaUploadWithoutAuthenticatedUser()
1352 $_SESSION['authenticated'] = false;
1357 * Test the api_media_upload() function with an invalid uploaded media.
1360 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1362 public function testApiMediaUploadWithMedia()
1367 'tmp_name' => 'tmp_name'
1374 * Test the api_media_upload() function with an valid uploaded media.
1378 public function testApiMediaUploadWithValidMedia()
1386 'tmp_name' => $this->getTempImage(),
1387 'name' => 'spacer.png',
1388 'type' => 'image/png'
1394 $result = api_media_upload();
1395 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1396 $this->assertEquals(1, $result['media']['image']['w']);
1397 $this->assertEquals(1, $result['media']['image']['h']);
1398 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1402 * Test the api_status_show() function.
1404 public function testApiStatusShowWithJson()
1406 $result = api_status_show('json', 1);
1407 $this->assertStatus($result['status']);
1411 * Test the api_status_show() function with an XML result.
1413 public function testApiStatusShowWithXml()
1415 $result = api_status_show('xml', 1);
1416 $this->assertXml($result, 'statuses');
1420 * Test the api_get_last_status() function
1422 public function testApiGetLastStatus()
1424 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1426 $this->assertNotNull($item);
1430 * Test the api_users_show() function.
1434 public function testApiUsersShow()
1436 $result = api_users_show('json');
1437 // We can't use assertSelfUser() here because the user object is missing some properties.
1438 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1439 $this->assertEquals('DFRN', $result['user']['location']);
1440 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1441 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1442 $this->assertEquals('dfrn', $result['user']['network']);
1443 $this->assertTrue($result['user']['verified']);
1447 * Test the api_users_show() function with an XML result.
1451 public function testApiUsersShowWithXml()
1453 $result = api_users_show('xml');
1454 $this->assertXml($result, 'statuses');
1458 * Test the api_users_search() function.
1462 public function testApiUsersSearch()
1464 $_GET['q'] = 'othercontact';
1465 $result = api_users_search('json');
1466 $this->assertOtherUser($result['users'][0]);
1470 * Test the api_users_search() function with an XML result.
1474 public function testApiUsersSearchWithXml()
1476 $_GET['q'] = 'othercontact';
1477 $result = api_users_search('xml');
1478 $this->assertXml($result, 'users');
1482 * Test the api_users_search() function without a GET q parameter.
1485 * @expectedException Friendica\Network\HTTPException\BadRequestException
1487 public function testApiUsersSearchWithoutQuery()
1489 api_users_search('json');
1493 * Test the api_users_lookup() function.
1496 * @expectedException Friendica\Network\HTTPException\NotFoundException
1498 public function testApiUsersLookup()
1500 api_users_lookup('json');
1504 * Test the api_users_lookup() function with an user ID.
1508 public function testApiUsersLookupWithUserId()
1510 $_REQUEST['user_id'] = $this->otherUser['id'];
1511 $result = api_users_lookup('json');
1512 $this->assertOtherUser($result['users'][0]);
1516 * Test the api_search() function.
1520 public function testApiSearch()
1522 $_REQUEST['q'] = 'reply';
1523 $_REQUEST['max_id'] = 10;
1524 $result = api_search('json');
1525 foreach ($result['status'] as $status) {
1526 $this->assertStatus($status);
1527 $this->assertContains('reply', $status['text'], null, true);
1532 * Test the api_search() function a count parameter.
1536 public function testApiSearchWithCount()
1538 $_REQUEST['q'] = 'reply';
1539 $_REQUEST['count'] = 20;
1540 $result = api_search('json');
1541 foreach ($result['status'] as $status) {
1542 $this->assertStatus($status);
1543 $this->assertContains('reply', $status['text'], null, true);
1548 * Test the api_search() function with an rpp parameter.
1552 public function testApiSearchWithRpp()
1554 $_REQUEST['q'] = 'reply';
1555 $_REQUEST['rpp'] = 20;
1556 $result = api_search('json');
1557 foreach ($result['status'] as $status) {
1558 $this->assertStatus($status);
1559 $this->assertContains('reply', $status['text'], null, true);
1564 * Test the api_search() function with an q parameter contains hashtag.
1568 public function testApiSearchWithHashtag()
1570 $_REQUEST['q'] = '%23friendica';
1571 $result = api_search('json');
1572 foreach ($result['status'] as $status) {
1573 $this->assertStatus($status);
1574 $this->assertContains('#friendica', $status['text'], null, true);
1579 * Test the api_search() function with an exclude_replies parameter.
1583 public function testApiSearchWithExcludeReplies()
1585 $_REQUEST['max_id'] = 10;
1586 $_REQUEST['exclude_replies'] = true;
1587 $_REQUEST['q'] = 'friendica';
1588 $result = api_search('json');
1589 foreach ($result['status'] as $status) {
1590 $this->assertStatus($status);
1595 * Test the api_search() function without an authenticated user.
1598 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1600 public function testApiSearchWithUnallowedUser()
1602 $_SESSION['allow_api'] = false;
1603 $_GET['screen_name'] = $this->selfUser['nick'];
1608 * Test the api_search() function without any GET query parameter.
1611 * @expectedException Friendica\Network\HTTPException\BadRequestException
1613 public function testApiSearchWithoutQuery()
1619 * Test the api_statuses_home_timeline() function.
1623 public function testApiStatusesHomeTimeline()
1625 $_REQUEST['max_id'] = 10;
1626 $_REQUEST['exclude_replies'] = true;
1627 $_REQUEST['conversation_id'] = 1;
1628 $result = api_statuses_home_timeline('json');
1629 $this->assertNotEmpty($result['status']);
1630 foreach ($result['status'] as $status) {
1631 $this->assertStatus($status);
1636 * Test the api_statuses_home_timeline() function with a negative page parameter.
1640 public function testApiStatusesHomeTimelineWithNegativePage()
1642 $_REQUEST['page'] = -2;
1643 $result = api_statuses_home_timeline('json');
1644 $this->assertNotEmpty($result['status']);
1645 foreach ($result['status'] as $status) {
1646 $this->assertStatus($status);
1651 * Test the api_statuses_home_timeline() with an unallowed user.
1654 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1656 public function testApiStatusesHomeTimelineWithUnallowedUser()
1658 $_SESSION['allow_api'] = false;
1659 $_GET['screen_name'] = $this->selfUser['nick'];
1660 api_statuses_home_timeline('json');
1664 * Test the api_statuses_home_timeline() function with an RSS result.
1668 public function testApiStatusesHomeTimelineWithRss()
1670 $result = api_statuses_home_timeline('rss');
1671 $this->assertXml($result, 'statuses');
1675 * Test the api_statuses_public_timeline() function.
1679 public function testApiStatusesPublicTimeline()
1681 $_REQUEST['max_id'] = 10;
1682 $_REQUEST['conversation_id'] = 1;
1683 $result = api_statuses_public_timeline('json');
1684 $this->assertNotEmpty($result['status']);
1685 foreach ($result['status'] as $status) {
1686 $this->assertStatus($status);
1691 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1695 public function testApiStatusesPublicTimelineWithExcludeReplies()
1697 $_REQUEST['max_id'] = 10;
1698 $_REQUEST['exclude_replies'] = true;
1699 $result = api_statuses_public_timeline('json');
1700 $this->assertNotEmpty($result['status']);
1701 foreach ($result['status'] as $status) {
1702 $this->assertStatus($status);
1707 * Test the api_statuses_public_timeline() function with a negative page parameter.
1711 public function testApiStatusesPublicTimelineWithNegativePage()
1713 $_REQUEST['page'] = -2;
1714 $result = api_statuses_public_timeline('json');
1715 $this->assertNotEmpty($result['status']);
1716 foreach ($result['status'] as $status) {
1717 $this->assertStatus($status);
1722 * Test the api_statuses_public_timeline() function with an unallowed user.
1725 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1727 public function testApiStatusesPublicTimelineWithUnallowedUser()
1729 $_SESSION['allow_api'] = false;
1730 $_GET['screen_name'] = $this->selfUser['nick'];
1731 api_statuses_public_timeline('json');
1735 * Test the api_statuses_public_timeline() function with an RSS result.
1739 public function testApiStatusesPublicTimelineWithRss()
1741 $result = api_statuses_public_timeline('rss');
1742 $this->assertXml($result, 'statuses');
1746 * Test the api_statuses_networkpublic_timeline() function.
1750 public function testApiStatusesNetworkpublicTimeline()
1752 $_REQUEST['max_id'] = 10;
1753 $result = api_statuses_networkpublic_timeline('json');
1754 $this->assertNotEmpty($result['status']);
1755 foreach ($result['status'] as $status) {
1756 $this->assertStatus($status);
1761 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1765 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1767 $_REQUEST['page'] = -2;
1768 $result = api_statuses_networkpublic_timeline('json');
1769 $this->assertNotEmpty($result['status']);
1770 foreach ($result['status'] as $status) {
1771 $this->assertStatus($status);
1776 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1779 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1781 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1783 $_SESSION['allow_api'] = false;
1784 $_GET['screen_name'] = $this->selfUser['nick'];
1785 api_statuses_networkpublic_timeline('json');
1789 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1793 public function testApiStatusesNetworkpublicTimelineWithRss()
1795 $result = api_statuses_networkpublic_timeline('rss');
1796 $this->assertXml($result, 'statuses');
1800 * Test the api_statuses_show() function.
1803 * @expectedException Friendica\Network\HTTPException\BadRequestException
1805 public function testApiStatusesShow()
1807 api_statuses_show('json');
1811 * Test the api_statuses_show() function with an ID.
1815 public function testApiStatusesShowWithId()
1817 $this->app->argv[3] = 1;
1818 $result = api_statuses_show('json');
1819 $this->assertStatus($result['status']);
1823 * Test the api_statuses_show() function with the conversation parameter.
1827 public function testApiStatusesShowWithConversation()
1829 $this->app->argv[3] = 1;
1830 $_REQUEST['conversation'] = 1;
1831 $result = api_statuses_show('json');
1832 $this->assertNotEmpty($result['status']);
1833 foreach ($result['status'] as $status) {
1834 $this->assertStatus($status);
1839 * Test the api_statuses_show() function with an unallowed user.
1842 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1844 public function testApiStatusesShowWithUnallowedUser()
1846 $_SESSION['allow_api'] = false;
1847 $_GET['screen_name'] = $this->selfUser['nick'];
1848 api_statuses_show('json');
1852 * Test the api_conversation_show() function.
1855 * @expectedException Friendica\Network\HTTPException\BadRequestException
1857 public function testApiConversationShow()
1859 api_conversation_show('json');
1863 * Test the api_conversation_show() function with an ID.
1867 public function testApiConversationShowWithId()
1869 $this->app->argv[3] = 1;
1870 $_REQUEST['max_id'] = 10;
1871 $_REQUEST['page'] = -2;
1872 $result = api_conversation_show('json');
1873 $this->assertNotEmpty($result['status']);
1874 foreach ($result['status'] as $status) {
1875 $this->assertStatus($status);
1880 * Test the api_conversation_show() function with an unallowed user.
1883 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1885 public function testApiConversationShowWithUnallowedUser()
1887 $_SESSION['allow_api'] = false;
1888 $_GET['screen_name'] = $this->selfUser['nick'];
1889 api_conversation_show('json');
1893 * Test the api_statuses_repeat() function.
1896 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1898 public function testApiStatusesRepeat()
1900 api_statuses_repeat('json');
1904 * Test the api_statuses_repeat() function without an authenticated user.
1907 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1909 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1911 $_SESSION['authenticated'] = false;
1912 api_statuses_repeat('json');
1916 * Test the api_statuses_repeat() function with an ID.
1920 public function testApiStatusesRepeatWithId()
1922 $this->app->argv[3] = 1;
1923 $result = api_statuses_repeat('json');
1924 $this->assertStatus($result['status']);
1926 // Also test with a shared status
1927 $this->app->argv[3] = 5;
1928 $result = api_statuses_repeat('json');
1929 $this->assertStatus($result['status']);
1933 * Test the api_statuses_destroy() function.
1936 * @expectedException Friendica\Network\HTTPException\BadRequestException
1938 public function testApiStatusesDestroy()
1940 api_statuses_destroy('json');
1944 * Test the api_statuses_destroy() function without an authenticated user.
1947 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1949 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1951 $_SESSION['authenticated'] = false;
1952 api_statuses_destroy('json');
1956 * Test the api_statuses_destroy() function with an ID.
1960 public function testApiStatusesDestroyWithId()
1962 $this->app->argv[3] = 1;
1963 $result = api_statuses_destroy('json');
1964 $this->assertStatus($result['status']);
1968 * Test the api_statuses_mentions() function.
1972 public function testApiStatusesMentions()
1974 $this->app->user = ['nickname' => $this->selfUser['nick']];
1975 $_REQUEST['max_id'] = 10;
1976 $result = api_statuses_mentions('json');
1977 $this->assertEmpty($result['status']);
1978 // We should test with mentions in the database.
1982 * Test the api_statuses_mentions() function with a negative page parameter.
1986 public function testApiStatusesMentionsWithNegativePage()
1988 $_REQUEST['page'] = -2;
1989 $result = api_statuses_mentions('json');
1990 $this->assertEmpty($result['status']);
1994 * Test the api_statuses_mentions() function with an unallowed user.
1997 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1999 public function testApiStatusesMentionsWithUnallowedUser()
2001 $_SESSION['allow_api'] = false;
2002 $_GET['screen_name'] = $this->selfUser['nick'];
2003 api_statuses_mentions('json');
2007 * Test the api_statuses_mentions() function with an RSS result.
2011 public function testApiStatusesMentionsWithRss()
2013 $result = api_statuses_mentions('rss');
2014 $this->assertXml($result, 'statuses');
2018 * Test the api_statuses_user_timeline() function.
2022 public function testApiStatusesUserTimeline()
2024 $_REQUEST['max_id'] = 10;
2025 $_REQUEST['exclude_replies'] = true;
2026 $_REQUEST['conversation_id'] = 1;
2027 $result = api_statuses_user_timeline('json');
2028 $this->assertNotEmpty($result['status']);
2029 foreach ($result['status'] as $status) {
2030 $this->assertStatus($status);
2035 * Test the api_statuses_user_timeline() function with a negative page parameter.
2039 public function testApiStatusesUserTimelineWithNegativePage()
2041 $_REQUEST['page'] = -2;
2042 $result = api_statuses_user_timeline('json');
2043 $this->assertNotEmpty($result['status']);
2044 foreach ($result['status'] as $status) {
2045 $this->assertStatus($status);
2050 * Test the api_statuses_user_timeline() function with an RSS result.
2054 public function testApiStatusesUserTimelineWithRss()
2056 $result = api_statuses_user_timeline('rss');
2057 $this->assertXml($result, 'statuses');
2061 * Test the api_statuses_user_timeline() function with an unallowed user.
2064 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2066 public function testApiStatusesUserTimelineWithUnallowedUser()
2068 $_SESSION['allow_api'] = false;
2069 $_GET['screen_name'] = $this->selfUser['nick'];
2070 api_statuses_user_timeline('json');
2074 * Test the api_favorites_create_destroy() function.
2077 * @expectedException Friendica\Network\HTTPException\BadRequestException
2079 public function testApiFavoritesCreateDestroy()
2081 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2082 $this->app->argc = count($this->app->argv);
2083 api_favorites_create_destroy('json');
2087 * Test the api_favorites_create_destroy() function with an invalid ID.
2090 * @expectedException Friendica\Network\HTTPException\BadRequestException
2092 public function testApiFavoritesCreateDestroyWithInvalidId()
2094 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2095 $this->app->argc = count($this->app->argv);
2096 api_favorites_create_destroy('json');
2100 * Test the api_favorites_create_destroy() function with an invalid action.
2103 * @expectedException Friendica\Network\HTTPException\BadRequestException
2105 public function testApiFavoritesCreateDestroyWithInvalidAction()
2107 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2108 $this->app->argc = count($this->app->argv);
2109 $_REQUEST['id'] = 1;
2110 api_favorites_create_destroy('json');
2114 * Test the api_favorites_create_destroy() function with the create action.
2118 public function testApiFavoritesCreateDestroyWithCreateAction()
2120 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2121 $this->app->argc = count($this->app->argv);
2122 $_REQUEST['id'] = 3;
2123 $result = api_favorites_create_destroy('json');
2124 $this->assertStatus($result['status']);
2128 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2132 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2134 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2135 $this->app->argc = count($this->app->argv);
2136 $_REQUEST['id'] = 3;
2137 $result = api_favorites_create_destroy('rss');
2138 $this->assertXml($result, 'status');
2142 * Test the api_favorites_create_destroy() function with the destroy action.
2146 public function testApiFavoritesCreateDestroyWithDestroyAction()
2148 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2149 $this->app->argc = count($this->app->argv);
2150 $_REQUEST['id'] = 3;
2151 $result = api_favorites_create_destroy('json');
2152 $this->assertStatus($result['status']);
2156 * Test the api_favorites_create_destroy() function without an authenticated user.
2159 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2161 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2163 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2164 $this->app->argc = count($this->app->argv);
2165 $_SESSION['authenticated'] = false;
2166 api_favorites_create_destroy('json');
2170 * Test the api_favorites() function.
2174 public function testApiFavorites()
2176 $_REQUEST['page'] = -1;
2177 $_REQUEST['max_id'] = 10;
2178 $result = api_favorites('json');
2179 foreach ($result['status'] as $status) {
2180 $this->assertStatus($status);
2185 * Test the api_favorites() function with an RSS result.
2189 public function testApiFavoritesWithRss()
2191 $result = api_favorites('rss');
2192 $this->assertXml($result, 'statuses');
2196 * Test the api_favorites() function with an unallowed user.
2199 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2201 public function testApiFavoritesWithUnallowedUser()
2203 $_SESSION['allow_api'] = false;
2204 $_GET['screen_name'] = $this->selfUser['nick'];
2205 api_favorites('json');
2209 * Test the api_format_messages() function.
2213 public function testApiFormatMessages()
2215 $result = api_format_messages(
2216 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2217 ['id' => 2, 'screen_name' => 'recipient_name'],
2218 ['id' => 3, 'screen_name' => 'sender_name']
2220 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2221 $this->assertEquals(1, $result['id']);
2222 $this->assertEquals(2, $result['recipient_id']);
2223 $this->assertEquals(3, $result['sender_id']);
2224 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2225 $this->assertEquals('sender_name', $result['sender_screen_name']);
2229 * Test the api_format_messages() function with HTML.
2233 public function testApiFormatMessagesWithHtmlText()
2235 $_GET['getText'] = 'html';
2236 $result = api_format_messages(
2237 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2238 ['id' => 2, 'screen_name' => 'recipient_name'],
2239 ['id' => 3, 'screen_name' => 'sender_name']
2241 $this->assertEquals('item_title', $result['title']);
2242 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2246 * Test the api_format_messages() function with plain text.
2250 public function testApiFormatMessagesWithPlainText()
2252 $_GET['getText'] = 'plain';
2253 $result = api_format_messages(
2254 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2255 ['id' => 2, 'screen_name' => 'recipient_name'],
2256 ['id' => 3, 'screen_name' => 'sender_name']
2258 $this->assertEquals('item_title', $result['title']);
2259 $this->assertEquals('item_body', $result['text']);
2263 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2267 public function testApiFormatMessagesWithoutUserObjects()
2269 $_GET['getUserObjects'] = 'false';
2270 $result = api_format_messages(
2271 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2272 ['id' => 2, 'screen_name' => 'recipient_name'],
2273 ['id' => 3, 'screen_name' => 'sender_name']
2275 $this->assertTrue(!isset($result['sender']));
2276 $this->assertTrue(!isset($result['recipient']));
2280 * Test the api_convert_item() function.
2284 public function testApiConvertItem()
2286 $result = api_convert_item(
2288 'network' => 'feed',
2289 'title' => 'item_title',
2290 // We need a long string to test that it is correctly cut
2291 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2292 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2293 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2294 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2295 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2296 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2297 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2298 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2299 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2300 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2301 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2302 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2303 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2304 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2305 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2306 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2307 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2308 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2309 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2310 'repellat officia illum quos impedit quam iste esse unde qui ' .
2311 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2312 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2313 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2314 'plink' => 'item_plink'
2317 $this->assertStringStartsWith('item_title', $result['text']);
2318 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2322 * Test the api_convert_item() function with an empty item body.
2326 public function testApiConvertItemWithoutBody()
2328 $result = api_convert_item(
2330 'network' => 'feed',
2331 'title' => 'item_title',
2333 'plink' => 'item_plink'
2336 $this->assertEquals('item_title', $result['text']);
2337 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2341 * Test the api_convert_item() function with the title in the body.
2345 public function testApiConvertItemWithTitleInBody()
2347 $result = api_convert_item(
2349 'title' => 'item_title',
2350 'body' => 'item_title item_body'
2353 $this->assertEquals('item_title item_body', $result['text']);
2354 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2358 * Test the api_get_attachments() function.
2362 public function testApiGetAttachments()
2365 $this->assertEmpty(api_get_attachments($body));
2369 * Test the api_get_attachments() function with an img tag.
2373 public function testApiGetAttachmentsWithImage()
2375 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2376 $this->assertInternalType('array', api_get_attachments($body));
2380 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2384 public function testApiGetAttachmentsWithImageAndAndStatus()
2386 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2387 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2388 $this->assertInternalType('array', api_get_attachments($body));
2392 * Test the api_get_entitities() function.
2396 public function testApiGetEntitities()
2399 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2403 * Test the api_get_entitities() function with the include_entities parameter.
2407 public function testApiGetEntititiesWithIncludeEntities()
2409 $_REQUEST['include_entities'] = 'true';
2411 $result = api_get_entitities($text, 'bbcode');
2412 $this->assertInternalType('array', $result['hashtags']);
2413 $this->assertInternalType('array', $result['symbols']);
2414 $this->assertInternalType('array', $result['urls']);
2415 $this->assertInternalType('array', $result['user_mentions']);
2419 * Test the api_format_items_embeded_images() function.
2423 public function testApiFormatItemsEmbededImages()
2425 $this->assertEquals(
2426 'text ' . DI::baseUrl() . '/display/item_guid',
2427 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2432 * Test the api_contactlink_to_array() function.
2436 public function testApiContactlinkToArray()
2438 $this->assertEquals(
2443 api_contactlink_to_array('text')
2448 * Test the api_contactlink_to_array() function with an URL.
2452 public function testApiContactlinkToArrayWithUrl()
2454 $this->assertEquals(
2456 'name' => ['link_text'],
2459 api_contactlink_to_array('text <a href="url">link_text</a>')
2464 * Test the api_format_items_activities() function.
2468 public function testApiFormatItemsActivities()
2470 $item = ['uid' => 0, 'uri' => ''];
2471 $result = api_format_items_activities($item);
2472 $this->assertArrayHasKey('like', $result);
2473 $this->assertArrayHasKey('dislike', $result);
2474 $this->assertArrayHasKey('attendyes', $result);
2475 $this->assertArrayHasKey('attendno', $result);
2476 $this->assertArrayHasKey('attendmaybe', $result);
2480 * Test the api_format_items_activities() function with an XML result.
2484 public function testApiFormatItemsActivitiesWithXml()
2486 $item = ['uid' => 0, 'uri' => ''];
2487 $result = api_format_items_activities($item, 'xml');
2488 $this->assertArrayHasKey('friendica:like', $result);
2489 $this->assertArrayHasKey('friendica:dislike', $result);
2490 $this->assertArrayHasKey('friendica:attendyes', $result);
2491 $this->assertArrayHasKey('friendica:attendno', $result);
2492 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2496 * Test the api_format_items() function.
2500 public function testApiFormatItems()
2504 'item_network' => 'item_network',
2510 'author-network' => Protocol::DFRN,
2511 'author-link' => 'http://localhost/profile/othercontact',
2515 $result = api_format_items($items, ['id' => 0], true);
2516 foreach ($result as $status) {
2517 $this->assertStatus($status);
2522 * Test the api_format_items() function with an XML result.
2526 public function testApiFormatItemsWithXml()
2534 'author-network' => Protocol::DFRN,
2535 'author-link' => 'http://localhost/profile/othercontact',
2539 $result = api_format_items($items, ['id' => 0], true, 'xml');
2540 foreach ($result as $status) {
2541 $this->assertStatus($status);
2546 * Test the api_format_items() function.
2550 public function testApiAccountRateLimitStatus()
2552 $result = api_account_rate_limit_status('json');
2553 $this->assertEquals(150, $result['hash']['remaining_hits']);
2554 $this->assertEquals(150, $result['hash']['hourly_limit']);
2555 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2559 * Test the api_format_items() function with an XML result.
2563 public function testApiAccountRateLimitStatusWithXml()
2565 $result = api_account_rate_limit_status('xml');
2566 $this->assertXml($result, 'hash');
2570 * Test the api_help_test() function.
2574 public function testApiHelpTest()
2576 $result = api_help_test('json');
2577 $this->assertEquals(['ok' => 'ok'], $result);
2581 * Test the api_help_test() function with an XML result.
2585 public function testApiHelpTestWithXml()
2587 $result = api_help_test('xml');
2588 $this->assertXml($result, 'ok');
2592 * Test the api_lists_list() function.
2596 public function testApiListsList()
2598 $result = api_lists_list('json');
2599 $this->assertEquals(['lists_list' => []], $result);
2603 * Test the api_lists_ownerships() function.
2607 public function testApiListsOwnerships()
2609 $result = api_lists_ownerships('json');
2610 foreach ($result['lists']['lists'] as $list) {
2611 $this->assertList($list);
2616 * Test the api_lists_ownerships() function without an authenticated user.
2619 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2621 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2623 $_SESSION['authenticated'] = false;
2624 api_lists_ownerships('json');
2628 * Test the api_lists_statuses() function.
2630 * @expectedException Friendica\Network\HTTPException\BadRequestException
2633 public function testApiListsStatuses()
2635 api_lists_statuses('json');
2639 * Test the api_lists_statuses() function with a list ID.
2643 public function testApiListsStatusesWithListId()
2645 $_REQUEST['list_id'] = 1;
2646 $_REQUEST['page'] = -1;
2647 $_REQUEST['max_id'] = 10;
2648 $result = api_lists_statuses('json');
2649 foreach ($result['status'] as $status) {
2650 $this->assertStatus($status);
2655 * Test the api_lists_statuses() function with a list ID and a RSS result.
2659 public function testApiListsStatusesWithListIdAndRss()
2661 $_REQUEST['list_id'] = 1;
2662 $result = api_lists_statuses('rss');
2663 $this->assertXml($result, 'statuses');
2667 * Test the api_lists_statuses() function with an unallowed user.
2670 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2672 public function testApiListsStatusesWithUnallowedUser()
2674 $_SESSION['allow_api'] = false;
2675 $_GET['screen_name'] = $this->selfUser['nick'];
2676 api_lists_statuses('json');
2680 * Test the api_statuses_f() function.
2684 public function testApiStatusesFWithFriends()
2687 $result = api_statuses_f('friends');
2688 $this->assertArrayHasKey('user', $result);
2692 * Test the api_statuses_f() function.
2696 public function testApiStatusesFWithFollowers()
2698 $result = api_statuses_f('followers');
2699 $this->assertArrayHasKey('user', $result);
2703 * Test the api_statuses_f() function.
2707 public function testApiStatusesFWithBlocks()
2709 $result = api_statuses_f('blocks');
2710 $this->assertArrayHasKey('user', $result);
2714 * Test the api_statuses_f() function.
2718 public function testApiStatusesFWithIncoming()
2720 $result = api_statuses_f('incoming');
2721 $this->assertArrayHasKey('user', $result);
2725 * Test the api_statuses_f() function an undefined cursor GET variable.
2729 public function testApiStatusesFWithUndefinedCursor()
2731 $_GET['cursor'] = 'undefined';
2732 $this->assertFalse(api_statuses_f('friends'));
2736 * Test the api_statuses_friends() function.
2740 public function testApiStatusesFriends()
2742 $result = api_statuses_friends('json');
2743 $this->assertArrayHasKey('user', $result);
2747 * Test the api_statuses_friends() function an undefined cursor GET variable.
2751 public function testApiStatusesFriendsWithUndefinedCursor()
2753 $_GET['cursor'] = 'undefined';
2754 $this->assertFalse(api_statuses_friends('json'));
2758 * Test the api_statuses_followers() function.
2762 public function testApiStatusesFollowers()
2764 $result = api_statuses_followers('json');
2765 $this->assertArrayHasKey('user', $result);
2769 * Test the api_statuses_followers() function an undefined cursor GET variable.
2773 public function testApiStatusesFollowersWithUndefinedCursor()
2775 $_GET['cursor'] = 'undefined';
2776 $this->assertFalse(api_statuses_followers('json'));
2780 * Test the api_blocks_list() function.
2784 public function testApiBlocksList()
2786 $result = api_blocks_list('json');
2787 $this->assertArrayHasKey('user', $result);
2791 * Test the api_blocks_list() function an undefined cursor GET variable.
2795 public function testApiBlocksListWithUndefinedCursor()
2797 $_GET['cursor'] = 'undefined';
2798 $this->assertFalse(api_blocks_list('json'));
2802 * Test the api_friendships_incoming() function.
2806 public function testApiFriendshipsIncoming()
2808 $result = api_friendships_incoming('json');
2809 $this->assertArrayHasKey('id', $result);
2813 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2817 public function testApiFriendshipsIncomingWithUndefinedCursor()
2819 $_GET['cursor'] = 'undefined';
2820 $this->assertFalse(api_friendships_incoming('json'));
2824 * Test the api_statusnet_config() function.
2828 public function testApiStatusnetConfig()
2830 $result = api_statusnet_config('json');
2831 $this->assertEquals('localhost', $result['config']['site']['server']);
2832 $this->assertEquals('default', $result['config']['site']['theme']);
2833 $this->assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2834 $this->assertTrue($result['config']['site']['fancy']);
2835 $this->assertEquals('en', $result['config']['site']['language']);
2836 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2837 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2838 $this->assertEquals('false', $result['config']['site']['private']);
2839 $this->assertEquals('false', $result['config']['site']['ssl']);
2840 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2844 * Test the api_statusnet_version() function.
2848 public function testApiStatusnetVersion()
2850 $result = api_statusnet_version('json');
2851 $this->assertEquals('0.9.7', $result['version']);
2855 * Test the api_ff_ids() function.
2859 public function testApiFfIds()
2861 $result = api_ff_ids('json', Contact::FOLLOWER);
2862 $this->assertEquals(['id' => []], $result);
2866 * Test the api_ff_ids() function with a result.
2870 public function testApiFfIdsWithResult()
2872 $this->markTestIncomplete();
2876 * Test the api_ff_ids() function without an authenticated user.
2879 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2881 public function testApiFfIdsWithoutAuthenticatedUser()
2883 $_SESSION['authenticated'] = false;
2884 api_ff_ids('json', Contact::FOLLOWER);
2888 * Test the api_friends_ids() function.
2892 public function testApiFriendsIds()
2894 $result = api_friends_ids('json');
2895 $this->assertEquals(['id' => []], $result);
2899 * Test the api_followers_ids() function.
2903 public function testApiFollowersIds()
2905 $result = api_followers_ids('json');
2906 $this->assertEquals(['id' => []], $result);
2910 * Test the api_direct_messages_new() function.
2914 public function testApiDirectMessagesNew()
2916 $result = api_direct_messages_new('json');
2917 $this->assertNull($result);
2921 * Test the api_direct_messages_new() function without an authenticated user.
2924 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2926 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2928 $_SESSION['authenticated'] = false;
2929 api_direct_messages_new('json');
2933 * Test the api_direct_messages_new() function with an user ID.
2937 public function testApiDirectMessagesNewWithUserId()
2939 $_POST['text'] = 'message_text';
2940 $_POST['user_id'] = $this->otherUser['id'];
2941 $result = api_direct_messages_new('json');
2942 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2946 * Test the api_direct_messages_new() function with a screen name.
2950 public function testApiDirectMessagesNewWithScreenName()
2952 $_POST['text'] = 'message_text';
2953 $_POST['screen_name'] = $this->friendUser['nick'];
2954 $result = api_direct_messages_new('json');
2955 $this->assertContains('message_text', $result['direct_message']['text']);
2956 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2957 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2961 * Test the api_direct_messages_new() function with a title.
2965 public function testApiDirectMessagesNewWithTitle()
2967 $_POST['text'] = 'message_text';
2968 $_POST['screen_name'] = $this->friendUser['nick'];
2969 $_REQUEST['title'] = 'message_title';
2970 $result = api_direct_messages_new('json');
2971 $this->assertContains('message_text', $result['direct_message']['text']);
2972 $this->assertContains('message_title', $result['direct_message']['text']);
2973 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2974 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2978 * Test the api_direct_messages_new() function with an RSS result.
2982 public function testApiDirectMessagesNewWithRss()
2984 $_POST['text'] = 'message_text';
2985 $_POST['screen_name'] = $this->friendUser['nick'];
2986 $result = api_direct_messages_new('rss');
2987 $this->assertXml($result, 'direct-messages');
2991 * Test the api_direct_messages_destroy() function.
2994 * @expectedException Friendica\Network\HTTPException\BadRequestException
2996 public function testApiDirectMessagesDestroy()
2998 api_direct_messages_destroy('json');
3002 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3006 public function testApiDirectMessagesDestroyWithVerbose()
3008 $_GET['friendica_verbose'] = 'true';
3009 $result = api_direct_messages_destroy('json');
3010 $this->assertEquals(
3013 'result' => 'error',
3014 'message' => 'message id or parenturi not specified'
3022 * Test the api_direct_messages_destroy() function without an authenticated user.
3025 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3027 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3029 $_SESSION['authenticated'] = false;
3030 api_direct_messages_destroy('json');
3034 * Test the api_direct_messages_destroy() function with a non-zero ID.
3037 * @expectedException Friendica\Network\HTTPException\BadRequestException
3039 public function testApiDirectMessagesDestroyWithId()
3041 $_REQUEST['id'] = 1;
3042 api_direct_messages_destroy('json');
3046 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3050 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3052 $_REQUEST['id'] = 1;
3053 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3054 $_GET['friendica_verbose'] = 'true';
3055 $result = api_direct_messages_destroy('json');
3056 $this->assertEquals(
3059 'result' => 'error',
3060 'message' => 'message id not in database'
3068 * Test the api_direct_messages_destroy() function with a non-zero ID.
3072 public function testApiDirectMessagesDestroyWithCorrectId()
3074 $this->markTestIncomplete('We need to add a dataset for this.');
3078 * Test the api_direct_messages_box() function.
3082 public function testApiDirectMessagesBoxWithSentbox()
3084 $_REQUEST['page'] = -1;
3085 $_REQUEST['max_id'] = 10;
3086 $result = api_direct_messages_box('json', 'sentbox', 'false');
3087 $this->assertArrayHasKey('direct_message', $result);
3091 * Test the api_direct_messages_box() function.
3095 public function testApiDirectMessagesBoxWithConversation()
3097 $result = api_direct_messages_box('json', 'conversation', 'false');
3098 $this->assertArrayHasKey('direct_message', $result);
3102 * Test the api_direct_messages_box() function.
3106 public function testApiDirectMessagesBoxWithAll()
3108 $result = api_direct_messages_box('json', 'all', 'false');
3109 $this->assertArrayHasKey('direct_message', $result);
3113 * Test the api_direct_messages_box() function.
3117 public function testApiDirectMessagesBoxWithInbox()
3119 $result = api_direct_messages_box('json', 'inbox', 'false');
3120 $this->assertArrayHasKey('direct_message', $result);
3124 * Test the api_direct_messages_box() function.
3128 public function testApiDirectMessagesBoxWithVerbose()
3130 $result = api_direct_messages_box('json', 'sentbox', 'true');
3131 $this->assertEquals(
3134 'result' => 'error',
3135 'message' => 'no mails available'
3143 * Test the api_direct_messages_box() function with a RSS result.
3147 public function testApiDirectMessagesBoxWithRss()
3149 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3150 $this->assertXml($result, 'direct-messages');
3154 * Test the api_direct_messages_box() function without an authenticated user.
3157 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3159 public function testApiDirectMessagesBoxWithUnallowedUser()
3161 $_SESSION['allow_api'] = false;
3162 $_GET['screen_name'] = $this->selfUser['nick'];
3163 api_direct_messages_box('json', 'sentbox', 'false');
3167 * Test the api_direct_messages_sentbox() function.
3171 public function testApiDirectMessagesSentbox()
3173 $result = api_direct_messages_sentbox('json');
3174 $this->assertArrayHasKey('direct_message', $result);
3178 * Test the api_direct_messages_inbox() function.
3182 public function testApiDirectMessagesInbox()
3184 $result = api_direct_messages_inbox('json');
3185 $this->assertArrayHasKey('direct_message', $result);
3189 * Test the api_direct_messages_all() function.
3193 public function testApiDirectMessagesAll()
3195 $result = api_direct_messages_all('json');
3196 $this->assertArrayHasKey('direct_message', $result);
3200 * Test the api_direct_messages_conversation() function.
3204 public function testApiDirectMessagesConversation()
3206 $result = api_direct_messages_conversation('json');
3207 $this->assertArrayHasKey('direct_message', $result);
3211 * Test the api_oauth_request_token() function.
3215 public function testApiOauthRequestToken()
3217 $this->markTestIncomplete('exit() kills phpunit as well');
3221 * Test the api_oauth_access_token() function.
3225 public function testApiOauthAccessToken()
3227 $this->markTestIncomplete('exit() kills phpunit as well');
3231 * Test the api_fr_photoalbum_delete() function.
3234 * @expectedException Friendica\Network\HTTPException\BadRequestException
3236 public function testApiFrPhotoalbumDelete()
3238 api_fr_photoalbum_delete('json');
3242 * Test the api_fr_photoalbum_delete() function with an album name.
3245 * @expectedException Friendica\Network\HTTPException\BadRequestException
3247 public function testApiFrPhotoalbumDeleteWithAlbum()
3249 $_REQUEST['album'] = 'album_name';
3250 api_fr_photoalbum_delete('json');
3254 * Test the api_fr_photoalbum_delete() function with an album name.
3258 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3260 $this->markTestIncomplete('We need to add a dataset for this.');
3264 * Test the api_fr_photoalbum_delete() function.
3267 * @expectedException Friendica\Network\HTTPException\BadRequestException
3269 public function testApiFrPhotoalbumUpdate()
3271 api_fr_photoalbum_update('json');
3275 * Test the api_fr_photoalbum_delete() function with an album name.
3278 * @expectedException Friendica\Network\HTTPException\BadRequestException
3280 public function testApiFrPhotoalbumUpdateWithAlbum()
3282 $_REQUEST['album'] = 'album_name';
3283 api_fr_photoalbum_update('json');
3287 * Test the api_fr_photoalbum_delete() function with an album name.
3290 * @expectedException Friendica\Network\HTTPException\BadRequestException
3292 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3294 $_REQUEST['album'] = 'album_name';
3295 $_REQUEST['album_new'] = 'album_name';
3296 api_fr_photoalbum_update('json');
3300 * Test the api_fr_photoalbum_update() function without an authenticated user.
3303 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3305 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3307 $_SESSION['authenticated'] = false;
3308 api_fr_photoalbum_update('json');
3312 * Test the api_fr_photoalbum_delete() function with an album name.
3316 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3318 $this->markTestIncomplete('We need to add a dataset for this.');
3322 * Test the api_fr_photos_list() function.
3326 public function testApiFrPhotosList()
3328 $result = api_fr_photos_list('json');
3329 $this->assertArrayHasKey('photo', $result);
3333 * Test the api_fr_photos_list() function without an authenticated user.
3336 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3338 public function testApiFrPhotosListWithoutAuthenticatedUser()
3340 $_SESSION['authenticated'] = false;
3341 api_fr_photos_list('json');
3345 * Test the api_fr_photo_create_update() function.
3348 * @expectedException Friendica\Network\HTTPException\BadRequestException
3350 public function testApiFrPhotoCreateUpdate()
3352 api_fr_photo_create_update('json');
3356 * Test the api_fr_photo_create_update() function without an authenticated user.
3359 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3361 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3363 $_SESSION['authenticated'] = false;
3364 api_fr_photo_create_update('json');
3368 * Test the api_fr_photo_create_update() function with an album name.
3371 * @expectedException Friendica\Network\HTTPException\BadRequestException
3373 public function testApiFrPhotoCreateUpdateWithAlbum()
3375 $_REQUEST['album'] = 'album_name';
3376 api_fr_photo_create_update('json');
3380 * Test the api_fr_photo_create_update() function with the update mode.
3384 public function testApiFrPhotoCreateUpdateWithUpdate()
3386 $this->markTestIncomplete('We need to create a dataset for this');
3390 * Test the api_fr_photo_create_update() function with an uploaded file.
3394 public function testApiFrPhotoCreateUpdateWithFile()
3396 $this->markTestIncomplete();
3400 * Test the api_fr_photo_delete() function.
3403 * @expectedException Friendica\Network\HTTPException\BadRequestException
3405 public function testApiFrPhotoDelete()
3407 api_fr_photo_delete('json');
3411 * Test the api_fr_photo_delete() function without an authenticated user.
3414 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3416 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3418 $_SESSION['authenticated'] = false;
3419 api_fr_photo_delete('json');
3423 * Test the api_fr_photo_delete() function with a photo ID.
3426 * @expectedException Friendica\Network\HTTPException\BadRequestException
3428 public function testApiFrPhotoDeleteWithPhotoId()
3430 $_REQUEST['photo_id'] = 1;
3431 api_fr_photo_delete('json');
3435 * Test the api_fr_photo_delete() function with a correct photo ID.
3439 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3441 $this->markTestIncomplete('We need to create a dataset for this.');
3445 * Test the api_fr_photo_detail() function.
3448 * @expectedException Friendica\Network\HTTPException\BadRequestException
3450 public function testApiFrPhotoDetail()
3452 api_fr_photo_detail('json');
3456 * Test the api_fr_photo_detail() function without an authenticated user.
3459 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3461 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3463 $_SESSION['authenticated'] = false;
3464 api_fr_photo_detail('json');
3468 * Test the api_fr_photo_detail() function with a photo ID.
3471 * @expectedException Friendica\Network\HTTPException\NotFoundException
3473 public function testApiFrPhotoDetailWithPhotoId()
3475 $_REQUEST['photo_id'] = 1;
3476 api_fr_photo_detail('json');
3480 * Test the api_fr_photo_detail() function with a correct photo ID.
3484 public function testApiFrPhotoDetailCorrectPhotoId()
3486 $this->markTestIncomplete('We need to create a dataset for this.');
3490 * Test the api_account_update_profile_image() function.
3493 * @expectedException Friendica\Network\HTTPException\BadRequestException
3495 public function testApiAccountUpdateProfileImage()
3497 api_account_update_profile_image('json');
3501 * Test the api_account_update_profile_image() function without an authenticated user.
3504 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3506 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3508 $_SESSION['authenticated'] = false;
3509 api_account_update_profile_image('json');
3513 * Test the api_account_update_profile_image() function with an uploaded file.
3516 * @expectedException Friendica\Network\HTTPException\BadRequestException
3518 public function testApiAccountUpdateProfileImageWithUpload()
3520 $this->markTestIncomplete();
3525 * Test the api_account_update_profile() function.
3529 public function testApiAccountUpdateProfile()
3531 $_POST['name'] = 'new_name';
3532 $_POST['description'] = 'new_description';
3533 $result = api_account_update_profile('json');
3534 // We can't use assertSelfUser() here because the user object is missing some properties.
3535 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3536 $this->assertEquals('DFRN', $result['user']['location']);
3537 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3538 $this->assertEquals('dfrn', $result['user']['network']);
3539 $this->assertEquals('new_name', $result['user']['name']);
3540 $this->assertEquals('new_description', $result['user']['description']);
3544 * Test the check_acl_input() function.
3548 public function testCheckAclInput()
3550 $result = check_acl_input('<aclstring>');
3551 // Where does this result come from?
3552 $this->assertEquals(1, $result);
3556 * Test the check_acl_input() function with an empty ACL string.
3560 public function testCheckAclInputWithEmptyAclString()
3562 $result = check_acl_input(' ');
3563 $this->assertFalse($result);
3567 * Test the save_media_to_database() function.
3571 public function testSaveMediaToDatabase()
3573 $this->markTestIncomplete();
3577 * Test the post_photo_item() function.
3581 public function testPostPhotoItem()
3583 $this->markTestIncomplete();
3587 * Test the prepare_photo_data() function.
3591 public function testPreparePhotoData()
3593 $this->markTestIncomplete();
3597 * Test the api_friendica_remoteauth() function.
3600 * @expectedException Friendica\Network\HTTPException\BadRequestException
3602 public function testApiFriendicaRemoteauth()
3604 api_friendica_remoteauth();
3608 * Test the api_friendica_remoteauth() function with an URL.
3611 * @expectedException Friendica\Network\HTTPException\BadRequestException
3613 public function testApiFriendicaRemoteauthWithUrl()
3615 $_GET['url'] = 'url';
3616 $_GET['c_url'] = 'url';
3617 api_friendica_remoteauth();
3621 * Test the api_friendica_remoteauth() function with a correct URL.
3625 public function testApiFriendicaRemoteauthWithCorrectUrl()
3627 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3628 $_GET['url'] = 'url';
3629 $_GET['c_url'] = $this->selfUser['nurl'];
3630 api_friendica_remoteauth();
3634 * Test the api_share_as_retweet() function.
3638 public function testApiShareAsRetweet()
3640 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3641 $result = api_share_as_retweet($item);
3642 $this->assertFalse($result);
3646 * Test the api_share_as_retweet() function with a valid item.
3650 public function testApiShareAsRetweetWithValidItem()
3652 $this->markTestIncomplete();
3656 * Test the api_in_reply_to() function.
3660 public function testApiInReplyTo()
3662 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3663 $this->assertArrayHasKey('status_id', $result);
3664 $this->assertArrayHasKey('user_id', $result);
3665 $this->assertArrayHasKey('status_id_str', $result);
3666 $this->assertArrayHasKey('user_id_str', $result);
3667 $this->assertArrayHasKey('screen_name', $result);
3671 * Test the api_in_reply_to() function with a valid item.
3675 public function testApiInReplyToWithValidItem()
3677 $this->markTestIncomplete();
3681 * Test the api_clean_plain_items() function.
3685 public function testApiCleanPlainItems()
3687 $_REQUEST['include_entities'] = 'true';
3688 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3689 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3693 * Test the api_best_nickname() function.
3697 public function testApiBestNickname()
3700 $result = api_best_nickname($contacts);
3701 $this->assertNull($result);
3705 * Test the api_best_nickname() function with contacts.
3709 public function testApiBestNicknameWithContacts()
3711 $this->markTestIncomplete();
3715 * Test the api_friendica_group_show() function.
3719 public function testApiFriendicaGroupShow()
3721 $this->markTestIncomplete();
3725 * Test the api_friendica_group_delete() function.
3729 public function testApiFriendicaGroupDelete()
3731 $this->markTestIncomplete();
3735 * Test the api_lists_destroy() function.
3739 public function testApiListsDestroy()
3741 $this->markTestIncomplete();
3745 * Test the group_create() function.
3749 public function testGroupCreate()
3751 $this->markTestIncomplete();
3755 * Test the api_friendica_group_create() function.
3759 public function testApiFriendicaGroupCreate()
3761 $this->markTestIncomplete();
3765 * Test the api_lists_create() function.
3769 public function testApiListsCreate()
3771 $this->markTestIncomplete();
3775 * Test the api_friendica_group_update() function.
3779 public function testApiFriendicaGroupUpdate()
3781 $this->markTestIncomplete();
3785 * Test the api_lists_update() function.
3789 public function testApiListsUpdate()
3791 $this->markTestIncomplete();
3795 * Test the api_friendica_activity() function.
3799 public function testApiFriendicaActivity()
3801 $this->markTestIncomplete();
3805 * Test the api_friendica_notification() function.
3808 * @expectedException Friendica\Network\HTTPException\BadRequestException
3810 public function testApiFriendicaNotification()
3812 api_friendica_notification('json');
3816 * Test the api_friendica_notification() function without an authenticated user.
3819 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3821 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3823 $_SESSION['authenticated'] = false;
3824 api_friendica_notification('json');
3828 * Test the api_friendica_notification() function with empty result
3832 public function testApiFriendicaNotificationWithEmptyResult()
3834 $this->app->argv = ['api', 'friendica', 'notification'];
3835 $this->app->argc = count($this->app->argv);
3836 $_SESSION['uid'] = 41;
3837 $result = api_friendica_notification('json');
3838 $this->assertEquals(['note' => false], $result);
3842 * Test the api_friendica_notification() function with an XML result.
3846 public function testApiFriendicaNotificationWithXmlResult()
3848 $this->app->argv = ['api', 'friendica', 'notification'];
3849 $this->app->argc = count($this->app->argv);
3850 $result = api_friendica_notification('xml');
3851 $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
3853 <?xml version="1.0"?>
3855 <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="Reply to" 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"/>
3858 $this->assertXmlStringEqualsXmlString($assertXml, $result);
3862 * Test the api_friendica_notification() function with an JSON result.
3866 public function testApiFriendicaNotificationWithJsonResult()
3868 $this->app->argv = ['api', 'friendica', 'notification'];
3869 $this->app->argc = count($this->app->argv);
3870 $result = json_encode(api_friendica_notification('json'));
3871 $this->assertJson($result);
3875 * Test the api_friendica_notification_seen() function.
3879 public function testApiFriendicaNotificationSeen()
3881 $this->markTestIncomplete();
3885 * Test the api_friendica_direct_messages_setseen() function.
3889 public function testApiFriendicaDirectMessagesSetseen()
3891 $this->markTestIncomplete();
3895 * Test the api_friendica_direct_messages_search() function.
3899 public function testApiFriendicaDirectMessagesSearch()
3901 $this->markTestIncomplete();
3905 * Test the api_saved_searches_list() function.
3909 public function testApiSavedSearchesList()
3911 $result = api_saved_searches_list('json');
3912 $this->assertEquals(1, $result['terms'][0]['id']);
3913 $this->assertEquals(1, $result['terms'][0]['id_str']);
3914 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3915 $this->assertEquals('Saved search', $result['terms'][0]['query']);