Open Journal Systems  3.3.0
MimeTypeTest.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use PHPUnit\Framework\TestCase;
17 
21 class MimeTypeTest extends TestCase
22 {
23  protected $path;
24 
26  {
27  $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
28  }
29 
30  public function testGuessImageWithDirectory()
31  {
32  $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
33 
34  MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
35  }
36 
38  {
39  $guesser = MimeTypeGuesser::getInstance();
40  $guesser->register(new FileBinaryMimeTypeGuesser());
41  $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
42  }
43 
45  {
46  $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
47  }
48 
50  {
51  $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
52  }
53 
54  public function testGuessWithIncorrectPath()
55  {
56  $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
57  MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');
58  }
59 
60  public function testGuessWithNonReadablePath()
61  {
62  if ('\\' === DIRECTORY_SEPARATOR) {
63  $this->markTestSkipped('Can not verify chmod operations on Windows');
64  }
65 
66  if (!getenv('USER') || 'root' === getenv('USER')) {
67  $this->markTestSkipped('This test will fail if run under superuser');
68  }
69 
70  $path = __DIR__.'/../Fixtures/to_delete';
71  touch($path);
72  @chmod($path, 0333);
73 
74  if (substr(sprintf('%o', fileperms($path)), -4) == '0333') {
75  $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
77  } else {
78  $this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');
79  }
80  }
81 
82  public static function tearDownAfterClass()
83  {
84  $path = __DIR__.'/../Fixtures/to_delete';
85  if (file_exists($path)) {
86  @chmod($path, 0666);
87  @unlink($path);
88  }
89  }
90 }
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\$path
$path
Definition: MimeTypeTest.php:23
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessImageWithoutExtension
testGuessImageWithoutExtension()
Definition: MimeTypeTest.php:25
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessImageWithFileBinaryMimeTypeGuesser
testGuessImageWithFileBinaryMimeTypeGuesser()
Definition: MimeTypeTest.php:37
Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser
Definition: lib/vendor/symfony/http-foundation/File/MimeType/FileBinaryMimeTypeGuesser.php:22
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessWithIncorrectPath
testGuessWithIncorrectPath()
Definition: MimeTypeTest.php:54
Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser\getInstance
static getInstance()
Definition: lib/vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php:64
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessImageWithKnownExtension
testGuessImageWithKnownExtension()
Definition: MimeTypeTest.php:44
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\tearDownAfterClass
static tearDownAfterClass()
Definition: MimeTypeTest.php:82
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest
Definition: MimeTypeTest.php:21
Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
Definition: lib/vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php:40
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessImageWithDirectory
testGuessImageWithDirectory()
Definition: MimeTypeTest.php:30
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessFileWithUnknownExtension
testGuessFileWithUnknownExtension()
Definition: MimeTypeTest.php:49
Symfony\Component\HttpFoundation\Tests\File\MimeType
Definition: MimeTypeTest.php:12
Symfony\Component\HttpFoundation\Tests\File\MimeType\MimeTypeTest\testGuessWithNonReadablePath
testGuessWithNonReadablePath()
Definition: MimeTypeTest.php:60