Reenable Twitter/UserTimeline tests

This commit is contained in:
Philipp 2021-12-09 21:23:58 +01:00
parent ccf7e251b5
commit f9c490b29a
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
2 changed files with 52 additions and 31 deletions

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

@ -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');