Skip to content

Commit f5bf1a7

Browse files
committed
expand tests for AVIF image format, add missing testImageConvertPngToWebp function
1 parent 4a1fc1e commit f5bf1a7

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

tests/system/Images/ImageMagickHandlerTest.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,14 @@ public function testMoreText(): void
313313

314314
public function testImageCreation(): void
315315
{
316-
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
316+
foreach (['gif', 'jpeg', 'png', 'webp', 'avif'] as $type) {
317317
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
318318
$this->expectException(ImageException::class);
319-
$this->expectExceptionMessage('Your server does not support the GD function required to process this type of image.');
319+
$this->expectExceptionMessage('Your server does not support the GD function required to process a webp image.');
320+
}
321+
if ($type === 'avif' && ! in_array('AVIF', Imagick::queryFormats(), true)) {
322+
$this->expectException(ImageException::class);
323+
$this->expectExceptionMessage('Your server does not support the GD function required to process an avif image.');
320324
}
321325

322326
$this->handler->withFile($this->origin . 'ci-logo.' . $type);
@@ -328,10 +332,14 @@ public function testImageCreation(): void
328332

329333
public function testImageCopy(): void
330334
{
331-
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
335+
foreach (['gif', 'jpeg', 'png', 'webp', 'avif'] as $type) {
332336
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
333337
$this->expectException(ImageException::class);
334-
$this->expectExceptionMessage('Your server does not support the GD function required to process this type of image.');
338+
$this->expectExceptionMessage('Your server does not support the GD function required to process a webp image.');
339+
}
340+
if ($type === 'avif' && ! in_array('AVIF', Imagick::queryFormats(), true)) {
341+
$this->expectException(ImageException::class);
342+
$this->expectExceptionMessage('Your server does not support the GD function required to process an avif image.');
335343
}
336344

337345
$this->handler->withFile($this->origin . 'ci-logo.' . $type);
@@ -347,7 +355,7 @@ public function testImageCopy(): void
347355

348356
public function testImageCopyWithNoTargetAndMaxQuality(): void
349357
{
350-
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
358+
foreach (['gif', 'jpeg', 'png', 'webp', 'avif'] as $type) {
351359
$this->handler->withFile($this->origin . 'ci-logo.' . $type);
352360
$this->handler->save(null, 100);
353361
$this->assertFileExists($this->origin . 'ci-logo.' . $type);
@@ -361,10 +369,14 @@ public function testImageCopyWithNoTargetAndMaxQuality(): void
361369

362370
public function testImageCompressionGetResource(): void
363371
{
364-
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
372+
foreach (['gif', 'jpeg', 'png', 'webp', 'avif'] as $type) {
365373
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
366374
$this->expectException(ImageException::class);
367-
$this->expectExceptionMessage('Your server does not support the GD function required to process this type of image.');
375+
$this->expectExceptionMessage('Your server does not support the GD function required to process a webp image.');
376+
}
377+
if ($type === 'avif' && ! in_array('AVIF', Imagick::queryFormats(), true)) {
378+
$this->expectException(ImageException::class);
379+
$this->expectExceptionMessage('Your server does not support the GD function required to process an avif image.');
368380
}
369381

370382
$this->handler->withFile($this->origin . 'ci-logo.' . $type);
@@ -381,10 +393,14 @@ public function testImageCompressionGetResource(): void
381393

382394
public function testImageCompressionWithResource(): void
383395
{
384-
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
396+
foreach (['gif', 'jpeg', 'png', 'webp', 'avif'] as $type) {
385397
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
386398
$this->expectException(ImageException::class);
387-
$this->expectExceptionMessage('Your server does not support the GD function required to process this type of image.');
399+
$this->expectExceptionMessage('Your server does not support the GD function required to process a webp image.');
400+
}
401+
if ($type === 'avif' && ! in_array('AVIF', Imagick::queryFormats(), true)) {
402+
$this->expectException(ImageException::class);
403+
$this->expectExceptionMessage('Your server does not support the GD function required to process an avif image.');
388404
}
389405

390406
$this->handler->withFile($this->origin . 'ci-logo.' . $type)
@@ -408,6 +424,22 @@ public function testImageConvert(): void
408424
$this->assertSame(IMAGETYPE_PNG, exif_imagetype($this->root . 'ci-logo.png'));
409425
}
410426

427+
public function testImageConvertPngToWebp(): void
428+
{
429+
$this->handler->withFile($this->origin . 'ci-logo.png');
430+
$this->handler->convert(IMAGETYPE_WEBP);
431+
$this->handler->save($this->root . 'ci-logo.webp');
432+
$this->assertSame(IMAGETYPE_WEBP, exif_imagetype($this->root . 'ci-logo.webp'));
433+
}
434+
435+
public function testImageConvertPngToAvif(): void
436+
{
437+
$this->handler->withFile($this->origin . 'ci-logo.png');
438+
$this->handler->convert(IMAGETYPE_AVIF);
439+
$this->handler->save($this->root . 'ci-logo.avif');
440+
$this->assertSame(IMAGETYPE_AVIF, exif_imagetype($this->root . 'ci-logo.avif'));
441+
}
442+
411443
public function testImageReorientLandscape(): void
412444
{
413445
for ($i = 0; $i <= 8; $i++) {

0 commit comments

Comments
 (0)