summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-12-04 22:32:54 +0100
committerBackportbot <backportbot-noreply@rullzer.com>2019-12-12 22:06:08 +0000
commit1d7db7d1979ed1d218ec585d490219f0e1850abd (patch)
treed878058f08c221bcd30d7f7ce3e1de437633fe8c /tests
parentb50c2078a02fcb32f16ed8b949eaa01d03ddf712 (diff)
downloadnextcloud-server-1d7db7d1979ed1d218ec585d490219f0e1850abd.tar.gz
nextcloud-server-1d7db7d1979ed1d218ec585d490219f0e1850abd.zip
Update the unit test to dataProviders
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Type/DetectionTest.php119
1 files changed, 77 insertions, 42 deletions
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index 1d01a96fcc0..c6dded1f6ff 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -37,61 +37,96 @@ class DetectionTest extends \Test\TestCase {
);
}
- public function testDetect() {
- $dir = \OC::$SERVERROOT.'/tests/data';
+ public function dataDetectPath(): array {
+ return [
+ ['foo.txt', 'text/plain'],
+ ['foo.png', 'image/png'],
+ ['foo.bar.png', 'image/png'],
+ ['.hidden.png', 'image/png'],
+ ['.hidden.foo.png', 'image/png'],
+ ['.hidden/foo.png', 'image/png'],
+ ['.hidden/.hidden.png', 'image/png'],
+ ['test.jpg/foo.png', 'image/png'],
+ ['.png', 'application/octet-stream'],
+ ['..hidden', 'application/octet-stream'],
+ ['foo', 'application/octet-stream'],
+ ['', 'application/octet-stream'],
+ ['foo.png.ocTransferId123456789.part', 'image/png'],
+ ['foo.png.v1234567890', 'image/png'],
+ ];
+ }
- $result = $this->detection->detect($dir."/");
- $expected = 'httpd/unix-directory';
- $this->assertEquals($expected, $result);
+ /**
+ * @dataProvider dataDetectPath
+ *
+ * @param string $path
+ * @param string $expected
+ */
+ public function testDetectPath(string $path, string $expected): void {
+ $this->assertEquals($expected, $this->detection->detectPath($path));
+ }
- $result = $this->detection->detect($dir."/data.tar.gz");
- $expected = 'application/x-gzip';
- $this->assertEquals($expected, $result);
+ public function dataDetectContent(): array {
+ return [
+ ['/', 'httpd/unix-directory'],
+ ['/data.tar.gz', 'application/x-gzip'],
+ ['/data.zip', 'application/zip'],
+ ['/testimage.mp3', 'audio/mpeg'],
+ ['/testimage.png', 'image/png'],
+ ];
+ }
- $result = $this->detection->detect($dir."/data.zip");
- $expected = 'application/zip';
- $this->assertEquals($expected, $result);
+ /**
+ * @dataProvider dataDetectContent
+ *
+ * @param string $path
+ * @param string $expected
+ */
+ public function testDetectContent(string $path, string $expected): void {
+ $this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path));
+ }
- $result = $this->detection->detect($dir."/testimagelarge.svg");
- $expected = 'image/svg+xml';
- $this->assertEquals($expected, $result);
+ public function dataDetect(): array {
+ return [
+ ['/', 'httpd/unix-directory'],
+ ['/data.tar.gz', 'application/x-gzip'],
+ ['/data.zip', 'application/zip'],
+ ['/testimagelarge.svg', 'image/svg+xml'],
+ ['/testimage.png', 'image/png'],
+ ];
+ }
- $result = $this->detection->detect($dir."/testimage.png");
- $expected = 'image/png';
- $this->assertEquals($expected, $result);
+ /**
+ * @dataProvider dataDetect
+ *
+ * @param string $path
+ * @param string $expected
+ */
+ public function testDetect(string $path, string $expected): void {
+ $this->assertEquals($expected, $this->detection->detect(\OC::$SERVERROOT . '/tests/data' . $path));
}
- public function testGetSecureMimeType() {
- $result = $this->detection->getSecureMimeType('image/svg+xml');
+ public function testDetectString(): void {
+ $result = $this->detection->detectString('/data/data.tar.gz');
$expected = 'text/plain';
$this->assertEquals($expected, $result);
-
- $result = $this->detection->getSecureMimeType('image/png');
- $expected = 'image/png';
- $this->assertEquals($expected, $result);
}
- public function testDetectPath() {
- $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('image/png', $this->detection->detectPath('.hidden.png'));
- $this->assertEquals('image/png', $this->detection->detectPath('.hidden.foo.png'));
- $this->assertEquals('image/png', $this->detection->detectPath('.hidden/foo.png'));
- $this->assertEquals('image/png', $this->detection->detectPath('.hidden/.hidden.png'));
- $this->assertEquals('image/png', $this->detection->detectPath('test.jpg/foo.png'));
- $this->assertEquals('application/octet-stream', $this->detection->detectPath('.png'));
- $this->assertEquals('application/octet-stream', $this->detection->detectPath('..hidden'));
- $this->assertEquals('application/octet-stream', $this->detection->detectPath('foo'));
- $this->assertEquals('application/octet-stream', $this->detection->detectPath(''));
- $this->assertEquals('image/png', $this->detection->detectPath('foo.png.ocTransferId123456789.part'));
- $this->assertEquals('image/png', $this->detection->detectPath('foo.png.v1234567890'));
+ public function dataGetSecureMimeType(): array {
+ return [
+ ['image/svg+xml', 'text/plain'],
+ ['image/png', 'image/png'],
+ ];
}
- public function testDetectString() {
- $result = $this->detection->detectString("/data/data.tar.gz");
- $expected = 'text/plain';
- $this->assertEquals($expected, $result);
+ /**
+ * @dataProvider dataGetSecureMimeType
+ *
+ * @param string $mimeType
+ * @param string $expected
+ */
+ public function testGetSecureMimeType(string $mimeType, string $expected): void {
+ $this->assertEquals($expected, $this->detection->getSecureMimeType($mimeType));
}
public function testMimeTypeIcon() {