diff --git a/tests/php/Models/LinkTest.php b/tests/php/Models/LinkTest.php index 4d57907f..65b43113 100644 --- a/tests/php/Models/LinkTest.php +++ b/tests/php/Models/LinkTest.php @@ -3,8 +3,11 @@ namespace SilverStripe\LinkField\Tests\Models; use ReflectionException; +use SilverStripe\Assets\Dev\TestAssetStore; +use SilverStripe\Assets\Image; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Config\Collections\MutableConfigCollectionInterface; +use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; use SilverStripe\LinkField\Models\EmailLink; @@ -17,6 +20,7 @@ use SilverStripe\LinkField\Type\Type; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\ValidationException; +use SilverStripe\Versioned\Versioned; class LinkTest extends SapphireTest { @@ -25,6 +29,30 @@ class LinkTest extends SapphireTest */ protected static $fixture_file = 'LinkTest.yml'; + protected function setUp(): void + { + parent::setUp(); + + TestAssetStore::activate('ImageTest'); + + /** @var Image $image */ + $image = $this->objFromFixture(Image::class, 'image-1'); + $image->setFromLocalFile(Director::baseFolder() . '/tests/resources/600x400.png'); + $image->write(); + $image->publishSingle(); + + /** @var SiteTree $page */ + $page = $this->objFromFixture(SiteTree::class, 'page-1'); + $page->publishSingle(); + } + + protected function tearDown(): void + { + TestAssetStore::reset(); + + parent::tearDown(); + } + public function testLinkModel(): void { $model = $this->objFromFixture(Link::class, 'link-1'); @@ -214,10 +242,14 @@ public function linkTypeEnabledProvider(): array */ public function testGetUrl(string $identifier, string $class, string $expected): void { - /** @var Link $link */ - $link = $this->objFromFixture($class, $identifier); + 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'); + $this->assertSame($expected, $link->getURL(), 'We expect specific URL value'); + }); } public function linkUrlCasesDataProvider(): array @@ -283,6 +315,16 @@ public function linkUrlCasesDataProvider(): array PhoneLink::class, '', ], + 'file link / with image' => [ + 'file-link-with-image', + FileLink::class, + '/assets/ImageTest/600x400.png', + ], + 'file link / no image' => [ + 'file-link-no-image', + FileLink::class, + '', + ], ]; } } diff --git a/tests/php/Models/LinkTest.yml b/tests/php/Models/LinkTest.yml index f60135fd..7faac9d9 100644 --- a/tests/php/Models/LinkTest.yml +++ b/tests/php/Models/LinkTest.yml @@ -3,6 +3,10 @@ SilverStripe\CMS\Model\SiteTree: Title: 'Page1' URLSegment: 'page-1' +SilverStripe\Assets\Image: + image-1: + Title: 'Image1' + SilverStripe\LinkField\Models\Link: link-1: Title: 'Link1' @@ -53,3 +57,10 @@ SilverStripe\LinkField\Models\PhoneLink: Phone: '+64 4 978 7330' phone-link-no-phone: Title: 'PhoneLinkNoPhone' + +SilverStripe\LinkField\Models\FileLink: + file-link-with-image: + Title: 'FileLinkWithImage' + File: =>SilverStripe\Assets\Image.image-1 + file-link-no-image: + Title: 'FileLinkNoImage' diff --git a/tests/resources/600x400.png b/tests/resources/600x400.png new file mode 100644 index 00000000..4d4a4dc2 Binary files /dev/null and b/tests/resources/600x400.png differ