24
24
use Psr \Log \LoggerInterface ;
25
25
use Test \TestCase ;
26
26
27
+ /**
28
+ * @group DB
29
+ */
27
30
class FilenameValidatorTest extends TestCase {
28
31
29
32
protected IFactory &MockObject $ l10n ;
30
33
protected IConfig &MockObject $ config ;
31
34
protected IDBConnection &MockObject $ database ;
32
35
protected LoggerInterface &MockObject $ logger ;
36
+ protected bool $ dbSupportsUtf8 = true ;
33
37
34
38
protected function setUp (): void {
35
39
parent ::setUp ();
@@ -45,7 +49,13 @@ protected function setUp(): void {
45
49
$ this ->config = $ this ->createMock (IConfig::class);
46
50
$ this ->logger = $ this ->createMock (LoggerInterface::class);
47
51
$ this ->database = $ this ->createMock (IDBConnection::class);
48
- $ this ->database ->method ('supports4ByteText ' )->willReturn (true );
52
+ $ this ->database ->method ('supports4ByteText ' )->willReturnCallback (fn () => $ this ->dbSupportsUtf8 );
53
+ $ this ->overwriteService (IDBConnection::class, $ this ->database );
54
+ }
55
+
56
+ protected function tearDown (): void {
57
+ $ this ->restoreAllServices ();
58
+ parent ::tearDown ();
49
59
}
50
60
51
61
/**
@@ -67,7 +77,7 @@ public function testValidateFilename(
67
77
'getForbiddenExtensions ' ,
68
78
'getForbiddenFilenames ' ,
69
79
])
70
- ->setConstructorArgs ([$ this ->l10n , $ this ->database , $ this -> config , $ this ->logger ])
80
+ ->setConstructorArgs ([$ this ->l10n , $ this ->config , $ this ->logger ])
71
81
->getMock ();
72
82
73
83
$ validator ->method ('getForbiddenBasenames ' )
@@ -106,7 +116,7 @@ public function testIsFilenameValid(
106
116
'getForbiddenFilenames ' ,
107
117
'getForbiddenCharacters ' ,
108
118
])
109
- ->setConstructorArgs ([$ this ->l10n , $ this ->database , $ this -> config , $ this ->logger ])
119
+ ->setConstructorArgs ([$ this ->l10n , $ this ->config , $ this ->logger ])
110
120
->getMock ();
111
121
112
122
$ validator ->method ('getForbiddenBasenames ' )
@@ -186,20 +196,17 @@ public function dataValidateFilename(): array {
186
196
* @dataProvider data4ByteUnicode
187
197
*/
188
198
public function testDatabaseDoesNotSupport4ByteText ($ filename ): void {
189
- $ database = $ this ->createMock (IDBConnection::class);
190
- $ database ->expects ($ this ->once ())
191
- ->method ('supports4ByteText ' )
192
- ->willReturn (false );
199
+ $ this ->dbSupportsUtf8 = false ;
200
+
193
201
$ this ->expectException (InvalidCharacterInPathException::class);
194
- $ validator = new FilenameValidator ($ this ->l10n , $ database , $ this ->config , $ this ->logger );
202
+ $ validator = new FilenameValidator ($ this ->l10n , $ this ->config , $ this ->logger );
195
203
$ validator ->validateFilename ($ filename );
196
204
}
197
205
198
206
public function data4ByteUnicode (): array {
199
207
return [
200
208
['plane 1 𐪅 ' ],
201
209
['emoji 😶🌫️ ' ],
202
-
203
210
];
204
211
}
205
212
@@ -208,7 +215,7 @@ public function data4ByteUnicode(): array {
208
215
*/
209
216
public function testInvalidAsciiCharactersAreAlwaysForbidden (string $ filename ): void {
210
217
$ this ->expectException (InvalidPathException::class);
211
- $ validator = new FilenameValidator ($ this ->l10n , $ this ->database , $ this -> config , $ this ->logger );
218
+ $ validator = new FilenameValidator ($ this ->l10n , $ this ->config , $ this ->logger );
212
219
$ validator ->validateFilename ($ filename );
213
220
}
214
221
@@ -256,7 +263,7 @@ public function testIsForbidden(string $filename, array $forbiddenNames, bool $e
256
263
/** @var FilenameValidator&MockObject */
257
264
$ validator = $ this ->getMockBuilder (FilenameValidator::class)
258
265
->onlyMethods (['getForbiddenFilenames ' ])
259
- ->setConstructorArgs ([$ this ->l10n , $ this ->database , $ this -> config , $ this ->logger ])
266
+ ->setConstructorArgs ([$ this ->l10n , $ this ->config , $ this ->logger ])
260
267
->getMock ();
261
268
262
269
$ validator ->method ('getForbiddenFilenames ' )
0 commit comments