1
0
Fork 0

Merge pull request #11084 from nupplaphil/feat/tests_followup

Another bunch of reeanbled tests & some minor API fixings
This commit is contained in:
Hypolite Petovan 2021-12-10 12:16:14 -05:00 committed by GitHub
commit ad9928e631
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 741 additions and 502 deletions

View file

@ -45,10 +45,10 @@ class Favorites extends BaseApi
Logger::info(BaseApi::LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites']); Logger::info(BaseApi::LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites']);
// params // params
$since_id = $_REQUEST['since_id'] ?? 0; $since_id = $request['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0; $max_id = $request['max_id'] ?? 0;
$count = $_GET['count'] ?? 20; $count = $request['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1; $page = $request['page'] ?? 1;
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
@ -64,7 +64,7 @@ class Favorites extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View file

@ -26,6 +26,7 @@ use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Network\HTTPException\BadRequestException;
/** /**
* Destroys a specific status. * Destroys a specific status.
@ -39,10 +40,12 @@ class Destroy extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
if (empty($this->parameters['id'])) { if (!empty($this->parameters['id'])) {
$id = intval($request['id'] ?? 0);
} else {
$id = (int)$this->parameters['id']; $id = (int)$this->parameters['id'];
} elseif (!empty($request['id'])) {
$id = (int)$request['id'];
} else {
throw new BadRequestException('An id is missing.');
} }
$this->logger->notice('API: api_statuses_destroy: ' . $id); $this->logger->notice('API: api_statuses_destroy: ' . $id);

View file

@ -70,6 +70,6 @@ class Retweet extends BaseApi
$status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray(); $status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray();
DI::apiResponse()->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); DI::apiResponse()->exit('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -42,14 +42,14 @@ class Show extends BaseApi
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
if (empty($this->parameters['id'])) { if (empty($this->parameters['id'])) {
$id = intval($_REQUEST['id'] ?? 0); $id = intval($request['id'] ?? 0);
} else { } else {
$id = (int)$this->parameters['id']; $id = (int)$this->parameters['id'];
} }
Logger::notice('API: api_statuses_show: ' . $id); Logger::notice('API: api_statuses_show: ' . $id);
$conversation = !empty($_REQUEST['conversation']); $conversation = !empty($request['conversation']);
// try to fetch the item for the local user - or the public item, if there is no local one // try to fetch the item for the local user - or the public item, if there is no local one
$uri_item = Post::selectFirst(['uri-id'], ['id' => $id]); $uri_item = Post::selectFirst(['uri-id'], ['id' => $id]);
@ -79,7 +79,7 @@ class Show extends BaseApi
throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id)); throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
} }
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {
@ -92,7 +92,7 @@ class Show extends BaseApi
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} else { } else {
$data = ['status' => $ret[0]]; $data = ['status' => $ret[0]];
$this->response->exit('status', ['status' => $data], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }
} }

View file

@ -44,7 +44,7 @@ use HTMLPurifier_Config;
*/ */
class Update extends BaseApi class Update extends BaseApi
{ {
public function post(array $request = [], array $post = []) public function post(array $request = [])
{ {
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
@ -101,10 +101,10 @@ class Update extends BaseApi
$item['coord'] = sprintf("%s %s", $request['lat'], $request['long']); $item['coord'] = sprintf("%s %s", $request['lat'], $request['long']);
} }
$item['allow_cid'] = $owner['allow_cid']; $item['allow_cid'] = $owner['allow_cid'] ?? '';
$item['allow_gid'] = $owner['allow_gid']; $item['allow_gid'] = $owner['allow_gid'] ?? '';
$item['deny_cid'] = $owner['deny_cid']; $item['deny_cid'] = $owner['deny_cid'] ?? '';
$item['deny_gid'] = $owner['deny_gid']; $item['deny_gid'] = $owner['deny_gid'] ?? '';
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) { if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
$item['private'] = Item::PRIVATE; $item['private'] = Item::PRIVATE;
@ -127,8 +127,8 @@ class Update extends BaseApi
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
} }
if (!empty($_REQUEST['media_ids'])) { if (!empty($request['media_ids'])) {
$ids = explode(',', $_REQUEST['media_ids']); $ids = explode(',', $request['media_ids']);
} elseif (!empty($_FILES['media'])) { } elseif (!empty($_FILES['media'])) {
// upload the image if we have one // upload the image if we have one
$picture = Photo::upload($uid, $_FILES['media']); $picture = Photo::upload($uid, $_FILES['media']);

View file

@ -40,17 +40,17 @@ class UserTimeline extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $_REQUEST]); Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $request]);
$cid = BaseApi::getContactIDForSearchterm($_REQUEST['screen_name'] ?? '', $_REQUEST['profileurl'] ?? '', $_REQUEST['user_id'] ?? 0, $uid); $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid);
$since_id = $_REQUEST['since_id'] ?? 0; $since_id = $request['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0; $max_id = $request['max_id'] ?? 0;
$exclude_replies = !empty($_REQUEST['exclude_replies']); $exclude_replies = !empty($request['exclude_replies']);
$conversation_id = $_REQUEST['conversation_id'] ?? 0; $conversation_id = $request['conversation_id'] ?? 0;
// pagination // pagination
$count = $_REQUEST['count'] ?? 20; $count = $request['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1; $page = $request['page'] ?? 1;
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
@ -74,7 +74,7 @@ class UserTimeline extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {
@ -82,6 +82,6 @@ class UserTimeline extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('user', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -39,8 +39,8 @@ class Lookup extends BaseApi
$users = []; $users = [];
if (!empty($_REQUEST['user_id'])) { if (!empty($request['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $cid) { foreach (explode(',', $request['user_id']) as $cid) {
if (!empty($cid) && is_numeric($cid)) { if (!empty($cid) && is_numeric($cid)) {
$users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid, false)->toArray(); $users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid, false)->toArray();
} }

View file

@ -42,15 +42,15 @@ class Search extends BaseApi
$userlist = []; $userlist = [];
if (!empty($_GET['q'])) { if (!empty($request['q'])) {
$contacts = Contact::selectToArray( $contacts = Contact::selectToArray(
['id'], ['id'],
[ [
'`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)', '`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)',
$_GET['q'], $request['q'],
$_GET['q'], $request['q'],
$_GET['q'], $request['q'],
$_GET['q'], $request['q'],
] ]
); );
@ -63,12 +63,12 @@ class Search extends BaseApi
} }
$userlist = ['users' => $userlist]; $userlist = ['users' => $userlist];
} else { } else {
throw new NotFoundException('User ' . $_GET['q'] . ' not found.'); throw new NotFoundException('User ' . $request['q'] . ' not found.');
} }
} else { } else {
throw new BadRequestException('No search term specified.'); throw new BadRequestException('No search term specified.');
} }
$this->response->exit('users', ['user' => $userlist], $this->parameters['extension'] ?? null); $this->response->exit('users', $userlist, $this->parameters['extension'] ?? null);
} }
} }

