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']);
// params
$since_id = $_REQUEST['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0;
$count = $_GET['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1;
$since_id = $request['since_id'] ?? 0;
$max_id = $request['max_id'] ?? 0;
$count = $request['count'] ?? 20;
$page = $request['page'] ?? 1;
$start = max(0, ($page - 1) * $count);
@ -64,7 +64,7 @@ class Favorites extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = [];
while ($status = DBA::fetch($statuses)) {

View File

@ -26,6 +26,7 @@ use Friendica\Module\BaseApi;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Network\HTTPException\BadRequestException;
/**
* Destroys a specific status.
@ -39,10 +40,12 @@ class Destroy extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
if (empty($this->parameters['id'])) {
$id = intval($request['id'] ?? 0);
} else {
if (!empty($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);

View File

@ -70,6 +70,6 @@ class Retweet extends BaseApi
$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();
if (empty($this->parameters['id'])) {
$id = intval($_REQUEST['id'] ?? 0);
$id = intval($request['id'] ?? 0);
} else {
$id = (int)$this->parameters['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
$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));
}
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = [];
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));
} else {
$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
{
public function post(array $request = [], array $post = [])
public function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -101,10 +101,10 @@ class Update extends BaseApi
$item['coord'] = sprintf("%s %s", $request['lat'], $request['long']);
}
$item['allow_cid'] = $owner['allow_cid'];
$item['allow_gid'] = $owner['allow_gid'];
$item['deny_cid'] = $owner['deny_cid'];
$item['deny_gid'] = $owner['deny_gid'];
$item['allow_cid'] = $owner['allow_cid'] ?? '';
$item['allow_gid'] = $owner['allow_gid'] ?? '';
$item['deny_cid'] = $owner['deny_cid'] ?? '';
$item['deny_gid'] = $owner['deny_gid'] ?? '';
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
$item['private'] = Item::PRIVATE;
@ -127,8 +127,8 @@ class Update extends BaseApi
$item['object-type'] = Activity\ObjectType::NOTE;
}
if (!empty($_REQUEST['media_ids'])) {
$ids = explode(',', $_REQUEST['media_ids']);
if (!empty($request['media_ids'])) {
$ids = explode(',', $request['media_ids']);
} elseif (!empty($_FILES['media'])) {
// upload the image if we have one
$picture = Photo::upload($uid, $_FILES['media']);

View File

@ -40,17 +40,17 @@ class UserTimeline extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$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);
$since_id = $_REQUEST['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0;
$exclude_replies = !empty($_REQUEST['exclude_replies']);
$conversation_id = $_REQUEST['conversation_id'] ?? 0;
$cid = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid);
$since_id = $request['since_id'] ?? 0;
$max_id = $request['max_id'] ?? 0;
$exclude_replies = !empty($request['exclude_replies']);
$conversation_id = $request['conversation_id'] ?? 0;
// pagination
$count = $_REQUEST['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1;
$count = $request['count'] ?? 20;
$page = $request['page'] ?? 1;
$start = max(0, ($page - 1) * $count);
@ -74,7 +74,7 @@ class UserTimeline 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');
$ret = [];
while ($status = DBA::fetch($statuses)) {
@ -82,6 +82,6 @@ class UserTimeline extends BaseApi
}
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 = [];
if (!empty($_REQUEST['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $cid) {
if (!empty($request['user_id'])) {
foreach (explode(',', $request['user_id']) as $cid) {
if (!empty($cid) && is_numeric($cid)) {
$users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid, false)->toArray();
}

View File

@ -42,15 +42,15 @@ class Search extends BaseApi
$userlist = [];
if (!empty($_GET['q'])) {
if (!empty($request['q'])) {
$contacts = Contact::selectToArray(
['id'],
[
'`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)',
$_GET['q'],
$_GET['q'],
$_GET['q'],
$_GET['q'],
$request['q'],
$request['q'],
$request['q'],
$request['q'],
]
);
@ -63,12 +63,12 @@ class Search extends BaseApi
}
$userlist = ['users' => $userlist];
} else {
throw new NotFoundException('User ' . $_GET['q'] . ' not found.');
throw new NotFoundException('User ' . $request['q'] . ' not found.');
}
} else {
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();
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 {
$cid = (int)$this->parameters['id'];
}

View File

@ -69,7 +69,8 @@ return [
'username' => 'Test user',
'nickname' => 'selfcontact',
'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',
],
],
@ -137,6 +138,8 @@ return [
'nurl' => 'http://localhost/profile/selfcontact',
'url' => 'http://localhost/profile/selfcontact',
'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,
'blocked' => 0,
'rel' => Contact::FOLLOWER,
@ -259,7 +262,7 @@ return [
"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-----",
"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}",
"baseurl" => null,
"gsid" => null,
@ -833,6 +836,16 @@ return [
'gid' => 1,
'contact-id' => 42,
],
[
'id' => 2,
'gid' => 1,
'contact-id' => 42,
],
[
'id' => 3,
'gid' => 2,
'contact-id' => 43,
],
],
'search' => [
[

View File

@ -112,55 +112,6 @@ class ApiTest extends FixtureTest
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.
*
@ -884,232 +835,6 @@ class ApiTest extends FixtureTest
// 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.
*

View File

@ -22,6 +22,7 @@
namespace Friendica\Test\src\Module\Api;
use Friendica\App;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Database\Database;
@ -32,9 +33,35 @@ use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppDouble;
use Friendica\Test\Util\AuthenticationDouble;
use Friendica\Test\Util\AuthTestConfig;
use Psr\Http\Message\ResponseInterface;
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.
*
@ -50,6 +77,92 @@ abstract class ApiTest extends FixtureTest
// 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
{
parent::setUp(); // TODO: Change the autogenerated stub

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']);
$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());
}
}

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]);
$response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']);
$responseText = (string)$response->getBody();
self::assertJson($responseText);
$json = json_decode($responseText);
$json = $this->toJson($response);
self::assertEquals('deleted', $json->result);
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]);
$response = $delete->run(['album' => 'test_album']);
$responseText = (string)$response->getBody();
self::assertJson($responseText);
$json = json_decode($responseText);
$json = $this->toJson($response);
self::assertEquals('deleted', $json->result);
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']);
$responseBody = (string)$response->getBody();
self::assertJson($responseBody);
$json = json_decode($responseBody);
$json = $this->toJson($response);
self::assertEquals('updated', $json->result);
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]);
$response = $config->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertEquals(1, 1);
$json = $this->toJson($response);
self::assertEquals('localhost', $json->site->server);
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']);
$response = $test->run();
$json = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals('"ok"', $response->getBody());
self::assertEquals('ok', $json);
}
public function testXml()

View File

@ -2,9 +2,6 @@
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

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]);
$response = $verifyCredentials->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertEquals(48, $json->id);
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']);
$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(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']);
$response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertEquals('new_name', $json->name);
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]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertIsArray($json->users);
}

View File

@ -32,6 +32,8 @@ class ContactEndpointTest extends FixtureTest
{
public function testIds()
{
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/*
$expectedEmpty = [
'ids' => [],
@ -77,6 +79,8 @@ class ContactEndpointTest extends FixtureTest
*/
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);
@ -88,6 +92,8 @@ class ContactEndpointTest extends FixtureTest
public function testIdsPagination()
{
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/*
$expectedDefaultPageResult = [
'ids' => [45],
@ -172,6 +178,8 @@ class ContactEndpointTest extends FixtureTest
*/
public function testList()
{
self::markTestIncomplete('Needs overall refactoring due changed method signature - Calling MrPetovan for help ;-)');
/*
$expectedEmpty = [
'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;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Favorites;
use Friendica\Test\src\Module\Api\ApiTest;
class FavoritesTest extends ApiTest
@ -13,14 +17,17 @@ class FavoritesTest extends ApiTest
*/
public function testApiFavorites()
{
/*
$_REQUEST['page'] = -1;
$_REQUEST['max_id'] = 10;
$result = api_favorites('json');
foreach ($result['status'] as $status) {
self::assertStatus($status);
$favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $favorites->run([
'page' => -1,
'max_id' => 10,
]);
$json = $this->toJson($response);
foreach ($json as $status) {
$this->assertStatus($status);
}
*/
}
/**
@ -30,8 +37,12 @@ class FavoritesTest extends ApiTest
*/
public function testApiFavoritesWithRss()
{
// $result = api_favorites('rss');
// self::assertXml($result, 'statuses');
$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]);
$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()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// 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]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
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]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
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]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
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]);
$response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
foreach ($json as $status) {
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();
$media = json_decode($response->getBody(), true);
self::assertEquals('image/png', $media['image']['image_type']);
self::assertEquals(1, $media['image']['w']);
self::assertEquals(1, $media['image']['h']);
self::assertNotEmpty($media['image']['friendica_preview_url']);
}
$media = $this->toJson($response);
/**
* Get the path to a temporary empty PNG image.
*
* @return string Path
*/
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;
self::assertEquals('image/png', $media->image->image_type);
self::assertEquals(1, $media->image->w);
self::assertEquals(1, $media->image->h);
self::assertNotEmpty($media->image->friendica_preview_url);
}
}

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']);
$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(1, $result[0]->id);

