Skip to content

Commit

Permalink
DEP Use PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 9, 2024
1 parent 7eb74af commit 3c63409
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 78 deletions.
35 changes: 12 additions & 23 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\VersionedAdmin\Forms\HistoryViewerField;
use PHPUnit\Framework\Attributes\DataProvider;

class BaseElementTest extends FunctionalTest
{
Expand Down Expand Up @@ -275,7 +276,7 @@ public function testUpdateContentForSearchIndex()
ElementContent::remove_extension(TestContentForSearchIndexExtension::class);
}

public function getElementAnchorDataProvider(): array
public static function getElementAnchorDataProvider(): array
{
return [
[
Expand All @@ -296,9 +297,7 @@ public function getElementAnchorDataProvider(): array
];
}

/**
* @dataProvider getElementAnchorDataProvider
*/
#[DataProvider('getElementAnchorDataProvider')]
public function testGetAnchorsInContent(string $elementClass, string $elementName, array $expectedAnchors): void
{
$element = $this->objFromFixture($elementClass, $elementName);
Expand All @@ -307,7 +306,7 @@ public function testGetAnchorsInContent(string $elementClass, string $elementNam
$this->assertSame($expectedAnchors, array_values($element->getAnchorsInContent()));
}

public function getElementCMSLinkDataProvider()
public static function getElementCMSLinkDataProvider()
{
return [
// Element in DataObject with $directLink === true
Expand Down Expand Up @@ -351,9 +350,7 @@ public function getElementCMSLinkDataProvider()
];
}

/**
* @dataProvider getElementCMSLinkDataProvider
*/
#[DataProvider('getElementCMSLinkDataProvider')]
public function testGetCMSEditLink(string $class, string $element, ?string $link, bool $directLink = false)
{
$object = $this->objFromFixture($class, $element);
Expand All @@ -366,7 +363,7 @@ public function testGetCMSEditLink(string $class, string $element, ?string $link
}
}

public function canDeleteProvider()
public static function canDeleteProvider()
{
return [
// Element on Page
Expand All @@ -384,9 +381,7 @@ public function canDeleteProvider()
];
}

/**
* @dataProvider canDeleteProvider
*/
#[DataProvider('canDeleteProvider')]
public function testCanDelete(
string $class,
string $element,
Expand All @@ -400,7 +395,7 @@ public function testCanDelete(
$this->assertTrue($canDelete);
}

public function linksProvider()
public static function linksProvider()
{
return [
// Element on Page
Expand All @@ -418,18 +413,14 @@ public function linksProvider()
];
}

/**
* @dataProvider linksProvider
*/
#[DataProvider('linksProvider')]
public function testLinkWithDataObject(string $class, string $element, ?string $link)
{
$object = $this->objFromFixture($class, $element);
$this->assertEquals($link, $object->Link());
}

/**
* @dataProvider linksProvider
*/
#[DataProvider('linksProvider')]
public function testAbsoluteLink(string $class, string $element, ?string $link)
{
$link = $link ? Director::absoluteURL($link) : $link;
Expand All @@ -438,7 +429,7 @@ public function testAbsoluteLink(string $class, string $element, ?string $link)
$this->assertEquals($link, $absoluteLink);
}

public function previewLinksProvider()
public static function previewLinksProvider()
{
return [
// Element on Page
Expand Down Expand Up @@ -474,9 +465,7 @@ public function previewLinksProvider()
];
}

/**
* @dataProvider previewLinksProvider
*/
#[DataProvider('previewLinksProvider')]
public function testPreviewLink(string $class, string $elementIdentifier, ?string $link)
{
/** @var BaseElement $element */
Expand Down
11 changes: 5 additions & 6 deletions tests/Controllers/ElementSiteTreeFilterSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\ORM\DataObjectSchema;
use DNADesign\Elemental\Models\ElementContent;
use DNADesign\Elemental\Tests\Src\TestElementContentExtension;
use PHPUnit\Framework\Attributes\DataProvider;

class ElementSiteTreeFilterSearchTest extends SapphireTest
{
Expand All @@ -34,8 +35,8 @@ class ElementSiteTreeFilterSearchTest extends SapphireTest
/**
* @param string $searchTerm
* @param array $expected
* @dataProvider searchProvider
*/
#[DataProvider('searchProvider')]
public function testElementalPageDataMatchesInCmsSearch($searchTerm, $expected)
{
$filter = CMSSiteTreeFilter_Search::create(['Term' => $searchTerm]);
Expand All @@ -47,7 +48,7 @@ public function testElementalPageDataMatchesInCmsSearch($searchTerm, $expected)
/**
* @return array[]
*/
public function searchProvider()
public static function searchProvider()
{
return [
'Nested block data' => ['specifically', [
Expand All @@ -63,9 +64,7 @@ public function searchProvider()
];
}

/**
* @dataProvider provideApplyDefaultFilters
*/
#[DataProvider('provideApplyDefaultFilters')]
public function testApplyDefaultFilters(bool $renderElements, string $term, array $expected): void
{
// Set protected method visibility - applyDefaultFilters() is essentially an
Expand All @@ -78,7 +77,7 @@ public function testApplyDefaultFilters(bool $renderElements, string $term, arra
$this->assertSame($expected, $ret->column('Title'));
}

public function provideApplyDefaultFilters(): array
public static function provideApplyDefaultFilters(): array
{

return [
Expand Down
61 changes: 21 additions & 40 deletions tests/Controllers/ElementalAreaControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DNADesign\Elemental\Tests\Blocks\TestElementContent;
use DNADesign\Elemental\Tests\Blocks\TestElementalArea;
use Exception;
use PHPUnit\Framework\Attributes\DataProvider;

class ElementalAreaControllerTest extends FunctionalTest
{
Expand Down Expand Up @@ -40,7 +41,7 @@ protected function tearDown(): void
}
}

public function provideElementFormGetSchema(): array
public static function provideElementFormGetSchema(): array
{
// There specifically isn't an 'invalid / missing' record test here with $idType, as existing behaviour
// is to return a 200 with a basically empty schema response.
Expand All @@ -57,9 +58,7 @@ public function provideElementFormGetSchema(): array
];
}

/**
* @dataProvider provideElementFormGetSchema
*/
#[DataProvider('provideElementFormGetSchema')]
public function testElementFormGetSchema(
string $fail,
int $expectedCode,
Expand Down Expand Up @@ -89,7 +88,7 @@ public function testElementFormGetSchema(
$this->assertFalse(array_key_exists('errors', $formSchema));
}

public function provideElementFormPost(): array
public static function provideElementFormPost(): array
{
return [
'Valid update existing record' => [
Expand Down Expand Up @@ -149,9 +148,7 @@ public function provideElementFormPost(): array
];
}

/**
* @dataProvider provideElementFormPost
*/
#[DataProvider('provideElementFormPost')]
public function testElementFormPost(string $idType, string $dataType, string $fail, int $expectedCode): void
{
TestElementContent::$fail = $fail;
Expand Down Expand Up @@ -232,7 +229,7 @@ public function testElementFormPost(string $idType, string $dataType, string $fa
}
}

public function provideElementFormReadonly(): array
public static function provideElementFormReadonly(): array
{
return [
'Can edit' => [
Expand All @@ -246,9 +243,7 @@ public function provideElementFormReadonly(): array
];
}

/**
* @dataProvider provideElementFormReadonly
*/
#[DataProvider('provideElementFormReadonly')]
public function testElementFormReadonly(string $fail, bool $expected): void
{
TestElementContent::$fail = $fail;
Expand All @@ -262,7 +257,7 @@ public function testElementFormReadonly(string $fail, bool $expected): void
$this->assertSame($expected, $actual);
}

public function provideApiDelete(): array
public static function provideApiDelete(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -303,9 +298,7 @@ public function provideApiDelete(): array
];
}

/**
* @dataProvider provideApiDelete
*/
#[DataProvider('provideApiDelete')]
public function testApiDelete(
string $idType,
string $fail,
Expand All @@ -330,7 +323,7 @@ public function testApiDelete(
}
}

public function provideApiCreate(): array
public static function provideApiCreate(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -386,9 +379,7 @@ public function provideApiCreate(): array
];
}

/**
* @dataProvider provideApiCreate
*/
#[DataProvider('provideApiCreate')]
public function testApiCreate(
string $fail,
?int $insertAfterElementID,
Expand Down Expand Up @@ -449,7 +440,7 @@ public function testApiCreate(
$this->assertSame($expected, $map);
}

public function provideApiDuplicate(): array
public static function provideApiDuplicate(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -500,9 +491,7 @@ public function provideApiDuplicate(): array
];
}

/**
* @dataProvider provideApiDuplicate
*/
#[DataProvider('provideApiDuplicate')]
public function testApiDuplicate(
string $idType,
string $fail,
Expand Down Expand Up @@ -547,7 +536,7 @@ public function testApiDuplicate(
}
}

public function provideApiPublish(): array
public static function provideApiPublish(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -588,9 +577,7 @@ public function provideApiPublish(): array
];
}

/**
* @dataProvider provideApiPublish
*/
#[DataProvider('provideApiPublish')]
public function testApiPublish(
string $idType,
string $fail,
Expand Down Expand Up @@ -627,7 +614,7 @@ public function testApiPublish(
}
}

public function provideApiRead(): array
public static function provideApiRead(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -668,9 +655,7 @@ public function provideApiRead(): array
];
}

/**
* @dataProvider provideApiRead
*/
#[DataProvider('provideApiRead')]
public function testApiRead(
string $idType,
string $fail,
Expand Down Expand Up @@ -762,7 +747,7 @@ public function testApiRead(
}
}

public function provideApiSort(): array
public static function provideApiSort(): array
{
return [
'Valid move from first' => [
Expand Down Expand Up @@ -816,9 +801,7 @@ public function provideApiSort(): array
];
}

/**
* @dataProvider provideApiSort
*/
#[DataProvider('provideApiSort')]
public function testApiSort(
string $idType,
string $fail,
Expand Down Expand Up @@ -866,7 +849,7 @@ public function testApiSort(
$this->assertSame($expected, $map);
}

public function provideApiUnpublish(): array
public static function provideApiUnpublish(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -907,9 +890,7 @@ public function provideApiUnpublish(): array
];
}

/**
* @dataProvider provideApiUnpublish
*/
#[DataProvider('provideApiUnpublish')]
public function testApiUnpublish(
string $idType,
string $fail,
Expand Down
Loading

0 comments on commit 3c63409

Please sign in to comment.