mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 16:50:07 +02:00
EncodedImage test
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
37
tests/EncodedImageTest.php
Normal file
37
tests/EncodedImageTest.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user