diff --git a/build/controllers/MimeTypeController.php b/build/controllers/MimeTypeController.php index 5b03491..91084e4 100644 --- a/build/controllers/MimeTypeController.php +++ b/build/controllers/MimeTypeController.php @@ -99,6 +99,11 @@ class MimeTypeController extends Controller $mimeMap = array_merge($mimeMap, $this->additionalMimeTypes); ksort($mimeMap); $array = VarDumper::export($mimeMap); + + if (PHP_VERSION_ID >= 80100) { + $array = array_replace($array, array('xz' => 'application/octet-stream')); + } + $content = <<= 80100) { - return static::getMimeTypeByExtension($file, $magicFile); - } - $info = finfo_open(FILEINFO_MIME_TYPE, $magicFile); if ($info) { diff --git a/framework/helpers/mimeTypes.php b/framework/helpers/mimeTypes.php index 6b0a78d..f1e3da4 100644 --- a/framework/helpers/mimeTypes.php +++ b/framework/helpers/mimeTypes.php @@ -8,7 +8,7 @@ * http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup * This file has been placed in the public domain for unlimited redistribution. */ -return [ +$mimeTypes = [ '3dml' => 'text/vnd.in3d.3dml', '3ds' => 'image/x-3ds', '3g2' => 'video/3gpp2', @@ -995,3 +995,9 @@ return [ 'zirz' => 'application/vnd.zul', 'zmm' => 'application/vnd.handheld-entertainment+xml', ]; + +if (PHP_VERSION_ID >= 80100) { + $mimeTypes = array_replace($mimeTypes, array('xz' => 'application/octet-stream')); +} + +return $mimeTypes; diff --git a/tests/framework/helpers/FileHelperTest.php b/tests/framework/helpers/FileHelperTest.php index 09da3d2..ae59b54 100644 --- a/tests/framework/helpers/FileHelperTest.php +++ b/tests/framework/helpers/FileHelperTest.php @@ -717,6 +717,24 @@ class FileHelperTest extends TestCase $this->assertTrue(in_array(FileHelper::getMimeType($file), ['application/json', 'text/plain'])); } + public function testGetUploadedImageMimeTypes() + { + $ds = DIRECTORY_SEPARATOR; + $phpunitPath = Yii::getAlias('@yiiunit'); + $runtimeLocation = Yii::getAlias('@yiiunit/runtime'); + $resourceSourceLocation = "{$phpunitPath}{$ds}framework{$ds}validators{$ds}data{$ds}mimeType"; + + $pngFile = "{$runtimeLocation}{$ds}php1234"; + copy("{$resourceSourceLocation}{$ds}test.png", $pngFile); + + $this->assertEquals('image/png', FileHelper::getMimeType($pngFile)); + + $jpgFile = "{$runtimeLocation}{$ds}php4567"; + copy("{$resourceSourceLocation}{$ds}test.jpg", $jpgFile); + + $this->assertEquals('image/jpeg', FileHelper::getMimeType($jpgFile)); + } + public function testNormalizePath() { $ds = DIRECTORY_SEPARATOR; diff --git a/tests/framework/helpers/MimeTest.php b/tests/framework/helpers/MimeTest.php index 9df42b1..a6a0a8a 100644 --- a/tests/framework/helpers/MimeTest.php +++ b/tests/framework/helpers/MimeTest.php @@ -37,8 +37,8 @@ class MimeTest extends TestCase public function testMimeTypes() { - $this->assertSame( - [ + + $coreMimeTypes = [ '3dml' => 'text/vnd.in3d.3dml', '3ds' => 'image/x-3ds', '3g2' => 'video/3gpp2', @@ -1024,7 +1024,13 @@ class MimeTest extends TestCase 'zir' => 'application/vnd.zul', 'zirz' => 'application/vnd.zul', 'zmm' => 'application/vnd.handheld-entertainment+xml', - ], + ]; + + if (PHP_VERSION_ID >= 80100) { + $coreMimeTypes = array_replace($coreMimeTypes, array('xz' => 'application/octet-stream')); + } + + $this->assertSame($coreMimeTypes, require __DIR__ . '/../../../framework/helpers/mimeTypes.php' ); } diff --git a/tests/framework/validators/FileValidatorTest.php b/tests/framework/validators/FileValidatorTest.php index 2ce3c79..d3dba37 100644 --- a/tests/framework/validators/FileValidatorTest.php +++ b/tests/framework/validators/FileValidatorTest.php @@ -535,7 +535,7 @@ class FileValidatorTest extends TestCase public function validMimeTypes() { - return array_filter([ + $validMimeTypes = array_filter([ ['test.svg', 'image/*', 'svg'], ['test.jpg', 'image/*', 'jpg'], ['test.png', 'image/*', 'png'], @@ -545,6 +545,14 @@ class FileValidatorTest extends TestCase ['test.odt', 'application/vnd*', 'odt'], ['test.tar.xz', 'application/x-xz', 'tar.xz'], ]); + + if (PHP_VERSION_ID >= 80100) { + $v81_zx = ['test.tar.xz', 'application/octet-stream', 'tar.xz']; + array_pop($validMimeTypes); + $validMimeTypes[] = $v81_zx; + } + + return $validMimeTypes; } public function invalidMimeTypes()