Skip to content

Commit

Permalink
ENH Add versioning to Link
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 28, 2023
1 parent 7a16b8b commit b008bad
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

// Avoid creating global variables
call_user_func(function () {

});
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "silverstripe-vendormodule",
"require": {
"php": "^8.1",
"silverstripe/cms": "^5"
"silverstripe/cms": "^5",
"silverstripe/versioned": "^2"
},
"require-dev": {
"silverstripe/recipe-testing": "^3",
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 5 additions & 15 deletions tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b008bad

Please sign in to comment.