View file

@ -38,7 +38,7 @@ class Show extends BaseApi
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
if (empty($this->parameters['id'])) { if (empty($this->parameters['id'])) {
$cid = BaseApi::getContactIDForSearchterm($_REQUEST['screen_name'] ?? '', $_REQUEST['profileurl'] ?? '', $_REQUEST['user_id'] ?? 0, $uid); $cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid);
} else { } else {
$cid = (int)$this->parameters['id']; $cid = (int)$this->parameters['id'];
} }

View file

@ -69,7 +69,8 @@ return [
'username' => 'Test user', 'username' => 'Test user',
'nickname' => 'selfcontact', 'nickname' => 'selfcontact',
'verified' => 1, 'verified' => 1,
'password' => '$2y$10$DLRNTRmJgKe1cSrFJ5Jb0edCqvXlA9sh/RHdSnfxjbR.04yZRm4Qm', 'prvkey' => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDVqxF9kIgtgRL0+q+jTi578FA1r1+crEmlYc0pdxcbmmrhjuRc\nrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/KHVks7eQ4yr4MxTRlsxo5qf2o\nnbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjsQPX240vGNXIkfLiAWwIDAQAB\nAoGBAIwuiPIdggqAtWQ+mD8HCx5LQwSFw6/xpPu5F7ZNqL52aAsGCbL3o2QoIG4c\na1qf9Ot16BNgNBqxQF3hzRTkBMrKYlmNTUkwJXun/zjQJq2JvOlcrSuXlIucUjs4\nXekVN25aYPHrX9m2FEIUwZTb4UYXbR80KbIDI53BkQ6EwSbpAkEA7aO49CR2Hf1Y\n1d2GaUI/Z0wvbj//+t0Kg0bPt16ca8KVjEQQA5ylsDaiw510jDz9NBQxSOk6If23\nUeRixc1RDQJBAOYtN4YnPM1Zfp6IxXlqMCc+xUWRTPEPFt+WpG+v79koNamAeA6o\nZzTl92hl58IqSdbgojeE2zXWQRvlimFMLQcCQQCV6jND0byyLqFcSeQBg0l8YROK\n+dUC7W80YfeoNod3c8nkMwvnO2tLPyxvO2XLEq6prBNra7bAus5rWyj0oBIBAkEA\n1EvUMFm0TLpEfLgtWuTD8Q6GKLnxO0ztjd+FXrXpBGN/ywyArxRHzJRmctW6wmz6\nmcOqGobhIHCysKYv0bnOtQJAc2M5RwlASHH4jGJzXgt3nboyiJfufM0RV9iry3ho\nCXQRWAONKoLqnsfC6qNP8OzY8FMJcwmPWj7Q/6z6yLBFTA==\n-----END RSA PRIVATE KEY-----",
'pubkey' => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----", 'password' => '$2y$10$DLRNTRmJgKe1cSrFJ5Jb0edCqvXlA9sh/RHdSnfxjbR.04yZRm4Qm',
'theme' => 'frio', 'theme' => 'frio',
], ],
], ],
@ -137,6 +138,8 @@ return [
'nurl' => 'http://localhost/profile/selfcontact', 'nurl' => 'http://localhost/profile/selfcontact',
'url' => 'http://localhost/profile/selfcontact', 'url' => 'http://localhost/profile/selfcontact',
'about' => 'User used in tests', 'about' => 'User used in tests',
'prvkey' => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDVqxF9kIgtgRL0+q+jTi578FA1r1+crEmlYc0pdxcbmmrhjuRc\nrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/KHVks7eQ4yr4MxTRlsxo5qf2o\nnbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjsQPX240vGNXIkfLiAWwIDAQAB\nAoGBAIwuiPIdggqAtWQ+mD8HCx5LQwSFw6/xpPu5F7ZNqL52aAsGCbL3o2QoIG4c\na1qf9Ot16BNgNBqxQF3hzRTkBMrKYlmNTUkwJXun/zjQJq2JvOlcrSuXlIucUjs4\nXekVN25aYPHrX9m2FEIUwZTb4UYXbR80KbIDI53BkQ6EwSbpAkEA7aO49CR2Hf1Y\n1d2GaUI/Z0wvbj//+t0Kg0bPt16ca8KVjEQQA5ylsDaiw510jDz9NBQxSOk6If23\nUeRixc1RDQJBAOYtN4YnPM1Zfp6IxXlqMCc+xUWRTPEPFt+WpG+v79koNamAeA6o\nZzTl92hl58IqSdbgojeE2zXWQRvlimFMLQcCQQCV6jND0byyLqFcSeQBg0l8YROK\n+dUC7W80YfeoNod3c8nkMwvnO2tLPyxvO2XLEq6prBNra7bAus5rWyj0oBIBAkEA\n1EvUMFm0TLpEfLgtWuTD8Q6GKLnxO0ztjd+FXrXpBGN/ywyArxRHzJRmctW6wmz6\nmcOqGobhIHCysKYv0bnOtQJAc2M5RwlASHH4jGJzXgt3nboyiJfufM0RV9iry3ho\nCXQRWAONKoLqnsfC6qNP8OzY8FMJcwmPWj7Q/6z6yLBFTA==\n-----END RSA PRIVATE KEY-----",
'pubkey' => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----",
'pending' => 0, 'pending' => 0,
'blocked' => 0, 'blocked' => 0,
'rel' => Contact::FOLLOWER, 'rel' => Contact::FOLLOWER,
@ -259,7 +262,7 @@ return [
"header" => null, "header" => null,
"addr" => "selfcontact@localhost", "addr" => "selfcontact@localhost",
"alias" => null, "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-----", "pubkey" => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----",
"subscribe" => "/follow?url={uri}", "subscribe" => "/follow?url={uri}",
"baseurl" => null, "baseurl" => null,
"gsid" => null, "gsid" => null,
@ -833,6 +836,16 @@ return [
'gid' => 1, 'gid' => 1,
'contact-id' => 42, 'contact-id' => 42,
], ],
[
'id' => 2,
'gid' => 1,
'contact-id' => 42,
],
[
'id' => 3,
'gid' => 2,
'contact-id' => 43,
],
], ],
'search' => [ 'search' => [
[ [

View file

@ -112,55 +112,6 @@ class ApiTest extends FixtureTest
BasicAuth::setCurrentUserID($this->selfUser['id']); BasicAuth::setCurrentUserID($this->selfUser['id']);
} }
/**
* Assert that an user array contains expected keys.
*
* @param array $user User array
*
* @return void
*/
private function assertSelfUser(array $user)
{
self::assertEquals($this->selfUser['id'], $user['uid']);
self::assertEquals($this->selfUser['id'], $user['cid']);
self::assertEquals(1, $user['self']);
self::assertEquals('DFRN', $user['location']);
self::assertEquals($this->selfUser['name'], $user['name']);
self::assertEquals($this->selfUser['nick'], $user['screen_name']);
self::assertEquals('dfrn', $user['network']);
self::assertTrue($user['verified']);
}
/**
* Assert that an user array contains expected keys.
*
* @param array $user User array
*
* @return void
*/
private function assertOtherUser(array $user = [])
{
self::assertEquals($this->otherUser['id'], $user['id']);
self::assertEquals($this->otherUser['id'], $user['id_str']);
self::assertEquals($this->otherUser['name'], $user['name']);
self::assertEquals($this->otherUser['nick'], $user['screen_name']);
self::assertFalse($user['verified']);
}
/**
* Assert that a status array contains expected keys.
*
* @param array $status Status array
*
* @return void
*/
private function assertStatus(array $status = [])
{
self::assertIsString($status['text'] ?? '');
self::assertIsInt($status['id'] ?? '');
// We could probably do more checks here.
}
/** /**
* Assert that a list array contains expected keys. * Assert that a list array contains expected keys.
* *
@ -884,232 +835,6 @@ class ApiTest extends FixtureTest
// api_statuses_mediap('json'); // api_statuses_mediap('json');
} }
/**
* Test the api_statuses_update() function.
*
* @return void
*/
public function testApiStatusesUpdate()
{
/*
$_REQUEST['status'] = 'Status content #friendica';
$_REQUEST['in_reply_to_status_id'] = -1;
$_REQUEST['lat'] = 48;
$_REQUEST['long'] = 7;
$_FILES = [
'media' => [
'id' => 666,
'size' => 666,
'width' => 666,
'height' => 666,
'tmp_name' => $this->getTempImage(),
'name' => 'spacer.png',
'type' => 'image/png'
]
];
$result = api_statuses_update('json');
self::assertStatus($result['status']);
*/
}
/**
* Test the api_statuses_update() function with an HTML status.
*
* @return void
*/
public function testApiStatusesUpdateWithHtml()
{
/*
$_REQUEST['htmlstatus'] = '<b>Status content</b>';
$result = api_statuses_update('json');
self::assertStatus($result['status']);
*/
}
/**
* Test the api_statuses_update() function without an authenticated user.
*
* @return void
*/
public function testApiStatusesUpdateWithoutAuthenticatedUser()
{
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_update('json');
*/
}
/**
* Test the api_statuses_update() function with a parent status.
*
* @return void
*/
public function testApiStatusesUpdateWithParent()
{
$this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
}
/**
* Test the api_statuses_update() function with a media_ids parameter.
*
* @return void
*/
public function testApiStatusesUpdateWithMediaIds()
{
$this->markTestIncomplete();
}
/**
* Test the api_statuses_update() function with the throttle limit reached.
*
* @return void
*/
public function testApiStatusesUpdateWithDayThrottleReached()
{
$this->markTestIncomplete();
}
/**
* Test the api_statuses_repeat() function.
*
* @return void
*/
public function testApiStatusesRepeat()
{
// $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
// api_statuses_repeat('json');
}
/**
* Test the api_statuses_repeat() function without an authenticated user.
*
* @return void
*/
public function testApiStatusesRepeatWithoutAuthenticatedUser()
{
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false;
// api_statuses_repeat('json');
}
/**
* Test the api_statuses_repeat() function with an ID.
*
* @return void
*/
public function testApiStatusesRepeatWithId()
{
// DI::args()->setArgv(['', '', '', 1]);
// $result = api_statuses_repeat('json');
// self::assertStatus($result['status']);
// Also test with a shared status
// DI::args()->setArgv(['', '', '', 5]);
// $result = api_statuses_repeat('json');
// self::assertStatus($result['status']);
}
/**
* Test the api_favorites_create_destroy() function.
*
* @return void
*/
public function testApiFavoritesCreateDestroy()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
// api_favorites_create_destroy('json');
}
/**
* Test the api_favorites_create_destroy() function with an invalid ID.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithInvalidId()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
// api_favorites_create_destroy('json');
}
/**
* Test the api_favorites_create_destroy() function with an invalid action.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithInvalidAction()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
// $_REQUEST['id'] = 1;
// api_favorites_create_destroy('json');
}
/**
* Test the api_favorites_create_destroy() function with the create action.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithCreateAction()
{
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
// $_REQUEST['id'] = 3;
// $result = api_favorites_create_destroy('json');
// self::assertStatus($result['status']);
}
/**
* Test the api_favorites_create_destroy() function with the create action and an RSS result.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
// $_REQUEST['id'] = 3;
// $result = api_favorites_create_destroy('rss');
// self::assertXml($result, 'status');
}
/**
* Test the api_favorites_create_destroy() function with the destroy action.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithDestroyAction()
{
// DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
// $_REQUEST['id'] = 3;
// $result = api_favorites_create_destroy('json');
// self::assertStatus($result['status']);
}
/**
* Test the api_favorites_create_destroy() function without an authenticated user.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
*/
}
/** /**
* Test the api_format_messages() function. * Test the api_format_messages() function.
* *

View file

@ -22,6 +22,7 @@
namespace Friendica\Test\src\Module\Api; namespace Friendica\Test\src\Module\Api;
use Friendica\App; use Friendica\App;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Database\Database; use Friendica\Database\Database;
@ -32,9 +33,35 @@ use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppDouble; use Friendica\Test\Util\AppDouble;
use Friendica\Test\Util\AuthenticationDouble; use Friendica\Test\Util\AuthenticationDouble;
use Friendica\Test\Util\AuthTestConfig; use Friendica\Test\Util\AuthTestConfig;
use Psr\Http\Message\ResponseInterface;
abstract class ApiTest extends FixtureTest abstract class ApiTest extends FixtureTest
{ {
// User data that the test database is populated with
const SELF_USER = [
'id' => 42,
'name' => 'Self contact',
'nick' => 'selfcontact',
'nurl' => 'http://localhost/profile/selfcontact'
];
const FRIEND_USER = [
'id' => 44,
'name' => 'Friend contact',
'nick' => 'friendcontact',
'nurl' => 'http://localhost/profile/friendcontact'
];
const OTHER_USER = [
'id' => 43,
'name' => 'othercontact',
'nick' => 'othercontact',
'nurl' => 'http://localhost/profile/othercontact'
];
// User ID that we know is not in the database
const WRONG_USER_ID = 666;
/** /**
* Assert that the string is XML and contain the root element. * Assert that the string is XML and contain the root element.
* *
@ -50,6 +77,92 @@ abstract class ApiTest extends FixtureTest
// We could probably do more checks here. // We could probably do more checks here.
} }
/**
* Assert that an user array contains expected keys.
*
* @param \stdClass $user User
*
* @return void
*/
protected function assertSelfUser(\stdClass $user)
{
self::assertEquals(self::SELF_USER['id'], $user->uid);
self::assertEquals(self::SELF_USER['id'], $user->cid);
self::assertEquals(1, $user->self);
self::assertEquals('DFRN', $user->location);
self::assertEquals(self::SELF_USER['name'], $user->name);
self::assertEquals(self::SELF_USER['nick'], $user->screen_name);
self::assertEquals('dfrn', $user->network);
self::assertTrue($user->verified);
}
/**
* Assert that an user array contains expected keys.
*
* @param \stdClass $user User
*
* @return void
*/
protected function assertOtherUser(\stdClass $user)
{
self::assertEquals(self::OTHER_USER['id'], $user->id);
self::assertEquals(self::OTHER_USER['id'], $user->id_str);
self::assertEquals(self::OTHER_USER['name'], $user->name);
self::assertEquals(self::OTHER_USER['nick'], $user->screen_name);
self::assertFalse($user->verified);
}
/**
* Assert that a status array contains expected keys.
*
* @param \stdClass $status Status
*
* @return void
*/
protected function assertStatus(\stdClass $status)
{
self::assertIsString($status->text);
self::assertIsInt($status->id);
// We could probably do more checks here.
}
/**
* Get the path to a temporary empty PNG image.
*
* @return string Path
*/
protected function getTempImage()
{
$tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
file_put_contents(
$tmpFile,
base64_decode(
// Empty 1x1 px PNG image
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
)
);
return $tmpFile;
}
/**
* Transforms a response into a JSON class
*
* @param ResponseInterface $response
*
* @return mixed
*/
protected function toJson(ResponseInterface $response)
{
self::assertEquals(ICanCreateResponses::TYPE_JSON, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
$body = (string)$response->getBody();
self::assertJson($body);
return json_decode($body);
}
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); // TODO: Change the autogenerated stub parent::setUp(); // TODO: Change the autogenerated stub
@ -63,7 +176,7 @@ abstract class ApiTest extends FixtureTest
DI::app()->setIsLoggedIn(true); DI::app()->setIsLoggedIn(true);
AuthTestConfig::$authenticated = true; AuthTestConfig::$authenticated = true;
AuthTestConfig::$user_id = 42; AuthTestConfig::$user_id = 42;
$this->installAuthTest(); $this->installAuthTest();
} }

