Reenable Twitter/Destroy tests

This commit is contained in:
Philipp 2021-12-09 21:03:33 +01:00
parent 354c2d828a
commit 4d330f2876
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
3 changed files with 24 additions and 11 deletions

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']) && !empty($request['id'])) {
$id = intval($request['id']);
} elseif (!empty($this->parameters['id'])) {
$id = (int)$this->parameters['id'];
} else {
throw new BadRequestException('An id is missing.');
}
$this->logger->notice('API: api_statuses_destroy: ' . $id);

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

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