* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpFoundation\Tests\File\MimeType; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; /** * @requires extension fileinfo */ class MimeTypeTest extends TestCase { protected $path; public function testGuessImageWithoutExtension() { $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test')); } public function testGuessImageWithDirectory() { $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory'); } public function testGuessImageWithFileBinaryMimeTypeGuesser() { $guesser = MimeTypeGuesser::getInstance(); $guesser->register(new FileBinaryMimeTypeGuesser()); $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test')); } public function testGuessImageWithKnownExtension() { $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif')); } public function testGuessFileWithUnknownExtension() { $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension')); } public function testGuessWithIncorrectPath() { $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here'); } public function testGuessWithNonReadablePath() { if ('\\' === DIRECTORY_SEPARATOR) { $this->markTestSkipped('Can not verify chmod operations on Windows'); } if (!getenv('USER') || 'root' === getenv('USER')) { $this->markTestSkipped('This test will fail if run under superuser'); } $path = __DIR__.'/../Fixtures/to_delete'; touch($path); @chmod($path, 0333); if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) { $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException'); MimeTypeGuesser::getInstance()->guess($path); } else { $this->markTestSkipped('Can not verify chmod operations, change of file permissions failed'); } } public static function tearDownAfterClass() { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { @chmod($path, 0666); @unlink($path); } } } __halt_compiler();----SIGNATURE:----C1hCNcGz/7Uz/DTZ3+668/b7zSxYSvdL/cXnMGrE95U5DFNRyESDAFsdNjdPSTG5akQk4VAs7/NUF/Unz2kCbUUMQYkvRh1DKy3LkF38XU9jEIUsQoW0z6hDlwPtT8Ta/+d981NhDPXj3WkIDYXHhUru02rFnimJ019N9VW++HyRu3puLYwwghIbTmSVDhTy+Wx6TbixoEiEb3KJmlIQIaHTzxAdSWocstPxblIeCltRw3vchXOdJhTqPFU2MWGTHTBptSIcPJe5I+NheViKyXFqMkeN2ijgalnLIwI2fxCWyRxXtAcj0ZqZeDAgT3xB8wdH5D7eLpb9AslmgHnQaOMAHKA/izExSEGhgtSCVRAwAaDTObCv/e+GWbz/mRSIhIxol2SQ1g8QnPlQQmXPyZB9nkt1m6ctYeyx7783xa2CdDcdU1xVslCvwcenG6ntUg2XtxUj2T8OuvLoEY/JoxQNqTzh0EIaxMA2Za6gGJW1sohSs4FmgMrmiqyNe2FAnJ5v9fcjHyS34OXoLrkZZYqHqt+k6ga47bLL8z01knrzS86ad64iqKYtqFZOQDFx5rmz4HovyvRnfI0yrpTF+bXPmkEKdT8khdcrKDHQZCgthh0uJl3wn2LyUZS24BBnf0JEGchNTczvulrYxiZm3mZD+oO2eVRQFNSa5gRc1WA=----ATTACHMENT:----NTEwNDU1NzYyNjcxODMzNyA0MTUxMDE4NDY2NTI0NTI4IDkzMjM0ODAzODg0NTY5Mg==