diff options
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 50 | ||||
-rw-r--r-- | apps/files_sharing/tests/EncryptedSizePropagationTest.php | 9 |
3 files changed, 54 insertions, 8 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 4ef9f536cb9..a712903d768 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -26,6 +26,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\ITagManager; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Mail\IMailer; @@ -111,6 +112,7 @@ class ApiTest extends TestCase { $logger = $this->createMock(LoggerInterface::class); $providerFactory = $this->createMock(IProviderFactory::class); $mailer = $this->createMock(IMailer::class); + $tagManager = $this->createMock(ITagManager::class); $dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get())); return new ShareAPIController( @@ -131,6 +133,7 @@ class ApiTest extends TestCase { $logger, $providerFactory, $mailer, + $tagManager, $userId, ); } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 29eae2dc581..02c133ee5d1 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -28,6 +28,8 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\ITagManager; +use OCP\ITags; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -76,6 +78,7 @@ class ShareAPIControllerTest extends TestCase { private LoggerInterface&MockObject $logger; private IProviderFactory&MockObject $factory; private IMailer&MockObject $mailer; + private ITagManager&MockObject $tagManager; protected function setUp(): void { $this->shareManager = $this->createMock(IManager::class); @@ -111,6 +114,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger = $this->createMock(LoggerInterface::class); $this->factory = $this->createMock(IProviderFactory::class); $this->mailer = $this->createMock(IMailer::class); + $this->tagManager = $this->createMock(ITagManager::class); $this->ocs = new ShareAPIController( $this->appName, @@ -130,6 +134,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ); } @@ -157,6 +162,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ])->onlyMethods(['formatShare']) ->getMock(); @@ -841,8 +847,8 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ]) ->onlyMethods(['canAccessShare']) ->getMock(); @@ -1474,6 +1480,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ]) ->onlyMethods(['formatShare']) @@ -1816,8 +1823,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -1913,8 +1921,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); $this->request @@ -2338,8 +2347,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -2408,8 +2418,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -2639,8 +2650,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); @@ -5138,4 +5150,30 @@ class ShareAPIControllerTest extends TestCase { $node->method('getId')->willReturn(42); return [$userFolder, $node]; } + + public function testPopulateTags(): void { + $tagger = $this->createMock(ITags::class); + $this->tagManager->method('load') + ->with('files') + ->willReturn($tagger); + $data = [ + ['file_source' => 10], + ['file_source' => 22, 'foo' => 'bar'], + ['file_source' => 42, 'x' => 'y'], + ]; + $tags = [ + 10 => ['tag3'], + 42 => ['tag1', 'tag2'], + ]; + $tagger->method('getTagsForObjects') + ->with([10, 22, 42]) + ->willReturn($tags); + + $result = self::invokePrivate($this->ocs, 'populateTags', [$data]); + $this->assertSame([ + ['file_source' => 10, 'tags' => ['tag3']], + ['file_source' => 22, 'foo' => 'bar', 'tags' => []], + ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], + ], $result); + } } diff --git a/apps/files_sharing/tests/EncryptedSizePropagationTest.php b/apps/files_sharing/tests/EncryptedSizePropagationTest.php index a416cd14715..6bcded8b3e2 100644 --- a/apps/files_sharing/tests/EncryptedSizePropagationTest.php +++ b/apps/files_sharing/tests/EncryptedSizePropagationTest.php @@ -24,14 +24,19 @@ class EncryptedSizePropagationTest extends SizePropagationTest { protected function setupUser($name, $password = '') { $this->createUser($name, $password); - $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); - $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); + $this->registerMountForUser($name); $this->setupForUser($name, $password); $this->loginWithEncryption($name); return new View('/' . $name . '/files'); } + private function registerMountForUser($user): void { + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); + $this->registerMount($user, '\OC\Files\Storage\Local', '/' . $user, ['datadir' => $tmpFolder]); + } + protected function loginHelper($user, $create = false, $password = false) { + $this->registerMountForUser($user); $this->setupForUser($user, $password); parent::loginHelper($user, $create, $password); } |