From 63b2bc136aa9b101b424cab89f31c772a9a4baea Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 8 Sep 2015 12:17:57 +0200 Subject: Move mimetype files into /resources/config/ --- config/mimetypealiases.dist.json | 73 ------------ config/mimetypemapping.dist.json | 171 ----------------------------- lib/private/files/type/detection.php | 35 +++--- lib/private/server.php | 4 +- resources/config/mimetypealiases.dist.json | 73 ++++++++++++ resources/config/mimetypemapping.dist.json | 171 +++++++++++++++++++++++++++++ tests/lib/files/type/detection.php | 66 +++++------ 7 files changed, 304 insertions(+), 289 deletions(-) delete mode 100644 config/mimetypealiases.dist.json delete mode 100644 config/mimetypemapping.dist.json create mode 100644 resources/config/mimetypealiases.dist.json create mode 100644 resources/config/mimetypemapping.dist.json diff --git a/config/mimetypealiases.dist.json b/config/mimetypealiases.dist.json deleted file mode 100644 index 2c9bdaa00c8..00000000000 --- a/config/mimetypealiases.dist.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "_comment" : "Array of mimetype aliases.", - "_comment2": "Any changes you make here will be overwritten on an update of ownCloud.", - "_comment3": "Put any custom aliases in a new file mimetypealiases.json in this directory", - - "_comment4": "After any change to mimetypealiases.json run:", - "_comment5": "./occ maintenance:mimetypesjs", - "_comment6": "Otherwise your update won't propagate through the system.", - - - "application/coreldraw": "image", - "application/font-sfnt": "font", - "application/font-woff": "font", - "application/illustrator": "image/vector", - "application/json": "text/code", - "application/msaccess": "database", - "application/msexcel": "x-office/spreadsheet", - "application/mspowerpoint": "x-office/presentation", - "application/msword": "x-office/document", - "application/octet-stream": "file", - "application/postscript": "image/vector", - "application/vnd.android.package-archive": "package/x-generic", - "application/vnd.ms-excel": "x-office/spreadsheet", - "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-fontobject": "font", - "application/vnd.ms-powerpoint": "x-office/presentation", - "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation", - "application/vnd.ms-word.document.macroEnabled.12": "x-office/document", - "application/vnd.ms-word.template.macroEnabled.12": "x-office/document", - "application/vnd.oasis.opendocument.presentation": "x-office/presentation", - "application/vnd.oasis.opendocument.presentation-template": "x-office/presentation", - "application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet", - "application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet", - "application/vnd.oasis.opendocument.text": "x-office/document", - "application/vnd.oasis.opendocument.text-master": "x-office/document", - "application/vnd.oasis.opendocument.text-template": "x-office/document", - "application/vnd.oasis.opendocument.text-web": "x-office/document", - "application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet", - "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", - "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", - "application/x-7z-compressed": "package/x-generic", - "application/x-compressed": "package/x-generic", - "application/x-dcraw": "image", - "application/x-deb": "package/x-generic", - "application/x-font": "font", - "application/x-gimp": "image", - "application/x-gzip": "package/x-generic", - "application/x-perl": "text/code", - "application/x-photoshop": "image", - "application/x-php": "text/code", - "application/x-rar-compressed": "package/x-generic", - "application/x-tar": "package/x-generic", - "application/x-tex": "text", - "application/xml": "text/html", - "application/yaml": "text/code", - "application/zip": "package/x-generic", - "httpd/unix-directory": "dir", - "image/svg+xml": "image/vector", - "text/css": "text/code", - "text/csv": "x-office/spreadsheet", - "text/x-shellscript": "text/code" -} - diff --git a/config/mimetypemapping.dist.json b/config/mimetypemapping.dist.json deleted file mode 100644 index 48ec4a56dab..00000000000 --- a/config/mimetypemapping.dist.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "_comment" : "Array mapping file extensions to mimetypes (in alphabetical order]", - "_comment2": "The first index in the mime type array is the assumed correct mimetype", - "_comment3": "and the second (if present] is a secure alternative", - - "_comment4": "Any changes you make here will be overwritten on an update of ownCloud", - "_comment5": "Put any custom mappings in a new file mimetypemapping.json in this directory", - - - "3gp": ["video/3gpp"], - "7z": ["application/x-7z-compressed"], - "accdb": ["application/msaccess"], - "ai": ["application/illustrator"], - "apk": ["application/vnd.android.package-archive"], - "arw": ["image/x-dcraw"], - "avi": ["video/x-msvideo"], - "bash": ["text/x-shellscript"], - "blend": ["application/x-blender"], - "bin": ["application/x-bin"], - "bmp": ["image/bmp"], - "bpg": ["image/bpg"], - "cb7": ["application/x-cbr"], - "cba": ["application/x-cbr"], - "cbr": ["application/x-cbr"], - "cbt": ["application/x-cbr"], - "cbtc": ["application/x-cbr"], - "cbz": ["application/x-cbr"], - "cc": ["text/x-c"], - "cdr": ["application/coreldraw"], - "cnf": ["text/plain"], - "conf": ["text/plain"], - "cpp": ["text/x-c++src"], - "cr2": ["image/x-dcraw"], - "css": ["text/css"], - "csv": ["text/csv"], - "cvbdl": ["application/x-cbr"], - "c": ["text/x-c"], - "c++": ["text/x-c++src"], - "dcr": ["image/x-dcraw"], - "deb": ["application/x-deb"], - "dng": ["image/x-dcraw"], - "doc": ["application/msword"], - "docm": ["application/vnd.ms-word.document.macroEnabled.12"], - "docx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], - "dot": ["application/msword"], - "dotx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"], - "dv": ["video/dv"], - "eot": ["application/vnd.ms-fontobject"], - "epub": ["application/epub+zip"], - "eps": ["application/postscript"], - "erf": ["image/x-dcraw"], - "exe": ["application/x-ms-dos-executable"], - "flac": ["audio/flac"], - "flv": ["video/x-flv"], - "gif": ["image/gif"], - "gz": ["application/x-gzip"], - "gzip": ["application/x-gzip"], - "h": ["text/x-h"], - "hh": ["text/x-h"], - "html": ["text/html", "text/plain"], - "htm": ["text/html", "text/plain"], - "ical": ["text/calendar"], - "ics": ["text/calendar"], - "iiq": ["image/x-dcraw"], - "impress": ["text/impress"], - "jpeg": ["image/jpeg"], - "jpg": ["image/jpeg"], - "jps": ["image/jpeg"], - "js": ["application/javascript", "text/plain"], - "json": ["application/json", "text/plain"], - "k25": ["image/x-dcraw"], - "kdc": ["image/x-dcraw"], - "key": ["application/x-iwork-keynote-sffkey"], - "keynote": ["application/x-iwork-keynote-sffkey"], - "kra": ["application/x-krita"], - "m2t": ["video/mp2t"], - "m4v": ["video/mp4"], - "markdown": ["text/markdown"], - "mdown": ["text/markdown"], - "md": ["text/markdown"], - "mdb": ["application/msaccess"], - "mdwn": ["text/markdown"], - "mkd": ["text/markdown"], - "mef": ["image/x-dcraw"], - "mkv": ["video/x-matroska"], - "mobi": ["application/x-mobipocket-ebook"], - "mov": ["video/quicktime"], - "mp3": ["audio/mpeg"], - "mp4": ["video/mp4"], - "mpeg": ["video/mpeg"], - "mpg": ["video/mpeg"], - "mpo": ["image/jpeg"], - "msi": ["application/x-msi"], - "mts": ["video/MP2T"], - "mt2s": ["video/MP2T"], - "nef": ["image/x-dcraw"], - "numbers": ["application/x-iwork-numbers-sffnumbers"], - "odf": ["application/vnd.oasis.opendocument.formula"], - "odg": ["application/vnd.oasis.opendocument.graphics"], - "odp": ["application/vnd.oasis.opendocument.presentation"], - "ods": ["application/vnd.oasis.opendocument.spreadsheet"], - "odt": ["application/vnd.oasis.opendocument.text"], - "oga": ["audio/ogg"], - "ogg": ["audio/ogg"], - "ogv": ["video/ogg"], - "opus": ["audio/ogg"], - "orf": ["image/x-dcraw"], - "otf": ["application/font-sfnt"], - "pages": ["application/x-iwork-pages-sffpages"], - "pdf": ["application/pdf"], - "pfb": ["application/x-font"], - "pef": ["image/x-dcraw"], - "php": ["application/x-php"], - "pl": ["application/x-perl"], - "png": ["image/png"], - "pot": ["application/vnd.ms-powerpoint"], - "potm": ["application/vnd.ms-powerpoint.template.macroEnabled.12"], - "potx": ["application/vnd.openxmlformats-officedocument.presentationml.template"], - "ppa": ["application/vnd.ms-powerpoint"], - "ppam": ["application/vnd.ms-powerpoint.addin.macroEnabled.12"], - "pps": ["application/vnd.ms-powerpoint"], - "ppsm": ["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"], - "ppsx": ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"], - "ppt": ["application/vnd.ms-powerpoint"], - "pptm": ["application/vnd.ms-powerpoint.presentation.macroEnabled.12"], - "pptx": ["application/vnd.openxmlformats-officedocument.presentationml.presentation"], - "ps": ["application/postscript"], - "psd": ["application/x-photoshop"], - "py": ["text/x-python"], - "raf": ["image/x-dcraw"], - "rar": ["application/x-rar-compressed"], - "reveal": ["text/reveal"], - "rw2": ["image/x-dcraw"], - "sgf": ["application/sgf"], - "sh-lib": ["text/x-shellscript"], - "sh": ["text/x-shellscript"], - "srf": ["image/x-dcraw"], - "sr2": ["image/x-dcraw"], - "svg": ["image/svg+xml", "text/plain"], - "swf": ["application/x-shockwave-flash", "application/octet-stream"], - "tar": ["application/x-tar"], - "tar.gz": ["application/x-compressed"], - "tex": ["application/x-tex"], - "tgz": ["application/x-compressed"], - "tiff": ["image/tiff"], - "tif": ["image/tiff"], - "ttf": ["application/font-sfnt"], - "txt": ["text/plain"], - "vcard": ["text/vcard"], - "vcf": ["text/vcard"], - "vob": ["video/dvd"], - "wav": ["audio/wav"], - "webm": ["video/webm"], - "woff": ["application/font-woff"], - "wmv": ["video/x-ms-wmv"], - "xcf": ["application/x-gimp"], - "xla": ["application/vnd.ms-excel"], - "xlam": ["application/vnd.ms-excel.addin.macroEnabled.12"], - "xls": ["application/vnd.ms-excel"], - "xlsb": ["application/vnd.ms-excel.sheet.binary.macroEnabled.12"], - "xlsm": ["application/vnd.ms-excel.sheet.macroEnabled.12"], - "xlsx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], - "xlt": ["application/vnd.ms-excel"], - "xltm": ["application/vnd.ms-excel.template.macroEnabled.12"], - "xltx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"], - "xml": ["application/xml", "text/plain"], - "xrf": ["image/x-dcraw"], - "yaml": ["application/yaml", "text/plain"], - "yml": ["application/yaml", "text/plain"], - "zip": ["application/zip"] -} diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 3dc3975fb2a..0c647ab44c6 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -49,15 +49,22 @@ class Detection implements IMimeTypeDetector { private $urlGenerator; /** @var string */ - private $configDir; + private $customConfigDir; + + /** @var string */ + private $defaultConfigDir; /** * @param IURLGenerator $urlGenerator - * @param string $configDir + * @param string $customConfigDir + * @param string $defaultConfigDir */ - public function __construct(IURLGenerator $urlGenerator, $configDir) { + public function __construct(IURLGenerator $urlGenerator, + $customConfigDir, + $defaultConfigDir) { $this->urlGenerator = $urlGenerator; - $this->configDir = $configDir; + $this->customConfigDir = $customConfigDir; + $this->defaultConfigDir = $defaultConfigDir; } /** @@ -71,7 +78,9 @@ class Detection implements IMimeTypeDetector { * @param string $mimetype * @param string|null $secureMimeType */ - public function registerType($extension, $mimetype, $secureMimeType = null) { + public function registerType($extension, + $mimetype, + $secureMimeType = null) { $this->mimetypes[$extension] = array($mimetype, $secureMimeType); $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; } @@ -102,10 +111,10 @@ class Detection implements IMimeTypeDetector { return; } - $this->mimeTypeAlias = json_decode(file_get_contents($this->configDir . '/mimetypealiases.dist.json'), true); + $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); - if (file_exists($this->configDir . '/mimetypealiases.json')) { - $custom = json_decode(file_get_contents($this->configDir . '/mimetypealiases.json'), true); + if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); } } @@ -126,15 +135,15 @@ class Detection implements IMimeTypeDetector { return; } - $mimetypemapping = json_decode(file_get_contents($this->configDir . '/mimetypemapping.dist.json'), true); + $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); //Check if need to load custom mappings - if (file_exists($this->configDir . '/mimetypemapping.json')) { - $custom = json_decode(file_get_contents($this->configDir . '/mimetypemapping.json'), true); - $mimetypemapping = array_merge($mimetypemapping, $custom); + if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); + $mimetypeMapping = array_merge($mimetypeMapping, $custom); } - $this->registerTypeArray($mimetypemapping); + $this->registerTypeArray($mimetypeMapping); } /** diff --git a/lib/private/server.php b/lib/private/server.php index d5f4f532c1c..9f99ead849b 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -470,7 +470,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('MimeTypeDetector', function(Server $c) { return new \OC\Files\Type\Detection( $c->getURLGenerator(), - \OC::$configDir); + \OC::$SERVERROOT . '/config/', + \OC::$SERVERROOT . '/resources/config/' + ); }); $this->registerService('MimeTypeLoader', function(Server $c) { return new \OC\Files\Type\Loader( diff --git a/resources/config/mimetypealiases.dist.json b/resources/config/mimetypealiases.dist.json new file mode 100644 index 00000000000..3d6c5edc132 --- /dev/null +++ b/resources/config/mimetypealiases.dist.json @@ -0,0 +1,73 @@ +{ + "_comment" : "Array of mimetype aliases.", + "_comment2": "Any changes you make here will be overwritten on an update of ownCloud.", + "_comment3": "Put any custom mappings in a new file mimetypealiases.json in the config/ folder of ownCloud", + + "_comment4": "After any change to mimetypealiases.json run:", + "_comment5": "./occ maintenance:mimetypesjs", + "_comment6": "Otherwise your update won't propagate through the system.", + + + "application/coreldraw": "image", + "application/font-sfnt": "font", + "application/font-woff": "font", + "application/illustrator": "image/vector", + "application/json": "text/code", + "application/msaccess": "database", + "application/msexcel": "x-office/spreadsheet", + "application/mspowerpoint": "x-office/presentation", + "application/msword": "x-office/document", + "application/octet-stream": "file", + "application/postscript": "image/vector", + "application/vnd.android.package-archive": "package/x-generic", + "application/vnd.ms-excel": "x-office/spreadsheet", + "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", + "application/vnd.ms-fontobject": "font", + "application/vnd.ms-powerpoint": "x-office/presentation", + "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation", + "application/vnd.ms-word.document.macroEnabled.12": "x-office/document", + "application/vnd.ms-word.template.macroEnabled.12": "x-office/document", + "application/vnd.oasis.opendocument.presentation": "x-office/presentation", + "application/vnd.oasis.opendocument.presentation-template": "x-office/presentation", + "application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet", + "application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet", + "application/vnd.oasis.opendocument.text": "x-office/document", + "application/vnd.oasis.opendocument.text-master": "x-office/document", + "application/vnd.oasis.opendocument.text-template": "x-office/document", + "application/vnd.oasis.opendocument.text-web": "x-office/document", + "application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet", + "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", + "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", + "application/x-7z-compressed": "package/x-generic", + "application/x-compressed": "package/x-generic", + "application/x-dcraw": "image", + "application/x-deb": "package/x-generic", + "application/x-font": "font", + "application/x-gimp": "image", + "application/x-gzip": "package/x-generic", + "application/x-perl": "text/code", + "application/x-photoshop": "image", + "application/x-php": "text/code", + "application/x-rar-compressed": "package/x-generic", + "application/x-tar": "package/x-generic", + "application/x-tex": "text", + "application/xml": "text/html", + "application/yaml": "text/code", + "application/zip": "package/x-generic", + "httpd/unix-directory": "dir", + "image/svg+xml": "image/vector", + "text/css": "text/code", + "text/csv": "x-office/spreadsheet", + "text/x-shellscript": "text/code" +} + diff --git a/resources/config/mimetypemapping.dist.json b/resources/config/mimetypemapping.dist.json new file mode 100644 index 00000000000..79b0ca65240 --- /dev/null +++ b/resources/config/mimetypemapping.dist.json @@ -0,0 +1,171 @@ +{ + "_comment" : "Array mapping file extensions to mimetypes (in alphabetical order]", + "_comment2": "The first index in the mime type array is the assumed correct mimetype", + "_comment3": "and the second (if present] is a secure alternative", + + "_comment4": "Any changes you make here will be overwritten on an update of ownCloud", + "_comment5": "Put any custom mappings in a new file mimetypemapping.json in the config/ folder of ownCloud", + + + "3gp": ["video/3gpp"], + "7z": ["application/x-7z-compressed"], + "accdb": ["application/msaccess"], + "ai": ["application/illustrator"], + "apk": ["application/vnd.android.package-archive"], + "arw": ["image/x-dcraw"], + "avi": ["video/x-msvideo"], + "bash": ["text/x-shellscript"], + "blend": ["application/x-blender"], + "bin": ["application/x-bin"], + "bmp": ["image/bmp"], + "bpg": ["image/bpg"], + "cb7": ["application/x-cbr"], + "cba": ["application/x-cbr"], + "cbr": ["application/x-cbr"], + "cbt": ["application/x-cbr"], + "cbtc": ["application/x-cbr"], + "cbz": ["application/x-cbr"], + "cc": ["text/x-c"], + "cdr": ["application/coreldraw"], + "cnf": ["text/plain"], + "conf": ["text/plain"], + "cpp": ["text/x-c++src"], + "cr2": ["image/x-dcraw"], + "css": ["text/css"], + "csv": ["text/csv"], + "cvbdl": ["application/x-cbr"], + "c": ["text/x-c"], + "c++": ["text/x-c++src"], + "dcr": ["image/x-dcraw"], + "deb": ["application/x-deb"], + "dng": ["image/x-dcraw"], + "doc": ["application/msword"], + "docm": ["application/vnd.ms-word.document.macroEnabled.12"], + "docx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], + "dot": ["application/msword"], + "dotx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"], + "dv": ["video/dv"], + "eot": ["application/vnd.ms-fontobject"], + "epub": ["application/epub+zip"], + "eps": ["application/postscript"], + "erf": ["image/x-dcraw"], + "exe": ["application/x-ms-dos-executable"], + "flac": ["audio/flac"], + "flv": ["video/x-flv"], + "gif": ["image/gif"], + "gz": ["application/x-gzip"], + "gzip": ["application/x-gzip"], + "h": ["text/x-h"], + "hh": ["text/x-h"], + "html": ["text/html", "text/plain"], + "htm": ["text/html", "text/plain"], + "ical": ["text/calendar"], + "ics": ["text/calendar"], + "iiq": ["image/x-dcraw"], + "impress": ["text/impress"], + "jpeg": ["image/jpeg"], + "jpg": ["image/jpeg"], + "jps": ["image/jpeg"], + "js": ["application/javascript", "text/plain"], + "json": ["application/json", "text/plain"], + "k25": ["image/x-dcraw"], + "kdc": ["image/x-dcraw"], + "key": ["application/x-iwork-keynote-sffkey"], + "keynote": ["application/x-iwork-keynote-sffkey"], + "kra": ["application/x-krita"], + "m2t": ["video/mp2t"], + "m4v": ["video/mp4"], + "markdown": ["text/markdown"], + "mdown": ["text/markdown"], + "md": ["text/markdown"], + "mdb": ["application/msaccess"], + "mdwn": ["text/markdown"], + "mkd": ["text/markdown"], + "mef": ["image/x-dcraw"], + "mkv": ["video/x-matroska"], + "mobi": ["application/x-mobipocket-ebook"], + "mov": ["video/quicktime"], + "mp3": ["audio/mpeg"], + "mp4": ["video/mp4"], + "mpeg": ["video/mpeg"], + "mpg": ["video/mpeg"], + "mpo": ["image/jpeg"], + "msi": ["application/x-msi"], + "mts": ["video/MP2T"], + "mt2s": ["video/MP2T"], + "nef": ["image/x-dcraw"], + "numbers": ["application/x-iwork-numbers-sffnumbers"], + "odf": ["application/vnd.oasis.opendocument.formula"], + "odg": ["application/vnd.oasis.opendocument.graphics"], + "odp": ["application/vnd.oasis.opendocument.presentation"], + "ods": ["application/vnd.oasis.opendocument.spreadsheet"], + "odt": ["application/vnd.oasis.opendocument.text"], + "oga": ["audio/ogg"], + "ogg": ["audio/ogg"], + "ogv": ["video/ogg"], + "opus": ["audio/ogg"], + "orf": ["image/x-dcraw"], + "otf": ["application/font-sfnt"], + "pages": ["application/x-iwork-pages-sffpages"], + "pdf": ["application/pdf"], + "pfb": ["application/x-font"], + "pef": ["image/x-dcraw"], + "php": ["application/x-php"], + "pl": ["application/x-perl"], + "png": ["image/png"], + "pot": ["application/vnd.ms-powerpoint"], + "potm": ["application/vnd.ms-powerpoint.template.macroEnabled.12"], + "potx": ["application/vnd.openxmlformats-officedocument.presentationml.template"], + "ppa": ["application/vnd.ms-powerpoint"], + "ppam": ["application/vnd.ms-powerpoint.addin.macroEnabled.12"], + "pps": ["application/vnd.ms-powerpoint"], + "ppsm": ["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"], + "ppsx": ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"], + "ppt": ["application/vnd.ms-powerpoint"], + "pptm": ["application/vnd.ms-powerpoint.presentation.macroEnabled.12"], + "pptx": ["application/vnd.openxmlformats-officedocument.presentationml.presentation"], + "ps": ["application/postscript"], + "psd": ["application/x-photoshop"], + "py": ["text/x-python"], + "raf": ["image/x-dcraw"], + "rar": ["application/x-rar-compressed"], + "reveal": ["text/reveal"], + "rw2": ["image/x-dcraw"], + "sgf": ["application/sgf"], + "sh-lib": ["text/x-shellscript"], + "sh": ["text/x-shellscript"], + "srf": ["image/x-dcraw"], + "sr2": ["image/x-dcraw"], + "svg": ["image/svg+xml", "text/plain"], + "swf": ["application/x-shockwave-flash", "application/octet-stream"], + "tar": ["application/x-tar"], + "tar.gz": ["application/x-compressed"], + "tex": ["application/x-tex"], + "tgz": ["application/x-compressed"], + "tiff": ["image/tiff"], + "tif": ["image/tiff"], + "ttf": ["application/font-sfnt"], + "txt": ["text/plain"], + "vcard": ["text/vcard"], + "vcf": ["text/vcard"], + "vob": ["video/dvd"], + "wav": ["audio/wav"], + "webm": ["video/webm"], + "woff": ["application/font-woff"], + "wmv": ["video/x-ms-wmv"], + "xcf": ["application/x-gimp"], + "xla": ["application/vnd.ms-excel"], + "xlam": ["application/vnd.ms-excel.addin.macroEnabled.12"], + "xls": ["application/vnd.ms-excel"], + "xlsb": ["application/vnd.ms-excel.sheet.binary.macroEnabled.12"], + "xlsm": ["application/vnd.ms-excel.sheet.macroEnabled.12"], + "xlsx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], + "xlt": ["application/vnd.ms-excel"], + "xltm": ["application/vnd.ms-excel.template.macroEnabled.12"], + "xltx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"], + "xml": ["application/xml", "text/plain"], + "xrf": ["image/x-dcraw"], + "yaml": ["application/yaml", "text/plain"], + "yml": ["application/yaml", "text/plain"], + "zip": ["application/zip"] +} diff --git a/tests/lib/files/type/detection.php b/tests/lib/files/type/detection.php index 1997fa4dfd6..5800f4eb8e3 100644 --- a/tests/lib/files/type/detection.php +++ b/tests/lib/files/type/detection.php @@ -19,58 +19,64 @@ * */ -namespace OC\Files\Type; +namespace Test\Files\Type; use \OC\Files\Type\Detection; class DetectionTest extends \Test\TestCase { + /** @var Detection */ + private $detection; + + public function setUp() { + parent::setUp(); + $this->detection = new Detection( + \OC::$server->getURLGenerator(), + \OC::$SERVERROOT . '/config/', + \OC::$SERVERROOT . '/resources/config/' + ); + } public function testDetect() { - $detection = new Detection(\OC::$server->getURLGenerator(), \OC::$configDir); $dir = \OC::$SERVERROOT.'/tests/data'; - $result = $detection->detect($dir."/"); + $result = $this->detection->detect($dir."/"); $expected = 'httpd/unix-directory'; $this->assertEquals($expected, $result); - $result = $detection->detect($dir."/data.tar.gz"); + $result = $this->detection->detect($dir."/data.tar.gz"); $expected = 'application/x-gzip'; $this->assertEquals($expected, $result); - $result = $detection->detect($dir."/data.zip"); + $result = $this->detection->detect($dir."/data.zip"); $expected = 'application/zip'; $this->assertEquals($expected, $result); - $result = $detection->detect($dir."/testimagelarge.svg"); + $result = $this->detection->detect($dir."/testimagelarge.svg"); $expected = 'image/svg+xml'; $this->assertEquals($expected, $result); - $result = $detection->detect($dir."/testimage.png"); + $result = $this->detection->detect($dir."/testimage.png"); $expected = 'image/png'; $this->assertEquals($expected, $result); } public function testGetSecureMimeType() { - $detection = new Detection(\OC::$server->getURLGenerator(), \OC::$configDir); - - $result = $detection->getSecureMimeType('image/svg+xml'); + $result = $this->detection->getSecureMimeType('image/svg+xml'); $expected = 'text/plain'; $this->assertEquals($expected, $result); - $result = $detection->getSecureMimeType('image/png'); + $result = $this->detection->getSecureMimeType('image/png'); $expected = 'image/png'; $this->assertEquals($expected, $result); } public function testDetectPath() { - $detection = new Detection(\OC::$server->getURLGenerator(), \OC::$configDir); - - $this->assertEquals('text/plain', $detection->detectPath('foo.txt')); - $this->assertEquals('image/png', $detection->detectPath('foo.png')); - $this->assertEquals('image/png', $detection->detectPath('foo.bar.png')); - $this->assertEquals('application/octet-stream', $detection->detectPath('.png')); - $this->assertEquals('application/octet-stream', $detection->detectPath('foo')); - $this->assertEquals('application/octet-stream', $detection->detectPath('')); + $this->assertEquals('text/plain', $this->detection->detectPath('foo.txt')); + $this->assertEquals('image/png', $this->detection->detectPath('foo.png')); + $this->assertEquals('image/png', $this->detection->detectPath('foo.bar.png')); + $this->assertEquals('application/octet-stream', $this->detection->detectPath('.png')); + $this->assertEquals('application/octet-stream', $this->detection->detectPath('foo')); + $this->assertEquals('application/octet-stream', $this->detection->detectPath('')); } public function testDetectString() { @@ -78,16 +84,14 @@ class DetectionTest extends \Test\TestCase { $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); } - $detection = new Detection(\OC::$server->getURLGenerator(), \OC::$configDir); - - $result = $detection->detectString("/data/data.tar.gz"); + $result = $this->detection->detectString("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($expected, $result); } public function testMimeTypeIcon() { if (!class_exists('org\\bovigo\\vfs\\vfsStream')) { - $this->markTestSkipped('Pacakge vfsStream not installed'); + $this->markTestSkipped('Package vfsStream not installed'); } $confDir = \org\bovigo\vfs\vfsStream::setup(); $mimetypealiases_dist = \org\bovigo\vfs\vfsStream::newFile('mimetypealiases.dist.json')->at($confDir); @@ -111,7 +115,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/folder.png')) ->willReturn('folder.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir'); $this->assertEquals('folder.svg', $mimeType); @@ -130,7 +134,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/folder-shared.png')) ->willReturn('folder-shared.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir-shared'); $this->assertEquals('folder-shared.svg', $mimeType); @@ -150,7 +154,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/folder-external.png')) ->willReturn('folder-external.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('dir-external'); $this->assertEquals('folder-external.svg', $mimeType); @@ -170,7 +174,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/my-type.png')) ->willReturn('my-type.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('my-type'); $this->assertEquals('my-type.svg', $mimeType); @@ -200,7 +204,7 @@ class DetectionTest extends \Test\TestCase { } )); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('my-type'); $this->assertEquals('my.svg', $mimeType); @@ -231,7 +235,7 @@ class DetectionTest extends \Test\TestCase { } )); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo-bar'); $this->assertEquals('file.svg', $mimeType); @@ -250,7 +254,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/foo-bar.png')) ->willReturn('foo-bar.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo-bar'); $this->assertEquals('foo-bar.svg', $mimeType); $mimeType = $detection->mimeTypeIcon('foo-bar'); @@ -276,7 +280,7 @@ class DetectionTest extends \Test\TestCase { ->with($this->equalTo('core'), $this->equalTo('filetypes/foobar-baz.png')) ->willReturn('foobar-baz.svg'); - $detection = new Detection($urlGenerator, $confDir->url()); + $detection = new Detection($urlGenerator, $confDir->url(), $confDir->url()); $mimeType = $detection->mimeTypeIcon('foo'); $this->assertEquals('foobar-baz.svg', $mimeType); } -- cgit v1.2.3