diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2015-04-09 15:19:57 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2015-07-27 14:58:45 +0200 |
commit | 6db6689740a5d11dd53b2502d1eea6e9157479df (patch) | |
tree | 276787c9cca5355c5faf50de3b76294b97cca559 /tests | |
parent | 4edfadac96fcf267c97371e67e5feccec94b337e (diff) | |
download | nextcloud-server-6db6689740a5d11dd53b2502d1eea6e9157479df.tar.gz nextcloud-server-6db6689740a5d11dd53b2502d1eea6e9157479df.zip |
Added mimetype detector
* Copied unit tests from old functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/type/detection.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/lib/files/type/detection.php b/tests/lib/files/type/detection.php new file mode 100644 index 00000000000..1483839bf7f --- /dev/null +++ b/tests/lib/files/type/detection.php @@ -0,0 +1,97 @@ +<?php +/** + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Files\Type; + +use \OC\Files\Type\Detection; + +class DetectionTest extends \Test\TestCase { + + public function testDetect() { + $detection = new Detection(); + $dir = \OC::$SERVERROOT.'/tests/data'; + + $result = $detection->detect($dir."/"); + $expected = 'httpd/unix-directory'; + $this->assertEquals($expected, $result); + + $result = $detection->detect($dir."/data.tar.gz"); + $expected = 'application/x-gzip'; + $this->assertEquals($expected, $result); + + $result = $detection->detect($dir."/data.zip"); + $expected = 'application/zip'; + $this->assertEquals($expected, $result); + + $result = $detection->detect($dir."/testimagelarge.svg"); + $expected = 'image/svg+xml'; + $this->assertEquals($expected, $result); + + $result = $detection->detect($dir."/testimage.png"); + $expected = 'image/png'; + $this->assertEquals($expected, $result); + } + + public function testGetSecureMimeType() { + $detection = new Detection(); + $dist = file_get_contents(\OC::$configDir . '/mimetypemapping.dist.json'); + $mimetypemapping = get_object_vars(json_decode($dist)); + $detection->registerTypeArray($mimetypemapping); + + $result = $detection->getSecureMimeType('image/svg+xml'); + $expected = 'text/plain'; + $this->assertEquals($expected, $result); + + $result = $detection->getSecureMimeType('image/png'); + $expected = 'image/png'; + $this->assertEquals($expected, $result); + } + + public function testDetectPath() { + $detection = new Detection(); + $dist = file_get_contents(\OC::$configDir . '/mimetypemapping.dist.json'); + $mimetypemapping = get_object_vars(json_decode($dist)); + $detection->registerTypeArray($mimetypemapping); + + $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('')); + } + + public function testDetectString() { + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); + } + + $detection = new Detection(); + $dist = file_get_contents(\OC::$configDir . '/mimetypemapping.dist.json'); + $mimetypemapping = get_object_vars(json_decode($dist)); + $detection->registerTypeArray($mimetypemapping); + + $result = $detection->detectString("/data/data.tar.gz"); + $expected = 'text/plain; charset=us-ascii'; + $this->assertEquals($expected, $result); + } + +} |