1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 20:51:20 +02:00

Add image tests

This commit is contained in:
Oliver Vogel
2024-01-15 12:10:49 +01:00
parent 7e42085afd
commit 0ed895c5dc
2 changed files with 111 additions and 7 deletions

View File

@@ -4,16 +4,19 @@ namespace Intervention\Image\Tests\Drivers\Gd;
use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Analyzers\WidthAnalyzer;
use Intervention\Image\Collection; use Intervention\Image\Collection;
use Intervention\Image\Colors\Hsl\Colorspace;
use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Drivers\Gd\Core; use Intervention\Image\Drivers\Gd\Core;
use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\EncodedImage; use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\Exceptions\EncoderException;
use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Image; use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\ResolutionInterface;
use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Modifiers\GreyscaleModifier;
@@ -87,9 +90,28 @@ class ImageTest extends TestCase
$this->assertTrue($this->image->isAnimated()); $this->assertTrue($this->image->isAnimated());
} }
public function testLoops(): void public function testSetGetLoops(): void
{ {
$this->assertEquals(0, $this->image->loops()); $this->assertEquals(0, $this->image->loops());
$result = $this->image->setLoops(10);
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(10, $this->image->loops());
}
public function testRemoveAnimation(): void
{
$this->assertTrue($this->image->isAnimated());
$result = $this->image->removeAnimation();
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertFalse($this->image->isAnimated());
}
public function testSliceAnimation(): void
{
$this->assertEquals(2, $this->image->count());
$result = $this->image->sliceAnimation(0, 1);
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(1, $this->image->count());
} }
public function testExif(): void public function testExif(): void
@@ -166,6 +188,22 @@ class ImageTest extends TestCase
unlink($path); unlink($path);
} }
public function testSaveFallback(): void
{
$path = __DIR__ . '/tmp.unknown';
$result = $this->readTestImage('blue.gif')->save($path);
$this->assertInstanceOf(Image::class, $result);
$this->assertFileExists($path);
$this->assertMediaType('image/gif', file_get_contents($path));
unlink($path);
}
public function testSaveUndeterminedPath(): void
{
$this->expectException(EncoderException::class);
$this->createTestImage(2, 3)->save();
}
public function testWidthHeightSize(): void public function testWidthHeightSize(): void
{ {
$this->assertEquals(3, $this->image->width()); $this->assertEquals(3, $this->image->width());
@@ -178,9 +216,23 @@ class ImageTest extends TestCase
$this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace());
} }
public function testResolution(): void public function testSetColorspace(): void
{ {
$this->assertInstanceOf(ResolutionInterface::class, $this->image->resolution()); $this->expectException(NotSupportedException::class);
$this->image->setColorspace(Colorspace::class);
}
public function testSetGetResolution(): void
{
$resolution = $this->image->resolution();
$this->assertInstanceOf(ResolutionInterface::class, $resolution);
$this->assertEquals(96, $resolution->x());
$this->assertEquals(96, $resolution->y());
$result = $this->image->setResolution(300, 300);
$resolution = $this->image->resolution();
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(300, $resolution->x());
$this->assertEquals(300, $resolution->y());
} }
public function testPickColor(): void public function testPickColor(): void

View File

@@ -5,16 +5,21 @@ namespace Intervention\Image\Tests\Drivers\Imagick;
use Imagick; use Imagick;
use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Analyzers\WidthAnalyzer;
use Intervention\Image\Collection; use Intervention\Image\Collection;
use Intervention\Image\Colors\Hsl\Colorspace as HslColorspace;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Drivers\Imagick\Core; use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Drivers\Imagick\Frame; use Intervention\Image\Drivers\Imagick\Frame;
use Intervention\Image\EncodedImage; use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\EncoderException;
use Intervention\Image\Image; use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\ResolutionInterface;
use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Modifiers\GreyscaleModifier;
@@ -86,9 +91,28 @@ class ImageTest extends TestCase
$this->assertTrue($this->image->isAnimated()); $this->assertTrue($this->image->isAnimated());
} }
public function testLoops(): void public function testSetGetLoops(): void
{ {
$this->assertEquals(3, $this->image->loops()); $this->assertEquals(3, $this->image->loops());
$result = $this->image->setLoops(10);
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(10, $this->image->loops());
}
public function testRemoveAnimation(): void
{
$this->assertTrue($this->image->isAnimated());
$result = $this->image->removeAnimation();
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertFalse($this->image->isAnimated());
}
public function testSliceAnimation(): void
{
$this->assertEquals(8, $this->image->count());
$result = $this->image->sliceAnimation(0, 2);
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(2, $this->image->count());
} }
public function testExif(): void public function testExif(): void
@@ -165,6 +189,22 @@ class ImageTest extends TestCase
unlink($path); unlink($path);
} }
public function testSaveFallback(): void
{
$path = __DIR__ . '/tmp.unknown';
$result = $this->readTestImage('blue.gif')->save($path);
$this->assertInstanceOf(Image::class, $result);
$this->assertFileExists($path);
$this->assertMediaType('image/gif', file_get_contents($path));
unlink($path);
}
public function testSaveUndeterminedPath(): void
{
$this->expectException(EncoderException::class);
$this->createTestImage(2, 3)->save();
}
public function testWidthHeightSize(): void public function testWidthHeightSize(): void
{ {
$this->assertEquals(20, $this->image->width()); $this->assertEquals(20, $this->image->width());
@@ -172,14 +212,26 @@ class ImageTest extends TestCase
$this->assertInstanceOf(SizeInterface::class, $this->image->size()); $this->assertInstanceOf(SizeInterface::class, $this->image->size());
} }
public function testColorspace(): void public function testSetGetColorspace(): void
{ {
$this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace());
$this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace());
$result = $this->image->setColorspace(CmykColorspace::class);
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertInstanceOf(CmykColorspace::class, $this->image->colorspace());
} }
public function testResolution(): void public function testSetGetResolution(): void
{ {
$this->assertInstanceOf(ResolutionInterface::class, $this->image->resolution()); $resolution = $this->image->resolution();
$this->assertInstanceOf(ResolutionInterface::class, $resolution);
$this->assertEquals(0, $resolution->x());
$this->assertEquals(0, $resolution->y());
$result = $this->image->setResolution(300, 300);
$resolution = $this->image->resolution();
$this->assertInstanceOf(ImageInterface::class, $result);
$this->assertEquals(300, $resolution->x());
$this->assertEquals(300, $resolution->y());
} }
public function testPickColor(): void public function testPickColor(): void