diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-27 16:03:37 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-27 16:03:37 +0200 |
commit | 20e7a0c07b4259a22231b70a1b66514be2adeed7 (patch) | |
tree | 0da2ceca12b9a7b504315b4736e2a48d35ea339e | |
parent | ca72c0150b3ea490c06c8c4824aebf0d0da33088 (diff) | |
download | nextcloud-server-20e7a0c07b4259a22231b70a1b66514be2adeed7.tar.gz nextcloud-server-20e7a0c07b4259a22231b70a1b66514be2adeed7.zip |
fix sharerecipientssorter tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r-- | apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php | 60 |
2 files changed, 50 insertions, 12 deletions
diff --git a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php index 5d19ed5d427..db213398118 100644 --- a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php +++ b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php @@ -55,12 +55,12 @@ class ShareRecipientSorter implements ISorter { if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { return; } - /** @var Node[] $nodes */ $user = $this->userSession->getUser(); if($user === null) { return; } $userFolder = $this->rootFolder->getUserFolder($user->getUID()); + /** @var Node[] $nodes */ $nodes = $userFolder->getById((int)$context['itemId']); if(count($nodes) === 0) { return; diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php index 42487e61622..8f516788761 100644 --- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php +++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php @@ -26,15 +26,20 @@ namespace OCA\Files_Sharing\Tests\Collaboration; use OCA\Files_Sharing\Collaboration\ShareRecipientSorter; use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IUser; +use OCP\IUserSession; use OCP\Share\IManager; use Test\TestCase; class ShareRecipientSorterTest extends TestCase { /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ protected $shareManager; - /** @var Folder|\PHPUnit_Framework_MockObject_MockObject */ - protected $userFolder; + /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */ + protected $rootFolder; + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ + protected $userSession; /** @var ShareRecipientSorter */ protected $sorter; @@ -42,9 +47,10 @@ class ShareRecipientSorterTest extends TestCase { parent::setUp(); $this->shareManager = $this->createMock(IManager::class); - $this->userFolder = $this->createMock(Folder::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->userSession = $this->createMock(IUserSession::class); - $this->sorter = new ShareRecipientSorter($this->shareManager, $this->userFolder); + $this->sorter = new ShareRecipientSorter($this->shareManager, $this->rootFolder, $this->userSession); } /** @@ -54,8 +60,23 @@ class ShareRecipientSorterTest extends TestCase { public function testSort($data) { $node = $this->createMock(Node::class); + /** @var Folder|\PHPUnit_Framework_MockObject_MockObject $folder */ + $folder = $this->createMock(Folder::class); + $this->rootFolder->expects($this->any()) + ->method('getUserFolder') + ->willReturn($folder); + + $user = $this->createMock(IUser::class); + $user->expects($this->any()) + ->method('getUID') + ->willReturn('yvonne'); + + $this->userSession->expects($this->once()) + ->method('getUser') + ->willReturn($user); + if ($data['context']['itemType'] === 'files') { - $this->userFolder->expects($this->once()) + $folder->expects($this->once()) ->method('getById') ->with($data['context']['itemId']) ->willReturn([$node]); @@ -65,7 +86,7 @@ class ShareRecipientSorterTest extends TestCase { ->with($node) ->willReturn($data['accessList']); } else { - $this->userFolder->expects($this->never()) + $folder->expects($this->never()) ->method('getById'); $this->shareManager->expects($this->never()) ->method('getAccessList'); @@ -78,17 +99,34 @@ class ShareRecipientSorterTest extends TestCase { } public function testSortNoNodes() { - $this->userFolder->expects($this->once()) + /** @var Folder|\PHPUnit_Framework_MockObject_MockObject $folder */ + $folder = $this->createMock(Folder::class); + $this->rootFolder->expects($this->any()) + ->method('getUserFolder') + ->willReturn($folder); + + $folder->expects($this->once()) ->method('getById') ->willReturn([]); + $user = $this->createMock(IUser::class); + $user->expects($this->any()) + ->method('getUID') + ->willReturn('yvonne'); + + $this->userSession->expects($this->once()) + ->method('getUser') + ->willReturn($user); + $this->shareManager->expects($this->never()) ->method('getAccessList'); - $originalArray = ['users' => [ - ['value' => ['shareWith' => 'alice']], - ['value' => ['shareWith' => 'bob']], - ]]; + $originalArray = [ + 'users' => [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ] + ]; $workArray = $originalArray; $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => 404]); |