mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 02:12:37 +02:00
Add tests
This commit is contained in:
@@ -156,15 +156,6 @@ abstract class AbstractDecoder extends DriverSpecialized implements DecoderInter
|
|||||||
return !empty($this->mediaType());
|
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
|
public function isBase64Encoded(): bool
|
||||||
{
|
{
|
||||||
if (isset($this->matches['base64']) && $this->matches['base64'] === ';base64') {
|
if (isset($this->matches['base64']) && $this->matches['base64'] === ';base64') {
|
||||||
|
@@ -138,6 +138,13 @@ class CollectionTest extends TestCase
|
|||||||
$this->assertEquals('default', $collection->getAtPosition(3, 'default'));
|
$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
|
public function testEmpty(): void
|
||||||
{
|
{
|
||||||
$collection = new Collection([1, 2, 3]);
|
$collection = new Collection([1, 2, 3]);
|
||||||
|
@@ -91,18 +91,31 @@ class AbstractDecoderTest extends TestCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
$result = $decoder->parse(
|
$result = $decoder->parse(
|
||||||
'data:image/gif;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7'
|
'data:image/gif;foo=bar;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertTrue($result->isValid());
|
$this->assertTrue($result->isValid());
|
||||||
$this->assertEquals('image/gif', $result->mediaType());
|
$this->assertEquals('image/gif', $result->mediaType());
|
||||||
$this->assertTrue($result->hasMediaType());
|
$this->assertTrue($result->hasMediaType());
|
||||||
$this->assertTrue($result->isBase64Encoded());
|
$this->assertTrue($result->isBase64Encoded());
|
||||||
$this->assertEquals([], $result->parameters());
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7',
|
'R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7',
|
||||||
$result->data()
|
$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
|
public function testIsValidBase64(): void
|
||||||
|
Reference in New Issue
Block a user