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'];
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 '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 'type' => 'image/png'
1117 $result = api_statuses_update('json');
1118 $this->assertStatus($result['status']);
1122 * Test the api_statuses_update() function with an HTML status.
1125 public function testApiStatusesUpdateWithHtml()
1127 $_GET['htmlstatus'] = '<b>Status content</b>';
1129 $result = api_statuses_update('json');
1130 $this->assertStatus($result['status']);
1134 * Test the api_statuses_update() function without an authenticated user.
1136 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1138 public function testApiStatusesUpdateWithoutAuthenticatedUser()
1140 $_SESSION['authenticated'] = false;
1141 api_statuses_update('json');
1145 * Test the api_statuses_update() function with a parent status.
1148 public function testApiStatusesUpdateWithParent()
1150 $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
1154 * Test the api_statuses_update() function with a media_ids parameter.
1157 public function testApiStatusesUpdateWithMediaIds()
1159 $this->markTestIncomplete();
1163 * Test the api_statuses_update() function with the throttle limit reached.
1166 public function testApiStatusesUpdateWithDayThrottleReached()
1168 $this->markTestIncomplete();
1172 * Test the api_media_upload() function.
1174 * @expectedException Friendica\Network\HTTPException\BadRequestException
1176 public function testApiMediaUpload()
1182 * Test the api_media_upload() function without an authenticated user.
1184 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1186 public function testApiMediaUploadWithoutAuthenticatedUser()
1188 $_SESSION['authenticated'] = false;
1193 * Test the api_media_upload() function with an invalid uploaded media.
1195 * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
1197 public function testApiMediaUploadWithMedia()
1208 * Test the api_media_upload() function with an valid uploaded media.
1211 public function testApiMediaUploadWithValidMedia()
1219 'tmp_name' => $this->getTempImage(),
1220 'type' => 'image/png'
1226 $result = api_media_upload();
1227 $this->assertEquals('image/png', $result['media']['image']['image_type']);
1228 $this->assertEquals(1, $result['media']['image']['w']);
1229 $this->assertEquals(1, $result['media']['image']['h']);
1233 * Test the api_status_show() function.
1236 public function testApiStatusShow()
1238 $result = api_status_show('json');
1239 $this->assertStatus($result['status']);
1243 * Test the api_status_show() function with an XML result.
1246 public function testApiStatusShowWithXml()
1248 $result = api_status_show('xml');
1249 $this->assertXml($result, 'statuses');
1253 * Test the api_status_show() function with a raw result.
1256 public function testApiStatusShowWithRaw()
1258 $this->assertStatus(api_status_show('raw'));
1262 * Test the api_users_show() function.
1265 public function testApiUsersShow()
1267 $result = api_users_show('json');
1268 // We can't use assertSelfUser() here because the user object is missing some properties.
1269 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
1270 $this->assertEquals('Friendica', $result['user']['location']);
1271 $this->assertEquals($this->selfUser['name'], $result['user']['name']);
1272 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
1273 $this->assertEquals('dfrn', $result['user']['network']);
1274 $this->assertTrue($result['user']['verified']);
1278 * Test the api_users_show() function with an XML result.
1281 public function testApiUsersShowWithXml()
1283 $result = api_users_show('xml');
1284 $this->assertXml($result, 'statuses');
1288 * Test the api_users_search() function.
1291 public function testApiUsersSearch()
1293 $_GET['q'] = 'othercontact';
1294 $result = api_users_search('json');
1295 $this->assertOtherUser($result['users'][0]);
1299 * Test the api_users_search() function with an XML result.
1302 public function testApiUsersSearchWithXml()
1304 $_GET['q'] = 'othercontact';
1305 $result = api_users_search('xml');
1306 $this->assertXml($result, 'users');
1310 * Test the api_users_search() function without a GET q parameter.
1312 * @expectedException Friendica\Network\HTTPException\BadRequestException
1314 public function testApiUsersSearchWithoutQuery()
1316 api_users_search('json');
1320 * Test the api_users_lookup() function.
1322 * @expectedException Friendica\Network\HTTPException\NotFoundException
1324 public function testApiUsersLookup()
1326 api_users_lookup('json');
1330 * Test the api_users_lookup() function with an user ID.
1333 public function testApiUsersLookupWithUserId()
1335 $_REQUEST['user_id'] = $this->otherUser['id'];
1336 $result = api_users_lookup('json');
1337 $this->assertOtherUser($result['users'][0]);
1341 * Test the api_search() function.
1344 public function testApiSearch()
1346 $_REQUEST['q'] = 'reply';
1347 $_REQUEST['max_id'] = 10;
1348 $result = api_search('json');
1349 foreach ($result['status'] as $status) {
1350 $this->assertStatus($status);
1351 $this->assertContains('reply', $status['text'], null, true);
1356 * Test the api_search() function a count parameter.
1359 public function testApiSearchWithCount()
1361 $_REQUEST['q'] = 'reply';
1362 $_REQUEST['count'] = 20;
1363 $result = api_search('json');
1364 foreach ($result['status'] as $status) {
1365 $this->assertStatus($status);
1366 $this->assertContains('reply', $status['text'], null, true);
1371 * Test the api_search() function with an rpp parameter.
1374 public function testApiSearchWithRpp()
1376 $_REQUEST['q'] = 'reply';
1377 $_REQUEST['rpp'] = 20;
1378 $result = api_search('json');
1379 foreach ($result['status'] as $status) {
1380 $this->assertStatus($status);
1381 $this->assertContains('reply', $status['text'], null, true);
1387 * Test the api_search() function without an authenticated user.
1389 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1391 public function testApiSearchWithUnallowedUser()
1393 $_SESSION['allow_api'] = false;
1394 $_GET['screen_name'] = $this->selfUser['nick'];
1399 * Test the api_search() function without any GET query parameter.
1401 * @expectedException Friendica\Network\HTTPException\BadRequestException
1403 public function testApiSearchWithoutQuery()
1409 * Test the api_statuses_home_timeline() function.
1412 public function testApiStatusesHomeTimeline()
1414 $_REQUEST['max_id'] = 10;
1415 $_REQUEST['exclude_replies'] = true;
1416 $_REQUEST['conversation_id'] = 1;
1417 $result = api_statuses_home_timeline('json');
1418 $this->assertNotEmpty($result['status']);
1419 foreach ($result['status'] as $status) {
1420 $this->assertStatus($status);
1425 * Test the api_statuses_home_timeline() function with a negative page parameter.
1428 public function testApiStatusesHomeTimelineWithNegativePage()
1430 $_REQUEST['page'] = -2;
1431 $result = api_statuses_home_timeline('json');
1432 $this->assertNotEmpty($result['status']);
1433 foreach ($result['status'] as $status) {
1434 $this->assertStatus($status);
1439 * Test the api_statuses_home_timeline() with an unallowed user.
1441 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1443 public function testApiStatusesHomeTimelineWithUnallowedUser()
1445 $_SESSION['allow_api'] = false;
1446 $_GET['screen_name'] = $this->selfUser['nick'];
1447 api_statuses_home_timeline('json');
1451 * Test the api_statuses_home_timeline() function with an RSS result.
1454 public function testApiStatusesHomeTimelineWithRss()
1456 $result = api_statuses_home_timeline('rss');
1457 $this->assertXml($result, 'statuses');
1461 * Test the api_statuses_public_timeline() function.
1464 public function testApiStatusesPublicTimeline()
1466 $_REQUEST['max_id'] = 10;
1467 $_REQUEST['conversation_id'] = 1;
1468 $result = api_statuses_public_timeline('json');
1469 $this->assertNotEmpty($result['status']);
1470 foreach ($result['status'] as $status) {
1471 $this->assertStatus($status);
1476 * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
1479 public function testApiStatusesPublicTimelineWithExcludeReplies()
1481 $_REQUEST['max_id'] = 10;
1482 $_REQUEST['exclude_replies'] = true;
1483 $result = api_statuses_public_timeline('json');
1484 $this->assertNotEmpty($result['status']);
1485 foreach ($result['status'] as $status) {
1486 $this->assertStatus($status);
1491 * Test the api_statuses_public_timeline() function with a negative page parameter.
1494 public function testApiStatusesPublicTimelineWithNegativePage()
1496 $_REQUEST['page'] = -2;
1497 $result = api_statuses_public_timeline('json');
1498 $this->assertNotEmpty($result['status']);
1499 foreach ($result['status'] as $status) {
1500 $this->assertStatus($status);
1505 * Test the api_statuses_public_timeline() function with an unallowed user.
1507 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1509 public function testApiStatusesPublicTimelineWithUnallowedUser()
1511 $_SESSION['allow_api'] = false;
1512 $_GET['screen_name'] = $this->selfUser['nick'];
1513 api_statuses_public_timeline('json');
1517 * Test the api_statuses_public_timeline() function with an RSS result.
1520 public function testApiStatusesPublicTimelineWithRss()
1522 $result = api_statuses_public_timeline('rss');
1523 $this->assertXml($result, 'statuses');
1527 * Test the api_statuses_networkpublic_timeline() function.
1530 public function testApiStatusesNetworkpublicTimeline()
1532 $_REQUEST['max_id'] = 10;
1533 $result = api_statuses_networkpublic_timeline('json');
1534 $this->assertNotEmpty($result['status']);
1535 foreach ($result['status'] as $status) {
1536 $this->assertStatus($status);
1541 * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
1544 public function testApiStatusesNetworkpublicTimelineWithNegativePage()
1546 $_REQUEST['page'] = -2;
1547 $result = api_statuses_networkpublic_timeline('json');
1548 $this->assertNotEmpty($result['status']);
1549 foreach ($result['status'] as $status) {
1550 $this->assertStatus($status);
1555 * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
1557 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1559 public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
1561 $_SESSION['allow_api'] = false;
1562 $_GET['screen_name'] = $this->selfUser['nick'];
1563 api_statuses_networkpublic_timeline('json');
1567 * Test the api_statuses_networkpublic_timeline() function with an RSS result.
1570 public function testApiStatusesNetworkpublicTimelineWithRss()
1572 $result = api_statuses_networkpublic_timeline('rss');
1573 $this->assertXml($result, 'statuses');
1577 * Test the api_statuses_show() function.
1579 * @expectedException Friendica\Network\HTTPException\BadRequestException
1581 public function testApiStatusesShow()
1583 api_statuses_show('json');
1587 * Test the api_statuses_show() function with an ID.
1590 public function testApiStatusesShowWithId()
1592 $this->app->argv[3] = 1;
1593 $result = api_statuses_show('json');
1594 $this->assertStatus($result['status']);
1598 * Test the api_statuses_show() function with the conversation parameter.
1601 public function testApiStatusesShowWithConversation()
1603 $this->app->argv[3] = 1;
1604 $_REQUEST['conversation'] = 1;
1605 $result = api_statuses_show('json');
1606 $this->assertNotEmpty($result['status']);
1607 foreach ($result['status'] as $status) {
1608 $this->assertStatus($status);
1613 * Test the api_statuses_show() function with an unallowed user.
1615 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1617 public function testApiStatusesShowWithUnallowedUser()
1619 $_SESSION['allow_api'] = false;
1620 $_GET['screen_name'] = $this->selfUser['nick'];
1621 api_statuses_show('json');
1625 * Test the api_conversation_show() function.
1627 * @expectedException Friendica\Network\HTTPException\BadRequestException
1629 public function testApiConversationShow()
1631 api_conversation_show('json');
1635 * Test the api_conversation_show() function with an ID.
1638 public function testApiConversationShowWithId()
1640 $this->app->argv[3] = 1;
1641 $_REQUEST['max_id'] = 10;
1642 $_REQUEST['page'] = -2;
1643 $result = api_conversation_show('json');
1644 $this->assertNotEmpty($result['status']);
1645 foreach ($result['status'] as $status) {
1646 $this->assertStatus($status);
1651 * Test the api_conversation_show() function with an unallowed user.
1653 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1655 public function testApiConversationShowWithUnallowedUser()
1657 $_SESSION['allow_api'] = false;
1658 $_GET['screen_name'] = $this->selfUser['nick'];
1659 api_conversation_show('json');
1663 * Test the api_statuses_repeat() function.
1665 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1667 public function testApiStatusesRepeat()
1669 api_statuses_repeat('json');
1673 * Test the api_statuses_repeat() function without an authenticated user.
1675 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1677 public function testApiStatusesRepeatWithoutAuthenticatedUser()
1679 $_SESSION['authenticated'] = false;
1680 api_statuses_repeat('json');
1684 * Test the api_statuses_repeat() function with an ID.
1687 public function testApiStatusesRepeatWithId()
1689 $this->app->argv[3] = 1;
1690 $result = api_statuses_repeat('json');
1691 $this->assertStatus($result['status']);
1693 // Also test with a shared status
1694 $this->app->argv[3] = 5;
1695 $result = api_statuses_repeat('json');
1696 $this->assertStatus($result['status']);
1700 * Test the api_statuses_destroy() function.
1702 * @expectedException Friendica\Network\HTTPException\BadRequestException
1704 public function testApiStatusesDestroy()
1706 api_statuses_destroy('json');
1710 * Test the api_statuses_destroy() function without an authenticated user.
1712 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1714 public function testApiStatusesDestroyWithoutAuthenticatedUser()
1716 $_SESSION['authenticated'] = false;
1717 api_statuses_destroy('json');
1721 * Test the api_statuses_destroy() function with an ID.
1724 public function testApiStatusesDestroyWithId()
1726 $this->app->argv[3] = 1;
1727 $result = api_statuses_destroy('json');
1728 $this->assertStatus($result['status']);
1732 * Test the api_statuses_mentions() function.
1735 public function testApiStatusesMentions()
1737 $this->app->user = ['nickname' => $this->selfUser['nick']];
1738 $_REQUEST['max_id'] = 10;
1739 $result = api_statuses_mentions('json');
1740 $this->assertEmpty($result['status']);
1741 // We should test with mentions in the database.
1745 * Test the api_statuses_mentions() function with a negative page parameter.
1748 public function testApiStatusesMentionsWithNegativePage()
1750 $_REQUEST['page'] = -2;
1751 $result = api_statuses_mentions('json');
1752 $this->assertEmpty($result['status']);
1756 * Test the api_statuses_mentions() function with an unallowed user.
1758 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1760 public function testApiStatusesMentionsWithUnallowedUser()
1762 $_SESSION['allow_api'] = false;
1763 $_GET['screen_name'] = $this->selfUser['nick'];
1764 api_statuses_mentions('json');
1768 * Test the api_statuses_mentions() function with an RSS result.
1771 public function testApiStatusesMentionsWithRss()
1773 $result = api_statuses_mentions('rss');
1774 $this->assertXml($result, 'statuses');
1778 * Test the api_statuses_user_timeline() function.
1781 public function testApiStatusesUserTimeline()
1783 $_REQUEST['max_id'] = 10;
1784 $_REQUEST['exclude_replies'] = true;
1785 $_REQUEST['conversation_id'] = 1;
1786 $result = api_statuses_user_timeline('json');
1787 $this->assertNotEmpty($result['status']);
1788 foreach ($result['status'] as $status) {
1789 $this->assertStatus($status);
1794 * Test the api_statuses_user_timeline() function with a negative page parameter.
1797 public function testApiStatusesUserTimelineWithNegativePage()
1799 $_REQUEST['page'] = -2;
1800 $result = api_statuses_user_timeline('json');
1801 $this->assertNotEmpty($result['status']);
1802 foreach ($result['status'] as $status) {
1803 $this->assertStatus($status);
1808 * Test the api_statuses_user_timeline() function with an RSS result.
1811 public function testApiStatusesUserTimelineWithRss()
1813 $result = api_statuses_user_timeline('rss');
1814 $this->assertXml($result, 'statuses');
1818 * Test the api_statuses_user_timeline() function with an unallowed user.
1820 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1822 public function testApiStatusesUserTimelineWithUnallowedUser()
1824 $_SESSION['allow_api'] = false;
1825 $_GET['screen_name'] = $this->selfUser['nick'];
1826 api_statuses_user_timeline('json');
1830 * Test the api_favorites_create_destroy() function.
1832 * @expectedException Friendica\Network\HTTPException\BadRequestException
1834 public function testApiFavoritesCreateDestroy()
1836 api_favorites_create_destroy('json');
1840 * Test the api_favorites_create_destroy() function with an invalid ID.
1842 * @expectedException Friendica\Network\HTTPException\BadRequestException
1844 public function testApiFavoritesCreateDestroyWithInvalidId()
1846 // This triggers a very specific condition ($action_argv_id + 2)
1847 $this->app->argv[1] = '1.1';
1848 $this->app->argc = 5;
1849 api_favorites_create_destroy('json');
1853 * Test the api_favorites_create_destroy() function with an invalid action.
1855 * @expectedException Friendica\Network\HTTPException\BadRequestException
1857 public function testApiFavoritesCreateDestroyWithInvalidAction()
1859 $this->app->argv[1] = '1.1';
1860 $this->app->argc = 10;
1861 $_REQUEST['id'] = 1;
1862 api_favorites_create_destroy('json');
1866 * Test the api_favorites_create_destroy() function with the create action.
1869 public function testApiFavoritesCreateDestroyWithCreateAction()
1871 $this->app->argv[1] = '1.1';
1872 $this->app->argv[3] = 'create';
1873 $this->app->argc = 10;
1874 $_REQUEST['id'] = 3;
1875 $result = api_favorites_create_destroy('json');
1876 $this->assertStatus($result['status']);
1880 * Test the api_favorites_create_destroy() function with the create action and an RSS result.
1883 public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
1885 $this->app->argv[1] = '1.1';
1886 $this->app->argv[3] = 'create';
1887 $this->app->argc = 10;
1888 $_REQUEST['id'] = 3;
1889 $result = api_favorites_create_destroy('rss');
1890 $this->assertXml($result, 'status');
1894 * Test the api_favorites_create_destroy() function with the destroy action.
1897 public function testApiFavoritesCreateDestroyWithDestroyAction()
1899 $this->app->argv[1] = '1.1';
1900 $this->app->argv[3] = 'destroy';
1901 $this->app->argc = 10;
1902 $_REQUEST['id'] = 3;
1903 $result = api_favorites_create_destroy('json');
1904 $this->assertStatus($result['status']);
1908 * Test the api_favorites_create_destroy() function without an authenticated user.
1910 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1912 public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
1914 $_SESSION['authenticated'] = false;
1915 api_favorites_create_destroy('json');
1919 * Test the api_favorites() function.
1922 public function testApiFavorites()
1924 $_REQUEST['page'] = -1;
1925 $_REQUEST['max_id'] = 10;
1926 $result = api_favorites('json');
1927 foreach ($result['status'] as $status) {
1928 $this->assertStatus($status);
1933 * Test the api_favorites() function with an RSS result.
1936 public function testApiFavoritesWithRss()
1938 $result = api_favorites('rss');
1939 $this->assertXml($result, 'statuses');
1943 * Test the api_favorites() function with an unallowed user.
1945 * @expectedException Friendica\Network\HTTPException\ForbiddenException
1947 public function testApiFavoritesWithUnallowedUser()
1949 $_SESSION['allow_api'] = false;
1950 $_GET['screen_name'] = $this->selfUser['nick'];
1951 api_favorites('json');
1955 * Test the api_format_messages() function.
1958 public function testApiFormatMessages()
1960 $result = api_format_messages(
1961 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1962 ['id' => 2, 'screen_name' => 'recipient_name'],
1963 ['id' => 3, 'screen_name' => 'sender_name']
1965 $this->assertEquals('item_title'.PHP_EOL.'item_body', $result['text']);
1966 $this->assertEquals(1, $result['id']);
1967 $this->assertEquals(2, $result['recipient_id']);
1968 $this->assertEquals(3, $result['sender_id']);
1969 $this->assertEquals('recipient_name', $result['recipient_screen_name']);
1970 $this->assertEquals('sender_name', $result['sender_screen_name']);
1974 * Test the api_format_messages() function with HTML.
1977 public function testApiFormatMessagesWithHtmlText()
1979 $_GET['getText'] = 'html';
1980 $result = api_format_messages(
1981 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1982 ['id' => 2, 'screen_name' => 'recipient_name'],
1983 ['id' => 3, 'screen_name' => 'sender_name']
1985 $this->assertEquals('item_title', $result['title']);
1986 $this->assertEquals('<strong>item_body</strong>', $result['text']);
1990 * Test the api_format_messages() function with plain text.
1993 public function testApiFormatMessagesWithPlainText()
1995 $_GET['getText'] = 'plain';
1996 $result = api_format_messages(
1997 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
1998 ['id' => 2, 'screen_name' => 'recipient_name'],
1999 ['id' => 3, 'screen_name' => 'sender_name']
2001 $this->assertEquals('item_title', $result['title']);
2002 $this->assertEquals('item_body', $result['text']);
2006 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
2009 public function testApiFormatMessagesWithoutUserObjects()
2011 $_GET['getUserObjects'] = 'false';
2012 $result = api_format_messages(
2013 ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
2014 ['id' => 2, 'screen_name' => 'recipient_name'],
2015 ['id' => 3, 'screen_name' => 'sender_name']
2017 $this->assertNull($result['sender']);
2018 $this->assertNull($result['recipient']);
2022 * Test the api_convert_item() function.
2025 public function testApiConvertItem()
2027 $result = api_convert_item(
2029 'network' => 'feed',
2030 'title' => 'item_title',
2031 // We need a long string to test that it is correctly cut
2032 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
2033 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
2034 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
2035 'laudantium atque commodi alias voluptatem non possimus aperiam '.
2036 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
2037 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
2038 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
2039 'veritatis nihil distinctio qui eum repellat officia illum quos '.
2040 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
2041 'omnis exercitationem quo magnam consequatur maxime aut illum '.
2042 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
2043 'temporibus corporis ratione blanditiis perspiciatis impedit '.
2044 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
2045 'sunt consequatur inventore dolor officiis pariatur doloremque '.
2046 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
2047 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
2048 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
2049 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
2050 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
2051 'repellat officia illum quos impedit quam iste esse unde qui '.
2052 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
2053 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
2054 'et sed beatae nihil ullam temporibus corporis ratione blanditiis'
2057 $this->assertStringStartsWith('item_title', $result['text']);
2058 $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
2062 * Test the api_convert_item() function with an empty item body.
2065 public function testApiConvertItemWithoutBody()
2067 $result = api_convert_item(
2069 'network' => 'feed',
2070 'title' => 'item_title',
2072 'plink' => 'item_plink'
2075 $this->assertEquals('item_title', $result['text']);
2076 $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
2080 * Test the api_convert_item() function with the title in the body.
2083 public function testApiConvertItemWithTitleInBody()
2085 $result = api_convert_item(
2087 'title' => 'item_title',
2088 'body' => 'item_title item_body'
2091 $this->assertEquals('item_title item_body', $result['text']);
2092 $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
2096 * Test the api_get_attachments() function.
2099 public function testApiGetAttachments()
2102 $this->assertEmpty(api_get_attachments($body));
2106 * Test the api_get_attachments() function with an img tag.
2109 public function testApiGetAttachmentsWithImage()
2111 $body = '[img]img_url[/img]';
2112 $this->assertInternalType('array', api_get_attachments($body));
2116 * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
2119 public function testApiGetAttachmentsWithImageAndAndStatus()
2121 $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
2122 $body = '[img]img_url[/img]';
2123 $this->assertInternalType('array', api_get_attachments($body));
2127 * Test the api_get_entitities() function.
2130 public function testApiGetEntitities()
2133 $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
2137 * Test the api_get_entitities() function with the include_entities parameter.
2140 public function testApiGetEntititiesWithIncludeEntities()
2142 $_REQUEST['include_entities'] = 'true';
2144 $result = api_get_entitities($text, 'bbcode');
2145 $this->assertInternalType('array', $result['hashtags']);
2146 $this->assertInternalType('array', $result['symbols']);
2147 $this->assertInternalType('array', $result['urls']);
2148 $this->assertInternalType('array', $result['user_mentions']);
2152 * Test the api_format_items_embeded_images() function.
2155 public function testApiFormatItemsEmbededImages()
2157 $this->assertEquals(
2158 'text http://localhost/display/item_guid',
2159 api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
2164 * Test the api_contactlink_to_array() function.
2167 public function testApiContactlinkToArray()
2169 $this->assertEquals(
2174 api_contactlink_to_array('text')
2179 * Test the api_contactlink_to_array() function with an URL.
2182 public function testApiContactlinkToArrayWithUrl()
2184 $this->assertEquals(
2186 'name' => ['link_text'],
2189 api_contactlink_to_array('text <a href="url">link_text</a>')
2194 * Test the api_format_items_activities() function.
2197 public function testApiFormatItemsActivities()
2200 $result = api_format_items_activities($item);
2201 $this->assertArrayHasKey('like', $result);
2202 $this->assertArrayHasKey('dislike', $result);
2203 $this->assertArrayHasKey('attendyes', $result);
2204 $this->assertArrayHasKey('attendno', $result);
2205 $this->assertArrayHasKey('attendmaybe', $result);
2209 * Test the api_format_items_activities() function with an XML result.
2212 public function testApiFormatItemsActivitiesWithXml()
2215 $result = api_format_items_activities($item, 'xml');
2216 $this->assertArrayHasKey('friendica:like', $result);
2217 $this->assertArrayHasKey('friendica:dislike', $result);
2218 $this->assertArrayHasKey('friendica:attendyes', $result);
2219 $this->assertArrayHasKey('friendica:attendno', $result);
2220 $this->assertArrayHasKey('friendica:attendmaybe', $result);
2224 * Test the api_format_items_profiles() function.
2227 public function testApiFormatItemsProfiles()
2230 'id' => 'profile_id',
2231 'profile-name' => 'profile_name',
2232 'is-default' => true,
2233 'hide-friends' => true,
2234 'photo' => 'profile_photo',
2235 'thumb' => 'profile_thumb',
2237 'net-publish' => true,
2238 'pdesc' => 'description',
2239 'dob' => 'date_of_birth',
2240 'address' => 'address',
2241 'locality' => 'city',
2242 'region' => 'region',
2243 'postal-code' => 'postal_code',
2244 'country-name' => 'country',
2245 'hometown' => 'hometown',
2246 'gender' => 'gender',
2247 'marital' => 'marital',
2248 'with' => 'marital_with',
2249 'howlong' => 'marital_since',
2250 'sexual' => 'sexual',
2251 'politic' => 'politic',
2252 'religion' => 'religion',
2253 'pub_keywords' => 'public_keywords',
2254 'prv_keywords' => 'private_keywords',
2257 'dislikes' => 'dislikes',
2263 'interest' => 'interest',
2264 'romance' => 'romance',
2266 'education' => 'education',
2267 'contact' => 'social_networks',
2268 'homepage' => 'homepage'
2270 $result = api_format_items_profiles($profile_row);
2271 $this->assertEquals(
2273 'profile_id' => 'profile_id',
2274 'profile_name' => 'profile_name',
2275 'is_default' => true,
2276 'hide_friends' => true,
2277 'profile_photo' => 'profile_photo',
2278 'profile_thumb' => 'profile_thumb',
2280 'net_publish' => true,
2281 'description' => 'description',
2282 'date_of_birth' => 'date_of_birth',
2283 'address' => 'address',
2285 'region' => 'region',
2286 'postal_code' => 'postal_code',
2287 'country' => 'country',
2288 'hometown' => 'hometown',
2289 'gender' => 'gender',
2290 'marital' => 'marital',
2291 'marital_with' => 'marital_with',
2292 'marital_since' => 'marital_since',
2293 'sexual' => 'sexual',
2294 'politic' => 'politic',
2295 'religion' => 'religion',
2296 'public_keywords' => 'public_keywords',
2297 'private_keywords' => 'private_keywords',
2300 'dislikes' => 'dislikes',
2306 'interest' => 'interest',
2307 'romance' => 'romance',
2309 'education' => 'education',
2310 'social_networks' => 'social_networks',
2311 'homepage' => 'homepage',
2319 * Test the api_format_items() function.
2322 public function testApiFormatItems()
2326 'item_network' => 'item_network',
2331 $result = api_format_items($items, [], true);
2332 foreach ($result as $status) {
2333 $this->assertStatus($status);
2338 * Test the api_format_items() function with an XML result.
2341 public function testApiFormatItemsWithXml()
2348 $result = api_format_items($items, [], true, 'xml');
2349 foreach ($result as $status) {
2350 $this->assertStatus($status);
2355 * Test the api_format_items() function.
2358 public function testApiAccountRateLimitStatus()
2360 $result = api_account_rate_limit_status('json');
2361 $this->assertEquals(150, $result['hash']['remaining_hits']);
2362 $this->assertEquals(150, $result['hash']['hourly_limit']);
2363 $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
2367 * Test the api_format_items() function with an XML result.
2370 public function testApiAccountRateLimitStatusWithXml()
2372 $result = api_account_rate_limit_status('xml');
2373 $this->assertXml($result, 'hash');
2377 * Test the api_help_test() function.
2380 public function testApiHelpTest()
2382 $result = api_help_test('json');
2383 $this->assertEquals(['ok' => 'ok'], $result);
2387 * Test the api_help_test() function with an XML result.
2390 public function testApiHelpTestWithXml()
2392 $this->markTestIncomplete('Triggers this error: "key() expects parameter 1 to be array, string given"');
2393 $result = api_help_test('xml');
2394 $this->assertXml($result, 'ok');
2398 * Test the api_lists_list() function.
2401 public function testApiListsList()
2403 $result = api_lists_list('json');
2404 $this->assertEquals(['lists_list' => []], $result);
2408 * Test the api_lists_ownerships() function.
2411 public function testApiListsOwnerships()
2413 $result = api_lists_ownerships('json');
2414 foreach ($result['lists']['lists'] as $list) {
2415 $this->assertList($list);
2420 * Test the api_lists_ownerships() function without an authenticated user.
2422 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2424 public function testApiListsOwnershipsWithoutAuthenticatedUser()
2426 $_SESSION['authenticated'] = false;
2427 api_lists_ownerships('json');
2431 * Test the api_lists_statuses() function.
2432 * @expectedException Friendica\Network\HTTPException\BadRequestException
2435 public function testApiListsStatuses()
2437 api_lists_statuses('json');
2441 * Test the api_lists_statuses() function with a list ID.
2444 public function testApiListsStatusesWithListId()
2446 $_REQUEST['list_id'] = 1;
2447 $_REQUEST['page'] = -1;
2448 $_REQUEST['max_id'] = 10;
2449 $result = api_lists_statuses('json');
2450 foreach ($result['status'] as $status) {
2451 $this->assertStatus($status);
2456 * Test the api_lists_statuses() function with a list ID and a RSS result.
2459 public function testApiListsStatusesWithListIdAndRss()
2461 $_REQUEST['list_id'] = 1;
2462 $result = api_lists_statuses('rss');
2463 $this->assertXml($result, 'statuses');
2467 * Test the api_lists_statuses() function with an unallowed user.
2469 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2471 public function testApiListsStatusesWithUnallowedUser()
2473 $_SESSION['allow_api'] = false;
2474 $_GET['screen_name'] = $this->selfUser['nick'];
2475 api_lists_statuses('json');
2479 * Test the api_statuses_f() function.
2482 public function testApiStatusesFWithFriends()
2485 $result = api_statuses_f('friends');
2486 $this->assertArrayHasKey('user', $result);
2490 * Test the api_statuses_f() function.
2493 public function testApiStatusesFWithFollowers()
2495 $result = api_statuses_f('followers');
2496 $this->assertArrayHasKey('user', $result);
2500 * Test the api_statuses_f() function.
2503 public function testApiStatusesFWithBlocks()
2505 $result = api_statuses_f('blocks');
2506 $this->assertArrayHasKey('user', $result);
2510 * Test the api_statuses_f() function.
2513 public function testApiStatusesFWithIncoming()
2515 $result = api_statuses_f('incoming');
2516 $this->assertArrayHasKey('user', $result);
2520 * Test the api_statuses_f() function an undefined cursor GET variable.
2523 public function testApiStatusesFWithUndefinedCursor()
2525 $_GET['cursor'] = 'undefined';
2526 $this->assertFalse(api_statuses_f('friends'));
2530 * Test the api_statuses_friends() function.
2533 public function testApiStatusesFriends()
2535 $result = api_statuses_friends('json');
2536 $this->assertArrayHasKey('user', $result);
2540 * Test the api_statuses_friends() function an undefined cursor GET variable.
2543 public function testApiStatusesFriendsWithUndefinedCursor()
2545 $_GET['cursor'] = 'undefined';
2546 $this->assertFalse(api_statuses_friends('json'));
2550 * Test the api_statuses_followers() function.
2553 public function testApiStatusesFollowers()
2555 $result = api_statuses_followers('json');
2556 $this->assertArrayHasKey('user', $result);
2560 * Test the api_statuses_followers() function an undefined cursor GET variable.
2563 public function testApiStatusesFollowersWithUndefinedCursor()
2565 $_GET['cursor'] = 'undefined';
2566 $this->assertFalse(api_statuses_followers('json'));
2570 * Test the api_blocks_list() function.
2573 public function testApiBlocksList()
2575 $result = api_blocks_list('json');
2576 $this->assertArrayHasKey('user', $result);
2580 * Test the api_blocks_list() function an undefined cursor GET variable.
2583 public function testApiBlocksListWithUndefinedCursor()
2585 $_GET['cursor'] = 'undefined';
2586 $this->assertFalse(api_blocks_list('json'));
2590 * Test the api_friendships_incoming() function.
2593 public function testApiFriendshipsIncoming()
2595 $result = api_friendships_incoming('json');
2596 $this->assertArrayHasKey('id', $result);
2600 * Test the api_friendships_incoming() function an undefined cursor GET variable.
2603 public function testApiFriendshipsIncomingWithUndefinedCursor()
2605 $_GET['cursor'] = 'undefined';
2606 $this->assertFalse(api_friendships_incoming('json'));
2610 * Test the api_statusnet_config() function.
2613 public function testApiStatusnetConfig()
2615 $result = api_statusnet_config('json');
2616 $this->assertEquals('localhost', $result['config']['site']['server']);
2617 $this->assertEquals('default', $result['config']['site']['theme']);
2618 $this->assertEquals('http://localhost/images/friendica-64.png', $result['config']['site']['logo']);
2619 $this->assertTrue($result['config']['site']['fancy']);
2620 $this->assertEquals('en', $result['config']['site']['language']);
2621 $this->assertEquals('UTC', $result['config']['site']['timezone']);
2622 $this->assertEquals(200000, $result['config']['site']['textlimit']);
2623 $this->assertEquals('false', $result['config']['site']['private']);
2624 $this->assertEquals('false', $result['config']['site']['ssl']);
2625 $this->assertEquals(30, $result['config']['site']['shorturllength']);
2629 * Test the api_statusnet_version() function.
2632 public function testApiStatusnetVersion()
2634 $result = api_statusnet_version('json');
2635 $this->assertEquals('0.9.7', $result['version']);
2639 * Test the api_ff_ids() function.
2642 public function testApiFfIds()
2644 $result = api_ff_ids('json');
2645 $this->assertNull($result);
2649 * Test the api_ff_ids() function with a result.
2652 public function testApiFfIdsWithResult()
2654 $this->markTestIncomplete();
2658 * Test the api_ff_ids() function without an authenticated user.
2660 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2662 public function testApiFfIdsWithoutAuthenticatedUser()
2664 $_SESSION['authenticated'] = false;
2669 * Test the api_friends_ids() function.
2672 public function testApiFriendsIds()
2674 $result = api_friends_ids('json');
2675 $this->assertNull($result);
2679 * Test the api_followers_ids() function.
2682 public function testApiFollowersIds()
2684 $result = api_followers_ids('json');
2685 $this->assertNull($result);
2689 * Test the api_direct_messages_new() function.
2692 public function testApiDirectMessagesNew()
2694 $result = api_direct_messages_new('json');
2695 $this->assertNull($result);
2699 * Test the api_direct_messages_new() function without an authenticated user.
2701 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2703 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
2705 $_SESSION['authenticated'] = false;
2706 api_direct_messages_new('json');
2710 * Test the api_direct_messages_new() function with an user ID.
2713 public function testApiDirectMessagesNewWithUserId()
2715 $_POST['text'] = 'message_text';
2716 $_POST['user_id'] = $this->otherUser['id'];
2717 $result = api_direct_messages_new('json');
2718 $this->assertEquals(['direct_message' => ['error' => -1]], $result);
2722 * Test the api_direct_messages_new() function with a screen name.
2725 public function testApiDirectMessagesNewWithScreenName()
2727 $_POST['text'] = 'message_text';
2728 $_POST['screen_name'] = $this->otherUser['nick'];
2729 $result = api_direct_messages_new('json');
2730 $this->assertEquals(1, $result['direct_message']['id']);
2731 $this->assertContains('message_text', $result['direct_message']['text']);
2732 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2733 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2737 * Test the api_direct_messages_new() function with a title.
2740 public function testApiDirectMessagesNewWithTitle()
2742 $_POST['text'] = 'message_text';
2743 $_POST['screen_name'] = $this->otherUser['nick'];
2744 $_REQUEST['title'] = 'message_title';
2745 $result = api_direct_messages_new('json');
2746 $this->assertEquals(1, $result['direct_message']['id']);
2747 $this->assertContains('message_text', $result['direct_message']['text']);
2748 $this->assertContains('message_title', $result['direct_message']['text']);
2749 $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
2750 $this->assertEquals(1, $result['direct_message']['friendica_seen']);
2754 * Test the api_direct_messages_new() function with an RSS result.
2757 public function testApiDirectMessagesNewWithRss()
2759 $_POST['text'] = 'message_text';
2760 $_POST['screen_name'] = $this->otherUser['nick'];
2761 $result = api_direct_messages_new('rss');
2762 $this->assertXml($result, 'direct-messages');
2766 * Test the api_direct_messages_destroy() function.
2768 * @expectedException Friendica\Network\HTTPException\BadRequestException
2770 public function testApiDirectMessagesDestroy()
2772 api_direct_messages_destroy('json');
2776 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
2779 public function testApiDirectMessagesDestroyWithVerbose()
2781 $_GET['friendica_verbose'] = 'true';
2782 $result = api_direct_messages_destroy('json');
2783 $this->assertEquals(
2786 'result' => 'error',
2787 'message' => 'message id or parenturi not specified'
2795 * Test the api_direct_messages_destroy() function without an authenticated user.
2797 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2799 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
2801 $_SESSION['authenticated'] = false;
2802 api_direct_messages_destroy('json');
2806 * Test the api_direct_messages_destroy() function with a non-zero ID.
2808 * @expectedException Friendica\Network\HTTPException\BadRequestException
2810 public function testApiDirectMessagesDestroyWithId()
2812 $_REQUEST['id'] = 1;
2813 api_direct_messages_destroy('json');
2817 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
2820 public function testApiDirectMessagesDestroyWithIdAndVerbose()
2822 $_REQUEST['id'] = 1;
2823 $_REQUEST['friendica_parenturi'] = 'parent_uri';
2824 $_GET['friendica_verbose'] = 'true';
2825 $result = api_direct_messages_destroy('json');
2826 $this->assertEquals(
2829 'result' => 'error',
2830 'message' => 'message id not in database'
2838 * Test the api_direct_messages_destroy() function with a non-zero ID.
2841 public function testApiDirectMessagesDestroyWithCorrectId()
2843 $this->markTestIncomplete('We need to add a dataset for this.');
2847 * Test the api_direct_messages_box() function.
2850 public function testApiDirectMessagesBoxWithSentbox()
2852 $_REQUEST['page'] = -1;
2853 $_REQUEST['max_id'] = 10;
2854 $result = api_direct_messages_box('json', 'sentbox', 'false');
2855 $this->assertArrayHasKey('direct_message', $result);
2859 * Test the api_direct_messages_box() function.
2862 public function testApiDirectMessagesBoxWithConversation()
2864 $result = api_direct_messages_box('json', 'conversation', 'false');
2865 $this->assertArrayHasKey('direct_message', $result);
2869 * Test the api_direct_messages_box() function.
2872 public function testApiDirectMessagesBoxWithAll()
2874 $result = api_direct_messages_box('json', 'all', 'false');
2875 $this->assertArrayHasKey('direct_message', $result);
2879 * Test the api_direct_messages_box() function.
2882 public function testApiDirectMessagesBoxWithInbox()
2884 $result = api_direct_messages_box('json', 'inbox', 'false');
2885 $this->assertArrayHasKey('direct_message', $result);
2889 * Test the api_direct_messages_box() function.
2892 public function testApiDirectMessagesBoxWithVerbose()
2894 $result = api_direct_messages_box('json', 'sentbox', 'true');
2895 $this->assertEquals(
2898 'result' => 'error',
2899 'message' => 'no mails available'
2907 * Test the api_direct_messages_box() function with a RSS result.
2910 public function testApiDirectMessagesBoxWithRss()
2912 $result = api_direct_messages_box('rss', 'sentbox', 'false');
2913 $this->assertXml($result, 'direct-messages');
2917 * Test the api_direct_messages_box() function without an authenticated user.
2919 * @expectedException Friendica\Network\HTTPException\ForbiddenException
2921 public function testApiDirectMessagesBoxWithUnallowedUser()
2923 $_SESSION['allow_api'] = false;
2924 $_GET['screen_name'] = $this->selfUser['nick'];
2925 api_direct_messages_box('json', 'sentbox', 'false');
2929 * Test the api_direct_messages_sentbox() function.
2932 public function testApiDirectMessagesSentbox()
2934 $result = api_direct_messages_sentbox('json');
2935 $this->assertArrayHasKey('direct_message', $result);
2939 * Test the api_direct_messages_inbox() function.
2942 public function testApiDirectMessagesInbox()
2944 $result = api_direct_messages_inbox('json');
2945 $this->assertArrayHasKey('direct_message', $result);
2949 * Test the api_direct_messages_all() function.
2952 public function testApiDirectMessagesAll()
2954 $result = api_direct_messages_all('json');
2955 $this->assertArrayHasKey('direct_message', $result);
2959 * Test the api_direct_messages_conversation() function.
2962 public function testApiDirectMessagesConversation()
2964 $result = api_direct_messages_conversation('json');
2965 $this->assertArrayHasKey('direct_message', $result);
2969 * Test the api_oauth_request_token() function.
2972 public function testApiOauthRequestToken()
2974 $this->markTestIncomplete('killme() kills phpunit as well');
2978 * Test the api_oauth_access_token() function.
2981 public function testApiOauthAccessToken()
2983 $this->markTestIncomplete('killme() kills phpunit as well');
2987 * Test the api_fr_photoalbum_delete() function.
2989 * @expectedException Friendica\Network\HTTPException\BadRequestException
2991 public function testApiFrPhotoalbumDelete()
2993 api_fr_photoalbum_delete('json');
2997 * Test the api_fr_photoalbum_delete() function with an album name.
2999 * @expectedException Friendica\Network\HTTPException\BadRequestException
3001 public function testApiFrPhotoalbumDeleteWithAlbum()
3003 $_REQUEST['album'] = 'album_name';
3004 api_fr_photoalbum_delete('json');
3008 * Test the api_fr_photoalbum_delete() function with an album name.
3011 public function testApiFrPhotoalbumDeleteWithValidAlbum()
3013 $this->markTestIncomplete('We need to add a dataset for this.');
3017 * Test the api_fr_photoalbum_delete() function.
3019 * @expectedException Friendica\Network\HTTPException\BadRequestException
3021 public function testApiFrPhotoalbumUpdate()
3023 api_fr_photoalbum_update('json');
3027 * Test the api_fr_photoalbum_delete() function with an album name.
3029 * @expectedException Friendica\Network\HTTPException\BadRequestException
3031 public function testApiFrPhotoalbumUpdateWithAlbum()
3033 $_REQUEST['album'] = 'album_name';
3034 api_fr_photoalbum_update('json');
3038 * Test the api_fr_photoalbum_delete() function with an album name.
3040 * @expectedException Friendica\Network\HTTPException\BadRequestException
3042 public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
3044 $_REQUEST['album'] = 'album_name';
3045 $_REQUEST['album_new'] = 'album_name';
3046 api_fr_photoalbum_update('json');
3050 * Test the api_fr_photoalbum_update() function without an authenticated user.
3052 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3054 public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
3056 $_SESSION['authenticated'] = false;
3057 api_fr_photoalbum_update('json');
3061 * Test the api_fr_photoalbum_delete() function with an album name.
3064 public function testApiFrPhotoalbumUpdateWithValidAlbum()
3066 $this->markTestIncomplete('We need to add a dataset for this.');
3070 * Test the api_fr_photos_list() function.
3073 public function testApiFrPhotosList()
3075 $result = api_fr_photos_list('json');
3076 $this->assertArrayHasKey('photo', $result);
3080 * Test the api_fr_photos_list() function without an authenticated user.
3082 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3084 public function testApiFrPhotosListWithoutAuthenticatedUser()
3086 $_SESSION['authenticated'] = false;
3087 api_fr_photos_list('json');
3091 * Test the api_fr_photo_create_update() function.
3093 * @expectedException Friendica\Network\HTTPException\BadRequestException
3095 public function testApiFrPhotoCreateUpdate()
3097 api_fr_photo_create_update('json');
3101 * Test the api_fr_photo_create_update() function without an authenticated user.
3103 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3105 public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
3107 $_SESSION['authenticated'] = false;
3108 api_fr_photo_create_update('json');
3112 * Test the api_fr_photo_create_update() function with an album name.
3114 * @expectedException Friendica\Network\HTTPException\BadRequestException
3116 public function testApiFrPhotoCreateUpdateWithAlbum()
3118 $_REQUEST['album'] = 'album_name';
3119 api_fr_photo_create_update('json');
3123 * Test the api_fr_photo_create_update() function with the update mode.
3126 public function testApiFrPhotoCreateUpdateWithUpdate()
3128 $this->markTestIncomplete('We need to create a dataset for this');
3132 * Test the api_fr_photo_create_update() function with an uploaded file.
3135 public function testApiFrPhotoCreateUpdateWithFile()
3137 $this->markTestIncomplete();
3141 * Test the api_fr_photo_delete() function.
3143 * @expectedException Friendica\Network\HTTPException\BadRequestException
3145 public function testApiFrPhotoDelete()
3147 api_fr_photo_delete('json');
3151 * Test the api_fr_photo_delete() function without an authenticated user.
3153 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3155 public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
3157 $_SESSION['authenticated'] = false;
3158 api_fr_photo_delete('json');
3162 * Test the api_fr_photo_delete() function with a photo ID.
3164 * @expectedException Friendica\Network\HTTPException\BadRequestException
3166 public function testApiFrPhotoDeleteWithPhotoId()
3168 $_REQUEST['photo_id'] = 1;
3169 api_fr_photo_delete('json');
3173 * Test the api_fr_photo_delete() function with a correct photo ID.
3176 public function testApiFrPhotoDeleteWithCorrectPhotoId()
3178 $this->markTestIncomplete('We need to create a dataset for this.');
3182 * Test the api_fr_photo_detail() function.
3184 * @expectedException Friendica\Network\HTTPException\BadRequestException
3186 public function testApiFrPhotoDetail()
3188 api_fr_photo_detail('json');
3192 * Test the api_fr_photo_detail() function without an authenticated user.
3194 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3196 public function testApiFrPhotoDetailWithoutAuthenticatedUser()
3198 $_SESSION['authenticated'] = false;
3199 api_fr_photo_detail('json');
3203 * Test the api_fr_photo_detail() function with a photo ID.
3205 * @expectedException Friendica\Network\HTTPException\NotFoundException
3207 public function testApiFrPhotoDetailWithPhotoId()
3209 $_REQUEST['photo_id'] = 1;
3210 api_fr_photo_detail('json');
3214 * Test the api_fr_photo_detail() function with a correct photo ID.
3217 public function testApiFrPhotoDetailCorrectPhotoId()
3219 $this->markTestIncomplete('We need to create a dataset for this.');
3223 * Test the api_account_update_profile_image() function.
3225 * @expectedException Friendica\Network\HTTPException\BadRequestException
3227 public function testApiAccountUpdateProfileImage()
3229 api_account_update_profile_image('json');
3233 * Test the api_account_update_profile_image() function without an authenticated user.
3235 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3237 public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
3239 $_SESSION['authenticated'] = false;
3240 api_account_update_profile_image('json');
3244 * Test the api_account_update_profile_image() function with an uploaded file.
3246 * @expectedException Friendica\Network\HTTPException\BadRequestException
3248 public function testApiAccountUpdateProfileImageWithUpload()
3250 $this->markTestIncomplete();
3255 * Test the api_account_update_profile() function.
3258 public function testApiAccountUpdateProfile()
3260 $_POST['name'] = 'new_name';
3261 $_POST['description'] = 'new_description';
3262 $result = api_account_update_profile('json');
3263 // We can't use assertSelfUser() here because the user object is missing some properties.
3264 $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
3265 $this->assertEquals('Friendica', $result['user']['location']);
3266 $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
3267 $this->assertEquals('dfrn', $result['user']['network']);
3268 $this->assertEquals('new_name', $result['user']['name']);
3269 $this->assertEquals('new_description', $result['user']['description']);
3273 * Test the check_acl_input() function.
3276 public function testCheckAclInput()
3278 $result = check_acl_input('<aclstring>');
3279 // Where does this result come from?
3280 $this->assertEquals(1, $result);
3284 * Test the check_acl_input() function with an empty ACL string.
3287 public function testCheckAclInputWithEmptyAclString()
3289 $result = check_acl_input(' ');
3290 $this->assertFalse($result);
3294 * Test the save_media_to_database() function.
3297 public function testSaveMediaToDatabase()
3299 $this->markTestIncomplete();
3303 * Test the post_photo_item() function.
3306 public function testPostPhotoItem()
3308 $this->markTestIncomplete();
3312 * Test the prepare_photo_data() function.
3315 public function testPreparePhotoData()
3317 $this->markTestIncomplete();
3321 * Test the api_friendica_remoteauth() function.
3323 * @expectedException Friendica\Network\HTTPException\BadRequestException
3325 public function testApiFriendicaRemoteauth()
3327 api_friendica_remoteauth();
3331 * Test the api_friendica_remoteauth() function with an URL.
3333 * @expectedException Friendica\Network\HTTPException\BadRequestException
3335 public function testApiFriendicaRemoteauthWithUrl()
3337 $_GET['url'] = 'url';
3338 $_GET['c_url'] = 'url';
3339 api_friendica_remoteauth();
3343 * Test the api_friendica_remoteauth() function with a correct URL.
3346 public function testApiFriendicaRemoteauthWithCorrectUrl()
3348 $this->markTestIncomplete("We can't use an assertion here because of goaway().");
3349 $_GET['url'] = 'url';
3350 $_GET['c_url'] = $this->selfUser['nurl'];
3351 api_friendica_remoteauth();
3355 * Test the api_share_as_retweet() function.
3358 public function testApiShareAsRetweet()
3361 $result = api_share_as_retweet($item);
3362 $this->assertFalse($result);
3366 * Test the api_share_as_retweet() function with a valid item.
3369 public function testApiShareAsRetweetWithValidItem()
3371 $this->markTestIncomplete();
3375 * Test the api_get_nick() function.
3378 public function testApiGetNick()
3380 $result = api_get_nick($this->otherUser['nurl']);
3381 $this->assertEquals('othercontact', $result);
3385 * Test the api_get_nick() function with a wrong URL.
3388 public function testApiGetNickWithWrongUrl()
3390 $result = api_get_nick('wrong_url');
3391 $this->assertFalse($result);
3395 * Test the api_in_reply_to() function.
3398 public function testApiInReplyTo()
3400 $result = api_in_reply_to([]);
3401 $this->assertArrayHasKey('status_id', $result);
3402 $this->assertArrayHasKey('user_id', $result);
3403 $this->assertArrayHasKey('status_id_str', $result);
3404 $this->assertArrayHasKey('user_id_str', $result);
3405 $this->assertArrayHasKey('screen_name', $result);
3409 * Test the api_in_reply_to() function with a valid item.
3412 public function testApiInReplyToWithValidItem()
3414 $this->markTestIncomplete();
3418 * Test the api_clean_plain_items() function.
3421 public function testApiCleanPlainItems()
3423 $_REQUEST['include_entities'] = 'true';
3424 $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
3425 $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
3429 * Test the api_clean_attachments() function.
3432 public function testApiCleanAttachments()
3434 $this->markTestIncomplete();
3438 * Test the api_best_nickname() function.
3441 public function testApiBestNickname()
3444 $result = api_best_nickname($contacts);
3445 $this->assertNull($result);
3449 * Test the api_best_nickname() function with contacts.
3452 public function testApiBestNicknameWithContacts()
3454 $this->markTestIncomplete();
3458 * Test the api_friendica_group_show() function.
3461 public function testApiFriendicaGroupShow()
3463 $this->markTestIncomplete();
3467 * Test the api_friendica_group_delete() function.
3470 public function testApiFriendicaGroupDelete()
3472 $this->markTestIncomplete();
3476 * Test the api_lists_destroy() function.
3479 public function testApiListsDestroy()
3481 $this->markTestIncomplete();
3485 * Test the group_create() function.
3488 public function testGroupCreate()
3490 $this->markTestIncomplete();
3494 * Test the api_friendica_group_create() function.
3497 public function testApiFriendicaGroupCreate()
3499 $this->markTestIncomplete();
3503 * Test the api_lists_create() function.
3506 public function testApiListsCreate()
3508 $this->markTestIncomplete();
3512 * Test the api_friendica_group_update() function.
3515 public function testApiFriendicaGroupUpdate()
3517 $this->markTestIncomplete();
3521 * Test the api_lists_update() function.
3524 public function testApiListsUpdate()
3526 $this->markTestIncomplete();
3530 * Test the api_friendica_activity() function.
3533 public function testApiFriendicaActivity()
3535 $this->markTestIncomplete();
3539 * Test the api_friendica_notification() function.
3541 * @expectedException Friendica\Network\HTTPException\BadRequestException
3543 public function testApiFriendicaNotification()
3545 api_friendica_notification('json');
3549 * Test the api_friendica_notification() function without an authenticated user.
3551 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3553 public function testApiFriendicaNotificationWithoutAuthenticatedUser()
3555 $_SESSION['authenticated'] = false;
3556 api_friendica_notification('json');
3560 * Test the api_friendica_notification() function with an argument count.
3563 public function testApiFriendicaNotificationWithArgumentCount()
3565 $this->app->argc = 3;
3566 $result = api_friendica_notification('json');
3567 $this->assertEquals(['note' => false], $result);
3571 * Test the api_friendica_notification() function with an XML result.
3574 public function testApiFriendicaNotificationWithXmlResult()
3576 $this->markTestIncomplete('Fails with "Invalid argument supplied for foreach()".');
3577 $this->app->argc = 3;
3578 $result = api_friendica_notification('xml');
3579 $this->assertXml($result, 'notes');
3583 * Test the api_friendica_notification_seen() function.
3586 public function testApiFriendicaNotificationSeen()
3588 $this->markTestIncomplete();
3592 * Test the api_friendica_direct_messages_setseen() function.
3595 public function testApiFriendicaDirectMessagesSetseen()
3597 $this->markTestIncomplete();
3601 * Test the api_friendica_direct_messages_search() function.
3604 public function testApiFriendicaDirectMessagesSearch()
3606 $this->markTestIncomplete();
3610 * Test the api_friendica_profile_show() function.
3613 public function testApiFriendicaProfileShow()
3615 $result = api_friendica_profile_show('json');
3616 // We can't use assertSelfUser() here because the user object is missing some properties.
3617 $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
3618 $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
3619 $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
3620 $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
3621 $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
3622 $this->assertTrue($result['$result']['friendica_owner']['verified']);
3623 $this->assertFalse($result['$result']['multi_profiles']);
3627 * Test the api_friendica_profile_show() function with a profile ID.
3630 public function testApiFriendicaProfileShowWithProfileId()
3632 $this->markTestIncomplete('We need to add a dataset for this.');
3636 * Test the api_friendica_profile_show() function with a wrong profile ID.
3638 * @expectedException Friendica\Network\HTTPException\BadRequestException
3640 public function testApiFriendicaProfileShowWithWrongProfileId()
3642 $_REQUEST['profile_id'] = 666;
3643 api_friendica_profile_show('json');
3647 * Test the api_friendica_profile_show() function without an authenticated user.
3649 * @expectedException Friendica\Network\HTTPException\ForbiddenException
3651 public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
3653 $_SESSION['authenticated'] = false;
3654 api_friendica_profile_show('json');
3658 * Test the api_saved_searches_list() function.
3661 public function testApiSavedSearchesList()
3663 $result = api_saved_searches_list('json');
3664 $this->assertEquals(1, $result['terms'][0]['id']);
3665 $this->assertEquals(1, $result['terms'][0]['id_str']);
3666 $this->assertEquals('Saved search', $result['terms'][0]['name']);
3667 $this->assertEquals('Saved search', $result['terms'][0]['query']);