6
6
use SilverStripe \Core \XssSanitiser ;
7
7
use SilverStripe \Dev \SapphireTest ;
8
8
use SilverStripe \View \Parsers \HTMLValue ;
9
+ use PHPUnit \Framework \Attributes \DataProvider ;
9
10
10
11
class XssSanitiserTest extends SapphireTest
11
12
{
12
13
protected $ usesDatabase = false ;
13
14
14
- public function provideSanitise (): array
15
+ public static function provideSanitise (): array
15
16
{
16
17
// Most of these scenarios are inspired by Symfony's HtmlSanitizerAllTest scenarios
17
18
return [
@@ -305,18 +306,14 @@ public function provideSanitise(): array
305
306
];
306
307
}
307
308
308
- /**
309
- * @dataProvider provideSanitise
310
- */
309
+ #[DataProvider('provideSanitise ' )]
311
310
public function testSanitiseString (string $ input , string $ expected ): void
312
311
{
313
312
$ sanitiser = new XssSanitiser ();
314
313
$ this ->assertSame ($ expected , $ sanitiser ->sanitiseString ($ input ));
315
314
}
316
315
317
- /**
318
- * @dataProvider provideSanitise
319
- */
316
+ #[DataProvider('provideSanitise ' )]
320
317
public function testSanitiseHtmlValue (string $ input , string $ expected ): void
321
318
{
322
319
$ sanitiser = new XssSanitiser ();
@@ -325,9 +322,7 @@ public function testSanitiseHtmlValue(string $input, string $expected): void
325
322
$ this ->assertSame ($ expected , $ htmlValue ->getContent ());
326
323
}
327
324
328
- /**
329
- * @dataProvider provideSanitise
330
- */
325
+ #[DataProvider('provideSanitise ' )]
331
326
public function testSanitiseElement (string $ input , string $ expected ): void
332
327
{
333
328
$ sanitiser = new XssSanitiser ();
@@ -341,7 +336,7 @@ public function testSanitiseElement(string $input, string $expected): void
341
336
$ this ->assertSame ($ expected , $ htmlValue ->getContent ());
342
337
}
343
338
344
- public function provideSanitiseElementsAllowed (): array
339
+ public static function provideSanitiseElementsAllowed (): array
345
340
{
346
341
return [
347
342
'disallow these by default ' => [
@@ -362,9 +357,7 @@ public function provideSanitiseElementsAllowed(): array
362
357
];
363
358
}
364
359
365
- /**
366
- * @dataProvider provideSanitiseElementsAllowed
367
- */
360
+ #[DataProvider('provideSanitiseElementsAllowed ' )]
368
361
public function testSanitiseElementsAllowed (string $ input , ?array $ removeElements , string $ expected ): void
369
362
{
370
363
$ sanitiser = new XssSanitiser ();
@@ -374,7 +367,7 @@ public function testSanitiseElementsAllowed(string $input, ?array $removeElement
374
367
$ this ->assertSame ($ expected , $ sanitiser ->sanitiseString ($ input ));
375
368
}
376
369
377
- public function provideSanitiseAttributesAllowed (): array
370
+ public static function provideSanitiseAttributesAllowed (): array
378
371
{
379
372
return [
380
373
'disallow these by default ' => [
@@ -413,9 +406,7 @@ public function provideSanitiseAttributesAllowed(): array
413
406
];
414
407
}
415
408
416
- /**
417
- * @dataProvider provideSanitiseAttributesAllowed
418
- */
409
+ #[DataProvider('provideSanitiseAttributesAllowed ' )]
419
410
public function testSanitiseAttributesAllowed (string $ input , ?array $ removeAttributes , string $ expected ): void
420
411
{
421
412
$ sanitiser = new XssSanitiser ();
@@ -425,7 +416,7 @@ public function testSanitiseAttributesAllowed(string $input, ?array $removeAttri
425
416
$ this ->assertSame ($ expected , $ sanitiser ->sanitiseString ($ input ));
426
417
}
427
418
428
- public function provideSanitiseNoKeepInnerHtml (): array
419
+ public static function provideSanitiseNoKeepInnerHtml (): array
429
420
{
430
421
return [
431
422
'keeps inner html ' => [
@@ -451,9 +442,7 @@ public function provideSanitiseNoKeepInnerHtml(): array
451
442
];
452
443
}
453
444
454
- /**
455
- * @dataProvider provideSanitiseNoKeepInnerHtml
456
- */
445
+ #[DataProvider('provideSanitiseNoKeepInnerHtml ' )]
457
446
public function testSanitiseNoKeepInnerHtml (string $ input , bool $ keepInnerHtml , string $ expected ): void
458
447
{
459
448
$ sanitiser = new XssSanitiser ();
0 commit comments