From 437a9154bea6d15eb5a17d1bf394b549bff6c9f9 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 28 Jul 2023 13:06:53 +1200 Subject: [PATCH] MISC: File link test. --- tests/php/Models/LinkTest.php | 48 +++++++++++++++++++++++++++++++--- tests/php/Models/LinkTest.yml | 11 ++++++++ tests/resources/600x400.png | Bin 0 -> 1780 bytes 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tests/resources/600x400.png 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 0000000000000000000000000000000000000000..4d4a4dc23b73f9d5bc5225d9fe43a847bfb8a12b GIT binary patch literal 1780 zcmb_c`&SYM8)j?Om*!lSQfhj-XnDalZ=1JRdB2sSk|64e$WKu*`S3!i`?BVyWr>%> zR4R4G038xIG2y7G6DQ^c@Q!|p7Rpi+5fS+Cf7pA@d){-N_q@+}p67@6m#{1T270D? z006)sFu(@_0DK+|0DSi3i+wueN3(qt-7pIaiS*S?tyXJkX&E0MP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