diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-10-06 16:47:59 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-10-06 17:33:16 +0200 |
commit | bbebffb60cef91553a7d73d7059c1e9278b1c3cb (patch) | |
tree | 43316afc4c589e3fb3251bad7ca85e01ad3d0947 /apps/files_external/tests | |
parent | 3413b766311c1936097d260544a5181695cd7822 (diff) | |
download | nextcloud-server-bbebffb60cef91553a7d73d7059c1e9278b1c3cb.tar.gz nextcloud-server-bbebffb60cef91553a7d73d7059c1e9278b1c3cb.zip |
Remove oc_storages entries after removing ext storages
When removing external storages, either system-wide or user-wide,
automatically remove the matching oc_storages and oc_filecache entries.
This can only work if the backend configuration doesn't contain any
substitution variable $user in which case the storage id cannot be
computed, so this case is ignored for now.
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r-- | apps/files_external/tests/service/storagesservicetest.php | 50 | ||||
-rw-r--r-- | apps/files_external/tests/service/userstoragesservicetest.php | 7 |
2 files changed, 53 insertions, 4 deletions
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php index 1bec543ff4c..7487ba459af 100644 --- a/apps/files_external/tests/service/storagesservicetest.php +++ b/apps/files_external/tests/service/storagesservicetest.php @@ -216,18 +216,57 @@ abstract class StoragesServiceTest extends \Test\TestCase { $this->service->updateStorage($storage); } - public function testDeleteStorage() { + public function deleteStorageDataProvider() { + return [ + // regular case, can properly delete the oc_storages entry + [ + [ + 'share' => 'share', + 'host' => 'example.com', + 'user' => 'test', + 'password' => 'testPassword', + 'root' => 'someroot', + ], + 'smb::test@example.com//share//someroot/', + 0 + ], + // special case with $user vars, cannot auto-remove the oc_storages entry + [ + [ + 'share' => 'share', + 'host' => 'example.com', + 'user' => '$user', + 'password' => 'testPassword', + 'root' => 'someroot', + ], + 'smb::someone@example.com//share//someroot/', + 1 + ], + ]; + } + + /** + * @dataProvider deleteStorageDataProvider + */ + public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); $storage->setMountPoint('mountpoint'); $storage->setBackend($backend); $storage->setAuthMechanism($authMechanism); - $storage->setBackendOptions(['password' => 'testPassword']); + $storage->setBackendOptions($backendOptions); $newStorage = $this->service->addStorage($storage); $this->assertEquals(1, $newStorage->getId()); + // manually trigger storage entry because normally it happens on first + // access, which isn't possible within this test + $storageCache = new \OC\Files\Cache\Storage($rustyStorageId); + + // get numeric id for later check + $numericId = $storageCache->getNumericId(); + $newStorage = $this->service->removeStorage(1); $caught = false; @@ -238,6 +277,13 @@ abstract class StoragesServiceTest extends \Test\TestCase { } $this->assertTrue($caught); + + // storage id was removed from oc_storages + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $storageCheckQuery = $qb->select('*') + ->from('storages') + ->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId))); + $this->assertCount($expectedCountAfterDeletion, $storageCheckQuery->execute()->fetchAll()); } /** diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php index f829f73f050..78f9231c3d1 100644 --- a/apps/files_external/tests/service/userstoragesservicetest.php +++ b/apps/files_external/tests/service/userstoragesservicetest.php @@ -138,8 +138,11 @@ class UserStoragesServiceTest extends StoragesServiceTest { $this->assertEmpty(self::$hookCalls); } - public function testDeleteStorage() { - parent::testDeleteStorage(); + /** + * @dataProvider deleteStorageDataProvider + */ + public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { + parent::testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion); // hook called once for user (first one was during test creation) $this->assertHookCall( |