summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php1
-rw-r--r--tests/enable_all.php2
-rw-r--r--tests/lib/app.php4
-rw-r--r--tests/lib/app/manager.php180
-rw-r--r--tests/lib/avatar.php13
-rw-r--r--tests/lib/cache/file.php7
-rw-r--r--tests/lib/cache/usercache.php7
-rw-r--r--tests/lib/encryption/keys/storage.php153
-rw-r--r--tests/lib/encryption/managertest.php58
-rw-r--r--tests/lib/encryption/utiltest.php18
-rw-r--r--tests/lib/files/cache/cache.php9
-rw-r--r--tests/lib/files/cache/updater.php8
-rw-r--r--tests/lib/files/cache/updaterlegacy.php21
-rw-r--r--tests/lib/files/cache/watcher.php10
-rw-r--r--tests/lib/files/etagtest.php17
-rw-r--r--tests/lib/files/filesystem.php12
-rw-r--r--tests/lib/files/node/integration.php12
-rw-r--r--tests/lib/files/storage/storage.php36
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php125
-rw-r--r--tests/lib/files/storage/wrapper/jail.php4
-rw-r--r--tests/lib/files/storage/wrapper/quota.php8
-rw-r--r--tests/lib/files/stream/encryption.php104
-rw-r--r--tests/lib/files/utils/scanner.php8
-rw-r--r--tests/lib/files/view.php12
-rw-r--r--tests/lib/group/manager.php6
-rw-r--r--tests/lib/preview.php92
-rw-r--r--tests/lib/repair/repairmimetypes.php53
-rw-r--r--tests/lib/share/share.php234
-rw-r--r--tests/lib/streamwrappers.php16
-rw-r--r--tests/lib/testcase.php15
-rw-r--r--tests/lib/util.php19
-rw-r--r--tests/settings/controller/CheckSetupControllerTest.php17
32 files changed, 960 insertions, 321 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index cebd899e785..5945dbdc11f 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -25,4 +25,3 @@ if (!class_exists('PHPUnit_Framework_TestCase')) {
OC_Hook::clear();
OC_Log::$enabled = false;
-OC_FileProxy::clearProxies();
diff --git a/tests/enable_all.php b/tests/enable_all.php
index e9b538713a5..464155b1f39 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -18,7 +18,7 @@ function enableApp($app) {
enableApp('files_sharing');
enableApp('files_trashbin');
-enableApp('files_encryption');
+enableApp('encryption');
enableApp('user_ldap');
enableApp('files_versions');
enableApp('provisioning_api');
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 86a407c1a95..3f380f74fd2 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -470,7 +470,7 @@ class Test_App extends \Test\TestCase {
return $appConfig;
});
\OC::$server->registerService('AppManager', function (\OC\Server $c) use ($appConfig) {
- return new \OC\App\AppManager($c->getUserSession(), $appConfig, $c->getGroupManager());
+ return new \OC\App\AppManager($c->getUserSession(), $appConfig, $c->getGroupManager(), $c->getMemCacheFactory());
});
}
@@ -482,7 +482,7 @@ class Test_App extends \Test\TestCase {
return new \OC\AppConfig(\OC_DB::getConnection());
});
\OC::$server->registerService('AppManager', function (\OC\Server $c) {
- return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager());
+ return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
});
// Remove the cache of the mocked apps list with a forceRefresh
diff --git a/tests/lib/app/manager.php b/tests/lib/app/manager.php
index cb41f737469..6cf7eb3bb6c 100644
--- a/tests/lib/app/manager.php
+++ b/tests/lib/app/manager.php
@@ -54,22 +54,55 @@ class Manager extends \PHPUnit_Framework_TestCase {
return $config;
}
+ /** @var \OCP\IUserSession */
+ protected $userSession;
+
+ /** @var \OCP\IGroupManager */
+ protected $groupManager;
+
+ /** @var \OCP\IAppConfig */
+ protected $appConfig;
+
+ /** @var \OCP\ICache */
+ protected $cache;
+
+ /** @var \OCP\ICacheFactory */
+ protected $cacheFactory;
+
+ /** @var \OCP\App\IAppManager */
+ protected $manager;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->userSession = $this->getMock('\OCP\IUserSession');
+ $this->groupManager = $this->getMock('\OCP\IGroupManager');
+ $this->appConfig = $this->getAppConfig();
+ $this->cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $this->cache = $this->getMock('\OCP\ICache');
+ $this->cacheFactory->expects($this->any())
+ ->method('create')
+ ->with('settings')
+ ->willReturn($this->cache);
+ $this->manager = new \OC\App\AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory);
+ }
+
+ protected function expectClearCache() {
+ $this->cache->expects($this->once())
+ ->method('clear')
+ ->with('listApps');
+ }
+
public function testEnableApp() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $manager->enableApp('test');
- $this->assertEquals('yes', $appConfig->getValue('test', 'enabled', 'no'));
+ $this->expectClearCache();
+ $this->manager->enableApp('test');
+ $this->assertEquals('yes', $this->appConfig->getValue('test', 'enabled', 'no'));
}
public function testDisableApp() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $manager->disableApp('test');
- $this->assertEquals('no', $appConfig->getValue('test', 'enabled', 'no'));
+ $this->expectClearCache();
+ $this->manager->disableApp('test');
+ $this->assertEquals('no', $this->appConfig->getValue('test', 'enabled', 'no'));
}
public function testEnableAppForGroups() {
@@ -77,151 +110,98 @@ class Manager extends \PHPUnit_Framework_TestCase {
new Group('group1', array(), null),
new Group('group2', array(), null)
);
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $userSession = $this->getMock('\OCP\IUserSession');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $manager->enableAppForGroups('test', $groups);
- $this->assertEquals('["group1","group2"]', $appConfig->getValue('test', 'enabled', 'no'));
+ $this->expectClearCache();
+ $this->manager->enableAppForGroups('test', $groups);
+ $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
}
public function testIsInstalledEnabled() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', 'yes');
- $this->assertTrue($manager->isInstalled('test'));
+ $this->appConfig->setValue('test', 'enabled', 'yes');
+ $this->assertTrue($this->manager->isInstalled('test'));
}
public function testIsInstalledDisabled() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', 'no');
- $this->assertFalse($manager->isInstalled('test'));
+ $this->appConfig->setValue('test', 'enabled', 'no');
+ $this->assertFalse($this->manager->isInstalled('test'));
}
public function testIsInstalledEnabledForGroups() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', '["foo"]');
- $this->assertTrue($manager->isInstalled('test'));
+ $this->appConfig->setValue('test', 'enabled', '["foo"]');
+ $this->assertTrue($this->manager->isInstalled('test'));
}
public function testIsEnabledForUserEnabled() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', 'yes');
+ $this->appConfig->setValue('test', 'enabled', 'yes');
$user = new User('user1', null);
- $this->assertTrue($manager->isEnabledForUser('test', $user));
+ $this->assertTrue($this->manager->isEnabledForUser('test', $user));
}
public function testIsEnabledForUserDisabled() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', 'no');
+ $this->appConfig->setValue('test', 'enabled', 'no');
$user = new User('user1', null);
- $this->assertFalse($manager->isEnabledForUser('test', $user));
+ $this->assertFalse($this->manager->isEnabledForUser('test', $user));
}
public function testIsEnabledForUserEnabledForGroup() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
$user = new User('user1', null);
-
- $groupManager->expects($this->once())
+ $this->groupManager->expects($this->once())
->method('getUserGroupIds')
->with($user)
->will($this->returnValue(array('foo', 'bar')));
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', '["foo"]');
- $this->assertTrue($manager->isEnabledForUser('test', $user));
+ $this->appConfig->setValue('test', 'enabled', '["foo"]');
+ $this->assertTrue($this->manager->isEnabledForUser('test', $user));
}
public function testIsEnabledForUserDisabledForGroup() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
$user = new User('user1', null);
-
- $groupManager->expects($this->once())
+ $this->groupManager->expects($this->once())
->method('getUserGroupIds')
->with($user)
->will($this->returnValue(array('bar')));
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', '["foo"]');
- $this->assertFalse($manager->isEnabledForUser('test', $user));
+ $this->appConfig->setValue('test', 'enabled', '["foo"]');
+ $this->assertFalse($this->manager->isEnabledForUser('test', $user));
}
public function testIsEnabledForUserLoggedOut() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
-
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', '["foo"]');
- $this->assertFalse($manager->IsEnabledForUser('test'));
+ $this->appConfig->setValue('test', 'enabled', '["foo"]');
+ $this->assertFalse($this->manager->IsEnabledForUser('test'));
}
public function testIsEnabledForUserLoggedIn() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
$user = new User('user1', null);
- $userSession->expects($this->once())
+ $this->userSession->expects($this->once())
->method('getUser')
->will($this->returnValue($user));
- $groupManager->expects($this->once())
+ $this->groupManager->expects($this->once())
->method('getUserGroupIds')
->with($user)
->will($this->returnValue(array('foo', 'bar')));
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test', 'enabled', '["foo"]');
- $this->assertTrue($manager->isEnabledForUser('test'));
+ $this->appConfig->setValue('test', 'enabled', '["foo"]');
+ $this->assertTrue($this->manager->isEnabledForUser('test'));
}
public function testGetInstalledApps() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
-
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test1', 'enabled', 'yes');
- $appConfig->setValue('test2', 'enabled', 'no');
- $appConfig->setValue('test3', 'enabled', '["foo"]');
- $this->assertEquals(['test1', 'test3'], $manager->getInstalledApps());
+ $this->appConfig->setValue('test1', 'enabled', 'yes');
+ $this->appConfig->setValue('test2', 'enabled', 'no');
+ $this->appConfig->setValue('test3', 'enabled', '["foo"]');
+ $this->assertEquals(['test1', 'test3'], $this->manager->getInstalledApps());
}
public function testGetAppsForUser() {
- $userSession = $this->getMock('\OCP\IUserSession');
- $groupManager = $this->getMock('\OCP\IGroupManager');
-
$user = new User('user1', null);
-
- $groupManager->expects($this->any())
+ $this->groupManager->expects($this->any())
->method('getUserGroupIds')
->with($user)
->will($this->returnValue(array('foo', 'bar')));
- $appConfig = $this->getAppConfig();
- $manager = new \OC\App\AppManager($userSession, $appConfig, $groupManager);
- $appConfig->setValue('test1', 'enabled', 'yes');
- $appConfig->setValue('test2', 'enabled', 'no');
- $appConfig->setValue('test3', 'enabled', '["foo"]');
- $appConfig->setValue('test4', 'enabled', '["asd"]');
- $this->assertEquals(['test1', 'test3'], $manager->getEnabledAppsForUser($user));
+ $this->appConfig->setValue('test1', 'enabled', 'yes');
+ $this->appConfig->setValue('test2', 'enabled', 'no');
+ $this->appConfig->setValue('test3', 'enabled', '["foo"]');
+ $this->appConfig->setValue('test4', 'enabled', '["asd"]');
+ $this->assertEquals(['test1', 'test3'], $this->manager->getEnabledAppsForUser($user));
}
}
diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php
index e852a7fc6ff..9e1f367108d 100644
--- a/tests/lib/avatar.php
+++ b/tests/lib/avatar.php
@@ -10,7 +10,9 @@
use OC\Avatar;
class Test_Avatar extends \Test\TestCase {
+ private static $trashBinStatus;
+ /** @var @var string */
private $user;
protected function setUp() {
@@ -21,6 +23,17 @@ class Test_Avatar extends \Test\TestCase {
\OC\Files\Filesystem::mount($storage, array(), '/' . $this->user . '/');
}
+ public static function setUpBeforeClass() {
+ self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
+ \OC_App::disable('files_trashbin');
+ }
+
+ public static function tearDownAfterClass() {
+ if (self::$trashBinStatus) {
+ \OC_App::enable('files_trashbin');
+ }
+ }
+
public function testAvatar() {
$avatar = new Avatar($this->user);
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index d51322036c8..153cb198f13 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -38,15 +38,8 @@ class FileCache extends \Test_Cache {
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
- //disabled atm
- //enable only the encryption hook if needed
- //if(OC_App::isEnabled('files_encryption')) {
- // OC_FileProxy::register(new OC_FileProxy_Encryption());
- //}
-
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php
index 3822a714d5a..26a9158ab3a 100644
--- a/tests/lib/cache/usercache.php
+++ b/tests/lib/cache/usercache.php
@@ -34,15 +34,8 @@ class UserCache extends \Test_Cache {
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
- //disabled atm
- //enable only the encryption hook if needed
- //if(OC_App::isEnabled('files_encryption')) {
- // OC_FileProxy::register(new OC_FileProxy_Encryption());
- //}
-
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index c2e5bdbd3d1..8ab46987f8c 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -28,6 +28,9 @@ use Test\TestCase;
class StorageTest extends TestCase {
+ /** @var Storage */
+ protected $storage;
+
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $util;
@@ -45,6 +48,8 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->storage = new Storage('encModule', $this->view, $this->util);
+
}
public function testSetFileKey() {
@@ -63,10 +68,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -89,10 +92,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -112,10 +113,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -138,10 +137,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -152,10 +149,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setSystemUserKey('shareKey_56884', 'key')
+ $this->storage->setSystemUserKey('shareKey_56884', 'key')
);
}
@@ -166,10 +161,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setUserKey('user1', 'publicKey', 'key')
+ $this->storage->setUserKey('user1', 'publicKey', 'key')
);
}
@@ -183,10 +176,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getSystemUserKey('shareKey_56884')
+ $this->storage->getSystemUserKey('shareKey_56884')
);
}
@@ -200,10 +191,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getUserKey('user1', 'publicKey')
+ $this->storage->getUserKey('user1', 'publicKey')
);
}
@@ -213,10 +202,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteUserKey('user1', 'publicKey')
+ $this->storage->deleteUserKey('user1', 'publicKey')
);
}
@@ -226,10 +213,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteSystemUserKey('shareKey_56884')
+ $this->storage->deleteSystemUserKey('shareKey_56884')
);
}
@@ -248,10 +233,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -270,11 +253,109 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ );
+ }
+
+ /**
+ * @dataProvider dataProviderCopyRename
+ */
+ public function testRenameKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(true);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(true);
+ $this->view->expects($this->once())
+ ->method('rename')
+ ->with(
+ $this->equalTo($expectedSource),
+ $this->equalTo($expectedTarget))
+ ->willReturn(true);
+ $this->util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
+ $this->util->expects($this->any())
+ ->method('isSystemWideMountPoint')
+ ->willReturn($systemWideMount);
+
+ $this->storage->renameKeys($source, $target);
+ }
+
+ /**
+ * @dataProvider dataProviderCopyRename
+ */
+ public function testCopyKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(true);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(true);
+ $this->view->expects($this->once())
+ ->method('copy')
+ ->with(
+ $this->equalTo($expectedSource),
+ $this->equalTo($expectedTarget))
+ ->willReturn(true);
+ $this->util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
+ $this->util->expects($this->any())
+ ->method('isSystemWideMountPoint')
+ ->willReturn($systemWideMount);
+
+ $this->storage->copyKeys($source, $target);
+ }
+
+ public function getUidAndFilenameCallback() {
+ $args = func_get_args();
+
+ $path = $args[0];
+ $parts = explode('/', $path);
+
+ return array($parts[1], '/' . implode('/', array_slice($parts, 2)));
+ }
+
+ public function dataProviderCopyRename() {
+ return array(
+ array('/user1/files/foo.txt', '/user1/files/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
+ array('/user1/files/foo/foo.txt', '/user1/files/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
+ array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/foo/bar.txt/'),
+ array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', true,
+ '/files_encryption/keys/files/foo.txt/', '/files_encryption/keys/files/foo/bar.txt/'),
);
}
+ public function testKeySetPreparation() {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('mkdir')
+ ->will($this->returnCallback(array($this, 'mkdirCallback')));
+
+ $this->mkdirStack = array(
+ '/user1/files_encryption/keys/foo',
+ '/user1/files_encryption/keys',
+ '/user1/files_encryption',
+ '/user1');
+
+ \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
+ }
+
+ public function mkdirCallback() {
+ $args = func_get_args();
+ $expected = array_pop($this->mkdirStack);
+ $this->assertSame($expected, $args[0]);
+ }
+
}
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
index ab297bae0cb..4fcbc3b9983 100644
--- a/tests/lib/encryption/managertest.php
+++ b/tests/lib/encryption/managertest.php
@@ -111,4 +111,62 @@ class ManagerTest extends TestCase {
$en0 = $m->getEncryptionModule(0);
$this->assertEquals(0, $en0->getId());
}
+
+// /**
+// * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
+// * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
+// */
+// public function testModuleRegistration() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->registerEncryptionModule($em);
+// }
+//
+// public function testModuleUnRegistration() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->unregisterEncryptionModule($em);
+// $this->assertFalse($m->isEnabled());
+// }
+//
+// /**
+// * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
+// * @expectedExceptionMessage Module with id: unknown does not exists.
+// */
+// public function testGetEncryptionModuleUnknown() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->getEncryptionModule('unknown');
+// }
+//
+// public function testGetEncryptionModule() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $en0 = $m->getEncryptionModule(0);
+// $this->assertEquals(0, $en0->getId());
+// }
}
diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php
index 672f9ff5e97..03aefe61151 100644
--- a/tests/lib/encryption/utiltest.php
+++ b/tests/lib/encryption/utiltest.php
@@ -20,6 +20,9 @@ class UtilTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
public function setUp() {
parent::setUp();
$this->view = $this->getMockBuilder('OC\Files\View')
@@ -29,13 +32,18 @@ class UtilTest extends TestCase {
$this->userManager = $this->getMockBuilder('OC\User\Manager')
->disableOriginalConstructor()
->getMock();
+
+ $this->config = $this->getMockBuilder('OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
}
/**
* @dataProvider providesHeadersForEncryptionModule
*/
public function testGetEncryptionModuleId($expected, $header) {
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$id = $u->getEncryptionModuleId($header);
$this->assertEquals($expected, $id);
}
@@ -53,7 +61,7 @@ class UtilTest extends TestCase {
*/
public function testReadHeader($header, $expected, $moduleId) {
$expected['oc_encryption_module'] = $moduleId;
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$result = $u->readHeader($header);
$this->assertSameSize($expected, $result);
foreach ($expected as $key => $value) {
@@ -70,7 +78,7 @@ class UtilTest extends TestCase {
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em->expects($this->any())->method('getId')->willReturn($moduleId);
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$result = $u->createHeader($header, $em);
$this->assertEquals($expected, $result);
}
@@ -94,7 +102,7 @@ class UtilTest extends TestCase {
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em->expects($this->any())->method('getId')->willReturn('moduleId');
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$u->createHeader($header, $em);
}
@@ -107,7 +115,7 @@ class UtilTest extends TestCase {
->method('userExists')
->will($this->returnCallback(array($this, 'isExcludedCallback')));
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$this->assertSame($expected,
$u->isExcluded($path)
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index f0ad6cf3ab1..9a64375f4e3 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -183,8 +183,8 @@ class Cache extends \Test\TestCase {
$file3 = 'folder/foo';
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
$fileData = array();
- $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
- $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $fileData['bar'] = array('size' => 1000, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
$this->cache->put($file1, $data1);
$this->cache->put($file2, $fileData['bar']);
@@ -194,8 +194,6 @@ class Cache extends \Test\TestCase {
$this->assertEquals(count($content), 2);
foreach ($content as $cachedData) {
$data = $fileData[$cachedData['name']];
- // indirect retrieval swaps unencrypted_size and size
- $this->assertEquals($data['unencrypted_size'], $cachedData['size']);
}
$file4 = 'folder/unkownSize';
@@ -207,11 +205,10 @@ class Cache extends \Test\TestCase {
$fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
$this->cache->put($file4, $fileData['unkownSize']);
- $this->assertEquals(916, $this->cache->calculateFolderSize($file1));
+ $this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
// direct cache entry retrieval returns the original values
$entry = $this->cache->get($file1);
$this->assertEquals(1025, $entry['size']);
- $this->assertEquals(916, $entry['unencrypted_size']);
$this->cache->remove($file2);
$this->cache->remove($file3);
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 970af2e68df..7c3ebd5a6f9 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -33,16 +33,12 @@ class Updater extends \Test\TestCase {
*/
protected $updater;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
- $this->originalStorage = Filesystem::getStorage('/');
+ $this->loginAsUser();
$this->storage = new Temporary(array());
- Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/');
$this->view = new View('');
$this->updater = new \OC\Files\Cache\Updater($this->view);
@@ -51,8 +47,8 @@ class Updater extends \Test\TestCase {
protected function tearDown() {
Filesystem::clearMounts();
- Filesystem::mount($this->originalStorage, array(), '/');
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
index 99cacca8e95..f4d52e9a390 100644
--- a/tests/lib/files/cache/updaterlegacy.php
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -22,26 +22,16 @@ class UpdaterLegacy extends \Test\TestCase {
*/
private $scanner;
- private $stateFilesEncryption;
-
/**
* @var \OC\Files\Cache\Cache $cache
*/
private $cache;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
private static $user;
protected function setUp() {
parent::setUp();
- // remember files_encryption state
- $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
- // we want to tests with the encryption app disabled
- \OC_App::disable('files_encryption');
-
$this->storage = new \OC\Files\Storage\Temporary(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
@@ -55,14 +45,12 @@ class UpdaterLegacy extends \Test\TestCase {
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
- $this->originalStorage = Filesystem::getStorage('/');
- Filesystem::tearDown();
if (!self::$user) {
self::$user = $this->getUniqueID();
}
\OC_User::createUser(self::$user, 'password');
- \OC_User::setUserId(self::$user);
+ $this->loginAsUser(self::$user);
Filesystem::init(self::$user, '/' . self::$user . '/files');
@@ -78,13 +66,8 @@ class UpdaterLegacy extends \Test\TestCase {
}
$result = \OC_User::deleteUser(self::$user);
$this->assertTrue($result);
- Filesystem::tearDown();
- Filesystem::mount($this->originalStorage, array(), '/');
- // reset app files_encryption
- if ($this->stateFilesEncryption) {
- \OC_App::enable('files_encryption');
- }
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index ee605c64e01..e6947e36a17 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -15,14 +15,10 @@ class Watcher extends \Test\TestCase {
*/
private $storages = array();
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC\Files\Filesystem::clearMounts();
+ $this->loginAsUser();
}
protected function tearDown() {
@@ -32,9 +28,7 @@ class Watcher extends \Test\TestCase {
$cache->clear();
}
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
-
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php
index eec24d9f4c6..055927652bc 100644
--- a/tests/lib/files/etagtest.php
+++ b/tests/lib/files/etagtest.php
@@ -16,16 +16,11 @@ class EtagTest extends \Test\TestCase {
private $tmpDir;
- private $uid;
-
/**
* @var \OC_User_Dummy $userBackend
*/
private $userBackend;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
@@ -37,21 +32,15 @@ class EtagTest extends \Test\TestCase {
$this->datadir = \OC_Config::getValue('datadirectory');
$this->tmpDir = \OC_Helper::tmpFolder();
\OC_Config::setValue('datadirectory', $this->tmpDir);
- $this->uid = \OC_User::getUser();
- \OC_User::setUserId(null);
$this->userBackend = new \OC_User_Dummy();
\OC_User::useBackend($this->userBackend);
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC_Util::tearDownFS();
}
protected function tearDown() {
\OC_Config::setValue('datadirectory', $this->datadir);
- \OC_User::setUserId($this->uid);
- \OC_Util::setupFS($this->uid);
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+ $this->logout();
parent::tearDown();
}
@@ -59,9 +48,7 @@ class EtagTest extends \Test\TestCase {
$user1 = $this->getUniqueID('user_');
$this->userBackend->createUser($user1, '');
- \OC_Util::tearDownFS();
- \OC_User::setUserId($user1);
- \OC_Util::setupFS($user1);
+ $this->loginAsUser($user1);
Filesystem::mkdir('/folder');
Filesystem::mkdir('/folder/subfolder');
Filesystem::file_put_contents('/foo.txt', 'asd');
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 7bf59315d77..98e96e0cc78 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -28,9 +28,6 @@ class Filesystem extends \Test\TestCase {
*/
private $tmpDirs = array();
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
/**
* @return array
*/
@@ -42,20 +39,15 @@ class Filesystem extends \Test\TestCase {
protected function setUp() {
parent::setUp();
-
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC_User::setUserId('');
- \OC\Files\Filesystem::clearMounts();
+ $this->loginAsUser();
}
protected function tearDown() {
foreach ($this->tmpDirs as $dir) {
\OC_Helper::rmdirr($dir);
}
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
- \OC_User::setUserId('');
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index 456a4a0e287..4e362607240 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -20,9 +20,6 @@ class IntegrationTests extends \Test\TestCase {
*/
private $root;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
/**
* @var \OC\Files\Storage\Storage[]
*/
@@ -36,9 +33,6 @@ class IntegrationTests extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC\Files\Filesystem::init('', '');
- \OC\Files\Filesystem::clearMounts();
$manager = \OC\Files\Filesystem::getMountManager();
\OC_Hook::clear('OC_Filesystem');
@@ -49,7 +43,8 @@ class IntegrationTests extends \Test\TestCase {
\OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');
$user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
- \OC_User::setUserId($user->getUID());
+ $this->loginAsUser($user->getUID());
+
$this->view = new View();
$this->root = new Root($manager, $this->view, $user);
$storage = new Temporary(array());
@@ -64,9 +59,8 @@ class IntegrationTests extends \Test\TestCase {
foreach ($this->storages as $storage) {
$storage->getCache()->clear();
}
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 30f403d60df..938fecb5bf3 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -104,13 +104,14 @@ abstract class Storage extends \Test\TestCase {
}
public function directoryProvider() {
- return array(
- array('folder'),
- array(' folder'),
- array('folder '),
- array('folder with space'),
- array('spéciäl földer'),
- );
+ return [
+ ['folder'],
+ [' folder'],
+ ['folder '],
+ ['folder with space'],
+ ['spéciäl földer'],
+ ['test single\'quote'],
+ ];
}
function loremFileProvider() {
@@ -163,15 +164,16 @@ abstract class Storage extends \Test\TestCase {
public function copyAndMoveProvider() {
- return array(
- array('/source.txt', '/target.txt'),
- array('/source.txt', '/target with space.txt'),
- array('/source with space.txt', '/target.txt'),
- array('/source with space.txt', '/target with space.txt'),
- array('/source.txt', '/tärgét.txt'),
- array('/sòurcē.txt', '/target.txt'),
- array('/sòurcē.txt', '/tärgét.txt'),
- );
+ return [
+ ['/source.txt', '/target.txt'],
+ ['/source.txt', '/target with space.txt'],
+ ['/source with space.txt', '/target.txt'],
+ ['/source with space.txt', '/target with space.txt'],
+ ['/source.txt', '/tärgét.txt'],
+ ['/sòurcē.txt', '/target.txt'],
+ ['/sòurcē.txt', '/tärgét.txt'],
+ ['/single \' quote.txt', '/tar\'get.txt'],
+ ];
}
public function initSourceAndTarget ($source, $target = null) {
@@ -251,7 +253,7 @@ abstract class Storage extends \Test\TestCase {
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$localFile = $this->instance->getLocalFile('/lorem.txt');
$this->assertTrue(file_exists($localFile));
- $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile));
+ $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile));
$this->instance->mkdir('/folder');
$this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile));
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
new file mode 100644
index 00000000000..bf4464f0eb9
--- /dev/null
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -0,0 +1,125 @@
+<?php
+
+namespace Test\Files\Storage\Wrapper;
+
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+
+class Encryption extends \Test\Files\Storage\Storage {
+
+ /**
+ * @var Temporary
+ */
+ private $sourceStorage;
+
+ public function setUp() {
+
+ parent::setUp();
+
+ $mockModule = $this->buildMockModule();
+ $encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
+ ->disableOriginalConstructor()
+ ->setMethods(['getDefaultEncryptionModule', 'getEncryptionModule', 'isEnabled'])
+ ->getMock();
+ $encryptionManager->expects($this->any())
+ ->method('getDefaultEncryptionModule')
+ ->willReturn($mockModule);
+ $encryptionManager->expects($this->any())
+ ->method('getEncryptionModule')
+ ->willReturn($mockModule);
+ $encryptionManager->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(true);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]);
+ $util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->willReturnCallback(function ($path) {
+ return ['user1', $path];
+ });
+
+ $file = $this->getMockBuilder('\OC\Encryption\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $logger = $this->getMock('\OC\Log');
+
+ $this->sourceStorage = new Temporary(array());
+ $keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
+ ->disableOriginalConstructor()->getMock();
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->setMethods(['getOption'])
+ ->getMock();
+ $mount->expects($this->any())->method('getOption')->willReturn(true);
+ $this->instance = new EncryptionWrapper([
+ 'storage' => $this->sourceStorage,
+ 'root' => 'foo',
+ 'mountPoint' => '/',
+ 'mount' => $mount
+ ],
+ $encryptionManager, $util, $logger, $file, null, $keyStore
+ );
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function buildMockModule() {
+ $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ ->disableOriginalConstructor()
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->getMock();
+
+ $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
+ $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
+ $encryptionModule->expects($this->any())->method('begin')->willReturn([]);
+ $encryptionModule->expects($this->any())->method('end')->willReturn('');
+ $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('update')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
+ $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ return $encryptionModule;
+ }
+
+// public function testMkDirRooted() {
+// $this->instance->mkdir('bar');
+// $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
+// }
+//
+// public function testFilePutContentsRooted() {
+// $this->instance->file_put_contents('bar', 'asd');
+// $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
+// }
+}
+
+//
+// FIXME: this is too bad and needs adjustment
+//
+class EncryptionWrapper extends \OC\Files\Storage\Wrapper\Encryption {
+ private $keyStore;
+
+ public function __construct(
+ $parameters,
+ \OC\Encryption\Manager $encryptionManager = null,
+ \OC\Encryption\Util $util = null,
+ \OC\Log $logger = null,
+ \OC\Encryption\File $fileHelper = null,
+ $uid = null,
+ $keyStore = null
+ ) {
+ $this->keyStore = $keyStore;
+ parent::__construct($parameters, $encryptionManager, $util, $logger, $fileHelper, $uid);
+ }
+
+ protected function getKeyStorage($encryptionModuleId) {
+ return $this->keyStore;
+ }
+
+}
diff --git a/tests/lib/files/storage/wrapper/jail.php b/tests/lib/files/storage/wrapper/jail.php
index 270ce750ecf..a7bd684df44 100644
--- a/tests/lib/files/storage/wrapper/jail.php
+++ b/tests/lib/files/storage/wrapper/jail.php
@@ -9,10 +9,6 @@
namespace Test\Files\Storage\Wrapper;
class Jail extends \Test\Files\Storage\Storage {
- /**
- * @var string tmpDir
- */
- private $tmpDir;
/**
* @var \OC\Files\Storage\Temporary
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 8ca8f308b71..a5828296be9 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -59,7 +59,7 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpace() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
- '', array('size' => 3, 'unencrypted_size' => 0)
+ '', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@@ -77,7 +77,7 @@ class Quota extends \Test\Files\Storage\Storage {
$instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 9));
$instance->getCache()->put(
- '', array('size' => 3, 'unencrypted_size' => 0)
+ '', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@@ -85,9 +85,9 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpaceAndEncryption() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
- '', array('size' => 7, 'unencrypted_size' => 3)
+ '', array('size' => 7)
);
- $this->assertEquals(6, $instance->free_space(''));
+ $this->assertEquals(2, $instance->free_space(''));
}
public function testFWriteNotEnoughSpace() {
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
new file mode 100644
index 00000000000..84156337ad7
--- /dev/null
+++ b/tests/lib/files/stream/encryption.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Test\Files\Stream;
+
+use OC\Files\View;
+use OCA\Encryption_Dummy\DummyModule;
+
+class Encryption extends \Test\TestCase {
+
+ /**
+ * @param string $mode
+ * @param integer $limit
+ */
+ protected function getStream($fileName, $mode, $unencryptedSize) {
+
+ $size = filesize($fileName);
+ $source = fopen($fileName, $mode);
+ $internalPath = $fileName;
+ $fullPath = $fileName;
+ $header = [];
+ $uid = '';
+ $encryptionModule = $this->buildMockModule();
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()->getMock();
+ $encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ ->disableOriginalConstructor()->getMock();
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $file = $this->getMockBuilder('\OC\Encryption\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]);
+ $util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->willReturn(['user1', $internalPath]);
+
+ return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
+ $fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
+ $util, $file, $mode, $size, $unencryptedSize);
+ }
+
+ public function testWriteRead() {
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ fclose($stream);
+
+ $stream = $this->getStream($fileName, 'r', 6);
+ $this->assertEquals('foobar', fread($stream, 100));
+ fclose($stream);
+ }
+
+ public function testSeek() {
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ $this->assertEquals(0, fseek($stream, 3));
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ fclose($stream);
+
+ $stream = $this->getStream($fileName, 'r', 9);
+ $this->assertEquals('foofoobar', fread($stream, 100));
+ fclose($stream);
+ }
+
+ public function testWriteReadBigFile() {
+ $expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/lorem-big.txt');
+ // write it
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ fwrite($stream, $expectedData);
+ fclose($stream);
+
+ // read it all
+ $stream = $this->getStream($fileName, 'r', strlen($expectedData));
+ $data = stream_get_contents($stream);
+ fclose($stream);
+
+ $this->assertEquals($expectedData, $data);
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function buildMockModule() {
+ $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ ->disableOriginalConstructor()
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->getMock();
+
+ $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
+ $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
+ $encryptionModule->expects($this->any())->method('begin')->willReturn([]);
+ $encryptionModule->expects($this->any())->method('end')->willReturn('');
+ $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('update')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
+ $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ return $encryptionModule;
+ }
+}
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index 65ddfe47514..dfc683c1bcf 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -39,18 +39,14 @@ class TestScanner extends \OC\Files\Utils\Scanner {
}
class Scanner extends \Test\TestCase {
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+ $this->loginAsUser();
}
protected function tearDown() {
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
-
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index cd9f2d4afd1..2ea9e8de78f 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -27,9 +27,6 @@ class View extends \Test\TestCase {
/** @var \OC\Files\Storage\Storage */
private $tempStorage;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
@@ -39,9 +36,10 @@ class View extends \Test\TestCase {
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
- \OC_User::setUserId('test');
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+ $this->loginAsUser('test');
+ // clear mounts but somehow keep the root storage
+ // that was initialized above...
\OC\Files\Filesystem::clearMounts();
$this->tempStorage = null;
@@ -59,9 +57,7 @@ class View extends \Test\TestCase {
system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir()));
}
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
-
+ $this->logout();
parent::tearDown();
}
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index e3462caf806..76996a2b9bb 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -448,7 +448,7 @@ class Manager extends \Test\TestCase {
$userBackend = $this->getMock('\OC_User_Backend');
$userManager->expects($this->any())
- ->method('search')
+ ->method('searchDisplayName')
->with('user3')
->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
switch($offset) {
@@ -513,7 +513,7 @@ class Manager extends \Test\TestCase {
$userBackend = $this->getMock('\OC_User_Backend');
$userManager->expects($this->any())
- ->method('search')
+ ->method('searchDisplayName')
->with('user3')
->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
switch($offset) {
@@ -580,7 +580,7 @@ class Manager extends \Test\TestCase {
$userBackend = $this->getMock('\OC_User_Backend');
$userManager->expects($this->any())
- ->method('search')
+ ->method('searchDisplayName')
->with('user3')
->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
switch($offset) {
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 2a6761403f4..ea9de9b777e 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -26,6 +26,8 @@ class Preview extends TestCase {
protected function setUp() {
parent::setUp();
+ // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout()
+ // (would currently break the tests for some reason)
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
// create a new user with his own filesystem view
@@ -48,6 +50,77 @@ class Preview extends TestCase {
parent::tearDown();
}
+ public function testIsMaxSizeWorking() {
+ // Max size from config
+ $maxX = 1024;
+ $maxY = 1024;
+
+ \OC::$server->getConfig()->setSystemValue('preview_max_x', $maxX);
+ \OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY);
+
+ // Sample is 1680x1050 JPEG
+ $sampleFile = '/' . $this->user . '/files/testimage.jpg';
+ $this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ $fileInfo = $this->rootView->getFileInfo($sampleFile);
+ $fileId = $fileInfo['fileid'];
+
+ $largeX = 1920;
+ $largeY = 1080;
+ $preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $largeX, $largeY);
+
+ $this->assertEquals($preview->isFileValid(), true);
+
+ // There should be no cached copy
+ $isCached = $preview->isCached($fileId);
+
+ $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png', $isCached);
+ $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached);
+ $this->assertNotEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $largeX . '-' . $largeY . '.png', $isCached);
+
+ // The returned preview should be of max size
+ $image = $preview->getPreview();
+
+ $this->assertEquals($image->width(), $maxX);
+ $this->assertEquals($image->height(), $maxY);
+
+ // The max thumbnail should be created
+ $maxThumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png';
+
+ $this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true);
+
+ // A preview of the asked size should not have been created
+ $thumbCacheFile = \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $largeX . '-' . $largeY . '.png';
+
+ $this->assertEquals($this->rootView->file_exists($thumbCacheFile), false);
+
+ // 2nd request should indicate that we have a cached copy of max dimension
+ $isCached = $preview->isCached($fileId);
+ $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached);
+
+ // Smaller previews should be based on the cached max preview
+ $smallX = 50;
+ $smallY = 50;
+ $preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $smallX, $smallY);
+ $isCached = $preview->isCached($fileId);
+
+ $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached);
+
+ // A small preview should be created
+ $image = $preview->getPreview();
+ $this->assertEquals($image->width(), $smallX);
+ $this->assertEquals($image->height(), $smallY);
+
+ // The cache should contain the small preview
+ $thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png';
+
+ $this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
+
+ // 2nd request should indicate that we have a cached copy of the exact dimension
+ $isCached = $preview->isCached($fileId);
+
+ $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png', $isCached);
+ }
+
public function testIsPreviewDeleted() {
$sampleFile = '/'.$this->user.'/files/test.txt';
@@ -96,25 +169,6 @@ class Preview extends TestCase {
$this->assertEquals($this->rootView->is_dir($thumbCacheFolder), false);
}
- public function testIsMaxSizeWorking() {
-
- $maxX = 250;
- $maxY = 250;
-
- \OC_Config::setValue('preview_max_x', $maxX);
- \OC_Config::setValue('preview_max_y', $maxY);
-
- $sampleFile = '/'.$this->user.'/files/test.txt';
-
- $this->rootView->file_put_contents($sampleFile, 'dummy file data');
-
- $preview = new \OC\Preview($this->user, 'files/', 'test.txt', 1000, 1000);
- $image = $preview->getPreview();
-
- $this->assertEquals($image->width(), $maxX);
- $this->assertEquals($image->height(), $maxY);
- }
-
public function txtBlacklist() {
$txt = 'random text file';
diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php
index efae25f7e7a..40ffc14612b 100644
--- a/tests/lib/repair/repairmimetypes.php
+++ b/tests/lib/repair/repairmimetypes.php
@@ -221,15 +221,52 @@ class RepairMimeTypes extends \Test\TestCase {
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
}
+ /**
+ * Test renaming the 3D image media type
+ */
public function testRename3dImagesMimeType() {
$currentMimeTypes = [
- ['test.eps', 'application/octet-stream'],
- ['test.ps', 'application/octet-stream'],
+ ['test.jps', 'application/octet-stream'],
+ ['test.mpo', 'application/octet-stream'],
];
$fixedMimeTypes = [
- ['test.eps', 'application/postscript'],
- ['test.ps', 'application/postscript'],
+ ['test.jps', 'image/jpeg'],
+ ['test.mpo', 'image/jpeg'],
+ ];
+
+ $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
+ }
+
+ /**
+ * Test renaming the conf/cnf media type
+ */
+ public function testRenameConfMimeType() {
+ $currentMimeTypes = [
+ ['test.conf', 'application/octet-stream'],
+ ['test.cnf', 'application/octet-stream'],
+ ];
+
+ $fixedMimeTypes = [
+ ['test.conf', 'text/plain'],
+ ['test.cnf', 'text/plain'],
+ ];
+
+ $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
+ }
+
+ /**
+ * Test renaming the yaml media type
+ */
+ public function testRenameYamlMimeType() {
+ $currentMimeTypes = [
+ ['test.yaml', 'application/octet-stream'],
+ ['test.yml', 'application/octet-stream'],
+ ];
+
+ $fixedMimeTypes = [
+ ['test.yaml', 'application/yaml'],
+ ['test.yml', 'application/yaml'],
];
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
@@ -348,6 +385,10 @@ class RepairMimeTypes extends \Test\TestCase {
['test.DNG', 'image/x-dcraw'],
['test.jps', 'image/jpeg'],
['test.MPO', 'image/jpeg'],
+ ['test.conf', 'text/plain'],
+ ['test.cnf', 'text/plain'],
+ ['test.yaml', 'application/yaml'],
+ ['test.yml', 'application/yaml'],
];
$fixedMimeTypes = [
@@ -383,6 +424,10 @@ class RepairMimeTypes extends \Test\TestCase {
['test.DNG', 'image/x-dcraw'],
['test.jps', 'image/jpeg'],
['test.MPO', 'image/jpeg'],
+ ['test.conf', 'text/plain'],
+ ['test.cnf', 'text/plain'],
+ ['test.yaml', 'application/yaml'],
+ ['test.yml', 'application/yaml'],
];
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index f35a0fa8e43..523f7b379a0 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1128,6 +1128,240 @@ class Test_Share extends \Test\TestCase {
\OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days');
\OC_Appconfig::deleteKey('core', 'shareapi_enforce_expire_date');
}
+
+ /**
+ * Cannot set password is there is no user
+ *
+ * @expectedException Exception
+ * @expectedExceptionMessage User not logged in
+ */
+ public function testSetPasswordNoUser() {
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $connection = $this->getMockBuilder('\OC\DB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
+ }
+
+ /**
+ * Test setting a password when everything is fine
+ */
+ public function testSetPassword() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->method('getUID')->willReturn('user');
+
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userSession->method('getUser')->willReturn($user);
+
+
+ $ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb->method('update')->will($this->returnSelf());
+ $qb->method('set')->will($this->returnSelf());
+ $qb->method('where')->will($this->returnSelf());
+ $qb->method('andWhere')->will($this->returnSelf());
+ $qb->method('select')->will($this->returnSelf());
+ $qb->method('from')->will($this->returnSelf());
+ $qb->method('setParameter')->will($this->returnSelf());
+ $qb->method('expr')->willReturn($ex);
+
+ $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $ret->method('fetch')->willReturn(['uid_owner' => 'user']);
+ $qb->method('execute')->willReturn($ret);
+
+
+ $connection = $this->getMockBuilder('\OC\DB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $connection->method('createQueryBuilder')->willReturn($qb);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+
+ $res = \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
+
+ $this->assertTrue($res);
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Cannot remove password
+ *
+ * Test removing a password when password is enforced
+ */
+ public function testSetPasswordRemove() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->method('getUID')->willReturn('user');
+
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userSession->method('getUser')->willReturn($user);
+
+
+ $ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb->method('update')->will($this->returnSelf());
+ $qb->method('select')->will($this->returnSelf());
+ $qb->method('from')->will($this->returnSelf());
+ $qb->method('set')->will($this->returnSelf());
+ $qb->method('where')->will($this->returnSelf());
+ $qb->method('andWhere')->will($this->returnSelf());
+ $qb->method('setParameter')->will($this->returnSelf());
+ $qb->method('expr')->willReturn($ex);
+
+ $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $ret->method('fetch')->willReturn(['uid_owner' => 'user']);
+ $qb->method('execute')->willReturn($ret);
+
+
+ $connection = $this->getMockBuilder('\OC\DB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $connection->method('createQueryBuilder')->willReturn($qb);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $config->method('getAppValue')->willReturn('yes');
+
+ \OC\Share\Share::setPassword($userSession, $connection, $config, 1, '');
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Share not found
+ *
+ * Test modification of invaid share
+ */
+ public function testSetPasswordInvalidShare() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->method('getUID')->willReturn('user');
+
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userSession->method('getUser')->willReturn($user);
+
+
+ $ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb->method('update')->will($this->returnSelf());
+ $qb->method('set')->will($this->returnSelf());
+ $qb->method('where')->will($this->returnSelf());
+ $qb->method('andWhere')->will($this->returnSelf());
+ $qb->method('select')->will($this->returnSelf());
+ $qb->method('from')->will($this->returnSelf());
+ $qb->method('setParameter')->will($this->returnSelf());
+ $qb->method('expr')->willReturn($ex);
+
+ $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $ret->method('fetch')->willReturn([]);
+ $qb->method('execute')->willReturn($ret);
+
+
+ $connection = $this->getMockBuilder('\OC\DB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $connection->method('createQueryBuilder')->willReturn($qb);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+
+ \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Cannot update share of a different user
+ *
+ * Test modification of share of another user
+ */
+ public function testSetPasswordShareOtherUser() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->method('getUID')->willReturn('user');
+
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userSession->method('getUser')->willReturn($user);
+
+
+ $ex = $this->getMockBuilder('\Doctrine\DBAL\Query\Expression\ExpressionBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $qb->method('update')->will($this->returnSelf());
+ $qb->method('set')->will($this->returnSelf());
+ $qb->method('where')->will($this->returnSelf());
+ $qb->method('andWhere')->will($this->returnSelf());
+ $qb->method('select')->will($this->returnSelf());
+ $qb->method('from')->will($this->returnSelf());
+ $qb->method('setParameter')->will($this->returnSelf());
+ $qb->method('expr')->willReturn($ex);
+
+ $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $ret->method('fetch')->willReturn(['uid_owner' => 'user2']);
+ $qb->method('execute')->willReturn($ret);
+
+
+ $connection = $this->getMockBuilder('\OC\DB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $connection->method('createQueryBuilder')->willReturn($qb);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+
+ \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
+ }
+
}
class DummyShareClass extends \OC\Share\Share {
diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php
index 2a8c8676c16..6216c5a4be8 100644
--- a/tests/lib/streamwrappers.php
+++ b/tests/lib/streamwrappers.php
@@ -21,6 +21,20 @@
*/
class Test_StreamWrappers extends \Test\TestCase {
+
+ private static $trashBinStatus;
+
+ public static function setUpBeforeClass() {
+ self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
+ \OC_App::disable('files_trashbin');
+ }
+
+ public static function tearDownAfterClass() {
+ if (self::$trashBinStatus) {
+ \OC_App::enable('files_trashbin');
+ }
+ }
+
public function testFakeDir() {
$items = array('foo', 'bar');
\OC\Files\Stream\Dir::register('test', $items);
@@ -58,6 +72,8 @@ class Test_StreamWrappers extends \Test\TestCase {
}
public function testOC() {
+ // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout()
+ // (would currently break the tests for some reason)
$originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index d532a3b01c0..e66dfb13353 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -71,7 +71,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
self::tearDownAfterClassCleanFileCache();
self::tearDownAfterClassCleanStrayDataFiles($dataDir);
self::tearDownAfterClassCleanStrayHooks();
- self::tearDownAfterClassCleanProxies();
parent::tearDownAfterClass();
}
@@ -165,22 +164,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
}
/**
- * Clean up the list of file proxies
- *
- * Also reenables file proxies, in case a test disabled them
- */
- static protected function tearDownAfterClassCleanProxies() {
- \OC_FileProxy::$enabled = true;
- \OC_FileProxy::clearProxies();
- }
-
- /**
* Login and setup FS as a given user,
* sets the given user as the current user.
*
- * @param string $user user id
+ * @param string $user user id or empty for a generic FS
*/
- static protected function loginAsUser($user) {
+ static protected function loginAsUser($user = '') {
self::logout();
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId($user);
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 49399c8cf01..e52a9fcc618 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -54,24 +54,27 @@ class Test_Util extends \Test\TestCase {
public function formatDateWithTZFromSessionData() {
return array(
- array(3, 'October 13, 2012 at 2:53:25 PM GMT+3'),
- array(15, 'October 13, 2012 at 11:53:25 AM GMT+0'),
- array(-13, 'October 13, 2012 at 11:53:25 AM GMT+0'),
- array(9.5, 'October 13, 2012 at 9:23:25 PM GMT+9:30'),
- array(-4.5, 'October 13, 2012 at 7:23:25 AM GMT-4:30'),
- array(15.5, 'October 13, 2012 at 11:53:25 AM GMT+0'),
+ array(3, 'October 13, 2012 at 2:53:25 PM GMT+3', 'Etc/GMT-3'),
+ array(15, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
+ array(-13, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
+ array(9.5, 'October 13, 2012 at 9:23:25 PM GMT+9:30', 'Australia/Darwin'),
+ array(-4.5, 'October 13, 2012 at 7:23:25 AM GMT-4:30', 'America/Caracas'),
+ array(15.5, 'October 13, 2012 at 11:53:25 AM GMT+0', 'UTC'),
);
}
/**
* @dataProvider formatDateWithTZFromSessionData
*/
- function testFormatDateWithTZFromSession($offset, $expected) {
+ function testFormatDateWithTZFromSession($offset, $expected, $expectedTimeZone) {
date_default_timezone_set("UTC");
$oldDateTimeFormatter = \OC::$server->query('DateTimeFormatter');
\OC::$server->getSession()->set('timezone', $offset);
- $newDateTimeFormatter = new \OC\DateTimeFormatter(\OC::$server->getDateTimeZone()->getTimeZone(), new \OC_L10N('lib', 'en'));
+
+ $selectedTimeZone = \OC::$server->getDateTimeZone()->getTimeZone(1350129205);
+ $this->assertEquals($expectedTimeZone, $selectedTimeZone->getName());
+ $newDateTimeFormatter = new \OC\DateTimeFormatter($selectedTimeZone, new \OC_L10N('lib', 'en'));
$this->setDateFormatter($newDateTimeFormatter);
$result = OC_Util::formatDate(1350129205, false);
diff --git a/tests/settings/controller/CheckSetupControllerTest.php b/tests/settings/controller/CheckSetupControllerTest.php
index fc17d2adc49..26f9f4e9459 100644
--- a/tests/settings/controller/CheckSetupControllerTest.php
+++ b/tests/settings/controller/CheckSetupControllerTest.php
@@ -22,11 +22,12 @@
namespace OC\Settings\Controller;
use OCP\AppFramework\Http\DataResponse;
-use Test\TestCase;
-use OCP\IRequest;
-use OCP\IConfig;
use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IURLGenerator;
use OC_Util;
+use Test\TestCase;
/**
* Class CheckSetupControllerTest
@@ -42,6 +43,8 @@ class CheckSetupControllerTest extends TestCase {
private $config;
/** @var IClientService */
private $clientService;
+ /** @var IURLGenerator */
+ private $urlGenerator;
/** @var OC_Util */
private $util;
@@ -58,12 +61,15 @@ class CheckSetupControllerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->util = $this->getMockBuilder('\OC_Util')
->disableOriginalConstructor()->getMock();
+ $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
+ ->disableOriginalConstructor()->getMock();
$this->checkSetupController = new CheckSetupController(
'settings',
$this->request,
$this->config,
$this->clientService,
+ $this->urlGenerator,
$this->util
);
}
@@ -218,12 +224,17 @@ class CheckSetupControllerTest extends TestCase {
$this->util->expects($this->once())
->method('isHtaccessWorking')
->will($this->returnValue(true));
+ $this->urlGenerator->expects($this->once())
+ ->method('linkToDocs')
+ ->with('admin-performance')
+ ->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance');
$expected = new DataResponse(
[
'serverHasInternetConnection' => false,
'dataDirectoryProtected' => true,
'isMemcacheConfigured' => true,
+ 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance',
]
);
$this->assertEquals($expected, $this->checkSetupController->check());