class MimeTypeGuesserTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php \Drupal\Tests\Core\File\MimeTypeGuesserTest
@coversDefaultClass \Drupal\Core\File\MimeType\MimeTypeGuesser @group DrupalKernel
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\File\MimeTypeGuesserTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of MimeTypeGuesserTest
File
-
core/
tests/ Drupal/ Tests/ Core/ File/ MimeTypeGuesserTest.php, line 15
Namespace
Drupal\Tests\Core\FileView source
class MimeTypeGuesserTest extends UnitTestCase {
/**
* @covers ::registerWithSymfonyGuesser
*
* @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
*/
public function testSymfonyGuesserRegistration() {
// Make the guessers property accessible on Symfony's MimeTypeGuesser.
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
// Test that the Drupal mime type guess is not being used before the
// override method is called. It is possible that the test environment does
// not support the default guessers.
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
if (count($guessers)) {
$this->assertNotInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
}
$container = new ContainerBuilder();
$container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
$this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
$this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
$count = count($guessers);
$container = new ContainerBuilder();
$container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
$this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
$this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
$new_count = count($guessers);
$this->assertEquals($count, $new_count, 'The count of mime type guessers remains the same after container re-init.');
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
MimeTypeGuesserTest::testSymfonyGuesserRegistration | public | function | @covers ::registerWithSymfonyGuesser | ||
PhpunitCompatibilityTrait::getMock | Deprecated | public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait::setExpectedException | Deprecated | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase::$randomGenerator | protected | property | The random generator. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::assertArrayEquals | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getBlockMockWithMachineName | Deprecated | protected | function | Mocks a block with a block plugin. | 1 |
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::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | ||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | ||
UnitTestCase::setUp | protected | function | 340 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.