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"?>'."\n".
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"?>'."\n".
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"?>'."\n".
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">'."\n".
578 ' <error>error_message</error>'."\n".
579 ' <code>200 Friendica\Network\HTTP</code>'."\n".
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"?>'."\n".
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">'."\n".
598 ' <error>error_message</error>'."\n".
599 ' <code>200 Friendica\Network\HTTP</code>'."\n".
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"?>'."\n".
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">'."\n".
618 ' <error>error_message</error>'."\n".
619 ' <code>200 Friendica\Network\HTTP</code>'."\n".
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', '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));
857 * Test the api_item_get_user() function.
859 * @runInSeparateProcess
861 public function testApiItemGetUser()
863 $users = api_item_get_user($this->app, []);
864 $this->assertSelfUser($users[0]);
868 * Test the api_item_get_user() function with a different item parent.
871 public function testApiItemGetUserWithDifferentParent()
873 $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
874 $this->assertSelfUser($users[0]);
875 $this->assertEquals($users[0], $users[1]);
879 * Test the api_walk_recursive() function.
882 public function testApiWalkRecursive()
890 // Should we test this with a callback that actually does something?
898 * Test the api_walk_recursive() function with an array.
901 public function testApiWalkRecursiveWithArray()
903 $array = [['item1'], ['item2']];
909 // Should we test this with a callback that actually does something?
917 * Test the api_reformat_xml() function.
920 public function testApiReformatXml()
924 $this->assertTrue(api_reformat_xml($item, $key));
925 $this->assertEquals('true', $item);
929 * Test the api_reformat_xml() function with a statusnet_api key.
932 public function testApiReformatXmlWithStatusnetKey()
935 $key = 'statusnet_api';
936 $this->assertTrue(api_reformat_xml($item, $key));
937 $this->assertEquals('statusnet:api', $key);
941 * Test the api_reformat_xml() function with a friendica_api key.
944 public function testApiReformatXmlWithFriendicaKey()
947 $key = 'friendica_api';
948 $this->assertTrue(api_reformat_xml($item, $key));
949 $this->assertEquals('friendica:api', $key);
953 * Test the api_create_xml() function.
956 public function testApiCreateXml()
959 '<?xml version="1.0"?>'."\n".
960 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
961 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
962 'xmlns:georss="http://www.georss.org/georss">'."\n".
963 ' <data>some_data</data>'."\n".
964 '</root_element>'."\n",
965 api_create_xml(['data' => ['some_data']], 'root_element')
970 * Test the api_create_xml() function without any XML namespace.
973 public function testApiCreateXmlWithoutNamespaces()
976 '<?xml version="1.0"?>'."\n".
978 ' <data>some_data</data>'."\n".
980 api_create_xml(['data' => ['some_data']], 'ok')
985 * Test the api_format_data() function.
988 public function testApiFormatData()
990 $data = ['some_data'];
991 $this->assertEquals($data, api_format_data('root_element', 'json', $data));
995 * Test the api_format_data() function with an XML result.
998 public function testApiFormatDataWithXml()
1000 $this->assertEquals(
1001 '<?xml version="1.0"?>'."\n".
1002 '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
1003 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
1004 'xmlns:georss="http://www.georss.org/georss">'."\n".
1005 ' <data>some_data</data>'."\n".
1006 '</root_element>'."\n",
1007 api_format_data('root_element', 'xml', ['data' => ['some_data']])
1012 * Test the api_account_verify_credentials() function.
1015 public function testApiAccountVerifyCredentials()
1017 $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
1021 * Test the api_account_verify_credentials() function without an authenticated user.
1023 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1025 public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
1027 $_SESSION['authenticated'] = false;
1028 api_account_verify_credentials('json');
1032 * Test the requestdata() function.
1035 public function testRequestdata()
1037 $this->assertNull(requestdata('variable_name'));
1041 * Test the requestdata() function with a POST parameter.
1044 public function testRequestdataWithPost()
1046 $_POST['variable_name'] = 'variable_value';
1047 $this->assertEquals('variable_value', requestdata('variable_name'));
1051 * Test the requestdata() function with a GET parameter.
1054 public function testRequestdataWithGet()
1056 $_GET['variable_name'] = 'variable_value';
1057 $this->assertEquals('variable_value', requestdata('variable_name'));
1061 * Test the api_statuses_mediap() function.
1064 public function testApiStatusesMediap()
1066 $this->app->argc = 2;
1074 'tmp_name' => $this->getTempImage(),
1075 'name' => 'spacer.png',
1076 'type' => 'image/png'
1079 $_GET['status'] = '<b>Status content</b>';
1081 $result = api_statuses_mediap('json');
1082 $this->assertStatus($result['status']);
1086 * Test the api_statuses_mediap() function without an authenticated user.
1088 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1090 public function testApiStatusesMediapWithoutAuthenticatedUser()
1092 $_SESSION['authenticated'] = false;
1093 api_statuses_mediap('json');
1097 * Test the api_statuses_update() function.
1100 public function testApiStatusesUpdate()
1102 $_GET['status'] = 'Status content';
1103 $_GET['in_reply_to_status_id'] = -1;
1112 'tmp_name' => $this->getTempImage(),
1113 'name' => 'spacer.png',
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 'name' => 'spacer.png',
1222 'type' => 'image/png'
1228 $result = api_media_upload();
1229 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1230 $this->assertEquals(1, $result['media']['image']['w']);
1231 $this->assertEquals(1, $result['media']['image']['h']);
1235 * Test the api_status_show() function.
1238 public function testApiStatusShow()
1240 $result = api_status_show('json');
1241 $this->assertStatus($result['status']);
1245 * Test the api_status_show() function with an XML result.
1248 public function testApiStatusShowWithXml()
1250 $result = api_status_show('xml');
1251 $this->assertXml($result, 'statuses');
1255 * Test the api_status_show() function with a raw result.
1258 public function testApiStatusShowWithRaw()
1260 $this->assertStatus(api_status_show('raw'));
1264 * Test the api_users_show() function.
1267 public function testApiUsersShow()
1269 $result = api_users_show('json');
1270 // We can't use assertSelfUser() here because the user object is missing some properties.
1271 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1272 $this->assertEquals('Friendica', $result['user']['location']);
1273 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1274 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1275 $this->assertEquals('dfrn', $result['user']['network']);
1276 $this->assertTrue($result['user']['verified']);
1280 * Test the api_users_show() function with an XML result.
1283 public function testApiUsersShowWithXml()
1285 $result = api_users_show('xml');
1286 $this->assertXml($result, 'statuses');
1290 * Test the api_users_search() function.
1293 public function testApiUsersSearch()
1295 $_GET['q'] = 'othercontact';
1296 $result = api_users_search('json');
1297 $this->assertOtherUser($result['users'][0]);
1301 * Test the api_users_search() function with an XML result.
1304 public function testApiUsersSearchWithXml()
1306 $_GET['q'] = 'othercontact';
1307 $result = api_users_search('xml');
1308 $this->assertXml($result, 'users');
1312 * Test the api_users_search() function without a GET q parameter.
1314 * @expectedException Friendica\Network\HTTPException\BadRequestException
1316 public function testApiUsersSearchWithoutQuery()
1318 api_users_search('json');
1322 * Test the api_users_lookup() function.
1324 * @expectedException Friendica\Network\HTTPException\NotFoundException
1326 public function testApiUsersLookup()
1328 api_users_lookup('json');
1332 * Test the api_users_lookup() function with an user ID.
1335 public function testApiUsersLookupWithUserId()
1337 $_REQUEST['user_id'] = $this->otherUser['id'];
1338 $result = api_users_lookup('json');
1339 $this->assertOtherUser($result['users'][0]);
1343 * Test the api_search() function.
1346 public function testApiSearch()
1348 $_REQUEST['q'] = 'reply';
1349 $_REQUEST['max_id'] = 10;
1350 $result = api_search('json');
1351 foreach ($result['status'] as $status) {
1352 $this->assertStatus($status);
1353 $this->assertContains('reply', $status['text'], null, true);
1358 * Test the api_search() function a count parameter.
1361 public function testApiSearchWithCount()
1363 $_REQUEST['q'] = 'reply';
1364 $_REQUEST['count'] = 20;
1365 $result = api_search('json');
1366 foreach ($result['status'] as $status) {
1367 $this->assertStatus($status);
1368 $this->assertContains('reply', $status['text'], null, true);
1373 * Test the api_search() function with an rpp parameter.
1376 public function testApiSearchWithRpp()
1378 $_REQUEST['q'] = 'reply';
1379 $_REQUEST['rpp'] = 20;
1380 $result = api_search('json');
1381 foreach ($result['status'] as $status) {
1382 $this->assertStatus($status);
1383 $this->assertContains('reply', $status['text'], null, true);
1389 * Test the api_search() function without an authenticated user.
1391 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1393 public function testApiSearchWithUnallowedUser()
1395 $_SESSION['allow_api'] = false;
1396 $_GET['screen_name'] = $this->selfUser['nick'];
1401 * Test the api_search() function without any GET query parameter.
1403 * @expectedException Friendica\Network\HTTPException\BadRequestException
1405 public function testApiSearchWithoutQuery()
1411 * Test the api_statuses_home_timeline() function.
1414 public function testApiStatusesHomeTimeline()
1416 $_REQUEST['max_id'] = 10;
1417 $_REQUEST['exclude_replies'] = true;
1418 $_REQUEST['conversation_id'] = 1;
1419 $result = api_statuses_home_timeline('json');
1420 $this->assertNotEmpty($result['status']);
1421 foreach ($result['status'] as $status) {
1422 $this->assertStatus($status);
1427 * Test the api_statuses_home_timeline() function with a negative page parameter.
1430 public function testApiStatusesHomeTimelineWithNegativePage()
1432 $_REQUEST['page'] = -2;
1433 $result = api_statuses_home_timeline('json');
1434 $this->assertNotEmpty($result['status']);
1435 foreach ($result['status'] as $status) {
1436 $this->assertStatus($status);
1441 * Test the api_statuses_home_timeline() with an unallowed user.
1443 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1445 public function testApiStatusesHomeTimelineWithUnallowedUser()
1447 $_SESSION['allow_api'] = false;
1448 $_GET['screen_name'] = $this->selfUser['nick'];
1449 api_statuses_home_timeline('json');
1453 * Test the api_statuses_home_timeline() function with an RSS result.
1456 public function testApiStatusesHomeTimelineWithRss()
1458 $result = api_statuses_home_timeline('rss');
1459 $this->assertXml($result, 'statuses');
1463 * Test the api_statuses_public_timeline() function.
1466 public function testApiStatusesPublicTimeline()
1468 $_REQUEST['max_id'] = 10;
1469 $_REQUEST['conversation_id'] = 1;
1470 $result = api_statuses_public_timeline('json');
1471 $this->assertNotEmpty($result['status']);
1472 foreach ($result['status'] as $status) {
1473 $this->assertStatus($status);
1478 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1481 public function testApiStatusesPublicTimelineWithExcludeReplies()
1483 $_REQUEST['max_id'] = 10;
1484 $_REQUEST['exclude_replies'] = true;
1485 $result = api_statuses_public_timeline('json');
1486 $this->assertNotEmpty($result['status']);
1487 foreach ($result['status'] as $status) {
1488 $this->assertStatus($status);
1493 * Test the api_statuses_public_timeline() function with a negative page parameter.
1496 public function testApiStatusesPublicTimelineWithNegativePage()
1498 $_REQUEST['page'] = -2;
1499 $result = api_statuses_public_timeline('json');
1500 $this->assertNotEmpty($result['status']);
1501 foreach ($result['status'] as $status) {
1502 $this->assertStatus($status);
1507 * Test the api_statuses_public_timeline() function with an unallowed user.
1509 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1511 public function testApiStatusesPublicTimelineWithUnallowedUser()
1513 $_SESSION['allow_api'] = false;
1514 $_GET['screen_name'] = $this->selfUser['nick'];
1515 api_statuses_public_timeline('json');
1519 * Test the api_statuses_public_timeline() function with an RSS result.
1522 public function testApiStatusesPublicTimelineWithRss()
1524 $result = api_statuses_public_timeline('rss');
1525 $this->assertXml($result, 'statuses');
1529 * Test the api_statuses_networkpublic_timeline() function.
1532 public function testApiStatusesNetworkpublicTimeline()
1534 $_REQUEST['max_id'] = 10;
1535 $result = api_statuses_networkpublic_timeline('json');
1536 $this->assertNotEmpty($result['status']);
1537 foreach ($result['status'] as $status) {
1538 $this->assertStatus($status);
1543 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1546 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1548 $_REQUEST['page'] = -2;
1549 $result = api_statuses_networkpublic_timeline('json');
1550 $this->assertNotEmpty($result['status']);
1551 foreach ($result['status'] as $status) {
1552 $this->assertStatus($status);
1557 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1559 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1561 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1563 $_SESSION['allow_api'] = false;
1564 $_GET['screen_name'] = $this->selfUser['nick'];
1565 api_statuses_networkpublic_timeline('json');
1569 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1572 public function testApiStatusesNetworkpublicTimelineWithRss()
1574 $result = api_statuses_networkpublic_timeline('rss');
1575 $this->assertXml($result, 'statuses');
1579 * Test the api_statuses_show() function.
1581 * @expectedException Friendica\Network\HTTPException\BadRequestException
1583 public function testApiStatusesShow()
1585 api_statuses_show('json');
1589 * Test the api_statuses_show() function with an ID.
1592 public function testApiStatusesShowWithId()
1594 $this->app->argv[3] = 1;
1595 $result = api_statuses_show('json');
1596 $this->assertStatus($result['status']);
1600 * Test the api_statuses_show() function with the conversation parameter.
1603 public function testApiStatusesShowWithConversation()
1605 $this->app->argv[3] = 1;
1606 $_REQUEST['conversation'] = 1;
1607 $result = api_statuses_show('json');
1608 $this->assertNotEmpty($result['status']);
1609 foreach ($result['status'] as $status) {
1610 $this->assertStatus($status);
1615 * Test the api_statuses_show() function with an unallowed user.
1617 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1619 public function testApiStatusesShowWithUnallowedUser()
1621 $_SESSION['allow_api'] = false;
1622 $_GET['screen_name'] = $this->selfUser['nick'];
1623 api_statuses_show('json');
1627 * Test the api_conversation_show() function.
1629 * @expectedException Friendica\Network\HTTPException\BadRequestException
1631 public function testApiConversationShow()
1633 api_conversation_show('json');
1637 * Test the api_conversation_show() function with an ID.
1640 public function testApiConversationShowWithId()
1642 $this->app->argv[3] = 1;
1643 $_REQUEST['max_id'] = 10;
1644 $_REQUEST['page'] = -2;
1645 $result = api_conversation_show('json');
1646 $this->assertNotEmpty($result['status']);
1647 foreach ($result['status'] as $status) {
1648 $this->assertStatus($status);
1653 * Test the api_conversation_show() function with an unallowed user.
1655 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1657 public function testApiConversationShowWithUnallowedUser()
1659 $_SESSION['allow_api'] = false;
1660 $_GET['screen_name'] = $this->selfUser['nick'];
1661 api_conversation_show('json');
1665 * Test the api_statuses_repeat() function.
1667 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1669 public function testApiStatusesRepeat()
1671 api_statuses_repeat('json');
1675 * Test the api_statuses_repeat() function without an authenticated user.
1677 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1679 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1681 $_SESSION['authenticated'] = false;
1682 api_statuses_repeat('json');
1686 * Test the api_statuses_repeat() function with an ID.
1689 public function testApiStatusesRepeatWithId()
1691 $this->app->argv[3] = 1;
1692 $result = api_statuses_repeat('json');
1693 $this->assertStatus($result['status']);
1695 // Also test with a shared status
1696 $this->app->argv[3] = 5;
1697 $result = api_statuses_repeat('json');
1698 $this->assertStatus($result['status']);
1702 * Test the api_statuses_destroy() function.
1704 * @expectedException Friendica\Network\HTTPException\BadRequestException
1706 public function testApiStatusesDestroy()
1708 api_statuses_destroy('json');
1712 * Test the api_statuses_destroy() function without an authenticated user.
1714 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1716 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1718 $_SESSION['authenticated'] = false;
1719 api_statuses_destroy('json');
1723 * Test the api_statuses_destroy() function with an ID.
1726 public function testApiStatusesDestroyWithId()
1728 $this->app->argv[3] = 1;
1729 $result = api_statuses_destroy('json');
1730 $this->assertStatus($result['status']);
1734 * Test the api_statuses_mentions() function.
1737 public function testApiStatusesMentions()
1739 $this->app->user = ['nickname' => $this->selfUser['nick']];
1740 $_REQUEST['max_id'] = 10;
1741 $result = api_statuses_mentions('json');
1742 $this->assertEmpty($result['status']);
1743 // We should test with mentions in the database.
1747 * Test the api_statuses_mentions() function with a negative page parameter.
1750 public function testApiStatusesMentionsWithNegativePage()
1752 $_REQUEST['page'] = -2;
1753 $result = api_statuses_mentions('json');
1754 $this->assertEmpty($result['status']);
1758 * Test the api_statuses_mentions() function with an unallowed user.
1760 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1762 public function testApiStatusesMentionsWithUnallowedUser()
1764 $_SESSION['allow_api'] = false;
1765 $_GET['screen_name'] = $this->selfUser['nick'];
1766 api_statuses_mentions('json');
1770 * Test the api_statuses_mentions() function with an RSS result.
1773 public function testApiStatusesMentionsWithRss()
1775 $result = api_statuses_mentions('rss');
1776 $this->assertXml($result, 'statuses');
1780 * Test the api_statuses_user_timeline() function.
1783 public function testApiStatusesUserTimeline()
1785 $_REQUEST['max_id'] = 10;
1786 $_REQUEST['exclude_replies'] = true;
1787 $_REQUEST['conversation_id'] = 1;
1788 $result = api_statuses_user_timeline('json');
1789 $this->assertNotEmpty($result['status']);
1790 foreach ($result['status'] as $status) {
1791 $this->assertStatus($status);
1796 * Test the api_statuses_user_timeline() function with a negative page parameter.
1799 public function testApiStatusesUserTimelineWithNegativePage()
1801 $_REQUEST['page'] = -2;
1802 $result = api_statuses_user_timeline('json');
1803 $this->assertNotEmpty($result['status']);
1804 foreach ($result['status'] as $status) {
1805 $this->assertStatus($status);
1810 * Test the api_statuses_user_timeline() function with an RSS result.
1813 public function testApiStatusesUserTimelineWithRss()
1815 $result = api_statuses_user_timeline('rss');
1816 $this->assertXml($result, 'statuses');
1820 * Test the api_statuses_user_timeline() function with an unallowed user.
1822 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1824 public function testApiStatusesUserTimelineWithUnallowedUser()
1826 $_SESSION['allow_api'] = false;
1827 $_GET['screen_name'] = $this->selfUser['nick'];
1828 api_statuses_user_timeline('json');
1832 * Test the api_favorites_create_destroy() function.
1834 * @expectedException Friendica\Network\HTTPException\BadRequestException
1836 public function testApiFavoritesCreateDestroy()
1838 api_favorites_create_destroy('json');
1842 * Test the api_favorites_create_destroy() function with an invalid ID.
1844 * @expectedException Friendica\Network\HTTPException\BadRequestException
1846 public function testApiFavoritesCreateDestroyWithInvalidId()
1848 // This triggers a very specific condition ($action_argv_id + 2)
1849 $this->app->argv[1] = '1.1';
1850 $this->app->argc = 5;
1851 api_favorites_create_destroy('json');
1855 * Test the api_favorites_create_destroy() function with an invalid action.
1857 * @expectedException Friendica\Network\HTTPException\BadRequestException
1859 public function testApiFavoritesCreateDestroyWithInvalidAction()
1861 $this->app->argv[1] = '1.1';
1862 $this->app->argc = 10;
1863 $_REQUEST['id'] = 1;
1864 api_favorites_create_destroy('json');
1868 * Test the api_favorites_create_destroy() function with the create action.
1871 public function testApiFavoritesCreateDestroyWithCreateAction()
1873 $this->app->argv[1] = '1.1';
1874 $this->app->argv[3] = 'create';
1875 $this->app->argc = 10;
1876 $_REQUEST['id'] = 3;
1877 $result = api_favorites_create_destroy('json');
1878 $this->assertStatus($result['status']);
1882 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1885 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1887 $this->app->argv[1] = '1.1';
1888 $this->app->argv[3] = 'create';
1889 $this->app->argc = 10;
1890 $_REQUEST['id'] = 3;
1891 $result = api_favorites_create_destroy('rss');
1892 $this->assertXml($result, 'status');
1896 * Test the api_favorites_create_destroy() function with the destroy action.
1899 public function testApiFavoritesCreateDestroyWithDestroyAction()
1901 $this->app->argv[1] = '1.1';
1902 $this->app->argv[3] = 'destroy';
1903 $this->app->argc = 10;
1904 $_REQUEST['id'] = 3;
1905 $result = api_favorites_create_destroy('json');
1906 $this->assertStatus($result['status']);
1910 * Test the api_favorites_create_destroy() function without an authenticated user.
1912 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1914 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1916 $_SESSION['authenticated'] = false;
1917 api_favorites_create_destroy('json');
1921 * Test the api_favorites() function.
1924 public function testApiFavorites()
1926 $_REQUEST['page'] = -1;
1927 $_REQUEST['max_id'] = 10;
1928 $result = api_favorites('json');
1929 foreach ($result['status'] as $status) {
1930 $this->assertStatus($status);
1935 * Test the api_favorites() function with an RSS result.
1938 public function testApiFavoritesWithRss()
1940 $result = api_favorites('rss');
1941 $this->assertXml($result, 'statuses');
1945 * Test the api_favorites() function with an unallowed user.
1947 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1949 public function testApiFavoritesWithUnallowedUser()
1951 $_SESSION['allow_api'] = false;
1952 $_GET['screen_name'] = $this->selfUser['nick'];
1953 api_favorites('json');
1957 * Test the api_format_messages() function.
1960 public function testApiFormatMessages()
1962 $result = api_format_messages(
1963 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1964 ['id' => 2, 'screen_name' => 'recipient_name'],
1965 ['id' => 3, 'screen_name' => 'sender_name']
1967 $this->assertEquals('item_title'."\n".'item_body', $result['text']);
1968 $this->assertEquals(1, $result['id']);
1969 $this->assertEquals(2, $result['recipient_id']);
1970 $this->assertEquals(3, $result['sender_id']);
1971 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1972 $this->assertEquals('sender_name', $result['sender_screen_name']);
1976 * Test the api_format_messages() function with HTML.
1979 public function testApiFormatMessagesWithHtmlText()
1981 $_GET['getText'] = 'html';
1982 $result = api_format_messages(
1983 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1984 ['id' => 2, 'screen_name' => 'recipient_name'],
1985 ['id' => 3, 'screen_name' => 'sender_name']
1987 $this->assertEquals('item_title', $result['title']);
1988 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1992 * Test the api_format_messages() function with plain text.
1995 public function testApiFormatMessagesWithPlainText()
1997 $_GET['getText'] = 'plain';
1998 $result = api_format_messages(
1999 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2000 ['id' => 2, 'screen_name' => 'recipient_name'],
2001 ['id' => 3, 'screen_name' => 'sender_name']
2003 $this->assertEquals('item_title', $result['title']);
2004 $this->assertEquals('item_body', $result['text']);
2008 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2011 public function testApiFormatMessagesWithoutUserObjects()
2013 $_GET['getUserObjects'] = 'false';
2014 $result = api_format_messages(
2015 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2016 ['id' => 2, 'screen_name' => 'recipient_name'],
2017 ['id' => 3, 'screen_name' => 'sender_name']
2019 $this->assertNull($result['sender']);
2020 $this->assertNull($result['recipient']);
2024 * Test the api_convert_item() function.
2027 public function testApiConvertItem()
2029 $result = api_convert_item(
2031 'network' => 'feed',
2032 'title' => 'item_title',
2033 // We need a long string to test that it is correctly cut
2034 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2035 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2036 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2037 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2038 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2039 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2040 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2041 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2042 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2043 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2044 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2045 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2046 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2047 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2048 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2049 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2050 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2051 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2052 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2053 'repellat officia illum quos impedit quam iste esse unde qui '.
2054 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2055 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2056 'et sed beatae nihil ullam temporibus corporis ratione blanditiis'
2059 $this->assertStringStartsWith('item_title', $result['text']);
2060 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2064 * Test the api_convert_item() function with an empty item body.
2067 public function testApiConvertItemWithoutBody()
2069 $result = api_convert_item(
2071 'network' => 'feed',
2072 'title' => 'item_title',
2074 'plink' => 'item_plink'
2077 $this->assertEquals('item_title', $result['text']);
2078 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2082 * Test the api_convert_item() function with the title in the body.
2085 public function testApiConvertItemWithTitleInBody()
2087 $result = api_convert_item(
2089 'title' => 'item_title',
2090 'body' => 'item_title item_body'
2093 $this->assertEquals('item_title item_body', $result['text']);
2094 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2098 * Test the api_get_attachments() function.
2101 public function testApiGetAttachments()
2104 $this->assertEmpty(api_get_attachments($body));
2108 * Test the api_get_attachments() function with an img tag.
2111 public function testApiGetAttachmentsWithImage()
2113 $body = '[img]img_url[/img]';
2114 $this->assertInternalType('array', api_get_attachments($body));
2118 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2121 public function testApiGetAttachmentsWithImageAndAndStatus()
2123 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2124 $body = '[img]img_url[/img]';
2125 $this->assertInternalType('array', api_get_attachments($body));
2129 * Test the api_get_entitities() function.
2132 public function testApiGetEntitities()
2135 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2139 * Test the api_get_entitities() function with the include_entities parameter.
2142 public function testApiGetEntititiesWithIncludeEntities()
2144 $_REQUEST['include_entities'] = 'true';
2146 $result = api_get_entitities($text, 'bbcode');
2147 $this->assertInternalType('array', $result['hashtags']);
2148 $this->assertInternalType('array', $result['symbols']);
2149 $this->assertInternalType('array', $result['urls']);
2150 $this->assertInternalType('array', $result['user_mentions']);
2154 * Test the api_format_items_embeded_images() function.
2157 public function testApiFormatItemsEmbededImages()
2159 $this->assertEquals(
2160 'text http://localhost/display/item_guid',
2161 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2166 * Test the api_contactlink_to_array() function.
2169 public function testApiContactlinkToArray()
2171 $this->assertEquals(
2176 api_contactlink_to_array('text')
2181 * Test the api_contactlink_to_array() function with an URL.
2184 public function testApiContactlinkToArrayWithUrl()
2186 $this->assertEquals(
2188 'name' => ['link_text'],
2191 api_contactlink_to_array('text <a href="url">link_text</a>')
2196 * Test the api_format_items_activities() function.
2199 public function testApiFormatItemsActivities()
2202 $result = api_format_items_activities($item);
2203 $this->assertArrayHasKey('like', $result);
2204 $this->assertArrayHasKey('dislike', $result);
2205 $this->assertArrayHasKey('attendyes', $result);
2206 $this->assertArrayHasKey('attendno', $result);
2207 $this->assertArrayHasKey('attendmaybe', $result);
2211 * Test the api_format_items_activities() function with an XML result.
2214 public function testApiFormatItemsActivitiesWithXml()
2217 $result = api_format_items_activities($item, 'xml');
2218 $this->assertArrayHasKey('friendica:like', $result);
2219 $this->assertArrayHasKey('friendica:dislike', $result);
2220 $this->assertArrayHasKey('friendica:attendyes', $result);
2221 $this->assertArrayHasKey('friendica:attendno', $result);
2222 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2226 * Test the api_format_items_profiles() function.
2229 public function testApiFormatItemsProfiles()
2232 'id' => 'profile_id',
2233 'profile-name' => 'profile_name',
2234 'is-default' => true,
2235 'hide-friends' => true,
2236 'photo' => 'profile_photo',
2237 'thumb' => 'profile_thumb',
2239 'net-publish' => true,
2240 'pdesc' => 'description',
2241 'dob' => 'date_of_birth',
2242 'address' => 'address',
2243 'locality' => 'city',
2244 'region' => 'region',
2245 'postal-code' => 'postal_code',
2246 'country-name' => 'country',
2247 'hometown' => 'hometown',
2248 'gender' => 'gender',
2249 'marital' => 'marital',
2250 'with' => 'marital_with',
2251 'howlong' => 'marital_since',
2252 'sexual' => 'sexual',
2253 'politic' => 'politic',
2254 'religion' => 'religion',
2255 'pub_keywords' => 'public_keywords',
2256 'prv_keywords' => 'private_keywords',
2259 'dislikes' => 'dislikes',
2265 'interest' => 'interest',
2266 'romance' => 'romance',
2268 'education' => 'education',
2269 'contact' => 'social_networks',
2270 'homepage' => 'homepage'
2272 $result = api_format_items_profiles($profile_row);
2273 $this->assertEquals(
2275 'profile_id' => 'profile_id',
2276 'profile_name' => 'profile_name',
2277 'is_default' => true,
2278 'hide_friends' => true,
2279 'profile_photo' => 'profile_photo',
2280 'profile_thumb' => 'profile_thumb',
2282 'net_publish' => true,
2283 'description' => 'description',
2284 'date_of_birth' => 'date_of_birth',
2285 'address' => 'address',
2287 'region' => 'region',
2288 'postal_code' => 'postal_code',
2289 'country' => 'country',
2290 'hometown' => 'hometown',
2291 'gender' => 'gender',
2292 'marital' => 'marital',
2293 'marital_with' => 'marital_with',
2294 'marital_since' => 'marital_since',
2295 'sexual' => 'sexual',
2296 'politic' => 'politic',
2297 'religion' => 'religion',
2298 'public_keywords' => 'public_keywords',
2299 'private_keywords' => 'private_keywords',
2302 'dislikes' => 'dislikes',
2308 'interest' => 'interest',
2309 'romance' => 'romance',
2311 'education' => 'education',
2312 'social_networks' => 'social_networks',
2313 'homepage' => 'homepage',
2321 * Test the api_format_items() function.
2324 public function testApiFormatItems()
2328 'item_network' => 'item_network',
2333 $result = api_format_items($items, [], true);
2334 foreach ($result as $status) {
2335 $this->assertStatus($status);
2340 * Test the api_format_items() function with an XML result.
2343 public function testApiFormatItemsWithXml()
2350 $result = api_format_items($items, [], true, 'xml');
2351 foreach ($result as $status) {
2352 $this->assertStatus($status);
2357 * Test the api_format_items() function.
2360 public function testApiAccountRateLimitStatus()
2362 $result = api_account_rate_limit_status('json');
2363 $this->assertEquals(150, $result['hash']['remaining_hits']);
2364 $this->assertEquals(150, $result['hash']['hourly_limit']);
2365 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2369 * Test the api_format_items() function with an XML result.
2372 public function testApiAccountRateLimitStatusWithXml()
2374 $result = api_account_rate_limit_status('xml');
2375 $this->assertXml($result, 'hash');
2379 * Test the api_help_test() function.
2382 public function testApiHelpTest()
2384 $result = api_help_test('json');
2385 $this->assertEquals(['ok' => 'ok'], $result);
2389 * Test the api_help_test() function with an XML result.
2392 public function testApiHelpTestWithXml()
2394 $this->markTestIncomplete('Triggers this error: "key() expects parameter 1 to be array, string given"');
2395 $result = api_help_test('xml');
2396 $this->assertXml($result, 'ok');
2400 * Test the api_lists_list() function.
2403 public function testApiListsList()
2405 $result = api_lists_list('json');
2406 $this->assertEquals(['lists_list' => []], $result);
2410 * Test the api_lists_ownerships() function.
2413 public function testApiListsOwnerships()
2415 $result = api_lists_ownerships('json');
2416 foreach ($result['lists']['lists'] as $list) {
2417 $this->assertList($list);
2422 * Test the api_lists_ownerships() function without an authenticated user.
2424 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2426 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2428 $_SESSION['authenticated'] = false;
2429 api_lists_ownerships('json');
2433 * Test the api_lists_statuses() function.
2434 * @expectedException Friendica\Network\HTTPException\BadRequestException
2437 public function testApiListsStatuses()
2439 api_lists_statuses('json');
2443 * Test the api_lists_statuses() function with a list ID.
2446 public function testApiListsStatusesWithListId()
2448 $_REQUEST['list_id'] = 1;
2449 $_REQUEST['page'] = -1;
2450 $_REQUEST['max_id'] = 10;
2451 $result = api_lists_statuses('json');
2452 foreach ($result['status'] as $status) {
2453 $this->assertStatus($status);
2458 * Test the api_lists_statuses() function with a list ID and a RSS result.
2461 public function testApiListsStatusesWithListIdAndRss()
2463 $_REQUEST['list_id'] = 1;
2464 $result = api_lists_statuses('rss');
2465 $this->assertXml($result, 'statuses');
2469 * Test the api_lists_statuses() function with an unallowed user.
2471 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2473 public function testApiListsStatusesWithUnallowedUser()
2475 $_SESSION['allow_api'] = false;
2476 $_GET['screen_name'] = $this->selfUser['nick'];
2477 api_lists_statuses('json');
2481 * Test the api_statuses_f() function.
2484 public function testApiStatusesFWithFriends()
2487 $result = api_statuses_f('friends');
2488 $this->assertArrayHasKey('user', $result);
2492 * Test the api_statuses_f() function.
2495 public function testApiStatusesFWithFollowers()
2497 $result = api_statuses_f('followers');
2498 $this->assertArrayHasKey('user', $result);
2502 * Test the api_statuses_f() function.
2505 public function testApiStatusesFWithBlocks()
2507 $result = api_statuses_f('blocks');
2508 $this->assertArrayHasKey('user', $result);
2512 * Test the api_statuses_f() function.
2515 public function testApiStatusesFWithIncoming()
2517 $result = api_statuses_f('incoming');
2518 $this->assertArrayHasKey('user', $result);
2522 * Test the api_statuses_f() function an undefined cursor GET variable.
2525 public function testApiStatusesFWithUndefinedCursor()
2527 $_GET['cursor'] = 'undefined';
2528 $this->assertFalse(api_statuses_f('friends'));
2532 * Test the api_statuses_friends() function.
2535 public function testApiStatusesFriends()
2537 $result = api_statuses_friends('json');
2538 $this->assertArrayHasKey('user', $result);
2542 * Test the api_statuses_friends() function an undefined cursor GET variable.
2545 public function testApiStatusesFriendsWithUndefinedCursor()
2547 $_GET['cursor'] = 'undefined';
2548 $this->assertFalse(api_statuses_friends('json'));
2552 * Test the api_statuses_followers() function.
2555 public function testApiStatusesFollowers()
2557 $result = api_statuses_followers('json');
2558 $this->assertArrayHasKey('user', $result);
2562 * Test the api_statuses_followers() function an undefined cursor GET variable.
2565 public function testApiStatusesFollowersWithUndefinedCursor()
2567 $_GET['cursor'] = 'undefined';
2568 $this->assertFalse(api_statuses_followers('json'));
2572 * Test the api_blocks_list() function.
2575 public function testApiBlocksList()
2577 $result = api_blocks_list('json');
2578 $this->assertArrayHasKey('user', $result);
2582 * Test the api_blocks_list() function an undefined cursor GET variable.
2585 public function testApiBlocksListWithUndefinedCursor()
2587 $_GET['cursor'] = 'undefined';
2588 $this->assertFalse(api_blocks_list('json'));
2592 * Test the api_friendships_incoming() function.
2595 public function testApiFriendshipsIncoming()
2597 $result = api_friendships_incoming('json');
2598 $this->assertArrayHasKey('id', $result);
2602 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2605 public function testApiFriendshipsIncomingWithUndefinedCursor()
2607 $_GET['cursor'] = 'undefined';
2608 $this->assertFalse(api_friendships_incoming('json'));
2612 * Test the api_statusnet_config() function.
2615 public function testApiStatusnetConfig()
2617 $result = api_statusnet_config('json');
2618 $this->assertEquals('localhost', $result['config']['site']['server']);
2619 $this->assertEquals('default', $result['config']['site']['theme']);
2620 $this->assertEquals('http://localhost/images/friendica-64.png', $result['config']['site']['logo']);
2621 $this->assertTrue($result['config']['site']['fancy']);
2622 $this->assertEquals('en', $result['config']['site']['language']);
2623 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2624 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2625 $this->assertEquals('false', $result['config']['site']['private']);
2626 $this->assertEquals('false', $result['config']['site']['ssl']);
2627 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2631 * Test the api_statusnet_version() function.
2634 public function testApiStatusnetVersion()
2636 $result = api_statusnet_version('json');
2637 $this->assertEquals('0.9.7', $result['version']);
2641 * Test the api_ff_ids() function.
2644 public function testApiFfIds()
2646 $result = api_ff_ids('json');
2647 $this->assertNull($result);
2651 * Test the api_ff_ids() function with a result.
2654 public function testApiFfIdsWithResult()
2656 $this->markTestIncomplete();
2660 * Test the api_ff_ids() function without an authenticated user.
2662 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2664 public function testApiFfIdsWithoutAuthenticatedUser()
2666 $_SESSION['authenticated'] = false;
2671 * Test the api_friends_ids() function.
2674 public function testApiFriendsIds()
2676 $result = api_friends_ids('json');
2677 $this->assertNull($result);
2681 * Test the api_followers_ids() function.
2684 public function testApiFollowersIds()
2686 $result = api_followers_ids('json');
2687 $this->assertNull($result);
2691 * Test the api_direct_messages_new() function.
2694 public function testApiDirectMessagesNew()
2696 $result = api_direct_messages_new('json');
2697 $this->assertNull($result);
2701 * Test the api_direct_messages_new() function without an authenticated user.
2703 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2705 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2707 $_SESSION['authenticated'] = false;
2708 api_direct_messages_new('json');
2712 * Test the api_direct_messages_new() function with an user ID.
2715 public function testApiDirectMessagesNewWithUserId()
2717 $_POST['text'] = 'message_text';
2718 $_POST['user_id'] = $this->otherUser['id'];
2719 $result = api_direct_messages_new('json');
2720 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2724 * Test the api_direct_messages_new() function with a screen name.
2727 public function testApiDirectMessagesNewWithScreenName()
2729 $_POST['text'] = 'message_text';
2730 $_POST['screen_name'] = $this->otherUser['nick'];
2731 $result = api_direct_messages_new('json');
2732 $this->assertEquals(1, $result['direct_message']['id']);
2733 $this->assertContains('message_text', $result['direct_message']['text']);
2734 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2735 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2739 * Test the api_direct_messages_new() function with a title.
2742 public function testApiDirectMessagesNewWithTitle()
2744 $_POST['text'] = 'message_text';
2745 $_POST['screen_name'] = $this->otherUser['nick'];
2746 $_REQUEST['title'] = 'message_title';
2747 $result = api_direct_messages_new('json');
2748 $this->assertEquals(1, $result['direct_message']['id']);
2749 $this->assertContains('message_text', $result['direct_message']['text']);
2750 $this->assertContains('message_title', $result['direct_message']['text']);
2751 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2752 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2756 * Test the api_direct_messages_new() function with an RSS result.
2759 public function testApiDirectMessagesNewWithRss()
2761 $_POST['text'] = 'message_text';
2762 $_POST['screen_name'] = $this->otherUser['nick'];
2763 $result = api_direct_messages_new('rss');
2764 $this->assertXml($result, 'direct-messages');
2768 * Test the api_direct_messages_destroy() function.
2770 * @expectedException Friendica\Network\HTTPException\BadRequestException
2772 public function testApiDirectMessagesDestroy()
2774 api_direct_messages_destroy('json');
2778 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2781 public function testApiDirectMessagesDestroyWithVerbose()
2783 $_GET['friendica_verbose'] = 'true';
2784 $result = api_direct_messages_destroy('json');
2785 $this->assertEquals(
2788 'result' => 'error',
2789 'message' => 'message id or parenturi not specified'
2797 * Test the api_direct_messages_destroy() function without an authenticated user.
2799 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2801 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2803 $_SESSION['authenticated'] = false;
2804 api_direct_messages_destroy('json');
2808 * Test the api_direct_messages_destroy() function with a non-zero ID.
2810 * @expectedException Friendica\Network\HTTPException\BadRequestException
2812 public function testApiDirectMessagesDestroyWithId()
2814 $_REQUEST['id'] = 1;
2815 api_direct_messages_destroy('json');
2819 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2822 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2824 $_REQUEST['id'] = 1;
2825 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2826 $_GET['friendica_verbose'] = 'true';
2827 $result = api_direct_messages_destroy('json');
2828 $this->assertEquals(
2831 'result' => 'error',
2832 'message' => 'message id not in database'
2840 * Test the api_direct_messages_destroy() function with a non-zero ID.
2843 public function testApiDirectMessagesDestroyWithCorrectId()
2845 $this->markTestIncomplete('We need to add a dataset for this.');
2849 * Test the api_direct_messages_box() function.
2852 public function testApiDirectMessagesBoxWithSentbox()
2854 $_REQUEST['page'] = -1;
2855 $_REQUEST['max_id'] = 10;
2856 $result = api_direct_messages_box('json', 'sentbox', 'false');
2857 $this->assertArrayHasKey('direct_message', $result);
2861 * Test the api_direct_messages_box() function.
2864 public function testApiDirectMessagesBoxWithConversation()
2866 $result = api_direct_messages_box('json', 'conversation', 'false');
2867 $this->assertArrayHasKey('direct_message', $result);
2871 * Test the api_direct_messages_box() function.
2874 public function testApiDirectMessagesBoxWithAll()
2876 $result = api_direct_messages_box('json', 'all', 'false');
2877 $this->assertArrayHasKey('direct_message', $result);
2881 * Test the api_direct_messages_box() function.
2884 public function testApiDirectMessagesBoxWithInbox()
2886 $result = api_direct_messages_box('json', 'inbox', 'false');
2887 $this->assertArrayHasKey('direct_message', $result);
2891 * Test the api_direct_messages_box() function.
2894 public function testApiDirectMessagesBoxWithVerbose()
2896 $result = api_direct_messages_box('json', 'sentbox', 'true');
2897 $this->assertEquals(
2900 'result' => 'error',
2901 'message' => 'no mails available'
2909 * Test the api_direct_messages_box() function with a RSS result.
2912 public function testApiDirectMessagesBoxWithRss()
2914 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2915 $this->assertXml($result, 'direct-messages');
2919 * Test the api_direct_messages_box() function without an authenticated user.
2921 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2923 public function testApiDirectMessagesBoxWithUnallowedUser()
2925 $_SESSION['allow_api'] = false;
2926 $_GET['screen_name'] = $this->selfUser['nick'];
2927 api_direct_messages_box('json', 'sentbox', 'false');
2931 * Test the api_direct_messages_sentbox() function.
2934 public function testApiDirectMessagesSentbox()
2936 $result = api_direct_messages_sentbox('json');
2937 $this->assertArrayHasKey('direct_message', $result);
2941 * Test the api_direct_messages_inbox() function.
2944 public function testApiDirectMessagesInbox()
2946 $result = api_direct_messages_inbox('json');
2947 $this->assertArrayHasKey('direct_message', $result);
2951 * Test the api_direct_messages_all() function.
2954 public function testApiDirectMessagesAll()
2956 $result = api_direct_messages_all('json');
2957 $this->assertArrayHasKey('direct_message', $result);
2961 * Test the api_direct_messages_conversation() function.
2964 public function testApiDirectMessagesConversation()
2966 $result = api_direct_messages_conversation('json');
2967 $this->assertArrayHasKey('direct_message', $result);
2971 * Test the api_oauth_request_token() function.
2974 public function testApiOauthRequestToken()
2976 $this->markTestIncomplete('killme() kills phpunit as well');
2980 * Test the api_oauth_access_token() function.
2983 public function testApiOauthAccessToken()
2985 $this->markTestIncomplete('killme() kills phpunit as well');
2989 * Test the api_fr_photoalbum_delete() function.
2991 * @expectedException Friendica\Network\HTTPException\BadRequestException
2993 public function testApiFrPhotoalbumDelete()
2995 api_fr_photoalbum_delete('json');
2999 * Test the api_fr_photoalbum_delete() function with an album name.
3001 * @expectedException Friendica\Network\HTTPException\BadRequestException
3003 public function testApiFrPhotoalbumDeleteWithAlbum()
3005 $_REQUEST['album'] = 'album_name';
3006 api_fr_photoalbum_delete('json');
3010 * Test the api_fr_photoalbum_delete() function with an album name.
3013 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3015 $this->markTestIncomplete('We need to add a dataset for this.');
3019 * Test the api_fr_photoalbum_delete() function.
3021 * @expectedException Friendica\Network\HTTPException\BadRequestException
3023 public function testApiFrPhotoalbumUpdate()
3025 api_fr_photoalbum_update('json');
3029 * Test the api_fr_photoalbum_delete() function with an album name.
3031 * @expectedException Friendica\Network\HTTPException\BadRequestException
3033 public function testApiFrPhotoalbumUpdateWithAlbum()
3035 $_REQUEST['album'] = 'album_name';
3036 api_fr_photoalbum_update('json');
3040 * Test the api_fr_photoalbum_delete() function with an album name.
3042 * @expectedException Friendica\Network\HTTPException\BadRequestException
3044 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3046 $_REQUEST['album'] = 'album_name';
3047 $_REQUEST['album_new'] = 'album_name';
3048 api_fr_photoalbum_update('json');
3052 * Test the api_fr_photoalbum_update() function without an authenticated user.
3054 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3056 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3058 $_SESSION['authenticated'] = false;
3059 api_fr_photoalbum_update('json');
3063 * Test the api_fr_photoalbum_delete() function with an album name.
3066 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3068 $this->markTestIncomplete('We need to add a dataset for this.');
3072 * Test the api_fr_photos_list() function.
3075 public function testApiFrPhotosList()
3077 $result = api_fr_photos_list('json');
3078 $this->assertArrayHasKey('photo', $result);
3082 * Test the api_fr_photos_list() function without an authenticated user.
3084 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3086 public function testApiFrPhotosListWithoutAuthenticatedUser()
3088 $_SESSION['authenticated'] = false;
3089 api_fr_photos_list('json');
3093 * Test the api_fr_photo_create_update() function.
3095 * @expectedException Friendica\Network\HTTPException\BadRequestException
3097 public function testApiFrPhotoCreateUpdate()
3099 api_fr_photo_create_update('json');
3103 * Test the api_fr_photo_create_update() function without an authenticated user.
3105 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3107 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3109 $_SESSION['authenticated'] = false;
3110 api_fr_photo_create_update('json');
3114 * Test the api_fr_photo_create_update() function with an album name.
3116 * @expectedException Friendica\Network\HTTPException\BadRequestException
3118 public function testApiFrPhotoCreateUpdateWithAlbum()
3120 $_REQUEST['album'] = 'album_name';
3121 api_fr_photo_create_update('json');
3125 * Test the api_fr_photo_create_update() function with the update mode.
3128 public function testApiFrPhotoCreateUpdateWithUpdate()
3130 $this->markTestIncomplete('We need to create a dataset for this');
3134 * Test the api_fr_photo_create_update() function with an uploaded file.
3137 public function testApiFrPhotoCreateUpdateWithFile()
3139 $this->markTestIncomplete();
3143 * Test the api_fr_photo_delete() function.
3145 * @expectedException Friendica\Network\HTTPException\BadRequestException
3147 public function testApiFrPhotoDelete()
3149 api_fr_photo_delete('json');
3153 * Test the api_fr_photo_delete() function without an authenticated user.
3155 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3157 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3159 $_SESSION['authenticated'] = false;
3160 api_fr_photo_delete('json');
3164 * Test the api_fr_photo_delete() function with a photo ID.
3166 * @expectedException Friendica\Network\HTTPException\BadRequestException
3168 public function testApiFrPhotoDeleteWithPhotoId()
3170 $_REQUEST['photo_id'] = 1;
3171 api_fr_photo_delete('json');
3175 * Test the api_fr_photo_delete() function with a correct photo ID.
3178 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3180 $this->markTestIncomplete('We need to create a dataset for this.');
3184 * Test the api_fr_photo_detail() function.
3186 * @expectedException Friendica\Network\HTTPException\BadRequestException
3188 public function testApiFrPhotoDetail()
3190 api_fr_photo_detail('json');
3194 * Test the api_fr_photo_detail() function without an authenticated user.
3196 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3198 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3200 $_SESSION['authenticated'] = false;
3201 api_fr_photo_detail('json');
3205 * Test the api_fr_photo_detail() function with a photo ID.
3207 * @expectedException Friendica\Network\HTTPException\NotFoundException
3209 public function testApiFrPhotoDetailWithPhotoId()
3211 $_REQUEST['photo_id'] = 1;
3212 api_fr_photo_detail('json');
3216 * Test the api_fr_photo_detail() function with a correct photo ID.
3219 public function testApiFrPhotoDetailCorrectPhotoId()
3221 $this->markTestIncomplete('We need to create a dataset for this.');
3225 * Test the api_account_update_profile_image() function.
3227 * @expectedException Friendica\Network\HTTPException\BadRequestException
3229 public function testApiAccountUpdateProfileImage()
3231 api_account_update_profile_image('json');
3235 * Test the api_account_update_profile_image() function without an authenticated user.
3237 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3239 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3241 $_SESSION['authenticated'] = false;
3242 api_account_update_profile_image('json');
3246 * Test the api_account_update_profile_image() function with an uploaded file.
3248 * @expectedException Friendica\Network\HTTPException\BadRequestException
3250 public function testApiAccountUpdateProfileImageWithUpload()
3252 $this->markTestIncomplete();
3257 * Test the api_account_update_profile() function.
3260 public function testApiAccountUpdateProfile()
3262 $_POST['name'] = 'new_name';
3263 $_POST['description'] = 'new_description';
3264 $result = api_account_update_profile('json');
3265 // We can't use assertSelfUser() here because the user object is missing some properties.
3266 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3267 $this->assertEquals('Friendica', $result['user']['location']);
3268 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3269 $this->assertEquals('dfrn', $result['user']['network']);
3270 $this->assertEquals('new_name', $result['user']['name']);
3271 $this->assertEquals('new_description', $result['user']['description']);
3275 * Test the check_acl_input() function.
3278 public function testCheckAclInput()
3280 $result = check_acl_input('<aclstring>');
3281 // Where does this result come from?
3282 $this->assertEquals(1, $result);
3286 * Test the check_acl_input() function with an empty ACL string.
3289 public function testCheckAclInputWithEmptyAclString()
3291 $result = check_acl_input(' ');
3292 $this->assertFalse($result);
3296 * Test the save_media_to_database() function.
3299 public function testSaveMediaToDatabase()
3301 $this->markTestIncomplete();
3305 * Test the post_photo_item() function.
3308 public function testPostPhotoItem()
3310 $this->markTestIncomplete();
3314 * Test the prepare_photo_data() function.
3317 public function testPreparePhotoData()
3319 $this->markTestIncomplete();
3323 * Test the api_friendica_remoteauth() function.
3325 * @expectedException Friendica\Network\HTTPException\BadRequestException
3327 public function testApiFriendicaRemoteauth()
3329 api_friendica_remoteauth();
3333 * Test the api_friendica_remoteauth() function with an URL.
3335 * @expectedException Friendica\Network\HTTPException\BadRequestException
3337 public function testApiFriendicaRemoteauthWithUrl()
3339 $_GET['url'] = 'url';
3340 $_GET['c_url'] = 'url';
3341 api_friendica_remoteauth();
3345 * Test the api_friendica_remoteauth() function with a correct URL.
3348 public function testApiFriendicaRemoteauthWithCorrectUrl()
3350 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3351 $_GET['url'] = 'url';
3352 $_GET['c_url'] = $this->selfUser['nurl'];
3353 api_friendica_remoteauth();
3357 * Test the api_share_as_retweet() function.
3360 public function testApiShareAsRetweet()
3363 $result = api_share_as_retweet($item);
3364 $this->assertFalse($result);
3368 * Test the api_share_as_retweet() function with a valid item.
3371 public function testApiShareAsRetweetWithValidItem()
3373 $this->markTestIncomplete();
3377 * Test the api_get_nick() function.
3380 public function testApiGetNick()
3382 $result = api_get_nick($this->otherUser['nurl']);
3383 $this->assertEquals('othercontact', $result);
3387 * Test the api_get_nick() function with a wrong URL.
3390 public function testApiGetNickWithWrongUrl()
3392 $result = api_get_nick('wrong_url');
3393 $this->assertFalse($result);
3397 * Test the api_in_reply_to() function.
3400 public function testApiInReplyTo()
3402 $result = api_in_reply_to([]);
3403 $this->assertArrayHasKey('status_id', $result);
3404 $this->assertArrayHasKey('user_id', $result);
3405 $this->assertArrayHasKey('status_id_str', $result);
3406 $this->assertArrayHasKey('user_id_str', $result);
3407 $this->assertArrayHasKey('screen_name', $result);
3411 * Test the api_in_reply_to() function with a valid item.
3414 public function testApiInReplyToWithValidItem()
3416 $this->markTestIncomplete();
3420 * Test the api_clean_plain_items() function.
3423 public function testApiCleanPlainItems()
3425 $_REQUEST['include_entities'] = 'true';
3426 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3427 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3431 * Test the api_clean_attachments() function.
3434 public function testApiCleanAttachments()
3436 $this->markTestIncomplete();
3440 * Test the api_best_nickname() function.
3443 public function testApiBestNickname()
3446 $result = api_best_nickname($contacts);
3447 $this->assertNull($result);
3451 * Test the api_best_nickname() function with contacts.
3454 public function testApiBestNicknameWithContacts()
3456 $this->markTestIncomplete();
3460 * Test the api_friendica_group_show() function.
3463 public function testApiFriendicaGroupShow()
3465 $this->markTestIncomplete();
3469 * Test the api_friendica_group_delete() function.
3472 public function testApiFriendicaGroupDelete()
3474 $this->markTestIncomplete();
3478 * Test the api_lists_destroy() function.
3481 public function testApiListsDestroy()
3483 $this->markTestIncomplete();
3487 * Test the group_create() function.
3490 public function testGroupCreate()
3492 $this->markTestIncomplete();
3496 * Test the api_friendica_group_create() function.
3499 public function testApiFriendicaGroupCreate()
3501 $this->markTestIncomplete();
3505 * Test the api_lists_create() function.
3508 public function testApiListsCreate()
3510 $this->markTestIncomplete();
3514 * Test the api_friendica_group_update() function.
3517 public function testApiFriendicaGroupUpdate()
3519 $this->markTestIncomplete();
3523 * Test the api_lists_update() function.
3526 public function testApiListsUpdate()
3528 $this->markTestIncomplete();
3532 * Test the api_friendica_activity() function.
3535 public function testApiFriendicaActivity()
3537 $this->markTestIncomplete();
3541 * Test the api_friendica_notification() function.
3543 * @expectedException Friendica\Network\HTTPException\BadRequestException
3545 public function testApiFriendicaNotification()
3547 api_friendica_notification('json');
3551 * Test the api_friendica_notification() function without an authenticated user.
3553 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3555 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3557 $_SESSION['authenticated'] = false;
3558 api_friendica_notification('json');
3562 * Test the api_friendica_notification() function with an argument count.
3565 public function testApiFriendicaNotificationWithArgumentCount()
3567 $this->app->argc = 3;
3568 $result = api_friendica_notification('json');
3569 $this->assertEquals(['note' => false], $result);
3573 * Test the api_friendica_notification() function with an XML result.
3576 public function testApiFriendicaNotificationWithXmlResult()
3578 $this->markTestIncomplete('Fails with "Invalid argument supplied for foreach()".');
3579 $this->app->argc = 3;
3580 $result = api_friendica_notification('xml');
3581 $this->assertXml($result, 'notes');
3585 * Test the api_friendica_notification_seen() function.
3588 public function testApiFriendicaNotificationSeen()
3590 $this->markTestIncomplete();
3594 * Test the api_friendica_direct_messages_setseen() function.
3597 public function testApiFriendicaDirectMessagesSetseen()
3599 $this->markTestIncomplete();
3603 * Test the api_friendica_direct_messages_search() function.
3606 public function testApiFriendicaDirectMessagesSearch()
3608 $this->markTestIncomplete();
3612 * Test the api_friendica_profile_show() function.
3615 public function testApiFriendicaProfileShow()
3617 $result = api_friendica_profile_show('json');
3618 // We can't use assertSelfUser() here because the user object is missing some properties.
3619 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3620 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3621 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3622 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3623 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3624 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3625 $this->assertFalse($result['$result']['multi_profiles']);
3629 * Test the api_friendica_profile_show() function with a profile ID.
3632 public function testApiFriendicaProfileShowWithProfileId()
3634 $this->markTestIncomplete('We need to add a dataset for this.');
3638 * Test the api_friendica_profile_show() function with a wrong profile ID.
3640 * @expectedException Friendica\Network\HTTPException\BadRequestException
3642 public function testApiFriendicaProfileShowWithWrongProfileId()
3644 $_REQUEST['profile_id'] = 666;
3645 api_friendica_profile_show('json');
3649 * Test the api_friendica_profile_show() function without an authenticated user.
3651 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3653 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3655 $_SESSION['authenticated'] = false;
3656 api_friendica_profile_show('json');
3660 * Test the api_saved_searches_list() function.
3663 public function testApiSavedSearchesList()
3665 $result = api_saved_searches_list('json');
3666 $this->assertEquals(1, $result['terms'][0]['id']);
3667 $this->assertEquals(1, $result['terms'][0]['id_str']);
3668 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3669 $this->assertEquals('Saved search', $result['terms'][0]['query']);