summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-04 23:15:17 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-04 23:15:17 +0200
commit835f477d8fda0566e5a03a652a3b8005cb886389 (patch)
tree46a4390fbd3611c0ba15115614c56d2c49aaabdc /tests/lib
parent206f83941b26b16f89e695ae84b998e9cf11132a (diff)
parent3b25babe35015224bb14e697c0b6d61da2841978 (diff)
downloadnextcloud-server-835f477d8fda0566e5a03a652a3b8005cb886389.tar.gz
nextcloud-server-835f477d8fda0566e5a03a652a3b8005cb886389.zip
Merge branch 'master' into appframework-master
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/db.php2
-rw-r--r--tests/lib/dbschema.php2
-rw-r--r--tests/lib/image.php36
-rw-r--r--tests/lib/preview.php108
-rw-r--r--tests/lib/util.php4
5 files changed, 139 insertions, 13 deletions
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 51edbf7b309..1977025cf12 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -15,7 +15,7 @@ class Test_DB extends PHPUnit_Framework_TestCase {
public function setUp() {
$dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml';
- $r = '_'.OC_Util::generate_random_bytes('4').'_';
+ $r = '_'.OC_Util::generateRandomBytes('4').'_';
$content = file_get_contents( $dbfile );
$content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content );
file_put_contents( self::$schema_file, $content );
diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php
index c2e55eabf4b..7de90c047ca 100644
--- a/tests/lib/dbschema.php
+++ b/tests/lib/dbschema.php
@@ -16,7 +16,7 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase {
$dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml';
$dbfile2 = OC::$SERVERROOT.'/tests/data/db_structure2.xml';
- $r = '_'.OC_Util::generate_random_bytes('4').'_';
+ $r = '_'.OC_Util::generateRandomBytes('4').'_';
$content = file_get_contents( $dbfile );
$content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content );
file_put_contents( $this->schema_file, $content );
diff --git a/tests/lib/image.php b/tests/lib/image.php
index 0583c300075..4aba1b0bc61 100644
--- a/tests/lib/image.php
+++ b/tests/lib/image.php
@@ -7,6 +7,10 @@
*/
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');
+ }
public function testGetMimeTypeForFile() {
$mimetype = \OC_Image::getMimeTypeForFile(OC::$SERVERROOT.'/tests/data/testimage.png');
@@ -55,7 +59,6 @@ class Test_Image extends PHPUnit_Framework_TestCase {
}
public function testMimeType() {
- $this->markTestSkipped("When loading from data or base64, imagetype is always image/png, see #4258.");
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
$this->assertEquals('image/png', $img->mimeType());
@@ -102,35 +105,50 @@ class Test_Image extends PHPUnit_Framework_TestCase {
$img->resize(16);
$img->save(OC::$SERVERROOT.'/tests/data/testimage2.png');
$this->assertEquals(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage2.png'), $img->data());
+
+ $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
+ $img->resize(128);
+ $img->save(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
+ $this->assertEquals(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage2.jpg'), $img->data());
}
public function testData() {
- $this->markTestSkipped("\OC_Image->data() converts to png before outputting data, see #4258.");
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
- $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png'));
+ ob_start();
+ imagepng($raw);
+ $expected = ob_get_clean();
$this->assertEquals($expected, $img->data());
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
- $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ ob_start();
+ imagejpeg($raw);
+ $expected = ob_get_clean();
$this->assertEquals($expected, $img->data());
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.gif');
- $expected = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif');
+ $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'));
+ ob_start();
+ imagegif($raw);
+ $expected = ob_get_clean();
$this->assertEquals($expected, $img->data());
}
+ /**
+ * @depends testData
+ */
public function testToString() {
- $this->markTestSkipped("\OC_Image->data() converts to png before outputting data, see #4258.");
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
- $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png'));
+ $expected = base64_encode($img->data());
$this->assertEquals($expected, (string)$img);
$img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
- $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ $expected = base64_encode($img->data());
$this->assertEquals($expected, (string)$img);
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.gif');
- $expected = base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'));
+ $expected = base64_encode($img->data());
$this->assertEquals($expected, (string)$img);
}
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
new file mode 100644
index 00000000000..bebdc12b500
--- /dev/null
+++ b/tests/lib/preview.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke <georg@ownCloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test;
+
+class Preview extends \PHPUnit_Framework_TestCase {
+
+ public function testIsPreviewDeleted() {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $x = 50;
+ $y = 50;
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
+ $preview->getPreview();
+
+ $fileinfo = $rootView->getFileInfo($samplefile);
+ $fileid = $fileinfo['fileid'];
+
+ $thumbcachefile = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $x . '-' . $y . '.png';
+
+ $this->assertEquals($rootView->file_exists($thumbcachefile), true);
+
+ $preview->deletePreview();
+
+ $this->assertEquals($rootView->file_exists($thumbcachefile), false);
+ }
+
+ public function testAreAllPreviewsDeleted() {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $x = 50;
+ $y = 50;
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', $x, $y);
+ $preview->getPreview();
+
+ $fileinfo = $rootView->getFileInfo($samplefile);
+ $fileid = $fileinfo['fileid'];
+
+ $thumbcachefolder = '/' . $user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileid . '/';
+
+ $this->assertEquals($rootView->is_dir($thumbcachefolder), true);
+
+ $preview->deleteAllPreviews();
+
+ $this->assertEquals($rootView->is_dir($thumbcachefolder), false);
+ }
+
+ public function testIsMaxSizeWorking() {
+ $user = $this->initFS();
+
+ $maxX = 250;
+ $maxY = 250;
+
+ \OC_Config::setValue('preview_max_x', $maxX);
+ \OC_Config::setValue('preview_max_y', $maxY);
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $samplefile = '/'.$user.'/files/test.txt';
+
+ $rootView->file_put_contents($samplefile, 'dummy file data');
+
+ $preview = new \OC\Preview($user, 'files/', 'test.txt', 1000, 1000);
+ $image = $preview->getPreview();
+
+ $this->assertEquals($image->width(), $maxX);
+ $this->assertEquals($image->height(), $maxY);
+ }
+
+ private function initFS() {
+ if(\OC\Files\Filesystem::getView()){
+ $user = \OC_User::getUser();
+ }else{
+ $user=uniqid();
+ \OC_User::setUserId($user);
+ \OC\Files\Filesystem::init($user, '/'.$user.'/files');
+ }
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
+
+ return $user;
+ }
+} \ No newline at end of file
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 13aa49c8c6f..d607a3e7725 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -71,8 +71,8 @@ class Test_Util extends PHPUnit_Framework_TestCase {
$this->assertTrue(\OC_Util::isInternetConnectionEnabled());
}
- function testGenerate_random_bytes() {
- $result = strlen(OC_Util::generate_random_bytes(59));
+ function testGenerateRandomBytes() {
+ $result = strlen(OC_Util::generateRandomBytes(59));
$this->assertEquals(59, $result);
}