diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2025-02-06 16:13:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-06 16:13:27 +0100 |
commit | 93c72f5675f391fb016f8f9aefc429c7bb0d459b (patch) | |
tree | fec3d61626fbd281136e76ddbc45505aaf08b540 /tests | |
parent | e71e58e06e4c3783e579de2a1cf04a8f201b24e9 (diff) | |
parent | 1e30936b78697c5a474c10537fa45e5cdce342e5 (diff) | |
download | nextcloud-server-93c72f5675f391fb016f8f9aefc429c7bb0d459b.tar.gz nextcloud-server-93c72f5675f391fb016f8f9aefc429c7bb0d459b.zip |
Merge pull request #50660 from nextcloud/fix/mime-int
fix: make sure we process mime extensions as string
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Type/DetectionTest.php | 35 |
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'], |