diff options
Diffstat (limited to 'apps/files_external/tests/service')
4 files changed, 100 insertions, 1 deletions
diff --git a/apps/files_external/tests/service/dbconfigservicetest.php b/apps/files_external/tests/service/dbconfigservicetest.php index d5b4ff1585d..bfb564c6663 100644 --- a/apps/files_external/tests/service/dbconfigservicetest.php +++ b/apps/files_external/tests/service/dbconfigservicetest.php @@ -230,4 +230,32 @@ class DBConfigServiceTest extends TestCase { $this->assertEquals($id1, $mounts[0]['mount_id']); $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']); } + + public function testSetMountPoint() { + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + + $this->dbConfig->setMountPoint($id1, '/asd'); + + $mount = $this->dbConfig->getMountById($id1); + $this->assertEquals('/asd', $mount['mount_point']); + + // remains unchanged + $mount = $this->dbConfig->getMountById($id2); + $this->assertEquals('/foo', $mount['mount_point']); + } + + public function testSetAuthBackend() { + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + + $this->dbConfig->setAuthBackend($id1, 'none'); + + $mount = $this->dbConfig->getMountById($id1); + $this->assertEquals('none', $mount['auth_backend']); + + // remains unchanged + $mount = $this->dbConfig->getMountById($id2); + $this->assertEquals('bar', $mount['auth_backend']); + } } diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php index 7847bd45d4a..d5430982899 100644 --- a/apps/files_external/tests/service/storagesservicetest.php +++ b/apps/files_external/tests/service/storagesservicetest.php @@ -465,4 +465,33 @@ abstract class StoragesServiceTest extends \Test\TestCase { $params[Filesystem::signal_param_users] ); } + + public function testUpdateStorageMountPoint() { + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); + + $storage = new StorageConfig(); + $storage->setMountPoint('mountpoint'); + $storage->setBackend($backend); + $storage->setAuthMechanism($authMechanism); + $storage->setBackendOptions(['password' => 'testPassword']); + + $savedStorage = $this->service->addStorage($storage); + + $newAuthMechanism = $this->backendService->getAuthMechanism('identifier:\Other\Auth\Mechanism'); + + $updatedStorage = new StorageConfig($savedStorage->getId()); + $updatedStorage->setMountPoint('mountpoint2'); + $updatedStorage->setBackend($backend); + $updatedStorage->setAuthMechanism($newAuthMechanism); + $updatedStorage->setBackendOptions(['password' => 'password2']); + + $this->service->updateStorage($updatedStorage); + + $savedStorage = $this->service->getStorage($updatedStorage->getId()); + + $this->assertEquals('/mountpoint2', $savedStorage->getMountPoint()); + $this->assertEquals($newAuthMechanism, $savedStorage->getAuthMechanism()); + $this->assertEquals('password2', $savedStorage->getBackendOption('password')); + } } diff --git a/apps/files_external/tests/service/userglobalstoragesservicetest.php b/apps/files_external/tests/service/userglobalstoragesservicetest.php index b8379288d43..d4c48b3f691 100644 --- a/apps/files_external/tests/service/userglobalstoragesservicetest.php +++ b/apps/files_external/tests/service/userglobalstoragesservicetest.php @@ -21,6 +21,7 @@ */ namespace OCA\Files_External\Tests\Service; +use OCA\Files_external\NotFoundException; use OCA\Files_external\Service\StoragesService; use \OCA\Files_External\Service\UserGlobalStoragesService; use \OCP\IGroupManager; @@ -140,6 +141,13 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint()); } else { $this->assertEquals(0, count($storages)); + + try { + $this->service->getStorage($newStorage->getId()); + $this->fail('Failed asserting that storage can\'t be accessed by id'); + } catch (NotFoundException $e) { + + } } } @@ -349,4 +357,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->assertTrue(true); } + public function testUpdateStorageMountPoint() { + // we don't test this here + $this->assertTrue(true); + } } diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php index 5e984c52bfd..a2d3819427c 100644 --- a/apps/files_external/tests/service/userstoragesservicetest.php +++ b/apps/files_external/tests/service/userstoragesservicetest.php @@ -23,6 +23,8 @@ namespace OCA\Files_external\Tests\Service; use \OC\Files\Filesystem; +use OCA\Files_external\Service\GlobalStoragesService; +use OCA\Files_external\Service\StoragesService; use \OCA\Files_external\Service\UserStoragesService; use \OCA\Files_external\NotFoundException; use \OCA\Files_external\Lib\StorageConfig; @@ -38,9 +40,16 @@ class UserStoragesServiceTest extends StoragesServiceTest { private $userId; + /** + * @var StoragesService + */ + protected $globalStoragesService; + public function setUp() { parent::setUp(); + $this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig); + $this->userId = $this->getUniqueID('user_'); $this->createUser($this->userId, $this->userId); $this->user = \OC::$server->getUserManager()->get($this->userId); @@ -122,8 +131,8 @@ class UserStoragesServiceTest extends StoragesServiceTest { $newStorage = $this->service->updateStorage($newStorage); $this->assertEquals('anotherPassword', $newStorage->getBackendOptions()['password']); + $this->assertEquals([$this->userId], $newStorage->getApplicableUsers()); // these attributes are unused for user storages - $this->assertEmpty($newStorage->getApplicableUsers()); $this->assertEmpty($newStorage->getApplicableGroups()); $this->assertEquals(0, $newStorage->getStatus()); @@ -174,4 +183,25 @@ class UserStoragesServiceTest extends StoragesServiceTest { $this->userId ); } + + /** + * @expectedException \OCA\Files_external\NotFoundException + */ + public function testGetAdminStorage() { + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); + + $storage = new StorageConfig(); + $storage->setMountPoint('mountpoint'); + $storage->setBackend($backend); + $storage->setAuthMechanism($authMechanism); + $storage->setBackendOptions(['password' => 'testPassword']); + $storage->setApplicableUsers([$this->userId]); + + $newStorage = $this->globalStoragesService->addStorage($storage); + + $this->assertInstanceOf('\OCA\Files_external\Lib\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId())); + + $this->service->getStorage($newStorage->getId()); + } } |