1
0
mirror of https://github.com/Intervention/image.git synced 2025-02-06 22:00:38 +01:00
intervention_image/tests/AbstractDecoderTest.php

149 lines
4.6 KiB
PHP
Raw Normal View History

2014-05-10 20:28:08 +02:00
<?php
2014-06-05 17:25:48 +02:00
class AbstractDecoderTest extends PHPUnit_Framework_TestCase
2014-05-10 20:28:08 +02:00
{
public function tearDown()
{
Mockery::close();
}
public function testIsImagick()
{
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(new \Imagick);
2014-05-10 20:28:08 +02:00
$this->assertTrue($source->isImagick());
2016-01-02 14:46:00 +01:00
$source = $this->getTestDecoder(new stdClass);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isImagick());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(null);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isImagick());
}
public function testIsGdResource()
{
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder($resource);
2014-05-10 20:28:08 +02:00
$this->assertTrue($source->isGdResource());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(tmpfile());
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isGdResource());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(null);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isGdResource());
}
public function testIsFilepath()
{
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(__DIR__.'/AbstractDecoderTest.php');
2014-05-10 20:28:08 +02:00
$this->assertTrue($source->isFilepath());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(null);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isFilepath());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(array());
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isFilepath());
2016-01-02 14:46:00 +01:00
$source = $this->getTestDecoder(new stdClass);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isFilepath());
}
public function testIsUrl()
{
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder('http://foo.bar');
2014-05-10 20:28:08 +02:00
$this->assertTrue($source->isUrl());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(null);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isUrl());
}
public function testIsStream()
{
$source = $this->getTestDecoder(fopen(__DIR__ . '/images/test.jpg', 'r'));
$this->assertTrue($source->isStream());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isStream());
}
2014-05-10 20:28:08 +02:00
public function testIsBinary()
{
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(file_get_contents(__DIR__.'/images/test.jpg'));
2014-05-10 20:28:08 +02:00
$this->assertTrue($source->isBinary());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(null);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isBinary());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(1);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isBinary());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(0);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isBinary());
2014-06-05 17:25:48 +02:00
$source = $this->getTestDecoder(array(1,2,3));
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isBinary());
2016-01-02 14:46:00 +01:00
$source = $this->getTestDecoder(new stdClass);
2014-05-10 20:28:08 +02:00
$this->assertFalse($source->isBinary());
}
2014-06-16 11:46:04 +02:00
public function testIsInterventionImage()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isInterventionImage());
$img = Mockery::mock('Intervention\Image\Image');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isInterventionImage());
}
public function testIsSplFileInfo()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isSplFileInfo());
$img = Mockery::mock('SplFileInfo');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isSplFileInfo());
$img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile', 'SplFileInfo');
$this->assertTrue($source->isSplFileInfo());
}
public function testIsSymfonyUpload()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isSymfonyUpload());
$img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isSymfonyUpload());
}
public function testIsDataUrl()
{
$source = $this->getTestDecoder('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC');
$this->assertTrue($source->isDataUrl());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isDataUrl());
}
public function testIsBase64()
{
$decoder = $this->getTestDecoder(null);
$this->assertFalse($decoder->isBase64());
$decoder = $this->getTestDecoder('random');
$this->assertFalse($decoder->isBase64());
$base64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC";
$decoder = $this->getTestDecoder($base64);
$this->assertTrue($decoder->isBase64());
}
2014-06-05 17:25:48 +02:00
public function getTestDecoder($data)
2014-05-10 20:28:08 +02:00
{
2014-06-05 17:25:48 +02:00
return $this->getMockForAbstractClass('\Intervention\Image\AbstractDecoder', array($data));
2014-05-10 20:28:08 +02:00
}
}