/
mediapool_test.php
61 lines (52 loc) · 1.92 KB
/
mediapool_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
class rex_mediapool_test extends TestCase
{
#[DataProvider('provideIsAllowedExtension')]
public function testIsAllowedExtension(bool $expected, string $filename, array $args = []): void
{
self::assertSame($expected, rex_mediapool::isAllowedExtension($filename, $args));
}
/** @return list<array{0: bool, 1: string, 2?: array{types: string}}> */
public static function provideIsAllowedExtension(): array
{
return [
[false, 'foo.bar.php'],
[false, 'foo.bar.php5'],
[false, 'foo.bar.php71'],
[false, 'foo.bar.php_71'],
[false, 'foo.bar.jsp'],
[false, '.htaccess'],
[false, '.htpasswd'],
[true, 'php_logo.jpg'],
[true, 'foo.bar.png', ['types' => 'jpg,png,gif']],
[false, 'foo.bar.txt', ['types' => 'jpg,png,gif']],
[false, 'foo.bar.php', ['types' => 'jpg,png,gif,php']],
];
}
#[DataProvider('provideIsAllowedMimeType')]
public function testIsAllowedMimeType(bool $expected, string $path, ?string $filename = null): void
{
$addon = rex_addon::get('mediapool');
$allowedMimeTypes = $addon->getProperty('allowed_mime_types');
$addon->setProperty('allowed_mime_types', [
'md' => ['text/plain'],
]);
self::assertSame($expected, rex_mediapool::isAllowedMimeType($path, $filename));
$addon->setProperty('allowed_mime_types', $allowedMimeTypes);
}
/** @return list<array{0: bool, 1: string, 2?: string}> */
public static function provideIsAllowedMimeType(): array
{
return [
[false, __FILE__],
[false, __FILE__, 'foo.md'],
[true, __DIR__ . '/../CHANGELOG.md'],
[false, __DIR__ . '/../CHANGELOG.md', 'foo.txt'],
];
}
}