summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/file.test37
-rw-r--r--modules/simpletest/tests/file_test.module15
-rw-r--r--modules/system/system.api.php22
-rw-r--r--modules/upload/upload.test1
4 files changed, 58 insertions, 17 deletions
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 9838793f1..8ca1867ee 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -579,6 +579,8 @@ class FileSaveUploadTest extends FileHookTestCase {
$this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.'));
$file1 = file_load($max_fid_after);
$this->assertTrue($file1, t('Loaded the file.'));
+ // MIME type of the uploaded image may be either image/jpeg or image/png.
+ $this->assertEqual(substr($file1->filemime, 0, 5), 'image', 'A MIME type was set.');
// Reset the hook counters to get rid of the 'load' we just called.
file_test_reset();
@@ -597,6 +599,8 @@ class FileSaveUploadTest extends FileHookTestCase {
$file2 = file_load($max_fid_after);
$this->assertTrue($file2);
+ // MIME type of the uploaded image may be either image/jpeg or image/png.
+ $this->assertEqual(substr($file2->filemime, 0, 5), 'image', 'A MIME type was set.');
// Load both files using file_load_multiple().
$files = file_load_multiple(array($file1->fid, $file2->fid));
@@ -2034,6 +2038,10 @@ class FileNameMungingTest extends FileTestCase {
* Tests for file_get_mimetype().
*/
class FileMimeTypeTest extends DrupalWebTestCase {
+ function setUp() {
+ parent::setUp('file_test');
+ }
+
public static function getInfo() {
return array(
'name' => 'File mimetypes',
@@ -2059,16 +2067,23 @@ class FileMimeTypeTest extends DrupalWebTestCase {
'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 using default mappings (not using 'mime_extension_mapping').
- variable_del('mime_extension_mapping');
+ // Test using default mappings.
foreach ($test_case as $input => $expected) {
+ // Test stream [URI].
+ $output = file_get_mimetype($prefix . $input);
+ $this->assertIdentical($output, $expected, t('Mimetype for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
+
+ // Test normal path equivalent
$output = file_get_mimetype($input);
$this->assertIdentical($output, $expected, t('Mimetype (using default mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
}
- // Now test using mappings from the mime_extension_mapping variable.
+ // Now test passing in the map.
$mapping = array(
'mimetypes' => array(
0 => 'application/java-archive',
@@ -2090,21 +2105,11 @@ class FileMimeTypeTest extends DrupalWebTestCase {
'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',
);
- variable_set('mime_extension_mapping', $mapping);
- foreach ($test_case as $input => $expected) {
- // Test stream [URI].
- $output = file_get_mimetype($prefix . $input);
- $this->assertIdentical($output, $expected, t('Mimetype for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
-
- // Test normal path equivalent
- $output = file_get_mimetype($input);
- $this->assertIdentical($output, $expected, t('Mimetype (using mappings from variable) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
- }
-
- // Now test the same when passing in the map.
- variable_del('mime_extension_mapping');
foreach ($test_case as $input => $expected) {
$output = file_get_mimetype($input, $mapping);
$this->assertIdentical($output, $expected, t('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index 8f087af77..8af46a510 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -315,6 +315,21 @@ function file_test_file_url_alter(&$uri) {
}
/**
+ * Implementation of 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 class for testing the stream wrapper registry.
*
* Dummy stream wrapper implementation (dummy://).
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 5f50c30d2..6ec40db01 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -2160,5 +2160,27 @@ function hook_profile_tasks() {
}
/**
+ * Alter MIME type mappings used to determine MIME type from a file extension.
+ *
+ * This hook is run when file_mimetype_mapping() is called. It is used to
+ * allow modules to add to or modify the default mapping from
+ * file_default_mimetype_mapping().
+ *
+ * @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 file_default_mimetype_mapping()
+ */
+function hook_file_mimetype_mapping_alter(&$mapping) {
+ // Add new MIME type 'drupal/info'.
+ $mapping['mimetypes']['example_info'] = 'drupal/info';
+ // Add new extension '.info' 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;
+}
+
+/**
* @} End of "addtogroup hooks".
*/
diff --git a/modules/upload/upload.test b/modules/upload/upload.test
index dfe8e0a7e..70306ef30 100644
--- a/modules/upload/upload.test
+++ b/modules/upload/upload.test
@@ -207,7 +207,6 @@ class UploadTestCase extends DrupalWebTestCase {
* @param string $filename Name of file to verify.
*/
function checkUploadedFile($filename) {
- global $base_url;
$file = 'public://' . $filename;
$this->drupalGet(file_create_url($file), array('external' => TRUE));
$this->assertResponse(array(200), 'Uploaded ' . $filename . ' is accessible.');