summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/karma.config.js18
-rw-r--r--tests/lib/connector/sabre/objecttree.php4
-rw-r--r--tests/lib/files/objectstore/swift.php106
-rw-r--r--tests/lib/helper.php24
-rw-r--r--tests/lib/repair/repairmimetypes.php207
5 files changed, 353 insertions, 6 deletions
diff --git a/tests/karma.config.js b/tests/karma.config.js
index 290790686b0..14a0d7e8464 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -110,15 +110,16 @@ module.exports = function(config) {
// core mocks
files.push(corePath + 'tests/specHelper.js');
+ var srcFile, i;
// add core library files
- for ( var i = 0; i < coreModule.libraries.length; i++ ) {
- var srcFile = corePath + coreModule.libraries[i];
+ for ( i = 0; i < coreModule.libraries.length; i++ ) {
+ srcFile = corePath + coreModule.libraries[i];
files.push(srcFile);
}
// add core modules files
- for ( var i = 0; i < coreModule.modules.length; i++ ) {
- var srcFile = corePath + coreModule.modules[i];
+ for ( i = 0; i < coreModule.modules.length; i++ ) {
+ srcFile = corePath + coreModule.modules[i];
files.push(srcFile);
if (enableCoverage) {
preprocessors[srcFile] = 'coverage';
@@ -155,12 +156,15 @@ module.exports = function(config) {
}
// add source files for apps to test
- for ( var i = 0; i < appsToTest.length; i++ ) {
+ for ( i = 0; i < appsToTest.length; i++ ) {
addApp(appsToTest[i]);
}
// serve images to avoid warnings
files.push({pattern: 'core/img/**/*', watched: false, included: false, served: true});
+
+ // include core CSS
+ files.push({pattern: 'core/css/*.css', watched: true, included: true, served: true});
config.set({
@@ -180,7 +184,9 @@ module.exports = function(config) {
proxies: {
// prevent warnings for images
- '/context.html//core/img/': 'http://localhost:9876/base/core/img/'
+ '/context.html//core/img/': 'http://localhost:9876/base/core/img/',
+ '/context.html//core/css/': 'http://localhost:9876/base/core/css/',
+ '/context.html//core/fonts/': 'http://localhost:9876/base/core/fonts/'
},
// test results reporter to use
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
index a88e23bbe2f..fc9f802066f 100644
--- a/tests/lib/connector/sabre/objecttree.php
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -25,6 +25,10 @@ class TestDoubleFileView extends \OC\Files\View{
return $this->updatables[$path];
}
+ public function isCreatable($path) {
+ return $this->updatables[$path];
+ }
+
public function isDeletable($path) {
return $this->deletables[$path];
}
diff --git a/tests/lib/files/objectstore/swift.php b/tests/lib/files/objectstore/swift.php
new file mode 100644
index 00000000000..7f3b45c0dab
--- /dev/null
+++ b/tests/lib/files/objectstore/swift.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * @author Jörn Friedrich Dreyer
+ * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\ObjectStore\Tests\Unit;
+
+use OC\Files\ObjectStore\ObjectStoreStorage;
+use OC\Files\ObjectStore\Swift as ObjectStoreToTest;
+
+use PHPUnit_Framework_TestCase;
+
+//class Swift extends PHPUnit_Framework_TestCase {
+class Swift extends \Test\Files\Storage\Storage {
+
+ private $objectStorage;
+
+ public function setUp() {
+
+ \OC_App::disable('files_sharing');
+ \OC_App::disable('files_versions');
+
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ // create users
+ $users = array('test');
+ foreach($users as $userName) {
+ \OC_User::deleteUser($userName);
+ \OC_User::createUser($userName, $userName);
+ }
+
+ // main test user
+ $userName = 'test';
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::tearDown();
+ \OC_User::setUserId('test');
+
+ $testContainer = 'oc-test-container-'.substr( md5(rand()), 0, 7);
+
+ $params = array(
+ 'username' => 'facebook100000330192569',
+ 'password' => 'Dbdj1sXnRSHxIGc4',
+ 'container' => $testContainer,
+ 'autocreate' => true,
+ 'region' => 'RegionOne', //required, trystack defaults to 'RegionOne'
+ 'url' => 'http://8.21.28.222:5000/v2.0', // The Identity / Keystone endpoint
+ 'tenantName' => 'facebook100000330192569', // required on trystack
+ 'serviceName' => 'swift', //trystack uses swift by default, the lib defaults to 'cloudFiles' if omitted
+ 'user' => \OC_User::getManager()->get($userName)
+ );
+ $this->objectStorage = new ObjectStoreToTest($params);
+ $params['objectstore'] = $this->objectStorage;
+ $this->instance = new ObjectStoreStorage($params);
+ }
+
+ public function tearDown() {
+ if (is_null($this->instance)) {
+ return;
+ }
+ $this->objectStorage->deleteContainer(true);
+ $this->instance->getCache()->clear();
+ }
+
+ public function testStat() {
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $ctimeStart = time();
+ $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
+ $this->assertTrue($this->instance->isReadable('/lorem.txt'));
+ $ctimeEnd = time();
+ $mTime = $this->instance->filemtime('/lorem.txt');
+
+ // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1)
+ $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime);
+ $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime);
+ $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
+
+ $stat = $this->instance->stat('/lorem.txt');
+ //only size and mtime are required in the result
+ $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt'));
+ $this->assertEquals($stat['mtime'], $mTime);
+
+ if ($this->instance->touch('/lorem.txt', 100) !== false) {
+ $mTime = $this->instance->filemtime('/lorem.txt');
+ $this->assertEquals($mTime, 100);
+ }
+ }
+
+}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index cfd66e99704..20b8571b91d 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -454,4 +454,28 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://localhost/owncloud/public.php?service=files', $result);
}
+ /**
+ * Tests recursive folder deletion with rmdirr()
+ */
+ public function testRecursiveFolderDeletion() {
+ $baseDir = \OC_Helper::tmpFolder() . '/';
+ mkdir($baseDir . 'a/b/c/d/e', 0777, true);
+ mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
+ mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a1/b', 0777, true);
+ mkdir($baseDir . 'a1/c', 0777, true);
+ file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
+ file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
+ file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
+ \OC_Helper::rmdirr($baseDir . 'a');
+
+ $this->assertFalse(file_exists($baseDir . 'a'));
+ $this->assertTrue(file_exists($baseDir . 'a1'));
+
+ \OC_Helper::rmdirr($baseDir);
+ $this->assertFalse(file_exists($baseDir));
+ }
}
diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php
new file mode 100644
index 00000000000..3ed19bd55bb
--- /dev/null
+++ b/tests/lib/repair/repairmimetypes.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Tests for the converting of legacy storages to home storages.
+ *
+ * @see \OC\Repair\RepairMimeTypes
+ */
+class TestRepairMimeTypes extends PHPUnit_Framework_TestCase {
+
+ /** @var \OC\RepairStep */
+ private $repair;
+
+ private $storage;
+
+ public function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+
+ $this->repair = new \OC\Repair\RepairMimeTypes();
+ }
+
+ public function tearDown() {
+ $this->storage->getCache()->clear();
+ $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
+ \OC_DB::executeAudited($sql, array($this->storage->getId()));
+ $this->clearMimeTypes();
+
+ DummyFileCache::clearCachedMimeTypes();
+ }
+
+ private function clearMimeTypes() {
+ $sql = 'DELETE FROM `*PREFIX*mimetypes`';
+ \OC_DB::executeAudited($sql);
+ }
+
+ private function addEntries($entries) {
+ // create files for the different extensions, this
+ // will also automatically create the corresponding mime types
+ foreach ($entries as $entry) {
+ $this->storage->getCache()->put(
+ $entry[0],
+ array(
+ 'size' => 0,
+ 'mtime' => 0,
+ 'mimetype' => $entry[1]
+ )
+ );
+ }
+
+ }
+
+ private function checkEntries($entries) {
+ foreach ($entries as $entry) {
+ $data = $this->storage->getCache()->get($entry[0]);
+ $this->assertEquals($entry[1], $data['mimetype']);
+ }
+ }
+
+ /**
+ * Returns the id of a given mime type or null
+ * if it does not exist.
+ */
+ private function getMimeTypeIdFromDB($mimeType) {
+ $sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
+ $results = \OC_DB::executeAudited($sql, array($mimeType));
+ $result = $results->fetchOne();
+ if ($result) {
+ return $result['id'];
+ }
+ return null;
+ }
+
+ /**
+ * Test renaming and splitting old office mime types
+ */
+ public function testRenameOfficeMimeTypes() {
+ $this->addEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/msword'),
+ array('test.xls', 'application/msexcel'),
+ array('test.xlsx', 'application/msexcel'),
+ array('test.ppt', 'application/mspowerpoint'),
+ array('test.pptx', 'application/mspowerpoint'),
+ )
+ );
+
+ $this->repair->run();
+
+ // force mimetype reload
+ DummyFileCache::clearCachedMimeTypes();
+ $this->storage->getCache()->loadMimeTypes();
+
+ $this->checkEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('test.xls', 'application/vnd.ms-excel'),
+ array('test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('test.ppt', 'application/vnd.ms-powerpoint'),
+ array('test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ )
+ );
+ }
+
+ /**
+ * Test renaming and splitting old office mime types when
+ * new ones already exist
+ */
+ public function testRenameOfficeMimeTypesWhenExist() {
+ $this->addEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/msword'),
+ array('test.xls', 'application/msexcel'),
+ array('test.xlsx', 'application/msexcel'),
+ array('test.ppt', 'application/mspowerpoint'),
+ array('test.pptx', 'application/mspowerpoint'),
+ // make it so that the new mimetypes already exist
+ array('bogus.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('bogus.xlsx', 'application/vnd.ms-excel'),
+ array('bogus.pptx', 'application/vnd.ms-powerpoint'),
+ array('bogus2.docx', 'application/wrong'),
+ array('bogus2.xlsx', 'application/wrong'),
+ array('bogus2.pptx', 'application/wrong'),
+ )
+ );
+
+ $this->repair->run();
+
+ // force mimetype reload
+ DummyFileCache::clearCachedMimeTypes();
+ $this->storage->getCache()->loadMimeTypes();
+
+ $this->checkEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('test.xls', 'application/vnd.ms-excel'),
+ array('test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('test.ppt', 'application/vnd.ms-powerpoint'),
+ array('test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ array('bogus.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('bogus.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('bogus.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ array('bogus2.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('bogus2.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('bogus2.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ )
+ );
+
+ // wrong mimetypes are gone
+ $this->assertNull($this->getMimeTypeIdFromDB('application/msexcel'));
+ $this->assertNull($this->getMimeTypeIdFromDB('application/mspowerpoint'));
+ }
+
+ /**
+ * Test that nothing happens and no error happens when all mimetypes are
+ * already correct and no old ones exist..
+ */
+ public function testDoNothingWhenOnlyNewFiles() {
+ $this->addEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('test.xls', 'application/vnd.ms-excel'),
+ array('test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('test.ppt', 'application/vnd.ms-powerpoint'),
+ array('test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ )
+ );
+
+ $this->repair->run();
+
+ // force mimetype reload
+ DummyFileCache::clearCachedMimeTypes();
+ $this->storage->getCache()->loadMimeTypes();
+
+ $this->checkEntries(
+ array(
+ array('test.doc', 'application/msword'),
+ array('test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
+ array('test.xls', 'application/vnd.ms-excel'),
+ array('test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
+ array('test.ppt', 'application/vnd.ms-powerpoint'),
+ array('test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
+ )
+ );
+ }
+}
+
+/**
+ * Dummy class to access protected members
+ */
+class DummyFileCache extends \OC\Files\Cache\Cache {
+
+ public static function clearCachedMimeTypes() {
+ self::$mimetypeIds = array();
+ self::$mimetypes = array();
+ }
+}
+