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

Add tests

This commit is contained in:
Oliver Vogel
2024-01-27 20:11:51 +01:00
parent 7e08e37319
commit 2b99dd439c
3 changed files with 22 additions and 11 deletions

View File

@@ -156,15 +156,6 @@ abstract class AbstractDecoder extends DriverSpecialized implements DecoderInter
return !empty($this->mediaType());
}
public function parameters(): array
{
if (isset($this->matches['parameters']) && !empty($this->matches['parameters'])) {
return explode(';', trim($this->matches['parameters'], ';'));
}
return [];
}
public function isBase64Encoded(): bool
{
if (isset($this->matches['base64']) && $this->matches['base64'] === ';base64') {

View File

@@ -138,6 +138,13 @@ class CollectionTest extends TestCase
$this->assertEquals('default', $collection->getAtPosition(3, 'default'));
}
public function testGetAtPositionEmpty(): void
{
$collection = new Collection();
$this->assertNull($collection->getAtPosition());
$this->assertEquals('default', $collection->getAtPosition(3, 'default'));
}
public function testEmpty(): void
{
$collection = new Collection([1, 2, 3]);

View File

@@ -91,18 +91,31 @@ class AbstractDecoderTest extends TestCase
};
$result = $decoder->parse(
'data:image/gif;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7'
'data:image/gif;foo=bar;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7'
);
$this->assertTrue($result->isValid());
$this->assertEquals('image/gif', $result->mediaType());
$this->assertTrue($result->hasMediaType());
$this->assertTrue($result->isBase64Encoded());
$this->assertEquals([], $result->parameters());
$this->assertEquals(
'R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7',
$result->data()
);
$result = $decoder->parse('data:text/plain;charset=utf-8,test');
$this->assertTrue($result->isValid());
$this->assertEquals('text/plain', $result->mediaType());
$this->assertTrue($result->hasMediaType());
$this->assertFalse($result->isBase64Encoded());
$this->assertEquals('test', $result->data());
$result = $decoder->parse('data:;charset=utf-8,');
$this->assertTrue($result->isValid());
$this->assertNull($result->mediaType());
$this->assertFalse($result->hasMediaType());
$this->assertFalse($result->isBase64Encoded());
$this->assertNull($result->data());
}
public function testIsValidBase64(): void