Reenable Twitter/Favorites tests

This commit is contained in:
Philipp Holzer 2021-12-09 21:52:40 +01:00
parent 732ef70b8d
commit f84c696925
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
3 changed files with 31 additions and 18 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

@ -115,14 +115,14 @@ abstract class ApiTest extends FixtureTest
/**
* Assert that a status array contains expected keys.
*
* @param array $status Status array
* @param \stdClass $status Status
*
* @return void
*/
protected function assertStatus(array $status = [])
protected function assertStatus(\stdClass $status)
{
self::assertIsString($status['text'] ?? '');
self::assertIsInt($status['id'] ?? '');
self::assertIsString($status->text);
self::assertIsInt($status->id);
// We could probably do more checks here.
}

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