summaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/service/storagesservicetest.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-10-31 11:41:07 +0100
committerVincent Petry <pvince81@owncloud.com>2015-03-12 18:51:02 +0100
commitce94a998dd5a5801beef7874dd13752095e35de0 (patch)
tree8d91631f709549c40555dcb74e9976519f895ae2 /apps/files_external/tests/service/storagesservicetest.php
parent23cc3cc5f2f42166c37fbe03fa62d3dd1dbfe5ed (diff)
downloadnextcloud-server-ce94a998dd5a5801beef7874dd13752095e35de0.tar.gz
nextcloud-server-ce94a998dd5a5801beef7874dd13752095e35de0.zip
Use storage id + appframework for ext storage CRUD
- Added StorageConfig class to replace ugly arrays - Implemented StorageService and StorageController for Global and User storages - Async status checking for storages (from Xenopathic) - Auto-generate id for external storage configs (not the same as storage_id) - Refactor JS classes for external storage settings, this mostly moves/encapsulated existing global event handlers into the MountConfigListView class. - Added some JS unit tests for the external storage UI
Diffstat (limited to 'apps/files_external/tests/service/storagesservicetest.php')
-rw-r--r--apps/files_external/tests/service/storagesservicetest.php180
1 files changed, 180 insertions, 0 deletions
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php
new file mode 100644
index 00000000000..1e338b3948d
--- /dev/null
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -0,0 +1,180 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Vincent Petry
+ * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Files_external\Tests\Service;
+
+use \OC\Files\Filesystem;
+
+use \OCA\Files_external\NotFoundException;
+use \OCA\Files_external\Lib\StorageConfig;
+
+abstract class StoragesServiceTest extends \Test\TestCase {
+
+ /**
+ * @var StoragesService
+ */
+ protected $service;
+
+ /**
+ * Data directory
+ *
+ * @var string
+ */
+ protected $dataDir;
+
+ /**
+ * Hook calls
+ *
+ * @var array
+ */
+ protected static $hookCalls;
+
+ public function setUp() {
+ self::$hookCalls = array();
+ $config = \OC::$server->getConfig();
+ $this->dataDir = $config->getSystemValue(
+ 'datadirectory',
+ \OC::$SERVERROOT . '/data/'
+ );
+ \OC_Mount_Config::$skipTest = true;
+
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create_mount,
+ get_class($this), 'createHookCallback');
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_delete_mount,
+ get_class($this), 'deleteHookCallback');
+
+ }
+
+ public function tearDown() {
+ \OC_Mount_Config::$skipTest = false;
+ self::$hookCalls = array();
+ }
+
+ /**
+ * Creates a StorageConfig instance based on array data
+ *
+ * @param array data
+ *
+ * @return StorageConfig storage config instance
+ */
+ protected function makeStorageConfig($data) {
+ $storage = new StorageConfig();
+ if (isset($data['id'])) {
+ $storage->setId($data['id']);
+ }
+ $storage->setMountPoint($data['mountPoint']);
+ $storage->setBackendClass($data['backendClass']);
+ $storage->setBackendOptions($data['backendOptions']);
+ if (isset($data['applicableUsers'])) {
+ $storage->setApplicableUsers($data['applicableUsers']);
+ }
+ if (isset($data['applicableGroups'])) {
+ $storage->setApplicableGroups($data['applicableGroups']);
+ }
+ if (isset($data['priority'])) {
+ $storage->setPriority($data['priority']);
+ }
+ return $storage;
+ }
+
+
+ /**
+ * @expectedException \OCA\Files_external\NotFoundException
+ */
+ public function testNonExistingStorage() {
+ $storage = new StorageConfig(255);
+ $storage->setMountPoint('mountpoint');
+ $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $this->service->updateStorage($storage);
+ }
+
+ public function testDeleteStorage() {
+ $storage = new StorageConfig(255);
+ $storage->setMountPoint('mountpoint');
+ $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackendOptions(['password' => 'testPassword']);
+
+ $newStorage = $this->service->addStorage($storage);
+ $this->assertEquals(1, $newStorage->getId());
+
+ $newStorage = $this->service->removeStorage(1);
+
+ $caught = false;
+ try {
+ $this->service->getStorage(1);
+ } catch (NotFoundException $e) {
+ $caught = true;
+ }
+
+ $this->assertTrue($caught);
+ }
+
+ /**
+ * @expectedException \OCA\Files_external\NotFoundException
+ */
+ public function testDeleteUnexistingStorage() {
+ $this->service->removeStorage(255);
+ }
+
+ public static function createHookCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_create_mount,
+ 'params' => $params
+ );
+ }
+
+ public static function deleteHookCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_delete_mount,
+ 'params' => $params
+ );
+ }
+
+ /**
+ * Asserts hook call
+ *
+ * @param array $callData hook call data to check
+ * @param string $signal signal name
+ * @param string $mountPath mount path
+ * @param string $mountType mount type
+ * @param string $applicable applicable users
+ */
+ protected function assertHookCall($callData, $signal, $mountPath, $mountType, $applicable) {
+ $this->assertEquals($signal, $callData['signal']);
+ $params = $callData['params'];
+ $this->assertEquals(
+ $mountPath,
+ $params[Filesystem::signal_param_path]
+ );
+ $this->assertEquals(
+ $mountType,
+ $params[Filesystem::signal_param_mount_type]
+ );
+ $this->assertEquals(
+ $applicable,
+ $params[Filesystem::signal_param_users]
+ );
+ }
+}