fix sharerecipientssorter tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
ca72c0150b
commit
20e7a0c07b
2 changed files with 50 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue