From bec093203896fe6475679e135e9db3142c7da706 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 6 Feb 2025 19:39:56 +0100 Subject: [PATCH] test: add test for shared storage root being changed after watcher Signed-off-by: Robin Appelman --- apps/files_sharing/tests/CacheTest.php | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 543a7e46495..1991f3e123a 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -6,9 +6,12 @@ */ namespace OCA\Files_Sharing\Tests; +use OC\Files\Filesystem; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Jail; use OCA\Files_Sharing\SharedStorage; +use OCP\Constants; +use OCP\Files\Cache\IWatcher; use OCP\Share\IShare; /** @@ -564,4 +567,38 @@ class CacheTest extends TestCase { $results = $sharedStorage->getCache()->search("foo.txt"); $this->assertCount(1, $results); } + + public function testWatcherRootChange() { + $sourceStorage = new Temporary(); + $sourceStorage->mkdir('shared'); + $sourceStorage->file_put_contents('shared/foo.txt', 'foo'); + $sourceStorage->getScanner()->scan(''); + $sourceStorage->getWatcher()->setPolicy(IWatcher::CHECK_ALWAYS); + $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $sourceStorage, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo'); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $node = $rootFolder->get('foo/shared'); + $this->assertEquals(3, $node->getSize()); + + $share = $this->shareManager->newShare(); + $share->setNode($node) + ->setShareType(IShare::TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER2) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(Constants::PERMISSION_ALL); + $share = $this->shareManager->createShare($share); + $share->setStatus(IShare::STATUS_ACCEPTED); + $this->shareManager->updateShare($share); + \OC_Util::tearDownFS(); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $view = Filesystem::getView(); + + $sourceStorage->rmdir('shared'); + + $this->assertFalse($view->getFileInfo('shared')); + } }