1
0
Fork 0

Reenable Twitter/UserTimeline tests

This commit is contained in:
Philipp Holzer 2021-12-09 21:23:58 +01:00
parent ccf7e251b5
commit f9c490b29a
Signed by: nupplaPhil
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); 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

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