6 namespace Friendica\Test;
10 use Friendica\BaseObject;
11 use Friendica\Core\Config\Configuration;
12 use Friendica\Core\Config\PConfiguration;
13 use Friendica\Core\Protocol;
14 use Friendica\Core\System;
15 use Friendica\Database\Database;
16 use Friendica\Network\HTTPException;
17 use Friendica\Test\Util\Database\StaticDatabase;
18 use Monolog\Handler\TestHandler;
20 require_once __DIR__ . '/../../include/api.php';
23 * Tests for the API functions.
25 * Functions that use header() need to be tested in a separate process.
26 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
28 class ApiTest extends DatabaseTest
31 * @var TestHandler Can handle log-outputs
38 protected $friendUser;
42 protected $wrongUserId;
47 /** @var Configuration */
54 * Create variables used by tests.
56 protected function setUp()
60 $this->dice = (new Dice())
61 ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
62 ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
63 BaseObject::setDependencyInjection($this->dice);
65 /** @var Database $dba */
66 $dba = $this->dice->create(Database::class);
68 /** @var Configuration $config */
69 $this->config = $this->dice->create(Configuration::class);
71 $this->config->set('system', 'url', 'http://localhost');
72 $this->config->set('system', 'hostname', 'localhost');
73 $this->config->set('system', 'worker_dont_fork', true);
76 $this->config->set('config', 'hostname', 'localhost');
77 $this->config->set('system', 'throttle_limit_day', 100);
78 $this->config->set('system', 'throttle_limit_week', 100);
79 $this->config->set('system', 'throttle_limit_month', 100);
80 $this->config->set('system', 'theme', 'system_theme');
82 // Load the API dataset for the whole API
83 $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
86 $this->app = BaseObject::getApp();
89 $this->app->argv = ['home'];
91 // User data that the test database is populated with
94 'name' => 'Self contact',
95 'nick' => 'selfcontact',
96 'nurl' => 'http://localhost/profile/selfcontact'
100 'name' => 'Friend contact',
101 'nick' => 'friendcontact',
102 'nurl' => 'http://localhost/profile/friendcontact'
106 'name' => 'othercontact',
107 'nick' => 'othercontact',
108 'nurl' => 'http://localhost/profile/othercontact'
111 // User ID that we know is not in the database
112 $this->wrongUserId = 666;
114 // Most API require login so we force the session
117 'authenticated' => true,
118 'uid' => $this->selfUser['id']
127 * Assert that an user array contains expected keys.
129 * @param array $user User array
133 private function assertSelfUser(array $user)
135 $this->assertEquals($this->selfUser['id'], $user['uid']);
136 $this->assertEquals($this->selfUser['id'], $user['cid']);
137 $this->assertEquals(1, $user['self']);
138 $this->assertEquals('DFRN', $user['location']);
139 $this->assertEquals($this->selfUser['name'], $user['name']);
140 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
141 $this->assertEquals('dfrn', $user['network']);
142 $this->assertTrue($user['verified']);
146 * Assert that an user array contains expected keys.
148 * @param array $user User array
152 private function assertOtherUser(array $user)
154 $this->assertEquals($this->otherUser['id'], $user['id']);
155 $this->assertEquals($this->otherUser['id'], $user['id_str']);
156 $this->assertEquals(0, $user['self']);
157 $this->assertEquals($this->otherUser['name'], $user['name']);
158 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
159 $this->assertFalse($user['verified']);
163 * Assert that a status array contains expected keys.
165 * @param array $status Status array
169 private function assertStatus(array $status)
171 $this->assertInternalType('string', $status['text']);
172 $this->assertInternalType('int', $status['id']);
173 // We could probably do more checks here.
177 * Assert that a list array contains expected keys.
179 * @param array $list List array
183 private function assertList(array $list)
185 $this->assertInternalType('string', $list['name']);
186 $this->assertInternalType('int', $list['id']);
187 $this->assertInternalType('string', $list['id_str']);
188 $this->assertContains($list['mode'], ['public', 'private']);
189 // We could probably do more checks here.
193 * Assert that the string is XML and contain the root element.
195 * @param string $result XML string
196 * @param string $root_element Root element name
200 private function assertXml($result, $root_element)
202 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
203 $this->assertContains('<' . $root_element, $result);
204 // We could probably do more checks here.
208 * Get the path to a temporary empty PNG image.
210 * @return string Path
212 private function getTempImage()
214 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
218 // Empty 1x1 px PNG image
219 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
227 * Test the api_user() function.
231 public function testApiUser()
233 $this->assertEquals($this->selfUser['id'], api_user());
237 * Test the api_user() function with an unallowed user.
241 public function testApiUserWithUnallowedUser()
243 $_SESSION = ['allow_api' => false];
244 $this->assertEquals(false, api_user());
248 * Test the api_source() function.
252 public function testApiSource()
254 $this->assertEquals('api', api_source());
258 * Test the api_source() function with a Twidere user agent.
262 public function testApiSourceWithTwidere()
264 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
265 $this->assertEquals('Twidere', api_source());
269 * Test the api_source() function with a GET parameter.
273 public function testApiSourceWithGet()
275 $_GET['source'] = 'source_name';
276 $this->assertEquals('source_name', api_source());
280 * Test the api_date() function.
284 public function testApiDate()
286 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
290 * Test the api_register_func() function.
294 public function testApiRegisterFunc()
306 $this->assertTrue($API['api_path']['auth']);
307 $this->assertEquals('method', $API['api_path']['method']);
308 $this->assertTrue(is_callable($API['api_path']['func']));
312 * Test the api_login() function without any login.
315 * @runInSeparateProcess
316 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
318 public function testApiLoginWithoutLogin()
320 api_login($this->app);
324 * Test the api_login() function with a bad login.
327 * @runInSeparateProcess
328 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
330 public function testApiLoginWithBadLogin()
332 $_SERVER['PHP_AUTH_USER'] = 'user@server';
333 api_login($this->app);
337 * Test the api_login() function with oAuth.
341 public function testApiLoginWithOauth()
343 $this->markTestIncomplete('Can we test this easily?');
347 * Test the api_login() function with authentication provided by an addon.
351 public function testApiLoginWithAddonAuth()
353 $this->markTestIncomplete('Can we test this easily?');
357 * Test the api_login() function with a correct login.
360 * @runInSeparateProcess
362 public function testApiLoginWithCorrectLogin()
364 $_SERVER['PHP_AUTH_USER'] = 'Test user';
365 $_SERVER['PHP_AUTH_PW'] = 'password';
366 api_login($this->app);
370 * Test the api_login() function with a remote user.
373 * @runInSeparateProcess
374 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
376 public function testApiLoginWithRemoteUser()
378 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
379 api_login($this->app);
383 * Test the api_check_method() function.
387 public function testApiCheckMethod()
389 $this->assertFalse(api_check_method('method'));
393 * Test the api_check_method() function with a correct method.
397 public function testApiCheckMethodWithCorrectMethod()
399 $_SERVER['REQUEST_METHOD'] = 'method';
400 $this->assertTrue(api_check_method('method'));
404 * Test the api_check_method() function with a wildcard.
408 public function testApiCheckMethodWithWildcard()
410 $this->assertTrue(api_check_method('*'));
414 * Test the api_call() function.
417 * @runInSeparateProcess
419 public function testApiCall()
423 'method' => 'method',
424 'func' => function () {
425 return ['data' => ['some_data']];
428 $_SERVER['REQUEST_METHOD'] = 'method';
429 $_GET['callback'] = 'callback_name';
431 $this->app->query_string = 'api_path';
433 'callback_name(["some_data"])',
439 * Test the api_call() function with the profiled enabled.
442 * @runInSeparateProcess
444 public function testApiCallWithProfiler()
448 'method' => 'method',
449 'func' => function () {
450 return ['data' => ['some_data']];
453 $_SERVER['REQUEST_METHOD'] = 'method';
454 $this->config->set('system', 'profiler', true);
455 $this->config->set('rendertime', 'callstack', true);
456 $this->app->callstack = [
457 'database' => ['some_function' => 200],
458 'database_write' => ['some_function' => 200],
459 'cache' => ['some_function' => 200],
460 'cache_write' => ['some_function' => 200],
461 'network' => ['some_function' => 200]
464 $this->app->query_string = 'api_path';
472 * Test the api_call() function without any result.
475 * @runInSeparateProcess
477 public function testApiCallWithNoResult()
481 'method' => 'method',
482 'func' => function () {
486 $_SERVER['REQUEST_METHOD'] = 'method';
488 $this->app->query_string = 'api_path';
490 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
496 * Test the api_call() function with an unimplemented API.
499 * @runInSeparateProcess
501 public function testApiCallWithUninplementedApi()
504 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
510 * Test the api_call() function with a JSON result.
513 * @runInSeparateProcess
515 public function testApiCallWithJson()
519 'method' => 'method',
520 'func' => function () {
521 return ['data' => ['some_data']];
524 $_SERVER['REQUEST_METHOD'] = 'method';
526 $this->app->query_string = 'api_path.json';
534 * Test the api_call() function with an XML result.
537 * @runInSeparateProcess
539 public function testApiCallWithXml()
543 'method' => 'method',
544 'func' => function () {
548 $_SERVER['REQUEST_METHOD'] = 'method';
550 $this->app->query_string = 'api_path.xml';
558 * Test the api_call() function with an RSS result.
561 * @runInSeparateProcess
563 public function testApiCallWithRss()
567 'method' => 'method',
568 'func' => function () {
572 $_SERVER['REQUEST_METHOD'] = 'method';
574 $this->app->query_string = 'api_path.rss';
576 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
583 * Test the api_call() function with an Atom result.
586 * @runInSeparateProcess
588 public function testApiCallWithAtom()
592 'method' => 'method',
593 'func' => function () {
597 $_SERVER['REQUEST_METHOD'] = 'method';
599 $this->app->query_string = 'api_path.atom';
601 '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
608 * Test the api_call() function with an unallowed method.
611 * @runInSeparateProcess
613 public function testApiCallWithWrongMethod()
616 $API['api_path'] = ['method' => 'method'];
618 $this->app->query_string = 'api_path';
620 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
626 * Test the api_call() function with an unauthorized user.
629 * @runInSeparateProcess
631 public function testApiCallWithWrongAuth()
635 'method' => 'method',
638 $_SERVER['REQUEST_METHOD'] = 'method';
639 $_SESSION['authenticated'] = false;
641 $this->app->query_string = 'api_path';
643 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
649 * Test the api_error() function with a JSON result.
652 * @runInSeparateProcess
654 public function testApiErrorWithJson()
657 '{"status":{"error":"error_message","code":"200 OK","request":""}}',
658 api_error('json', new HTTPException\OKException('error_message'))
663 * Test the api_error() function with an XML result.
666 * @runInSeparateProcess
668 public function testApiErrorWithXml()
671 '<?xml version="1.0"?>' . "\n" .
672 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
673 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
674 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
675 ' <error>error_message</error>' . "\n" .
676 ' <code>200 OK</code>' . "\n" .
677 ' <request/>' . "\n" .
679 api_error('xml', new HTTPException\OKException('error_message'))
684 * Test the api_error() function with an RSS result.
687 * @runInSeparateProcess
689 public function testApiErrorWithRss()
692 '<?xml version="1.0"?>' . "\n" .
693 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
694 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
695 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
696 ' <error>error_message</error>' . "\n" .
697 ' <code>200 OK</code>' . "\n" .
698 ' <request/>' . "\n" .
700 api_error('rss', new HTTPException\OKException('error_message'))
705 * Test the api_error() function with an Atom result.
708 * @runInSeparateProcess
710 public function testApiErrorWithAtom()
713 '<?xml version="1.0"?>' . "\n" .
714 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
715 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
716 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
717 ' <error>error_message</error>' . "\n" .
718 ' <code>200 OK</code>' . "\n" .
719 ' <request/>' . "\n" .
721 api_error('atom', new HTTPException\OKException('error_message'))
726 * Test the api_rss_extra() function.
730 public function testApiRssExtra()
732 $user_info = ['url' => 'user_url', 'lang' => 'en'];
733 $result = api_rss_extra($this->app, [], $user_info);
734 $this->assertEquals($user_info, $result['$user']);
735 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
736 $this->assertArrayHasKey('self', $result['$rss']);
737 $this->assertArrayHasKey('base', $result['$rss']);
738 $this->assertArrayHasKey('updated', $result['$rss']);
739 $this->assertArrayHasKey('atom_updated', $result['$rss']);
740 $this->assertArrayHasKey('language', $result['$rss']);
741 $this->assertArrayHasKey('logo', $result['$rss']);
745 * Test the api_rss_extra() function without any user info.
749 public function testApiRssExtraWithoutUserInfo()
751 $result = api_rss_extra($this->app, [], null);
752 $this->assertInternalType('array', $result['$user']);
753 $this->assertArrayHasKey('alternate', $result['$rss']);
754 $this->assertArrayHasKey('self', $result['$rss']);
755 $this->assertArrayHasKey('base', $result['$rss']);
756 $this->assertArrayHasKey('updated', $result['$rss']);
757 $this->assertArrayHasKey('atom_updated', $result['$rss']);
758 $this->assertArrayHasKey('language', $result['$rss']);
759 $this->assertArrayHasKey('logo', $result['$rss']);
763 * Test the api_unique_id_to_nurl() function.
767 public function testApiUniqueIdToNurl()
769 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
773 * Test the api_unique_id_to_nurl() function with a correct ID.
777 public function testApiUniqueIdToNurlWithCorrectId()
779 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
783 * Test the api_get_user() function.
787 public function testApiGetUser()
789 $user = api_get_user($this->app);
790 $this->assertSelfUser($user);
791 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
792 $this->assertEquals('6fdbe8', $user['profile_link_color']);
793 $this->assertEquals('ededed', $user['profile_background_color']);
797 * Test the api_get_user() function with a Frio schema.
801 public function testApiGetUserWithFrioSchema()
803 $pConfig = $this->dice->create(PConfiguration::class);
804 $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
805 $user = api_get_user($this->app);
806 $this->assertSelfUser($user);
807 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
808 $this->assertEquals('6fdbe8', $user['profile_link_color']);
809 $this->assertEquals('ededed', $user['profile_background_color']);
813 * Test the api_get_user() function with a custom Frio schema.
817 public function testApiGetUserWithCustomFrioSchema()
819 $pConfig = $this->dice->create(PConfiguration::class);
820 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
821 $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
822 $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
823 $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
824 $user = api_get_user($this->app);
825 $this->assertSelfUser($user);
826 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
827 $this->assertEquals('123456', $user['profile_link_color']);
828 $this->assertEquals('123456', $user['profile_background_color']);
832 * Test the api_get_user() function with an empty Frio schema.
836 public function testApiGetUserWithEmptyFrioSchema()
838 $pConfig = $this->dice->create(PConfiguration::class);
839 $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
840 $user = api_get_user($this->app);
841 $this->assertSelfUser($user);
842 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
843 $this->assertEquals('6fdbe8', $user['profile_link_color']);
844 $this->assertEquals('ededed', $user['profile_background_color']);
848 * Test the api_get_user() function with an user that is not allowed to use the API.
851 * @runInSeparateProcess
853 public function testApiGetUserWithoutApiUser()
855 $_SERVER['PHP_AUTH_USER'] = 'Test user';
856 $_SERVER['PHP_AUTH_PW'] = 'password';
857 $_SESSION['allow_api'] = false;
858 $this->assertFalse(api_get_user($this->app));
862 * Test the api_get_user() function with an user ID in a GET parameter.
866 public function testApiGetUserWithGetId()
868 $_GET['user_id'] = $this->otherUser['id'];
869 $this->assertOtherUser(api_get_user($this->app));
873 * Test the api_get_user() function with a wrong user ID in a GET parameter.
876 * @expectedException Friendica\Network\HTTPException\BadRequestException
878 public function testApiGetUserWithWrongGetId()
880 $_GET['user_id'] = $this->wrongUserId;
881 $this->assertOtherUser(api_get_user($this->app));
885 * Test the api_get_user() function with an user name in a GET parameter.
889 public function testApiGetUserWithGetName()
891 $_GET['screen_name'] = $this->selfUser['nick'];
892 $this->assertSelfUser(api_get_user($this->app));
896 * Test the api_get_user() function with a profile URL in a GET parameter.
900 public function testApiGetUserWithGetUrl()
902 $_GET['profileurl'] = $this->selfUser['nurl'];
903 $this->assertSelfUser(api_get_user($this->app));
907 * Test the api_get_user() function with an user ID in the API path.
911 public function testApiGetUserWithNumericCalledApi()
914 $called_api = ['api_path'];
915 $this->app->argv[1] = $this->otherUser['id'] . '.json';
916 $this->assertOtherUser(api_get_user($this->app));
920 * Test the api_get_user() function with the $called_api global variable.
924 public function testApiGetUserWithCalledApi()
927 $called_api = ['api', 'api_path'];
928 $this->assertSelfUser(api_get_user($this->app));
932 * Test the api_get_user() function with a valid user.
936 public function testApiGetUserWithCorrectUser()
938 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
942 * Test the api_get_user() function with a wrong user ID.
945 * @expectedException Friendica\Network\HTTPException\BadRequestException
947 public function testApiGetUserWithWrongUser()
949 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
953 * Test the api_get_user() function with a 0 user ID.
957 public function testApiGetUserWithZeroUser()
959 $this->assertSelfUser(api_get_user($this->app, 0));
963 * Test the api_item_get_user() function.
967 public function testApiItemGetUser()
969 $users = api_item_get_user($this->app, []);
970 $this->assertSelfUser($users[0]);
974 * Test the api_item_get_user() function with a different item parent.
978 public function testApiItemGetUserWithDifferentParent()
980 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
981 $this->assertSelfUser($users[0]);
982 $this->assertEquals($users[0], $users[1]);
986 * Test the api_walk_recursive() function.
990 public function testApiWalkRecursive()
998 // Should we test this with a callback that actually does something?
1006 * Test the api_walk_recursive() function with an array.
1010 public function testApiWalkRecursiveWithArray()
1012 $array = [['item1'], ['item2']];
1013 $this->assertEquals(
1018 // Should we test this with a callback that actually does something?
1026 * Test the api_reformat_xml() function.
1030 public function testApiReformatXml()
1034 $this->assertTrue(api_reformat_xml($item, $key));
1035 $this->assertEquals('true', $item);
1039 * Test the api_reformat_xml() function with a statusnet_api key.
1043 public function testApiReformatXmlWithStatusnetKey()
1046 $key = 'statusnet_api';
1047 $this->assertTrue(api_reformat_xml($item, $key));
1048 $this->assertEquals('statusnet:api', $key);
1052 * Test the api_reformat_xml() function with a friendica_api key.
1056 public function testApiReformatXmlWithFriendicaKey()
1059 $key = 'friendica_api';
1060 $this->assertTrue(api_reformat_xml($item, $key));
1061 $this->assertEquals('friendica:api', $key);
1065 * Test the api_create_xml() function.
1069 public function testApiCreateXml()
1071 $this->assertEquals(
1072 '<?xml version="1.0"?>' . "\n" .
1073 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1074 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1075 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1076 ' <data>some_data</data>' . "\n" .
1077 '</root_element>' . "\n",
1078 api_create_xml(['data' => ['some_data']], 'root_element')
1083 * Test the api_create_xml() function without any XML namespace.
1087 public function testApiCreateXmlWithoutNamespaces()
1089 $this->assertEquals(
1090 '<?xml version="1.0"?>' . "\n" .
1092 ' <data>some_data</data>' . "\n" .
1094 api_create_xml(['data' => ['some_data']], 'ok')
1099 * Test the api_format_data() function.
1103 public function testApiFormatData()
1105 $data = ['some_data'];
1106 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
1110 * Test the api_format_data() function with an XML result.
1114 public function testApiFormatDataWithXml()
1116 $this->assertEquals(
1117 '<?xml version="1.0"?>' . "\n" .
1118 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
1119 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
1120 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
1121 ' <data>some_data</data>' . "\n" .
1122 '</root_element>' . "\n",
1123 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1128 * Test the api_account_verify_credentials() function.
1132 public function testApiAccountVerifyCredentials()
1134 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1138 * Test the api_account_verify_credentials() function without an authenticated user.
1141 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1143 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1145 $_SESSION['authenticated'] = false;
1146 api_account_verify_credentials('json');
1150 * Test the requestdata() function.
1154 public function testRequestdata()
1156 $this->assertNull(requestdata('variable_name'));
1160 * Test the requestdata() function with a POST parameter.
1164 public function testRequestdataWithPost()
1166 $_POST['variable_name'] = 'variable_value';
1167 $this->assertEquals('variable_value', requestdata('variable_name'));
1171 * Test the requestdata() function with a GET parameter.
1175 public function testRequestdataWithGet()
1177 $_GET['variable_name'] = 'variable_value';
1178 $this->assertEquals('variable_value', requestdata('variable_name'));
1182 * Test the api_statuses_mediap() function.
1186 public function testApiStatusesMediap()
1188 $this->app->argc = 2;
1196 'tmp_name' => $this->getTempImage(),
1197 'name' => 'spacer.png',
1198 'type' => 'image/png'
1201 $_GET['status'] = '<b>Status content</b>';
1203 $result = api_statuses_mediap('json');
1204 $this->assertStatus($result['status']);
1208 * Test the api_statuses_mediap() function without an authenticated user.
1211 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1213 public function testApiStatusesMediapWithoutAuthenticatedUser()
1215 $_SESSION['authenticated'] = false;
1216 api_statuses_mediap('json');
1220 * Test the api_statuses_update() function.
1224 public function testApiStatusesUpdate()
1226 $_GET['status'] = 'Status content #friendica';
1227 $_GET['in_reply_to_status_id'] = -1;
1236 'tmp_name' => $this->getTempImage(),
1237 'name' => 'spacer.png',
1238 'type' => 'image/png'
1242 $result = api_statuses_update('json');
1243 $this->assertStatus($result['status']);
1247 * Test the api_statuses_update() function with an HTML status.
1251 public function testApiStatusesUpdateWithHtml()
1253 $_GET['htmlstatus'] = '<b>Status content</b>';
1255 $result = api_statuses_update('json');
1256 $this->assertStatus($result['status']);
1260 * Test the api_statuses_update() function without an authenticated user.
1263 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1265 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1267 $_SESSION['authenticated'] = false;
1268 api_statuses_update('json');
1272 * Test the api_statuses_update() function with a parent status.
1276 public function testApiStatusesUpdateWithParent()
1278 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1282 * Test the api_statuses_update() function with a media_ids parameter.
1286 public function testApiStatusesUpdateWithMediaIds()
1288 $this->markTestIncomplete();
1292 * Test the api_statuses_update() function with the throttle limit reached.
1296 public function testApiStatusesUpdateWithDayThrottleReached()
1298 $this->markTestIncomplete();
1302 * Test the api_media_upload() function.
1305 * @expectedException Friendica\Network\HTTPException\BadRequestException
1307 public function testApiMediaUpload()
1313 * Test the api_media_upload() function without an authenticated user.
1316 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1318 public function testApiMediaUploadWithoutAuthenticatedUser()
1320 $_SESSION['authenticated'] = false;
1325 * Test the api_media_upload() function with an invalid uploaded media.
1328 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1330 public function testApiMediaUploadWithMedia()
1335 'tmp_name' => 'tmp_name'
1342 * Test the api_media_upload() function with an valid uploaded media.
1346 public function testApiMediaUploadWithValidMedia()
1354 'tmp_name' => $this->getTempImage(),
1355 'name' => 'spacer.png',
1356 'type' => 'image/png'
1362 $result = api_media_upload();
1363 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1364 $this->assertEquals(1, $result['media']['image']['w']);
1365 $this->assertEquals(1, $result['media']['image']['h']);
1366 $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
1370 * Test the api_status_show() function.
1372 public function testApiStatusShowWithJson()
1374 $result = api_status_show('json', 1);
1375 $this->assertStatus($result['status']);
1379 * Test the api_status_show() function with an XML result.
1381 public function testApiStatusShowWithXml()
1383 $result = api_status_show('xml', 1);
1384 $this->assertXml($result, 'statuses');
1388 * Test the api_get_last_status() function
1390 public function testApiGetLastStatus()
1392 $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
1394 $this->assertNotNull($item);
1398 * Test the api_users_show() function.
1402 public function testApiUsersShow()
1404 $result = api_users_show('json');
1405 // We can't use assertSelfUser() here because the user object is missing some properties.
1406 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1407 $this->assertEquals('DFRN', $result['user']['location']);
1408 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1409 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1410 $this->assertEquals('dfrn', $result['user']['network']);
1411 $this->assertTrue($result['user']['verified']);
1415 * Test the api_users_show() function with an XML result.
1419 public function testApiUsersShowWithXml()
1421 $result = api_users_show('xml');
1422 $this->assertXml($result, 'statuses');
1426 * Test the api_users_search() function.
1430 public function testApiUsersSearch()
1432 $_GET['q'] = 'othercontact';
1433 $result = api_users_search('json');
1434 $this->assertOtherUser($result['users'][0]);
1438 * Test the api_users_search() function with an XML result.
1442 public function testApiUsersSearchWithXml()
1444 $_GET['q'] = 'othercontact';
1445 $result = api_users_search('xml');
1446 $this->assertXml($result, 'users');
1450 * Test the api_users_search() function without a GET q parameter.
1453 * @expectedException Friendica\Network\HTTPException\BadRequestException
1455 public function testApiUsersSearchWithoutQuery()
1457 api_users_search('json');
1461 * Test the api_users_lookup() function.
1464 * @expectedException Friendica\Network\HTTPException\NotFoundException
1466 public function testApiUsersLookup()
1468 api_users_lookup('json');
1472 * Test the api_users_lookup() function with an user ID.
1476 public function testApiUsersLookupWithUserId()
1478 $_REQUEST['user_id'] = $this->otherUser['id'];
1479 $result = api_users_lookup('json');
1480 $this->assertOtherUser($result['users'][0]);
1484 * Test the api_search() function.
1488 public function testApiSearch()
1490 $_REQUEST['q'] = 'reply';
1491 $_REQUEST['max_id'] = 10;
1492 $result = api_search('json');
1493 foreach ($result['status'] as $status) {
1494 $this->assertStatus($status);
1495 $this->assertContains('reply', $status['text'], null, true);
1500 * Test the api_search() function a count parameter.
1504 public function testApiSearchWithCount()
1506 $_REQUEST['q'] = 'reply';
1507 $_REQUEST['count'] = 20;
1508 $result = api_search('json');
1509 foreach ($result['status'] as $status) {
1510 $this->assertStatus($status);
1511 $this->assertContains('reply', $status['text'], null, true);
1516 * Test the api_search() function with an rpp parameter.
1520 public function testApiSearchWithRpp()
1522 $_REQUEST['q'] = 'reply';
1523 $_REQUEST['rpp'] = 20;
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 with an q parameter contains hashtag.
1536 public function testApiSearchWithHashtag()
1538 $_REQUEST['q'] = '%23friendica';
1539 $result = api_search('json');
1540 foreach ($result['status'] as $status) {
1541 $this->assertStatus($status);
1542 $this->assertContains('#friendica', $status['text'], null, true);
1547 * Test the api_search() function with an exclude_replies parameter.
1551 public function testApiSearchWithExcludeReplies()
1553 $_REQUEST['max_id'] = 10;
1554 $_REQUEST['exclude_replies'] = true;
1555 $_REQUEST['q'] = 'friendica';
1556 $result = api_search('json');
1557 foreach ($result['status'] as $status) {
1558 $this->assertStatus($status);
1563 * Test the api_search() function without an authenticated user.
1566 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1568 public function testApiSearchWithUnallowedUser()
1570 $_SESSION['allow_api'] = false;
1571 $_GET['screen_name'] = $this->selfUser['nick'];
1576 * Test the api_search() function without any GET query parameter.
1579 * @expectedException Friendica\Network\HTTPException\BadRequestException
1581 public function testApiSearchWithoutQuery()
1587 * Test the api_statuses_home_timeline() function.
1591 public function testApiStatusesHomeTimeline()
1593 $_REQUEST['max_id'] = 10;
1594 $_REQUEST['exclude_replies'] = true;
1595 $_REQUEST['conversation_id'] = 1;
1596 $result = api_statuses_home_timeline('json');
1597 $this->assertNotEmpty($result['status']);
1598 foreach ($result['status'] as $status) {
1599 $this->assertStatus($status);
1604 * Test the api_statuses_home_timeline() function with a negative page parameter.
1608 public function testApiStatusesHomeTimelineWithNegativePage()
1610 $_REQUEST['page'] = -2;
1611 $result = api_statuses_home_timeline('json');
1612 $this->assertNotEmpty($result['status']);
1613 foreach ($result['status'] as $status) {
1614 $this->assertStatus($status);
1619 * Test the api_statuses_home_timeline() with an unallowed user.
1622 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1624 public function testApiStatusesHomeTimelineWithUnallowedUser()
1626 $_SESSION['allow_api'] = false;
1627 $_GET['screen_name'] = $this->selfUser['nick'];
1628 api_statuses_home_timeline('json');
1632 * Test the api_statuses_home_timeline() function with an RSS result.
1636 public function testApiStatusesHomeTimelineWithRss()
1638 $result = api_statuses_home_timeline('rss');
1639 $this->assertXml($result, 'statuses');
1643 * Test the api_statuses_public_timeline() function.
1647 public function testApiStatusesPublicTimeline()
1649 $_REQUEST['max_id'] = 10;
1650 $_REQUEST['conversation_id'] = 1;
1651 $result = api_statuses_public_timeline('json');
1652 $this->assertNotEmpty($result['status']);
1653 foreach ($result['status'] as $status) {
1654 $this->assertStatus($status);
1659 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1663 public function testApiStatusesPublicTimelineWithExcludeReplies()
1665 $_REQUEST['max_id'] = 10;
1666 $_REQUEST['exclude_replies'] = true;
1667 $result = api_statuses_public_timeline('json');
1668 $this->assertNotEmpty($result['status']);
1669 foreach ($result['status'] as $status) {
1670 $this->assertStatus($status);
1675 * Test the api_statuses_public_timeline() function with a negative page parameter.
1679 public function testApiStatusesPublicTimelineWithNegativePage()
1681 $_REQUEST['page'] = -2;
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 an unallowed user.
1693 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1695 public function testApiStatusesPublicTimelineWithUnallowedUser()
1697 $_SESSION['allow_api'] = false;
1698 $_GET['screen_name'] = $this->selfUser['nick'];
1699 api_statuses_public_timeline('json');
1703 * Test the api_statuses_public_timeline() function with an RSS result.
1707 public function testApiStatusesPublicTimelineWithRss()
1709 $result = api_statuses_public_timeline('rss');
1710 $this->assertXml($result, 'statuses');
1714 * Test the api_statuses_networkpublic_timeline() function.
1718 public function testApiStatusesNetworkpublicTimeline()
1720 $_REQUEST['max_id'] = 10;
1721 $result = api_statuses_networkpublic_timeline('json');
1722 $this->assertNotEmpty($result['status']);
1723 foreach ($result['status'] as $status) {
1724 $this->assertStatus($status);
1729 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1733 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1735 $_REQUEST['page'] = -2;
1736 $result = api_statuses_networkpublic_timeline('json');
1737 $this->assertNotEmpty($result['status']);
1738 foreach ($result['status'] as $status) {
1739 $this->assertStatus($status);
1744 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1747 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1749 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1751 $_SESSION['allow_api'] = false;
1752 $_GET['screen_name'] = $this->selfUser['nick'];
1753 api_statuses_networkpublic_timeline('json');
1757 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1761 public function testApiStatusesNetworkpublicTimelineWithRss()
1763 $result = api_statuses_networkpublic_timeline('rss');
1764 $this->assertXml($result, 'statuses');
1768 * Test the api_statuses_show() function.
1771 * @expectedException Friendica\Network\HTTPException\BadRequestException
1773 public function testApiStatusesShow()
1775 api_statuses_show('json');
1779 * Test the api_statuses_show() function with an ID.
1783 public function testApiStatusesShowWithId()
1785 $this->app->argv[3] = 1;
1786 $result = api_statuses_show('json');
1787 $this->assertStatus($result['status']);
1791 * Test the api_statuses_show() function with the conversation parameter.
1795 public function testApiStatusesShowWithConversation()
1797 $this->app->argv[3] = 1;
1798 $_REQUEST['conversation'] = 1;
1799 $result = api_statuses_show('json');
1800 $this->assertNotEmpty($result['status']);
1801 foreach ($result['status'] as $status) {
1802 $this->assertStatus($status);
1807 * Test the api_statuses_show() function with an unallowed user.
1810 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1812 public function testApiStatusesShowWithUnallowedUser()
1814 $_SESSION['allow_api'] = false;
1815 $_GET['screen_name'] = $this->selfUser['nick'];
1816 api_statuses_show('json');
1820 * Test the api_conversation_show() function.
1823 * @expectedException Friendica\Network\HTTPException\BadRequestException
1825 public function testApiConversationShow()
1827 api_conversation_show('json');
1831 * Test the api_conversation_show() function with an ID.
1835 public function testApiConversationShowWithId()
1837 $this->app->argv[3] = 1;
1838 $_REQUEST['max_id'] = 10;
1839 $_REQUEST['page'] = -2;
1840 $result = api_conversation_show('json');
1841 $this->assertNotEmpty($result['status']);
1842 foreach ($result['status'] as $status) {
1843 $this->assertStatus($status);
1848 * Test the api_conversation_show() function with an unallowed user.
1851 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1853 public function testApiConversationShowWithUnallowedUser()
1855 $_SESSION['allow_api'] = false;
1856 $_GET['screen_name'] = $this->selfUser['nick'];
1857 api_conversation_show('json');
1861 * Test the api_statuses_repeat() function.
1864 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1866 public function testApiStatusesRepeat()
1868 api_statuses_repeat('json');
1872 * Test the api_statuses_repeat() function without an authenticated user.
1875 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1877 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1879 $_SESSION['authenticated'] = false;
1880 api_statuses_repeat('json');
1884 * Test the api_statuses_repeat() function with an ID.
1888 public function testApiStatusesRepeatWithId()
1890 $this->app->argv[3] = 1;
1891 $result = api_statuses_repeat('json');
1892 $this->assertStatus($result['status']);
1894 // Also test with a shared status
1895 $this->app->argv[3] = 5;
1896 $result = api_statuses_repeat('json');
1897 $this->assertStatus($result['status']);
1901 * Test the api_statuses_destroy() function.
1904 * @expectedException Friendica\Network\HTTPException\BadRequestException
1906 public function testApiStatusesDestroy()
1908 api_statuses_destroy('json');
1912 * Test the api_statuses_destroy() function without an authenticated user.
1915 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1917 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1919 $_SESSION['authenticated'] = false;
1920 api_statuses_destroy('json');
1924 * Test the api_statuses_destroy() function with an ID.
1928 public function testApiStatusesDestroyWithId()
1930 $this->app->argv[3] = 1;
1931 $result = api_statuses_destroy('json');
1932 $this->assertStatus($result['status']);
1936 * Test the api_statuses_mentions() function.
1940 public function testApiStatusesMentions()
1942 $this->app->user = ['nickname' => $this->selfUser['nick']];
1943 $_REQUEST['max_id'] = 10;
1944 $result = api_statuses_mentions('json');
1945 $this->assertEmpty($result['status']);
1946 // We should test with mentions in the database.
1950 * Test the api_statuses_mentions() function with a negative page parameter.
1954 public function testApiStatusesMentionsWithNegativePage()
1956 $_REQUEST['page'] = -2;
1957 $result = api_statuses_mentions('json');
1958 $this->assertEmpty($result['status']);
1962 * Test the api_statuses_mentions() function with an unallowed user.
1965 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1967 public function testApiStatusesMentionsWithUnallowedUser()
1969 $_SESSION['allow_api'] = false;
1970 $_GET['screen_name'] = $this->selfUser['nick'];
1971 api_statuses_mentions('json');
1975 * Test the api_statuses_mentions() function with an RSS result.
1979 public function testApiStatusesMentionsWithRss()
1981 $result = api_statuses_mentions('rss');
1982 $this->assertXml($result, 'statuses');
1986 * Test the api_statuses_user_timeline() function.
1990 public function testApiStatusesUserTimeline()
1992 $_REQUEST['max_id'] = 10;
1993 $_REQUEST['exclude_replies'] = true;
1994 $_REQUEST['conversation_id'] = 1;
1995 $result = api_statuses_user_timeline('json');
1996 $this->assertNotEmpty($result['status']);
1997 foreach ($result['status'] as $status) {
1998 $this->assertStatus($status);
2003 * Test the api_statuses_user_timeline() function with a negative page parameter.
2007 public function testApiStatusesUserTimelineWithNegativePage()
2009 $_REQUEST['page'] = -2;
2010 $result = api_statuses_user_timeline('json');
2011 $this->assertNotEmpty($result['status']);
2012 foreach ($result['status'] as $status) {
2013 $this->assertStatus($status);
2018 * Test the api_statuses_user_timeline() function with an RSS result.
2022 public function testApiStatusesUserTimelineWithRss()
2024 $result = api_statuses_user_timeline('rss');
2025 $this->assertXml($result, 'statuses');
2029 * Test the api_statuses_user_timeline() function with an unallowed user.
2032 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2034 public function testApiStatusesUserTimelineWithUnallowedUser()
2036 $_SESSION['allow_api'] = false;
2037 $_GET['screen_name'] = $this->selfUser['nick'];
2038 api_statuses_user_timeline('json');
2042 * Test the api_favorites_create_destroy() function.
2045 * @expectedException Friendica\Network\HTTPException\BadRequestException
2047 public function testApiFavoritesCreateDestroy()
2049 $this->app->argv = ['api', '1.1', 'favorites', 'create'];
2050 $this->app->argc = count($this->app->argv);
2051 api_favorites_create_destroy('json');
2055 * Test the api_favorites_create_destroy() function with an invalid ID.
2058 * @expectedException Friendica\Network\HTTPException\BadRequestException
2060 public function testApiFavoritesCreateDestroyWithInvalidId()
2062 $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
2063 $this->app->argc = count($this->app->argv);
2064 api_favorites_create_destroy('json');
2068 * Test the api_favorites_create_destroy() function with an invalid action.
2071 * @expectedException Friendica\Network\HTTPException\BadRequestException
2073 public function testApiFavoritesCreateDestroyWithInvalidAction()
2075 $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
2076 $this->app->argc = count($this->app->argv);
2077 $_REQUEST['id'] = 1;
2078 api_favorites_create_destroy('json');
2082 * Test the api_favorites_create_destroy() function with the create action.
2086 public function testApiFavoritesCreateDestroyWithCreateAction()
2088 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2089 $this->app->argc = count($this->app->argv);
2090 $_REQUEST['id'] = 3;
2091 $result = api_favorites_create_destroy('json');
2092 $this->assertStatus($result['status']);
2096 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
2100 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
2102 $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
2103 $this->app->argc = count($this->app->argv);
2104 $_REQUEST['id'] = 3;
2105 $result = api_favorites_create_destroy('rss');
2106 $this->assertXml($result, 'status');
2110 * Test the api_favorites_create_destroy() function with the destroy action.
2114 public function testApiFavoritesCreateDestroyWithDestroyAction()
2116 $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
2117 $this->app->argc = count($this->app->argv);
2118 $_REQUEST['id'] = 3;
2119 $result = api_favorites_create_destroy('json');
2120 $this->assertStatus($result['status']);
2124 * Test the api_favorites_create_destroy() function without an authenticated user.
2127 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2129 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
2131 $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
2132 $this->app->argc = count($this->app->argv);
2133 $_SESSION['authenticated'] = false;
2134 api_favorites_create_destroy('json');
2138 * Test the api_favorites() function.
2142 public function testApiFavorites()
2144 $_REQUEST['page'] = -1;
2145 $_REQUEST['max_id'] = 10;
2146 $result = api_favorites('json');
2147 foreach ($result['status'] as $status) {
2148 $this->assertStatus($status);
2153 * Test the api_favorites() function with an RSS result.
2157 public function testApiFavoritesWithRss()
2159 $result = api_favorites('rss');
2160 $this->assertXml($result, 'statuses');
2164 * Test the api_favorites() function with an unallowed user.
2167 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2169 public function testApiFavoritesWithUnallowedUser()
2171 $_SESSION['allow_api'] = false;
2172 $_GET['screen_name'] = $this->selfUser['nick'];
2173 api_favorites('json');
2177 * Test the api_format_messages() function.
2181 public function testApiFormatMessages()
2183 $result = api_format_messages(
2184 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2185 ['id' => 2, 'screen_name' => 'recipient_name'],
2186 ['id' => 3, 'screen_name' => 'sender_name']
2188 $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
2189 $this->assertEquals(1, $result['id']);
2190 $this->assertEquals(2, $result['recipient_id']);
2191 $this->assertEquals(3, $result['sender_id']);
2192 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
2193 $this->assertEquals('sender_name', $result['sender_screen_name']);
2197 * Test the api_format_messages() function with HTML.
2201 public function testApiFormatMessagesWithHtmlText()
2203 $_GET['getText'] = 'html';
2204 $result = api_format_messages(
2205 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2206 ['id' => 2, 'screen_name' => 'recipient_name'],
2207 ['id' => 3, 'screen_name' => 'sender_name']
2209 $this->assertEquals('item_title', $result['title']);
2210 $this->assertEquals('<strong>item_body</strong>', $result['text']);
2214 * Test the api_format_messages() function with plain text.
2218 public function testApiFormatMessagesWithPlainText()
2220 $_GET['getText'] = 'plain';
2221 $result = api_format_messages(
2222 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2223 ['id' => 2, 'screen_name' => 'recipient_name'],
2224 ['id' => 3, 'screen_name' => 'sender_name']
2226 $this->assertEquals('item_title', $result['title']);
2227 $this->assertEquals('item_body', $result['text']);
2231 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2235 public function testApiFormatMessagesWithoutUserObjects()
2237 $_GET['getUserObjects'] = 'false';
2238 $result = api_format_messages(
2239 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2240 ['id' => 2, 'screen_name' => 'recipient_name'],
2241 ['id' => 3, 'screen_name' => 'sender_name']
2243 $this->assertTrue(!isset($result['sender']));
2244 $this->assertTrue(!isset($result['recipient']));
2248 * Test the api_convert_item() function.
2252 public function testApiConvertItem()
2254 $result = api_convert_item(
2256 'network' => 'feed',
2257 'title' => 'item_title',
2258 // We need a long string to test that it is correctly cut
2259 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
2260 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
2261 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
2262 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
2263 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
2264 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
2265 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
2266 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
2267 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
2268 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
2269 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
2270 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
2271 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
2272 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
2273 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
2274 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
2275 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
2276 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
2277 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
2278 'repellat officia illum quos impedit quam iste esse unde qui ' .
2279 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
2280 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
2281 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
2282 'plink' => 'item_plink'
2285 $this->assertStringStartsWith('item_title', $result['text']);
2286 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2290 * Test the api_convert_item() function with an empty item body.
2294 public function testApiConvertItemWithoutBody()
2296 $result = api_convert_item(
2298 'network' => 'feed',
2299 'title' => 'item_title',
2301 'plink' => 'item_plink'
2304 $this->assertEquals('item_title', $result['text']);
2305 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2309 * Test the api_convert_item() function with the title in the body.
2313 public function testApiConvertItemWithTitleInBody()
2315 $result = api_convert_item(
2317 'title' => 'item_title',
2318 'body' => 'item_title item_body'
2321 $this->assertEquals('item_title item_body', $result['text']);
2322 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2326 * Test the api_get_attachments() function.
2330 public function testApiGetAttachments()
2333 $this->assertEmpty(api_get_attachments($body));
2337 * Test the api_get_attachments() function with an img tag.
2341 public function testApiGetAttachmentsWithImage()
2343 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2344 $this->assertInternalType('array', api_get_attachments($body));
2348 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2352 public function testApiGetAttachmentsWithImageAndAndStatus()
2354 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2355 $body = '[img]http://via.placeholder.com/1x1.png[/img]';
2356 $this->assertInternalType('array', api_get_attachments($body));
2360 * Test the api_get_entitities() function.
2364 public function testApiGetEntitities()
2367 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2371 * Test the api_get_entitities() function with the include_entities parameter.
2375 public function testApiGetEntititiesWithIncludeEntities()
2377 $_REQUEST['include_entities'] = 'true';
2379 $result = api_get_entitities($text, 'bbcode');
2380 $this->assertInternalType('array', $result['hashtags']);
2381 $this->assertInternalType('array', $result['symbols']);
2382 $this->assertInternalType('array', $result['urls']);
2383 $this->assertInternalType('array', $result['user_mentions']);
2387 * Test the api_format_items_embeded_images() function.
2391 public function testApiFormatItemsEmbededImages()
2393 $this->assertEquals(
2394 'text ' . System::baseUrl() . '/display/item_guid',
2395 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2400 * Test the api_contactlink_to_array() function.
2404 public function testApiContactlinkToArray()
2406 $this->assertEquals(
2411 api_contactlink_to_array('text')
2416 * Test the api_contactlink_to_array() function with an URL.
2420 public function testApiContactlinkToArrayWithUrl()
2422 $this->assertEquals(
2424 'name' => ['link_text'],
2427 api_contactlink_to_array('text <a href="url">link_text</a>')
2432 * Test the api_format_items_activities() function.
2436 public function testApiFormatItemsActivities()
2438 $item = ['uid' => 0, 'uri' => ''];
2439 $result = api_format_items_activities($item);
2440 $this->assertArrayHasKey('like', $result);
2441 $this->assertArrayHasKey('dislike', $result);
2442 $this->assertArrayHasKey('attendyes', $result);
2443 $this->assertArrayHasKey('attendno', $result);
2444 $this->assertArrayHasKey('attendmaybe', $result);
2448 * Test the api_format_items_activities() function with an XML result.
2452 public function testApiFormatItemsActivitiesWithXml()
2454 $item = ['uid' => 0, 'uri' => ''];
2455 $result = api_format_items_activities($item, 'xml');
2456 $this->assertArrayHasKey('friendica:like', $result);
2457 $this->assertArrayHasKey('friendica:dislike', $result);
2458 $this->assertArrayHasKey('friendica:attendyes', $result);
2459 $this->assertArrayHasKey('friendica:attendno', $result);
2460 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2464 * Test the api_format_items_profiles() function.
2468 public function testApiFormatItemsProfiles()
2471 'id' => 'profile_id',
2472 'profile-name' => 'profile_name',
2473 'is-default' => true,
2474 'hide-friends' => true,
2475 'photo' => 'profile_photo',
2476 'thumb' => 'profile_thumb',
2478 'net-publish' => true,
2479 'pdesc' => 'description',
2480 'dob' => 'date_of_birth',
2481 'address' => 'address',
2482 'locality' => 'city',
2483 'region' => 'region',
2484 'postal-code' => 'postal_code',
2485 'country-name' => 'country',
2486 'hometown' => 'hometown',
2487 'gender' => 'gender',
2488 'marital' => 'marital',
2489 'with' => 'marital_with',
2490 'howlong' => 'marital_since',
2491 'sexual' => 'sexual',
2492 'politic' => 'politic',
2493 'religion' => 'religion',
2494 'pub_keywords' => 'public_keywords',
2495 'prv_keywords' => 'private_keywords',
2498 'dislikes' => 'dislikes',
2504 'interest' => 'interest',
2505 'romance' => 'romance',
2507 'education' => 'education',
2508 'contact' => 'social_networks',
2509 'homepage' => 'homepage'
2511 $result = api_format_items_profiles($profile_row);
2512 $this->assertEquals(
2514 'profile_id' => 'profile_id',
2515 'profile_name' => 'profile_name',
2516 'is_default' => true,
2517 'hide_friends' => true,
2518 'profile_photo' => 'profile_photo',
2519 'profile_thumb' => 'profile_thumb',
2521 'net_publish' => true,
2522 'description' => 'description',
2523 'date_of_birth' => 'date_of_birth',
2524 'address' => 'address',
2526 'region' => 'region',
2527 'postal_code' => 'postal_code',
2528 'country' => 'country',
2529 'hometown' => 'hometown',
2530 'gender' => 'gender',
2531 'marital' => 'marital',
2532 'marital_with' => 'marital_with',
2533 'marital_since' => 'marital_since',
2534 'sexual' => 'sexual',
2535 'politic' => 'politic',
2536 'religion' => 'religion',
2537 'public_keywords' => 'public_keywords',
2538 'private_keywords' => 'private_keywords',
2541 'dislikes' => 'dislikes',
2547 'interest' => 'interest',
2548 'romance' => 'romance',
2550 'education' => 'education',
2551 'social_networks' => 'social_networks',
2552 'homepage' => 'homepage',
2560 * Test the api_format_items() function.
2564 public function testApiFormatItems()
2568 'item_network' => 'item_network',
2574 'author-network' => Protocol::DFRN,
2575 'author-link' => 'http://localhost/profile/othercontact',
2579 $result = api_format_items($items, ['id' => 0], true);
2580 foreach ($result as $status) {
2581 $this->assertStatus($status);
2586 * Test the api_format_items() function with an XML result.
2590 public function testApiFormatItemsWithXml()
2598 'author-network' => Protocol::DFRN,
2599 'author-link' => 'http://localhost/profile/othercontact',
2603 $result = api_format_items($items, ['id' => 0], true, 'xml');
2604 foreach ($result as $status) {
2605 $this->assertStatus($status);
2610 * Test the api_format_items() function.
2614 public function testApiAccountRateLimitStatus()
2616 $result = api_account_rate_limit_status('json');
2617 $this->assertEquals(150, $result['hash']['remaining_hits']);
2618 $this->assertEquals(150, $result['hash']['hourly_limit']);
2619 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2623 * Test the api_format_items() function with an XML result.
2627 public function testApiAccountRateLimitStatusWithXml()
2629 $result = api_account_rate_limit_status('xml');
2630 $this->assertXml($result, 'hash');
2634 * Test the api_help_test() function.
2638 public function testApiHelpTest()
2640 $result = api_help_test('json');
2641 $this->assertEquals(['ok' => 'ok'], $result);
2645 * Test the api_help_test() function with an XML result.
2649 public function testApiHelpTestWithXml()
2651 $result = api_help_test('xml');
2652 $this->assertXml($result, 'ok');
2656 * Test the api_lists_list() function.
2660 public function testApiListsList()
2662 $result = api_lists_list('json');
2663 $this->assertEquals(['lists_list' => []], $result);
2667 * Test the api_lists_ownerships() function.
2671 public function testApiListsOwnerships()
2673 $result = api_lists_ownerships('json');
2674 foreach ($result['lists']['lists'] as $list) {
2675 $this->assertList($list);
2680 * Test the api_lists_ownerships() function without an authenticated user.
2683 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2685 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2687 $_SESSION['authenticated'] = false;
2688 api_lists_ownerships('json');
2692 * Test the api_lists_statuses() function.
2694 * @expectedException Friendica\Network\HTTPException\BadRequestException
2697 public function testApiListsStatuses()
2699 api_lists_statuses('json');
2703 * Test the api_lists_statuses() function with a list ID.
2707 public function testApiListsStatusesWithListId()
2709 $_REQUEST['list_id'] = 1;
2710 $_REQUEST['page'] = -1;
2711 $_REQUEST['max_id'] = 10;
2712 $result = api_lists_statuses('json');
2713 foreach ($result['status'] as $status) {
2714 $this->assertStatus($status);
2719 * Test the api_lists_statuses() function with a list ID and a RSS result.
2723 public function testApiListsStatusesWithListIdAndRss()
2725 $_REQUEST['list_id'] = 1;
2726 $result = api_lists_statuses('rss');
2727 $this->assertXml($result, 'statuses');
2731 * Test the api_lists_statuses() function with an unallowed user.
2734 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2736 public function testApiListsStatusesWithUnallowedUser()
2738 $_SESSION['allow_api'] = false;
2739 $_GET['screen_name'] = $this->selfUser['nick'];
2740 api_lists_statuses('json');
2744 * Test the api_statuses_f() function.
2748 public function testApiStatusesFWithFriends()
2751 $result = api_statuses_f('friends');
2752 $this->assertArrayHasKey('user', $result);
2756 * Test the api_statuses_f() function.
2760 public function testApiStatusesFWithFollowers()
2762 $result = api_statuses_f('followers');
2763 $this->assertArrayHasKey('user', $result);
2767 * Test the api_statuses_f() function.
2771 public function testApiStatusesFWithBlocks()
2773 $result = api_statuses_f('blocks');
2774 $this->assertArrayHasKey('user', $result);
2778 * Test the api_statuses_f() function.
2782 public function testApiStatusesFWithIncoming()
2784 $result = api_statuses_f('incoming');
2785 $this->assertArrayHasKey('user', $result);
2789 * Test the api_statuses_f() function an undefined cursor GET variable.
2793 public function testApiStatusesFWithUndefinedCursor()
2795 $_GET['cursor'] = 'undefined';
2796 $this->assertFalse(api_statuses_f('friends'));
2800 * Test the api_statuses_friends() function.
2804 public function testApiStatusesFriends()
2806 $result = api_statuses_friends('json');
2807 $this->assertArrayHasKey('user', $result);
2811 * Test the api_statuses_friends() function an undefined cursor GET variable.
2815 public function testApiStatusesFriendsWithUndefinedCursor()
2817 $_GET['cursor'] = 'undefined';
2818 $this->assertFalse(api_statuses_friends('json'));
2822 * Test the api_statuses_followers() function.
2826 public function testApiStatusesFollowers()
2828 $result = api_statuses_followers('json');
2829 $this->assertArrayHasKey('user', $result);
2833 * Test the api_statuses_followers() function an undefined cursor GET variable.
2837 public function testApiStatusesFollowersWithUndefinedCursor()
2839 $_GET['cursor'] = 'undefined';
2840 $this->assertFalse(api_statuses_followers('json'));
2844 * Test the api_blocks_list() function.
2848 public function testApiBlocksList()
2850 $result = api_blocks_list('json');
2851 $this->assertArrayHasKey('user', $result);
2855 * Test the api_blocks_list() function an undefined cursor GET variable.
2859 public function testApiBlocksListWithUndefinedCursor()
2861 $_GET['cursor'] = 'undefined';
2862 $this->assertFalse(api_blocks_list('json'));
2866 * Test the api_friendships_incoming() function.
2870 public function testApiFriendshipsIncoming()
2872 $result = api_friendships_incoming('json');
2873 $this->assertArrayHasKey('id', $result);
2877 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2881 public function testApiFriendshipsIncomingWithUndefinedCursor()
2883 $_GET['cursor'] = 'undefined';
2884 $this->assertFalse(api_friendships_incoming('json'));
2888 * Test the api_statusnet_config() function.
2892 public function testApiStatusnetConfig()
2894 $result = api_statusnet_config('json');
2895 $this->assertEquals('localhost', $result['config']['site']['server']);
2896 $this->assertEquals('default', $result['config']['site']['theme']);
2897 $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
2898 $this->assertTrue($result['config']['site']['fancy']);
2899 $this->assertEquals('en', $result['config']['site']['language']);
2900 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2901 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2902 $this->assertEquals('false', $result['config']['site']['private']);
2903 $this->assertEquals('false', $result['config']['site']['ssl']);
2904 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2908 * Test the api_statusnet_version() function.
2912 public function testApiStatusnetVersion()
2914 $result = api_statusnet_version('json');
2915 $this->assertEquals('0.9.7', $result['version']);
2919 * Test the api_ff_ids() function.
2923 public function testApiFfIds()
2925 $result = api_ff_ids('json');
2926 $this->assertNull($result);
2930 * Test the api_ff_ids() function with a result.
2934 public function testApiFfIdsWithResult()
2936 $this->markTestIncomplete();
2940 * Test the api_ff_ids() function without an authenticated user.
2943 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2945 public function testApiFfIdsWithoutAuthenticatedUser()
2947 $_SESSION['authenticated'] = false;
2952 * Test the api_friends_ids() function.
2956 public function testApiFriendsIds()
2958 $result = api_friends_ids('json');
2959 $this->assertNull($result);
2963 * Test the api_followers_ids() function.
2967 public function testApiFollowersIds()
2969 $result = api_followers_ids('json');
2970 $this->assertNull($result);
2974 * Test the api_direct_messages_new() function.
2978 public function testApiDirectMessagesNew()
2980 $result = api_direct_messages_new('json');
2981 $this->assertNull($result);
2985 * Test the api_direct_messages_new() function without an authenticated user.
2988 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2990 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2992 $_SESSION['authenticated'] = false;
2993 api_direct_messages_new('json');
2997 * Test the api_direct_messages_new() function with an user ID.
3001 public function testApiDirectMessagesNewWithUserId()
3003 $_POST['text'] = 'message_text';
3004 $_POST['user_id'] = $this->otherUser['id'];
3005 $result = api_direct_messages_new('json');
3006 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
3010 * Test the api_direct_messages_new() function with a screen name.
3014 public function testApiDirectMessagesNewWithScreenName()
3016 $_POST['text'] = 'message_text';
3017 $_POST['screen_name'] = $this->friendUser['nick'];
3018 $result = api_direct_messages_new('json');
3019 $this->assertContains('message_text', $result['direct_message']['text']);
3020 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3021 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3025 * Test the api_direct_messages_new() function with a title.
3029 public function testApiDirectMessagesNewWithTitle()
3031 $_POST['text'] = 'message_text';
3032 $_POST['screen_name'] = $this->friendUser['nick'];
3033 $_REQUEST['title'] = 'message_title';
3034 $result = api_direct_messages_new('json');
3035 $this->assertContains('message_text', $result['direct_message']['text']);
3036 $this->assertContains('message_title', $result['direct_message']['text']);
3037 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
3038 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
3042 * Test the api_direct_messages_new() function with an RSS result.
3046 public function testApiDirectMessagesNewWithRss()
3048 $_POST['text'] = 'message_text';
3049 $_POST['screen_name'] = $this->friendUser['nick'];
3050 $result = api_direct_messages_new('rss');
3051 $this->assertXml($result, 'direct-messages');
3055 * Test the api_direct_messages_destroy() function.
3058 * @expectedException Friendica\Network\HTTPException\BadRequestException
3060 public function testApiDirectMessagesDestroy()
3062 api_direct_messages_destroy('json');
3066 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
3070 public function testApiDirectMessagesDestroyWithVerbose()
3072 $_GET['friendica_verbose'] = 'true';
3073 $result = api_direct_messages_destroy('json');
3074 $this->assertEquals(
3077 'result' => 'error',
3078 'message' => 'message id or parenturi not specified'
3086 * Test the api_direct_messages_destroy() function without an authenticated user.
3089 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3091 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
3093 $_SESSION['authenticated'] = false;
3094 api_direct_messages_destroy('json');
3098 * Test the api_direct_messages_destroy() function with a non-zero ID.
3101 * @expectedException Friendica\Network\HTTPException\BadRequestException
3103 public function testApiDirectMessagesDestroyWithId()
3105 $_REQUEST['id'] = 1;
3106 api_direct_messages_destroy('json');
3110 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
3114 public function testApiDirectMessagesDestroyWithIdAndVerbose()
3116 $_REQUEST['id'] = 1;
3117 $_REQUEST['friendica_parenturi'] = 'parent_uri';
3118 $_GET['friendica_verbose'] = 'true';
3119 $result = api_direct_messages_destroy('json');
3120 $this->assertEquals(
3123 'result' => 'error',
3124 'message' => 'message id not in database'
3132 * Test the api_direct_messages_destroy() function with a non-zero ID.
3136 public function testApiDirectMessagesDestroyWithCorrectId()
3138 $this->markTestIncomplete('We need to add a dataset for this.');
3142 * Test the api_direct_messages_box() function.
3146 public function testApiDirectMessagesBoxWithSentbox()
3148 $_REQUEST['page'] = -1;
3149 $_REQUEST['max_id'] = 10;
3150 $result = api_direct_messages_box('json', 'sentbox', 'false');
3151 $this->assertArrayHasKey('direct_message', $result);
3155 * Test the api_direct_messages_box() function.
3159 public function testApiDirectMessagesBoxWithConversation()
3161 $result = api_direct_messages_box('json', 'conversation', 'false');
3162 $this->assertArrayHasKey('direct_message', $result);
3166 * Test the api_direct_messages_box() function.
3170 public function testApiDirectMessagesBoxWithAll()
3172 $result = api_direct_messages_box('json', 'all', 'false');
3173 $this->assertArrayHasKey('direct_message', $result);
3177 * Test the api_direct_messages_box() function.
3181 public function testApiDirectMessagesBoxWithInbox()
3183 $result = api_direct_messages_box('json', 'inbox', 'false');
3184 $this->assertArrayHasKey('direct_message', $result);
3188 * Test the api_direct_messages_box() function.
3192 public function testApiDirectMessagesBoxWithVerbose()
3194 $result = api_direct_messages_box('json', 'sentbox', 'true');
3195 $this->assertEquals(
3198 'result' => 'error',
3199 'message' => 'no mails available'
3207 * Test the api_direct_messages_box() function with a RSS result.
3211 public function testApiDirectMessagesBoxWithRss()
3213 $result = api_direct_messages_box('rss', 'sentbox', 'false');
3214 $this->assertXml($result, 'direct-messages');
3218 * Test the api_direct_messages_box() function without an authenticated user.
3221 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3223 public function testApiDirectMessagesBoxWithUnallowedUser()
3225 $_SESSION['allow_api'] = false;
3226 $_GET['screen_name'] = $this->selfUser['nick'];
3227 api_direct_messages_box('json', 'sentbox', 'false');
3231 * Test the api_direct_messages_sentbox() function.
3235 public function testApiDirectMessagesSentbox()
3237 $result = api_direct_messages_sentbox('json');
3238 $this->assertArrayHasKey('direct_message', $result);
3242 * Test the api_direct_messages_inbox() function.
3246 public function testApiDirectMessagesInbox()
3248 $result = api_direct_messages_inbox('json');
3249 $this->assertArrayHasKey('direct_message', $result);
3253 * Test the api_direct_messages_all() function.
3257 public function testApiDirectMessagesAll()
3259 $result = api_direct_messages_all('json');
3260 $this->assertArrayHasKey('direct_message', $result);
3264 * Test the api_direct_messages_conversation() function.
3268 public function testApiDirectMessagesConversation()
3270 $result = api_direct_messages_conversation('json');
3271 $this->assertArrayHasKey('direct_message', $result);
3275 * Test the api_oauth_request_token() function.
3279 public function testApiOauthRequestToken()
3281 $this->markTestIncomplete('killme() kills phpunit as well');
3285 * Test the api_oauth_access_token() function.
3289 public function testApiOauthAccessToken()
3291 $this->markTestIncomplete('killme() kills phpunit as well');
3295 * Test the api_fr_photoalbum_delete() function.
3298 * @expectedException Friendica\Network\HTTPException\BadRequestException
3300 public function testApiFrPhotoalbumDelete()
3302 api_fr_photoalbum_delete('json');
3306 * Test the api_fr_photoalbum_delete() function with an album name.
3309 * @expectedException Friendica\Network\HTTPException\BadRequestException
3311 public function testApiFrPhotoalbumDeleteWithAlbum()
3313 $_REQUEST['album'] = 'album_name';
3314 api_fr_photoalbum_delete('json');
3318 * Test the api_fr_photoalbum_delete() function with an album name.
3322 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3324 $this->markTestIncomplete('We need to add a dataset for this.');
3328 * Test the api_fr_photoalbum_delete() function.
3331 * @expectedException Friendica\Network\HTTPException\BadRequestException
3333 public function testApiFrPhotoalbumUpdate()
3335 api_fr_photoalbum_update('json');
3339 * Test the api_fr_photoalbum_delete() function with an album name.
3342 * @expectedException Friendica\Network\HTTPException\BadRequestException
3344 public function testApiFrPhotoalbumUpdateWithAlbum()
3346 $_REQUEST['album'] = 'album_name';
3347 api_fr_photoalbum_update('json');
3351 * Test the api_fr_photoalbum_delete() function with an album name.
3354 * @expectedException Friendica\Network\HTTPException\BadRequestException
3356 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3358 $_REQUEST['album'] = 'album_name';
3359 $_REQUEST['album_new'] = 'album_name';
3360 api_fr_photoalbum_update('json');
3364 * Test the api_fr_photoalbum_update() function without an authenticated user.
3367 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3369 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3371 $_SESSION['authenticated'] = false;
3372 api_fr_photoalbum_update('json');
3376 * Test the api_fr_photoalbum_delete() function with an album name.
3380 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3382 $this->markTestIncomplete('We need to add a dataset for this.');
3386 * Test the api_fr_photos_list() function.
3390 public function testApiFrPhotosList()
3392 $result = api_fr_photos_list('json');
3393 $this->assertArrayHasKey('photo', $result);
3397 * Test the api_fr_photos_list() function without an authenticated user.
3400 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3402 public function testApiFrPhotosListWithoutAuthenticatedUser()
3404 $_SESSION['authenticated'] = false;
3405 api_fr_photos_list('json');
3409 * Test the api_fr_photo_create_update() function.
3412 * @expectedException Friendica\Network\HTTPException\BadRequestException
3414 public function testApiFrPhotoCreateUpdate()
3416 api_fr_photo_create_update('json');
3420 * Test the api_fr_photo_create_update() function without an authenticated user.
3423 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3425 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3427 $_SESSION['authenticated'] = false;
3428 api_fr_photo_create_update('json');
3432 * Test the api_fr_photo_create_update() function with an album name.
3435 * @expectedException Friendica\Network\HTTPException\BadRequestException
3437 public function testApiFrPhotoCreateUpdateWithAlbum()
3439 $_REQUEST['album'] = 'album_name';
3440 api_fr_photo_create_update('json');
3444 * Test the api_fr_photo_create_update() function with the update mode.
3448 public function testApiFrPhotoCreateUpdateWithUpdate()
3450 $this->markTestIncomplete('We need to create a dataset for this');
3454 * Test the api_fr_photo_create_update() function with an uploaded file.
3458 public function testApiFrPhotoCreateUpdateWithFile()
3460 $this->markTestIncomplete();
3464 * Test the api_fr_photo_delete() function.
3467 * @expectedException Friendica\Network\HTTPException\BadRequestException
3469 public function testApiFrPhotoDelete()
3471 api_fr_photo_delete('json');
3475 * Test the api_fr_photo_delete() function without an authenticated user.
3478 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3480 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3482 $_SESSION['authenticated'] = false;
3483 api_fr_photo_delete('json');
3487 * Test the api_fr_photo_delete() function with a photo ID.
3490 * @expectedException Friendica\Network\HTTPException\BadRequestException
3492 public function testApiFrPhotoDeleteWithPhotoId()
3494 $_REQUEST['photo_id'] = 1;
3495 api_fr_photo_delete('json');
3499 * Test the api_fr_photo_delete() function with a correct photo ID.
3503 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3505 $this->markTestIncomplete('We need to create a dataset for this.');
3509 * Test the api_fr_photo_detail() function.
3512 * @expectedException Friendica\Network\HTTPException\BadRequestException
3514 public function testApiFrPhotoDetail()
3516 api_fr_photo_detail('json');
3520 * Test the api_fr_photo_detail() function without an authenticated user.
3523 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3525 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3527 $_SESSION['authenticated'] = false;
3528 api_fr_photo_detail('json');
3532 * Test the api_fr_photo_detail() function with a photo ID.
3535 * @expectedException Friendica\Network\HTTPException\NotFoundException
3537 public function testApiFrPhotoDetailWithPhotoId()
3539 $_REQUEST['photo_id'] = 1;
3540 api_fr_photo_detail('json');
3544 * Test the api_fr_photo_detail() function with a correct photo ID.
3548 public function testApiFrPhotoDetailCorrectPhotoId()
3550 $this->markTestIncomplete('We need to create a dataset for this.');
3554 * Test the api_account_update_profile_image() function.
3557 * @expectedException Friendica\Network\HTTPException\BadRequestException
3559 public function testApiAccountUpdateProfileImage()
3561 api_account_update_profile_image('json');
3565 * Test the api_account_update_profile_image() function without an authenticated user.
3568 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3570 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3572 $_SESSION['authenticated'] = false;
3573 api_account_update_profile_image('json');
3577 * Test the api_account_update_profile_image() function with an uploaded file.
3580 * @expectedException Friendica\Network\HTTPException\BadRequestException
3582 public function testApiAccountUpdateProfileImageWithUpload()
3584 $this->markTestIncomplete();
3589 * Test the api_account_update_profile() function.
3593 public function testApiAccountUpdateProfile()
3595 $_POST['name'] = 'new_name';
3596 $_POST['description'] = 'new_description';
3597 $result = api_account_update_profile('json');
3598 // We can't use assertSelfUser() here because the user object is missing some properties.
3599 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3600 $this->assertEquals('DFRN', $result['user']['location']);
3601 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3602 $this->assertEquals('dfrn', $result['user']['network']);
3603 $this->assertEquals('new_name', $result['user']['name']);
3604 $this->assertEquals('new_description', $result['user']['description']);
3608 * Test the check_acl_input() function.
3612 public function testCheckAclInput()
3614 $result = check_acl_input('<aclstring>');
3615 // Where does this result come from?
3616 $this->assertEquals(1, $result);
3620 * Test the check_acl_input() function with an empty ACL string.
3624 public function testCheckAclInputWithEmptyAclString()
3626 $result = check_acl_input(' ');
3627 $this->assertFalse($result);
3631 * Test the save_media_to_database() function.
3635 public function testSaveMediaToDatabase()
3637 $this->markTestIncomplete();
3641 * Test the post_photo_item() function.
3645 public function testPostPhotoItem()
3647 $this->markTestIncomplete();
3651 * Test the prepare_photo_data() function.
3655 public function testPreparePhotoData()
3657 $this->markTestIncomplete();
3661 * Test the api_friendica_remoteauth() function.
3664 * @expectedException Friendica\Network\HTTPException\BadRequestException
3666 public function testApiFriendicaRemoteauth()
3668 api_friendica_remoteauth();
3672 * Test the api_friendica_remoteauth() function with an URL.
3675 * @expectedException Friendica\Network\HTTPException\BadRequestException
3677 public function testApiFriendicaRemoteauthWithUrl()
3679 $_GET['url'] = 'url';
3680 $_GET['c_url'] = 'url';
3681 api_friendica_remoteauth();
3685 * Test the api_friendica_remoteauth() function with a correct URL.
3689 public function testApiFriendicaRemoteauthWithCorrectUrl()
3691 $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
3692 $_GET['url'] = 'url';
3693 $_GET['c_url'] = $this->selfUser['nurl'];
3694 api_friendica_remoteauth();
3698 * Test the api_share_as_retweet() function.
3702 public function testApiShareAsRetweet()
3704 $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
3705 $result = api_share_as_retweet($item);
3706 $this->assertFalse($result);
3710 * Test the api_share_as_retweet() function with a valid item.
3714 public function testApiShareAsRetweetWithValidItem()
3716 $this->markTestIncomplete();
3720 * Test the api_get_nick() function.
3724 public function testApiGetNick()
3726 $result = api_get_nick($this->otherUser['nurl']);
3727 $this->assertEquals('othercontact', $result);
3731 * Test the api_get_nick() function with a wrong URL.
3735 public function testApiGetNickWithWrongUrl()
3737 $result = api_get_nick('wrong_url');
3738 $this->assertFalse($result);
3742 * Test the api_in_reply_to() function.
3746 public function testApiInReplyTo()
3748 $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
3749 $this->assertArrayHasKey('status_id', $result);
3750 $this->assertArrayHasKey('user_id', $result);
3751 $this->assertArrayHasKey('status_id_str', $result);
3752 $this->assertArrayHasKey('user_id_str', $result);
3753 $this->assertArrayHasKey('screen_name', $result);
3757 * Test the api_in_reply_to() function with a valid item.
3761 public function testApiInReplyToWithValidItem()
3763 $this->markTestIncomplete();
3767 * Test the api_clean_plain_items() function.
3771 public function testApiCleanPlainItems()
3773 $_REQUEST['include_entities'] = 'true';
3774 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3775 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3779 * Test the api_best_nickname() function.
3783 public function testApiBestNickname()
3786 $result = api_best_nickname($contacts);
3787 $this->assertNull($result);
3791 * Test the api_best_nickname() function with contacts.
3795 public function testApiBestNicknameWithContacts()
3797 $this->markTestIncomplete();
3801 * Test the api_friendica_group_show() function.
3805 public function testApiFriendicaGroupShow()
3807 $this->markTestIncomplete();
3811 * Test the api_friendica_group_delete() function.
3815 public function testApiFriendicaGroupDelete()
3817 $this->markTestIncomplete();
3821 * Test the api_lists_destroy() function.
3825 public function testApiListsDestroy()
3827 $this->markTestIncomplete();
3831 * Test the group_create() function.
3835 public function testGroupCreate()
3837 $this->markTestIncomplete();
3841 * Test the api_friendica_group_create() function.
3845 public function testApiFriendicaGroupCreate()
3847 $this->markTestIncomplete();
3851 * Test the api_lists_create() function.
3855 public function testApiListsCreate()
3857 $this->markTestIncomplete();
3861 * Test the api_friendica_group_update() function.
3865 public function testApiFriendicaGroupUpdate()
3867 $this->markTestIncomplete();
3871 * Test the api_lists_update() function.
3875 public function testApiListsUpdate()
3877 $this->markTestIncomplete();
3881 * Test the api_friendica_activity() function.
3885 public function testApiFriendicaActivity()
3887 $this->markTestIncomplete();
3891 * Test the api_friendica_notification() function.
3894 * @expectedException Friendica\Network\HTTPException\BadRequestException
3896 public function testApiFriendicaNotification()
3898 api_friendica_notification('json');
3902 * Test the api_friendica_notification() function without an authenticated user.
3905 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3907 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3909 $_SESSION['authenticated'] = false;
3910 api_friendica_notification('json');
3914 * Test the api_friendica_notification() function with an argument count.
3918 public function testApiFriendicaNotificationWithArgumentCount()
3920 $this->app->argv = ['api', 'friendica', 'notification'];
3921 $this->app->argc = count($this->app->argv);
3922 $result = api_friendica_notification('json');
3923 $this->assertEquals(['note' => false], $result);
3927 * Test the api_friendica_notification() function with an XML result.
3931 public function testApiFriendicaNotificationWithXmlResult()
3933 $this->app->argv = ['api', 'friendica', 'notification'];
3934 $this->app->argc = count($this->app->argv);
3935 $result = api_friendica_notification('xml');
3936 $this->assertXml($result, 'notes');
3940 * Test the api_friendica_notification_seen() function.
3944 public function testApiFriendicaNotificationSeen()
3946 $this->markTestIncomplete();
3950 * Test the api_friendica_direct_messages_setseen() function.
3954 public function testApiFriendicaDirectMessagesSetseen()
3956 $this->markTestIncomplete();
3960 * Test the api_friendica_direct_messages_search() function.
3964 public function testApiFriendicaDirectMessagesSearch()
3966 $this->markTestIncomplete();
3970 * Test the api_friendica_profile_show() function.
3974 public function testApiFriendicaProfileShow()
3976 $result = api_friendica_profile_show('json');
3977 // We can't use assertSelfUser() here because the user object is missing some properties.
3978 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3979 $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
3980 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3981 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3982 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3983 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3984 $this->assertFalse($result['$result']['multi_profiles']);
3988 * Test the api_friendica_profile_show() function with a profile ID.
3992 public function testApiFriendicaProfileShowWithProfileId()
3994 $this->markTestIncomplete('We need to add a dataset for this.');
3998 * Test the api_friendica_profile_show() function with a wrong profile ID.
4001 * @expectedException Friendica\Network\HTTPException\BadRequestException
4003 public function testApiFriendicaProfileShowWithWrongProfileId()
4005 $_REQUEST['profile_id'] = 666;
4006 api_friendica_profile_show('json');
4010 * Test the api_friendica_profile_show() function without an authenticated user.
4013 * @expectedException Friendica\Network\HTTPException\ForbiddenException
4015 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
4017 $_SESSION['authenticated'] = false;
4018 api_friendica_profile_show('json');
4022 * Test the api_saved_searches_list() function.
4026 public function testApiSavedSearchesList()
4028 $result = api_saved_searches_list('json');
4029 $this->assertEquals(1, $result['terms'][0]['id']);
4030 $this->assertEquals(1, $result['terms'][0]['id_str']);
4031 $this->assertEquals('Saved search', $result['terms'][0]['name']);
4032 $this->assertEquals('Saved search', $result['terms'][0]['query']);