aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2025-02-05 11:51:10 +0100
committerskjnldsv <skjnldsv@protonmail.com>2025-02-05 12:35:41 +0100
commit6baafd82b65eb8021d9611319886d19c28586e1f (patch)
tree00f7a5c42bd5bb15d0f4ef7914f884e5ed4dcd5b /tests
parent83e35b69915039a6c174be6e471145673995e439 (diff)
downloadnextcloud-server-6baafd82b65eb8021d9611319886d19c28586e1f.tar.gz
nextcloud-server-6baafd82b65eb8021d9611319886d19c28586e1f.zip
fix: make sure we process mime extensions as string
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Type/DetectionTest.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index dcbb455efc9..a11a59bed1e 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -100,6 +100,41 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
+ public function dataMimeTypeCustom(): array {
+ return [
+ ['123', 'foobar/123'],
+ ['a123', 'foobar/123'],
+ ['bar', 'foobar/bar'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataMimeTypeCustom
+ *
+ * @param string $ext
+ * @param string $mime
+ */
+ public function testDetectMimeTypeCustom(string $ext, string $mime): void {
+ $confDir = sys_get_temp_dir();
+ file_put_contents($confDir . '/mimetypemapping.dist.json', json_encode([]));
+
+ /** @var IURLGenerator $urlGenerator */
+ $urlGenerator = $this->getMockBuilder(IURLGenerator::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ /** @var LoggerInterface $logger */
+ $logger = $this->createMock(LoggerInterface::class);
+
+ // Create new mapping file
+ file_put_contents($confDir . '/mimetypemapping.dist.json', json_encode([$ext => [$mime]]));
+
+ $detection = new Detection($urlGenerator, $logger, $confDir, $confDir);
+ $mappings = $detection->getAllMappings();
+ $this->assertArrayHasKey($ext, $mappings);
+ $this->assertEquals($mime, $detection->detectPath('foo.' . $ext));
+ }
+
public function dataGetSecureMimeType(): array {
return [
['image/svg+xml', 'text/plain'],