summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorkondou <kondou@ts.unde.re>2013-08-31 23:48:23 +0200
committerkondou <kondou@ts.unde.re>2013-08-31 23:48:23 +0200
commit235638e5abd35f2f19944bbe0b5a838b83465252 (patch)
tree27b531a7f9a2de054e707d4415ce7de2a2c51556 /tests/lib
parent0869f9b655ddd0b285629256521d7eafde2f5d8a (diff)
parent92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7 (diff)
downloadnextcloud-server-235638e5abd35f2f19944bbe0b5a838b83465252.tar.gz
nextcloud-server-235638e5abd35f2f19944bbe0b5a838b83465252.zip
Merge branch 'master' into fix_4258
Conflicts: lib/image.php
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/preview.php108
1 files changed, 108 insertions, 0 deletions
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