diff --git a/src/Core/GSFile.php b/src/Core/GSFile.php index c1733bf949..770e55dc3f 100644 --- a/src/Core/GSFile.php +++ b/src/Core/GSFile.php @@ -221,7 +221,7 @@ class GSFile /** * Get the minor part of a mimetype. image/webp -> image */ - public static function mimetypeMajor(string $mime) + public static function mimetypeMajor(string $mime): string { return explode('/', self::mimetypeBare($mime))[0]; } @@ -229,7 +229,7 @@ class GSFile /** * Get the minor part of a mimetype. image/webp -> webp */ - public static function mimetypeMinor(string $mime) + public static function mimetypeMinor(string $mime): string { return explode('/', self::mimetypeBare($mime))[1]; } @@ -237,7 +237,7 @@ class GSFile /** * Get only the mimetype and not additional info (separated from bare mime with semi-colon) */ - public static function mimetypeBare(string $mimetype) + public static function mimetypeBare(string $mimetype): string { $mimetype = mb_strtolower($mimetype); if (($semicolon = mb_strpos($mimetype, ';')) !== false) { diff --git a/tests/Core/GSFileTest.php b/tests/Core/GSFileTest.php new file mode 100644 index 0000000000..bb6827ce43 --- /dev/null +++ b/tests/Core/GSFileTest.php @@ -0,0 +1,46 @@ +. + +// }}} + +namespace App\Tests\Core; + +use App\Core\GSFile; +use App\Util\GNUsocialTestCase; + +class GSFileTest extends GNUsocialTestCase +{ + public function testMimetype() + { + static::assertSame('image', GSFile::mimetypeMajor('image/png')); + static::assertSame('image', GSFile::mimetypeMajor('IMAGE/PNG')); + static::assertSame('image', GSFile::mimetypeMajor('image/jpeg')); + static::assertSame('text', GSFile::mimetypeMajor('text/html')); + static::assertSame('text', GSFile::mimetypeMajor('text/html; charset=utf-8')); + + static::assertSame('png', GSFile::mimetypeMinor('image/png')); + static::assertSame('png', GSFile::mimetypeMinor('IMAGE/PNG')); + static::assertSame('jpeg', GSFile::mimetypeMinor('image/jpeg')); + static::assertSame('html', GSFile::mimetypeMinor('text/html')); + static::assertSame('html', GSFile::mimetypeMinor('text/html; charset=utf-8')); + + static::assertSame('text/html', GSFile::mimetypeBare('text/html')); + static::assertSame('text/html', GSFile::mimetypeBare('text/html; charset=utf-8')); + } +}