Reenable Twitter/Favorites tests

This commit is contained in:
Philipp 2021-12-09 21:52:40 +01:00
parent 732ef70b8d
commit f84c696925
No known key found for this signature in database
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']); 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

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

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