View file

@ -78,7 +78,16 @@ XML;
$notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']);
$response = $notification->run(); $response = $notification->run();
self::assertJson($response->getBody()); $json = $this->toJson($response);
self::assertIsArray($json);
foreach ($json as $note) {
self::assertIsInt($note->id);
self::assertIsInt($note->uid);
self::assertIsString($note->msg);
}
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
} }
} }

View file

@ -53,11 +53,7 @@ class DeleteTest extends ApiTest
$delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']); $response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']);
$responseText = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($responseText);
$json = json_decode($responseText);
self::assertEquals('deleted', $json->result); self::assertEquals('deleted', $json->result);
self::assertEquals('photo with id `709057080661a283a6aa598501504178` has been deleted from server.', $json->message); self::assertEquals('photo with id `709057080661a283a6aa598501504178` has been deleted from server.', $json->message);

View file

@ -49,11 +49,7 @@ class DeleteTest extends ApiTest
$delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $delete->run(['album' => 'test_album']); $response = $delete->run(['album' => 'test_album']);
$responseText = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($responseText);
$json = json_decode($responseText);
self::assertEquals('deleted', $json->result); self::assertEquals('deleted', $json->result);
self::assertEquals('album `test_album` with all containing photos has been deleted.', $json->message); self::assertEquals('album `test_album` with all containing photos has been deleted.', $json->message);

