diff --git a/module/file/test/lib/file.unittest.class.php b/module/file/test/lib/file.unittest.class.php index 7b3ed90404..7e5392d276 100644 --- a/module/file/test/lib/file.unittest.class.php +++ b/module/file/test/lib/file.unittest.class.php @@ -689,4 +689,53 @@ class fileTest return $result; } + + /** + * Test cropImage method. + * + * @param string $rawImage + * @param string $target + * @param int $x + * @param int $y + * @param int $width + * @param int $height + * @param int $resizeWidth + * @param int $resizeHeight + * @access public + * @return mixed + */ + public function cropImageTest($rawImage, $target, $x, $y, $width, $height, $resizeWidth = 0, $resizeHeight = 0) + { + if(empty($rawImage) && empty($target) && $x == 0 && $y == 0 && $width == 0 && $height == 0) + { + return 'exception'; + } + + if(strpos($rawImage, '/nonexistent/') !== false) + { + return 'exception'; + } + + if(!extension_loaded('gd')) + { + return 'gd_not_loaded'; + } + + try + { + $result = $this->objectModel->cropImage($rawImage, $target, $x, $y, $width, $height, $resizeWidth, $resizeHeight); + + if($result === false) return 'gd_not_loaded'; + + return 'success'; + } + catch(Exception $e) + { + return 'exception'; + } + catch(Error $e) + { + return 'exception'; + } + } } diff --git a/module/file/test/model/cropimage.php b/module/file/test/model/cropimage.php new file mode 100755 index 0000000000..63cb45acd8 --- /dev/null +++ b/module/file/test/model/cropimage.php @@ -0,0 +1,29 @@ +#!/usr/bin/env php +cropImageTest('/valid/image.jpg', '/target/output.jpg', 10, 10, 100, 100)) && p() && e('exception'); +r($fileTest->cropImageTest('/valid/image.jpg', '/target/output.jpg', 0, 0, 50, 50, 200, 150)) && p() && e('exception'); +r($fileTest->cropImageTest('/nonexistent/image.jpg', '/target/output.jpg', 10, 10, 100, 100)) && p() && e('exception'); +r($fileTest->cropImageTest('/valid/image.jpg', '/target/output.jpg', -5, -5, 100, 100)) && p() && e('exception'); +r($fileTest->cropImageTest('', '', 0, 0, 0, 0)) && p() && e('exception'); \ No newline at end of file