From 0040633fa4f86b88b437877d832996fab8007ad1 Mon Sep 17 00:00:00 2001
From: lubosdz <lubosdz@gmail.com>
Date: Fri, 4 Apr 2014 13:50:58 +0200
Subject: [PATCH] Fixed test break and JSON MIME type. Fixes issue #2978.

---
 framework/helpers/mimeTypes.php                 | 2 ++
 tests/unit/framework/helpers/FileHelperTest.php | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/framework/helpers/mimeTypes.php b/framework/helpers/mimeTypes.php
index 7f95e0b..0e6c7a4 100644
--- a/framework/helpers/mimeTypes.php
+++ b/framework/helpers/mimeTypes.php
@@ -71,6 +71,8 @@ return [
     'jpeg' => 'image/jpeg',
     'jpg' => 'image/jpeg',
     'js' => 'application/x-javascript',
+	'json' => 'application/json',
+	'jsonp' => 'text/javascript',
     'kar' => 'audio/midi',
     'latex' => 'application/x-latex',
     'lha' => 'application/octet-stream',
diff --git a/tests/unit/framework/helpers/FileHelperTest.php b/tests/unit/framework/helpers/FileHelperTest.php
index 0c1a9bc..edc6cab 100644
--- a/tests/unit/framework/helpers/FileHelperTest.php
+++ b/tests/unit/framework/helpers/FileHelperTest.php
@@ -348,10 +348,14 @@ class FileHelperTest extends TestCase
         $file = $this->testFilePath . DIRECTORY_SEPARATOR . 'mime_type_test.txt';
         file_put_contents($file, 'some text');
         $this->assertEquals('text/plain', FileHelper::getMimeType($file));
-
+		
+		// see http://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type
+		// JSON/JSONP should not use text/plain - see http://jibbering.com/blog/?p=514
+		// with "fileinfo" extension enabled, returned MIME is not quite correctly "text/plain"
+		// without "fileinfo" it falls back to getMimeTypeByExtension() and returns application/json
         $file = $this->testFilePath . DIRECTORY_SEPARATOR . 'mime_type_test.json';
         file_put_contents($file, '{"a": "b"}');
-        $this->assertEquals('text/plain', FileHelper::getMimeType($file));
+        $this->assertTrue(in_array(FileHelper::getMimeType($file), array('application/json', 'text/plain')));
     }
 
     public function testNormalizePath()
--
libgit2 0.27.1