View file

@ -58,11 +58,7 @@ class UpdateTest extends ApiTest
$response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'test_album', 'album_new' => 'test_album_2']); $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'test_album', 'album_new' => 'test_album_2']);
$responseBody = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($responseBody);
$json = json_decode($responseBody);
self::assertEquals('updated', $json->result); self::assertEquals('updated', $json->result);
self::assertEquals('album `test_album` with all containing photos has been renamed to `test_album_2`.', $json->message); self::assertEquals('album `test_album` with all containing photos has been renamed to `test_album_2`.', $json->message);

View file

@ -19,13 +19,8 @@ class ConfigTest extends ApiTest
$config = new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $config = new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $config->run(); $response = $config->run();
$body = (string)$response->getBody();
self::assertJson($body); $json = $this->toJson($response);
$json = json_decode($body);
self::assertEquals(1, 1);
self::assertEquals('localhost', $json->site->server); self::assertEquals('localhost', $json->site->server);
self::assertEquals('frio', $json->site->theme); self::assertEquals('frio', $json->site->theme);

View file

@ -14,8 +14,10 @@ class TestTest extends ApiTest
$test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']);
$response = $test->run(); $response = $test->run();
$json = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals('"ok"', $response->getBody()); self::assertEquals('ok', $json);
} }
public function testXml() public function testXml()

