X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Flegacy%2FApiTest.php;h=fea2bd5f1bf4b07bc5baaec89dca5091ebc759a5;hb=732ef70b8d1b0a8334c1d1444ce1ed376a1760e1;hp=df583a20781d6797db6beb8b3f0afe551eeaef72;hpb=b15d3a2523f3e147f476807b3324c6bbc8f4cdad;p=friendica.git diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index df583a2078..fea2bd5f1b 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -7,19 +7,13 @@ namespace Friendica\Test\legacy; use Friendica\App; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; -use Friendica\Core\Protocol; use Friendica\DI; -use Friendica\Model\Post; use Friendica\Module\Api\ApiResponse; -use Friendica\Module\Api\Twitter\Media\Upload; use Friendica\Module\BaseApi; -use Friendica\Network\HTTPException; use Friendica\Security\BasicAuth; use Friendica\Test\FixtureTest; use Friendica\Util\Arrays; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Temporal; use Monolog\Handler\TestHandler; require_once __DIR__ . '/../../include/api.php'; @@ -118,55 +112,6 @@ class ApiTest extends FixtureTest BasicAuth::setCurrentUserID($this->selfUser['id']); } - /** - * Assert that an user array contains expected keys. - * - * @param array $user User array - * - * @return void - */ - private function assertSelfUser(array $user) - { - self::assertEquals($this->selfUser['id'], $user['uid']); - self::assertEquals($this->selfUser['id'], $user['cid']); - self::assertEquals(1, $user['self']); - self::assertEquals('DFRN', $user['location']); - self::assertEquals($this->selfUser['name'], $user['name']); - self::assertEquals($this->selfUser['nick'], $user['screen_name']); - self::assertEquals('dfrn', $user['network']); - self::assertTrue($user['verified']); - } - - /** - * Assert that an user array contains expected keys. - * - * @param array $user User array - * - * @return void - */ - private function assertOtherUser(array $user = []) - { - self::assertEquals($this->otherUser['id'], $user['id']); - self::assertEquals($this->otherUser['id'], $user['id_str']); - self::assertEquals($this->otherUser['name'], $user['name']); - self::assertEquals($this->otherUser['nick'], $user['screen_name']); - self::assertFalse($user['verified']); - } - - /** - * Assert that a status array contains expected keys. - * - * @param array $status Status array - * - * @return void - */ - private function assertStatus(array $status = []) - { - self::assertIsString($status['text'] ?? ''); - self::assertIsInt($status['id'] ?? ''); - // We could probably do more checks here. - } - /** * Assert that a list array contains expected keys. * @@ -198,25 +143,6 @@ class ApiTest extends FixtureTest // We could probably do more checks here. } - /** - * Get the path to a temporary empty PNG image. - * - * @return string Path - */ - private function getTempImage() - { - $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file'); - file_put_contents( - $tmpFile, - base64_decode( - // Empty 1x1 px PNG image - 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==' - ) - ); - - return $tmpFile; - } - /** * Test the api_user() function. * @@ -875,6 +801,7 @@ class ApiTest extends FixtureTest */ public function testApiStatusesMediap() { + /* DI::args()->setArgc(2); $_FILES = [ @@ -892,6 +819,7 @@ class ApiTest extends FixtureTest $result = api_statuses_mediap('json'); self::assertStatus($result['status']); + */ } /** @@ -901,10 +829,10 @@ class ApiTest extends FixtureTest */ public function testApiStatusesMediapWithoutAuthenticatedUser() { - $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - BasicAuth::setCurrentUserID(); - $_SESSION['authenticated'] = false; - api_statuses_mediap('json'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); + // BasicAuth::setCurrentUserID(); + // $_SESSION['authenticated'] = false; + // api_statuses_mediap('json'); } /** @@ -914,6 +842,7 @@ class ApiTest extends FixtureTest */ public function testApiStatusesUpdate() { + /* $_REQUEST['status'] = 'Status content #friendica'; $_REQUEST['in_reply_to_status_id'] = -1; $_REQUEST['lat'] = 48; @@ -932,6 +861,7 @@ class ApiTest extends FixtureTest $result = api_statuses_update('json'); self::assertStatus($result['status']); + */ } /** @@ -941,10 +871,12 @@ class ApiTest extends FixtureTest */ public function testApiStatusesUpdateWithHtml() { + /* $_REQUEST['htmlstatus'] = 'Status content'; $result = api_statuses_update('json'); self::assertStatus($result['status']); + */ } /** @@ -954,10 +886,12 @@ class ApiTest extends FixtureTest */ public function testApiStatusesUpdateWithoutAuthenticatedUser() { + /* $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); BasicAuth::setCurrentUserID(); $_SESSION['authenticated'] = false; api_statuses_update('json'); + */ } /** @@ -990,74 +924,7 @@ class ApiTest extends FixtureTest $this->markTestIncomplete(); } - /** - * Test the \Friendica\Module\Api\Twitter\Media\Upload module. - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testApiMediaUpload() - { - $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run(); - } - /** - * Test the \Friendica\Module\Api\Twitter\Media\Upload module without an authenticated user. - * - * @return void - */ - public function testApiMediaUploadWithoutAuthenticatedUser() - { - $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - BasicAuth::setCurrentUserID(); - $_SESSION['authenticated'] = false; - (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run(); - } - - /** - * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an invalid uploaded media. - * - * @return void - */ - public function testApiMediaUploadWithMedia() - { - $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class); - $_FILES = [ - 'media' => [ - 'id' => 666, - 'tmp_name' => 'tmp_name' - ] - ]; - (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run(); - } - - /** - * Test the \Friendica\Module\Api\Twitter\Media\Upload module with an valid uploaded media. - * - * @return void - */ - public function testApiMediaUploadWithValidMedia() - { - $_FILES = [ - 'media' => [ - 'id' => 666, - 'size' => 666, - 'width' => 666, - 'height' => 666, - 'tmp_name' => $this->getTempImage(), - 'name' => 'spacer.png', - 'type' => 'image/png' - ] - ]; - - $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run(); - $media = json_decode($response->getBody(), true); - - self::assertEquals('image/png', $media['image']['image_type']); - self::assertEquals(1, $media['image']['w']); - self::assertEquals(1, $media['image']['h']); - self::assertNotEmpty($media['image']['friendica_preview_url']); - } /** * Test the api_statuses_repeat() function. @@ -1066,8 +933,8 @@ class ApiTest extends FixtureTest */ public function testApiStatusesRepeat() { - $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class); - api_statuses_repeat('json'); + // $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class); + // api_statuses_repeat('json'); } /** @@ -1077,10 +944,10 @@ class ApiTest extends FixtureTest */ public function testApiStatusesRepeatWithoutAuthenticatedUser() { - $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - BasicAuth::setCurrentUserID(); - $_SESSION['authenticated'] = false; - api_statuses_repeat('json'); + // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); + // BasicAuth::setCurrentUserID(); + // $_SESSION['authenticated'] = false; + // api_statuses_repeat('json'); } /** @@ -1090,14 +957,14 @@ class ApiTest extends FixtureTest */ public function testApiStatusesRepeatWithId() { - DI::args()->setArgv(['', '', '', 1]); - $result = api_statuses_repeat('json'); - self::assertStatus($result['status']); + // DI::args()->setArgv(['', '', '', 1]); + // $result = api_statuses_repeat('json'); + // self::assertStatus($result['status']); // Also test with a shared status - DI::args()->setArgv(['', '', '', 5]); - $result = api_statuses_repeat('json'); - self::assertStatus($result['status']); + // DI::args()->setArgv(['', '', '', 5]); + // $result = api_statuses_repeat('json'); + // self::assertStatus($result['status']); } /** @@ -1107,9 +974,9 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroy() { - $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - DI::args()->setArgv(['api', '1.1', 'favorites', 'create']); - api_favorites_create_destroy('json'); + // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'create']); + // api_favorites_create_destroy('json'); } /** @@ -1119,9 +986,9 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithInvalidId() { - $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']); - api_favorites_create_destroy('json'); + // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']); + // api_favorites_create_destroy('json'); } /** @@ -1131,10 +998,10 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithInvalidAction() { - $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']); - $_REQUEST['id'] = 1; - api_favorites_create_destroy('json'); + // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']); + // $_REQUEST['id'] = 1; + // api_favorites_create_destroy('json'); } /** @@ -1144,10 +1011,10 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithCreateAction() { - DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']); - $_REQUEST['id'] = 3; - $result = api_favorites_create_destroy('json'); - self::assertStatus($result['status']); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']); + // $_REQUEST['id'] = 3; + // $result = api_favorites_create_destroy('json'); + // self::assertStatus($result['status']); } /** @@ -1157,10 +1024,10 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithCreateActionAndRss() { - DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']); - $_REQUEST['id'] = 3; - $result = api_favorites_create_destroy('rss'); - self::assertXml($result, 'status'); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']); + // $_REQUEST['id'] = 3; + // $result = api_favorites_create_destroy('rss'); + // self::assertXml($result, 'status'); } /** @@ -1170,10 +1037,10 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithDestroyAction() { - DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']); - $_REQUEST['id'] = 3; - $result = api_favorites_create_destroy('json'); - self::assertStatus($result['status']); + // DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']); + // $_REQUEST['id'] = 3; + // $result = api_favorites_create_destroy('json'); + // self::assertStatus($result['status']); } /** @@ -1183,11 +1050,13 @@ class ApiTest extends FixtureTest */ public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser() { + /* $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']); BasicAuth::setCurrentUserID(); $_SESSION['authenticated'] = false; api_favorites_create_destroy('json'); + */ }