1
0
mirror of https://github.com/Intervention/image.git synced 2025-02-23 13:52:20 +01:00
intervention_image/tests/Drivers/Imagick/InputHandlerTest.php

126 lines
4.3 KiB
PHP
Raw Normal View History

2021-10-21 14:32:05 +02:00
<?php
namespace Intervention\Image\Tests\Drivers\Imagick;
2023-10-28 11:05:11 +02:00
use SplFileInfo;
use Intervention\Image\Colors\Rgb\Color as RgbColor;
2021-10-21 14:32:05 +02:00
use Intervention\Image\Drivers\Imagick\Image;
use Intervention\Image\Drivers\Imagick\InputHandler;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Tests\TestCase;
/**
* @requires extension imagick
2021-12-22 14:34:28 +01:00
* @covers \Intervention\Image\Drivers\Imagick\InputHandler
*/
2021-10-21 14:32:05 +02:00
class InputHandlerTest extends TestCase
{
public function testHandleEmptyString(): void
{
$handler = new InputHandler();
$this->expectException(DecoderException::class);
2023-10-15 10:39:15 +02:00
$handler->handle('');
2021-10-21 14:32:05 +02:00
}
public function testHandleBinaryImage(): void
{
$handler = new InputHandler();
$input = file_get_contents(__DIR__ . '/../../images/animation.gif');
$result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result);
}
2023-10-28 11:05:11 +02:00
public function testHandleSplFileInfo(): void
{
$handler = new InputHandler();
$input = new SplFileInfo(__DIR__ . '/../../images/test.jpg');
$result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result);
}
2021-10-21 14:32:05 +02:00
public function testHandleFilePathImage(): void
{
$handler = new InputHandler();
$input = __DIR__ . '/../../images/animation.gif';
$result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result);
}
public function testHandleBase64Image(): void
{
$handler = new InputHandler();
$input = base64_encode(file_get_contents(__DIR__ . '/../../images/animation.gif'));
$result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result);
}
public function testHandleDataUriImage(): void
{
$handler = new InputHandler();
$input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
$result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result);
}
2023-10-15 10:39:15 +02:00
public function testHandleHexColor(): void
2021-10-21 14:32:05 +02:00
{
$handler = new InputHandler();
2023-10-15 10:39:15 +02:00
$input = 'ccff33';
2021-10-21 14:32:05 +02:00
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-17 17:08:45 +02:00
$this->assertEquals([204, 255, 51, 255], $result->toArray());
2023-10-15 10:39:15 +02:00
$handler = new InputHandler();
$input = 'cf3';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-17 17:08:45 +02:00
$this->assertEquals([204, 255, 51, 255], $result->toArray());
2023-10-15 10:39:15 +02:00
$handler = new InputHandler();
$input = '#123456';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-17 17:08:45 +02:00
$this->assertEquals([18, 52, 86, 255], $result->toArray());
2023-10-15 10:39:15 +02:00
$handler = new InputHandler();
$input = '#333';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-17 17:08:45 +02:00
$this->assertEquals([51, 51, 51, 255], $result->toArray());
2023-10-15 10:39:15 +02:00
$handler = new InputHandler();
$input = '#3333';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-15 10:39:15 +02:00
$this->assertEquals([51, 51, 51, 51], $result->toArray());
$handler = new InputHandler();
$input = '#33333333';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-15 10:39:15 +02:00
$this->assertEquals([51, 51, 51, 51], $result->toArray());
}
public function testHandleRgbString(): void
{
$handler = new InputHandler();
$result = $handler->handle('rgb(10, 20, 30)');
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-17 17:08:45 +02:00
$this->assertEquals([10, 20, 30, 255], $result->toArray());
2023-10-15 10:39:15 +02:00
$handler = new InputHandler();
$result = $handler->handle('rgba(10, 20, 30, 1.0)');
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-15 10:39:15 +02:00
$this->assertEquals([10, 20, 30, 255], $result->toArray());
2021-10-21 14:32:05 +02:00
}
2023-10-20 15:58:35 +02:00
public function testHandleTransparent(): void
{
$handler = new InputHandler();
$input = 'transparent';
$result = $handler->handle($input);
$this->assertInstanceOf(RgbColor::class, $result);
2023-10-20 15:58:35 +02:00
$this->assertEquals([0, 0, 0, 0], $result->toArray());
}
2021-10-21 14:32:05 +02:00
}