diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index c4b9b1e94..a6a94ad81 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -221,6 +221,16 @@ class ApiResponse extends Response $this->addContent($return); } + /** + * Wrapper around exit() for JSON only responses + * + * @param array $data + */ + public function exitWithJson(array $data) + { + $this->exit('content', ['content' => $data], static::TYPE_JSON); + } + /** * Quit execution with the message that the endpoint isn't implemented * diff --git a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php index 472ca7f56..058a52f63 100644 --- a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php @@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi // @todo Support the source property, $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); - System::jsonExit($account); + $this->response->exitWithJson($account->toArray()); } } diff --git a/src/Module/Api/Twitter/Account/UpdateProfile.php b/src/Module/Api/Twitter/Account/UpdateProfile.php index 5a66e2772..100b121b3 100644 --- a/src/Module/Api/Twitter/Account/UpdateProfile.php +++ b/src/Module/Api/Twitter/Account/UpdateProfile.php @@ -39,22 +39,22 @@ class UpdateProfile extends BaseApi $api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray(); - if (!empty($_POST['name'])) { - DBA::update('profile', ['name' => $_POST['name']], ['uid' => $uid]); - DBA::update('user', ['username' => $_POST['name']], ['uid' => $uid]); - Contact::update(['name' => $_POST['name']], ['uid' => $uid, 'self' => 1]); - Contact::update(['name' => $_POST['name']], ['id' => $api_user['id']]); + if (!empty($request['name'])) { + DBA::update('profile', ['name' => $request['name']], ['uid' => $uid]); + DBA::update('user', ['username' => $request['name']], ['uid' => $uid]); + Contact::update(['name' => $request['name']], ['uid' => $uid, 'self' => 1]); + Contact::update(['name' => $request['name']], ['id' => $api_user['id']]); } - if (isset($_POST['description'])) { - DBA::update('profile', ['about' => $_POST['description']], ['uid' => $uid]); - Contact::update(['about' => $_POST['description']], ['uid' => $uid, 'self' => 1]); - Contact::update(['about' => $_POST['description']], ['id' => $api_user['id']]); + if (isset($request['description'])) { + DBA::update('profile', ['about' => $request['description']], ['uid' => $uid]); + Contact::update(['about' => $request['description']], ['uid' => $uid, 'self' => 1]); + Contact::update(['about' => $request['description']], ['id' => $api_user['id']]); } Profile::publishUpdate($uid); - $skip_status = $_REQUEST['skip_status'] ?? false; + $skip_status = $request['skip_status'] ?? false; $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray(); diff --git a/src/Module/Api/Twitter/Blocks/Lists.php b/src/Module/Api/Twitter/Blocks/Lists.php index 1260b9c7b..44ffe0024 100644 --- a/src/Module/Api/Twitter/Blocks/Lists.php +++ b/src/Module/Api/Twitter/Blocks/Lists.php @@ -87,6 +87,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 5f6696341..1982d921b 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -92,6 +92,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 7b38ed366..16947d072 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -92,6 +92,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friendships/Incoming.php b/src/Module/Api/Twitter/Friendships/Incoming.php index fed2bffbc..9cfcd056d 100644 --- a/src/Module/Api/Twitter/Friendships/Incoming.php +++ b/src/Module/Api/Twitter/Friendships/Incoming.php @@ -86,6 +86,6 @@ class Incoming extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('incoming', ['incoming' => $return]); } } diff --git a/src/Module/Api/Twitter/Lists/Statuses.php b/src/Module/Api/Twitter/Lists/Statuses.php index d647e4a27..9763e4575 100644 --- a/src/Module/Api/Twitter/Lists/Statuses.php +++ b/src/Module/Api/Twitter/Lists/Statuses.php @@ -40,23 +40,23 @@ class Statuses extends BaseApi BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); $uid = BaseApi::getCurrentUserID(); - if (empty($_REQUEST['list_id'])) { + if (empty($request['list_id'])) { throw new BadRequestException('list_id not specified'); } // params - $count = $_REQUEST['count'] ?? 20; - $page = $_REQUEST['page'] ?? 1; - $since_id = $_REQUEST['since_id'] ?? 0; - $max_id = $_REQUEST['max_id'] ?? 0; - $exclude_replies = (!empty($_REQUEST['exclude_replies']) ? 1 : 0); - $conversation_id = $_REQUEST['conversation_id'] ?? 0; + $count = $request['count'] ?? 20; + $page = $request['page'] ?? 1; + $since_id = $request['since_id'] ?? 0; + $max_id = $request['max_id'] ?? 0; + $exclude_replies = (!empty($request['exclude_replies']) ? 1 : 0); + $conversation_id = $request['conversation_id'] ?? 0; $start = max(0, ($page - 1) * $count); - $groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]); + $groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]); $gids = array_column($groups, 'contact-id'); - $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids]; + $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids]; $condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]); if ($max_id > 0) { @@ -75,7 +75,7 @@ class Statuses extends BaseApi $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $statuses = Post::selectForUser($uid, [], $condition, $params); - $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); + $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $items = []; while ($status = DBA::fetch($statuses)) { diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 9e0174c02..a8705696f 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -36,7 +36,7 @@ return [ 'mail', 'post-delivery-data', // Base test config to avoid notice messages - 'config' => [ + 'config' => [ [ 'cat' => 'system', 'k' => 'url', @@ -63,7 +63,7 @@ return [ 'v' => '1', ], ], - 'user' => [ + 'user' => [ [ 'uid' => 42, 'username' => 'Test user', @@ -73,7 +73,7 @@ return [ 'theme' => 'frio', ], ], - 'item-uri' => [ + 'item-uri' => [ [ 'id' => 1, 'uri' => '1', @@ -128,100 +128,149 @@ return [ ], 'contact' => [ [ - 'id' => 42, - 'uid' => 42, - 'uri-id' => 42, - 'name' => 'Self contact', - 'nick' => 'selfcontact', - 'self' => 1, - 'nurl' => 'http://localhost/profile/selfcontact', - 'url' => 'http://localhost/profile/selfcontact', - 'about' => 'User used in tests', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FOLLOWER, - 'network' => Protocol::DFRN, + 'id' => 42, + 'uid' => 42, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 1, + 'nurl' => 'http://localhost/profile/selfcontact', + 'url' => 'http://localhost/profile/selfcontact', + 'about' => 'User used in tests', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FOLLOWER, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], // Having the same name and nick allows us to test // the fallback to api_get_nick() in api_get_user() [ - 'id' => 43, - 'uid' => 0, - 'uri-id' => 43, - 'name' => 'othercontact', - 'nick' => 'othercontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/othercontact', - 'url' => 'http://localhost/profile/othercontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::NOTHING, - 'network' => Protocol::DFRN, + 'id' => 43, + 'uid' => 0, + 'uri-id' => 43, + 'name' => 'othercontact', + 'nick' => 'othercontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/othercontact', + 'url' => 'http://localhost/profile/othercontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::NOTHING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 44, - 'uid' => 42, - 'uri-id' => 44, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 44, + 'uid' => 42, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 45, - 'uid' => 0, - 'uri-id' => 44, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 45, + 'uid' => 0, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 46, - 'uid' => 42, - 'uri-id' => 46, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FRIEND, - 'network' => Protocol::DFRN, + 'id' => 46, + 'uid' => 42, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FRIEND, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 47, - 'uid' => 0, - 'uri-id' => 46, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 47, + 'uid' => 0, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 48, + 'uid' => 0, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/selfcontact', + 'url' => 'http://localhost/profile/selfcontact', + 'about' => 'User used in tests', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FOLLOWER, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], ], - 'verb' => [ + 'apcontact' => [ + [ + "url" => "http://localhost/profile/selfcontact", + "uri-id" => 1, + "uuid" => "42", + "type" => "Person", + "following" => "http://localhost/following/selfcontact", + "followers" => "http://localhost/followers/selfcontact", + "inbox" => "http://localhost/inbox/selfcontact", + "outbox" => "http://localhost/outbox/selfcontact", + "sharedinbox" => "http://localhost/inbox", + "manually-approve" => 1, + "discoverable" => 0, + "nick" => "selfcontact", + "name" => "Self contact", + "about" => "User used in tests", + "xmpp" => null, + "matrix" => null, + "photo" => "http://localhost/photo/profile/admin.jpeg", + "header" => null, + "addr" => "selfcontact@localhost", + "alias" => null, + "pubkey" => "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzLquDFnFxNYZZFQNbA9f\nkgtUJpC+MPrhxhEsjxme1ivvE4itdPnCueBHifknUkwfmqormyeqr4TdoVbNuKRg\nj2QRBdtaGbUJLQVdbiTKFOmJIYMtV05WIIHEhUW84fwIXmF+6u3kbOw+sIjWY3OW\nwC/2+54HiYS2n8cddfwoZBim6Na8yyQI8pQSKqJ+I4gDfkGuoVex0svNPEv9liLE\nykpQ3PuoeLJV2Wex0Cy6FYPgcfH6xvvUVxh6e8w0w22jC3DJInfDrmbw5H7aUbf+\nMMwV3TVI6/CqTO0cLEOZUjsUwdm6lIV0O0fTsrkjU9G0bc0sLJl7n9i9ICDOKOMf\nCLaK2Pj2sVbpkzXJoufLUDf0oSftdVvN9jR9WYxRdnwsyF8N/xVTw8AsyHhkXawR\n3YDgi6i2uZj5kvG7GPBf7EPZ/MpbGhEZB+/GQuZuyhLdgFDSi/uX8STBmn1jI/zY\nTLZ8JCwMzFKAXAtYaBPklZBbcRyz9O1893MsAXO8d6ODTOkD324gAjRUtuOMscYc\nWV98NZIUSbqQrznmMoJn1fiMNVgx+UXOPkiZuDxnrr1T3vynKnl5LXmadx2YeoAf\nxPeCoDb0eJtCDLcsTZ9qlztaEaohPV+H3HBSpdItea7LgAbccILHPssk9tUgmHVl\na5yV8uFenhKKQ9g93Pt63LsCAwEAAQ==\n-----END PUBLIC KEY-----", + "subscribe" => "/follow?url={uri}", + "baseurl" => null, + "gsid" => null, + "generator" => "Friendica 'Siberian Iris' 2021.12-dev-1443", + "following_count" => 0, + "followers_count" => 0, + "statuses_count" => 0, + "updated" => "2021-11-19 19:17:59", + ], + ], + 'verb' => [ [ 'id' => 0, 'name' => '', @@ -291,7 +340,7 @@ return [ 'plink' => 'http://localhost/display/6', ], ], - 'post' => [ + 'post' => [ [ 'uri-id' => 1, 'parent-uri-id' => 1, @@ -636,135 +685,135 @@ return [ 'wall' => 0, ], ], - 'post-thread' => [ + 'post-thread' => [ [ - 'uri-id' => 1, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'network' => Protocol::DFRN, + 'uri-id' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'network' => Protocol::DFRN, ], [ - 'uri-id' => 3, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'network' => Protocol::DFRN, + 'uri-id' => 3, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'network' => Protocol::DFRN, ], [ - 'uri-id' => 6, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'network' => Protocol::DFRN, + 'uri-id' => 6, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, ], ], - 'post-thread-user' => [ + 'post-thread-user' => [ [ - 'uri-id' => 1, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 1, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 1, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'contact-id' => 42, - 'network' => Protocol::DFRN, - 'starred' => 1, - 'origin' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'contact-id' => 42, + 'network' => Protocol::DFRN, + 'starred' => 1, + 'origin' => 1, ], [ - 'uri-id' => 3, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 3, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 3, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'contact-id' => 43, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 1, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'contact-id' => 43, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ - 'uri-id' => 6, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 6, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 6, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'contact-id' => 44, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 1, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'contact-id' => 44, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ - 'uri-id' => 1, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 1, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 7, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'contact-id' => 42, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'contact-id' => 42, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ - 'uri-id' => 3, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 3, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 9, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'contact-id' => 43, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'contact-id' => 43, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ - 'uri-id' => 6, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 6, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 12, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'contact-id' => 44, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'contact-id' => 44, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], ], 'notify' => [ [ - 'id' => 1, - 'type' => 8, - 'name' => 'Reply to', - 'url' => 'http://localhost/display/1', - 'photo' => 'http://localhost/', - 'date' => '2020-01-01 12:12:02', - 'msg' => 'A test reply from an item', - 'uid' => 42, - 'link' => 'http://localhost/notification/1', - 'iid' => 4, - 'seen' => 0, - 'verb' => \Friendica\Protocol\Activity::POST, - 'otype' => Notification\ObjectType::ITEM, + 'id' => 1, + 'type' => 8, + 'name' => 'Reply to', + 'url' => 'http://localhost/display/1', + 'photo' => 'http://localhost/', + 'date' => '2020-01-01 12:12:02', + 'msg' => 'A test reply from an item', + 'uid' => 42, + 'link' => 'http://localhost/notification/1', + 'iid' => 4, + 'seen' => 0, + 'verb' => \Friendica\Protocol\Activity::POST, + 'otype' => Notification\ObjectType::ITEM, 'name_cache' => 'Reply to', - 'msg_cache' => 'A test reply from an item', + 'msg_cache' => 'A test reply from an item', ], ], 'profile' => [ [ - 'id' => 1, + 'id' => 1, 'uid' => 42, ], ], - 'group' => [ + 'group' => [ [ 'id' => 1, 'uid' => 42, @@ -778,7 +827,14 @@ return [ 'name' => 'Private list', ], ], - 'search' => [ + 'group_member' => [ + [ + 'id' => 1, + 'gid' => 1, + 'contact-id' => 42, + ], + ], + 'search' => [ [ 'id' => 1, 'term' => 'Saved search', diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index eb5394ec9..2067a3536 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -6,21 +6,14 @@ namespace Friendica\Test\legacy; use Friendica\App; -use Friendica\App\Router; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; -use Friendica\Core\Protocol; use Friendica\DI; -use Friendica\Model\Post; use Friendica\Module\Api\ApiResponse; -use Friendica\Module\Api\Twitter\Media\Upload; use Friendica\Module\BaseApi; -use Friendica\Network\HTTPException; use Friendica\Security\BasicAuth; use Friendica\Test\FixtureTest; use Friendica\Util\Arrays; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Temporal; use Monolog\Handler\TestHandler; require_once __DIR__ . '/../../include/api.php'; diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php index 287b47b40..3cc1df296 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php @@ -2,29 +2,39 @@ namespace Friendica\Test\src\Module\Api\GnuSocial\GnuSocial; +use Friendica\App\BaseURL; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\GNUSocial\GNUSocial\Config; use Friendica\Test\src\Module\Api\ApiTest; class ConfigTest extends ApiTest { /** * Test the api_statusnet_config() function. - * - * @return void */ public function testApiStatusnetConfig() { - /* - $result = api_statusnet_config('json'); - self::assertEquals('localhost', $result['config']['site']['server']); - self::assertEquals('default', $result['config']['site']['theme']); - self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']); - self::assertTrue($result['config']['site']['fancy']); - self::assertEquals('en', $result['config']['site']['language']); - self::assertEquals('UTC', $result['config']['site']['timezone']); - self::assertEquals(200000, $result['config']['site']['textlimit']); - self::assertEquals('false', $result['config']['site']['private']); - self::assertEquals('false', $result['config']['site']['ssl']); - self::assertEquals(30, $result['config']['site']['shorturllength']); - */ + DI::config()->set('system', 'ssl_policy', BaseURL::SSL_POLICY_FULL); + + $config = new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $config->run(); + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertEquals(1, 1); + + self::assertEquals('localhost', $json->site->server); + self::assertEquals('frio', $json->site->theme); + self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $json->site->logo); + self::assertTrue($json->site->fancy); + self::assertEquals('en', $json->site->language); + self::assertEquals('UTC', $json->site->timezone); + self::assertEquals(200000, $json->site->textlimit); + self::assertFalse($json->site->private); + self::assertEquals('always', $json->site->ssl); } } diff --git a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php index 885afbb3e..f2a709531 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php @@ -2,6 +2,9 @@ namespace Friendica\Test\src\Module\Api\Mastodon\Accounts; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Mastodon\Accounts\Statuses; use Friendica\Test\src\Module\Api\ApiTest; class StatusesTest extends ApiTest @@ -11,6 +14,8 @@ class StatusesTest extends ApiTest */ public function testApiStatusShowWithJson() { + self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader'); + // $result = api_status_show('json', 1); // self::assertStatus($result['status']); } @@ -20,6 +25,8 @@ class StatusesTest extends ApiTest */ public function testApiStatusShowWithXml() { + self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader'); + // $result = api_status_show('xml', 1); // self::assertXml($result, 'statuses'); } diff --git a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php index 25611b245..5170f1cb2 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php @@ -2,6 +2,9 @@ namespace Friendica\Test\src\Module\Api\Mastodon\Accounts; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Mastodon\Accounts\VerifyCredentials; use Friendica\Test\src\Module\Api\ApiTest; class VerifyCredentialsTest extends ApiTest @@ -13,7 +16,18 @@ class VerifyCredentialsTest extends ApiTest */ public function testApiAccountVerifyCredentials() { - // self::assertArrayHasKey('user', api_account_verify_credentials('json')); + $verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $verifyCredentials->run(); + + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertEquals(48, $json->id); + self::assertIsArray($json->emojis); + self::assertIsArray($json->fields); } /** @@ -23,6 +37,8 @@ class VerifyCredentialsTest extends ApiTest */ public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser() { + self::markTestIncomplete('Needs dynamic BasicAuth first'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // BasicAuth::setCurrentUserID(); // $_SESSION['authenticated'] = false; diff --git a/tests/src/Module/Api/Mastodon/ConversationsTest.php b/tests/src/Module/Api/Mastodon/ConversationsTest.php index 838c591c2..e645cb8dd 100644 --- a/tests/src/Module/Api/Mastodon/ConversationsTest.php +++ b/tests/src/Module/Api/Mastodon/ConversationsTest.php @@ -13,6 +13,8 @@ class ConversationsTest extends ApiTest */ public function testApiConversationShow() { + self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader'); + // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); // api_conversation_show('json'); } @@ -24,6 +26,8 @@ class ConversationsTest extends ApiTest */ public function testApiConversationShowWithId() { + self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader'); + /* DI::args()->setArgv(['', '', '', 1]); $_REQUEST['max_id'] = 10; @@ -43,6 +47,8 @@ class ConversationsTest extends ApiTest */ public function testApiConversationShowWithUnallowedUser() { + self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // BasicAuth::setCurrentUserID(); // api_conversation_show('json'); diff --git a/tests/src/Module/Api/Mastodon/SearchTest.php b/tests/src/Module/Api/Mastodon/SearchTest.php index 417cb4d4b..caa0ed976 100644 --- a/tests/src/Module/Api/Mastodon/SearchTest.php +++ b/tests/src/Module/Api/Mastodon/SearchTest.php @@ -13,6 +13,8 @@ class SearchTest extends ApiTest */ public function testApiSearch() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['q'] = 'reply'; $_REQUEST['max_id'] = 10; @@ -31,6 +33,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithCount() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['q'] = 'reply'; $_REQUEST['count'] = 20; @@ -49,6 +53,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithRpp() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['q'] = 'reply'; $_REQUEST['rpp'] = 20; @@ -66,6 +72,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithHashtag() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['q'] = '%23friendica'; $result = api_search('json'); @@ -82,6 +90,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithExcludeReplies() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['max_id'] = 10; $_REQUEST['exclude_replies'] = true; @@ -100,6 +110,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithUnallowedUser() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // BasicAuth::setCurrentUserID(); // api_search('json'); @@ -112,6 +124,8 @@ class SearchTest extends ApiTest */ public function testApiSearchWithoutQuery() { + self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader'); + // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); // api_search('json'); } diff --git a/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php b/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php index 74b32ba79..b25cee378 100644 --- a/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php +++ b/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php @@ -13,6 +13,8 @@ class HomeTest extends ApiTest */ public function testApiStatusesHomeTimeline() { + self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['max_id'] = 10; $_REQUEST['exclude_replies'] = true; @@ -32,6 +34,8 @@ class HomeTest extends ApiTest */ public function testApiStatusesHomeTimelineWithNegativePage() { + self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['page'] = -2; $result = api_statuses_home_timeline('json'); @@ -49,6 +53,8 @@ class HomeTest extends ApiTest */ public function testApiStatusesHomeTimelineWithUnallowedUser() { + self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader'); + /* $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); BasicAuth::setCurrentUserID(); @@ -63,6 +69,8 @@ class HomeTest extends ApiTest */ public function testApiStatusesHomeTimelineWithRss() { + self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader'); + // $result = api_statuses_home_timeline('rss'); // self::assertXml($result, 'statuses'); } diff --git a/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php b/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php index c475dc2d6..a75c2f111 100644 --- a/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php +++ b/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php @@ -13,6 +13,8 @@ class PublicTimelineTest extends ApiTest */ public function testApiStatusesPublicTimeline() { + self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['max_id'] = 10; $_REQUEST['conversation_id'] = 1; @@ -31,6 +33,8 @@ class PublicTimelineTest extends ApiTest */ public function testApiStatusesPublicTimelineWithExcludeReplies() { + self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['max_id'] = 10; $_REQUEST['exclude_replies'] = true; @@ -49,6 +53,8 @@ class PublicTimelineTest extends ApiTest */ public function testApiStatusesPublicTimelineWithNegativePage() { + self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader'); + /* $_REQUEST['page'] = -2; $result = api_statuses_public_timeline('json'); @@ -66,6 +72,8 @@ class PublicTimelineTest extends ApiTest */ public function testApiStatusesPublicTimelineWithUnallowedUser() { + self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // BasicAuth::setCurrentUserID(); // api_statuses_public_timeline('json'); @@ -78,6 +86,8 @@ class PublicTimelineTest extends ApiTest */ public function testApiStatusesPublicTimelineWithRss() { + self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader'); + // $result = api_statuses_public_timeline('rss'); // self::assertXml($result, 'statuses'); } diff --git a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php index 64becb75c..1368990d0 100644 --- a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php +++ b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php @@ -2,6 +2,7 @@ namespace Friendica\Test\src\Module\Api\Twitter\Account; +use Friendica\App\Router; use Friendica\Capabilities\ICanCreateResponses; use Friendica\DI; use Friendica\Module\Api\Twitter\Account\RateLimitStatus; @@ -11,7 +12,7 @@ class RateLimitStatusTest extends ApiTest { public function testWithJson() { - $rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); + $rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); $response = $rateLimitStatus->run(); $result = json_decode($response->getBody()); diff --git a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php new file mode 100644 index 000000000..4ce3420d2 --- /dev/null +++ b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php @@ -0,0 +1,29 @@ + Router::POST], ['extension' => 'json']); + $response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']); + + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertEquals('new_name', $json->name); + self::assertEquals('new_description', $json->description); + } +} diff --git a/tests/src/Module/Api/Twitter/Account/UpdateTest.php b/tests/src/Module/Api/Twitter/Account/UpdateTest.php deleted file mode 100644 index 0be870042..000000000 --- a/tests/src/Module/Api/Twitter/Account/UpdateTest.php +++ /dev/null @@ -1,28 +0,0 @@ -selfUser['id'], $result['user']['cid']); - self::assertEquals('DFRN', $result['user']['location']); - self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']); - self::assertEquals('new_name', $result['user']['name']); - self::assertEquals('new_description', $result['user']['description']); - */ - } -} diff --git a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php index 9783a51e4..4f63581a7 100644 --- a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php @@ -2,30 +2,28 @@ namespace Friendica\Test\src\Module\Api\Twitter\Blocks; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Twitter\Blocks\Lists; use Friendica\Test\src\Module\Api\ApiTest; class ListsTest extends ApiTest { /** * Test the api_statuses_f() function. - * - * @return void */ public function testApiStatusesFWithBlocks() { - // $result = api_statuses_f('blocks'); - // self::assertArrayHasKey('user', $result); - } + $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $lists->run(); - /** - * Test the api_blocks_list() function. - * - * @return void - */ - public function testApiBlocksList() - { - // $result = api_blocks_list('json'); - // self::assertArrayHasKey('user', $result); + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertIsArray($json->users); } /** @@ -35,6 +33,8 @@ class ListsTest extends ApiTest */ public function testApiBlocksListWithUndefinedCursor() { + self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks'); + // $_GET['cursor'] = 'undefined'; // self::assertFalse(api_blocks_list('json')); } diff --git a/tests/src/Module/Api/Twitter/Followers/ListsTest.php b/tests/src/Module/Api/Twitter/Followers/ListsTest.php index 200822795..c1e053e5a 100644 --- a/tests/src/Module/Api/Twitter/Followers/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Followers/ListsTest.php @@ -2,30 +2,28 @@ namespace Friendica\Test\src\Module\Api\Twitter\Followers; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Twitter\Followers\Lists; use Friendica\Test\src\Module\Api\ApiTest; class ListsTest extends ApiTest { /** * Test the api_statuses_f() function. - * - * @return void */ public function testApiStatusesFWithFollowers() { - // $result = api_statuses_f('followers'); - // self::assertArrayHasKey('user', $result); - } + $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $lists->run(); - /** - * Test the api_statuses_followers() function. - * - * @return void - */ - public function testApiStatusesFollowers() - { - // $result = api_statuses_followers('json'); - // self::assertArrayHasKey('user', $result); + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertIsArray($json->users); } /** @@ -35,6 +33,8 @@ class ListsTest extends ApiTest */ public function testApiStatusesFollowersWithUndefinedCursor() { + self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks'); + // $_GET['cursor'] = 'undefined'; // self::assertFalse(api_statuses_followers('json')); } diff --git a/tests/src/Module/Api/Twitter/Friends/ListsTest.php b/tests/src/Module/Api/Twitter/Friends/ListsTest.php index c4c48dace..363f8d73c 100644 --- a/tests/src/Module/Api/Twitter/Friends/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Friends/ListsTest.php @@ -2,6 +2,9 @@ namespace Friendica\Test\src\Module\Api\Twitter\Friends; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Twitter\Friends\Lists; use Friendica\Test\src\Module\Api\ApiTest; class ListsTest extends ApiTest @@ -13,9 +16,16 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithFriends() { - // $_GET['page'] = -1; - // $result = api_statuses_f('friends'); - // self::assertArrayHasKey('user', $result); + $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $lists->run(); + + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertIsArray($json->users); } /** @@ -25,29 +35,9 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithUndefinedCursor() { + self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks'); + // $_GET['cursor'] = 'undefined'; // self::assertFalse(api_statuses_f('friends')); } - - /** - * Test the api_statuses_friends() function. - * - * @return void - */ - public function testApiStatusesFriends() - { - // $result = api_statuses_friends('json'); - // self::assertArrayHasKey('user', $result); - } - - /** - * Test the api_statuses_friends() function an undefined cursor GET variable. - * - * @return void - */ - public function testApiStatusesFriendsWithUndefinedCursor() - { - // $_GET['cursor'] = 'undefined'; - // self::assertFalse(api_statuses_friends('json')); - } } diff --git a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php index 583280097..8c5cb6426 100644 --- a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php +++ b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php @@ -2,6 +2,9 @@ namespace Friendica\Test\src\Module\Api\Twitter\Friendships; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Twitter\Friendships\Incoming; use Friendica\Test\src\Module\Api\ApiTest; class IncomingTest extends ApiTest @@ -13,8 +16,16 @@ class IncomingTest extends ApiTest */ public function testApiFriendshipsIncoming() { - // $result = api_friendships_incoming('json'); - // self::assertArrayHasKey('id', $result); + $lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $lists->run(); + + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + self::assertIsArray($json->ids); } /** @@ -24,6 +35,8 @@ class IncomingTest extends ApiTest */ public function testApiFriendshipsIncomingWithUndefinedCursor() { + self::markTestIncomplete('Needs refactoring of Incoming - replace filter_input() with $request parameter checks'); + // $_GET['cursor'] = 'undefined'; // self::assertFalse(api_friendships_incoming('json')); } diff --git a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php index 8dcb9d331..5d989b71e 100644 --- a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php +++ b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php @@ -2,6 +2,10 @@ namespace Friendica\Test\src\Module\Api\Twitter\Lists; +use Friendica\App\Router; +use Friendica\DI; +use Friendica\Module\Api\Twitter\Lists\Statuses; +use Friendica\Network\HTTPException\BadRequestException; use Friendica\Test\src\Module\Api\ApiTest; class StatusesTest extends ApiTest @@ -13,37 +17,41 @@ class StatusesTest extends ApiTest */ public function testApiListsStatuses() { - // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - // api_lists_statuses('json'); + $this->expectException(BadRequestException::class); + + $lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $lists->run(); } /** * Test the api_lists_statuses() function with a list ID. - * @doesNotPerformAssertions */ public function testApiListsStatusesWithListId() { - /* - $_REQUEST['list_id'] = 1; - $_REQUEST['page'] = -1; - $_REQUEST['max_id'] = 10; - $result = api_lists_statuses('json'); - foreach ($result['status'] as $status) { - self::assertStatus($status); + $lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); + $response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]); + + $body = (string)$response->getBody(); + + self::assertJson($body); + + $json = json_decode($body); + + foreach ($json as $status) { + self::assertIsString($status->text); + self::assertIsInt($status->id); } - */ } /** * Test the api_lists_statuses() function with a list ID and a RSS result. - * - * @return void */ public function testApiListsStatusesWithListIdAndRss() { - // $_REQUEST['list_id'] = 1; - // $result = api_lists_statuses('rss'); - // self::assertXml($result, 'statuses'); + $lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); + $response = $lists->run(['list_id' => 1]); + + self::assertXml((string)$response->getBody()); } /** @@ -53,6 +61,8 @@ class StatusesTest extends ApiTest */ public function testApiListsStatusesWithUnallowedUser() { + self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // BasicAuth::setCurrentUserID(); // api_lists_statuses('json');