[Pkg-owncloud-commits] [owncloud] 252/457: Add unit tests for wrapStorage
David Prévot
taffit at moszumanska.debian.org
Sun Jun 28 20:06:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch stable8
in repository owncloud.
commit 50a31fa8f905c3f9483137bc7b1e57cbf950d2c2
Author: Joas Schilling <nickvergessen at owncloud.com>
Date: Tue Jun 2 12:33:17 2015 +0200
Add unit tests for wrapStorage
---
lib/private/encryption/util.php | 3 +--
tests/lib/encryption/utiltest.php | 45 +++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php
index d233b71..16c09cd 100644
--- a/lib/private/encryption/util.php
+++ b/lib/private/encryption/util.php
@@ -26,7 +26,6 @@ use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException;
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
use OC\Files\Filesystem;
-use OC\Files\Storage\Shared;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
use OCP\Encryption\IEncryptionModule;
@@ -404,7 +403,7 @@ class Util {
'mountPoint' => $mountPoint,
'mount' => $mount];
- if (!($storage instanceof Shared)) {
+ if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')) {
$manager = \OC::$server->getEncryptionManager();
$user = \OC::$server->getUserSession()->getUser();
$logger = \OC::$server->getLogger();
diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php
index d3a4e21..d5f5ce4c 100644
--- a/tests/lib/encryption/utiltest.php
+++ b/tests/lib/encryption/utiltest.php
@@ -194,4 +194,49 @@ class UtilTest extends TestCase {
);
}
+ /**
+ * @dataProvider provideWrapStorage
+ */
+ public function testWrapStorage($expectedWrapped, $wrappedStorages) {
+ $storage = $this->getMockBuilder('OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ foreach ($wrappedStorages as $wrapper) {
+ $storage->expects($this->any())
+ ->method('instanceOfStorage')
+ ->willReturnMap([
+ [$wrapper, true],
+ ]);
+ }
+
+ $mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $returnedStorage = $this->util->wrapStorage('mountPoint', $storage, $mount);
+
+ $this->assertEquals(
+ $expectedWrapped,
+ $returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'),
+ 'Asserted that the storage is (not) wrapped with encryption'
+ );
+ }
+
+ public function provideWrapStorage() {
+ return [
+ // Wrap when not wrapped or not wrapped with storage
+ [true, []],
+ [true, ['OCA\Files_Trashbin\Storage']],
+
+ // Do not wrap shared storages
+ [false, ['OC\Files\Storage\Shared']],
+ [false, ['OCA\Files_Sharing\External\Storage']],
+ [false, ['OC\Files\Storage\OwnCloud']],
+ [false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage']],
+ [false, ['OC\Files\Storage\Shared', 'OC\Files\Storage\OwnCloud']],
+ [false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
+ [false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
+ ];
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list