summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-13 20:56:49 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-13 20:56:49 +0200
commit5b3388c7c4c37492627700c38b385f31a397fb91 (patch)
tree8bac096896f14f5468da359ee80678956cab6563 /tests
parent206f83941b26b16f89e695ae84b998e9cf11132a (diff)
parentc149b57d3b4020c65d33966d5dc8395b8b821fc9 (diff)
downloadnextcloud-server-5b3388c7c4c37492627700c38b385f31a397fb91.tar.gz
nextcloud-server-5b3388c7c4c37492627700c38b385f31a397fb91.zip
Merge branch 'master' into appframework-master
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/db.php2
-rw-r--r--tests/lib/dbschema.php2
-rw-r--r--tests/lib/files/view.php31
-rw-r--r--tests/lib/helper.php62
-rw-r--r--tests/lib/image.php36
-rw-r--r--tests/lib/preview.php108
-rw-r--r--tests/lib/util.php4
7 files changed, 201 insertions, 44 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/files/view.php b/tests/lib/files/view.php
index 3bac9e770aa..0de436f570a 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -25,7 +25,7 @@ class View extends \PHPUnit_Framework_TestCase {
//login
\OC_User::createUser('test', 'test');
- $this->user=\OC_User::getUser();
+ $this->user = \OC_User::getUser();
\OC_User::setUserId('test');
\OC\Files\Filesystem::clearMounts();
@@ -326,6 +326,35 @@ class View extends \PHPUnit_Framework_TestCase {
}
/**
+ * @medium
+ */
+ function testViewHooks() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $defaultRoot = \OC\Files\Filesystem::getRoot();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot . '/substorage');
+ \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
+
+ $rootView = new \OC\Files\View('');
+ $subView = new \OC\Files\View($defaultRoot . '/substorage');
+ $this->hookPath = null;
+
+ $rootView->file_put_contents('/foo.txt', 'asd');
+ $this->assertNull($this->hookPath);
+
+ $subView->file_put_contents('/foo.txt', 'asd');
+ $this->assertNotNull($this->hookPath);
+ $this->assertEquals('/substorage/foo.txt', $this->hookPath);
+ }
+
+ private $hookPath;
+
+ function dummyHook($params) {
+ $this->hookPath = $params['path'];
+ }
+
+ /**
* @param bool $scan
* @return \OC\Files\Storage\Storage
*/
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 67b5a3d43ec..b4d896e5196 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -8,40 +8,42 @@
class Test_Helper extends PHPUnit_Framework_TestCase {
- function testHumanFileSize() {
- $result = OC_Helper::humanFileSize(0);
- $expected = '0 B';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(1024);
- $expected = '1 kB';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(10000000);
- $expected = '9.5 MB';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(500000000000);
- $expected = '465.7 GB';
- $this->assertEquals($result, $expected);
+ /**
+ * @dataProvider humanFileSizeProvider
+ */
+ public function testHumanFileSize($expected, $input)
+ {
+ $result = OC_Helper::humanFileSize($input);
+ $this->assertEquals($expected, $result);
}
- function testComputerFileSize() {
- $result = OC_Helper::computerFileSize("0 B");
- $expected = '0.0';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::computerFileSize("1 kB");
- $expected = '1024.0';
- $this->assertEquals($result, $expected);
+ public function humanFileSizeProvider()
+ {
+ return array(
+ array('0 B', 0),
+ array('1 kB', 1024),
+ array('9.5 MB', 10000000),
+ array('465.7 GB', 500000000000),
+ array('454.7 TB', 500000000000000),
+ array('444.1 PB', 500000000000000000),
+ );
+ }
- $result = OC_Helper::computerFileSize("9.5 MB");
- $expected = '9961472.0';
- $this->assertEquals($result, $expected);
+ /**
+ * @dataProvider computerFileSizeProvider
+ */
+ function testComputerFileSize($expected, $input) {
+ $result = OC_Helper::computerFileSize($input);
+ $this->assertEquals($expected, $result);
+ }
- $result = OC_Helper::computerFileSize("465.7 GB");
- $expected = '500041567436.8';
- $this->assertEquals($result, $expected);
+ function computerFileSizeProvider(){
+ return array(
+ array(0.0, "0 B"),
+ array(1024.0, "1 kB"),
+ array(9961472.0, "9.5 MB"),
+ array(500041567436.8, "465.7 GB"),
+ );
}
function testGetMimeType() {
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);
}