class MimeTypeMapTest
Tests the MIME type mapper to extension.
@coversDefaultClass \Drupal\Core\File\MimeType\MimeTypeMap
@group File
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\File\MimeType\MimeTypeMapTest implements \Drupal\Tests\UnitTestCase
Expanded class hierarchy of MimeTypeMapTest
File
-
core/
tests/ Drupal/ Tests/ Core/ File/ MimeType/ MimeTypeMapTest.php, line 17
Namespace
Drupal\Tests\Core\File\MimeTypeView source
class MimeTypeMapTest extends UnitTestCase {
/**
* The default MIME type map under test.
*/
protected MimeTypeMap $map;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->map = new MimeTypeMap();
}
/**
* @covers ::addMapping
*/
public function testAddMapping() : void {
$this->map
->addMapping('image/gif', 'gif');
$this->assertEquals('image/gif', $this->map
->getMimeTypeForExtension('gif'));
$this->map
->addMapping('image/jpeg', 'jpeg');
$this->assertEquals('image/jpeg', $this->map
->getMimeTypeForExtension('jpeg'));
}
/**
* @covers ::removeMapping
*/
public function testRemoveMapping() : void {
$this->assertTrue($this->map
->removeMapping('image/jpeg', 'jpg'));
$this->assertNull($this->map
->getMimeTypeForExtension('jpg'));
$this->assertFalse($this->map
->removeMapping('bar', 'foo'));
}
/**
* @covers ::removeMimeType
*/
public function testRemoveMimeType() : void {
$this->assertTrue($this->map
->removeMimeType('image/jpeg'));
$this->assertNull($this->map
->getMimeTypeForExtension('jpg'));
$this->assertFalse($this->map
->removeMimeType('foo/bar'));
}
/**
* @covers ::listMimeTypes
*/
public function testListMimeTypes() : void {
$mimeTypes = $this->map
->listMimeTypes();
$this->assertContains('application/java-archive', $mimeTypes);
$this->assertContains('image/jpeg', $mimeTypes);
}
/**
* @covers ::hasMimeType
*/
public function testHasMimeType() : void {
$this->assertTrue($this->map
->hasMimeType('image/jpeg'));
$this->assertFalse($this->map
->hasMimeType('foo/bar'));
}
/**
* @covers ::getMimeTypeForExtension
*/
public function testGetMimeTypeForExtension() : void {
$this->assertSame('image/jpeg', $this->map
->getMimeTypeForExtension('jpe'));
}
/**
* @covers ::getExtensionsForMimeType
*/
public function testGetExtensionsForMimeType() : void {
$this->assertEquals([
'jpe',
'jpeg',
'jpg',
], $this->map
->getExtensionsForMimeType('image/jpeg'));
}
/**
* @covers ::listExtensions
*/
public function testListExtension() : void {
$extensions = $this->map
->listExtensions();
$this->assertContains('jar', $extensions);
$this->assertContains('jpg', $extensions);
}
/**
* @covers ::hasExtension
*/
public function testHasExtension() : void {
$this->assertTrue($this->map
->hasExtension('jpg'));
$this->assertFalse($this->map
->hasExtension('foo'));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
MimeTypeMapTest::$map | protected | property | The default MIME type map under test. | |
MimeTypeMapTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
MimeTypeMapTest::testAddMapping | public | function | @covers ::addMapping[[api-linebreak]] | |
MimeTypeMapTest::testGetExtensionsForMimeType | public | function | @covers ::getExtensionsForMimeType[[api-linebreak]] | |
MimeTypeMapTest::testGetMimeTypeForExtension | public | function | @covers ::getMimeTypeForExtension[[api-linebreak]] | |
MimeTypeMapTest::testHasExtension | public | function | @covers ::hasExtension[[api-linebreak]] | |
MimeTypeMapTest::testHasMimeType | public | function | @covers ::hasMimeType[[api-linebreak]] | |
MimeTypeMapTest::testListExtension | public | function | @covers ::listExtensions[[api-linebreak]] | |
MimeTypeMapTest::testListMimeTypes | public | function | @covers ::listMimeTypes[[api-linebreak]] | |
MimeTypeMapTest::testRemoveMapping | public | function | @covers ::removeMapping[[api-linebreak]] | |
MimeTypeMapTest::testRemoveMimeType | public | function | @covers ::removeMimeType[[api-linebreak]] | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.