View File

@ -2,6 +2,10 @@
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;
class DestroyTest extends ApiTest
@ -13,8 +17,10 @@ class DestroyTest extends ApiTest
*/
public function testApiStatusesDestroy()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_statuses_destroy('json');
$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();
}
/**
@ -24,6 +30,8 @@ class DestroyTest extends ApiTest
*/
public function testApiStatusesDestroyWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false;
@ -37,8 +45,13 @@ class DestroyTest extends ApiTest
*/
public function testApiStatusesDestroyWithId()
{
// DI::args()->setArgv(['', '', '', 1]);
// $result = api_statuses_destroy('json');
// self::assertStatus($result['status']);
$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' => 1]);
$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;
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;
class MentionsTest extends ApiTest
@ -13,13 +17,13 @@ class MentionsTest extends ApiTest
*/
public function testApiStatusesMentions()
{
/*
$this->app->setLoggedInUserNickname($this->selfUser['nick']);
$_REQUEST['max_id'] = 10;
$result = api_statuses_mentions('json');
self::assertEmpty($result['status']);
$mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $mentions->run(['max_id' => 10]);
$json = $this->toJson($response);
self::assertEmpty($json);
// We should test with mentions in the database.
*/
}
/**
@ -29,9 +33,13 @@ class MentionsTest extends ApiTest
*/
public function testApiStatusesMentionsWithNegativePage()
{
// $_REQUEST['page'] = -2;
// $result = api_statuses_mentions('json');
// self::assertEmpty($result['status']);
$mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $mentions->run(['page' => -2]);
$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()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_statuses_mentions('json');
@ -53,7 +63,11 @@ class MentionsTest extends ApiTest
*/
public function testApiStatusesMentionsWithRss()
{
// $result = api_statuses_mentions('rss');
// self::assertXml($result, 'statuses');
$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]);
$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;
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;
class NetworkPublicTimelineTest extends ApiTest
@ -13,14 +17,17 @@ class NetworkPublicTimelineTest extends ApiTest
*/
public function testApiStatusesNetworkpublicTimeline()
{
/*
$_REQUEST['max_id'] = 10;
$result = api_statuses_networkpublic_timeline('json');
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) {
self::assertStatus($status);
$networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $networkPublicTimeline->run(['max_id' => 10]);
$json = $this->toJson($response);
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()
{
/*
$_REQUEST['page'] = -2;
$result = api_statuses_networkpublic_timeline('json');
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) {
self::assertStatus($status);
$networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $networkPublicTimeline->run(['page' => -2]);
$json = $this->toJson($response);
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()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_statuses_networkpublic_timeline('json');
@ -59,7 +71,11 @@ class NetworkPublicTimelineTest extends ApiTest
*/
public function testApiStatusesNetworkpublicTimelineWithRss()
{
// $result = api_statuses_networkpublic_timeline('rss');
// self::assertXml($result, 'statuses');
$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]);
$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;
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;
class ShowTest extends ApiTest
@ -13,8 +17,10 @@ class ShowTest extends ApiTest
*/
public function testApiStatusesShow()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_statuses_show('json');
$this->expectException(BadRequestException::class);
$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()
{
// DI::args()->setArgv(['', '', '', 1]);
// $result = api_statuses_show('json');
// self::assertStatus($result['status']);
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $show->run(['id' => 1]);
$json = $this->toJson($response);
self::assertIsInt($json->id);
self::assertIsString($json->text);
}
/**
@ -36,15 +46,17 @@ class ShowTest extends ApiTest
*/
public function testApiStatusesShowWithConversation()
{
/*
DI::args()->setArgv(['', '', '', 1]);
$_REQUEST['conversation'] = 1;
$result = api_statuses_show('json');
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) {
self::assertStatus($status);
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $show->run(['id' => 1, 'conversation' => 1]);
$json = $this->toJson($response);
self::assertIsArray($json);
foreach ($json as $status) {
self::assertIsInt($status->id);
self::assertIsString($status->text);
}
*/
}
/**
@ -54,6 +66,8 @@ class ShowTest extends ApiTest
*/
public function testApiStatusesShowWithUnallowedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// 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;
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;
class UserTimelineTest extends ApiTest
@ -13,18 +17,23 @@ class UserTimelineTest extends ApiTest
*/
public function testApiStatusesUserTimeline()
{
/*
$_REQUEST['user_id'] = 42;
$_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true;
$_REQUEST['conversation_id'] = 7;
$networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$result = api_statuses_user_timeline('json');
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) {
self::assertStatus($status);
$response = $networkPublicTimeline->run([
'user_id' => 42,
'max_id' => 10,
'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()
{
/*
$_REQUEST['user_id'] = 42;
$_REQUEST['page'] = -2;
$networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$result = api_statuses_user_timeline('json');
self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) {
self::assertStatus($status);
$response = $networkPublicTimeline->run([
'user_id' => 42,
'page' => -2,
]);
$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()
{
// $result = api_statuses_user_timeline('rss');
// self::assertXml($result, 'statuses');
$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]);
$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()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_statuses_user_timeline('json');

View File

@ -2,6 +2,10 @@
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;
class LookupTest extends ApiTest
@ -13,8 +17,10 @@ class LookupTest extends ApiTest
*/
public function testApiUsersLookup()
{
// $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
// api_users_lookup('json');
$this->expectException(NotFoundException::class);
$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()
{
// $_REQUEST['user_id'] = $this->otherUser['id'];
// $result = api_users_lookup('json');
// self::assertOtherUser($result['users'][0]);
$lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$respone = $lookup->run(['user_id' => static::OTHER_USER['id']]);
$json = $this->toJson($respone);
self::assertOtherUser($json[0]);
}
}

View File

@ -2,6 +2,11 @@
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;
class SearchTest extends ApiTest
@ -13,9 +18,12 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearch()
{
// $_GET['q'] = 'othercontact';
// $result = api_users_search('json');
// self::assertOtherUser($result['users'][0]);
$search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$respone = $search->run(['q' => static::OTHER_USER['name']]);
$json = $this->toJson($respone);
self::assertOtherUser($json[0]);
}
/**
@ -25,9 +33,10 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearchWithXml()
{
// $_GET['q'] = 'othercontact';
// $result = api_users_search('xml');
// self::assertXml($result, 'users');
$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]);
$respone = $search->run(['q' => static::OTHER_USER['name']]);
self::assertXml((string)$respone->getBody(), 'users');
}
/**
@ -37,7 +46,9 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearchWithoutQuery()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_users_search('json');
$this->expectException(BadRequestException::class);
$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;
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;
class ShowTest extends ApiTest
@ -13,15 +17,17 @@ class ShowTest extends ApiTest
*/
public function testApiUsersShow()
{
/*
$result = api_users_show('json');
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $show->run();
$json = $this->toJson($response);
// We can't use assertSelfUser() here because the user object is missing some properties.
self::assertEquals($this->selfUser['id'], $result['user']['cid']);
self::assertEquals('DFRN', $result['user']['location']);
self::assertEquals($this->selfUser['name'], $result['user']['name']);
self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
self::assertTrue($result['user']['verified']);
*/
self::assertEquals(static::SELF_USER['id'], $json->cid);
self::assertEquals('DFRN', $json->location);
self::assertEquals(static::SELF_USER['name'], $json->name);
self::assertEquals(static::SELF_USER['nick'], $json->screen_name);
self::assertTrue($json->verified);
}
/**
@ -31,7 +37,11 @@ class ShowTest extends ApiTest
*/
public function testApiUsersShowWithXml()
{
// $result = api_users_show('xml');
// self::assertXml($result, 'statuses');
$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]);
$response = $show->run();
self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
self::assertXml((string)$response->getBody(), 'statuses');
}
}