namespace Friendica\Test\legacy;
use Friendica\App;
-use Friendica\App\Router;
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';
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.
*
// 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.
*
$this->markTestIncomplete();
}
- /**
- * Test the \Friendica\Module\Api\Twitter\Media\Upload module.
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testApiMediaUpload()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- $_SERVER['REQUEST_METHOD'] = Router::POST;
- (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;
- $_SERVER['REQUEST_METHOD'] = Router::POST;
- (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'
- ]
- ];
- $_SERVER['REQUEST_METHOD'] = Router::POST;
- (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'
- ]
- ];
-
- $_SERVER['REQUEST_METHOD'] = Router::POST;
-
- $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.