View file

@ -2,9 +2,6 @@
namespace Friendica\Test\src\Module\Api\Mastodon\Accounts; 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; use Friendica\Test\src\Module\Api\ApiTest;
class StatusesTest extends ApiTest class StatusesTest extends ApiTest

View file

@ -19,11 +19,7 @@ class VerifyCredentialsTest extends ApiTest
$verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $verifyCredentials->run(); $response = $verifyCredentials->run();
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertEquals(48, $json->id); self::assertEquals(48, $json->id);
self::assertIsArray($json->emojis); self::assertIsArray($json->emojis);

View file

@ -15,7 +15,7 @@ class RateLimitStatusTest extends ApiTest
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['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(); $response = $rateLimitStatus->run();
$result = json_decode($response->getBody()); $result = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals(150, $result->remaining_hits); self::assertEquals(150, $result->remaining_hits);

View file

@ -17,11 +17,7 @@ class UpdateProfileTest extends ApiTest
$updateProfile = new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']); $updateProfile = new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']);
$response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']); $response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']);
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertEquals('new_name', $json->name); self::assertEquals('new_name', $json->name);
self::assertEquals('new_description', $json->description); self::assertEquals('new_description', $json->description);

View file

@ -17,11 +17,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(); $response = $lists->run();
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users); self::assertIsArray($json->users);
} }

View file

@ -32,6 +32,8 @@ class ContactEndpointTest extends FixtureTest
{ {
public function testIds() public function testIds()
{ {
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/* /*
$expectedEmpty = [ $expectedEmpty = [
'ids' => [], 'ids' => [],
@ -77,6 +79,8 @@ class ContactEndpointTest extends FixtureTest
*/ */
public function testIdsStringify() public function testIdsStringify()
{ {
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/* /*
$result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true); $result = ContactEndpointMock::ids(Contact::SHARING, 42, -1, ContactEndpoint::DEFAULT_COUNT, true);
@ -88,6 +92,8 @@ class ContactEndpointTest extends FixtureTest
public function testIdsPagination() public function testIdsPagination()
{ {
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/* /*
$expectedDefaultPageResult = [ $expectedDefaultPageResult = [
'ids' => [45], 'ids' => [45],
@ -172,6 +178,8 @@ class ContactEndpointTest extends FixtureTest
*/ */
public function testList() public function testList()
{ {
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/* /*
$expectedEmpty = [ $expectedEmpty = [
'users' => [], 'users' => [],

View file

@ -0,0 +1,74 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Favorites;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Favorites\Create;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
class CreateTest extends ApiTest
{
/**
* Test the api_favorites_create_destroy() function with an invalid ID.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithInvalidId()
{
$this->expectException(BadRequestException::class);
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$create->run();
}
/**
* Test the api_favorites_create_destroy() function with the create action.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithCreateAction()
{
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $create->run(['id' => 3]);
$json = $this->toJson($response);
self::assertStatus($json);
}
/**
* Test the api_favorites_create_destroy() function with the create action and an RSS result.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS]);
$response = $create->run(['id' => 3]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
}
/**
* Test the api_favorites_create_destroy() function without an authenticated user.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
*/
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Favorites;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Favorites\Destroy;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
class DestroyTest extends ApiTest
{
/**
* Test the api_favorites_create_destroy() function with an invalid ID.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithInvalidId()
{
$this->expectException(BadRequestException::class);
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$destroy->run();
}
/**
* Test the api_favorites_create_destroy() function with the destroy action.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithDestroyAction()
{
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $destroy->run(['id' => 3]);
$json = $this->toJson($response);
self::assertStatus($json);
}
/**
* Test the api_favorites_create_destroy() function without an authenticated user.
*
* @return void
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
*/
}
}

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter; namespace Friendica\Test\src\Module\Api\Twitter;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Favorites;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class FavoritesTest extends ApiTest class FavoritesTest extends ApiTest
@ -13,14 +17,17 @@ class FavoritesTest extends ApiTest
*/ */
public function testApiFavorites() public function testApiFavorites()
{ {
/* $favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$_REQUEST['page'] = -1; $response = $favorites->run([
$_REQUEST['max_id'] = 10; 'page' => -1,
$result = api_favorites('json'); 'max_id' => 10,
foreach ($result['status'] as $status) { ]);
self::assertStatus($status);
$json = $this->toJson($response);
foreach ($json as $status) {
$this->assertStatus($status);
} }
*/
} }
/** /**
@ -30,8 +37,12 @@ class FavoritesTest extends ApiTest
*/ */
public function testApiFavoritesWithRss() public function testApiFavoritesWithRss()
{ {
// $result = api_favorites('rss'); $favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]);
// self::assertXml($result, 'statuses'); $response = $favorites->run();
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
} }
/** /**
@ -41,6 +52,8 @@ class FavoritesTest extends ApiTest
*/ */
public function testApiFavoritesWithUnallowedUser() public function testApiFavoritesWithUnallowedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// api_favorites('json'); // api_favorites('json');

View file

@ -17,11 +17,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(); $response = $lists->run();
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users); self::assertIsArray($json->users);
} }

View file

@ -19,11 +19,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(); $response = $lists->run();
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users); self::assertIsArray($json->users);
} }

View file

@ -19,11 +19,7 @@ class IncomingTest extends ApiTest
$lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(); $response = $lists->run();
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->ids); self::assertIsArray($json->ids);
} }

