Skip to content

Commit b842972

Browse files
Merge pull request #11557 from creative-commoners/pulls/6.0/static-providers
MNT Make data providers static
2 parents 9b61628 + c307ecc commit b842972

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

tests/php/Core/XssSanitiserTest.php

+11-22
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
use SilverStripe\Core\XssSanitiser;
77
use SilverStripe\Dev\SapphireTest;
88
use SilverStripe\View\Parsers\HTMLValue;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class XssSanitiserTest extends SapphireTest
1112
{
1213
protected $usesDatabase = false;
1314

14-
public function provideSanitise(): array
15+
public static function provideSanitise(): array
1516
{
1617
// Most of these scenarios are inspired by Symfony's HtmlSanitizerAllTest scenarios
1718
return [
@@ -305,18 +306,14 @@ public function provideSanitise(): array
305306
];
306307
}
307308

308-
/**
309-
* @dataProvider provideSanitise
310-
*/
309+
#[DataProvider('provideSanitise')]
311310
public function testSanitiseString(string $input, string $expected): void
312311
{
313312
$sanitiser = new XssSanitiser();
314313
$this->assertSame($expected, $sanitiser->sanitiseString($input));
315314
}
316315

317-
/**
318-
* @dataProvider provideSanitise
319-
*/
316+
#[DataProvider('provideSanitise')]
320317
public function testSanitiseHtmlValue(string $input, string $expected): void
321318
{
322319
$sanitiser = new XssSanitiser();
@@ -325,9 +322,7 @@ public function testSanitiseHtmlValue(string $input, string $expected): void
325322
$this->assertSame($expected, $htmlValue->getContent());
326323
}
327324

328-
/**
329-
* @dataProvider provideSanitise
330-
*/
325+
#[DataProvider('provideSanitise')]
331326
public function testSanitiseElement(string $input, string $expected): void
332327
{
333328
$sanitiser = new XssSanitiser();
@@ -341,7 +336,7 @@ public function testSanitiseElement(string $input, string $expected): void
341336
$this->assertSame($expected, $htmlValue->getContent());
342337
}
343338

344-
public function provideSanitiseElementsAllowed(): array
339+
public static function provideSanitiseElementsAllowed(): array
345340
{
346341
return [
347342
'disallow these by default' => [
@@ -362,9 +357,7 @@ public function provideSanitiseElementsAllowed(): array
362357
];
363358
}
364359

365-
/**
366-
* @dataProvider provideSanitiseElementsAllowed
367-
*/
360+
#[DataProvider('provideSanitiseElementsAllowed')]
368361
public function testSanitiseElementsAllowed(string $input, ?array $removeElements, string $expected): void
369362
{
370363
$sanitiser = new XssSanitiser();
@@ -374,7 +367,7 @@ public function testSanitiseElementsAllowed(string $input, ?array $removeElement
374367
$this->assertSame($expected, $sanitiser->sanitiseString($input));
375368
}
376369

377-
public function provideSanitiseAttributesAllowed(): array
370+
public static function provideSanitiseAttributesAllowed(): array
378371
{
379372
return [
380373
'disallow these by default' => [
@@ -413,9 +406,7 @@ public function provideSanitiseAttributesAllowed(): array
413406
];
414407
}
415408

416-
/**
417-
* @dataProvider provideSanitiseAttributesAllowed
418-
*/
409+
#[DataProvider('provideSanitiseAttributesAllowed')]
419410
public function testSanitiseAttributesAllowed(string $input, ?array $removeAttributes, string $expected): void
420411
{
421412
$sanitiser = new XssSanitiser();
@@ -425,7 +416,7 @@ public function testSanitiseAttributesAllowed(string $input, ?array $removeAttri
425416
$this->assertSame($expected, $sanitiser->sanitiseString($input));
426417
}
427418

428-
public function provideSanitiseNoKeepInnerHtml(): array
419+
public static function provideSanitiseNoKeepInnerHtml(): array
429420
{
430421
return [
431422
'keeps inner html' => [
@@ -451,9 +442,7 @@ public function provideSanitiseNoKeepInnerHtml(): array
451442
];
452443
}
453444

454-
/**
455-
* @dataProvider provideSanitiseNoKeepInnerHtml
456-
*/
445+
#[DataProvider('provideSanitiseNoKeepInnerHtml')]
457446
public function testSanitiseNoKeepInnerHtml(string $input, bool $keepInnerHtml, string $expected): void
458447
{
459448
$sanitiser = new XssSanitiser();

tests/php/Forms/FormMessageTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
use SilverStripe\Core\XssSanitiser;
77
use SilverStripe\Dev\SapphireTest;
88
use SilverStripe\Forms\Tests\FormMessageTest\TestFormMessage;
9-
use SilverStripe\ORM\ValidationResult;
9+
use SilverStripe\Core\Validation\ValidationResult;
10+
use PHPUnit\Framework\Attributes\DataProvider;
1011

1112
class FormMessageTest extends SapphireTest
1213
{
1314
protected $usesDatabase = false;
1415

15-
public function provideGetMessage(): array
16+
public static function provideGetMessage(): array
1617
{
1718
return [
1819
'empty HTML' => [
@@ -69,8 +70,8 @@ public function provideGetMessage(): array
6970
/**
7071
* Test that getMessage() generally works and calls the sanitiser as appropriate.
7172
* Note we don't actually test the sanitisation here, as that is handled by the sanitiser's unit tests.
72-
* @dataProvider provideGetMessage
7373
*/
74+
#[DataProvider('provideGetMessage')]
7475
public function testGetMessage(string $message, string $type, string $casting, string $expected): void
7576
{
7677
$mockSanitiserClass = get_class(new class extends XssSanitiser {

tests/php/View/Shortcodes/EmbedShortcodeProviderTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use SilverStripe\View\Embed\EmbedContainer;
1313
use stdClass;
1414
use RuntimeException;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516

1617
class EmbedShortcodeProviderTest extends EmbedUnitTest
1718
{
@@ -222,7 +223,7 @@ public function testOnlyWhitelistedAttributesAllowed()
222223
);
223224
}
224225

225-
public function provideSandboxHtml(): array
226+
public static function provideSandboxHtml(): array
226227
{
227228
return [
228229
'normal' => [
@@ -365,9 +366,7 @@ public function provideSandboxHtml(): array
365366
];
366367
}
367368

368-
/**
369-
* @dataProvider provideSandboxHtml
370-
*/
369+
#[DataProvider('provideSandboxHtml')]
371370
public function testSandboxHtml(
372371
string $url,
373372
array $excluded,

0 commit comments

Comments
 (0)