summaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-05-10 17:34:10 +0200
committerRobin Appelman <robin@icewind.nl>2021-05-19 17:08:20 +0200
commited2396b045c7b10555d7f05df5f81d2d17a00caf (patch)
treea467de2d39cb89fb76b061246b92c7cf56940a82 /apps/files_external/tests
parentfd284f428dc15c0ebd4054fa5e4e9431d518bcb1 (diff)
downloadnextcloud-server-ed2396b045c7b10555d7f05df5f81d2d17a00caf.tar.gz
nextcloud-server-ed2396b045c7b10555d7f05df5f81d2d17a00caf.zip
better cleanup of filecache when deleting an external storage
this way it can delete the cache entries even with per-user credentials Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/Service/StoragesServiceTest.php40
-rw-r--r--apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php2
-rw-r--r--apps/files_external/tests/Service/UserStoragesServiceTest.php4
3 files changed, 36 insertions, 10 deletions
diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTest.php
index 9817c779a31..1e4707e05b5 100644
--- a/apps/files_external/tests/Service/StoragesServiceTest.php
+++ b/apps/files_external/tests/Service/StoragesServiceTest.php
@@ -40,7 +40,11 @@ use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\DBConfigService;
use OCA\Files_External\Service\StoragesService;
use OCP\AppFramework\IAppContainer;
+use OCP\Files\Cache\ICache;
use OCP\Files\Config\IUserMountCache;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Storage\IStorage;
+use OCP\IUser;
class CleaningDBConfig extends DBConfigService {
private $mountIds = [];
@@ -279,10 +283,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
'password' => 'testPassword',
'root' => 'someroot',
],
- 'webdav::test@example.com//someroot/',
- 0
+ 'webdav::test@example.com//someroot/'
],
- // special case with $user vars, cannot auto-remove the oc_storages entry
[
[
'host' => 'example.com',
@@ -290,8 +292,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
'password' => 'testPassword',
'root' => 'someroot',
],
- 'webdav::someone@example.com//someroot/',
- 1
+ 'webdav::someone@example.com//someroot/'
],
];
}
@@ -299,7 +300,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
/**
* @dataProvider deleteStorageDataProvider
*/
- public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) {
+ public function testDeleteStorage($backendOptions, $rustyStorageId) {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255);
@@ -315,6 +316,31 @@ abstract class StoragesServiceTest extends \Test\TestCase {
// access, which isn't possible within this test
$storageCache = new \OC\Files\Cache\Storage($rustyStorageId);
+ /** @var IUserMountCache $mountCache */
+ $mountCache = \OC::$server->get(IUserMountCache::class);
+ $mountCache->clear();
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn('test');
+ $cache = $this->createMock(ICache::class);
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getCache')->willReturn($cache);
+ $mount = $this->createMock(IMountPoint::class);
+ $mount->method('getStorage')
+ ->willReturn($storage);
+ $mount->method('getStorageId')
+ ->willReturn($rustyStorageId);
+ $mount->method('getNumericStorageId')
+ ->willReturn($storageCache->getNumericId());
+ $mount->method('getStorageRootId')
+ ->willReturn(1);
+ $mount->method('getMountPoint')
+ ->willReturn('dummy');
+ $mount->method('getMountId')
+ ->willReturn($id);
+ $mountCache->registerMounts($user, [
+ $mount
+ ]);
+
// get numeric id for later check
$numericId = $storageCache->getNumericId();
@@ -338,7 +364,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$result = $storageCheckQuery->execute();
$storages = $result->fetchAll();
$result->closeCursor();
- $this->assertCount($expectedCountAfterDeletion, $storages, "expected $expectedCountAfterDeletion storages, got " . json_encode($storages));
+ $this->assertCount(0, $storages, "expected 0 storages, got " . json_encode($storages));
}
protected function actualDeletedUnexistingStorageTest() {
diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
index c2f3f42ade8..2ad75c88940 100644
--- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
@@ -204,7 +204,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
/**
* @dataProvider deleteStorageDataProvider
*/
- public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) {
+ public function testDeleteStorage($backendOptions, $rustyStorageId) {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php
index c7bc660c538..e54fc6d515f 100644
--- a/apps/files_external/tests/Service/UserStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php
@@ -150,8 +150,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
/**
* @dataProvider deleteStorageDataProvider
*/
- public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) {
- parent::testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion);
+ public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ parent::testDeleteStorage($backendOptions, $rustyStorageId);
// hook called once for user (first one was during test creation)
$this->assertHookCall(