Skip to content

Commit

Permalink
Merge branch '1' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Jul 28, 2023
2 parents da54033 + 437a915 commit e5e0532
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
48 changes: 45 additions & 3 deletions tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
'',
],
];
}
}
11 changes: 11 additions & 0 deletions tests/php/Models/LinkTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Binary file added tests/resources/600x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5e0532

Please sign in to comment.