summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2015-01-28 10:55:26 +0000
committerNathaniel Catchpole2015-01-28 10:55:26 +0000
commit5bf651dabf88766a588adf3c34a7ee2fa1ab4016 (patch)
treecc0a336284078cf4400f4da4bfbf1658f99cb7f7
parent887eea80cabe8bb99775bad5c2208beaa7c78f08 (diff)
Revert "Issue #2388749 by alexpott, adci_contributor, ParisLiakos: Register symfony's mime guessers if they are supported"8.0.0-beta6
This reverts commit 4dae1d994e9ab6ceefdc14e63040f56cabbfec37.
-rw-r--r--core/core.services.yml9
-rw-r--r--core/includes/file.inc26
-rw-r--r--core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php45
-rw-r--r--core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php32
-rw-r--r--core/modules/file/file.module2
-rw-r--r--core/modules/file/src/Entity/File.php2
-rw-r--r--core/modules/file/src/Tests/FileManagedUnitTestBase.php8
-rw-r--r--core/modules/file/src/Tests/SaveDataTest.php6
-rw-r--r--core/modules/file/tests/file_test/file_test.module15
-rw-r--r--core/modules/system/file.api.php24
-rw-r--r--core/modules/system/src/Form/ThemeSettingsForm.php18
-rw-r--r--core/modules/system/src/Tests/File/MimeTypeTest.php94
-rw-r--r--core/tests/Drupal/Tests/Core/File/ExtensionMimeTypeGuesserTest.php59
-rw-r--r--core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php36
14 files changed, 219 insertions, 157 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index 10d5121..c4c7593 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1168,7 +1168,6 @@ services:
alias: plugin.manager.element_info
file.mime_type.guesser:
class: Drupal\Core\File\MimeType\MimeTypeGuesser
- arguments: ['@stream_wrapper_manager']
tags:
- { name: service_collector, tag: mime_type_guesser, call: addGuesser }
file.mime_type.guesser.extension:
@@ -1176,14 +1175,6 @@ services:
arguments: ['@module_handler']
tags:
- { name: mime_type_guesser }
- file.mime_type.guesser.fileinfo:
- class: Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser
- tags:
- - { name: mime_type_guesser, priority: 64 }
- file.mime_type.guesser.filebinary:
- class: Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser
- tags:
- - { name: mime_type_guesser, priority: 32 }
renderer:
class: Drupal\Core\Render\Renderer
arguments: ['@controller_resolver', '@theme.manager', '@plugin.manager.element_info', '@request_stack', '@cache_factory', '@cache_contexts']
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 066f0bd..d47fbc4 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -1151,6 +1151,32 @@ function file_upload_max_size() {
}
/**
+ * Determines an Internet Media Type or MIME type from a filename.
+ *
+ * @param $uri
+ * A string containing the URI, path, or filename.
+ * @param $mapping
+ * An optional map of extensions to their mimetypes, in the form:
+ * - 'mimetypes': a list of mimetypes, keyed by an identifier,
+ * - 'extensions': the mapping itself, an associative array in which the key
+ * is the extension (lowercase) and the value is the mimetype identifier.
+ *
+ * @return
+ * The internet media type registered for the extension or
+ * application/octet-stream for unknown extensions.
+ *
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Calls are
+ * passed on to a new file.mime_type.guesser service, and the $mapping
+ * parameter is ignored. Use
+ * \Drupal::service('file.mime_type.guesser')->guess($uri).
+ *
+ * @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess()
+ */
+function file_get_mimetype($uri, $mapping = NULL) {
+ return \Drupal::service('file.mime_type.guesser')->guess($uri);
+}
+
+/**
* Sets the permissions on a file or directory.
*
* This function will use the file_chmod_directory and
diff --git a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
index dda1c4e..53712ca 100644
--- a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
+++ b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
@@ -16,12 +16,12 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
/**
- * MIME extension mappings.
+ * Default MIME extension mapping.
*
* @var array
* Array of mimetypes correlated to the extensions that relate to them.
*/
- protected $mapping = array(
+ protected $defaultMapping = array(
'mimetypes' => array(
0 => 'application/andrew-inset',
1 => 'application/atom',
@@ -865,9 +865,40 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
);
/**
+ * The MIME types mapping array after going through the module handler.
+ *
+ * @var array
+ */
+ protected $mapping;
+
+ /**
+ * The module handler.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ protected $moduleHandler;
+
+ /**
+ * Constructs a new ExtensionMimeTypeGuesser.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler.
+ */
+ public function __construct(ModuleHandlerInterface $module_handler) {
+ $this->moduleHandler = $module_handler;
+ }
+
+ /**
* {@inheritdoc}
*/
public function guess($path) {
+ if ($this->mapping === NULL) {
+ $mapping = $this->defaultMapping;
+ // Allow modules to alter the default mapping.
+ $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
+ $this->mapping = $mapping;
+ }
+
$extension = '';
$file_parts = explode('.', drupal_basename($path));
@@ -889,4 +920,14 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
return 'application/octet-stream';
}
+ /**
+ * Sets the mimetypes/extension mapping to use when guessing mimetype.
+ *
+ * @param array|null $mapping
+ * Passing a NULL mapping will cause guess() to use self::$defaultMapping.
+ */
+ public function setMapping(array $mapping = NULL) {
+ $this->mapping = $mapping;
+ }
+
}
diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php
index ee3bc7d..2054463 100644
--- a/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php
+++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php
@@ -7,7 +7,6 @@
namespace Drupal\Core\File\MimeType;
-use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
@@ -18,13 +17,6 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
class MimeTypeGuesser implements MimeTypeGuesserInterface {
/**
- * The stream wrapper manager.
- *
- * @var \Drupal\Core\StreamWrapper\StreamWrapperManager
- */
- protected $streamWrapperManager;
-
- /**
* An array of arrays of registered guessers keyed by priority.
*
* @var array
@@ -44,20 +36,10 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface {
protected $sortedGuessers = NULL;
/**
- * Constructs the mime type guesser service.
- *
- * @param \Drupal\Core\StreamWrapper\StreamWrapperManager $stream_wrapper_manager
- * The stream wrapper manager.
- */
- public function __construct(StreamWrapperManager $stream_wrapper_manager) {
- $this->streamWrapperManager = $stream_wrapper_manager;
- }
-
- /**
* {@inheritdoc}
*/
public function guess($path) {
- if ($wrapper = $this->streamWrapperManager->getViaUri($path)) {
+ if ($wrapper = file_stream_wrapper_get_instance_by_uri($path)) {
// Get the real path from the stream wrapper.
$path = $wrapper->realpath();
}
@@ -86,15 +68,9 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface {
* @return $this
*/
public function addGuesser(MimeTypeGuesserInterface $guesser, $priority = 0) {
- // Only add guessers which are supported.
- // @see \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser
- // @see \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser
- $supported = method_exists($guesser, 'isSupported') ? $guesser->isSupported() : TRUE;
- if ($supported) {
- $this->guessers[$priority][] = $guesser;
- // Mark sorted guessers for rebuild.
- $this->sortedGuessers = NULL;
- }
+ $this->guessers[$priority][] = $guesser;
+ // Mark sorted guessers for rebuild.
+ $this->sortedGuessers = NULL;
return $this;
}
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index e572585..6545301 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -756,7 +756,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
'uri' => $file_info->getRealPath(),
'filesize' => $file_info->getSize(),
);
- $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['uri']);
+ $values['filemime'] = file_get_mimetype($values['filename']);
$file = entity_create('file', $values);
$extensions = '';
diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php
index 2dbbf31..7cf5058 100644
--- a/core/modules/file/src/Entity/File.php
+++ b/core/modules/file/src/Entity/File.php
@@ -185,7 +185,7 @@ class File extends ContentEntityBase implements FileInterface {
// Automatically detect filemime if not set.
if (!isset($values['filemime']) && isset($values['uri'])) {
- $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['uri']);
+ $values['filemime'] = file_get_mimetype($values['uri']);
}
}
diff --git a/core/modules/file/src/Tests/FileManagedUnitTestBase.php b/core/modules/file/src/Tests/FileManagedUnitTestBase.php
index d822aea..00448c5 100644
--- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php
+++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php
@@ -151,8 +151,7 @@ abstract class FileManagedUnitTestBase extends KernelTestBase {
*
* @param $filepath
* Optional string specifying the file path. If none is provided then a
- * randomly named file with the extension .txt will be created in the site's
- * files directory.
+ * randomly named file will be created in the site's files directory.
* @param $contents
* Optional contents to save into the file. If a NULL value is provided an
* arbitrary string will be used.
@@ -183,8 +182,7 @@ abstract class FileManagedUnitTestBase extends KernelTestBase {
*
* @param string $filepath
* Optional string specifying the file path. If none is provided then a
- * randomly named file with the extension .txt will be created in the site's
- * files directory.
+ * randomly named file will be created in the site's files directory.
* @param string $contents
* Optional contents to save into the file. If a NULL value is provided an
* arbitrary string will be used.
@@ -204,7 +202,7 @@ abstract class FileManagedUnitTestBase extends KernelTestBase {
if (!isset($scheme)) {
$scheme = file_default_scheme();
}
- $filepath = $scheme . '://' . $filepath . '.txt';
+ $filepath = $scheme . '://' . $filepath;
if (!isset($contents)) {
$contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
diff --git a/core/modules/file/src/Tests/SaveDataTest.php b/core/modules/file/src/Tests/SaveDataTest.php
index bf1255f..8368e0b 100644
--- a/core/modules/file/src/Tests/SaveDataTest.php
+++ b/core/modules/file/src/Tests/SaveDataTest.php
@@ -25,7 +25,7 @@ class SaveDataTest extends FileManagedUnitTestBase {
$this->assertEqual(file_default_scheme(), file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
$this->assertEqual($result->getFilename(), drupal_basename($result->getFileUri()), "Filename was set to the file's basename.");
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
- $this->assertEqual($result->getMimeType(), 'text/plain', 'A MIME type was set.');
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
$this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
// Check that the correct hooks were called.
@@ -74,7 +74,7 @@ class SaveDataTest extends FileManagedUnitTestBase {
$this->assertEqual('public', file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
$this->assertEqual($result->getFilename(), $existing->getFilename(), 'Filename was set to the basename of the source, rather than that of the renamed file.');
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
- $this->assertEqual($result->getMimeType(), 'text/plain', 'A MIME type was set.');
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
$this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
// Check that the correct hooks were called.
@@ -102,7 +102,7 @@ class SaveDataTest extends FileManagedUnitTestBase {
$this->assertEqual('public', file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
$this->assertEqual($result->getFilename(), $existing->getFilename(), 'Filename was set to the basename of the existing file, rather than preserving the original name.');
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
- $this->assertEqual($result->getMimeType(), 'text/plain', 'A MIME type was set.');
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
$this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
// Check that the correct hooks were called.
diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module
index 8c12c56..6ee2ecc 100644
--- a/core/modules/file/tests/file_test/file_test.module
+++ b/core/modules/file/tests/file_test/file_test.module
@@ -284,6 +284,21 @@ function file_test_file_url_alter(&$uri) {
}
/**
+ * Implements hook_file_mimetype_mapping_alter().
+ */
+function file_test_file_mimetype_mapping_alter(&$mapping) {
+ // Add new mappings.
+ $mapping['mimetypes']['file_test_mimetype_1'] = 'madeup/file_test_1';
+ $mapping['mimetypes']['file_test_mimetype_2'] = 'madeup/file_test_2';
+ $mapping['mimetypes']['file_test_mimetype_3'] = 'madeup/doc';
+ $mapping['extensions']['file_test_1'] = 'file_test_mimetype_1';
+ $mapping['extensions']['file_test_2'] = 'file_test_mimetype_2';
+ $mapping['extensions']['file_test_3'] = 'file_test_mimetype_2';
+ // Override existing mapping.
+ $mapping['extensions']['doc'] = 'file_test_mimetype_3';
+}
+
+/**
* Helper validator that returns the $errors parameter.
*/
function file_test_validator(File $file, $errors) {
diff --git a/core/modules/system/file.api.php b/core/modules/system/file.api.php
index 21b62b3..a4fd8e4 100644
--- a/core/modules/system/file.api.php
+++ b/core/modules/system/file.api.php
@@ -100,6 +100,30 @@ function hook_file_url_alter(&$uri) {
}
/**
+ * Alter MIME type mappings used to determine MIME type from a file extension.
+ *
+ * Invoked by \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess(). It
+ * is used to allow modules to add to or modify the default mapping from
+ * \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping.
+ *
+ * @param $mapping
+ * An array of mimetypes correlated to the extensions that relate to them.
+ * The array has 'mimetypes' and 'extensions' elements, each of which is an
+ * array.
+ *
+ * @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess()
+ * @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping
+ */
+function hook_file_mimetype_mapping_alter(&$mapping) {
+ // Add new MIME type 'drupal/info'.
+ $mapping['mimetypes']['example_info'] = 'drupal/info';
+ // Add new extension '.info.yml' and map it to the 'drupal/info' MIME type.
+ $mapping['extensions']['info'] = 'example_info';
+ // Override existing extension mapping for '.ogg' files.
+ $mapping['extensions']['ogg'] = 189;
+}
+
+/**
* Alter archiver information declared by other modules.
*
* See hook_archiver_info() for a description of archivers and the archiver
diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php
index 1e40d85..79cf305 100644
--- a/core/modules/system/src/Form/ThemeSettingsForm.php
+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -12,7 +12,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\StreamWrapper\PublicStream;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactoryInterface;
@@ -46,13 +45,6 @@ class ThemeSettingsForm extends ConfigFormBase {
protected $editableConfig = [];
/**
- * The mime type guesser.
- *
- * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
- */
- protected $mimeTypeGuesser;
-
- /**
* Constructs a ThemeSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
@@ -61,15 +53,12 @@ class ThemeSettingsForm extends ConfigFormBase {
* The module handler instance to use.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
- * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser
- * The mime type guesser.
*/
- public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser) {
+ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
parent::__construct($config_factory);
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
- $this->mimeTypeGuesser = $mime_type_guesser;
}
/**
@@ -79,8 +68,7 @@ class ThemeSettingsForm extends ConfigFormBase {
return new static(
$container->get('config.factory'),
$container->get('module_handler'),
- $container->get('theme_handler'),
- $container->get('file.mime_type.guesser')
+ $container->get('theme_handler')
);
}
@@ -458,7 +446,7 @@ class ThemeSettingsForm extends ConfigFormBase {
}
if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {
- $values['favicon_mimetype'] = $this->mimeTypeGuesser->guess($values['favicon_path']);
+ $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']);
}
}
diff --git a/core/modules/system/src/Tests/File/MimeTypeTest.php b/core/modules/system/src/Tests/File/MimeTypeTest.php
new file mode 100644
index 0000000..f09b60d
--- /dev/null
+++ b/core/modules/system/src/Tests/File/MimeTypeTest.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\system\Tests\File\MimeTypeTest.
+ */
+
+namespace Drupal\system\Tests\File;
+
+/**
+ * Tests filename mimetype detection.
+ *
+ * @group File
+ */
+class MimeTypeTest extends FileTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('file_test');
+
+ /**
+ * Test mapping of mimetypes from filenames.
+ */
+ public function testFileMimeTypeDetection() {
+ $prefix = 'public://';
+
+ $test_case = array(
+ 'test.jar' => 'application/java-archive',
+ 'test.jpeg' => 'image/jpeg',
+ 'test.JPEG' => 'image/jpeg',
+ 'test.jpg' => 'image/jpeg',
+ 'test.jar.jpg' => 'image/jpeg',
+ 'test.jpg.jar' => 'application/java-archive',
+ 'test.pcf.Z' => 'application/x-font',
+ 'pcf.z' => 'application/octet-stream',
+ 'jar' => 'application/octet-stream',
+ 'some.junk' => 'application/octet-stream',
+ 'foo.file_test_1' => 'madeup/file_test_1',
+ 'foo.file_test_2' => 'madeup/file_test_2',
+ 'foo.doc' => 'madeup/doc',
+ 'test.ogg' => 'audio/ogg',
+ );
+
+ $guesser = $this->container->get('file.mime_type.guesser');
+ // Test using default mappings.
+ foreach ($test_case as $input => $expected) {
+ // Test stream [URI].
+ $output = $guesser->guess($prefix . $input);
+ $this->assertIdentical($output, $expected, format_string('Mimetype for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
+
+ // Test normal path equivalent
+ $output = $guesser->guess($input);
+ $this->assertIdentical($output, $expected, format_string('Mimetype (using default mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
+ }
+
+ // Now test the extension gusser by passing in a custom mapping.
+ $mapping = array(
+ 'mimetypes' => array(
+ 0 => 'application/java-archive',
+ 1 => 'image/jpeg',
+ ),
+ 'extensions' => array(
+ 'jar' => 0,
+ 'jpg' => 1,
+ )
+ );
+
+ $test_case = array(
+ 'test.jar' => 'application/java-archive',
+ 'test.jpeg' => 'application/octet-stream',
+ 'test.jpg' => 'image/jpeg',
+ 'test.jar.jpg' => 'image/jpeg',
+ 'test.jpg.jar' => 'application/java-archive',
+ 'test.pcf.z' => 'application/octet-stream',
+ 'pcf.z' => 'application/octet-stream',
+ 'jar' => 'application/octet-stream',
+ 'some.junk' => 'application/octet-stream',
+ 'foo.file_test_1' => 'application/octet-stream',
+ 'foo.file_test_2' => 'application/octet-stream',
+ 'foo.doc' => 'application/octet-stream',
+ 'test.ogg' => 'application/octet-stream',
+ );
+ $extension_guesser = $this->container->get('file.mime_type.guesser.extension');
+ $extension_guesser->setMapping($mapping);
+
+ foreach ($test_case as $input => $expected) {
+ $output = $extension_guesser->guess($input);
+ $this->assertIdentical($output, $expected, format_string('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
+ }
+ }
+}
diff --git a/core/tests/Drupal/Tests/Core/File/ExtensionMimeTypeGuesserTest.php b/core/tests/Drupal/Tests/Core/File/ExtensionMimeTypeGuesserTest.php
deleted file mode 100644
index b1160de..0000000
--- a/core/tests/Drupal/Tests/Core/File/ExtensionMimeTypeGuesserTest.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\Tests\Core\File\ExtensionMimeTypeGuesserTest.
- */
-
-namespace Drupal\Tests\Core\File {
-
-use Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser;
-use Drupal\Tests\UnitTestCase;
-
-/**
- * @coversDefaultClass \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser
- * @group File
- */
-class ExtensionMimeTypeGuesserTest extends UnitTestCase {
-
- /**
- * @covers ::guess
- * @dataProvider guesserDataProvider
- */
- public function testGuesser($path, $mime_type) {
- $guesser = new ExtensionMimeTypeGuesser();
- $this->assertEquals($mime_type, $guesser->guess($path));
- }
-
- /**
- * Provides data for ExtensionMimeTypeGuesserTest::testGuesser().
- */
- public function guesserDataProvider() {
- return [
- ['test.jar', 'application/java-archive'],
- ['test.jpeg', 'image/jpeg'],
- ['test.JPEG', 'image/jpeg'],
- ['test.jpg', 'image/jpeg'],
- ['test.jar.jpg', 'image/jpeg'],
- ['test.jpg.jar', 'application/java-archive'],
- ['test.pcf.Z', 'application/x-font'],
- ['pcf.z', 'application/octet-stream'],
- ['jar', 'application/octet-stream'],
- ['some.junk', 'application/octet-stream'],
- ['foo.file_test_1', 'application/octet-stream'],
- ['foo.file_test_2', 'application/octet-stream'],
- ['foo.doc', 'application/msword'],
- ['test.ogg', 'audio/ogg'],
- ];
- }
-
-}
-
-}
-namespace {
- if (!function_exists('drupal_basename')) {
- function drupal_basename($uri, $suffix = NULL) {
- return basename($uri, $suffix);
- }
- }
-}
diff --git a/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php b/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php
index 87729bd..a1bf9c2 100644
--- a/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php
+++ b/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php
@@ -14,40 +14,11 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMim
/**
* @coversDefaultClass \Drupal\Core\File\MimeType\MimeTypeGuesser
- * @group File
+ * @group DrupalKernel
*/
class MimeTypeGuesserTest extends UnitTestCase {
/**
- * @covers ::guess
- * @covers ::addGuesser
- * @covers ::sortGuessers
- */
- public function testGuess() {
- $stream_wrapper_manager = $this->getMockBuilder('Drupal\Core\StreamWrapper\StreamWrapperManager')
- ->disableOriginalConstructor()
- ->getMock();
- $stream_wrapper_manager->expects($this->any())
- ->method('getViaUri')
- ->willReturn(NULL);
- $mime_guesser_service = new MimeTypeGuesser($stream_wrapper_manager);
- $guesser_1 = $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface');
- $guesser_1->expects($this->once())
- ->method('guess')
- ->with('file.txt')
- ->willReturn('text/plain');
- $mime_guesser_service->addGuesser($guesser_1);
- $this->assertEquals('text/plain', $mime_guesser_service->guess('file.txt'));
- $guesser_2 = $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface');
- $guesser_2->expects($this->once())
- ->method('guess')
- ->with('file.txt')
- ->willReturn('text/x-diff');
- $mime_guesser_service->addGuesser($guesser_2, 10);
- $this->assertEquals('text/x-diff', $mime_guesser_service->guess('file.txt'));
- }
-
- /**
* @covers ::registerWithSymfonyGuesser
*
* @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
@@ -62,11 +33,8 @@ class MimeTypeGuesserTest extends UnitTestCase {
if (count($guessers)) {
$this->assertNotInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]);
}
- $stream_wrapper_manager = $this->getMockBuilder('Drupal\Core\StreamWrapper\StreamWrapperManager')
- ->disableOriginalConstructor()
- ->getMock();
$container = new ContainerBuilder();
- $container->set('file.mime_type.guesser', new MimeTypeGuesser($stream_wrapper_manager));
+ $container->set('file.mime_type.guesser', new MimeTypeGuesser());
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
$this->assertInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]);