From 66103e992c854b76780dd855a77cc3ea588bb7a6 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 27 Sep 2023 11:54:05 +1300 Subject: [PATCH] ENH Add versioning to Link --- README.md | 12 ++++++++++++ _config.php | 1 - src/Models/Link.php | 5 +++++ tests/php/Models/LinkTest.php | 20 +++++--------------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 90fa633f..134bc3d3 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,18 @@ class Page extends SiteTree 'HasOneLink' => Link::class, ]; + private static array $owns = [ + 'HasOneLink' + ]; + + private static array $cascade_deletess = [ + 'HasOneLink' + ]; + + private static array $cascade_duplicatess = [ + 'HasOneLink' + ]; + public function getCMSFields() { $fields = parent::getCMSFields(); diff --git a/_config.php b/_config.php index 9e519d4a..71c7914c 100644 --- a/_config.php +++ b/_config.php @@ -5,5 +5,4 @@ // Avoid creating global variables call_user_func(function () { - }); diff --git a/src/Models/Link.php b/src/Models/Link.php index 87d2de0f..13088bdc 100644 --- a/src/Models/Link.php +++ b/src/Models/Link.php @@ -16,6 +16,7 @@ use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\View\Requirements; +use SilverStripe\Versioned\Versioned; /** * A Link Data Object. This class should be a subclass, and you should never directly interact with a plain Link @@ -32,6 +33,10 @@ class Link extends DataObject implements JsonData, Type 'Title' => 'Varchar', 'OpenInNew' => 'Boolean', ]; + + private static array $extensions = [ + Versioned::class, + ]; /** * In-memory only property used to change link type diff --git a/tests/php/Models/LinkTest.php b/tests/php/Models/LinkTest.php index 396f676e..0119bf33 100644 --- a/tests/php/Models/LinkTest.php +++ b/tests/php/Models/LinkTest.php @@ -37,13 +37,8 @@ protected function setUp(): void /** @var Image $image */ $image = $this->objFromFixture(Image::class, 'image-1'); - $image->setFromLocalFile(Director::baseFolder() . '/tests/resources/600x400.png'); + $image->setFromLocalFile(dirname(dirname(dirname(__FILE__))) . '/resources/600x400.png'); $image->write(); - $image->publishSingle(); - - /** @var SiteTree $page */ - $page = $this->objFromFixture(SiteTree::class, 'page-1'); - $page->publishSingle(); } protected function tearDown(): void @@ -245,14 +240,9 @@ public function linkTypeEnabledProvider(): array */ public function testGetUrl(string $identifier, string $class, string $expected): void { - Versioned::withVersionedMode(function () use ($identifier, $class, $expected): void { - Versioned::set_stage(Versioned::LIVE); - - /** @var Link $link */ - $link = $this->objFromFixture($class, $identifier); - - $this->assertSame($expected, $link->getURL(), 'We expect specific URL value'); - }); + /** @var Link $link */ + $link = $this->objFromFixture($class, $identifier); + $this->assertSame($expected, $link->getURL(), 'We expect specific URL value'); } public function linkUrlCasesDataProvider(): array @@ -321,7 +311,7 @@ public function linkUrlCasesDataProvider(): array 'file link / with image' => [ 'file-link-with-image', FileLink::class, - '/assets/ImageTest/600x400.png', + '/assets/8cf6c65fa7/600x400.png', ], 'file link / no image' => [ 'file-link-no-image',