1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

EncodedImage test

This commit is contained in:
Oliver Vogel
2021-10-30 17:47:52 +00:00
parent 8c2766bcba
commit e9a3e4a034
2 changed files with 38 additions and 1 deletions

View File

@@ -25,7 +25,7 @@ class EncodedImage
}
}
public function toDataUrl(): string
public function toDataUri(): string
{
return sprintf('data:%s;base64,%s', $this->mimetype, base64_encode($this->data));
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Intervention\Image\Tests;
use Intervention\Image\EncodedImage;
class EncodedImageTest extends TestCase
{
public function testConstructor()
{
$image = new EncodedImage('foo', 'bar');
$this->assertInstanceOf(EncodedImage::class, $image);
}
public function testSave(): void
{
$image = new EncodedImage('foo', 'bar');
$path = __DIR__ . '/foo.tmp';
$this->assertFalse(file_exists($path));
$image->save($path);
$this->assertTrue(file_exists($path));
$this->assertEquals('foo', file_get_contents($path));
unlink($path);
}
public function testToDataUri(): void
{
$image = new EncodedImage('foo', 'bar');
$this->assertEquals('data:bar;base64,Zm9v', $image->toDataUri());
}
public function testToString(): void
{
$image = new EncodedImage('foo', 'bar');
$this->assertEquals('foo', (string) $image);
}
}