diff --git a/src/DataFixtures/MediaFixtures.php b/src/DataFixtures/MediaFixtures.php index 0651c570de..6bd435c6b6 100644 --- a/src/DataFixtures/MediaFixtures.php +++ b/src/DataFixtures/MediaFixtures.php @@ -21,6 +21,29 @@ class MediaFixtures extends Fixture $file = new File($copy_filepath, checkPath: true); GSFile::validateAndStoreFileAsAttachment($file, dest_dir: Common::config('attachments', 'dir') . 'test/', title: $title, actor_id: $actor->getId()); }; + + $test_files = [ + 'image.png' => 'image/png', + 'image.gif' => 'image/gif', + 'image.jpg' => 'image/jpeg', + 'image.jpeg' => 'image/jpeg', + 'office.pdf' => 'application/pdf', + 'wordproc.odt' => 'application/vnd.oasis.opendocument.text', + 'wordproc.ott' => 'application/vnd.oasis.opendocument.text-template', + 'wordproc.doc' => 'application/msword', + 'wordproc.docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'wordproc.rtf' => 'text/rtf', + 'spreadsheet.ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'spreadsheet.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'spreadsheet.xls' => 'application/vnd.ms-excel', + 'spreadsheet.xlt' => 'application/vnd.ms-excel', + 'spreadsheet.xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'presentation.odp' => 'application/vnd.oasis.opendocument.presentation', + 'presentation.otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'presentation.ppt' => 'application/vnd.ms-powerpoint', + 'presentation.pptx' => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation", + ]; + $store(INSTALLDIR . '/tests/Media/sample-uploads/image.jpeg', '1x1 JPEG image title'); $manager->flush(); } diff --git a/tests/Media/MediaFileTest.php b/tests/Media/MediaFileTest.php deleted file mode 100644 index 33e4264f03..0000000000 --- a/tests/Media/MediaFileTest.php +++ /dev/null @@ -1,127 +0,0 @@ -. - -namespace Tests\Unit; - -if (!defined('INSTALLDIR')) { - define('INSTALLDIR', dirname(dirname(__DIR__))); -} -if (!defined('PUBLICDIR')) { - define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); -} -if (!defined('GNUSOCIAL')) { - define('GNUSOCIAL', true); -} -if (!defined('STATUSNET')) { // Compatibility - define('STATUSNET', true); -} - -use ClientException; -use Exception; -use MediaFile; -use TemporaryFile; -use PHPUnit\Framework\TestCase; -use ServerException; - -require_once INSTALLDIR . '/lib/util/common.php'; - -final class MediaFileTest extends TestCase -{ - protected function setup(): void - { - $this->old_attachments_supported = common_config('attachments', 'supported'); - $GLOBALS['config']['attachments']['supported'] = true; - } - - protected function tearDown(): void - { - $GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported; - } - - /** - * @dataProvider fileTypeCases - * - * @param $filename - * @param $expectedType - * - * @throws ClientException - * @throws ServerException - */ - public function testMimeType($filename, $expectedType) - { - if (!file_exists($filename)) { - throw new Exception("Test file {$filename} missing"); - } - - $type = MediaFile::getUploadedMimeType($filename, basename($filename)); - static::assertSame($expectedType, $type); - } - - /** - * @dataProvider fileTypeCases - * - * @param $filename - * @param $expectedType - * - * @throws ClientException - * @throws ServerException - */ - public function testUploadedMimeType($filename, $expectedType) - { - if (!file_exists($filename)) { - throw new Exception("WTF? {$filename} test file missing"); - } - $tempfile = new TemporaryFile('gs-mediafiletest'); - fwrite($tempfile->getResource(), file_get_contents($filename)); - fflush($tempfile->getResource()); - - $type = MediaFile::getUploadedMimeType($tempfile->getRealPath(), basename($filename)); - static::assertSame($expectedType, $type); - } - - public static function fileTypeCases() - { - $base = __DIR__; - $dir = "{$base}/sample-uploads"; - $files = [ - 'image.png' => 'image/png', - 'image.gif' => 'image/gif', - 'image.jpg' => 'image/jpeg', - 'image.jpeg' => 'image/jpeg', - 'office.pdf' => 'application/pdf', - 'wordproc.odt' => 'application/vnd.oasis.opendocument.text', - 'wordproc.ott' => 'application/vnd.oasis.opendocument.text-template', - 'wordproc.doc' => 'application/msword', - 'wordproc.docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'wordproc.rtf' => 'text/rtf', - 'spreadsheet.ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'spreadsheet.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', - 'spreadsheet.xls' => 'application/vnd.ms-excel', - 'spreadsheet.xlt' => 'application/vnd.ms-excel', - 'spreadsheet.xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'presentation.odp' => 'application/vnd.oasis.opendocument.presentation', - 'presentation.otp' => 'application/vnd.oasis.opendocument.presentation-template', - 'presentation.ppt' => 'application/vnd.ms-powerpoint', - 'presentation.pptx' => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation", - ]; - - $dataset = []; - foreach ($files as $file => $type) { - $dataset[] = ["{$dir}/{$file}", $type]; - } - return $dataset; - } -}