diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-07-09 15:38:33 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-07-12 20:14:30 +0200 |
commit | 967b3848e0e2eeb7ca5447599769fd9fbf825069 (patch) | |
tree | 2711b6de5aa29c96d30c79de16f29fd72aa1396e /apps/files_sharing/tests | |
parent | bc5839e5b5e2192ed7d2dd2173ab5ca72b1d8ebc (diff) | |
download | nextcloud-server-967b3848e0e2eeb7ca5447599769fd9fbf825069.tar.gz nextcloud-server-967b3848e0e2eeb7ca5447599769fd9fbf825069.zip |
fix(files_sharing): phpunit & openapi fixes
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 6 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 58 | ||||
-rw-r--r-- | apps/files_sharing/tests/MountProviderTest.php | 20 |
3 files changed, 57 insertions, 27 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 2fc5219931a..cb5fbd145e9 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -19,6 +19,8 @@ use OCP\IDateTimeZone; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\Mail\IMailer; +use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; use Psr\Container\ContainerInterface; @@ -97,6 +99,8 @@ class ApiTest extends TestCase { $previewManager = $this->createMock(IPreview::class); $dateTimeZone = $this->createMock(IDateTimeZone::class); $logger = $this->createMock(LoggerInterface::class); + $providerFactory = $this->createMock(IProviderFactory::class); + $mailer = $this->createMock(IMailer::class); $dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get())); return new ShareAPIController( @@ -115,6 +119,8 @@ class ApiTest extends TestCase { $previewManager, $dateTimeZone, $logger, + $providerFactory, + $mailer, $userId, ); } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index c8b8c0e94fc..c47bb6d4395 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -28,9 +28,11 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Lock\LockedException; +use OCP\Mail\IMailer; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\IAttributes as IShareAttributes; use OCP\Share\IManager; +use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; use Psr\Container\ContainerInterface; @@ -62,6 +64,8 @@ class ShareAPIControllerTest extends TestCase { private IPreview|\PHPUnit\Framework\MockObject\MockObject $previewManager; private IDateTimeZone|\PHPUnit\Framework\MockObject\MockObject $dateTimeZone; private LoggerInterface $logger; + private IProviderFactory|\PHPUnit\Framework\MockObject\MockObject $factory; + private IMailer|\PHPUnit\Framework\MockObject\MockObject $mailer; protected function setUp(): void { $this->shareManager = $this->createMock(IManager::class); @@ -95,6 +99,8 @@ class ShareAPIControllerTest extends TestCase { }); $this->dateTimeZone = $this->createMock(IDateTimeZone::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->factory = $this->createMock(IProviderFactory::class); + $this->mailer = $this->createMock(IMailer::class); $this->ocs = new ShareAPIController( $this->appName, @@ -112,6 +118,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ); } @@ -137,6 +145,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -152,7 +162,7 @@ class ShareAPIControllerTest extends TestCase { [ 'scope' => 'permissions', 'key' => 'download', - 'enabled' => true + 'value' => true ] ]; @@ -360,7 +370,7 @@ class ShareAPIControllerTest extends TestCase { // canDeleteShareFromSelf $user = $this->createMock(IUser::class); - $group = $this->getMockBuilder('OCP\IGroup')->getMock(); + $group = $this->getMockBuilder(IGroup::class)->getMock(); $this->groupManager ->method('get') ->with('group') @@ -377,7 +387,7 @@ class ShareAPIControllerTest extends TestCase { ->method('lock') ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -423,7 +433,7 @@ class ShareAPIControllerTest extends TestCase { // canDeleteShareFromSelf $user = $this->createMock(IUser::class); - $group = $this->getMockBuilder('OCP\IGroup')->getMock(); + $group = $this->getMockBuilder(IGroup::class)->getMock(); $this->groupManager ->method('get') ->with('group') @@ -440,7 +450,7 @@ class ShareAPIControllerTest extends TestCase { ->method('lock') ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -522,7 +532,7 @@ class ShareAPIControllerTest extends TestCase { $storage->method('getId')->willReturn('STORAGE'); $storage->method('getCache')->willReturn($cache); - $parentFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $parentFolder = $this->getMockBuilder(Folder::class)->getMock(); $parentFolder->method('getId')->willReturn(3); $file = $this->getMockBuilder('OCP\Files\File')->getMock(); @@ -534,7 +544,7 @@ class ShareAPIControllerTest extends TestCase { $file->method('getMTime')->willReturn(1234567890); $file->method('getMimeType')->willReturn('myMimeType'); - $folder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $folder = $this->getMockBuilder(Folder::class)->getMock(); $folder->method('getId')->willReturn(2); $folder->method('getPath')->willReturn('folder'); $folder->method('getStorage')->willReturn($storage); @@ -739,6 +749,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['canAccessShare']) @@ -754,7 +766,7 @@ class ShareAPIControllerTest extends TestCase { ->with($share->getFullId(), 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $userFolder ->method('getRelativePath') ->willReturnArgument(0); @@ -788,7 +800,7 @@ class ShareAPIControllerTest extends TestCase { $user->method('getDisplayName')->willReturn('userDisplay'); $user->method('getSystemEMailAddress')->willReturn('userId@example.com'); - $group = $this->getMockBuilder('OCP\IGroup')->getMock(); + $group = $this->getMockBuilder(IGroup::class)->getMock(); $group->method('getGID')->willReturn('groupId'); $this->userManager->method('get')->willReturnMap([ @@ -822,7 +834,7 @@ class ShareAPIControllerTest extends TestCase { ->with('ocinternal:42', 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1371,6 +1383,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -1385,7 +1399,7 @@ class ShareAPIControllerTest extends TestCase { } ); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $userFolder->method('get') ->with('path') ->willReturn($getSharesParameters['path']); @@ -1447,7 +1461,7 @@ class ShareAPIControllerTest extends TestCase { $file = $this->getMockBuilder(File::class)->getMock(); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1480,9 +1494,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($user); - $group = $this->getMockBuilder('OCP\IGroup')->getMock(); + $group = $this->getMockBuilder(IGroup::class)->getMock(); $group->method('inGroup')->with($user)->willReturn(true); - $group2 = $this->getMockBuilder('OCP\IGroup')->getMock(); + $group2 = $this->getMockBuilder(IGroup::class)->getMock(); $group2->method('inGroup')->with($user)->willReturn(false); $this->groupManager->method('get')->willReturnMap([ @@ -1543,7 +1557,7 @@ class ShareAPIControllerTest extends TestCase { * @param bool canAccessShareByHelper */ public function testCanAccessRoomShare(bool $expected, \OCP\Share\IShare $share, bool $helperAvailable, bool $canAccessShareByHelper) { - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1712,6 +1726,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -1808,6 +1824,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -2228,6 +2246,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -2296,6 +2316,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -2537,6 +2559,8 @@ class ShareAPIControllerTest extends TestCase { $this->previewManager, $this->dateTimeZone, $this->logger, + $this->factory, + $this->mailer, $this->currentUser, ])->setMethods(['formatShare']) ->getMock(); @@ -3806,7 +3830,7 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, - 'attributes' => '[{"scope":"permissions","key":"download","enabled":true}]', + 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', ], $share, [], false ]; // User backend up @@ -3845,7 +3869,7 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, - 'attributes' => '[{"scope":"permissions","key":"download","enabled":true}]', + 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', ], $share, [ ['owner', $owner], ['initiator', $initiator], diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php index dc796437316..f565d2e3656 100644 --- a/apps/files_sharing/tests/MountProviderTest.php +++ b/apps/files_sharing/tests/MountProviderTest.php @@ -70,7 +70,7 @@ class MountProviderTest extends \Test\TestCase { $result = null; foreach ($attrs as $attr) { if ($attr['key'] === $key && $attr['scope'] === $scope) { - $result = $attr['enabled']; + $result = $attr['value']; } } return $result; @@ -117,7 +117,7 @@ class MountProviderTest extends \Test\TestCase { $rootFolder = $this->createMock(IRootFolder::class); $userManager = $this->createMock(IUserManager::class); $attr1 = []; - $attr2 = [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]; + $attr2 = [['scope' => 'permission', 'key' => 'download', 'value' => true]]; $userShares = [ $this->makeMockShare(1, 100, 'user2', '/share2', 0, $attr1), $this->makeMockShare(2, 100, 'user2', '/share2', 31, $attr2), @@ -221,14 +221,14 @@ class MountProviderTest extends \Test\TestCase { // #1: share as outsider with "group1" and "user1" with different permissions [ [ - [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute1', 'enabled' => true]]], + [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true], ['scope' => 'app', 'key' => 'attribute1', 'value' => true]]], ], [ - [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => false], ['scope' => 'app', 'key' => 'attribute2', 'enabled' => false]]], + [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => false], ['scope' => 'app', 'key' => 'attribute2', 'value' => false]]], ], [ // use highest permissions - ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute1', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute2', 'enabled' => false]]], + ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true], ['scope' => 'app', 'key' => 'attribute1', 'value' => true], ['scope' => 'app', 'key' => 'attribute2', 'value' => false]]], ], ], // #2: share as outsider with "group1" and "group2" with same permissions @@ -249,12 +249,12 @@ class MountProviderTest extends \Test\TestCase { [ ], [ - [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => false]]], - [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]], + [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => false]]], + [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], ], [ // use higher permissions (most permissive) - ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]], + ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], ], ], // #4: share as insider with "group1" @@ -273,8 +273,8 @@ class MountProviderTest extends \Test\TestCase { [ ], [ - [1, 100, 'user1', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]], - [2, 100, 'user1', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => false]]], + [1, 100, 'user1', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], + [2, 100, 'user1', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => false]]], ], [ // no received share since "user1" is the sharer/owner |