aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/controller/globalstoragescontrollertest.php4
-rw-r--r--apps/files_external/tests/controller/storagescontrollertest.php61
-rw-r--r--apps/files_external/tests/controller/userstoragescontrollertest.php51
-rw-r--r--apps/files_external/tests/dynamicmountconfig.php104
-rw-r--r--apps/files_external/tests/service/globalstoragesservicetest.php26
-rw-r--r--apps/files_external/tests/service/storagesservicetest.php47
-rw-r--r--apps/files_external/tests/service/userstoragesservicetest.php4
-rw-r--r--apps/files_external/tests/storageconfigtest.php8
8 files changed, 147 insertions, 158 deletions
diff --git a/apps/files_external/tests/controller/globalstoragescontrollertest.php b/apps/files_external/tests/controller/globalstoragescontrollertest.php
index fc58743454a..e1bfad8caf6 100644
--- a/apps/files_external/tests/controller/globalstoragescontrollertest.php
+++ b/apps/files_external/tests/controller/globalstoragescontrollertest.php
@@ -28,7 +28,9 @@ use \OCA\Files_external\NotFoundException;
class GlobalStoragesControllerTest extends StoragesControllerTest {
public function setUp() {
parent::setUp();
- $this->service = $this->getMock('\OCA\Files_external\Service\GlobalStoragesService');
+ $this->service = $this->getMockBuilder('\OCA\Files_external\Service\GlobalStoragesService')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->controller = new GlobalStoragesController(
'files_external',
diff --git a/apps/files_external/tests/controller/storagescontrollertest.php b/apps/files_external/tests/controller/storagescontrollertest.php
index 86874ef9786..f3e8c9afbac 100644
--- a/apps/files_external/tests/controller/storagescontrollertest.php
+++ b/apps/files_external/tests/controller/storagescontrollertest.php
@@ -47,11 +47,33 @@ abstract class StoragesControllerTest extends \Test\TestCase {
\OC_Mount_Config::$skipTest = false;
}
+ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OC\Files\Storage\SMB') {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getStorageClass')
+ ->willReturn($storageClass);
+ $backend->method('getClass')
+ ->willReturn($storageClass);
+ return $backend;
+ }
+
public function testAddStorage() {
+ $backend = $this->getBackendMock();
+ $backend->method('validateStorage')
+ ->willReturn(true);
+ $backend->method('isVisibleFor')
+ ->willReturn(true);
+
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('mount');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setBackendOptions([]);
$this->service->expects($this->once())
+ ->method('createStorage')
+ ->will($this->returnValue($storageConfig));
+ $this->service->expects($this->once())
->method('addStorage')
->will($this->returnValue($storageConfig));
@@ -71,10 +93,21 @@ abstract class StoragesControllerTest extends \Test\TestCase {
}
public function testUpdateStorage() {
+ $backend = $this->getBackendMock();
+ $backend->method('validateStorage')
+ ->willReturn(true);
+ $backend->method('isVisibleFor')
+ ->willReturn(true);
+
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('mount');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setBackendOptions([]);
$this->service->expects($this->once())
+ ->method('createStorage')
+ ->will($this->returnValue($storageConfig));
+ $this->service->expects($this->once())
->method('updateStorage')
->will($this->returnValue($storageConfig));
@@ -106,6 +139,14 @@ abstract class StoragesControllerTest extends \Test\TestCase {
* @dataProvider mountPointNamesProvider
*/
public function testAddOrUpdateStorageInvalidMountPoint($mountPoint) {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint($mountPoint);
+ $storageConfig->setBackend($this->getBackendMock());
+ $storageConfig->setBackendOptions([]);
+
+ $this->service->expects($this->exactly(2))
+ ->method('createStorage')
+ ->will($this->returnValue($storageConfig));
$this->service->expects($this->never())
->method('addStorage');
$this->service->expects($this->never())
@@ -138,6 +179,9 @@ abstract class StoragesControllerTest extends \Test\TestCase {
}
public function testAddOrUpdateStorageInvalidBackend() {
+ $this->service->expects($this->exactly(2))
+ ->method('createStorage')
+ ->will($this->throwException(new \InvalidArgumentException()));
$this->service->expects($this->never())
->method('addStorage');
$this->service->expects($this->never())
@@ -170,6 +214,20 @@ abstract class StoragesControllerTest extends \Test\TestCase {
}
public function testUpdateStorageNonExisting() {
+ $backend = $this->getBackendMock();
+ $backend->method('validateStorage')
+ ->willReturn(true);
+ $backend->method('isVisibleFor')
+ ->willReturn(true);
+
+ $storageConfig = new StorageConfig(255);
+ $storageConfig->setMountPoint('mount');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setBackendOptions([]);
+
+ $this->service->expects($this->once())
+ ->method('createStorage')
+ ->will($this->returnValue($storageConfig));
$this->service->expects($this->once())
->method('updateStorage')
->will($this->throwException(new NotFoundException()));
@@ -206,9 +264,10 @@ abstract class StoragesControllerTest extends \Test\TestCase {
}
public function testGetStorage() {
+ $backend = $this->getBackendMock();
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('test');
- $storageConfig->setBackendClass('\OC\Files\Storage\SMB');
+ $storageConfig->setBackend($backend);
$storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']);
$storageConfig->setMountOptions(['priority' => false]);
diff --git a/apps/files_external/tests/controller/userstoragescontrollertest.php b/apps/files_external/tests/controller/userstoragescontrollertest.php
index f9b4c5b2681..99825f26394 100644
--- a/apps/files_external/tests/controller/userstoragescontrollertest.php
+++ b/apps/files_external/tests/controller/userstoragescontrollertest.php
@@ -24,6 +24,8 @@ use \OCA\Files_external\Controller\UserStoragesController;
use \OCA\Files_external\Service\UserStoragesService;
use \OCP\AppFramework\Http;
use \OCA\Files_external\NotFoundException;
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Service\BackendService;
class UserStoragesControllerTest extends StoragesControllerTest {
@@ -44,41 +46,22 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$this->getMock('\OCP\IL10N'),
$this->service
);
-
- $config = \OC::$server->getConfig();
-
- $this->oldAllowedBackends = $config->getAppValue(
- 'files_external',
- 'user_mounting_backends',
- ''
- );
- $config->setAppValue(
- 'files_external',
- 'user_mounting_backends',
- '\OC\Files\Storage\SMB'
- );
}
- public function tearDown() {
- $config = \OC::$server->getConfig();
- $config->setAppValue(
- 'files_external',
- 'user_mounting_backends',
- $this->oldAllowedBackends
- );
- parent::tearDown();
- }
+ public function testAddOrUpdateStorageDisallowedBackend() {
+ $backend = $this->getBackendMock();
+ $backend->method('isVisibleFor')
+ ->with(BackendService::VISIBILITY_PERSONAL)
+ ->willReturn(false);
- function disallowedBackendClassProvider() {
- return array(
- array('\OC\Files\Storage\Local'),
- array('\OC\Files\Storage\FTP'),
- );
- }
- /**
- * @dataProvider disallowedBackendClassProvider
- */
- public function testAddOrUpdateStorageDisallowedBackend($backendClass) {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('mount');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setBackendOptions([]);
+
+ $this->service->expects($this->exactly(2))
+ ->method('createStorage')
+ ->will($this->returnValue($storageConfig));
$this->service->expects($this->never())
->method('addStorage');
$this->service->expects($this->never())
@@ -86,7 +69,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->create(
'mount',
- $backendClass,
+ '\OC\Files\Storage\SMB',
array(),
[],
[],
@@ -99,7 +82,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->update(
1,
'mount',
- $backendClass,
+ '\OC\Files\Storage\SMB',
array(),
[],
[],
diff --git a/apps/files_external/tests/dynamicmountconfig.php b/apps/files_external/tests/dynamicmountconfig.php
deleted file mode 100644
index 48791ca89a5..00000000000
--- a/apps/files_external/tests/dynamicmountconfig.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-require_once __DIR__ . '/../../../lib/base.php';
-
-/**
- * Class Test_Mount_Config_Dummy_Backend
- */
-class Test_Mount_Config_Dummy_Backend {
- public static $checkDependencies = true;
-
- public static function checkDependencies() {
- return self::$checkDependencies;
- }
-}
-
-/**
- * Class Test_Dynamic_Mount_Config
- */
-class Test_Dynamic_Mount_Config extends \Test\TestCase {
-
- private $backup;
-
- public function testRegistration() {
-
- // second registration shall return false
- $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array(
- 'backend' => 'Test Dummy',
- 'configuration' => array(),
- 'has_dependencies' => true));
-
- $this->assertTrue($result);
- }
-
- public function testDependencyGetBackend() {
-
- // is the backend listed?
- Test_Mount_Config_Dummy_Backend::$checkDependencies = true;
- $backEnds = OC_Mount_Config::getBackends();
- $this->assertArrayHasKey('Test_Mount_Config_Dummy_Backend', $backEnds);
-
- // backend shall not be listed
- Test_Mount_Config_Dummy_Backend::$checkDependencies = false;
-
- $backEnds = OC_Mount_Config::getBackends();
- $this->assertArrayNotHasKey('Test_Mount_Config_Dummy_Backend', $backEnds);
-
- }
-
- public function testCheckDependencies() {
-
- Test_Mount_Config_Dummy_Backend::$checkDependencies = true;
- $message = OC_Mount_Config::checkDependencies();
- $this->assertEmpty($message);
-
- // backend shall not be listed
- Test_Mount_Config_Dummy_Backend::$checkDependencies = array('dummy');
-
- $message = OC_Mount_Config::checkDependencies();
- $this->assertEquals('<br /><b>Note:</b> "dummy" is not installed. Mounting of <i>Test Dummy</i> is not possible. Please ask your system administrator to install it.',
- $message);
-
- }
-
- protected function setUp() {
- parent::setUp();
-
- $this->backup = OC_Mount_Config::setUp();
-
- // register dummy backend
- $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array(
- 'backend' => 'Test Dummy',
- 'configuration' => array(),
- 'has_dependencies' => true));
-
- $this->assertTrue($result);
- }
-
- protected function tearDown()
- {
- OC_Mount_Config::setUp($this->backup);
- parent::tearDown();
- }
-}
diff --git a/apps/files_external/tests/service/globalstoragesservicetest.php b/apps/files_external/tests/service/globalstoragesservicetest.php
index ac25f58b1d1..422f3543f35 100644
--- a/apps/files_external/tests/service/globalstoragesservicetest.php
+++ b/apps/files_external/tests/service/globalstoragesservicetest.php
@@ -29,7 +29,7 @@ use \OCA\Files_external\Lib\StorageConfig;
class GlobalStoragesServiceTest extends StoragesServiceTest {
public function setUp() {
parent::setUp();
- $this->service = new GlobalStoragesService();
+ $this->service = new GlobalStoragesService($this->backendService);
}
public function tearDown() {
@@ -59,7 +59,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
return [
// all users
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
'backendClass' => '\OC\Files\Storage\SMB',
'backendOptions' => [
@@ -70,11 +70,11 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
'applicableUsers' => [],
'applicableGroups' => [],
'priority' => 15,
- ]),
+ ],
],
// some users
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
'backendClass' => '\OC\Files\Storage\SMB',
'backendOptions' => [
@@ -85,11 +85,11 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
'applicableUsers' => ['user1', 'user2'],
'applicableGroups' => [],
'priority' => 15,
- ]),
+ ],
],
// some groups
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
'backendClass' => '\OC\Files\Storage\SMB',
'backendOptions' => [
@@ -100,11 +100,11 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
'applicableUsers' => [],
'applicableGroups' => ['group1', 'group2'],
'priority' => 15,
- ]),
+ ],
],
// both users and groups
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
'backendClass' => '\OC\Files\Storage\SMB',
'backendOptions' => [
@@ -115,7 +115,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
'applicableUsers' => ['user1', 'user2'],
'applicableGroups' => ['group1', 'group2'],
'priority' => 15,
- ]),
+ ],
],
];
}
@@ -123,7 +123,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
/**
* @dataProvider storageDataProvider
*/
- public function testAddStorage($storage) {
+ public function testAddStorage($storageParams) {
+ $storage = $this->makeStorageConfig($storageParams);
$newStorage = $this->service->addStorage($storage);
$this->assertEquals(1, $newStorage->getId());
@@ -132,7 +133,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$newStorage = $this->service->getStorage(1);
$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
- $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
$this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers());
$this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups());
@@ -148,7 +149,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
/**
* @dataProvider storageDataProvider
*/
- public function testUpdateStorage($updatedStorage) {
+ public function testUpdateStorage($updatedStorageParams) {
+ $updatedStorage = $this->makeStorageConfig($updatedStorageParams);
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
'backendClass' => '\OC\Files\Storage\SMB',
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php
index 36f68a83b11..99e179cc93a 100644
--- a/apps/files_external/tests/service/storagesservicetest.php
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -24,6 +24,7 @@ use \OC\Files\Filesystem;
use \OCA\Files_external\NotFoundException;
use \OCA\Files_external\Lib\StorageConfig;
+use \OCA\Files_External\Lib\BackendService;
abstract class StoragesServiceTest extends \Test\TestCase {
@@ -32,6 +33,9 @@ abstract class StoragesServiceTest extends \Test\TestCase {
*/
protected $service;
+ /** @var BackendService */
+ protected $backendService;
+
/**
* Data directory
*
@@ -55,6 +59,25 @@ abstract class StoragesServiceTest extends \Test\TestCase {
);
\OC_Mount_Config::$skipTest = true;
+ $this->backendService =
+ $this->getMockBuilder('\OCA\Files_External\Service\BackendService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $backends = [
+ '\OC\Files\Storage\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OC\Files\Storage\SMB'),
+ '\OC\Files\Storage\SFTP' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OC\Files\Storage\SFTP'),
+ ];
+ $this->backendService->method('getBackend')
+ ->will($this->returnCallback(function($backendClass) use ($backends) {
+ if (isset($backends[$backendClass])) {
+ return $backends[$backendClass];
+ }
+ return null;
+ }));
+ $this->backendService->method('getBackends')
+ ->will($this->returnValue($backends));
+
\OCP\Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_create_mount,
@@ -71,6 +94,17 @@ abstract class StoragesServiceTest extends \Test\TestCase {
self::$hookCalls = array();
}
+ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OC\Files\Storage\SMB') {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getStorageClass')
+ ->willReturn($storageClass);
+ $backend->method('getClass')
+ ->willReturn($storageClass);
+ return $backend;
+ }
+
/**
* Creates a StorageConfig instance based on array data
*
@@ -84,7 +118,12 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$storage->setId($data['id']);
}
$storage->setMountPoint($data['mountPoint']);
- $storage->setBackendClass($data['backendClass']);
+ if (!isset($data['backend'])) {
+ // data providers are run before $this->backendService is initialised
+ // so $data['backend'] can be specified directly
+ $data['backend'] = $this->backendService->getBackend($data['backendClass']);
+ }
+ $storage->setBackend($data['backend']);
$storage->setBackendOptions($data['backendOptions']);
if (isset($data['applicableUsers'])) {
$storage->setApplicableUsers($data['applicableUsers']);
@@ -106,16 +145,18 @@ abstract class StoragesServiceTest extends \Test\TestCase {
* @expectedException \OCA\Files_external\NotFoundException
*/
public function testNonExistingStorage() {
+ $backend = $this->backendService->getBackend('\OC\Files\Storage\SMB');
$storage = new StorageConfig(255);
$storage->setMountPoint('mountpoint');
- $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackend($backend);
$this->service->updateStorage($storage);
}
public function testDeleteStorage() {
+ $backend = $this->backendService->getBackend('\OC\Files\Storage\SMB');
$storage = new StorageConfig(255);
$storage->setMountPoint('mountpoint');
- $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackend($backend);
$storage->setBackendOptions(['password' => 'testPassword']);
$newStorage = $this->service->addStorage($storage);
diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php
index ab102741ee2..98a9993918a 100644
--- a/apps/files_external/tests/service/userstoragesservicetest.php
+++ b/apps/files_external/tests/service/userstoragesservicetest.php
@@ -40,7 +40,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
->method('getUser')
->will($this->returnValue($this->user));
- $this->service = new UserStoragesService($userSession);
+ $this->service = new UserStoragesService($this->backendService, $userSession);
// create home folder
mkdir($this->dataDir . '/' . $this->userId . '/');
@@ -76,7 +76,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$newStorage = $this->service->getStorage(1);
$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
- $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
$this->assertEquals(1, $newStorage->getId());
$this->assertEquals(0, $newStorage->getStatus());
diff --git a/apps/files_external/tests/storageconfigtest.php b/apps/files_external/tests/storageconfigtest.php
index c30a4935ce1..69edb36e707 100644
--- a/apps/files_external/tests/storageconfigtest.php
+++ b/apps/files_external/tests/storageconfigtest.php
@@ -26,9 +26,15 @@ use \OCA\Files_external\Lib\StorageConfig;
class StorageConfigTest extends \Test\TestCase {
public function testJsonSerialization() {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getClass')
+ ->willReturn('\OC\Files\Storage\SMB');
+
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('test');
- $storageConfig->setBackendClass('\OC\Files\Storage\SMB');
+ $storageConfig->setBackend($backend);
$storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123']);
$storageConfig->setPriority(128);
$storageConfig->setApplicableUsers(['user1', 'user2']);