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 10, 2024
1 parent 7eb74af commit 8621539
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 88 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
31 changes: 15 additions & 16 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,57 +77,57 @@ public function testApplyDefaultFilters(bool $renderElements, string $term, arra
$this->assertSame($expected, $ret->column('Title'));
}

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

return [
'render_elements true - text search' => [
'render_elements' => true,
'renderElements' => true,
'term' => 'This content is rendered',
'expected' => ['Content blocks page']
],
'render_elements true - unrendered search' => [
'render_elements' => true,
'renderElements' => true,
'term' => 'This field is unrendered',
'expected' => []
],
'render_elements true - extended search' => [
'render_elements' => true,
'renderElements' => true,
'term' => 'This content is from an extension hook',
'expected' => []
],
'render_elements true - int search' => [
'render_elements' => true,
'renderElements' => true,
'term' => '456',
'expected' => []
],
'render_elements true - enum search' => [
'render_elements' => true,
'renderElements' => true,
'term' => 'Sunny',
'expected' => []
],
'render_elements false - text search' => [
'render_elements' => false,
'renderElements' => false,
'term' => 'This content is rendered',
'expected' => ['Content blocks page']
],
'render_elements false - unrendered search' => [
'render_elements' => false,
'renderElements' => false,
'term' => 'This field is unrendered',
'expected' => ['Content blocks page']
],
'render_elements false - extended search' => [
'render_elements' => false,
'renderElements' => false,
'term' => 'This content is from an extension hook',
'expected' => ['Content blocks page']
],
'render_elements false - int search' => [
'render_elements' => false,
'renderElements' => false,
'term' => '456',
'expected' => []
],
'render_elements false - enum search' => [
'render_elements' => false,
'renderElements' => false,
'term' => 'Sunny',
'expected' => []
],
Expand Down
Loading

0 comments on commit 8621539

Please sign in to comment.