6 namespace Friendica\Test;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Network\BadRequestException;
12 use Friendica\Network\HTTPException;
13 use Friendica\Render\FriendicaSmarty;
16 * Tests for the API functions.
18 * Functions that use header() need to be tested in a separate process.
19 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
21 class ApiTest extends DatabaseTest
25 * Create variables used by tests.
27 protected function setUp()
32 // User data that the test database is populated with
35 'name' => 'Self contact',
36 'nick' => 'selfcontact',
37 'nurl' => 'http://localhost/profile/selfcontact'
41 'name' => 'othercontact',
42 'nick' => 'othercontact',
43 'nurl' => 'http://localhost/profile/othercontact'
46 // User ID that we know is not in the database
47 $this->wrongUserId = 666;
49 // Most API require login so we force the session
52 'authenticated' => true,
53 'uid' => $this->selfUser['id']
56 // Reusable App object
57 $this->app = new App(__DIR__.'/../');
61 Config::set('config', 'hostname', 'localhost');
62 Config::set('system', 'throttle_limit_day', 100);
63 Config::set('system', 'throttle_limit_week', 100);
64 Config::set('system', 'throttle_limit_month', 100);
65 Config::set('system', 'theme', 'system_theme');
69 * Assert that an user array contains expected keys.
70 * @param array $user User array
73 private function assertSelfUser(array $user)
75 $this->assertEquals($this->selfUser['id'], $user['uid']);
76 $this->assertEquals($this->selfUser['id'], $user['cid']);
77 $this->assertEquals(1, $user['self']);
78 $this->assertEquals('Friendica', $user['location']);
79 $this->assertEquals($this->selfUser['name'], $user['name']);
80 $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
81 $this->assertEquals('dfrn', $user['network']);
82 $this->assertTrue($user['verified']);
86 * Assert that an user array contains expected keys.
87 * @param array $user User array
90 private function assertOtherUser(array $user)
92 $this->assertEquals($this->otherUser['id'], $user['id']);
93 $this->assertEquals($this->otherUser['id'], $user['id_str']);
94 $this->assertEquals(0, $user['self']);
95 $this->assertEquals($this->otherUser['name'], $user['name']);
96 $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
97 $this->assertFalse($user['verified']);
101 * Assert that a status array contains expected keys.
102 * @param array $status Status array
105 private function assertStatus(array $status)
107 $this->assertInternalType('string', $status['text']);
108 $this->assertInternalType('int', $status['id']);
109 // We could probably do more checks here.
113 * Assert that a list array contains expected keys.
114 * @param array $list List array
117 private function assertList(array $list)
119 $this->assertInternalType('string', $list['name']);
120 $this->assertInternalType('int', $list['id']);
121 $this->assertInternalType('string', $list['id_str']);
122 $this->assertContains($list['mode'], ['public', 'private']);
123 // We could probably do more checks here.
127 * Assert that the string is XML and contain the root element.
128 * @param string $result XML string
129 * @param string $root_element Root element name
132 private function assertXml($result, $root_element)
134 $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
135 $this->assertContains('<'.$root_element, $result);
136 // We could probably do more checks here.
140 * Get the path to a temporary empty PNG image.
141 * @return string Path
143 private function getTempImage()
145 $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
149 // Empty 1x1 px PNG image
150 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
158 * Test the api_user() function.
161 public function testApiUser()
163 $this->assertEquals($this->selfUser['id'], api_user());
167 * Test the api_user() function with an unallowed user.
170 public function testApiUserWithUnallowedUser()
172 $_SESSION = ['allow_api' => false];
173 $this->assertEquals(false, api_user());
177 * Test the api_source() function.
180 public function testApiSource()
182 $this->assertEquals('api', api_source());
186 * Test the api_source() function with a Twidere user agent.
189 public function testApiSourceWithTwidere()
191 $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
192 $this->assertEquals('Twidere', api_source());
196 * Test the api_source() function with a GET parameter.
199 public function testApiSourceWithGet()
201 $_GET['source'] = 'source_name';
202 $this->assertEquals('source_name', api_source());
206 * Test the api_date() function.
209 public function testApiDate()
211 $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
215 * Test the api_register_func() function.
218 public function testApiRegisterFunc()
230 $this->assertTrue($API['api_path']['auth']);
231 $this->assertEquals('method', $API['api_path']['method']);
232 $this->assertTrue(is_callable($API['api_path']['func']));
236 * Test the api_login() function without any login.
238 * @runInSeparateProcess
239 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
241 public function testApiLoginWithoutLogin()
243 api_login($this->app);
247 * Test the api_login() function with a bad login.
249 * @runInSeparateProcess
250 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
252 public function testApiLoginWithBadLogin()
254 $_SERVER['PHP_AUTH_USER'] = 'user@server';
255 api_login($this->app);
259 * Test the api_login() function with oAuth.
262 public function testApiLoginWithOauth()
264 $this->markTestIncomplete('Can we test this easily?');
268 * Test the api_login() function with authentication provided by an addon.
271 public function testApiLoginWithAddonAuth()
273 $this->markTestIncomplete('Can we test this easily?');
277 * Test the api_login() function with a correct login.
279 * @runInSeparateProcess
281 public function testApiLoginWithCorrectLogin()
283 $_SERVER['PHP_AUTH_USER'] = 'Test user';
284 $_SERVER['PHP_AUTH_PW'] = 'password';
285 api_login($this->app);
289 * Test the api_login() function with a remote user.
291 * @runInSeparateProcess
292 * @expectedException Friendica\Network\HTTPException\UnauthorizedException
294 public function testApiLoginWithRemoteUser()
296 $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
297 api_login($this->app);
301 * Test the api_check_method() function.
304 public function testApiCheckMethod()
306 $this->assertFalse(api_check_method('method'));
310 * Test the api_check_method() function with a correct method.
313 public function testApiCheckMethodWithCorrectMethod()
315 $_SERVER['REQUEST_METHOD'] = 'method';
316 $this->assertTrue(api_check_method('method'));
320 * Test the api_check_method() function with a wildcard.
323 public function testApiCheckMethodWithWildcard()
325 $this->assertTrue(api_check_method('*'));
329 * Test the api_call() function.
331 * @runInSeparateProcess
333 public function testApiCall()
337 'method' => 'method',
338 'func' => function () {
339 return ['data' => ['some_data']];
342 $_SERVER['REQUEST_METHOD'] = 'method';
343 $_GET['callback'] = 'callback_name';
345 $this->app->query_string = 'api_path';
347 'callback_name(["some_data"])',
353 * Test the api_call() function with the profiled enabled.
355 * @runInSeparateProcess
357 public function testApiCallWithProfiler()
361 'method' => 'method',
362 'func' => function () {
363 return ['data' => ['some_data']];
366 $_SERVER['REQUEST_METHOD'] = 'method';
367 Config::set('system', 'profiler', true);
368 Config::set('rendertime', 'callstack', true);
369 $this->app->callstack = [
370 'database' => ['some_function' => 200],
371 'database_write' => ['some_function' => 200],
372 'cache' => ['some_function' => 200],
373 'cache_write' => ['some_function' => 200],
374 'network' => ['some_function' => 200]
377 $this->app->query_string = 'api_path';
385 * Test the api_call() function without any result.
387 * @runInSeparateProcess
389 public function testApiCallWithNoResult()
393 'method' => 'method',
394 'func' => function () {
398 $_SERVER['REQUEST_METHOD'] = 'method';
400 $this->app->query_string = 'api_path';
402 '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
408 * Test the api_call() function with an unimplemented API.
410 * @runInSeparateProcess
412 public function testApiCallWithUninplementedApi()
415 '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
421 * Test the api_call() function with a JSON result.
423 * @runInSeparateProcess
425 public function testApiCallWithJson()
429 'method' => 'method',
430 'func' => function () {
431 return ['data' => ['some_data']];
434 $_SERVER['REQUEST_METHOD'] = 'method';
436 $this->app->query_string = 'api_path.json';
444 * Test the api_call() function with an XML result.
446 * @runInSeparateProcess
448 public function testApiCallWithXml()
452 'method' => 'method',
453 'func' => function () {
457 $_SERVER['REQUEST_METHOD'] = 'method';
459 $this->app->query_string = 'api_path.xml';
467 * Test the api_call() function with an RSS result.
469 * @runInSeparateProcess
471 public function testApiCallWithRss()
475 'method' => 'method',
476 'func' => function () {
480 $_SERVER['REQUEST_METHOD'] = 'method';
482 $this->app->query_string = 'api_path.rss';
484 '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL.
491 * Test the api_call() function with an Atom result.
493 * @runInSeparateProcess
495 public function testApiCallWithAtom()
499 'method' => 'method',
500 'func' => function () {
504 $_SERVER['REQUEST_METHOD'] = 'method';
506 $this->app->query_string = 'api_path.atom';
508 '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL.
515 * Test the api_call() function with an unallowed method.
517 * @runInSeparateProcess
519 public function testApiCallWithWrongMethod()
522 $API['api_path'] = ['method' => 'method'];
524 $this->app->query_string = 'api_path';
526 '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
532 * Test the api_call() function with an unauthorized user.
534 * @runInSeparateProcess
536 public function testApiCallWithWrongAuth()
540 'method' => 'method',
543 $_SERVER['REQUEST_METHOD'] = 'method';
544 $_SESSION['authenticated'] = false;
546 $this->app->query_string = 'api_path';
548 '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
554 * Test the api_error() function with a JSON result.
556 * @runInSeparateProcess
558 public function testApiErrorWithJson()
561 '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
562 api_error('json', new HTTPException('error_message'))
567 * Test the api_error() function with an XML result.
569 * @runInSeparateProcess
571 public function testApiErrorWithXml()
574 '<?xml version="1.0"?>'.PHP_EOL.
575 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
576 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
577 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
578 ' <error>error_message</error>'.PHP_EOL.
579 ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
580 ' <request/>'.PHP_EOL.
582 api_error('xml', new HTTPException('error_message'))
587 * Test the api_error() function with an RSS result.
589 * @runInSeparateProcess
591 public function testApiErrorWithRss()
594 '<?xml version="1.0"?>'.PHP_EOL.
595 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
596 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
597 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
598 ' <error>error_message</error>'.PHP_EOL.
599 ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
600 ' <request/>'.PHP_EOL.
602 api_error('rss', new HTTPException('error_message'))
607 * Test the api_error() function with an Atom result.
609 * @runInSeparateProcess
611 public function testApiErrorWithAtom()
614 '<?xml version="1.0"?>'.PHP_EOL.
615 '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
616 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
617 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
618 ' <error>error_message</error>'.PHP_EOL.
619 ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
620 ' <request/>'.PHP_EOL.
622 api_error('atom', new HTTPException('error_message'))
627 * Test the api_rss_extra() function.
630 public function testApiRssExtra()
632 $user_info = ['url' => 'user_url', 'language' => 'en'];
633 $result = api_rss_extra($this->app, [], $user_info);
634 $this->assertEquals($user_info, $result['$user']);
635 $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
636 $this->assertArrayHasKey('self', $result['$rss']);
637 $this->assertArrayHasKey('base', $result['$rss']);
638 $this->assertArrayHasKey('updated', $result['$rss']);
639 $this->assertArrayHasKey('atom_updated', $result['$rss']);
640 $this->assertArrayHasKey('language', $result['$rss']);
641 $this->assertArrayHasKey('logo', $result['$rss']);
645 * Test the api_rss_extra() function without any user info.
647 * @runInSeparateProcess
649 public function testApiRssExtraWithoutUserInfo()
651 $result = api_rss_extra($this->app, [], null);
652 $this->assertInternalType('array', $result['$user']);
653 $this->assertArrayHasKey('alternate', $result['$rss']);
654 $this->assertArrayHasKey('self', $result['$rss']);
655 $this->assertArrayHasKey('base', $result['$rss']);
656 $this->assertArrayHasKey('updated', $result['$rss']);
657 $this->assertArrayHasKey('atom_updated', $result['$rss']);
658 $this->assertArrayHasKey('language', $result['$rss']);
659 $this->assertArrayHasKey('logo', $result['$rss']);
663 * Test the api_unique_id_to_nurl() function.
666 public function testApiUniqueIdToNurl()
668 $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
672 * Test the api_unique_id_to_nurl() function with a correct ID.
675 public function testApiUniqueIdToNurlWithCorrectId()
677 $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
681 * Test the api_get_user() function.
683 * @runInSeparateProcess
685 public function testApiGetUser()
687 $user = api_get_user($this->app);
688 $this->assertSelfUser($user);
689 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
690 $this->assertEquals('6fdbe8', $user['profile_link_color']);
691 $this->assertEquals('ededed', $user['profile_background_color']);
695 * Test the api_get_user() function with a Frio schema.
697 * @runInSeparateProcess
699 public function testApiGetUserWithFrioSchema()
701 PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
702 $user = api_get_user($this->app);
703 $this->assertSelfUser($user);
704 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
705 $this->assertEquals('6fdbe8', $user['profile_link_color']);
706 $this->assertEquals('ededed', $user['profile_background_color']);
710 * Test the api_get_user() function with a custom Frio schema.
712 * @runInSeparateProcess
714 public function testApiGetUserWithCustomFrioSchema()
716 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
717 PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
718 PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
719 PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
720 $user = api_get_user($this->app);
721 $this->assertSelfUser($user);
722 $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
723 $this->assertEquals('123456', $user['profile_link_color']);
724 $this->assertEquals('123456', $user['profile_background_color']);
728 * Test the api_get_user() function with an empty Frio schema.
730 * @runInSeparateProcess
732 public function testApiGetUserWithEmptyFrioSchema()
734 PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
735 $user = api_get_user($this->app);
736 $this->assertSelfUser($user);
737 $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
738 $this->assertEquals('6fdbe8', $user['profile_link_color']);
739 $this->assertEquals('ededed', $user['profile_background_color']);
743 * Test the api_get_user() function with an user that is not allowed to use the API.
745 * @runInSeparateProcess
747 public function testApiGetUserWithoutApiUser()
749 $_SERVER['PHP_AUTH_USER'] = 'Test user';
750 $_SERVER['PHP_AUTH_PW'] = 'password';
751 $_SESSION['allow_api'] = false;
752 $this->assertFalse(api_get_user($this->app));
756 * Test the api_get_user() function with an user ID in a GET parameter.
758 * @runInSeparateProcess
760 public function testApiGetUserWithGetId()
762 $_GET['user_id'] = $this->otherUser['id'];
763 $this->assertOtherUser(api_get_user($this->app));
767 * Test the api_get_user() function with a wrong user ID in a GET parameter.
769 * @runInSeparateProcess
770 * @expectedException Friendica\Network\HTTPException\BadRequestException
772 public function testApiGetUserWithWrongGetId()
774 $_GET['user_id'] = $this->wrongUserId;
775 $this->assertOtherUser(api_get_user($this->app));
779 * Test the api_get_user() function with an user name in a GET parameter.
781 * @runInSeparateProcess
783 public function testApiGetUserWithGetName()
785 $_GET['screen_name'] = $this->selfUser['nick'];
786 $this->assertSelfUser(api_get_user($this->app));
790 * Test the api_get_user() function with a profile URL in a GET parameter.
792 * @runInSeparateProcess
794 public function testApiGetUserWithGetUrl()
796 $_GET['profileurl'] = $this->selfUser['nurl'];
797 $this->assertSelfUser(api_get_user($this->app));
801 * Test the api_get_user() function with an user ID in the API path.
803 * @runInSeparateProcess
805 public function testApiGetUserWithNumericCalledApi()
808 $called_api = ['api_path'];
809 $this->app->argv[1] = $this->otherUser['id'].'.json';
810 $this->assertOtherUser(api_get_user($this->app));
814 * Test the api_get_user() function with the $called_api global variable.
816 * @runInSeparateProcess
818 public function testApiGetUserWithCalledApi()
821 $called_api = ['api_path'];
822 $this->assertSelfUser(api_get_user($this->app));
826 * Test the api_get_user() function with a valid user.
828 * @runInSeparateProcess
830 public function testApiGetUserWithCorrectUser()
832 $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
836 * Test the api_get_user() function with a wrong user ID.
838 * @runInSeparateProcess
839 * @expectedException Friendica\Network\HTTPException\BadRequestException
841 public function testApiGetUserWithWrongUser()
843 $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
847 * Test the api_get_user() function with a 0 user ID.
849 * @runInSeparateProcess
851 public function testApiGetUserWithZeroUser()
853 $this->assertSelfUser(api_get_user($this->app, 0));
858 * Test the api_item_get_user() function.
860 * @runInSeparateProcess
862 public function testApiItemGetUser()
864 $users = api_item_get_user($this->app, []);
865 $this->assertSelfUser($users[0]);
869 * Test the api_item_get_user() function with a different item parent.
872 public function testApiItemGetUserWithDifferentParent()
874 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
875 $this->assertSelfUser($users[0]);
876 $this->assertEquals($users[0], $users[1]);
880 * Test the api_walk_recursive() function.
883 public function testApiWalkRecursive()
891 // Should we test this with a callback that actually does something?
899 * Test the api_walk_recursive() function with an array.
902 public function testApiWalkRecursiveWithArray()
904 $array = [['item1'], ['item2']];
910 // Should we test this with a callback that actually does something?
918 * Test the api_reformat_xml() function.
921 public function testApiReformatXml()
925 $this->assertTrue(api_reformat_xml($item, $key));
926 $this->assertEquals('true', $item);
930 * Test the api_reformat_xml() function with a statusnet_api key.
933 public function testApiReformatXmlWithStatusnetKey()
936 $key = 'statusnet_api';
937 $this->assertTrue(api_reformat_xml($item, $key));
938 $this->assertEquals('statusnet:api', $key);
942 * Test the api_reformat_xml() function with a friendica_api key.
945 public function testApiReformatXmlWithFriendicaKey()
948 $key = 'friendica_api';
949 $this->assertTrue(api_reformat_xml($item, $key));
950 $this->assertEquals('friendica:api', $key);
954 * Test the api_create_xml() function.
957 public function testApiCreateXml()
960 '<?xml version="1.0"?>'.PHP_EOL.
961 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
962 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
963 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
964 ' <data>some_data</data>'.PHP_EOL.
965 '</root_element>'.PHP_EOL,
966 api_create_xml(['data' => ['some_data']], 'root_element')
971 * Test the api_create_xml() function without any XML namespace.
974 public function testApiCreateXmlWithoutNamespaces()
977 '<?xml version="1.0"?>'.PHP_EOL.
979 ' <data>some_data</data>'.PHP_EOL.
981 api_create_xml(['data' => ['some_data']], 'ok')
986 * Test the api_format_data() function.
989 public function testApiFormatData()
991 $data = ['some_data'];
992 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
996 * Test the api_format_data() function with an XML result.
999 public function testApiFormatDataWithXml()
1001 $this->assertEquals(
1002 '<?xml version="1.0"?>'.PHP_EOL.
1003 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1004 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1005 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
1006 ' <data>some_data</data>'.PHP_EOL.
1007 '</root_element>'.PHP_EOL,
1008 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1013 * Test the api_account_verify_credentials() function.
1016 public function testApiAccountVerifyCredentials()
1018 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1022 * Test the api_account_verify_credentials() function without an authenticated user.
1024 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1026 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1028 $_SESSION['authenticated'] = false;
1029 api_account_verify_credentials('json');
1033 * Test the requestdata() function.
1036 public function testRequestdata()
1038 $this->assertNull(requestdata('variable_name'));
1042 * Test the requestdata() function with a POST parameter.
1045 public function testRequestdataWithPost()
1047 $_POST['variable_name'] = 'variable_value';
1048 $this->assertEquals('variable_value', requestdata('variable_name'));
1052 * Test the requestdata() function with a GET parameter.
1055 public function testRequestdataWithGet()
1057 $_GET['variable_name'] = 'variable_value';
1058 $this->assertEquals('variable_value', requestdata('variable_name'));
1062 * Test the api_statuses_mediap() function.
1065 public function testApiStatusesMediap()
1067 $this->app->argc = 2;
1075 'tmp_name' => $this->getTempImage(),
1076 'name' => 'spacer.png',
1077 'type' => 'image/png'
1080 $_GET['status'] = '<b>Status content</b>';
1082 $result = api_statuses_mediap('json');
1083 $this->assertStatus($result['status']);
1087 * Test the api_statuses_mediap() function without an authenticated user.
1089 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1091 public function testApiStatusesMediapWithoutAuthenticatedUser()
1093 $_SESSION['authenticated'] = false;
1094 api_statuses_mediap('json');
1098 * Test the api_statuses_update() function.
1101 public function testApiStatusesUpdate()
1103 $_GET['status'] = 'Status content';
1104 $_GET['in_reply_to_status_id'] = -1;
1113 'tmp_name' => $this->getTempImage(),
1114 'type' => 'image/png'
1118 $result = api_statuses_update('json');
1119 $this->assertStatus($result['status']);
1123 * Test the api_statuses_update() function with an HTML status.
1126 public function testApiStatusesUpdateWithHtml()
1128 $_GET['htmlstatus'] = '<b>Status content</b>';
1130 $result = api_statuses_update('json');
1131 $this->assertStatus($result['status']);
1135 * Test the api_statuses_update() function without an authenticated user.
1137 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1139 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1141 $_SESSION['authenticated'] = false;
1142 api_statuses_update('json');
1146 * Test the api_statuses_update() function with a parent status.
1149 public function testApiStatusesUpdateWithParent()
1151 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1155 * Test the api_statuses_update() function with a media_ids parameter.
1158 public function testApiStatusesUpdateWithMediaIds()
1160 $this->markTestIncomplete();
1164 * Test the api_statuses_update() function with the throttle limit reached.
1167 public function testApiStatusesUpdateWithDayThrottleReached()
1169 $this->markTestIncomplete();
1173 * Test the api_media_upload() function.
1175 * @expectedException Friendica\Network\HTTPException\BadRequestException
1177 public function testApiMediaUpload()
1183 * Test the api_media_upload() function without an authenticated user.
1185 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1187 public function testApiMediaUploadWithoutAuthenticatedUser()
1189 $_SESSION['authenticated'] = false;
1194 * Test the api_media_upload() function with an invalid uploaded media.
1196 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1198 public function testApiMediaUploadWithMedia()
1209 * Test the api_media_upload() function with an valid uploaded media.
1212 public function testApiMediaUploadWithValidMedia()
1220 'tmp_name' => $this->getTempImage(),
1221 'type' => 'image/png'
1227 $result = api_media_upload();
1228 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1229 $this->assertEquals(1, $result['media']['image']['w']);
1230 $this->assertEquals(1, $result['media']['image']['h']);
1234 * Test the api_status_show() function.
1237 public function testApiStatusShow()
1239 $result = api_status_show('json');
1240 $this->assertStatus($result['status']);
1244 * Test the api_status_show() function with an XML result.
1247 public function testApiStatusShowWithXml()
1249 $result = api_status_show('xml');
1250 $this->assertXml($result, 'statuses');
1254 * Test the api_status_show() function with a raw result.
1257 public function testApiStatusShowWithRaw()
1259 $this->assertStatus(api_status_show('raw'));
1263 * Test the api_users_show() function.
1266 public function testApiUsersShow()
1268 $result = api_users_show('json');
1269 // We can't use assertSelfUser() here because the user object is missing some properties.
1270 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1271 $this->assertEquals('Friendica', $result['user']['location']);
1272 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1273 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1274 $this->assertEquals('dfrn', $result['user']['network']);
1275 $this->assertTrue($result['user']['verified']);
1279 * Test the api_users_show() function with an XML result.
1282 public function testApiUsersShowWithXml()
1284 $result = api_users_show('xml');
1285 $this->assertXml($result, 'statuses');
1289 * Test the api_users_search() function.
1292 public function testApiUsersSearch()
1294 $_GET['q'] = 'othercontact';
1295 $result = api_users_search('json');
1296 $this->assertOtherUser($result['users'][0]);
1300 * Test the api_users_search() function with an XML result.
1303 public function testApiUsersSearchWithXml()
1305 $_GET['q'] = 'othercontact';
1306 $result = api_users_search('xml');
1307 $this->assertXml($result, 'users');
1311 * Test the api_users_search() function without a GET q parameter.
1313 * @expectedException Friendica\Network\HTTPException\BadRequestException
1315 public function testApiUsersSearchWithoutQuery()
1317 api_users_search('json');
1321 * Test the api_users_lookup() function.
1323 * @expectedException Friendica\Network\HTTPException\NotFoundException
1325 public function testApiUsersLookup()
1327 api_users_lookup('json');
1331 * Test the api_users_lookup() function with an user ID.
1334 public function testApiUsersLookupWithUserId()
1336 $_REQUEST['user_id'] = $this->otherUser['id'];
1337 $result = api_users_lookup('json');
1338 $this->assertOtherUser($result['users'][0]);
1342 * Test the api_search() function.
1345 public function testApiSearch()
1347 $_REQUEST['q'] = 'reply';
1348 $_REQUEST['max_id'] = 10;
1349 $result = api_search('json');
1350 foreach ($result['status'] as $status) {
1351 $this->assertStatus($status);
1352 $this->assertContains('reply', $status['text'], null, true);
1357 * Test the api_search() function a count parameter.
1360 public function testApiSearchWithCount()
1362 $_REQUEST['q'] = 'reply';
1363 $_REQUEST['count'] = 20;
1364 $result = api_search('json');
1365 foreach ($result['status'] as $status) {
1366 $this->assertStatus($status);
1367 $this->assertContains('reply', $status['text'], null, true);
1372 * Test the api_search() function with an rpp parameter.
1375 public function testApiSearchWithRpp()
1377 $_REQUEST['q'] = 'reply';
1378 $_REQUEST['rpp'] = 20;
1379 $result = api_search('json');
1380 foreach ($result['status'] as $status) {
1381 $this->assertStatus($status);
1382 $this->assertContains('reply', $status['text'], null, true);
1388 * Test the api_search() function without an authenticated user.
1390 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1392 public function testApiSearchWithUnallowedUser()
1394 $_SESSION['allow_api'] = false;
1395 $_GET['screen_name'] = $this->selfUser['nick'];
1400 * Test the api_search() function without any GET query parameter.
1402 * @expectedException Friendica\Network\HTTPException\BadRequestException
1404 public function testApiSearchWithoutQuery()
1410 * Test the api_statuses_home_timeline() function.
1413 public function testApiStatusesHomeTimeline()
1415 $_REQUEST['max_id'] = 10;
1416 $_REQUEST['exclude_replies'] = true;
1417 $_REQUEST['conversation_id'] = 1;
1418 $result = api_statuses_home_timeline('json');
1419 $this->assertNotEmpty($result['status']);
1420 foreach ($result['status'] as $status) {
1421 $this->assertStatus($status);
1426 * Test the api_statuses_home_timeline() function with a negative page parameter.
1429 public function testApiStatusesHomeTimelineWithNegativePage()
1431 $_REQUEST['page'] = -2;
1432 $result = api_statuses_home_timeline('json');
1433 $this->assertNotEmpty($result['status']);
1434 foreach ($result['status'] as $status) {
1435 $this->assertStatus($status);
1440 * Test the api_statuses_home_timeline() with an unallowed user.
1442 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1444 public function testApiStatusesHomeTimelineWithUnallowedUser()
1446 $_SESSION['allow_api'] = false;
1447 $_GET['screen_name'] = $this->selfUser['nick'];
1448 api_statuses_home_timeline('json');
1452 * Test the api_statuses_home_timeline() function with an RSS result.
1455 public function testApiStatusesHomeTimelineWithRss()
1457 $result = api_statuses_home_timeline('rss');
1458 $this->assertXml($result, 'statuses');
1462 * Test the api_statuses_public_timeline() function.
1465 public function testApiStatusesPublicTimeline()
1467 $_REQUEST['max_id'] = 10;
1468 $_REQUEST['conversation_id'] = 1;
1469 $result = api_statuses_public_timeline('json');
1470 $this->assertNotEmpty($result['status']);
1471 foreach ($result['status'] as $status) {
1472 $this->assertStatus($status);
1477 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1480 public function testApiStatusesPublicTimelineWithExcludeReplies()
1482 $_REQUEST['max_id'] = 10;
1483 $_REQUEST['exclude_replies'] = true;
1484 $result = api_statuses_public_timeline('json');
1485 $this->assertNotEmpty($result['status']);
1486 foreach ($result['status'] as $status) {
1487 $this->assertStatus($status);
1492 * Test the api_statuses_public_timeline() function with a negative page parameter.
1495 public function testApiStatusesPublicTimelineWithNegativePage()
1497 $_REQUEST['page'] = -2;
1498 $result = api_statuses_public_timeline('json');
1499 $this->assertNotEmpty($result['status']);
1500 foreach ($result['status'] as $status) {
1501 $this->assertStatus($status);
1506 * Test the api_statuses_public_timeline() function with an unallowed user.
1508 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1510 public function testApiStatusesPublicTimelineWithUnallowedUser()
1512 $_SESSION['allow_api'] = false;
1513 $_GET['screen_name'] = $this->selfUser['nick'];
1514 api_statuses_public_timeline('json');
1518 * Test the api_statuses_public_timeline() function with an RSS result.
1521 public function testApiStatusesPublicTimelineWithRss()
1523 $result = api_statuses_public_timeline('rss');
1524 $this->assertXml($result, 'statuses');
1528 * Test the api_statuses_networkpublic_timeline() function.
1531 public function testApiStatusesNetworkpublicTimeline()
1533 $_REQUEST['max_id'] = 10;
1534 $result = api_statuses_networkpublic_timeline('json');
1535 $this->assertNotEmpty($result['status']);
1536 foreach ($result['status'] as $status) {
1537 $this->assertStatus($status);
1542 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1545 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1547 $_REQUEST['page'] = -2;
1548 $result = api_statuses_networkpublic_timeline('json');
1549 $this->assertNotEmpty($result['status']);
1550 foreach ($result['status'] as $status) {
1551 $this->assertStatus($status);
1556 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1558 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1560 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1562 $_SESSION['allow_api'] = false;
1563 $_GET['screen_name'] = $this->selfUser['nick'];
1564 api_statuses_networkpublic_timeline('json');
1568 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1571 public function testApiStatusesNetworkpublicTimelineWithRss()
1573 $result = api_statuses_networkpublic_timeline('rss');
1574 $this->assertXml($result, 'statuses');
1578 * Test the api_statuses_show() function.
1580 * @expectedException Friendica\Network\HTTPException\BadRequestException
1582 public function testApiStatusesShow()
1584 api_statuses_show('json');
1588 * Test the api_statuses_show() function with an ID.
1591 public function testApiStatusesShowWithId()
1593 $this->app->argv[3] = 1;
1594 $result = api_statuses_show('json');
1595 $this->assertStatus($result['status']);
1599 * Test the api_statuses_show() function with the conversation parameter.
1602 public function testApiStatusesShowWithConversation()
1604 $this->app->argv[3] = 1;
1605 $_REQUEST['conversation'] = 1;
1606 $result = api_statuses_show('json');
1607 $this->assertNotEmpty($result['status']);
1608 foreach ($result['status'] as $status) {
1609 $this->assertStatus($status);
1614 * Test the api_statuses_show() function with an unallowed user.
1616 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1618 public function testApiStatusesShowWithUnallowedUser()
1620 $_SESSION['allow_api'] = false;
1621 $_GET['screen_name'] = $this->selfUser['nick'];
1622 api_statuses_show('json');
1626 * Test the api_conversation_show() function.
1628 * @expectedException Friendica\Network\HTTPException\BadRequestException
1630 public function testApiConversationShow()
1632 api_conversation_show('json');
1636 * Test the api_conversation_show() function with an ID.
1639 public function testApiConversationShowWithId()
1641 $this->app->argv[3] = 1;
1642 $_REQUEST['max_id'] = 10;
1643 $_REQUEST['page'] = -2;
1644 $result = api_conversation_show('json');
1645 $this->assertNotEmpty($result['status']);
1646 foreach ($result['status'] as $status) {
1647 $this->assertStatus($status);
1652 * Test the api_conversation_show() function with an unallowed user.
1654 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1656 public function testApiConversationShowWithUnallowedUser()
1658 $_SESSION['allow_api'] = false;
1659 $_GET['screen_name'] = $this->selfUser['nick'];
1660 api_conversation_show('json');
1664 * Test the api_statuses_repeat() function.
1666 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1668 public function testApiStatusesRepeat()
1670 api_statuses_repeat('json');
1674 * Test the api_statuses_repeat() function without an authenticated user.
1676 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1678 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1680 $_SESSION['authenticated'] = false;
1681 api_statuses_repeat('json');
1685 * Test the api_statuses_repeat() function with an ID.
1688 public function testApiStatusesRepeatWithId()
1690 $this->app->argv[3] = 1;
1691 $result = api_statuses_repeat('json');
1692 $this->assertStatus($result['status']);
1694 // Also test with a shared status
1695 $this->app->argv[3] = 5;
1696 $result = api_statuses_repeat('json');
1697 $this->assertStatus($result['status']);
1701 * Test the api_statuses_destroy() function.
1703 * @expectedException Friendica\Network\HTTPException\BadRequestException
1705 public function testApiStatusesDestroy()
1707 api_statuses_destroy('json');
1711 * Test the api_statuses_destroy() function without an authenticated user.
1713 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1715 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1717 $_SESSION['authenticated'] = false;
1718 api_statuses_destroy('json');
1722 * Test the api_statuses_destroy() function with an ID.
1725 public function testApiStatusesDestroyWithId()
1727 $this->app->argv[3] = 1;
1728 $result = api_statuses_destroy('json');
1729 $this->assertStatus($result['status']);
1733 * Test the api_statuses_mentions() function.
1736 public function testApiStatusesMentions()
1738 $this->app->user = ['nickname' => $this->selfUser['nick']];
1739 $_REQUEST['max_id'] = 10;
1740 $result = api_statuses_mentions('json');
1741 $this->assertEmpty($result['status']);
1742 // We should test with mentions in the database.
1746 * Test the api_statuses_mentions() function with a negative page parameter.
1749 public function testApiStatusesMentionsWithNegativePage()
1751 $_REQUEST['page'] = -2;
1752 $result = api_statuses_mentions('json');
1753 $this->assertEmpty($result['status']);
1757 * Test the api_statuses_mentions() function with an unallowed user.
1759 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1761 public function testApiStatusesMentionsWithUnallowedUser()
1763 $_SESSION['allow_api'] = false;
1764 $_GET['screen_name'] = $this->selfUser['nick'];
1765 api_statuses_mentions('json');
1769 * Test the api_statuses_mentions() function with an RSS result.
1772 public function testApiStatusesMentionsWithRss()
1774 $result = api_statuses_mentions('rss');
1775 $this->assertXml($result, 'statuses');
1779 * Test the api_statuses_user_timeline() function.
1782 public function testApiStatusesUserTimeline()
1784 $_REQUEST['max_id'] = 10;
1785 $_REQUEST['exclude_replies'] = true;
1786 $_REQUEST['conversation_id'] = 1;
1787 $result = api_statuses_user_timeline('json');
1788 $this->assertNotEmpty($result['status']);
1789 foreach ($result['status'] as $status) {
1790 $this->assertStatus($status);
1795 * Test the api_statuses_user_timeline() function with a negative page parameter.
1798 public function testApiStatusesUserTimelineWithNegativePage()
1800 $_REQUEST['page'] = -2;
1801 $result = api_statuses_user_timeline('json');
1802 $this->assertNotEmpty($result['status']);
1803 foreach ($result['status'] as $status) {
1804 $this->assertStatus($status);
1809 * Test the api_statuses_user_timeline() function with an RSS result.
1812 public function testApiStatusesUserTimelineWithRss()
1814 $result = api_statuses_user_timeline('rss');
1815 $this->assertXml($result, 'statuses');
1819 * Test the api_statuses_user_timeline() function with an unallowed user.
1821 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1823 public function testApiStatusesUserTimelineWithUnallowedUser()
1825 $_SESSION['allow_api'] = false;
1826 $_GET['screen_name'] = $this->selfUser['nick'];
1827 api_statuses_user_timeline('json');
1831 * Test the api_favorites_create_destroy() function.
1833 * @expectedException Friendica\Network\HTTPException\BadRequestException
1835 public function testApiFavoritesCreateDestroy()
1837 api_favorites_create_destroy('json');
1841 * Test the api_favorites_create_destroy() function with an invalid ID.
1843 * @expectedException Friendica\Network\HTTPException\BadRequestException
1845 public function testApiFavoritesCreateDestroyWithInvalidId()
1847 // This triggers a very specific condition ($action_argv_id + 2)
1848 $this->app->argv[1] = '1.1';
1849 $this->app->argc = 5;
1850 api_favorites_create_destroy('json');
1854 * Test the api_favorites_create_destroy() function with an invalid action.
1856 * @expectedException Friendica\Network\HTTPException\BadRequestException
1858 public function testApiFavoritesCreateDestroyWithInvalidAction()
1860 $this->app->argv[1] = '1.1';
1861 $this->app->argc = 10;
1862 $_REQUEST['id'] = 1;
1863 api_favorites_create_destroy('json');
1867 * Test the api_favorites_create_destroy() function with the create action.
1870 public function testApiFavoritesCreateDestroyWithCreateAction()
1872 $this->app->argv[1] = '1.1';
1873 $this->app->argv[3] = 'create';
1874 $this->app->argc = 10;
1875 $_REQUEST['id'] = 3;
1876 $result = api_favorites_create_destroy('json');
1877 $this->assertStatus($result['status']);
1881 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1884 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1886 $this->app->argv[1] = '1.1';
1887 $this->app->argv[3] = 'create';
1888 $this->app->argc = 10;
1889 $_REQUEST['id'] = 3;
1890 $result = api_favorites_create_destroy('rss');
1891 $this->assertXml($result, 'status');
1895 * Test the api_favorites_create_destroy() function with the destroy action.
1898 public function testApiFavoritesCreateDestroyWithDestroyAction()
1900 $this->app->argv[1] = '1.1';
1901 $this->app->argv[3] = 'destroy';
1902 $this->app->argc = 10;
1903 $_REQUEST['id'] = 3;
1904 $result = api_favorites_create_destroy('json');
1905 $this->assertStatus($result['status']);
1909 * Test the api_favorites_create_destroy() function without an authenticated user.
1911 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1913 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1915 $_SESSION['authenticated'] = false;
1916 api_favorites_create_destroy('json');
1920 * Test the api_favorites() function.
1923 public function testApiFavorites()
1925 $_REQUEST['page'] = -1;
1926 $_REQUEST['max_id'] = 10;
1927 $result = api_favorites('json');
1928 foreach ($result['status'] as $status) {
1929 $this->assertStatus($status);
1934 * Test the api_favorites() function with an RSS result.
1937 public function testApiFavoritesWithRss()
1939 $result = api_favorites('rss');
1940 $this->assertXml($result, 'statuses');
1944 * Test the api_favorites() function with an unallowed user.
1946 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1948 public function testApiFavoritesWithUnallowedUser()
1950 $_SESSION['allow_api'] = false;
1951 $_GET['screen_name'] = $this->selfUser['nick'];
1952 api_favorites('json');
1956 * Test the api_format_messages() function.
1959 public function testApiFormatMessages()
1961 $result = api_format_messages(
1962 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1963 ['id' => 2, 'screen_name' => 'recipient_name'],
1964 ['id' => 3, 'screen_name' => 'sender_name']
1966 $this->assertEquals('item_title'.PHP_EOL.'item_body', $result['text']);
1967 $this->assertEquals(1, $result['id']);
1968 $this->assertEquals(2, $result['recipient_id']);
1969 $this->assertEquals(3, $result['sender_id']);
1970 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1971 $this->assertEquals('sender_name', $result['sender_screen_name']);
1975 * Test the api_format_messages() function with HTML.
1978 public function testApiFormatMessagesWithHtmlText()
1980 $_GET['getText'] = 'html';
1981 $result = api_format_messages(
1982 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1983 ['id' => 2, 'screen_name' => 'recipient_name'],
1984 ['id' => 3, 'screen_name' => 'sender_name']
1986 $this->assertEquals('item_title', $result['title']);
1987 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1991 * Test the api_format_messages() function with plain text.
1994 public function testApiFormatMessagesWithPlainText()
1996 $_GET['getText'] = 'plain';
1997 $result = api_format_messages(
1998 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1999 ['id' => 2, 'screen_name' => 'recipient_name'],
2000 ['id' => 3, 'screen_name' => 'sender_name']
2002 $this->assertEquals('item_title', $result['title']);
2003 $this->assertEquals('item_body', $result['text']);
2007 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2010 public function testApiFormatMessagesWithoutUserObjects()
2012 $_GET['getUserObjects'] = 'false';
2013 $result = api_format_messages(
2014 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2015 ['id' => 2, 'screen_name' => 'recipient_name'],
2016 ['id' => 3, 'screen_name' => 'sender_name']
2018 $this->assertNull($result['sender']);
2019 $this->assertNull($result['recipient']);
2023 * Test the api_convert_item() function.
2026 public function testApiConvertItem()
2028 $result = api_convert_item(
2030 'network' => 'feed',
2031 'title' => 'item_title',
2032 // We need a long string to test that it is correctly cut
2033 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2034 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2035 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2036 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2037 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2038 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2039 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2040 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2041 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2042 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2043 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2044 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2045 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2046 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2047 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2048 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2049 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2050 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2051 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2052 'repellat officia illum quos impedit quam iste esse unde qui '.
2053 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2054 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2055 'et sed beatae nihil ullam temporibus corporis ratione blanditiis'
2058 $this->assertStringStartsWith('item_title', $result['text']);
2059 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2063 * Test the api_convert_item() function with an empty item body.
2066 public function testApiConvertItemWithoutBody()
2068 $result = api_convert_item(
2070 'network' => 'feed',
2071 'title' => 'item_title',
2073 'plink' => 'item_plink'
2076 $this->assertEquals('item_title', $result['text']);
2077 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2081 * Test the api_convert_item() function with the title in the body.
2084 public function testApiConvertItemWithTitleInBody()
2086 $result = api_convert_item(
2088 'title' => 'item_title',
2089 'body' => 'item_title item_body'
2092 $this->assertEquals('item_title item_body', $result['text']);
2093 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2097 * Test the api_get_attachments() function.
2100 public function testApiGetAttachments()
2103 $this->assertEmpty(api_get_attachments($body));
2107 * Test the api_get_attachments() function with an img tag.
2110 public function testApiGetAttachmentsWithImage()
2112 $body = '[img]img_url[/img]';
2113 $this->assertInternalType('array', api_get_attachments($body));
2117 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2120 public function testApiGetAttachmentsWithImageAndAndStatus()
2122 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2123 $body = '[img]img_url[/img]';
2124 $this->assertInternalType('array', api_get_attachments($body));
2128 * Test the api_get_entitities() function.
2131 public function testApiGetEntitities()
2134 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2138 * Test the api_get_entitities() function with the include_entities parameter.
2141 public function testApiGetEntititiesWithIncludeEntities()
2143 $_REQUEST['include_entities'] = 'true';
2145 $result = api_get_entitities($text, 'bbcode');
2146 $this->assertInternalType('array', $result['hashtags']);
2147 $this->assertInternalType('array', $result['symbols']);
2148 $this->assertInternalType('array', $result['urls']);
2149 $this->assertInternalType('array', $result['user_mentions']);
2153 * Test the api_format_items_embeded_images() function.
2156 public function testApiFormatItemsEmbededImages()
2158 $this->assertEquals(
2159 'text http://localhost/display/item_guid',
2160 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2165 * Test the api_contactlink_to_array() function.
2168 public function testApiContactlinkToArray()
2170 $this->assertEquals(
2175 api_contactlink_to_array('text')
2180 * Test the api_contactlink_to_array() function with an URL.
2183 public function testApiContactlinkToArrayWithUrl()
2185 $this->assertEquals(
2187 'name' => ['link_text'],
2190 api_contactlink_to_array('text <a href="url">link_text</a>')
2195 * Test the api_format_items_activities() function.
2198 public function testApiFormatItemsActivities()
2201 $result = api_format_items_activities($item);
2202 $this->assertArrayHasKey('like', $result);
2203 $this->assertArrayHasKey('dislike', $result);
2204 $this->assertArrayHasKey('attendyes', $result);
2205 $this->assertArrayHasKey('attendno', $result);
2206 $this->assertArrayHasKey('attendmaybe', $result);
2210 * Test the api_format_items_activities() function with an XML result.
2213 public function testApiFormatItemsActivitiesWithXml()
2216 $result = api_format_items_activities($item, 'xml');
2217 $this->assertArrayHasKey('friendica:like', $result);
2218 $this->assertArrayHasKey('friendica:dislike', $result);
2219 $this->assertArrayHasKey('friendica:attendyes', $result);
2220 $this->assertArrayHasKey('friendica:attendno', $result);
2221 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2225 * Test the api_format_items_profiles() function.
2228 public function testApiFormatItemsProfiles()
2231 'id' => 'profile_id',
2232 'profile-name' => 'profile_name',
2233 'is-default' => true,
2234 'hide-friends' => true,
2235 'photo' => 'profile_photo',
2236 'thumb' => 'profile_thumb',
2238 'net-publish' => true,
2239 'pdesc' => 'description',
2240 'dob' => 'date_of_birth',
2241 'address' => 'address',
2242 'locality' => 'city',
2243 'region' => 'region',
2244 'postal-code' => 'postal_code',
2245 'country-name' => 'country',
2246 'hometown' => 'hometown',
2247 'gender' => 'gender',
2248 'marital' => 'marital',
2249 'with' => 'marital_with',
2250 'howlong' => 'marital_since',
2251 'sexual' => 'sexual',
2252 'politic' => 'politic',
2253 'religion' => 'religion',
2254 'pub_keywords' => 'public_keywords',
2255 'prv_keywords' => 'private_keywords',
2258 'dislikes' => 'dislikes',
2264 'interest' => 'interest',
2265 'romance' => 'romance',
2267 'education' => 'education',
2268 'contact' => 'social_networks',
2269 'homepage' => 'homepage'
2271 $result = api_format_items_profiles($profile_row);
2272 $this->assertEquals(
2274 'profile_id' => 'profile_id',
2275 'profile_name' => 'profile_name',
2276 'is_default' => true,
2277 'hide_friends' => true,
2278 'profile_photo' => 'profile_photo',
2279 'profile_thumb' => 'profile_thumb',
2281 'net_publish' => true,
2282 'description' => 'description',
2283 'date_of_birth' => 'date_of_birth',
2284 'address' => 'address',
2286 'region' => 'region',
2287 'postal_code' => 'postal_code',
2288 'country' => 'country',
2289 'hometown' => 'hometown',
2290 'gender' => 'gender',
2291 'marital' => 'marital',
2292 'marital_with' => 'marital_with',
2293 'marital_since' => 'marital_since',
2294 'sexual' => 'sexual',
2295 'politic' => 'politic',
2296 'religion' => 'religion',
2297 'public_keywords' => 'public_keywords',
2298 'private_keywords' => 'private_keywords',
2301 'dislikes' => 'dislikes',
2307 'interest' => 'interest',
2308 'romance' => 'romance',
2310 'education' => 'education',
2311 'social_networks' => 'social_networks',
2312 'homepage' => 'homepage',
2320 * Test the api_format_items() function.
2323 public function testApiFormatItems()
2327 'item_network' => 'item_network',
2332 $result = api_format_items($items, [], true);
2333 foreach ($result as $status) {
2334 $this->assertStatus($status);
2339 * Test the api_format_items() function with an XML result.
2342 public function testApiFormatItemsWithXml()
2349 $result = api_format_items($items, [], true, 'xml');
2350 foreach ($result as $status) {
2351 $this->assertStatus($status);
2356 * Test the api_format_items() function.
2359 public function testApiAccountRateLimitStatus()
2361 $result = api_account_rate_limit_status('json');
2362 $this->assertEquals(150, $result['hash']['remaining_hits']);
2363 $this->assertEquals(150, $result['hash']['hourly_limit']);
2364 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2368 * Test the api_format_items() function with an XML result.
2371 public function testApiAccountRateLimitStatusWithXml()
2373 $result = api_account_rate_limit_status('xml');
2374 $this->assertXml($result, 'hash');
2378 * Test the api_help_test() function.
2381 public function testApiHelpTest()
2383 $result = api_help_test('json');
2384 $this->assertEquals(['ok' => 'ok'], $result);
2388 * Test the api_help_test() function with an XML result.
2391 public function testApiHelpTestWithXml()
2393 $this->markTestIncomplete('Triggers this error: "key() expects parameter 1 to be array, string given"');
2394 $result = api_help_test('xml');
2395 $this->assertXml($result, 'ok');
2399 * Test the api_lists_list() function.
2402 public function testApiListsList()
2404 $result = api_lists_list('json');
2405 $this->assertEquals(['lists_list' => []], $result);
2409 * Test the api_lists_ownerships() function.
2412 public function testApiListsOwnerships()
2414 $result = api_lists_ownerships('json');
2415 foreach ($result['lists']['lists'] as $list) {
2416 $this->assertList($list);
2421 * Test the api_lists_ownerships() function without an authenticated user.
2423 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2425 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2427 $_SESSION['authenticated'] = false;
2428 api_lists_ownerships('json');
2432 * Test the api_lists_statuses() function.
2433 * @expectedException Friendica\Network\HTTPException\BadRequestException
2436 public function testApiListsStatuses()
2438 api_lists_statuses('json');
2442 * Test the api_lists_statuses() function with a list ID.
2445 public function testApiListsStatusesWithListId()
2447 $_REQUEST['list_id'] = 1;
2448 $_REQUEST['page'] = -1;
2449 $_REQUEST['max_id'] = 10;
2450 $result = api_lists_statuses('json');
2451 foreach ($result['status'] as $status) {
2452 $this->assertStatus($status);
2457 * Test the api_lists_statuses() function with a list ID and a RSS result.
2460 public function testApiListsStatusesWithListIdAndRss()
2462 $_REQUEST['list_id'] = 1;
2463 $result = api_lists_statuses('rss');
2464 $this->assertXml($result, 'statuses');
2468 * Test the api_lists_statuses() function with an unallowed user.
2470 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2472 public function testApiListsStatusesWithUnallowedUser()
2474 $_SESSION['allow_api'] = false;
2475 $_GET['screen_name'] = $this->selfUser['nick'];
2476 api_lists_statuses('json');
2480 * Test the api_statuses_f() function.
2483 public function testApiStatusesFWithFriends()
2486 $result = api_statuses_f('friends');
2487 $this->assertArrayHasKey('user', $result);
2491 * Test the api_statuses_f() function.
2494 public function testApiStatusesFWithFollowers()
2496 $result = api_statuses_f('followers');
2497 $this->assertArrayHasKey('user', $result);
2501 * Test the api_statuses_f() function.
2504 public function testApiStatusesFWithBlocks()
2506 $result = api_statuses_f('blocks');
2507 $this->assertArrayHasKey('user', $result);
2511 * Test the api_statuses_f() function.
2514 public function testApiStatusesFWithIncoming()
2516 $result = api_statuses_f('incoming');
2517 $this->assertArrayHasKey('user', $result);
2521 * Test the api_statuses_f() function an undefined cursor GET variable.
2524 public function testApiStatusesFWithUndefinedCursor()
2526 $_GET['cursor'] = 'undefined';
2527 $this->assertFalse(api_statuses_f('friends'));
2531 * Test the api_statuses_friends() function.
2534 public function testApiStatusesFriends()
2536 $result = api_statuses_friends('json');
2537 $this->assertArrayHasKey('user', $result);
2541 * Test the api_statuses_friends() function an undefined cursor GET variable.
2544 public function testApiStatusesFriendsWithUndefinedCursor()
2546 $_GET['cursor'] = 'undefined';
2547 $this->assertFalse(api_statuses_friends('json'));
2551 * Test the api_statuses_followers() function.
2554 public function testApiStatusesFollowers()
2556 $result = api_statuses_followers('json');
2557 $this->assertArrayHasKey('user', $result);
2561 * Test the api_statuses_followers() function an undefined cursor GET variable.
2564 public function testApiStatusesFollowersWithUndefinedCursor()
2566 $_GET['cursor'] = 'undefined';
2567 $this->assertFalse(api_statuses_followers('json'));
2571 * Test the api_blocks_list() function.
2574 public function testApiBlocksList()
2576 $result = api_blocks_list('json');
2577 $this->assertArrayHasKey('user', $result);
2581 * Test the api_blocks_list() function an undefined cursor GET variable.
2584 public function testApiBlocksListWithUndefinedCursor()
2586 $_GET['cursor'] = 'undefined';
2587 $this->assertFalse(api_blocks_list('json'));
2591 * Test the api_friendships_incoming() function.
2594 public function testApiFriendshipsIncoming()
2596 $result = api_friendships_incoming('json');
2597 $this->assertArrayHasKey('id', $result);
2601 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2604 public function testApiFriendshipsIncomingWithUndefinedCursor()
2606 $_GET['cursor'] = 'undefined';
2607 $this->assertFalse(api_friendships_incoming('json'));
2611 * Test the api_statusnet_config() function.
2614 public function testApiStatusnetConfig()
2616 $result = api_statusnet_config('json');
2617 $this->assertEquals('localhost', $result['config']['site']['server']);
2618 $this->assertEquals('default', $result['config']['site']['theme']);
2619 $this->assertEquals('http://localhost/images/friendica-64.png', $result['config']['site']['logo']);
2620 $this->assertTrue($result['config']['site']['fancy']);
2621 $this->assertEquals('en', $result['config']['site']['language']);
2622 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2623 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2624 $this->assertEquals('false', $result['config']['site']['private']);
2625 $this->assertEquals('false', $result['config']['site']['ssl']);
2626 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2630 * Test the api_statusnet_version() function.
2633 public function testApiStatusnetVersion()
2635 $result = api_statusnet_version('json');
2636 $this->assertEquals('0.9.7', $result['version']);
2640 * Test the api_ff_ids() function.
2643 public function testApiFfIds()
2645 $result = api_ff_ids('json');
2646 $this->assertNull($result);
2650 * Test the api_ff_ids() function with a result.
2653 public function testApiFfIdsWithResult()
2655 $this->markTestIncomplete();
2659 * Test the api_ff_ids() function without an authenticated user.
2661 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2663 public function testApiFfIdsWithoutAuthenticatedUser()
2665 $_SESSION['authenticated'] = false;
2670 * Test the api_friends_ids() function.
2673 public function testApiFriendsIds()
2675 $result = api_friends_ids('json');
2676 $this->assertNull($result);
2680 * Test the api_followers_ids() function.
2683 public function testApiFollowersIds()
2685 $result = api_followers_ids('json');
2686 $this->assertNull($result);
2690 * Test the api_direct_messages_new() function.
2693 public function testApiDirectMessagesNew()
2695 $result = api_direct_messages_new('json');
2696 $this->assertNull($result);
2700 * Test the api_direct_messages_new() function without an authenticated user.
2702 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2704 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2706 $_SESSION['authenticated'] = false;
2707 api_direct_messages_new('json');
2711 * Test the api_direct_messages_new() function with an user ID.
2714 public function testApiDirectMessagesNewWithUserId()
2716 $_POST['text'] = 'message_text';
2717 $_POST['user_id'] = $this->otherUser['id'];
2718 $result = api_direct_messages_new('json');
2719 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2723 * Test the api_direct_messages_new() function with a screen name.
2726 public function testApiDirectMessagesNewWithScreenName()
2728 $_POST['text'] = 'message_text';
2729 $_POST['screen_name'] = $this->otherUser['nick'];
2730 $result = api_direct_messages_new('json');
2731 $this->assertEquals(1, $result['direct_message']['id']);
2732 $this->assertContains('message_text', $result['direct_message']['text']);
2733 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2734 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2738 * Test the api_direct_messages_new() function with a title.
2741 public function testApiDirectMessagesNewWithTitle()
2743 $_POST['text'] = 'message_text';
2744 $_POST['screen_name'] = $this->otherUser['nick'];
2745 $_REQUEST['title'] = 'message_title';
2746 $result = api_direct_messages_new('json');
2747 $this->assertEquals(1, $result['direct_message']['id']);
2748 $this->assertContains('message_text', $result['direct_message']['text']);
2749 $this->assertContains('message_title', $result['direct_message']['text']);
2750 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2751 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2755 * Test the api_direct_messages_new() function with an RSS result.
2758 public function testApiDirectMessagesNewWithRss()
2760 $_POST['text'] = 'message_text';
2761 $_POST['screen_name'] = $this->otherUser['nick'];
2762 $result = api_direct_messages_new('rss');
2763 $this->assertXml($result, 'direct-messages');
2767 * Test the api_direct_messages_destroy() function.
2769 * @expectedException Friendica\Network\HTTPException\BadRequestException
2771 public function testApiDirectMessagesDestroy()
2773 api_direct_messages_destroy('json');
2777 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2780 public function testApiDirectMessagesDestroyWithVerbose()
2782 $_GET['friendica_verbose'] = 'true';
2783 $result = api_direct_messages_destroy('json');
2784 $this->assertEquals(
2787 'result' => 'error',
2788 'message' => 'message id or parenturi not specified'
2796 * Test the api_direct_messages_destroy() function without an authenticated user.
2798 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2800 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2802 $_SESSION['authenticated'] = false;
2803 api_direct_messages_destroy('json');
2807 * Test the api_direct_messages_destroy() function with a non-zero ID.
2809 * @expectedException Friendica\Network\HTTPException\BadRequestException
2811 public function testApiDirectMessagesDestroyWithId()
2813 $_REQUEST['id'] = 1;
2814 api_direct_messages_destroy('json');
2818 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2821 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2823 $_REQUEST['id'] = 1;
2824 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2825 $_GET['friendica_verbose'] = 'true';
2826 $result = api_direct_messages_destroy('json');
2827 $this->assertEquals(
2830 'result' => 'error',
2831 'message' => 'message id not in database'
2839 * Test the api_direct_messages_destroy() function with a non-zero ID.
2842 public function testApiDirectMessagesDestroyWithCorrectId()
2844 $this->markTestIncomplete('We need to add a dataset for this.');
2848 * Test the api_direct_messages_box() function.
2851 public function testApiDirectMessagesBoxWithSentbox()
2853 $_REQUEST['page'] = -1;
2854 $_REQUEST['max_id'] = 10;
2855 $result = api_direct_messages_box('json', 'sentbox', 'false');
2856 $this->assertArrayHasKey('direct_message', $result);
2860 * Test the api_direct_messages_box() function.
2863 public function testApiDirectMessagesBoxWithConversation()
2865 $result = api_direct_messages_box('json', 'conversation', 'false');
2866 $this->assertArrayHasKey('direct_message', $result);
2870 * Test the api_direct_messages_box() function.
2873 public function testApiDirectMessagesBoxWithAll()
2875 $result = api_direct_messages_box('json', 'all', 'false');
2876 $this->assertArrayHasKey('direct_message', $result);
2880 * Test the api_direct_messages_box() function.
2883 public function testApiDirectMessagesBoxWithInbox()
2885 $result = api_direct_messages_box('json', 'inbox', 'false');
2886 $this->assertArrayHasKey('direct_message', $result);
2890 * Test the api_direct_messages_box() function.
2893 public function testApiDirectMessagesBoxWithVerbose()
2895 $result = api_direct_messages_box('json', 'sentbox', 'true');
2896 $this->assertEquals(
2899 'result' => 'error',
2900 'message' => 'no mails available'
2908 * Test the api_direct_messages_box() function with a RSS result.
2911 public function testApiDirectMessagesBoxWithRss()
2913 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2914 $this->assertXml($result, 'direct-messages');
2918 * Test the api_direct_messages_box() function without an authenticated user.
2920 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2922 public function testApiDirectMessagesBoxWithUnallowedUser()
2924 $_SESSION['allow_api'] = false;
2925 $_GET['screen_name'] = $this->selfUser['nick'];
2926 api_direct_messages_box('json', 'sentbox', 'false');
2930 * Test the api_direct_messages_sentbox() function.
2933 public function testApiDirectMessagesSentbox()
2935 $result = api_direct_messages_sentbox('json');
2936 $this->assertArrayHasKey('direct_message', $result);
2940 * Test the api_direct_messages_inbox() function.
2943 public function testApiDirectMessagesInbox()
2945 $result = api_direct_messages_inbox('json');
2946 $this->assertArrayHasKey('direct_message', $result);
2950 * Test the api_direct_messages_all() function.
2953 public function testApiDirectMessagesAll()
2955 $result = api_direct_messages_all('json');
2956 $this->assertArrayHasKey('direct_message', $result);
2960 * Test the api_direct_messages_conversation() function.
2963 public function testApiDirectMessagesConversation()
2965 $result = api_direct_messages_conversation('json');
2966 $this->assertArrayHasKey('direct_message', $result);
2970 * Test the api_oauth_request_token() function.
2973 public function testApiOauthRequestToken()
2975 $this->markTestIncomplete('killme() kills phpunit as well');
2979 * Test the api_oauth_access_token() function.
2982 public function testApiOauthAccessToken()
2984 $this->markTestIncomplete('killme() kills phpunit as well');
2988 * Test the api_fr_photoalbum_delete() function.
2990 * @expectedException Friendica\Network\HTTPException\BadRequestException
2992 public function testApiFrPhotoalbumDelete()
2994 api_fr_photoalbum_delete('json');
2998 * Test the api_fr_photoalbum_delete() function with an album name.
3000 * @expectedException Friendica\Network\HTTPException\BadRequestException
3002 public function testApiFrPhotoalbumDeleteWithAlbum()
3004 $_REQUEST['album'] = 'album_name';
3005 api_fr_photoalbum_delete('json');
3009 * Test the api_fr_photoalbum_delete() function with an album name.
3012 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3014 $this->markTestIncomplete('We need to add a dataset for this.');
3018 * Test the api_fr_photoalbum_delete() function.
3020 * @expectedException Friendica\Network\HTTPException\BadRequestException
3022 public function testApiFrPhotoalbumUpdate()
3024 api_fr_photoalbum_update('json');
3028 * Test the api_fr_photoalbum_delete() function with an album name.
3030 * @expectedException Friendica\Network\HTTPException\BadRequestException
3032 public function testApiFrPhotoalbumUpdateWithAlbum()
3034 $_REQUEST['album'] = 'album_name';
3035 api_fr_photoalbum_update('json');
3039 * Test the api_fr_photoalbum_delete() function with an album name.
3041 * @expectedException Friendica\Network\HTTPException\BadRequestException
3043 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3045 $_REQUEST['album'] = 'album_name';
3046 $_REQUEST['album_new'] = 'album_name';
3047 api_fr_photoalbum_update('json');
3051 * Test the api_fr_photoalbum_update() function without an authenticated user.
3053 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3055 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3057 $_SESSION['authenticated'] = false;
3058 api_fr_photoalbum_update('json');
3062 * Test the api_fr_photoalbum_delete() function with an album name.
3065 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3067 $this->markTestIncomplete('We need to add a dataset for this.');
3071 * Test the api_fr_photos_list() function.
3074 public function testApiFrPhotosList()
3076 $result = api_fr_photos_list('json');
3077 $this->assertArrayHasKey('photo', $result);
3081 * Test the api_fr_photos_list() function without an authenticated user.
3083 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3085 public function testApiFrPhotosListWithoutAuthenticatedUser()
3087 $_SESSION['authenticated'] = false;
3088 api_fr_photos_list('json');
3092 * Test the api_fr_photo_create_update() function.
3094 * @expectedException Friendica\Network\HTTPException\BadRequestException
3096 public function testApiFrPhotoCreateUpdate()
3098 api_fr_photo_create_update('json');
3102 * Test the api_fr_photo_create_update() function without an authenticated user.
3104 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3106 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3108 $_SESSION['authenticated'] = false;
3109 api_fr_photo_create_update('json');
3113 * Test the api_fr_photo_create_update() function with an album name.
3115 * @expectedException Friendica\Network\HTTPException\BadRequestException
3117 public function testApiFrPhotoCreateUpdateWithAlbum()
3119 $_REQUEST['album'] = 'album_name';
3120 api_fr_photo_create_update('json');
3124 * Test the api_fr_photo_create_update() function with the update mode.
3127 public function testApiFrPhotoCreateUpdateWithUpdate()
3129 $this->markTestIncomplete('We need to create a dataset for this');
3133 * Test the api_fr_photo_create_update() function with an uploaded file.
3136 public function testApiFrPhotoCreateUpdateWithFile()
3138 $this->markTestIncomplete();
3142 * Test the api_fr_photo_delete() function.
3144 * @expectedException Friendica\Network\HTTPException\BadRequestException
3146 public function testApiFrPhotoDelete()
3148 api_fr_photo_delete('json');
3152 * Test the api_fr_photo_delete() function without an authenticated user.
3154 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3156 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3158 $_SESSION['authenticated'] = false;
3159 api_fr_photo_delete('json');
3163 * Test the api_fr_photo_delete() function with a photo ID.
3165 * @expectedException Friendica\Network\HTTPException\BadRequestException
3167 public function testApiFrPhotoDeleteWithPhotoId()
3169 $_REQUEST['photo_id'] = 1;
3170 api_fr_photo_delete('json');
3174 * Test the api_fr_photo_delete() function with a correct photo ID.
3177 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3179 $this->markTestIncomplete('We need to create a dataset for this.');
3183 * Test the api_fr_photo_detail() function.
3185 * @expectedException Friendica\Network\HTTPException\BadRequestException
3187 public function testApiFrPhotoDetail()
3189 api_fr_photo_detail('json');
3193 * Test the api_fr_photo_detail() function without an authenticated user.
3195 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3197 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3199 $_SESSION['authenticated'] = false;
3200 api_fr_photo_detail('json');
3204 * Test the api_fr_photo_detail() function with a photo ID.
3206 * @expectedException Friendica\Network\HTTPException\NotFoundException
3208 public function testApiFrPhotoDetailWithPhotoId()
3210 $_REQUEST['photo_id'] = 1;
3211 api_fr_photo_detail('json');
3215 * Test the api_fr_photo_detail() function with a correct photo ID.
3218 public function testApiFrPhotoDetailCorrectPhotoId()
3220 $this->markTestIncomplete('We need to create a dataset for this.');
3224 * Test the api_account_update_profile_image() function.
3226 * @expectedException Friendica\Network\HTTPException\BadRequestException
3228 public function testApiAccountUpdateProfileImage()
3230 api_account_update_profile_image('json');
3234 * Test the api_account_update_profile_image() function without an authenticated user.
3236 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3238 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3240 $_SESSION['authenticated'] = false;
3241 api_account_update_profile_image('json');
3245 * Test the api_account_update_profile_image() function with an uploaded file.
3247 * @expectedException Friendica\Network\HTTPException\BadRequestException
3249 public function testApiAccountUpdateProfileImageWithUpload()
3251 $this->markTestIncomplete();
3256 * Test the api_account_update_profile() function.
3259 public function testApiAccountUpdateProfile()
3261 $_POST['name'] = 'new_name';
3262 $_POST['description'] = 'new_description';
3263 $result = api_account_update_profile('json');
3264 // We can't use assertSelfUser() here because the user object is missing some properties.
3265 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3266 $this->assertEquals('Friendica', $result['user']['location']);
3267 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3268 $this->assertEquals('dfrn', $result['user']['network']);
3269 $this->assertEquals('new_name', $result['user']['name']);
3270 $this->assertEquals('new_description', $result['user']['description']);
3274 * Test the check_acl_input() function.
3277 public function testCheckAclInput()
3279 $result = check_acl_input('<aclstring>');
3280 // Where does this result come from?
3281 $this->assertEquals(1, $result);
3285 * Test the check_acl_input() function with an empty ACL string.
3288 public function testCheckAclInputWithEmptyAclString()
3290 $result = check_acl_input(' ');
3291 $this->assertFalse($result);
3295 * Test the save_media_to_database() function.
3298 public function testSaveMediaToDatabase()
3300 $this->markTestIncomplete();
3304 * Test the post_photo_item() function.
3307 public function testPostPhotoItem()
3309 $this->markTestIncomplete();
3313 * Test the prepare_photo_data() function.
3316 public function testPreparePhotoData()
3318 $this->markTestIncomplete();
3322 * Test the api_friendica_remoteauth() function.
3324 * @expectedException Friendica\Network\HTTPException\BadRequestException
3326 public function testApiFriendicaRemoteauth()
3328 api_friendica_remoteauth();
3332 * Test the api_friendica_remoteauth() function with an URL.
3334 * @expectedException Friendica\Network\HTTPException\BadRequestException
3336 public function testApiFriendicaRemoteauthWithUrl()
3338 $_GET['url'] = 'url';
3339 $_GET['c_url'] = 'url';
3340 api_friendica_remoteauth();
3344 * Test the api_friendica_remoteauth() function with a correct URL.
3347 public function testApiFriendicaRemoteauthWithCorrectUrl()
3349 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3350 $_GET['url'] = 'url';
3351 $_GET['c_url'] = $this->selfUser['nurl'];
3352 api_friendica_remoteauth();
3356 * Test the api_share_as_retweet() function.
3359 public function testApiShareAsRetweet()
3362 $result = api_share_as_retweet($item);
3363 $this->assertFalse($result);
3367 * Test the api_share_as_retweet() function with a valid item.
3370 public function testApiShareAsRetweetWithValidItem()
3372 $this->markTestIncomplete();
3376 * Test the api_get_nick() function.
3379 public function testApiGetNick()
3381 $result = api_get_nick($this->otherUser['nurl']);
3382 $this->assertEquals('othercontact', $result);
3386 * Test the api_get_nick() function with a wrong URL.
3389 public function testApiGetNickWithWrongUrl()
3391 $result = api_get_nick('wrong_url');
3392 $this->assertFalse($result);
3396 * Test the api_in_reply_to() function.
3399 public function testApiInReplyTo()
3401 $result = api_in_reply_to([]);
3402 $this->assertArrayHasKey('status_id', $result);
3403 $this->assertArrayHasKey('user_id', $result);
3404 $this->assertArrayHasKey('status_id_str', $result);
3405 $this->assertArrayHasKey('user_id_str', $result);
3406 $this->assertArrayHasKey('screen_name', $result);
3410 * Test the api_in_reply_to() function with a valid item.
3413 public function testApiInReplyToWithValidItem()
3415 $this->markTestIncomplete();
3419 * Test the api_clean_plain_items() function.
3422 public function testApiCleanPlainItems()
3424 $_REQUEST['include_entities'] = 'true';
3425 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3426 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3430 * Test the api_clean_attachments() function.
3433 public function testApiCleanAttachments()
3435 $this->markTestIncomplete();
3439 * Test the api_best_nickname() function.
3442 public function testApiBestNickname()
3445 $result = api_best_nickname($contacts);
3446 $this->assertNull($result);
3450 * Test the api_best_nickname() function with contacts.
3453 public function testApiBestNicknameWithContacts()
3455 $this->markTestIncomplete();
3459 * Test the api_friendica_group_show() function.
3462 public function testApiFriendicaGroupShow()
3464 $this->markTestIncomplete();
3468 * Test the api_friendica_group_delete() function.
3471 public function testApiFriendicaGroupDelete()
3473 $this->markTestIncomplete();
3477 * Test the api_lists_destroy() function.
3480 public function testApiListsDestroy()
3482 $this->markTestIncomplete();
3486 * Test the group_create() function.
3489 public function testGroupCreate()
3491 $this->markTestIncomplete();
3495 * Test the api_friendica_group_create() function.
3498 public function testApiFriendicaGroupCreate()
3500 $this->markTestIncomplete();
3504 * Test the api_lists_create() function.
3507 public function testApiListsCreate()
3509 $this->markTestIncomplete();
3513 * Test the api_friendica_group_update() function.
3516 public function testApiFriendicaGroupUpdate()
3518 $this->markTestIncomplete();
3522 * Test the api_lists_update() function.
3525 public function testApiListsUpdate()
3527 $this->markTestIncomplete();
3531 * Test the api_friendica_activity() function.
3534 public function testApiFriendicaActivity()
3536 $this->markTestIncomplete();
3540 * Test the api_friendica_notification() function.
3542 * @expectedException Friendica\Network\HTTPException\BadRequestException
3544 public function testApiFriendicaNotification()
3546 api_friendica_notification('json');
3550 * Test the api_friendica_notification() function without an authenticated user.
3552 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3554 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3556 $_SESSION['authenticated'] = false;
3557 api_friendica_notification('json');
3561 * Test the api_friendica_notification() function with an argument count.
3564 public function testApiFriendicaNotificationWithArgumentCount()
3566 $this->app->argc = 3;
3567 $result = api_friendica_notification('json');
3568 $this->assertEquals(['note' => false], $result);
3572 * Test the api_friendica_notification() function with an XML result.
3575 public function testApiFriendicaNotificationWithXmlResult()
3577 $this->markTestIncomplete('Fails with "Invalid argument supplied for foreach()".');
3578 $this->app->argc = 3;
3579 $result = api_friendica_notification('xml');
3580 $this->assertXml($result, 'notes');
3584 * Test the api_friendica_notification_seen() function.
3587 public function testApiFriendicaNotificationSeen()
3589 $this->markTestIncomplete();
3593 * Test the api_friendica_direct_messages_setseen() function.
3596 public function testApiFriendicaDirectMessagesSetseen()
3598 $this->markTestIncomplete();
3602 * Test the api_friendica_direct_messages_search() function.
3605 public function testApiFriendicaDirectMessagesSearch()
3607 $this->markTestIncomplete();
3611 * Test the api_friendica_profile_show() function.
3614 public function testApiFriendicaProfileShow()
3616 $result = api_friendica_profile_show('json');
3617 // We can't use assertSelfUser() here because the user object is missing some properties.
3618 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3619 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3620 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3621 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3622 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3623 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3624 $this->assertFalse($result['$result']['multi_profiles']);
3628 * Test the api_friendica_profile_show() function with a profile ID.
3631 public function testApiFriendicaProfileShowWithProfileId()
3633 $this->markTestIncomplete('We need to add a dataset for this.');
3637 * Test the api_friendica_profile_show() function with a wrong profile ID.
3639 * @expectedException Friendica\Network\HTTPException\BadRequestException
3641 public function testApiFriendicaProfileShowWithWrongProfileId()
3643 $_REQUEST['profile_id'] = 666;
3644 api_friendica_profile_show('json');
3648 * Test the api_friendica_profile_show() function without an authenticated user.
3650 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3652 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3654 $_SESSION['authenticated'] = false;
3655 api_friendica_profile_show('json');
3659 * Test the api_saved_searches_list() function.
3662 public function testApiSavedSearchesList()
3664 $result = api_saved_searches_list('json');
3665 $this->assertEquals(1, $result['terms'][0]['id']);
3666 $this->assertEquals(1, $result['terms'][0]['id_str']);
3667 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3668 $this->assertEquals('Saved search', $result['terms'][0]['query']);