Add unit tests for wrapStorage
This commit is contained in:
parent
9a4040c7ca
commit
50a31fa8f9
|
@ -26,7 +26,6 @@ use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException;
|
||||||
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
|
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
|
||||||
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Storage\Shared;
|
|
||||||
use OC\Files\Storage\Wrapper\Encryption;
|
use OC\Files\Storage\Wrapper\Encryption;
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
use OCP\Encryption\IEncryptionModule;
|
use OCP\Encryption\IEncryptionModule;
|
||||||
|
@ -404,7 +403,7 @@ class Util {
|
||||||
'mountPoint' => $mountPoint,
|
'mountPoint' => $mountPoint,
|
||||||
'mount' => $mount];
|
'mount' => $mount];
|
||||||
|
|
||||||
if (!($storage instanceof Shared)) {
|
if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')) {
|
||||||
$manager = \OC::$server->getEncryptionManager();
|
$manager = \OC::$server->getEncryptionManager();
|
||||||
$user = \OC::$server->getUserSession()->getUser();
|
$user = \OC::$server->getUserSession()->getUser();
|
||||||
$logger = \OC::$server->getLogger();
|
$logger = \OC::$server->getLogger();
|
||||||
|
|
|
@ -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']],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue