summaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/controller/storagescontrollertest.php
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-08-11 18:45:07 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-19 10:05:11 +0100
commit37beb58c6f395523d8e2934870c5f52a8c6f6df0 (patch)
treeb14325a790ddaf7236c3f8c1939ce9ef10df58bb /apps/files_external/tests/controller/storagescontrollertest.php
parent74237a9c44192fb98944ea7f3c14fa6f22c0814b (diff)
downloadnextcloud-server-37beb58c6f395523d8e2934870c5f52a8c6f6df0.tar.gz
nextcloud-server-37beb58c6f395523d8e2934870c5f52a8c6f6df0.zip
Introduce BackendService for managing external storage backends
Backends are registered to the BackendService through new data structures: Backends are concrete classes, deriving from \OCA\Files_External\Lib\Backend\Backend. During construction, the various configuration parameters of the Backend can be set, in a design similar to Symfony Console. DefinitionParameter stores a parameter configuration for an external storage: name of parameter, human-readable name, type of parameter (text, password, hidden, checkbox), flags (optional or not). Storages in the StoragesController now get their parameters validated server-side (fixes a TODO).
Diffstat (limited to 'apps/files_external/tests/controller/storagescontrollertest.php')
-rw-r--r--apps/files_external/tests/controller/storagescontrollertest.php61
1 files changed, 60 insertions, 1 deletions
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]);