]> source.dussan.org Git - nextcloud-server.git/commitdiff
unit tests for specific image type output added
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 17 Mar 2014 07:40:59 +0000 (08:40 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 17 Mar 2014 07:40:59 +0000 (08:40 +0100)
lib/private/image.php
tests/lib/image.php

index dd041442ed6f04254da54325d78f520f384a4cb4..c987ce92c3c6d8257d96b791482c3f7fa465f51e 100644 (file)
@@ -239,7 +239,12 @@ class OC_Image {
                                $retVal = imagepng($this->resource, $filePath);
                                break;
                        case IMAGETYPE_XBM:
-                               $retVal = imagexbm($this->resource, $filePath);
+                               if (function_exists('imagexbm')) {
+                                       $retVal = imagexbm($this->resource, $filePath);
+                               } else {
+                                       throw new Exception('\OC_Image::_output(): imagexbm() is not supported.');
+                               }
+
                                break;
                        case IMAGETYPE_WBMP:
                                $retVal = imagewbmp($this->resource, $filePath);
index 4aba1b0bc61e56fd46eb7dfaebac55273aed2a34..131a9d86f3eaef89200d003bdbff303581cd1eb1 100644 (file)
@@ -8,8 +8,8 @@
 
 class Test_Image extends PHPUnit_Framework_TestCase {
        public static function tearDownAfterClass() {
-               unlink(OC::$SERVERROOT.'/tests/data/testimage2.png');
-               unlink(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
+               @unlink(OC::$SERVERROOT.'/tests/data/testimage2.png');
+               @unlink(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
        }
 
        public function testGetMimeTypeForFile() {
@@ -236,4 +236,24 @@ class Test_Image extends PHPUnit_Framework_TestCase {
                $this->assertEquals(200, $img->width());
                $this->assertEquals(200, $img->height());
        }
+
+       function convertDataProvider() {
+               return array(
+                       array( 'image/gif'),
+                       array( 'image/jpeg'),
+                       array( 'image/png'),
+               );
+       }
+
+       /**
+        * @dataProvider convertDataProvider
+        */
+       public function testConvert($mimeType) {
+               $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
+               $tempFile = tempnam(sys_get_temp_dir(), 'img-test');
+
+               $img->save($tempFile, $mimeType);
+               $actualMimeType = \OC_Image::getMimeTypeForFile($tempFile);
+               $this->assertEquals($mimeType, $actualMimeType);
+       }
 }