From 6baafd82b65eb8021d9611319886d19c28586e1f Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Wed, 5 Feb 2025 11:51:10 +0100 Subject: fix: make sure we process mime extensions as string Signed-off-by: skjnldsv --- tests/lib/Files/Type/DetectionTest.php | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') 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'], -- cgit v1.2.3