Skip to content

Commit

Permalink
Merge branch '1.13' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 28, 2023
2 parents 9cba90a + fb2e4b6 commit b90f25f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
17 changes: 6 additions & 11 deletions src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,23 +1072,15 @@ protected function castDimension($value, $dimension)
*/
private function copyImageBackend(): AssetContainer
{
// Store result in new DBFile instance
/** @var DBFile $file */
$file = DBField::create_field(
'DBFile',
[
'Filename' => $this->getFilename(),
'Hash' => $this->getHash(),
'Variant' => $this->getVariant()
]
);
$file = clone $this;

$backend = $this->getImageBackend();
if ($backend) {
$file->setImageBackend($backend);
}

return $file->setOriginal($this);
$file->File->setOriginal($this);
return $file;
}

/**
Expand All @@ -1107,6 +1099,9 @@ public function setAttribute($name, $value)
[$name => $value]
));

// If this file has already been rendered then AttributesHTML will be cached, so we have to clear the cache
$file->objCacheClear();

return $file;
}

Expand Down
28 changes: 24 additions & 4 deletions tests/php/ImageManipulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

namespace SilverStripe\Assets\Tests;

use InvalidArgumentException;
use Prophecy\Prophecy\ObjectProphecy;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Image_Backend;
use SilverStripe\Assets\InterventionBackend;
use SilverStripe\Assets\Storage\AssetContainer;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Assets\Tests\ImageManipulationTest\LazyLoadAccessorExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\SSViewer;
Expand Down Expand Up @@ -363,6 +360,29 @@ public function testBadLazyLoad($val)
);
}

public function testLazyLoadIsAccessibleInExtensions()
{
Image::add_extension(LazyLoadAccessorExtension::class);

/** @var Image $origin */
$image = $this->objFromFixture(Image::class, 'imageWithTitle');

$this->assertTrue(
$image->LazyLoad(true)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);
$this->assertFalse(
$image->LazyLoad(false)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);
$this->assertTrue(
$image->LazyLoad(false)->LazyLoad(true)->getLazyLoadValueViaExtension(),
'Incorrect LazyLoad value reported by extension'
);

Image::remove_extension(LazyLoadAccessorExtension::class);
}

public function renderProvider()
{
$alt = 'This is a image Title';
Expand Down
13 changes: 13 additions & 0 deletions tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace SilverStripe\Assets\Tests\ImageManipulationTest;

use SilverStripe\Core\Extension;

class LazyLoadAccessorExtension extends Extension
{
public function getLazyLoadValueViaExtension(): bool
{
return $this->getOwner()->IsLazyLoaded();
}
}

0 comments on commit b90f25f

Please sign in to comment.