'jpeg.jpg', 'png' => 'png.png', 'gif' => 'gif_nonanimated.gif', 'animated' => 'gif_animated.gif', 'nonexistant' => 'nonexisting.jpg', 'invalid' => 'text.txt', ); protected $testFiltersSuccess = array( 0 => array( 0 => array( 'name' => 'scaleExact', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), 1 => array( 'name' => 'crop', 'options' => array( 'xStart' => 10, 'xEnd' => 40, 'yStart' => 10, 'yEnd' => 40, ), ), 2 => array( 'name' => 'colorspace', 'options' => array( 'space' => ezcImageFiltersInterfaceColorspace::COLORSPACE_GREY, ), ), ), 1 => array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 1000, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_DOWN, ), ), 2 => array( 'name' => 'colorspace', 'options' => array( 'space' => ezcImageFiltersInterfaceColorspace::COLORSPACE_MONOCHROME, ), ), ), 2 => array( 0 => array( 'name' => 'scaleHeight', 'options' => array( 'height' => 70, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), 2 => array( 'name' => 'colorspace', 'options' => array( 'space' => ezcImageFiltersInterfaceColorspace::COLORSPACE_SEPIA, ), ), ), ); protected $testFiltersFailure = array( // Nonexistant filter 0 => array( 0 => array( 'name' => 'toby', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), 1 => array( 'name' => 'crop', 'options' => array( 'xStart' => 10, 'xEnd' => 40, 'yStart' => 10, 'yEnd' => 40, ), ), 2 => array( 'name' => 'colorspace', 'options' => array( 'space' => ezcImageFiltersInterfaceColorspace::COLORSPACE_GREY, ), ), ), // Missing option 1 => array( 0 => array( 'name' => 'scale', 'options' => array( ), ), 2 => array( 'name' => 'colorspace', 'options' => array( 'space' => ezcImageFiltersInterfaceColorspace::COLORSPACE_MONOCHROME, ), ), ), ); protected $converter; protected $basePath; protected $testPath; public static function suite() { return new ezcTestSuite( "ezcImageConversionTransformationTest" ); } /** * setUp * * @access public */ public function setUp() { static $i = 1; $this->basePath = dirname( __FILE__ ) . '/data/'; $conversionsIn = array( 'image/gif' => 'image/png', 'image/xpm' => 'image/jpeg', 'image/wbmp' => 'image/jpeg', ); $settings = array( 'handlers' => array( 'GD', ), 'conversions' => $conversionsIn, ); $this->converter = new ezcImageConverter( $settings ); } /** * tearDown * * @access public */ public function tearDown() { unset( $this->converter ); // $this->removeTempDir(); } public function testConstructSuccess() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), 1 => array( 'name' => 'scaleWidth', 'options' => array( 'width' => 40, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), 2 => array( 'name' => 'crop', 'options' => array( 'xStart' => 10, 'xEnd' => 30, 'yStart' => 10, 'yEnd' => 30, ), ), ); $mimeIn = array( 'image/jpeg' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); $transArr = (array)$trans; $filters = $transArr["\0*\0filters"]; $mimeOut = $transArr["\0*\0mimeOut"]; $this->assertEquals( $mimeIn, $mimeOut, 'MIME types not registered correctly in transformation.' ); $this->assertEquals( $filtersIn, $filters, 'Filters not registered correctly in transformation.' ); } public function testConstructFailure_1() { $filtersIn = array( 0 => array( 'name' => 'toby', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $mimeIn = array( 'image/jpeg' ); try { $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); } catch ( ezcImageFiltersException $e ) { $this->assertEquals( ezcImageFiltersException::NOT_AVAILABLE, $e->getCode(), 'Transformation threw incorrect exception on invalid filter.' ); return; } $this->fail( 'Transformation did not throw exception on invalid filter.' ); } public function testConstructFailure_2() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $mimeIn = array( 'application/toby' ); try { $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); } catch ( ezcImageConverterException $e ) { $this->assertEquals( ezcImageConverterException::MIMETYPE_NOT_AVAILABLE, $e->getCode(), 'Transformation threw incorrect exception on invalid MIME type.' ); return; } $this->fail( 'Transformation did not throw exception on invalid MIME type.' ); } public function testAddFilterSuccess() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $newFilter = array( 'name' => 'scaleWidth', 'options' => array( 'width' => 40, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ); $filtersOut = $filtersIn; $filtersOut[] = $newFilter; $mimeIn = array( 'image/jpeg' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); $trans->addFilter( $newFilter['name'], $newFilter['options'] ); $transArr = (array)$trans; $filters = $transArr["\0*\0filters"]; $this->assertEquals( $filtersOut, $filters, 'Filters not added correctly to transformation.' ); } public function testAddFilterFailure() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $newFilter = array( 'name' => 'toby', 'options' => array( 'width' => 40, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ); $filtersOut = $filtersIn; $filtersOut[] = $newFilter; $mimeIn = array( 'image/jpeg' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); try { $trans->addFilter( $newFilter['name'], $newFilter['options'] ); } catch ( ezcImageFiltersException $e ) { $this->assertEquals( ezcImageFiltersException::NOT_AVAILABLE, $e->getCode(), 'Transformation threw incorrect exception on invalid filter.' ); return; } $this->fail( 'Transformation did not throw exception on invalid filter.' ); } public function testGetOutMimeSuccess_1() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $mimeIn = array( 'image/jpeg' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); $this->assertEquals( 'image/jpeg', $trans->getOutMime( $this->basePath . $this->testFiles['jpeg'] ), 'Transformation returned incorrect output MIME type.' ); } public function testGetOutMimeSuccess_2() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $mimeIn = array( 'image/jpeg', 'image/png' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); $this->assertEquals( 'image/png', $trans->getOutMime( $this->basePath . $this->testFiles['gif'] ), 'Transformation returned incorrect output MIME type.' ); } public function testGetOutMimeSuccess_3() { $filtersIn = array( 0 => array( 'name' => 'scale', 'options' => array( 'width' => 50, 'height' => 50, 'direction' => ezcImageFiltersInterfaceGeometry::SCALE_BOTH, ), ), ); $mimeIn = array( 'image/jpeg' ); $trans = new ezcImageTransformation( $this->converter, 'test', $filtersIn, $mimeIn ); $this->assertEquals( 'image/jpeg', $trans->getOutMime( $this->basePath . $this->testFiles['gif'] ), 'Transformation returned incorrect output MIME type.' ); } public function testTransformSuccessPng_1() { $this->commonTransformTestSuccess( 'png', 0, 'b1d842a9d1f1558c8f6e2db67a90ab30', __METHOD__ ); } public function testTransformSuccessPng_2() { $this->commonTransformTestSuccess( 'png', 1, 'f68c2cfeb59e835a50c22e2935c97721', __METHOD__ ); } public function testTransformSuccessPng_3() { $this->commonTransformTestSuccess( 'png', 2, '7d767ecd7b180b9927a0f765355a6ab0', __METHOD__ ); } public function testTransformSuccessJpeg_1() { $this->commonTransformTestSuccess( 'jpeg', 0, '6189790a171de230781c13a51cd05713', __METHOD__ ); } public function testTransformSuccessJpeg_2() { $this->commonTransformTestSuccess( 'jpeg', 1, 'ab06a96e6af122a972bd86159b71b228', __METHOD__ ); } public function testTransformSuccessJpeg_3() { $this->commonTransformTestSuccess( 'jpeg', 2, 'f1a2fede0c65f3d807c66f39f090b399', __METHOD__ ); } public function testTransformSuccessGif_1() { $this->commonTransformTestSuccess( 'gif', 0, 'fac15d3387899936b4c74417b4a1f1a2', __METHOD__ ); } public function testTransformSuccessGif_2() { $this->commonTransformTestSuccess( 'gif', 1, 'acf997971e72d3857ae2f2b9e670f8dd', __METHOD__ ); } public function testTransformSuccessGif_3() { $this->commonTransformTestSuccess( 'gif', 2, '9c505c2263a65dec7a6167d4f0ae0de1', __METHOD__ ); } public function testTransformSuccessGifAnimated() { $this->commonTransformTestSuccess( 'animated', 2, '9a6e0141efc695a7bca2c0889b329935', __METHOD__ ); } public function testTransformFailure_1() { $this->commonTransformTestFailure( 'jpeg', 0, 'ezcImageFiltersException', ezcImageFiltersException::NOT_AVAILABLE, __METHOD__ ); } public function testTransformFailure_2() { $this->commonTransformTestFailure( 'jpeg', 1, 'ezcImageFiltersException', ezcImageFiltersException::MISSING_PARAMETER, __METHOD__ ); } protected function commonTransformTestSuccess( $inFileRef, $filtersRef, $md5sum, $name ) { $inFile = $this->basePath . $this->testFiles[$inFileRef]; $outFile = $this->createTempDir( str_replace( '::', '_', $name ) . '_' ) . '/result'; $mimeIn = array( 'image/jpeg', 'image/png' ); $trans = new ezcImageTransformation( $this->converter, 'test', $this->testFiltersSuccess[$filtersRef], $mimeIn ); $trans->transform( $inFile, $outFile ); // Uncomment to get md5 sums: // echo "\n$name: ".md5_file( $outFile )."\n\n"; $this->assertEquals( $md5sum, md5_file( $outFile ), 'Transformation did not produce correct output.' ); // Comment this for visual inspection $this->removeTempDir(); } protected function commonTransformTestFailure( $inFileRef, $filtersRef, $exceptionClass, $exceptionCode, $name ) { $inFile = $this->basePath . $this->testFiles[$inFileRef]; $outFile = $this->createTempDir( str_replace( '::', '_', $name ) . '_' ) . '/result'; $mimeIn = array( 'image/jpeg', 'image/png' ); try { $trans = new ezcImageTransformation( $this->converter, 'test', $this->testFiltersFailure[$filtersRef], $mimeIn ); $trans->transform( $inFile, $outFile ); } catch ( Exception $e ) { $this->assertTrue( get_class( $e ) === $exceptionClass, 'Transformation threw incorrect exception class <'.get_class( $e ).'> on invalid data <'.$filtersRef.'>.' ); $this->assertEquals( $exceptionCode, $e->getCode(), 'Transformation did not throw the correct exception code <'.$exceptionCode.'> on invalid data <'.$filtersRef.'>, but: <'.$e->getCode().'>.' ); $this->removeTempDir(); return; } // If we failed, this stays. $this->removeTempDir(); $this->fail( 'Transformation did not throw exception on invalid data.' ); } } ?>