View file

@ -31,11 +31,7 @@ class StatusesTest extends ApiTest
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $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]); $response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]);
$body = (string)$response->getBody(); $json = $this->toJson($response);
self::assertJson($body);
$json = json_decode($body);
foreach ($json as $status) { foreach ($json as $status) {
self::assertIsString($status->text); self::assertIsString($status->text);

View file

@ -72,30 +72,12 @@ class UploadTest extends ApiTest
]; ];
$response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run();
$media = json_decode($response->getBody(), true);
self::assertEquals('image/png', $media['image']['image_type']); $media = $this->toJson($response);
self::assertEquals(1, $media['image']['w']);
self::assertEquals(1, $media['image']['h']);
self::assertNotEmpty($media['image']['friendica_preview_url']);
}
/** self::assertEquals('image/png', $media->image->image_type);
* Get the path to a temporary empty PNG image. self::assertEquals(1, $media->image->w);
* self::assertEquals(1, $media->image->h);
* @return string Path self::assertNotEmpty($media->image->friendica_preview_url);
*/
private function getTempImage()
{
$tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
file_put_contents(
$tmpFile,
base64_decode(
// Empty 1x1 px PNG image
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
)
);
return $tmpFile;
} }
} }

View file

@ -14,7 +14,7 @@ class SavedSearchesTest extends ApiTest
$savedSearch = new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $savedSearch = new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']);
$response = $savedSearch->run(); $response = $savedSearch->run();
$result = json_decode($response->getBody()); $result = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals(1, $result[0]->id); self::assertEquals(1, $result[0]->id);

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Statuses; namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\Destroy;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class DestroyTest extends ApiTest class DestroyTest extends ApiTest
@ -13,8 +17,10 @@ class DestroyTest extends ApiTest
*/ */
public function testApiStatusesDestroy() public function testApiStatusesDestroy()
{ {
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); $this->expectException(BadRequestException::class);
// api_statuses_destroy('json');
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$destroy->run();
} }
/** /**
@ -24,6 +30,8 @@ class DestroyTest extends ApiTest
*/ */
public function testApiStatusesDestroyWithoutAuthenticatedUser() public function testApiStatusesDestroyWithoutAuthenticatedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false; // $_SESSION['authenticated'] = false;
@ -37,8 +45,13 @@ class DestroyTest extends ApiTest
*/ */
public function testApiStatusesDestroyWithId() public function testApiStatusesDestroyWithId()
{ {
// DI::args()->setArgv(['', '', '', 1]); $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
// $result = api_statuses_destroy('json'); $response = $destroy->run(['id' => 1]);
// self::assertStatus($result['status']);
$json = $this->toJson($response);
self::assertEquals(1, $json->id);
self::assertIsObject($json->user);
self::assertIsObject($json->friendica_author);
} }
} }

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Statuses; namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\Mentions;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class MentionsTest extends ApiTest class MentionsTest extends ApiTest
@ -13,13 +17,13 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentions() public function testApiStatusesMentions()
{ {
/* $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$this->app->setLoggedInUserNickname($this->selfUser['nick']); $response = $mentions->run(['max_id' => 10]);
$_REQUEST['max_id'] = 10;
$result = api_statuses_mentions('json'); $json = $this->toJson($response);
self::assertEmpty($result['status']);
self::assertEmpty($json);
// We should test with mentions in the database. // We should test with mentions in the database.
*/
} }
/** /**
@ -29,9 +33,13 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentionsWithNegativePage() public function testApiStatusesMentionsWithNegativePage()
{ {
// $_REQUEST['page'] = -2; $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
// $result = api_statuses_mentions('json'); $response = $mentions->run(['page' => -2]);
// self::assertEmpty($result['status']);
$json = $this->toJson($response);
self::assertEmpty($json);
// We should test with mentions in the database.
} }
/** /**
@ -41,6 +49,8 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentionsWithUnallowedUser() public function testApiStatusesMentionsWithUnallowedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// api_statuses_mentions('json'); // api_statuses_mentions('json');
@ -53,7 +63,11 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentionsWithRss() public function testApiStatusesMentionsWithRss()
{ {
// $result = api_statuses_mentions('rss'); $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]);
// self::assertXml($result, 'statuses'); $response = $mentions->run(['page' => -2]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
} }
} }

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Statuses; namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\NetworkPublicTimeline;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class NetworkPublicTimelineTest extends ApiTest class NetworkPublicTimelineTest extends ApiTest
@ -13,14 +17,17 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimeline() public function testApiStatusesNetworkpublicTimeline()
{ {
/* $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$_REQUEST['max_id'] = 10; $response = $networkPublicTimeline->run(['max_id' => 10]);
$result = api_statuses_networkpublic_timeline('json');
self::assertNotEmpty($result['status']); $json = $this->toJson($response);
foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertIsArray($json);
self::assertNotEmpty($json);
foreach ($json as $status) {
self::assertIsString($status->text);
self::assertIsInt($status->id);
} }
*/
} }
/** /**
@ -30,14 +37,17 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimelineWithNegativePage() public function testApiStatusesNetworkpublicTimelineWithNegativePage()
{ {
/* $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$_REQUEST['page'] = -2; $response = $networkPublicTimeline->run(['page' => -2]);
$result = api_statuses_networkpublic_timeline('json');
self::assertNotEmpty($result['status']); $json = $this->toJson($response);
foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertIsArray($json);
self::assertNotEmpty($json);
foreach ($json as $status) {
self::assertIsString($status->text);
self::assertIsInt($status->id);
} }
*/
} }
/** /**
@ -47,6 +57,8 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimelineWithUnallowedUser() public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// api_statuses_networkpublic_timeline('json'); // api_statuses_networkpublic_timeline('json');
@ -59,7 +71,11 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimelineWithRss() public function testApiStatusesNetworkpublicTimelineWithRss()
{ {
// $result = api_statuses_networkpublic_timeline('rss'); $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]);
// self::assertXml($result, 'statuses'); $response = $networkPublicTimeline->run(['page' => -2]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
} }
} }

View file

@ -0,0 +1,70 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\Retweet;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
class RetweetTest extends ApiTest
{
/**
* Test the api_statuses_repeat() function.
*
* @return void
*/
public function testApiStatusesRepeat()
{
$this->expectException(BadRequestException::class);
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$retweet->run();
}
/**
* Test the api_statuses_repeat() function without an authenticated user.
*
* @return void
*/
public function testApiStatusesRepeatWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false;
// api_statuses_repeat('json');
}
/**
* Test the api_statuses_repeat() function with an ID.
*
* @return void
*/
public function testApiStatusesRepeatWithId()
{
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $retweet->run(['id' => 1]);
$json = $this->toJson($response);
self::assertStatus($json);
}
/**
* Test the api_statuses_repeat() function with an shared ID.
*
* @return void
*/
public function testApiStatusesRepeatWithSharedId()
{
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $retweet->run(['id' => 5]);
$json = $this->toJson($response);
self::assertStatus($json);
}
}

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Statuses; namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\Show;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class ShowTest extends ApiTest class ShowTest extends ApiTest
@ -13,8 +17,10 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShow() public function testApiStatusesShow()
{ {
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); $this->expectException(BadRequestException::class);
// api_statuses_show('json');
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$show->run();
} }
/** /**
@ -24,9 +30,13 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShowWithId() public function testApiStatusesShowWithId()
{ {
// DI::args()->setArgv(['', '', '', 1]); $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
// $result = api_statuses_show('json'); $response = $show->run(['id' => 1]);
// self::assertStatus($result['status']);
$json = $this->toJson($response);
self::assertIsInt($json->id);
self::assertIsString($json->text);
} }
/** /**
@ -36,15 +46,17 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShowWithConversation() public function testApiStatusesShowWithConversation()
{ {
/* $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
DI::args()->setArgv(['', '', '', 1]); $response = $show->run(['id' => 1, 'conversation' => 1]);
$_REQUEST['conversation'] = 1;
$result = api_statuses_show('json'); $json = $this->toJson($response);
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { self::assertIsArray($json);
self::assertStatus($status);
foreach ($json as $status) {
self::assertIsInt($status->id);
self::assertIsString($status->text);
} }
*/
} }
/** /**
@ -54,6 +66,8 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShowWithUnallowedUser() public function testApiStatusesShowWithUnallowedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// api_statuses_show('json'); // api_statuses_show('json');

View file

@ -0,0 +1,109 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\Update;
use Friendica\Test\src\Module\Api\ApiTest;
class UpdateTest extends ApiTest
{
/**
* Test the api_statuses_update() function.
*
* @return void
*/
public function testApiStatusesUpdate()
{
$_FILES = [
'media' => [
'id' => 666,
'size' => 666,
'width' => 666,
'height' => 666,
'tmp_name' => $this->getTempImage(),
'name' => 'spacer.png',
'type' => 'image/png'
]
];
$show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $show->run([
'status' => 'Status content #friendica',
'in_reply_to_status_id' => 0,
'lat' => 48,
'long' => 7,
]);
$json = $this->toJson($response);
self::assertStatus($json);
self::assertContains('Status content #friendica', $json->text);
self::assertContains('Status content #', $json->statusnet_html);
}
/**
* Test the api_statuses_update() function with an HTML status.
*
* @return void
*/
public function testApiStatusesUpdateWithHtml()
{
$show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$response = $show->run([
'htmlstatus' => '<b>Status content</b>',
]);
$json = $this->toJson($response);
self::assertStatus($json);
}
/**
* Test the api_statuses_update() function without an authenticated user.
*
* @return void
*/
public function testApiStatusesUpdateWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_update('json');
*/
}
/**
* Test the api_statuses_update() function with a parent status.
*
* @return void
*/
public function testApiStatusesUpdateWithParent()
{
$this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
}
/**
* Test the api_statuses_update() function with a media_ids parameter.
*
* @return void
*/
public function testApiStatusesUpdateWithMediaIds()
{
$this->markTestIncomplete();
}
/**
* Test the api_statuses_update() function with the throttle limit reached.
*
* @return void
*/
public function testApiStatusesUpdateWithDayThrottleReached()
{
$this->markTestIncomplete();
}
}

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Statuses; namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Statuses\UserTimeline;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class UserTimelineTest extends ApiTest class UserTimelineTest extends ApiTest
@ -13,18 +17,23 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimeline() public function testApiStatusesUserTimeline()
{ {
/* $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$_REQUEST['user_id'] = 42;
$_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true;
$_REQUEST['conversation_id'] = 7;
$result = api_statuses_user_timeline('json'); $response = $networkPublicTimeline->run([
self::assertNotEmpty($result['status']); 'user_id' => 42,
foreach ($result['status'] as $status) { 'max_id' => 10,
self::assertStatus($status); 'exclude_replies' => true,
} 'conversation_id' => 7,
*/ ]);
$json = $this->toJson($response);
self::assertIsArray($json);
self::assertNotEmpty($json);
foreach ($json as $status) {
self::assertIsString($status->text);
self::assertIsInt($status->id);
}
} }
/** /**
@ -34,16 +43,21 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimelineWithNegativePage() public function testApiStatusesUserTimelineWithNegativePage()
{ {
/* $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$_REQUEST['user_id'] = 42;
$_REQUEST['page'] = -2;
$result = api_statuses_user_timeline('json'); $response = $networkPublicTimeline->run([
self::assertNotEmpty($result['status']); 'user_id' => 42,
foreach ($result['status'] as $status) { 'page' => -2,
self::assertStatus($status); ]);
$json = $this->toJson($response);
self::assertIsArray($json);
self::assertNotEmpty($json);
foreach ($json as $status) {
self::assertIsString($status->text);
self::assertIsInt($status->id);
} }
*/
} }
/** /**
@ -53,8 +67,13 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimelineWithRss() public function testApiStatusesUserTimelineWithRss()
{ {
// $result = api_statuses_user_timeline('rss'); $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]);
// self::assertXml($result, 'statuses');
$response = $networkPublicTimeline->run();
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
} }
/** /**
@ -64,6 +83,8 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimelineWithUnallowedUser() public function testApiStatusesUserTimelineWithUnallowedUser()
{ {
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID(); // BasicAuth::setCurrentUserID();
// api_statuses_user_timeline('json'); // api_statuses_user_timeline('json');

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Users; namespace Friendica\Test\src\Module\Api\Twitter\Users;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Users\Lookup;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class LookupTest extends ApiTest class LookupTest extends ApiTest
@ -13,8 +17,10 @@ class LookupTest extends ApiTest
*/ */
public function testApiUsersLookup() public function testApiUsersLookup()
{ {
// $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class); $this->expectException(NotFoundException::class);
// api_users_lookup('json');
$lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$lookup->run();
} }
/** /**
@ -24,8 +30,11 @@ class LookupTest extends ApiTest
*/ */
public function testApiUsersLookupWithUserId() public function testApiUsersLookupWithUserId()
{ {
// $_REQUEST['user_id'] = $this->otherUser['id']; $lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
// $result = api_users_lookup('json'); $respone = $lookup->run(['user_id' => static::OTHER_USER['id']]);
// self::assertOtherUser($result['users'][0]);
$json = $this->toJson($respone);
self::assertOtherUser($json[0]);
} }
} }

