Skip to content

Commit e4b8b96

Browse files
Merge branch '3.2' into 3
2 parents d912743 + 76c633c commit e4b8b96

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function PreviewLink($action = null)
110110

111111
// Temporarily disallow animated manipulations if necessary
112112
$backend = $this->getImageBackend();
113-
$origAllowAnimation = $backend->getAllowsAnimationInManipulations();
113+
$origAllowAnimation = $backend?->getAllowsAnimationInManipulations();
114114
if ($origAllowAnimation && !static::config()->get('allow_animated_preview')) {
115115
$backend->setAllowsAnimationInManipulations(false);
116116
}

tests/php/FileTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,4 +1273,34 @@ public function testMoveFileRenamesDuplicateFilename()
12731273
$this->assertTrue(strpos($file1->getFilename(), 'FileTest-v2.pdf') !== false);
12741274
$this->assertTrue(strpos($file2->getFilename(), 'FileTest.pdf') !== false);
12751275
}
1276+
1277+
public static function providePreviewLink(): array
1278+
{
1279+
return [
1280+
[true],
1281+
[false],
1282+
];
1283+
}
1284+
1285+
#[DataProvider('providePreviewLink')]
1286+
public function testPreviewLink(bool $fileExists): void
1287+
{
1288+
$image = Image::create([
1289+
'Name' => 'animated.gif',
1290+
'FileFilename' => 'animated.gif',
1291+
]);
1292+
$image->write();
1293+
if ($fileExists) {
1294+
$sourcePath = __DIR__ . '/ImageTest/' . $image->Name;
1295+
$image->setFromLocalFile($sourcePath, $image->Filename);
1296+
}
1297+
$image->publishSingle();
1298+
1299+
$previewLink = $image->PreviewLink();
1300+
if ($fileExists) {
1301+
$this->assertStringEndsWith('/assets/FileTest/animated__FitMaxWzkzMCwzMzZd.gif', $previewLink);
1302+
} else {
1303+
$this->assertStringContainsString('/_resources/vendor/silverstripe/framework/client/images/app_icons/generic_92.png', $previewLink);
1304+
}
1305+
}
12761306
}

0 commit comments

Comments
 (0)