View file

@ -2,6 +2,11 @@
namespace Friendica\Test\src\Module\Api\Twitter\Users; namespace Friendica\Test\src\Module\Api\Twitter\Users;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Users\Search;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class SearchTest extends ApiTest class SearchTest extends ApiTest
@ -13,9 +18,12 @@ class SearchTest extends ApiTest
*/ */
public function testApiUsersSearch() public function testApiUsersSearch()
{ {
// $_GET['q'] = 'othercontact'; $search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
// $result = api_users_search('json'); $respone = $search->run(['q' => static::OTHER_USER['name']]);
// self::assertOtherUser($result['users'][0]);
$json = $this->toJson($respone);
self::assertOtherUser($json[0]);
} }
/** /**
@ -25,9 +33,10 @@ class SearchTest extends ApiTest
*/ */
public function testApiUsersSearchWithXml() public function testApiUsersSearchWithXml()
{ {
// $_GET['q'] = 'othercontact'; $search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]);
// $result = api_users_search('xml'); $respone = $search->run(['q' => static::OTHER_USER['name']]);
// self::assertXml($result, 'users');
self::assertXml((string)$respone->getBody(), 'users');
} }
/** /**
@ -37,7 +46,9 @@ class SearchTest extends ApiTest
*/ */
public function testApiUsersSearchWithoutQuery() public function testApiUsersSearchWithoutQuery()
{ {
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); $this->expectException(BadRequestException::class);
// api_users_search('json');
$search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$search->run();
} }
} }

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Users; namespace Friendica\Test\src\Module\Api\Twitter\Users;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Users\Show;
use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\src\Module\Api\ApiTest;
class ShowTest extends ApiTest class ShowTest extends ApiTest
@ -13,15 +17,17 @@ class ShowTest extends ApiTest
*/ */
public function testApiUsersShow() public function testApiUsersShow()
{ {
/* $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$result = api_users_show('json'); $response = $show->run();
$json = $this->toJson($response);
// We can't use assertSelfUser() here because the user object is missing some properties. // We can't use assertSelfUser() here because the user object is missing some properties.
self::assertEquals($this->selfUser['id'], $result['user']['cid']); self::assertEquals(static::SELF_USER['id'], $json->cid);
self::assertEquals('DFRN', $result['user']['location']); self::assertEquals('DFRN', $json->location);
self::assertEquals($this->selfUser['name'], $result['user']['name']); self::assertEquals(static::SELF_USER['name'], $json->name);
self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']); self::assertEquals(static::SELF_USER['nick'], $json->screen_name);
self::assertTrue($result['user']['verified']); self::assertTrue($json->verified);
*/
} }
/** /**
@ -31,7 +37,11 @@ class ShowTest extends ApiTest
*/ */
public function testApiUsersShowWithXml() public function testApiUsersShowWithXml()
{ {
// $result = api_users_show('xml'); $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]);
// self::assertXml($result, 'statuses'); $response = $show->run();
self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
} }
} }